summaryrefslogtreecommitdiff
path: root/codegen.py
diff options
context:
space:
mode:
authorDavid Wragg <david@rabbitmq.com>2010-12-02 12:32:21 +0000
committerDavid Wragg <david@rabbitmq.com>2010-12-02 12:32:21 +0000
commit49ce527be88c18a549d9c8a5be0aca6befc3ca30 (patch)
tree38daec44925af2d487ea64303af19edb68d223b9 /codegen.py
parent4c3b5cdd2dfc88287855b90e67a3778ed1208eed (diff)
parentb46009dcd98f61d156712d2b2178ed19a98c0a33 (diff)
downloadrabbitmq-server-git-49ce527be88c18a549d9c8a5be0aca6befc3ca30.tar.gz
Merge from default
Diffstat (limited to 'codegen.py')
-rw-r--r--codegen.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/codegen.py b/codegen.py
index 142297533f..979c5bd82d 100644
--- a/codegen.py
+++ b/codegen.py
@@ -75,6 +75,8 @@ def erlangize(s):
AmqpMethod.erlangName = lambda m: "'" + erlangize(m.klass.name) + '.' + erlangize(m.name) + "'"
+AmqpClass.erlangName = lambda c: "'" + erlangize(c.name) + "'"
+
def erlangConstantName(s):
return '_'.join(re.split('[- ]', s.upper()))
@@ -167,6 +169,9 @@ def genErl(spec):
def genLookupMethodName(m):
print "lookup_method_name({%d, %d}) -> %s;" % (m.klass.index, m.index, m.erlangName())
+ def genLookupClassName(c):
+ print "lookup_class_name(%d) -> %s;" % (c.index, c.erlangName())
+
def genMethodId(m):
print "method_id(%s) -> {%d, %d};" % (m.erlangName(), m.klass.index, m.index)
@@ -235,8 +240,6 @@ def genErl(spec):
elif type == 'table':
print " F%d = rabbit_binary_parser:parse_table(F%dTab)," % \
(f.index, f.index)
- elif type == 'shortstr':
- print " if F%dLen > 255 -> exit(method_field_shortstr_overflow); true -> ok end," % (f.index)
else:
pass
@@ -273,8 +276,7 @@ def genErl(spec):
print " F%dTab = rabbit_binary_generator:generate_table(F%d)," % (f.index, f.index)
print " F%dLen = size(F%dTab)," % (f.index, f.index)
elif type == 'shortstr':
- print " F%dLen = size(F%d)," % (f.index, f.index)
- print " if F%dLen > 255 -> exit(method_field_shortstr_overflow); true -> ok end," % (f.index)
+ print " F%dLen = shortstr_size(F%d)," % (f.index, f.index)
elif type == 'longstr':
print " F%dLen = size(F%d)," % (f.index, f.index)
else:
@@ -325,6 +327,8 @@ def genErl(spec):
-export([version/0]).
-export([lookup_method_name/1]).
+-export([lookup_class_name/1]).
+
-export([method_id/1]).
-export([method_has_content/1]).
-export([is_method_synchronous/1]).
@@ -341,9 +345,11 @@ def genErl(spec):
print "%% Various types"
print "-ifdef(use_specs)."
- print """-export_type([amqp_table/0, amqp_property_type/0, amqp_method_record/0,
- amqp_method_name/0, amqp_method/0, amqp_class_id/0,
- amqp_value/0, amqp_array/0, amqp_exception/0, amqp_property_record/0]).
+ print """-export_type([amqp_field_type/0, amqp_property_type/0,
+ amqp_table/0, amqp_array/0, amqp_value/0,
+ amqp_method_name/0, amqp_method/0, amqp_method_record/0,
+ amqp_method_field_name/0, amqp_property_record/0,
+ amqp_exception/0, amqp_exception_code/0, amqp_class_id/0]).
-type(amqp_field_type() ::
'longstr' | 'signedint' | 'decimal' | 'timestamp' |
@@ -411,7 +417,7 @@ def genErl(spec):
(amqp_method_name(), binary()) -> amqp_method_record() | rabbit_types:connection_exit()).
-spec(decode_properties/2 :: (non_neg_integer(), binary()) -> amqp_property_record()).
-spec(encode_method_fields/1 :: (amqp_method_record()) -> binary()).
--spec(encode_properties/1 :: (amqp_method_record()) -> binary()).
+-spec(encode_properties/1 :: (amqp_property_record()) -> binary()).
-spec(lookup_amqp_exception/1 :: (amqp_exception()) -> {boolean(), amqp_exception_code(), binary()}).
-spec(amqp_exception/1 :: (amqp_exception_code()) -> amqp_exception()).
-endif. % use_specs
@@ -419,6 +425,12 @@ def genErl(spec):
bitvalue(true) -> 1;
bitvalue(false) -> 0;
bitvalue(undefined) -> 0.
+
+shortstr_size(S) ->
+ case size(S) of
+ Len when Len =< 255 -> Len;
+ _ -> exit(method_field_shortstr_overflow)
+ end.
"""
version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision)
if version == '{8, 0, 0}': version = '{0, 8, 0}'
@@ -427,6 +439,9 @@ bitvalue(undefined) -> 0.
for m in methods: genLookupMethodName(m)
print "lookup_method_name({_ClassId, _MethodId} = Id) -> exit({unknown_method_id, Id})."
+ for c in spec.allClasses(): genLookupClassName(c)
+ print "lookup_class_name(ClassId) -> exit({unknown_class_id, ClassId})."
+
for m in methods: genMethodId(m)
print "method_id(Name) -> exit({unknown_method_name, Name})."