diff options
Diffstat (limited to 'qpid/dotnet/client-010/gentool')
-rw-r--r-- | qpid/dotnet/client-010/gentool/Composite.tpl | 273 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/Composite.tpl.bak | 273 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/Constant.tpl | 16 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/Enum.tpl | 38 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/Invoker.tpl | 46 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/MethodDelegate.tpl | 14 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/MethodDelegate.tpl.bak | 14 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/Option.tpl | 21 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/StructFactory.tpl | 43 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/Type.tpl | 82 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/build.xml | 52 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/build.xml.bak | 52 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/codegen | 64 | ||||
-rw-r--r-- | qpid/dotnet/client-010/gentool/dotnetgenutil$py.class | bin | 0 -> 19091 bytes | |||
-rw-r--r-- | qpid/dotnet/client-010/gentool/dotnetgenutil.py | 252 |
15 files changed, 1240 insertions, 0 deletions
diff --git a/qpid/dotnet/client-010/gentool/Composite.tpl b/qpid/dotnet/client-010/gentool/Composite.tpl new file mode 100644 index 0000000000..3b8bb00850 --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Composite.tpl @@ -0,0 +1,273 @@ +using System; +using org.apache.qpid.transport.codec; +using System.Collections.Generic; +using org.apache.qpid.transport.util; +using org.apache.qpid.transport.network; +using System.IO; + +namespace org.apache.qpid.transport +{ + +${ +from genutil import * + +cls = klass(type)["@name"] + +segments = type["segments"] + +if type.name in ("control", "command"): + override = "override" + base = "Method" + size = 0 + pack = 2 + if segments: + payload = "true" + else: + payload = "false" + if type.name == "control" and cls == "connection": + track = "Frame.L1" + elif cls == "session" and type["@name"] in ("attach", "attached", "detach", "detached"): + track = "Frame.L2" + elif type.name == "command": + track = "Frame.L4" + else: + track = "Frame.L3" +else: + override = "" + base = "Struct" + size = type["@size"] + pack = num(type["@pack"]) + payload = "false" + track = "4" + +PACK_TYPES = { + 1: "byte", + 2: "int", + 4: "int" +} + +typecode = code(type) +} + +public sealed class $name : $base { + + public const int TYPE = $typecode; + + public override int getStructType() { + return TYPE; + } + + public override int getSizeWidth() { + return $size; + } + + public override int getPackWidth() { + return $pack; + } + + public $override bool hasPayload() { + return $payload; + } + + public $override byte EncodedTrack + { + get{ return $track; } + set { throw new NotImplementedException(); } + } + +${ +from dotnetgenutil import * +if pack > 0: + out(" private $(PACK_TYPES[pack]) packing_flags = 0;\n"); + +fields = get_fields(type) +params = get_dotnetparameters(type, fields) +options = get_options(fields) + +for f in fields: + if not f.empty: + out(" private $(f.type) _$(f.name);\n") + +if segments: + out(" private Header _header;\n") + out(" private MemoryStream _body;\n") +} + +${ +if fields: + out(" public $name() {}\n") +} + + public $name($(", ".join(params))) { +${ +for f in fields: + if f.option: continue + out(" $(f.set)($(f.name));\n") + +if segments: + out(" Header = header;\n") + out(" Body = body;\n") + +if options or base == "Method": + out(""" + for (int i=0; i < _options.Length; i++) { + switch (_options[i]) { +""") + + for f in options: + out(" case Option.$(f.option): packing_flags |= $(f.flag_mask(pack)); break;\n") + + if base == "Method": + out(""" case Option.SYNC: Sync = true; break; + case Option.BATCH: Batch = true; break; +""") + out(""" case Option.NONE: break; + default: throw new Exception("invalid option: " + _options[i]); + } + } +""") +} + } + + public $override void dispatch<C>(C context, MethodDelegate<C> mdelegate) { + mdelegate.$(dromedary(name))(context, this); + } + +${ +for f in fields: + if pack > 0: + out(""" + public bool $(f.has)() { + return (packing_flags & $(f.flag_mask(pack))) != 0; + } + + public $name $(f.clear)() { + packing_flags = (byte) (packing_flags & ~$(f.flag_mask(pack))); +${ +if (not f.empty and not (f.default == "null")): + out(" _$(f.name) = $(f.default);") +} + Dirty = true; + return this; + } +""") + + out(""" + public $(f.type) $(f.get)() { +${ +if f.empty: + out(" return $(f.has)();") +else: + out(" return _$(f.name);") +} + } + + public $name $(f.set)($(f.type) value) { +${ +if not f.empty: + out(" _$(f.name) = value;") +} +${ +if pack > 0: + out(" packing_flags |= $(f.flag_mask(pack));") +} + Dirty = true; + return this; + } + + public $name $(f.name)($(f.type) value) { + return $(f.set)(value); + } +""") +} + +${ +if segments: + out(""" public Header Header { + get { return _header;} + set { _header = value;} + } + + public $name header(Header header) { + Header = header; + return this; + } + + public MemoryStream Body + { + get{ return _body;} + set{ _body = value;} + } + + public $name body(MemoryStream body) + { + Body = body; + return this; + } +""") +} + + public override void write(Encoder enc) + { +${ +if pack > 0: + out(" enc.writeUint%s(packing_flags);\n" % (pack*8)); + +for f in fields: + if f.empty: + continue + if pack > 0: + out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ") + pre = "" + post = "" + if f.type_node.name == "struct": + pre = "%s.TYPE, " % cname(f.type_node) + elif f.type_node.name == "domain": + post = "" + pre = "(short)" + out(" enc.write$(f.coder)($(pre)_$(f.name)$(post));\n") +} + } + + public override void read(Decoder dec) + { +${ +if pack > 0: + out(" packing_flags = ($(PACK_TYPES[pack])) dec.readUint%s();\n" % (pack*8)); + +for f in fields: + if f.empty: + continue + if pack > 0: + out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ") + pre = "" + post = "" + arg = "" + if f.type_node.name == "struct": + pre = "(%s)" % cname(f.type_node) + arg = "%s.TYPE" % cname(f.type_node) + elif f.type_node.name == "domain": + pre = "%sGetter.get(" % cname(f.type_node) + post = ")" + out(" _$(f.name) = $(pre)dec.read$(f.coder)($(arg))$(post);\n") +} + } + + public override Dictionary<String,Object> Fields + { + get{ + Dictionary<String,Object> result = new Dictionary<String,Object>(); + +${ +for f in fields: + if pack > 0: + out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ") + out(' result.Add("_$(f.name)", $(f.get)());\n') +} + + return result; + } + } + +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/Composite.tpl.bak b/qpid/dotnet/client-010/gentool/Composite.tpl.bak new file mode 100644 index 0000000000..660980c448 --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Composite.tpl.bak @@ -0,0 +1,273 @@ +using System; +using org.apache.qpid.transport.codec; +using System.Collections.Generic; +using org.apache.qpid.transport.util; +using org.apache.qpid.transport.network; +using System.IO; + +namespace org.apache.qpid.transport +{ + +${ +from genutil import * + +cls = klass(type)["@name"] + +segments = type["segments"] + +if type.name in ("control", "command"): + override = "override" + base = "Method" + size = 0 + pack = 2 + if segments: + payload = "true" + else: + payload = "false" + if type.name == "control" and cls == "connection": + track = "Frame.L1" + elif cls == "session" and type["@name"] in ("attach", "attached", "detach", "detached"): + track = "Frame.L2" + elif type.name == "command": + track = "Frame.L4" + else: + track = "Frame.L3" +else: + override = "" + base = "Struct" + size = type["@size"] + pack = num(type["@pack"]) + payload = "false" + track = "4" + +PACK_TYPES = { + 1: "byte", + 2: "short", + 4: "int" +} + +typecode = code(type) +} + +public sealed class $name : $base { + + public const int TYPE = $typecode; + + public override int getStructType() { + return TYPE; + } + + public override int getSizeWidth() { + return $size; + } + + public override int getPackWidth() { + return $pack; + } + + public $override bool hasPayload() { + return $payload; + } + + public $override byte EncodedTrack + { + get{ return $track; } + set { throw new NotImplementedException(); } + } + +${ +from dotnetgenutil import * +if pack > 0: + out(" private $(PACK_TYPES[pack]) packing_flags = 0;\n"); + +fields = get_fields(type) +params = get_dotnetparameters(type, fields) +options = get_options(fields) + +for f in fields: + if not f.empty: + out(" private $(f.type) _$(f.name);\n") + +if segments: + out(" private Header _header;\n") + out(" private MemoryStream _body;\n") +} + +${ +if fields: + out(" public $name() {}\n") +} + + public $name($(", ".join(params))) { +${ +for f in fields: + if f.option: continue + out(" $(f.set)($(f.name));\n") + +if segments: + out(" Header = header;\n") + out(" Body = body;\n") + +if options or base == "Method": + out(""" + for (int i=0; i < _options.Length; i++) { + switch (_options[i]) { +""") + + for f in options: + out(" case Option.$(f.option): packing_flags |= $(f.flag_mask(pack)); break;\n") + + if base == "Method": + out(""" case Option.SYNC: Sync = true; break; + case Option.BATCH: Batch = true; break; +""") + out(""" case Option.NONE: break; + default: throw new Exception("invalid option: " + _options[i]); + } + } +""") +} + } + + public $override void dispatch<C>(C context, MethodDelegate<C> mdelegate) { + mdelegate.$(dromedary(name))(context, this); + } + +${ +for f in fields: + if pack > 0: + out(""" + public bool $(f.has)() { + return (packing_flags & $(f.flag_mask(pack))) != 0; + } + + public $name $(f.clear)() { + packing_flags = (byte) (packing_flags & ~$(f.flag_mask(pack))); +${ +if (not f.empty and not (f.default == "null")): + out(" _$(f.name) = $(f.default);") +} + Dirty = true; + return this; + } +""") + + out(""" + public $(f.type) $(f.get)() { +${ +if f.empty: + out(" return $(f.has)();") +else: + out(" return _$(f.name);") +} + } + + public $name $(f.set)($(f.type) value) { +${ +if not f.empty: + out(" _$(f.name) = value;") +} +${ +if pack > 0: + out(" packing_flags |= $(f.flag_mask(pack));") +} + Dirty = true; + return this; + } + + public $name $(f.name)($(f.type) value) { + return $(f.set)(value); + } +""") +} + +${ +if segments: + out(""" public Header Header { + get { return _header;} + set { _header = value;} + } + + public $name header(Header header) { + Header = header; + return this; + } + + public MemoryStream Body + { + get{ return _body;} + set{ _body = value;} + } + + public $name body(MemoryStream body) + { + Body = body; + return this; + } +""") +} + + public override void write(Encoder enc) + { +${ +if pack > 0: + out(" enc.writeUint%s(packing_flags);\n" % (pack*8)); + +for f in fields: + if f.empty: + continue + if pack > 0: + out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ") + pre = "" + post = "" + if f.type_node.name == "struct": + pre = "%s.TYPE, " % cname(f.type_node) + elif f.type_node.name == "domain": + post = "" + pre = "(short)" + out(" enc.write$(f.coder)($(pre)_$(f.name)$(post));\n") +} + } + + public override void read(Decoder dec) + { +${ +if pack > 0: + out(" packing_flags = ($(PACK_TYPES[pack])) dec.readUint%s();\n" % (pack*8)); + +for f in fields: + if f.empty: + continue + if pack > 0: + out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ") + pre = "" + post = "" + arg = "" + if f.type_node.name == "struct": + pre = "(%s)" % cname(f.type_node) + arg = "%s.TYPE" % cname(f.type_node) + elif f.type_node.name == "domain": + pre = "%sGetter.get(" % cname(f.type_node) + post = ")" + out(" _$(f.name) = $(pre)dec.read$(f.coder)($(arg))$(post);\n") +} + } + + public override Dictionary<String,Object> Fields + { + get{ + Dictionary<String,Object> result = new Dictionary<String,Object>(); + +${ +for f in fields: + if pack > 0: + out(" if ((packing_flags & $(f.flag_mask(pack))) != 0)\n ") + out(' result.Add("_$(f.name)", $(f.get)());\n') +} + + return result; + } + } + +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/Constant.tpl b/qpid/dotnet/client-010/gentool/Constant.tpl new file mode 100644 index 0000000000..87652b6f7d --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Constant.tpl @@ -0,0 +1,16 @@ +namespace org.apache.qpid.transport +{ + +${from genutil import *} + +public class Constant +{ +${ +constants = spec.query["amqp/constant"] + +for c in constants: + name = scream(c["@name"]) + value = c["@value"] + out(" public const int $name = $value;\n") +}} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/Enum.tpl b/qpid/dotnet/client-010/gentool/Enum.tpl new file mode 100644 index 0000000000..b3b6d93f8a --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Enum.tpl @@ -0,0 +1,38 @@ +using System; +namespace org.apache.qpid.transport +{ +${ +from genutil import * + +vtype = jtype(resolve_type(type)) + +out(" public enum $name : $vtype") + +choices = [(scream(ch["@name"]), "= %s" % (ch["@value"])) + for ch in type.query["enum/choice"]] +} + { + $(",\n ".join(["%s%s" % ch for ch in choices])) + } + +${ + +out(" public struct $name") +out("Getter") +} + { + public static $name get($vtype value) + { + switch (value) + { +${ +choices = [(scream(ch["@name"]), "%s" % (ch["@value"])) + for ch in type.query["enum/choice"]] + +for ch, value in choices: + out(' case $value: return $name.$ch;\n') +} default: throw new Exception("no such value: " + value); + } + } + } +} diff --git a/qpid/dotnet/client-010/gentool/Invoker.tpl b/qpid/dotnet/client-010/gentool/Invoker.tpl new file mode 100644 index 0000000000..f1909d2e29 --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Invoker.tpl @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.IO; +using common.org.apache.qpid.transport.util; + +namespace org.apache.qpid.transport +{ + +public abstract class Invoker { + + protected abstract void invoke(Method method); + public abstract Future<T> invoke<T>(Method method, Future<T> resultClass); + +${ +from dotnetgenutil import * + +for c in composites: + name = cname(c) + fields = get_fields(c) + params = get_dotnetparameters(c, fields) + args = get_arguments(c, fields) + result = c["result"] + if result: + if not result["@type"]: + rname = cname(result["struct"]) + else: + rname = cname(result, "@type") + jresult = "Future<%s>" % rname + jreturn = "return " + jclass = ", new ResultFuture<%s>()" % rname + jinvoke = "invoke" + else: + jinvoke = "invoke" + jresult = "void" + jreturn = "" + jclass = "" + + out(""" + public $jresult $(dromedary(name))($(", ".join(params))) { + $(jreturn)$jinvoke(new $name($(", ".join(args)))$jclass); + } +""") +} + +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/MethodDelegate.tpl b/qpid/dotnet/client-010/gentool/MethodDelegate.tpl new file mode 100644 index 0000000000..4c7010d5bb --- /dev/null +++ b/qpid/dotnet/client-010/gentool/MethodDelegate.tpl @@ -0,0 +1,14 @@ +namespace org.apache.qpid.transport +{ + +public abstract class MethodDelegate<C> { + +${ +from genutil import * + +for c in composites: + name = cname(c) + out(" public virtual void $(dromedary(name))(C context, $name mystruct) {}\n") +} +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/MethodDelegate.tpl.bak b/qpid/dotnet/client-010/gentool/MethodDelegate.tpl.bak new file mode 100644 index 0000000000..58a578b556 --- /dev/null +++ b/qpid/dotnet/client-010/gentool/MethodDelegate.tpl.bak @@ -0,0 +1,14 @@ +namespace org.apache.qpid.transport +{ + +public abstract class MethodDelegate<C> { + +${ +from genutil import * + +for c in composites: + name = cname(c) + out(" public void $(dromedary(name))(C context, $name mystruct) {}\n") +} +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/Option.tpl b/qpid/dotnet/client-010/gentool/Option.tpl new file mode 100644 index 0000000000..ce4c0a3da1 --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Option.tpl @@ -0,0 +1,21 @@ +namespace org.apache.qpid.transport +{ +public enum Option { + +${ +from genutil import * + +options = {} + +for c in composites: + for f in c.query["field"]: + t = resolve_type(f) + if t["@name"] == "bit": + option = scream(f["@name"]) + if not options.has_key(option): + options[option] = None + out(" $option,\n")} + BATCH, + NONE +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/StructFactory.tpl b/qpid/dotnet/client-010/gentool/StructFactory.tpl new file mode 100644 index 0000000000..2efa749bbf --- /dev/null +++ b/qpid/dotnet/client-010/gentool/StructFactory.tpl @@ -0,0 +1,43 @@ +using System; + +namespace org.apache.qpid.transport +{ + +class StructFactory { + + public static Struct create(int type) + { + switch (type) + { +${ +from genutil import * + +fragment = """ case $name.TYPE: + return new $name(); +""" + +for c in composites: + name = cname(c) + if c.name == "struct": + out(fragment) +} default: + throw new Exception("type: " + type); + } + } + + public static Struct createInstruction(int type) + { + switch (type) + { +${ +for c in composites: + name = cname(c) + if c.name in ("command", "control"): + out(fragment) +} default: + throw new Exception("type: " + type); + } + } + +} +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/Type.tpl b/qpid/dotnet/client-010/gentool/Type.tpl new file mode 100644 index 0000000000..914f320519 --- /dev/null +++ b/qpid/dotnet/client-010/gentool/Type.tpl @@ -0,0 +1,82 @@ +using System; + +namespace org.apache.qpid.transport +{ + +${from genutil import *} + +public struct QpidType +{ + public Code code; + public int width; + public bool isfixed; + + public Code Code + { + get { return code; } + set { code = value; } + } + + public int Width + { + get { return width; } + set { width = value; } + } + + public bool Fixed + { + get { return isfixed; } + set { isfixed = value; } + } + + QpidType(Code code, int width, bool isfixed) + { + this.code = code; + this.width = width; + this.isfixed = isfixed; + } + + public static QpidType get(byte code) + { + switch (code) + { +${ +types = spec.query["amqp/type"] + spec.query["amqp/class/type"] +codes = {} +first = True +for t in types: + code = t["@code"] + fix_width = t["@fixed-width"] + var_width = t["@variable-width"] + + if code is None: + continue + + if fix_width is None: + width = var_width + fixed = "false" + else: + width = fix_width + fixed = "true" + + name = scream(t["@name"]) + codes[code] = name + + out(" case $code : return new QpidType(Code.$name, $width, $fixed);\n") +} + default: throw new Exception("unknown code: " + code); + } + } +} + +public enum Code : byte + { +${ +keys = list(codes.keys()) +keys.sort() + +for code in keys: + out(" $(codes[code]) = $code,\n") +} + } +}
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/build.xml b/qpid/dotnet/client-010/gentool/build.xml new file mode 100644 index 0000000000..8d9622dcda --- /dev/null +++ b/qpid/dotnet/client-010/gentool/build.xml @@ -0,0 +1,52 @@ +<!--
+ -
+ - Licensed to the Apache Software Foundation (ASF) under one
+ - or more contributor license agreements. See the NOTICE file
+ - distributed with this work for additional information
+ - regarding copyright ownership. The ASF licenses this file
+ - to you under the Apache License, Version 2.0 (the
+ - "License"); you may not use this file except in compliance
+ - with the License. You may obtain a copy of the License at
+ -
+ - http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing,
+ - software distributed under the License is distributed on an
+ - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ - KIND, either express or implied. See the License for the
+ - specific language governing permissions and limitations
+ - under the License.
+ -
+ -->
+<project name="GenTool" default="build">
+
+ <property name="generated.dir" location="../client/" />
+ <property name="gentools.timestamp" location="${generated.dir}/gentools.timestamp" />
+ <property name="jython.timestamp" location="${generated.dir}/jython.timestamp" />
+ <property name="java.basedir" location="../../../java/common" />
+ <property name="mllib.dir" location="../../../python" />
+ <property name="xml.spec.dir" location="../../../specs" />
+
+
+ <target name="check_jython_deps">
+ <uptodate property="jython.notRequired" targetfile="${jython.timestamp}">
+ <srcfiles dir="${xml.spec.dir}" includes="amqp.0-10-qpid-errata.xml" />
+ </uptodate>
+ </target>
+
+ <target name="build" depends="check_jython_deps" unless="jython.notRequired">
+ <java classname="org.python.util.jython" fork="true" failonerror="true">
+ <arg value="-Dpython.cachedir.skip=true"/>
+ <arg value="-Dpython.path=${java.basedir}/jython-lib.jar/Lib${path.separator}${mllib.dir}${path.separator}${java.basedir}${path.separator}${basedir}"/>
+ <arg value="${basedir}/codegen"/>
+ <arg value="${generated.dir}"/>
+ <arg value="${xml.spec.dir}/amqp.0-10-qpid-errata.xml"/>
+ <arg value="${basedir}"/>
+ <classpath>
+ <pathelement location="${java.basedir}/jython-2.2-rc2.jar"/>
+ </classpath>
+ </java>
+ <touch file="${jython.timestamp}" />
+ </target>
+
+</project>
diff --git a/qpid/dotnet/client-010/gentool/build.xml.bak b/qpid/dotnet/client-010/gentool/build.xml.bak new file mode 100644 index 0000000000..d0d8d9297f --- /dev/null +++ b/qpid/dotnet/client-010/gentool/build.xml.bak @@ -0,0 +1,52 @@ +<!--
+ -
+ - Licensed to the Apache Software Foundation (ASF) under one
+ - or more contributor license agreements. See the NOTICE file
+ - distributed with this work for additional information
+ - regarding copyright ownership. The ASF licenses this file
+ - to you under the Apache License, Version 2.0 (the
+ - "License"); you may not use this file except in compliance
+ - with the License. You may obtain a copy of the License at
+ -
+ - http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing,
+ - software distributed under the License is distributed on an
+ - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ - KIND, either express or implied. See the License for the
+ - specific language governing permissions and limitations
+ - under the License.
+ -
+ -->
+<project name="GenTool" default="build">
+
+ <property name="generated.dir" location="../client/generated" />
+ <property name="gentools.timestamp" location="${generated.dir}/gentools.timestamp" />
+ <property name="jython.timestamp" location="${generated.dir}/jython.timestamp" />
+ <property name="java.basedir" location="../../../java/common" />
+ <property name="mllib.dir" location="../../../python" />
+ <property name="xml.spec.dir" location="../../../specs" />
+
+
+ <target name="check_jython_deps">
+ <uptodate property="jython.notRequired" targetfile="${jython.timestamp}">
+ <srcfiles dir="${xml.spec.dir}" includes="amqp.0-10-qpid-errata.xml" />
+ </uptodate>
+ </target>
+
+ <target name="build" depends="check_jython_deps" unless="jython.notRequired">
+ <java classname="org.python.util.jython" fork="true" failonerror="true">
+ <arg value="-Dpython.cachedir.skip=true"/>
+ <arg value="-Dpython.path=${java.basedir}/jython-lib.jar/Lib${path.separator}${mllib.dir}${path.separator}${java.basedir}${path.separator}${basedir}"/>
+ <arg value="${basedir}/codegen"/>
+ <arg value="${generated.dir}"/>
+ <arg value="${xml.spec.dir}/amqp.0-10-qpid-errata.xml"/>
+ <arg value="${basedir}"/>
+ <classpath>
+ <pathelement location="${java.basedir}/jython-2.2-rc2.jar"/>
+ </classpath>
+ </java>
+ <touch file="${jython.timestamp}" />
+ </target>
+
+</project>
diff --git a/qpid/dotnet/client-010/gentool/codegen b/qpid/dotnet/client-010/gentool/codegen new file mode 100644 index 0000000000..7a1476b75e --- /dev/null +++ b/qpid/dotnet/client-010/gentool/codegen @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +import os, sys, mllib +from templating import Parser +from dotnetgenutil import * + +out_dir = sys.argv[1] +spec_file = sys.argv[2] +tpl_dir = sys.argv[3] +pkg_dir = os.path.join(out_dir, "generated") + +if not os.path.exists(pkg_dir): + os.makedirs(pkg_dir) + +spec = mllib.xml_parse(spec_file) + +def excludes(nd): + if (nd.parent is not None and + nd.parent.name == "class" and + nd.parent["@name"] in ("file", "stream")): + return False + else: + return True + +def execute(output, template, **kwargs): + f = open(os.path.join(tpl_dir, template)) + input = f.read() + f.close() + p = Parser(**kwargs) + p.parse(input) + fname = os.path.join(pkg_dir, output) + f = open(fname, "w") + f.write(p.output) + f.close() + +execute("Type.cs", "Type.tpl", spec = spec) +execute("Constant.cs", "Constant.tpl", spec = spec) + +structs = spec.query["amqp/struct"] + \ + spec.query["amqp/class/struct", excludes] + \ + spec.query["amqp/class/command/result/struct", excludes] +controls = spec.query["amqp/class/control", excludes] +commands = spec.query["amqp/class/command", excludes] + +composites = structs + controls + commands + +for c in composites: + name = cname(c) + execute("%s.cs" % name, "Composite.tpl", type = c, name = name) + +execute("MethodDelegate.cs", "MethodDelegate.tpl", composites = composites) +execute("Option.cs", "Option.tpl", composites = composites) +execute("Invoker.cs", "Invoker.tpl", composites = controls + commands) +execute("StructFactory.cs", "StructFactory.tpl", composites = composites) + +def is_enum(nd): + return nd["enum"] is not None + +enums = spec.query["amqp/domain", is_enum] + \ + spec.query["amqp/class/domain", is_enum] + +for e in enums: + name = cname(e) + execute("%s.cs" % name, "Enum.tpl", name = name, type = e)
\ No newline at end of file diff --git a/qpid/dotnet/client-010/gentool/dotnetgenutil$py.class b/qpid/dotnet/client-010/gentool/dotnetgenutil$py.class Binary files differnew file mode 100644 index 0000000000..ddb8855f7c --- /dev/null +++ b/qpid/dotnet/client-010/gentool/dotnetgenutil$py.class diff --git a/qpid/dotnet/client-010/gentool/dotnetgenutil.py b/qpid/dotnet/client-010/gentool/dotnetgenutil.py new file mode 100644 index 0000000000..0bfea4a0ba --- /dev/null +++ b/qpid/dotnet/client-010/gentool/dotnetgenutil.py @@ -0,0 +1,252 @@ +
+def camel(offset, *args):
+ parts = []
+ for a in args:
+ parts.extend(a.split("-"))
+ return "".join(parts[:offset] + [p[0].upper() + p[1:] for p in parts[offset:]])
+
+def dromedary(s):
+ return s[0].lower() + s[1:]
+
+def scream(*args):
+ return "_".join([a.replace("-", "_").upper() for a in args])
+
+def num(x, default=None):
+ if x is not None and x != "":
+ return int(x, 0)
+ else:
+ return default
+
+def klass(nd):
+ parent = nd.parent
+ while parent is not None:
+ if hasattr(parent, "name") and parent.name == "class":
+ return parent
+ parent = parent.parent
+
+untyped = -1
+
+def code(nd):
+ global untyped
+ cd = num(nd["@code"])
+ if cd is None:
+ cd = untyped
+ untyped -= 1
+ return cd
+
+ cls = klass(nd)
+ if cls:
+ cd |= (num(cls["@code"]) << 8)
+ return cd
+
+def root(nd):
+ if nd.parent is None:
+ return nd
+ else:
+ return root(nd.parent)
+
+def qname(nd):
+ name = nd["@name"]
+ cls = klass(nd)
+ if cls != None:
+ return "%s.%s" % (cls["@name"], name)
+ else:
+ return name
+
+RESOLVED = {}
+
+def resolve(node, name):
+ key = (node, name)
+ if RESOLVED.has_key(key):
+ return RESOLVED[key]
+ else:
+ spec = root(node)
+ cls = klass(node)
+ if cls:
+ for nd in cls.query["#tag"]:
+ if nd["@name"] == name:
+ RESOLVED[key] = nd
+ return nd
+ for nd in spec.query["amqp/#tag"] + spec.query["amqp/class/#tag"]:
+ if name == qname(nd):
+ RESOLVED[key] = nd
+ return nd
+ raise Exception("unresolved name: %s" % name)
+
+def resolve_type(nd):
+ if hasattr(nd, "_resolved_type"):
+ return nd._resolved_type
+ else:
+ name = nd["@type"]
+ type = resolve(nd, name)
+ if type.name == "domain" and not type["enum"]:
+ type = resolve_type(type)
+ nd._resolved_type = type
+ return type
+
+TYPES = {
+ "bit": "bool",
+ "uint8": "short",
+ "uint16": "int",
+ "uint32": "long",
+ "uint64": "long",
+ "datetime": "long",
+ "uuid": "UUID",
+ "sequence-no": "int",
+ "sequence-set": "RangeSet", # XXX
+ "byte-ranges": "RangeSet", # XXX
+ "str8": "String",
+ "str16": "String",
+ "vbin8": "byte[]",
+ "vbin16": "byte[]",
+ "vbin32": "byte[]",
+ "struct32": "Struct",
+ "map": "Dictionary<String,Object>",
+ "array": "List<Object>"
+ }
+
+def cname(nd, field="@name"):
+ cls = klass(nd)
+ if cls:
+ if (nd.name in ("struct", "result") and
+ cls["@name"] != "session" and
+ nd[field] != "header"):
+ return camel(0, nd[field])
+ else:
+ return camel(0, cls["@name"], nd[field])
+ else:
+ return camel(0, nd[field])
+
+def jtype(nd):
+ if nd.name == "struct" or nd["enum"]:
+ return cname(nd)
+ else:
+ return TYPES[nd["@name"]]
+
+REFS = {
+ "bool": "Boolean",
+ "byte": "Byte",
+ "short": "Short",
+ "int": "Integer",
+ "long": "Long",
+ "float": "Float",
+ "double": "Double",
+ "char": "Character"
+}
+
+def jref(jt):
+ return REFS.get(jt, jt)
+
+def jclass(jt):
+ idx = jt.find('<')
+ if idx > 0:
+ return jt[:idx]
+ else:
+ return jt
+
+DEFAULTS = {
+ "long": 0,
+ "int": 0,
+ "short": 0,
+ "byte": 0,
+ "char": 0,
+ "bool": "false"
+ }
+
+class Field:
+
+ def __init__(self, index, nd):
+ self.index = index
+ self.name = camel(1, nd["@name"])
+ self.type_node = resolve_type(nd)
+ if self.type_node.name == "domain":
+ self.prim_type = resolve_type(self.type_node)
+ else:
+ self.prim_type = self.type_node
+ self.variable_width = num(self.prim_type["@variable-width"], 0)
+ self.fixed_width = num(self.prim_type["@fixed-width"], 0)
+ self.empty = self.variable_width == 0 and self.fixed_width == 0 and self.prim_type.name != "struct"
+ tname = cname(self.type_node)
+ if self.type_node.name == "struct":
+ self.read = "(%s) dec.readStruct(%s.TYPE)" % (tname, tname)
+ self.write = "enc.writeStruct(%s.TYPE, check(struct).%s)" % (tname, self.name)
+ self.coder = "Struct"
+ elif self.type_node.name == "domain":
+ self.coder = camel(0, self.prim_type["@name"])
+ self.read = "%s.get(dec.read%s())" % (tname, self.coder)
+ self.write = "enc.write%s(check(struct).%s.getValue())" % (self.coder, self.name)
+ else:
+ self.coder = camel(0, self.type_node["@name"])
+ self.read = "dec.read%s()" % self.coder
+ self.write = "enc.write%s(check(struct).%s)" % (self.coder, self.name)
+ self.type = jtype(self.type_node)
+ self.default = DEFAULTS.get(self.type, "null")
+ self.has = camel(1, "has", self.name)
+ self.get = camel(1, "get", self.name)
+ self.set = camel(1, "set", self.name)
+ self.clear = camel(1, "clear", self.name)
+ if self.type == "bool":
+ self.option = scream(nd["@name"])
+ else:
+ self.option = None
+
+ def flag_mask(self, pack):
+ flag = pack * 8 - 8 - (self.index/8)*8 + (self.index % 8)
+ return 1 << flag
+
+
+def get_fields(nd):
+ fields = []
+ index = 0
+ for f in nd.query["field"]:
+ fields.append(Field(index, f))
+ index += 1
+ return fields
+
+def get_parameters(type, fields):
+ params = []
+ options = False
+ for f in fields:
+ if f.option:
+ options = True
+ else:
+ params.append("%s %s" % (f.type, f.name))
+ if type["segments"]:
+ params.append("Header header")
+ params.append("MemoryStream body")
+ if options or type.name in ("control", "command"):
+ params.append("Option ... _options")
+ return params
+
+def get_arguments(type, fields):
+ args = []
+ options = False
+ for f in fields:
+ if f.option:
+ options = True
+ else:
+ args.append(f.name)
+ if type["segments"]:
+ args.append("header")
+ args.append("body")
+ if options or type.name in ("control", "command"):
+ args.append("_options")
+ return args
+
+def get_options(fields):
+ return [f for f in fields if f.option]
+
+def get_dotnetparameters(type, fields):
+ params = []
+ options = False
+ for f in fields:
+ if f.option:
+ options = True
+ else:
+ params.append("%s %s" % (f.type, f.name))
+ if type["segments"]:
+ params.append("Header header")
+ params.append("MemoryStream body")
+ if options or type.name in ("control", "command"):
+ params.append("params Option[] _options")
+ return params
\ No newline at end of file |