From c61a2425626f80c16eedc53ef5ad638e2ba50c3e Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Thu, 1 Jul 2010 16:48:32 +0100 Subject: partially moved types out of rabbit.hrl --- codegen.py | 101 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 50 deletions(-) (limited to 'codegen.py') diff --git a/codegen.py b/codegen.py index 0d6d9d56..8317e2b8 100644 --- a/codegen.py +++ b/codegen.py @@ -332,6 +332,9 @@ def genErl(spec): -export([lookup_amqp_exception/1]). -export([amqp_exception/1]). +-export_type([amqp_table/0, amqp_property_type/0, amqp_method_record/0, + amqp_method_name/0, amqp_method/0]). + bitvalue(true) -> 1; bitvalue(false) -> 0; bitvalue(undefined) -> 0. @@ -350,8 +353,56 @@ bitvalue(undefined) -> 0. -spec(encode_properties/1 :: (amqp_method_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 + +-ifdef(use_specs). +-type(amqp_field_type() :: + 'longstr' | 'signedint' | 'decimal' | 'timestamp' | + 'table' | 'byte' | 'double' | 'float' | 'long' | + 'short' | 'bool' | 'binary' | 'void'). +-type(amqp_property_type() :: + 'shortstr' | 'longstr' | 'octet' | 'shortint' | 'longint' | + 'longlongint' | 'timestamp' | 'bit' | 'table'). +%% we could make this more precise but ultimately are limited by +%% dialyzer's lack of support for recursive types +-type(amqp_table() :: [{binary(), amqp_field_type(), any()}]). +%% TODO: make this more precise +-type(amqp_properties() :: tuple()). +-type(resource_name() :: binary()). +-type(vhost() :: binary()). +-type(ctag() :: binary()). +-type(binding_key() :: binary()). + -endif. % use_specs """ + print "-ifdef(use_specs)." + print "%% Various types" + print prettyType("amqp_method_name()", + [m.erlangName() for m in methods]) + print prettyType("amqp_method()", + ["{%s, %s}" % (m.klass.index, m.index) for m in methods], + 6) + print prettyType("amqp_method_record()", + ["#%s{}" % (m.erlangName()) for m in methods]) + fieldNames = set() + for m in methods: + fieldNames.update(m.arguments) + fieldNames = [erlangize(f.name) for f in fieldNames] + print prettyType("amqp_method_field_name()", + fieldNames) + print prettyType("amqp_property_record()", + ["#'P_%s'{}" % erlangize(c.name) for c in spec.allClasses()]) + print prettyType("amqp_exception()", + ["'%s'" % erlangConstantName(c).lower() for (c, v, cls) in spec.constants]) + print prettyType("amqp_exception_code()", + ["%i" % v for (c, v, cls) in spec.constants]) + classIds = set() + for m in spec.allMethods(): + classIds.add(m.klass.index) + print prettyType("amqp_class_id()", + ["%i" % ci for ci in classIds]) + print "-endif. % use_specs" + for m in methods: genLookupMethodName(m) print "lookup_method_name({_ClassId, _MethodId} = Id) -> exit({unknown_method_id, Id})." @@ -425,63 +476,13 @@ def genHrl(spec): for c in spec.allClasses(): print "-record('P_%s', {%s})." % (erlangize(c.name), fieldNameList(c.fields)) - print "-ifdef(use_specs)." - print "%% Various types" - print prettyType("amqp_method_name()", - [m.erlangName() for m in methods]) - print prettyType("amqp_method()", - ["{%s, %s}" % (m.klass.index, m.index) for m in methods], - 6) - print prettyType("amqp_method_record()", - ["#%s{}" % (m.erlangName()) for m in methods]) - fieldNames = set() - for m in methods: - fieldNames.update(m.arguments) - fieldNames = [erlangize(f.name) for f in fieldNames] - print prettyType("amqp_method_field_name()", - fieldNames) - print prettyType("amqp_property_record()", - ["#'P_%s'{}" % erlangize(c.name) for c in spec.allClasses()]) - print prettyType("amqp_exception()", - ["'%s'" % erlangConstantName(c).lower() for (c, v, cls) in spec.constants]) - print prettyType("amqp_exception_code()", - ["%i" % v for (c, v, cls) in spec.constants]) - print "-endif. % use_specs" def genSpec(spec): methods = spec.allMethods() printFileHeader() print """% Hard-coded types --type(amqp_field_type() :: - 'longstr' | 'signedint' | 'decimal' | 'timestamp' | - 'table' | 'byte' | 'double' | 'float' | 'long' | - 'short' | 'bool' | 'binary' | 'void'). --type(amqp_property_type() :: - 'shortstr' | 'longstr' | 'octet' | 'shortint' | 'longint' | - 'longlongint' | 'timestamp' | 'bit' | 'table'). -%% we could make this more precise but ultimately are limited by -%% dialyzer's lack of support for recursive types --type(amqp_table() :: [{binary(), amqp_field_type(), any()}]). -%% TODO: make this more precise --type(amqp_properties() :: tuple()). - --type(channel_number() :: non_neg_integer()). --type(resource_name() :: binary()). --type(routing_key() :: binary()). --type(username() :: binary()). --type(password() :: binary()). --type(vhost() :: binary()). --type(ctag() :: binary()). --type(exchange_type() :: atom()). --type(binding_key() :: binary()). """ - print "% Auto-generated types" - classIds = set() - for m in spec.allMethods(): - classIds.add(m.klass.index) - print prettyType("amqp_class_id()", - ["%i" % ci for ci in classIds]) def generateErl(specPath): genErl(AmqpSpec(specPath)) -- cgit v1.2.1 From fd2dda1d51ee7862d1f66dbeaf57fbb42240f674 Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Fri, 2 Jul 2010 11:51:10 +0100 Subject: redistributed all types from rabbit_framing_spec.hrl and rabbit.hrl --- codegen.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'codegen.py') diff --git a/codegen.py b/codegen.py index 8317e2b8..5c235e35 100644 --- a/codegen.py +++ b/codegen.py @@ -333,7 +333,8 @@ def genErl(spec): -export([amqp_exception/1]). -export_type([amqp_table/0, amqp_property_type/0, amqp_method_record/0, - amqp_method_name/0, amqp_method/0]). + amqp_method_name/0, amqp_method/0, vhost/0, ctag/0, + resource_name/0, amqp_properties/0, amqp_class_id/0]). bitvalue(true) -> 1; bitvalue(false) -> 0; @@ -371,7 +372,6 @@ bitvalue(undefined) -> 0. -type(resource_name() :: binary()). -type(vhost() :: binary()). -type(ctag() :: binary()). --type(binding_key() :: binary()). -endif. % use_specs """ @@ -477,24 +477,13 @@ def genHrl(spec): print "-record('P_%s', {%s})." % (erlangize(c.name), fieldNameList(c.fields)) -def genSpec(spec): - methods = spec.allMethods() - - printFileHeader() - print """% Hard-coded types -""" - def generateErl(specPath): genErl(AmqpSpec(specPath)) def generateHrl(specPath): genHrl(AmqpSpec(specPath)) -def generateSpec(specPath): - genSpec(AmqpSpec(specPath)) - if __name__ == "__main__": do_main_dict({"header": generateHrl, - "spec": generateSpec, "body": generateErl}) -- cgit v1.2.1 From d81c817d65ceba84c8095b0df866e068779c92f2 Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Fri, 2 Jul 2010 12:25:30 +0100 Subject: moved most hard-coded types from rabbit_framing --- codegen.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'codegen.py') diff --git a/codegen.py b/codegen.py index 5c235e35..d0008cf3 100644 --- a/codegen.py +++ b/codegen.py @@ -333,8 +333,7 @@ def genErl(spec): -export([amqp_exception/1]). -export_type([amqp_table/0, amqp_property_type/0, amqp_method_record/0, - amqp_method_name/0, amqp_method/0, vhost/0, ctag/0, - resource_name/0, amqp_properties/0, amqp_class_id/0]). + amqp_method_name/0, amqp_method/0, amqp_class_id/0]). bitvalue(true) -> 1; bitvalue(false) -> 0; @@ -367,12 +366,7 @@ bitvalue(undefined) -> 0. %% we could make this more precise but ultimately are limited by %% dialyzer's lack of support for recursive types -type(amqp_table() :: [{binary(), amqp_field_type(), any()}]). -%% TODO: make this more precise -type(amqp_properties() :: tuple()). --type(resource_name() :: binary()). --type(vhost() :: binary()). --type(ctag() :: binary()). - -endif. % use_specs """ print "-ifdef(use_specs)." -- cgit v1.2.1 From 334d32e77e309e1e49d2f0710ff98208a4bb5c08 Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Fri, 2 Jul 2010 15:01:15 +0100 Subject: better types --- codegen.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'codegen.py') diff --git a/codegen.py b/codegen.py index d0008cf3..81cbc506 100644 --- a/codegen.py +++ b/codegen.py @@ -333,7 +333,8 @@ def genErl(spec): -export([amqp_exception/1]). -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_method_name/0, amqp_method/0, amqp_class_id/0, + amqp_value/0, amqp_array/0]). bitvalue(true) -> 1; bitvalue(false) -> 0; @@ -353,9 +354,7 @@ bitvalue(undefined) -> 0. -spec(encode_properties/1 :: (amqp_method_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 --ifdef(use_specs). -type(amqp_field_type() :: 'longstr' | 'signedint' | 'decimal' | 'timestamp' | 'table' | 'byte' | 'double' | 'float' | 'long' | @@ -363,10 +362,23 @@ bitvalue(undefined) -> 0. -type(amqp_property_type() :: 'shortstr' | 'longstr' | 'octet' | 'shortint' | 'longint' | 'longlongint' | 'timestamp' | 'bit' | 'table'). -%% we could make this more precise but ultimately are limited by -%% dialyzer's lack of support for recursive types --type(amqp_table() :: [{binary(), amqp_field_type(), any()}]). --type(amqp_properties() :: tuple()). + +-type(amqp_table() :: [{binary(), amqp_field_type(), amqp_value()}]). +-type(amqp_array() :: [{amqp_field_type(), amqp_value()}]). +-type(amqp_value() :: binary() | % longstr + integer() | % signedint + {non_neg_integer(), non_neg_integer()} | % decimal + amqp_table() | + amqp_array() | + byte() | % byte + float() | % double + integer() | % long + integer() | % short + boolean() | % bool + binary() | % binary + 'undefined' | % void + non_neg_integer() % timestamp + ). -endif. % use_specs """ print "-ifdef(use_specs)." -- cgit v1.2.1 From 6a67fc1e887b427feaaa1511be2ccbbae905fbe5 Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Mon, 5 Jul 2010 14:18:06 +0100 Subject: added missing export_types --- codegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'codegen.py') diff --git a/codegen.py b/codegen.py index 81cbc506..ca1d235b 100644 --- a/codegen.py +++ b/codegen.py @@ -334,7 +334,7 @@ def genErl(spec): -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_value/0, amqp_array/0, amqp_exception/0, amqp_property_record/0]). bitvalue(true) -> 1; bitvalue(false) -> 0; -- cgit v1.2.1 From d84e67b9e089c41eab143045f37183e87d46534d Mon Sep 17 00:00:00 2001 From: Alexandru Scvortov Date: Mon, 5 Jul 2010 23:39:33 +0100 Subject: moved export_types to inside ifdefs --- codegen.py | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'codegen.py') diff --git a/codegen.py b/codegen.py index ca1d235b..1244aae1 100644 --- a/codegen.py +++ b/codegen.py @@ -332,29 +332,14 @@ def genErl(spec): -export([lookup_amqp_exception/1]). -export([amqp_exception/1]). --export_type([amqp_table/0, amqp_property_type/0, amqp_method_record/0, +""" + 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]). -bitvalue(true) -> 1; -bitvalue(false) -> 0; -bitvalue(undefined) -> 0. - -%% Method signatures --ifdef(use_specs). --spec(lookup_method_name/1 :: (amqp_method()) -> amqp_method_name()). --spec(method_id/1 :: (amqp_method_name()) -> amqp_method()). --spec(method_has_content/1 :: (amqp_method_name()) -> boolean()). --spec(is_method_synchronous/1 :: (amqp_method_record()) -> boolean()). --spec(method_record/1 :: (amqp_method_name()) -> amqp_method_record()). --spec(method_fieldnames/1 :: (amqp_method_name()) -> [amqp_method_field_name()]). --spec(decode_method_fields/2 :: (amqp_method_name(), binary()) -> amqp_method_record()). --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(lookup_amqp_exception/1 :: (amqp_exception()) -> {boolean(), amqp_exception_code(), binary()}). --spec(amqp_exception/1 :: (amqp_exception_code()) -> amqp_exception()). - -type(amqp_field_type() :: 'longstr' | 'signedint' | 'decimal' | 'timestamp' | 'table' | 'byte' | 'double' | 'float' | 'long' | @@ -379,10 +364,8 @@ bitvalue(undefined) -> 0. 'undefined' | % void non_neg_integer() % timestamp ). --endif. % use_specs """ - print "-ifdef(use_specs)." - print "%% Various types" + print prettyType("amqp_method_name()", [m.erlangName() for m in methods]) print prettyType("amqp_method()", @@ -409,6 +392,27 @@ bitvalue(undefined) -> 0. ["%i" % ci for ci in classIds]) print "-endif. % use_specs" + print """ +%% Method signatures +-ifdef(use_specs). +-spec(lookup_method_name/1 :: (amqp_method()) -> amqp_method_name()). +-spec(method_id/1 :: (amqp_method_name()) -> amqp_method()). +-spec(method_has_content/1 :: (amqp_method_name()) -> boolean()). +-spec(is_method_synchronous/1 :: (amqp_method_record()) -> boolean()). +-spec(method_record/1 :: (amqp_method_name()) -> amqp_method_record()). +-spec(method_fieldnames/1 :: (amqp_method_name()) -> [amqp_method_field_name()]). +-spec(decode_method_fields/2 :: (amqp_method_name(), binary()) -> amqp_method_record()). +-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(lookup_amqp_exception/1 :: (amqp_exception()) -> {boolean(), amqp_exception_code(), binary()}). +-spec(amqp_exception/1 :: (amqp_exception_code()) -> amqp_exception()). +-endif. % use_specs + +bitvalue(true) -> 1; +bitvalue(false) -> 0; +bitvalue(undefined) -> 0. +""" for m in methods: genLookupMethodName(m) print "lookup_method_name({_ClassId, _MethodId} = Id) -> exit({unknown_method_id, Id})." -- cgit v1.2.1