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/23 00:13:47 UTC

svn commit: r630353 - in /incubator/qpid/trunk/qpid/cpp: rubygen/amqpgen.rb rubygen/cppgen.rb rubygen/generate rubygen/templates/amqp_0_10.rb src/qpid/amqp_0_10/helpers.h src/qpid/amqp_0_10/visitors.h src/qpid/client/Session.h

Author: aconway
Date: Fri Feb 22 15:13:43 2008
New Revision: 630353

URL: http://svn.apache.org/viewvc?rev=630353&view=rev
Log:

Fixed rubygen to skip unchanged generated files, prevents needless
rebuilding every time the code generator changes.

Start of amqp 0-10 mapping, work in progress.

Added:
    incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h   (with props)
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/qpid/client/Session.h

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb?rev=630353&r1=630352&r2=630353&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/amqpgen.rb Fri Feb 22 15:13:43 2008
@@ -127,6 +127,9 @@
     @cache_child[[elname,name]] ||= children(elname).find { |c| c.name==name }
   end
 
+  # Fully qualified amqp dotted name of this element
+  def dotted_name() (parent ? parent.dotted_name+"." : "") + name; end
+
   # The root <amqp> element.
   def root() @root ||=parent ? parent.root : self; end
 
@@ -142,7 +145,9 @@
 
 end
 
-AmqpResponse = AmqpElement
+class AmqpResponse < AmqpElement
+   def initialize(xml, parent) super; end
+end
 
 class AmqpDoc < AmqpElement
   def initialize(xml,parent) super; end
@@ -183,7 +188,6 @@
   def initialize(xml, amqp) super; end;
   def domain() root.domain(xml.attributes["domain"]); end
   amqp_single_child_reader :struct # preview
-  # FIXME aconway 2008-02-21: exceptions in fields - need to update c++ mapping.
   amqp_child_reader :exception
   amqp_attr_reader :type, :default, :code, :required
 end
@@ -198,11 +202,6 @@
   amqp_attr_reader :value, :class
 end
 
-# FIXME aconway 2008-02-21: 
-# class AmqpResponse < AmqpElement
-#   def initialize(xml, parent) super; end
-# end
-
 class AmqpResult < AmqpElement
   def initialize(xml, parent) super; end
   amqp_single_child_reader :struct # preview
@@ -236,8 +235,8 @@
   amqp_attr_reader :size, :code, :pack 
   amqp_child_reader :field
 
-  alias :raw_pack :pack
   # preview - preview code needs default "short" for pack.
+  alias :raw_pack :pack
   def pack() raw_pack or (not parent.final? and "short"); end 
   def result?() parent.xml.name == "result"; end
   def domain?() parent.xml.name == "domain"; end
@@ -299,9 +298,14 @@
 end
 
 class AmqpType < AmqpElement
+  def initialize(xml,amqp) super; end
   amqp_attr_reader :code, :fixed_width, :variable_width
 end
 
+class AmqpXref < AmqpElement
+  def initialize(xml,amqp) super; end
+end
+
 # AMQP root element.
 class AmqpRoot < AmqpElement
   amqp_attr_reader :major, :minor, :port, :comment
@@ -319,9 +323,9 @@
 
   def version() major + "-" + minor; end
 
-  # Find a child node from a dotted amqp name, e.g. message.transfer
-  def lookup(dotted_name) elements[dotted_name.gsub(/\./,"/")]; 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()
@@ -353,7 +357,7 @@
 # Collect information about generated files.
 class GenFiles
   @@files =[]
-  def GenFiles.add(f) @@files << f; puts f; end
+  def GenFiles.add(f) @@files << f; end
   def GenFiles.get() @@files; end
 end
 
@@ -378,7 +382,14 @@
     if (@outdir != "-")         
       path=Pathname.new "#{@outdir}/#{file}"
       path.parent.mkpath
-      path.open('w') { |@out| yield }
+      @out=String.new           # Generate in memory first
+      yield                     # Generate to @out
+      if path.exist? and path.read == @out  
+        puts "Skipped #{path} - unchanged" # Dont generate if unchanged
+      else
+        path.open('w') { |f| f << @out }
+        puts "Generated #{path}"
+      end
     end
   end
 

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb?rev=630353&r1=630352&r2=630353&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb Fri Feb 22 15:13:43 2008
@@ -54,12 +54,23 @@
 CppMangle = CppKeywords+Set.new(["string"])
 
 class String
-  def cppsafe()
-    CppMangle.include?(self) ? self+"_" : self
+  def cppsafe() CppMangle.include?(self) ? self+"_" : self; end
+  def amqp2cpp()
+    path=split(".")
+    name=path.pop
+    path.map! { |n| n.bars }
+    (path << name.caps).join("::")
   end
 end
 
 # Hold information about a C++ type.
+# 
+# preview - new mapping does not use CppType,
+# Each amqp type corresponds exactly by dotted name
+# to a type, domain or struct, which in turns
+# corresponds by name to a C++ type or typedef.
+# (see String.amqp2cpp)
+# 
 class CppType
   def initialize(name) @name=@param=@ret=name; end
   attr_reader :name, :param, :ret, :code
@@ -93,6 +104,16 @@
   def to_s() name; end;
 end
 
+class AmqpElement
+  def cppfqname()
+    names=parent.dotted_name.split(".")
+    # Field children are moved up to method in C++b
+    prefix.pop if parent.is_a? AmqpField
+    prefix.push cppname
+    prefix.join("::")
+  end
+end
+  
 class AmqpField
   def cppname() name.lcaps.cppsafe; end
   def cpptype() domain.cpptype;  end

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/generate
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/generate?rev=630353&r1=630352&r2=630353&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/generate (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/generate Fri Feb 22 15:13:43 2008
@@ -69,7 +69,7 @@
     }
     out << <<EOS
 if GENERATE
-$(rgen_srcs) $(srcdir)/#{File.basename makefile}: $(rgen_generator) $(specs)
+$(srcdir)/#{File.basename makefile}: $(rgen_generator) $(specs)
 	$(rgen_cmd)
 
 # Empty rule in case a generator file is renamed/removed.

Added: incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb?rev=630353&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb (added)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb Fri Feb 22 15:13:43 2008
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby
+$: << ".."                      # Include .. in load path
+require 'cppgen'
+
+class Amqp_0_10 < CppGen
+  
+  def initialize(outdir, amqp)
+    super(outdir, amqp)
+    @namespace="qpid::amqp_0_10"
+    @filename="qpid/amqp_0_10"
+  end
+
+  def action_h(a, base)
+    struct(a.cppname, "public #{base}") {
+      genl "static const uint8_t CODE=#{a.code};"
+      a.fields.each { |f|
+        genl "#{(f.type_.amqp2cpp)} #{f.cppname};"
+      }
+    }
+  end
+
+  def action_cpp(a, base)
+    
+  end
+
+  def gen_amqp_0_10_h
+    h_file("#{@filename}.h") { 
+      namespace(@namespace) {
+        @amqp.classes.each { |cl|
+          namespace(cl.cppname) { 
+            struct("ClassInfo") {
+              genl "static const uint8_t CODE=#{cl.code};"
+              genl "static const char* NAME;"
+            }
+            cl.commands.each { |c| action_h c, "Command"}
+            cl.controls.each { |c| action_h c, "Control"}
+          }
+        }
+      }
+    }
+  end
+
+  def gen_amqp_0_10_cpp
+    cpp_file("#{@filename}.cpp") { 
+      include @filename
+
+      namespace(@namespace) {
+        @amqp.classes.each { |cl|
+          namespace(cl.cppname) {
+            genl "static const char* ClassInfo::NAME=\"#{cl.name};"
+          }
+        }
+      }
+    }
+  end
+
+  def generate
+    gen_amqp_0_10_h
+    gen_amqp_0_10_cpp
+  end
+end
+
+Amqp_0_10.new(Outdir, Amqp).generate();
+

Propchange: incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/rubygen/templates/amqp_0_10.rb
------------------------------------------------------------------------------
    svn:executable = *

Added: 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=630353&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h Fri Feb 22 15:13:43 2008
@@ -0,0 +1,70 @@
+#ifndef QPID_AMQP_0_10_HELPERS_H
+#define QPID_AMQP_0_10_HELPERS_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include <string>
+
+namespace qpid {
+
+namespace amqp_0_10 {
+
+struct ClassAttributes { uint8_t code; const char* name };
+
+struct MemberAttributes {
+    ClassAttributes class_;
+    const char* name
+    uint8_t code;
+
+    std::string fullName() const {
+        return std::string(class_.name)+"."+name;
+    }
+};
+
+struct StructAttributes : public MemberAttributes { uint8_t size, pack; };
+
+static const ClassAttributes getClass(uint8_t code);
+static const MemberAttributes getCommand(uint8_t classCode, uint8_t code);
+static const MemberAttributes getControl(uint8_t classCode, uint8_t code);
+
+struct Command : public Member {
+    class Visitor;
+    virtual const MemberAttributes& attributes() const = 0;
+    virtual void accept(Visitor&) const = 0;
+};
+
+struct Control : public Member {
+    class Visitor;
+    struct Attributes { uint8_t classCode, code };
+
+    virtual const MemberAttributes& attributes() const = 0;
+    virtual void accept(Visitor&) const = 0;
+};
+
+
+struct Struct : public Member {
+    virtual const StructAttributes&  attributes() const = 0;
+};
+
+
+}} // namespace qpid::amqp_0_10
+
+#endif  /*!QPID_AMQP_0_10_HELPERS_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/helpers.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h?rev=630353&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h Fri Feb 22 15:13:43 2008
@@ -0,0 +1,15 @@
+// Visitors
+template <class Base> struct Visitor;
+template <class Base, class F, class R> FunctorVisitor;
+
+/** Template base implementation for visitables. */
+template <class Base, class Derived>
+struct VisitableBase : public Base {
+    virtual void accept(Visitor<Derived>& v) {
+        v.visit(static_cast<Derived>&(*this));
+    }
+    virtual void accept(Visitor<Derived>& v) const {
+        v.visit(static_cast<const Derived>&(*this));
+    }
+};
+

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/visitors.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h?rev=630353&r1=630352&r2=630353&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h Fri Feb 22 15:13:43 2008
@@ -27,7 +27,7 @@
 namespace client {
 
 /**
- * Session is currently just an alias for Session_0_10
+ * Session is currently just an alias for Session_99_0
  *
  * \ingroup clientapi
  */