From 54b9b8aeb902851cd52825764938e1b012e06a43 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Mon, 27 Aug 2007 12:56:29 +0000 Subject: * rubygen/amqpgen.rb: Performance and API improvements. Added nodes for all amqp.xml elements except doc, assert and rule. (They can easily be added.) In particular AmqpDomain is a proper node, providing a place to do type mapping. Every node has reader methods for AMQP attributes/elements: - attr() for each AMQP attribute "attr" returns the string value. - foos() returns AmqpElements for all the "foo" children. - foo(name) returns AmqpElements for the named "foo" child domain() returns an AmqpDomain rather than the string name. Method names that would clash with Object methods get a trailing "_" So: class_/classes, method_/methods_, type_/types Notes: - no amqp_ prefixes. - AmqpElement does not inherit REXML::Element, AmqpElement#xml() to get the REXML element. Performance: all templates run in 2.8 seconds on my laptop, compared to almost two minutes previously. Main change was to replace xpath searches with simple descent of the Amqp model and cache values selectively based on profiling. * rubygen/cppgen.rb: - Updated for amqpgen changes. - Introduced CppType to manage C++ type information - Moved all type mapping to CppType/AmqpDomain Some templates still do their own type calculations, these should be centralized in CppType so they can be re-used. * rubygen/templates/*: Updated for new API * src/qpid/framing/amqp_types_full.h: Added Uuid.h * xml/cluster.xml: change "type" attribute to "domain" git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@570096 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/rubygen/cppgen.rb | 166 ++++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 78 deletions(-) (limited to 'cpp/rubygen/cppgen.rb') diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb index 109005e743..99d80b0b4e 100755 --- a/cpp/rubygen/cppgen.rb +++ b/cpp/rubygen/cppgen.rb @@ -36,20 +36,20 @@ Copyright=< or " - end - end +class AmqpDomain + @@typemap = { + "bit"=> CppType.new("bool").code("Octet"), + "octet"=>CppType.new("u_int8_t").code("Octet"), # FIXME aconway 2007-08-25: uint + "short"=>CppType.new("u_int16_t").code("Short"), + "long"=>CppType.new("u_int32_t").code("Long"), + "longlong"=>CppType.new("u_int64_t").code("LongLong"), + "timestamp"=>CppType.new("u_int64_t").code("LongLong"), + "longstr"=>CppType.new("string").passcref.retcref.code("LongString"), + "shortstr"=>CppType.new("string").passcref.retcref.code("ShortString"), + "table"=>CppType.new("FieldTable").passcref.retcref.code("FieldTable"), + "content"=>CppType.new("Content").passcref.retcref.code("Content"), + "rfc1982-long-set"=>CppType.new("SequenceNumberSet").passcref.retcref, + "long-struct"=>CppType.new("string").passcref.retcref.code("LongString"), + "uuid"=>CppType.new("string").passcref.retcref.code("ShortString") # FIXME aconway 2007-08-25: Remove, +# "uuid"=>CppType.new("Uuid").passcref.retcref.code, + } + + def cppname() name.caps; end + def cpptype() + d=unalias + @cpptype ||= @@typemap[d.type_] or + CppType.new(d.cppname).passcref.retcref or + raise "Invalid type #{self}" end end -# Additional methos for AmqpRoot -class AmqpRoot - # FIXME aconway 2007-06-20: fix u_int types, should be uint - CppTypeMap={ - "bit"=> ["bool"], - "octet"=>["u_int8_t"], - "short"=>["u_int16_t"], - "long"=>["u_int32_t"], - "longlong"=>["u_int64_t"], - "timestamp"=>["u_int64_t"], - "longstr"=>["string", "const string&"], - "shortstr"=>["string", "const string&"], - "table"=>["FieldTable", "const FieldTable&", "const FieldTable&"], - "content"=>["Content", "const Content&", "const Content&"], - "rfc1982-long-set"=>["SequenceNumberSet", "const SequenceNumberSet&", "const SequenceNumberSet&"], - "long-struct"=>["string", "const string&"], - "uuid"=>["string", "const string&"] # FIXME should be: ["Uuid", "const Uuid&", "const Uuid&"] - } - - def lookup(amqptype) - CppTypeMap[amqptype] or raise "No cpp type for #{amqptype}"; +class AmqpResult + def cpptype() + @cpptype=CppType.new(parent.parent.name.caps+parent.name.caps+"Result").passcref end - - def member_type(amqptype) lookup(amqptype)[0]; end - def param_type(amqptype) t=lookup(amqptype); t[1] or t[0]; end - def return_type(amqptype) t=lookup(amqptype); t[2] or t[0]; end +end + +class AmqpStruct + def cpptype() parent.cpptype; end + def cppname() cpptype.name; end end class CppGen < Generator @@ -197,10 +203,14 @@ class CppGen < Generator scope("{","};") { yield } end - def struct(name, *bases, &block) struct_class("struct", name, bases, &block); end - def cpp_class(name, *bases, &block) struct_class("class", name, bases, &block); end + def struct(name, *bases, &block) + struct_class("struct", name, bases, &block); + end + def cpp_class(name, *bases, &block) + struct_class("class", name, bases, &block); + end - def typedef(type, name) genl "typedef #{type} #{name};\n" end + def typedef(type, name) genl "typedef #{type} #{name};\n"; end def variant(types) "boost::variant<#{types.join(", ")}>"; end def variantl(types) "boost::variant<#{types.join(", \n")}>"; end -- cgit v1.2.1