summaryrefslogtreecommitdiff
path: root/cpp/rubygen/0-10
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-02-27 21:49:04 +0000
committerAlan Conway <aconway@apache.org>2008-02-27 21:49:04 +0000
commit6bf200b4a953e3e7ae521c1e269e420af7e52cba (patch)
treef9cbe87cb8c85f6fc902d1d2874139257c4ef6f9 /cpp/rubygen/0-10
parent12ea725d2b2cd95e9a8ef5f4b4511e841054b628 (diff)
downloadqpid-python-6bf200b4a953e3e7ae521c1e269e420af7e52cba.tar.gz
Generating domains, structs, commands and controls for 0-10 final spec.
Not yet generating: holders, visitors. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@631740 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen/0-10')
-rwxr-xr-xcpp/rubygen/0-10/amqp_0_10.rb175
-rwxr-xr-xcpp/rubygen/0-10/specification.rb177
2 files changed, 177 insertions, 175 deletions
diff --git a/cpp/rubygen/0-10/amqp_0_10.rb b/cpp/rubygen/0-10/amqp_0_10.rb
deleted file mode 100755
index 985d275668..0000000000
--- a/cpp/rubygen/0-10/amqp_0_10.rb
+++ /dev/null
@@ -1,175 +0,0 @@
-#!/usr/bin/env ruby
-$: << ".." # 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"
- }
-
- def initialize(outdir, amqp)
- super(outdir, amqp)
- @ns="qpid::amqp_0_10"
- @dir="qpid/amqp_0_10"
- end
-
- # domains
-
- def domain_h(d)
- typename=d.name.typename
- if d.enum
- scope("enum #{typename} {", "};") {
- 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"
- else
- genl "typedef #{d.type_.amqp2cpp} #{typename};"
- end
- end
-
- # structs
-
- # 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(", ")
- }
- 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 }}
- }
- }
- 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
-
- # 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?
- scope("template <class T> void invoke(T& target) {","}") {
- scope("target.#{a.funcname}(", ");") { genl a.values }
- }
- 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 class_cpp(c)
- genl "const ClassInfo CLASS_INFO = { #{c.code}, \"#{c.name}\" };"
- c.structs.each { |s| struct_cpp s }
- end
-
- def gen_specification()
- h_file("#{@dir}/specification") {
- include "#{@dir}/built_in_types"
- include "#{@dir}/helpers"
- 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}
- }
- }
- }
- 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}
- }
- }
- }
- end
-
- def gen_proxy()
- h_file("#{@dir}/Proxy.h") {
- include "#{@dir}/specification"
- namespace(@ns) {
- genl "template <class F, class R=F::result_type>"
- cpp_class("ProxyTemplate") {
- public
- genl "ProxyTemplate(F f) : functor(f) {}"
- @amqp.classes.each { |c|
- c.actions.each { |a|
- scope("R #{a.funcname}(", ")") { genl a.parameters }
- scope() {
- var=a.name.funcname
- scope("#{a.classname} #{var}(",");") { genl a.arguments }
- genl "return functor(#{var});"
- }
- }
- }
- private
- genl "F functor;"
- }
- }
- }
- end
-
- def generate
- gen_specification
- gen_proxy
- end
-end
-
-Amqp_0_10.new($outdir, $amqp).generate();
-
diff --git a/cpp/rubygen/0-10/specification.rb b/cpp/rubygen/0-10/specification.rb
new file mode 100755
index 0000000000..026b49e1a9
--- /dev/null
+++ b/cpp/rubygen/0-10/specification.rb
@@ -0,0 +1,177 @@
+#!/usr/bin/env ruby
+$: << ".." # Include .. in load path
+require 'cppgen'
+
+class Specification < CppGen
+ def initialize(outdir, amqp)
+ super(outdir, amqp)
+ @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")
+ }
+ elsif (d.type_ == "array")
+ genl "typedef Array<#{ArrayTypes[d.name].amqp2cpp}> #{typename};"
+ else
+ genl "typedef #{d.type_.amqp2cpp} #{typename};"
+ end
+ end
+
+ # class constants
+
+ 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
+
+ # 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
+ }
+ 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)
+ 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?
+ }
+ end
+
+ def action_cpp(a) action_struct_cpp(a); 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"
+ include "#{@dir}/helpers"
+ include "<boost/call_traits.hpp>"
+ genl "using boost::call_traits;"
+ namespace(@ns) {
+ # 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
+ c.actions.each { |a| action_cpp a}
+ c.structs.each { |s| struct_cpp s }
+ }
+ }
+ }
+ end
+
+ def gen_proxy()
+ h_file("#{@dir}/Proxy.h") {
+ include "#{@dir}/specification"
+ namespace(@ns) {
+ genl "template <class F, class R=F::result_type>"
+ cpp_class("ProxyTemplate") {
+ public
+ genl "ProxyTemplate(F f) : functor(f) {}"
+ @amqp.classes.each { |c|
+ c.actions.each { |a|
+ scope("R #{a.funcname}(", ")") { genl a.parameters }
+ scope() {
+ var=a.name.funcname
+ scope("#{a.classname} #{var}(",");") { genl a.arguments }
+ genl "return functor(#{var});"
+ }
+ }
+ }
+ private
+ genl "F functor;"
+ }
+ }
+ }
+ end
+
+ def generate
+ gen_specification
+ gen_proxy
+ end
+end
+
+Specification.new($outdir, $amqp).generate();
+