You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2008/02/27 22:49:05 UTC
svn commit: r631740 - in /incubator/qpid/trunk/qpid/cpp:
rubygen/0-10/amqp_0_10.rb rubygen/0-10/specification.rb rubygen/amqpgen.rb
rubygen/cppgen.rb rubygen/generate src/Makefile.am
src/qpid/amqp_0_10/helpers.h
Author: aconway
Date: Wed Feb 27 13:49:04 2008
New Revision: 631740
URL: http://svn.apache.org/viewvc?rev=631740&view=rev
Log:
Generating domains, structs, commands and controls for 0-10 final spec.
Not yet generating: holders, visitors.
Added:
incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
- copied, changed from r631638, incubator/qpid/trunk/qpid/cpp/rubygen/0-10/amqp_0_10.rb
Removed:
incubator/qpid/trunk/qpid/cpp/rubygen/0-10/amqp_0_10.rb
Modified:
incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb
incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
incubator/qpid/trunk/qpid/cpp/rubygen/generate
incubator/qpid/trunk/qpid/cpp/src/Makefile.am
incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h
Copied: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb (from r631638, incubator/qpid/trunk/qpid/cpp/rubygen/0-10/amqp_0_10.rb)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb?p2=incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb&p1=incubator/qpid/trunk/qpid/cpp/rubygen/0-10/amqp_0_10.rb&r1=631638&r2=631740&rev=631740&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/0-10/amqp_0_10.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb Wed Feb 27 13:49:04 2008
@@ -2,121 +2,104 @@
$: << ".." # Include .. in load path
require 'cppgen'
-class Amqp_0_10 < CppGen
- ArrayTypes={
- "str16-array" => "Str16",
- "amqp-host-array" => "connection::AmqpHostUrl",
- "command-fragments" => "session::CommandFragment",
- "in-doubt" => "dtx::Xid"
- }
-
+class Specification < CppGen
def initialize(outdir, amqp)
super(outdir, amqp)
- @ns="qpid::amqp_0_10"
- @dir="qpid/amqp_0_10"
+ @ns="qpid::amqp_#{@amqp.version.bars}"
+ @dir="qpid/amqp_#{@amqp.version.bars}"
end
# domains
def domain_h(d)
+ genl
typename=d.name.typename
if d.enum
scope("enum #{typename} {", "};") {
- genl d.enum.choices.map { |c| "#{c.name.constname} = #{c.value}" }.join(",\n")
+ genl d.enum.choices.map { |c|
+ "#{c.name.constname} = #{c.value}" }.join(",\n")
}
- elsif d.type_ == "array"
- @array_domains << "typedef Array<#{ArrayTypes[d.name]}> #{typename};\n"
+ elsif (d.type_ == "array")
+ genl "typedef Array<#{ArrayTypes[d.name].amqp2cpp}> #{typename};"
else
genl "typedef #{d.type_.amqp2cpp} #{typename};"
end
end
- # structs
+ # class constants
- # field members and MemberInfo
- def member_h(m)
- genl "static const MemberInfo INFO;"
- m.fields.each { |f| genl "#{f.type_.amqp2cpp} #{f.cppname};" }
- end
-
- # MemberInfo constant definition.
- def member_cpp(m)
- infotype=m.is_a?(AmqpStruct) ? "Struct1Info" : "MemberInfo"
- scope("{infotype} #{m.classname}::INFO = {","};") {
- inits=[]
- inits << (m.parent.is_a?(AmqpClass) ? "&CLASS_INFO" : "0")
- inits << m.name << (m.code or "0");
- if m.is_a?(AmqpStruct)
- inits << (m.size or 0) << (m.pack or 0)
- end
- genl inits.join(", ")
- }
+ def class_h(c)
+ genl "const uint8_t CODE=#{c.code};"
+ genl "extern const char* NAME;"
+ end
+
+ def class_cpp(c)
+ genl "const char* NAME=\"#{c.fqname}\";"
end
- def struct_h(s) struct(s.classname, "public Struct") { member_h s }; end
- def struct_cpp(s) member_cpp s; end
- def gen_structs()
- file="#{@dir}/structs"
- h_file(file) {
- include "#{@dir}/built_in_types.h"
- include "#{@dir}/helpers.h"
- include "<boost/call_traits.hpp>"
- genl "using boost::call_traits;"
- namespace(@ns) {
- @amqp.structs.each { |s| struct_h s }
- each_class_ns { |c| c.structs.each { |s| struct_h s }}
- }
+ # Used by structs, commands and controls.
+ def action_struct_h(x, base, consts, &block)
+ genl
+ struct(x.classname, "public #{base}") {
+ x.fields.each { |f| genl "#{f.type_.amqp2cpp} #{f.cppname};" }
+ genl
+ genl "static const char* NAME;"
+ consts.each { |c| genl "static const uint8_t #{c.upcase}=#{x.send c or 0};"}
+ genl "static const uint8_t CLASS_CODE=#{x.containing_class.nsname}::CODE;"
+ genl
+ genl "#{x.classname}();"
+ scope("#{x.classname}(",");") { genl x.parameters } unless x.fields.empty?
+ genl
+ genl "void accept(Visitor&) const;"
+ genl
+ yield if block
}
- cpp_file(file) {
- include file
- namespace(@ns) {
- @amqp.structs.each { |s| struct_h s }
- each_class_ns { |c| c.structs.each { |s| struct_cpp s }}
- }
+ end
+
+ def action_struct_cpp(x)
+ genl
+ genl "const char* #{x.classname}::NAME=\"#{x.fqname}\";"
+ genl
+ genl "#{x.classname}::#{x.classname}() {}";
+ genl
+ if not x.fields.empty?
+ scope("#{x.classname}::#{x.classname}(",") :") { genl x.parameters }
+ indent() { genl x.initializers }
+ genl "{}"
+ genl
+ end
+ scope("void #{x.classname}::accept(Visitor&) const {","}") {
+ genl "// FIXME aconway 2008-02-27: todo"
}
end
+ # structs
+
+ def struct_h(s) action_struct_h(s, "Struct", ["size","pack","code"]); end
+ def struct_cpp(s) action_struct_cpp(s) end
+
# command and control
- def action_h(a)
- name=a.name.typename
- struct(name, "public #{a.base}") {
- genl "#{name}() {}"
- scope("#{name}(",");") { genl a.parameters } unless a.fields.empty?
+ def action_h(a)
+ action_struct_h(a, a.base, ["code"]) {
scope("template <class T> void invoke(T& target) {","}") {
scope("target.#{a.funcname}(", ");") { genl a.values }
}
+ genl
scope("template <class S> void serialize(S& s) {","}") {
gen "s"
a.fields.each { |f| gen "(#{f.cppname})"}
genl ";"
} unless a.fields.empty?
- member_h a
}
end
- def action_cpp(a) # command or control
- # ctor
- scope("#{a.classname}::#{a.classname}(",") :") { genl a.parameters }
- indent() { genl a.initializers }
- genl "{}"
- # member constants
- member_cpp a
- end
-
- def class_h(c)
- genl "extern const ClassInfo CLASS_INFO;"
- @array_domains=""
- c.domains.each { |d| domain_h d }
- c.structs.each { |s| struct_h s }
- gen @array_domains
- end
+ def action_cpp(a) action_struct_cpp(a); end
- def class_cpp(c)
- genl "const ClassInfo CLASS_INFO = { #{c.code}, \"#{c.name}\" };"
- c.structs.each { |s| struct_cpp s }
- end
+ # Types that must be generated early because they are used by other types.
+ def pregenerate?(x) not @amqp.used_by[x.fqname].empty?; end
+ # Generate the log
def gen_specification()
h_file("#{@dir}/specification") {
include "#{@dir}/built_in_types"
@@ -124,17 +107,36 @@
include "<boost/call_traits.hpp>"
genl "using boost::call_traits;"
namespace(@ns) {
- # We don't generate top-level domains, as they have clashing values.
- each_class_ns { |c| class_h c }
- each_class_ns { |c| c.actions.each { |a| action_h a}
+ # Top level
+ @amqp.domains.each { |d|
+ # segment-type and track are are built in
+ domain_h d unless ["track","segment-type"].include?(d.name)
+ }
+ puts @amqp.used_by.inspect
+
+ # Domains and structs that must be generated early because
+ # they are used by other definitions:
+ each_class_ns { |c|
+ class_h c
+ c.domains.each { |d| domain_h d if pregenerate? d }
+ c.structs.each { |s| struct_h s if pregenerate? s }
+ }
+ # Now dependent domains/structs and actions
+ each_class_ns { |c|
+ c.domains.each { |d| domain_h d if not pregenerate? d }
+ c.structs.each { |s| struct_h s if not pregenerate? s }
+ c.actions.each { |a| action_h a }
}
}
}
+
cpp_file("#{@dir}/specification") {
include "#{@dir}/specification"
namespace(@ns) {
- each_class_ns { |c| class_cpp c }
- each_class_ns { |c| c.actions.each { |a| action_cpp a}
+ each_class_ns { |c|
+ class_cpp c
+ c.actions.each { |a| action_cpp a}
+ c.structs.each { |s| struct_cpp s }
}
}
}
@@ -171,5 +173,5 @@
end
end
-Amqp_0_10.new($outdir, $amqp).generate();
+Specification.new($outdir, $amqp).generate();
Modified: incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb?rev=631740&r1=631739&r2=631740&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb Wed Feb 27 13:49:04 2008
@@ -152,10 +152,21 @@
# Text of doc child if there is one.
def doc() d=xml.elements["doc"]; d and d.text; end
+ def fqname()
+ throw "fqname: #{self} #{parent.fqname} has no name" unless name
+ p=parent && parent.fqname
+ p ? p+"."+name : name;
+ end
+
+ def containing_class()
+ return self if is_a? AmqpClass
+ return parent && parent.containing_class
+ end
+
end
class AmqpResponse < AmqpElement
- def initialize(xml, parent) super; end
+ def initialize(xml, parent) super; end
end
class AmqpDoc < AmqpElement
@@ -167,18 +178,32 @@
def initialize(xml,parent) super; end
amqp_attr_reader :name, :value
end
-
+
class AmqpEnum < AmqpElement
def initialize(xml,parent) super; end
amqp_child_reader :choice
end
+# 0-10 array domains are missing element type information, add it here.
+ArrayTypes={
+ "str16-array" => "str-16",
+ "amqp-host-array" => "connection.amqp-host-url",
+ "command-fragments" => "session.command-fragment",
+ "in-doubt" => "dtx.xid"
+}
+
class AmqpDomain < AmqpElement
- def initialize(xml, parent) super; end
+ def initialize(xml, parent)
+ super
+ root.used_by[uses].push(fqname) if uses and uses.index('.')
+ end
+
amqp_attr_reader :type
amqp_single_child_reader :struct # preview
amqp_single_child_reader :enum
+ def uses() type_=="array" ? ArrayTypes[name] : type_; end
+
def unalias()
d=self
while (d.type_ != d.name and root.domain(d.type_))
@@ -194,7 +219,11 @@
end
class AmqpField < AmqpElement
- def initialize(xml, amqp) super; end;
+ def initialize(xml, amqp)
+ super;
+ root.used_by[type_].push(parent.fqname) if type_ and type_.index('.')
+ end
+
def domain() root.domain(xml.attributes["domain"]); end
amqp_single_child_reader :struct # preview
amqp_child_reader :exception
@@ -215,6 +244,7 @@
def initialize(xml, parent) super; end
amqp_single_child_reader :struct # preview
amqp_attr_reader :type
+ def name() "result"; end
end
class AmqpEntry < AmqpElement
@@ -333,16 +363,16 @@
raise "No XML spec files." if specs.empty?
xml=parse(specs.shift)
specs.each { |s| xml_merge(xml, parse(s)) }
+ @used_by=Hash.new{ |h,k| h[k]=[] }
super(xml, nil)
end
+ attr_reader :used_by
+
def merge(root) xml_merge(xml, root.xml); end
def version() major + "-" + minor; end
- # Find the element corresponding to an amqp dotted name.
- def lookup(dotted_name) xml.elements[dotted_name.gsub(/\./,"/")]; end
-
# preview - only struct child reader remains for new mapping
def domain_structs() domains.map{ |d| d.struct }.compact; end
def result_structs()
@@ -358,6 +388,8 @@
@methods_on[chassis] ||= classes.map { |c| c.methods_on(chassis) }.flatten
end
+ def fqname() nil; end
+
# TODO aconway 2008-02-21: methods by role.
private
@@ -390,7 +422,7 @@
@prefix=[''] # For indentation or comments.
@indentstr=' ' # One indent level.
@outdent=2
- Pathname.new(@outdir).mkpath unless @outdir=="-" or File.directory?(@outdir)
+ Pathname.new(@outdir).mkpath unless @outdir=="-"
end
# Create a new file, set @out.
Modified: incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb?rev=631740&r1=631739&r2=631740&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb Wed Feb 27 13:49:04 2008
@@ -61,7 +61,7 @@
name=path.pop
return name.typename if path.empty?
path.map! { |n| n.nsname }
- return "amqp_0_10::"+(path << name.caps).join("::")
+ return (path << name.caps).join("::")
end
alias :typename :caps
@@ -137,12 +137,8 @@
def body_name() parent.name.caps+name.caps+"Body"; end
end
-class AmqpAction
- def nsname() name.namespace; end
- def classname() name.typename; end
- def funcname() parent.name.funcname + name.caps; end
-
- def parameters()
+module AmqpHasFields
+ def parameters()
fields.map { |f| "#{f.paramtype} #{f.cppname}_"}.join(",\n")
end
@@ -155,21 +151,26 @@
end
def initializers()
- fields.map { |f| "#{f.cppname}(#{f.cppname}_)}"}.join(",\n")
+ fields.map { |f| "#{f.cppname}(#{f.cppname}_)"}.join(",\n")
end
+end
+class AmqpAction
+ def classname() name.typename; end
+ def funcname() parent.name.funcname + name.caps; end
+ include AmqpHasFields
end
-class AmqpCommand
+class AmqpCommand < AmqpAction
def base() "Command"; end
end
-class AmqpControl
+class AmqpControl < AmqpAction
def base() "Control"; end
end
class AmqpClass
- def cppname() name.caps; end
+ def cppname() name.caps; end # preview
def nsname() name.nsname; end
end
@@ -212,9 +213,14 @@
end
class AmqpStruct
- def cpp_pack_type() AmqpDomain.lookup_type(pack()) or CppType.new("uint16_t"); end
+ include AmqpHasFields
+
+ def cpp_pack_type() # preview
+ AmqpDomain.lookup_type(pack()) or CppType.new("uint16_t");
+ end
def cpptype() parent.cpptype; end # preview
def cppname() cpptype.name; end # preview
+
def classname() name.typename; end
end
Modified: incubator/qpid/trunk/qpid/cpp/rubygen/generate
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/generate?rev=631740&r1=631739&r2=631740&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/generate (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/generate Wed Feb 27 13:49:04 2008
@@ -74,7 +74,7 @@
rgen_client_cpp=#{make_continue(rgen_srcs.grep(%r|/qpid/client/.+\.cpp$|))}
-rgen_common_cpp=#{make_continue(rgen_srcs.grep(%r|qpid/framing/.+\.cpp$|))}
+rgen_common_cpp=#{make_continue(rgen_srcs.grep(%r{qpid/(framing|amqp_.+)/.+\.cpp$}))}
rgen_srcs=#{make_continue rgen_srcs}
Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=631740&r1=631739&r2=631740&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Wed Feb 27 13:49:04 2008
@@ -103,6 +103,7 @@
libqpidcommon_la_SOURCES = \
$(rgen_common_cpp) \
$(platform_src) \
+ qpid/amqp_0_10/helpers.cpp \
qpid/Serializer.h \
qpid/amqp_0_10/built_in_types.h \
qpid/amqp_0_10/Codec.h \
@@ -251,6 +252,7 @@
nobase_include_HEADERS = \
$(platform_hdr) \
+ qpid/amqp_0_10/helpers.h \
qpid/assert.h \
qpid/DataDir.h \
qpid/Exception.h \
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h?rev=631740&r1=631739&r2=631740&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h Wed Feb 27 13:49:04 2008
@@ -27,46 +27,28 @@
namespace amqp_0_10 {
-/** Static information about an AMQP class */
-struct ClassInfo { uint8_t code; const char* name; };
-
-/** Info about a class memeber - command, control or struct */
-struct MemberInfo {
- ClassInfo* class_; // 0 for top level struct.
-
- const char* name;
- uint8_t code;
- std::string fullName() const {
- return std::string(class_->name)+"."+name;
- }
-};
-
-/** Info about a struct */
-struct StructInfo : public MemberInfo { uint8_t size, pack; };
-
-// Look up info by code.
-const ClassInfo& getClassInfo(uint8_t code);
-const MemberInfo& getCommandInfo(uint8_t classCode, uint8_t code);
-const MemberInfo& getControlInfo(uint8_t classCode, uint8_t code);
-const StructInfo& getStructInfo(uint8_t classCode, uint8_t code);
+// Look up names by code
+const char* getClassName(uint8_t code);
+const char* getCommandName(uint8_t classCode, uint8_t code);
+const char* getControlName(uint8_t classCode, uint8_t code);
+const char* getStructName(uint8_t classCode, uint8_t code);
struct Command {
virtual ~Command();
class Visitor;
- virtual const MemberInfo& info() const = 0;
virtual void accept(Visitor&) const = 0;
};
struct Control {
virtual ~Control();
class Visitor;
- virtual const MemberInfo& info() const = 0;
virtual void accept(Visitor&) const = 0;
};
struct Struct {
virtual ~Struct();
- virtual const StructInfo& info() const = 0;
+ class Visitor;
+ virtual void accept(Visitor&) const = 0;
};
/** Base class for generated enum domains.