summaryrefslogtreecommitdiff
path: root/codegen.py
diff options
context:
space:
mode:
Diffstat (limited to 'codegen.py')
-rw-r--r--codegen.py61
1 files changed, 58 insertions, 3 deletions
diff --git a/codegen.py b/codegen.py
index 84741ea2..6f39574f 100644
--- a/codegen.py
+++ b/codegen.py
@@ -92,6 +92,40 @@ class PackedMethodBitField:
def full(self):
return self.count() == 8
+
+def printFileHeader():
+ print """%% Autogenerated code. Do not edit.
+%%
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (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.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+%% License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developers of the Original Code are LShift Ltd,
+%% Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
+%%
+%% Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
+%% Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
+%% are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
+%% Technologies LLC, and Rabbit Technologies Ltd.
+%%
+%% Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
+%% Ltd. Portions created by Cohesive Financial Technologies LLC are
+%% Copyright (C) 2007-2009 Cohesive Financial Technologies
+%% LLC. Portions created by Rabbit Technologies Ltd are Copyright
+%% (C) 2007-2009 Rabbit Technologies Ltd.
+%%
+%% All Rights Reserved.
+%%
+%% Contributor(s): ______________________________________.
+%%"""
def genErl(spec):
def erlType(domain):
@@ -117,6 +151,13 @@ def genErl(spec):
def genMethodHasContent(m):
print "method_has_content(%s) -> %s;" % (m.erlangName(), str(m.hasContent).lower())
+
+ def genMethodIsSynchronous(m):
+ hasNoWait = "nowait" in fieldNameList(m.arguments)
+ if m.isSynchronous and hasNoWait:
+ print "is_method_synchronous(#%s{nowait = NoWait}) -> not(NoWait);" % (m.erlangName())
+ else:
+ print "is_method_synchronous(#%s{}) -> %s;" % (m.erlangName(), str(m.isSynchronous).lower())
def genMethodFieldTypes(m):
"""Not currently used - may be useful in future?"""
@@ -221,12 +262,12 @@ def genErl(spec):
print " rabbit_binary_generator:encode_properties(%s, %s);" % \
(fieldTypeList(c.fields), fieldTempList(c.fields))
- def massageConstantClass(cls):
+ def messageConstantClass(cls):
# We do this because 0.8 uses "soft error" and 8.1 uses "soft-error".
return erlangConstantName(cls)
def genLookupException(c,v,cls):
- mCls = massageConstantClass(cls)
+ mCls = messageConstantClass(cls)
if mCls == 'SOFT_ERROR': genLookupException1(c,'false')
elif mCls == 'HARD_ERROR': genLookupException1(c, 'true')
elif mCls == '': pass
@@ -237,8 +278,14 @@ def genErl(spec):
print 'lookup_amqp_exception(%s) -> {%s, ?%s, <<"%s">>};' % \
(n.lower(), hardErrorBoolStr, n, n)
+ def genAmqpException(c,v,cls):
+ n = erlangConstantName(c)
+ print 'amqp_exception(?%s) -> %s;' % \
+ (n, n.lower())
+
methods = spec.allMethods()
+ printFileHeader()
print """-module(rabbit_framing).
-include("rabbit_framing.hrl").
@@ -246,12 +293,14 @@ def genErl(spec):
-export([method_id/1]).
-export([method_has_content/1]).
+-export([is_method_synchronous/1]).
-export([method_fieldnames/1]).
-export([decode_method_fields/2]).
-export([decode_properties/2]).
-export([encode_method_fields/1]).
-export([encode_properties/1]).
-export([lookup_amqp_exception/1]).
+-export([amqp_exception/1]).
bitvalue(true) -> 1;
bitvalue(false) -> 0;
@@ -266,6 +315,9 @@ bitvalue(undefined) -> 0.
for m in methods: genMethodHasContent(m)
print "method_has_content(Name) -> exit({unknown_method_name, Name})."
+ for m in methods: genMethodIsSynchronous(m)
+ print "is_method_synchronous(Name) -> exit({unknown_method_name, Name})."
+
for m in methods: genMethodFieldNames(m)
print "method_fieldnames(Name) -> exit({unknown_method_name, Name})."
@@ -285,8 +337,10 @@ bitvalue(undefined) -> 0.
for (c,v,cls) in spec.constants: genLookupException(c,v,cls)
print "lookup_amqp_exception(Code) ->"
print " rabbit_log:warning(\"Unknown AMQP error code '~p'~n\", [Code]),"
- print " {true, ?INTERNAL_ERROR, <<\"INTERNAL_ERROR\">>}."
+ print " {true, ?INTERNAL_ERROR, <<\"INTERNAL_ERROR\">>}."
+ for(c,v,cls) in spec.constants: genAmqpException(c,v,cls)
+ print "amqp_exception(_Code) -> undefined."
def genHrl(spec):
def erlType(domain):
@@ -306,6 +360,7 @@ def genHrl(spec):
methods = spec.allMethods()
+ printFileHeader()
print "-define(PROTOCOL_VERSION_MAJOR, %d)." % (spec.major)
print "-define(PROTOCOL_VERSION_MINOR, %d)." % (spec.minor)
print "-define(PROTOCOL_PORT, %d)." % (spec.port)