diff options
author | Alan Conway <aconway@apache.org> | 2007-08-01 16:50:33 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-08-01 16:50:33 +0000 |
commit | 28b22a308cb6cf0232067636fb6676a4c96d82f7 (patch) | |
tree | 1f5b4cd32c425ffda3a7295dd47f0aaba3c0ce25 /cpp/rubygen | |
parent | 9235b5d09b3273c7c495ff266e18781fad363a9b (diff) | |
download | qpid-python-28b22a308cb6cf0232067636fb6676a4c96d82f7.tar.gz |
* src/generate.sh: Moved requirements test to configure.ac
* rubygen: Cleanup and improvements, template for cluster work.
* configure.ac:
- support for ruby code generator + cleanup.
- moved "can generate" tests to configure.ac
- removed redundant APR stuff.
* bootstrap: Remove codegen from bootstrap, all in config/make.
* src/Makefile.am (libqpidcommon_la_LIBADD):
- Ruby code generator.
- Improvements to existing generator rules.
- Removed APR stuff.
* configure.ac (CPPUNIT_CXXFLAGS): Removed APR stuff.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@561869 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/rubygen')
-rw-r--r-- | cpp/rubygen/README | 13 | ||||
-rwxr-xr-x | cpp/rubygen/amqpgen.rb | 15 | ||||
-rwxr-xr-x | cpp/rubygen/cppgen.rb | 25 | ||||
-rwxr-xr-x | cpp/rubygen/generate | 23 | ||||
-rw-r--r-- | cpp/rubygen/templates/frame_body_lists.rb | 31 |
5 files changed, 95 insertions, 12 deletions
diff --git a/cpp/rubygen/README b/cpp/rubygen/README index 43111d4c4f..a1fd6cfec8 100644 --- a/cpp/rubygen/README +++ b/cpp/rubygen/README @@ -1,16 +1,13 @@ RUBY CODE GENERATOR -amqpgen.rb: builds an AMQP model from XML files and provides generic code generation functions (e.g. capitalization of names etc) +Run ./generate for usage. +Examples in samples/ -cppgen.rb: C++ specific code generation functions. +For example: + ./generate . ../../specs/amqp.0-9.xml samples/Proxy.rb +will generate -A template is a ruby file that generates one or more source files. -For an example run - samples/runme test <amqp.xml files> - -The first argument is a directory for generated files, remaining arguments -are xml files. diff --git a/cpp/rubygen/amqpgen.rb b/cpp/rubygen/amqpgen.rb index 3fc66525d8..1bd11848a6 100755 --- a/cpp/rubygen/amqpgen.rb +++ b/cpp/rubygen/amqpgen.rb @@ -135,12 +135,13 @@ class AmqpRoot < AmqpElement def classes() @cache_classes ||= elements.collect("class") { |c| AmqpClass.new(c,self) }.sort_by_name end - + + # Return all methods on all classes. + def methods() classes.collect { |c| c.methods }.flatten; end + # Return all methods on chassis for all classes. def methods_on(chassis) - classes.collect { |c| - c.methods_on(chassis) - }.flatten + classes.collect { |c| c.methods_on(chassis) }.flatten end # Merge contents of elements. @@ -190,6 +191,12 @@ class Generator @midline = /[^\n]\z/ === str end + # Append str + '\n' to generated code. + def genl(str="") + gen str + gen "\n" + end + # Generate code with added prefix. def prefix(add) save=@prefix diff --git a/cpp/rubygen/cppgen.rb b/cpp/rubygen/cppgen.rb index 3e3800c4cd..b5f4758411 100755 --- a/cpp/rubygen/cppgen.rb +++ b/cpp/rubygen/cppgen.rb @@ -105,6 +105,7 @@ class CppGen < Generator # Write a header file. def h_file(path) + path = (/\.h$/ === path ? path : path+".h") guard=path.upcase.tr('./-','_') file(path) { gen "#ifndef #{guard}\n" @@ -122,5 +123,29 @@ class CppGen < Generator yield end end + + def include(header) genl "#include \"#{header}\""; end + + def scope(open="{",close="}", &block) + genl open; indent(&block); genl close + end + + def namespace(name, &block) + names = name.split("::") + names.each { |n| genl "namespace #{n} {" } + yield + genl('}'*names.size+" // "+name) + end + + def struct_class(type, name, *bases, &block) + gen "#{type} #{name}" + gen ": #{bases.join(', ')}" unless bases.empty + genl "{" + yield + genl "};" + end + + def struct(name, *bases, &block) struc_class("struct", bases, &block); end + def class_(name, *bases, &block) struc_class("struct", bases, &block); end end diff --git a/cpp/rubygen/generate b/cpp/rubygen/generate new file mode 100755 index 0000000000..09b27211af --- /dev/null +++ b/cpp/rubygen/generate @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby +require 'amqpgen' + +# +# Run a set of code generation templates. +# + +if ARGV.size < 3 + puts <<EOS +Usage: #{ARGV[0]} OUTDIR SPEC.xml [ ... ] TEMPLATE.rb [ ... ] +Parse all SPEC.xml files to create an AMQP model, run each TEMPLATE +putting the resulting files under OUTDIR. Prints a list of files +generated to standard output. + +If OUTDIR is '-' then just prints file list without generating files. +EOS + exit 1 +end +outdir=ARGV[0] +specs=ARGV.grep(/\.xml$/) +templates=ARGV.grep(/\.rb$/) +Amqp=AmqpRoot.new(*specs) +templates.each { |t| require t } diff --git a/cpp/rubygen/templates/frame_body_lists.rb b/cpp/rubygen/templates/frame_body_lists.rb new file mode 100644 index 0000000000..33c416fe84 --- /dev/null +++ b/cpp/rubygen/templates/frame_body_lists.rb @@ -0,0 +1,31 @@ +$: << ".." # Include .. in load path +require 'cppgen' + +class FrameBodyListsGen < CppGen + + def initialize(outdir, amqp) + super(outdir, amqp); + end + + def generate + h_file("qpid/framing/frame_body_lists.h") { + gen <<EOS +/**@file + * Macro lists of frame body classes, used to generate Visitors + */ +EOS + gen "#define METHOD_BODIES() " + @amqp.methods.each { |m| gen "\\\n (#{m.body_name}) " } + gen <<EOS + + +#define OTHER_BODIES() (AMQContentBody)(AMQHeaderBody)(AMQHeartbeatBody)) + +EOS + } + end +end + +FrameBodyListsGen.new(ARGV[0], Amqp).generate; + + |