diff options
| -rw-r--r-- | codegen.py | 72 | ||||
| -rw-r--r-- | include/rabbit_framing_spec.hrl | 3 |
2 files changed, 72 insertions, 3 deletions
diff --git a/codegen.py b/codegen.py index 91c70e8196..5ea47734a4 100644 --- a/codegen.py +++ b/codegen.py @@ -370,6 +370,43 @@ def genHrl(spec): return result return ', '.join([fillField(f) for f in fields]) + def multiLineFormat(things, prologue, separator, lineSeparator, epilogue, thingsPerLine = 4): + r = [prologue] + i = 0 + for t in things: + if i != 0: + if i % thingsPerLine == 0: + r += [lineSeparator] + else: + r += [separator] + r += [t] + i += 1 + r += [epilogue] + return "".join(r) + + def prettyType(typeName, subTypes, typesPerLine = 4): + sTs = multiLineFormat(subTypes, + "( ", " | ", "\n\t| ", " )", + thingsPerLine = typesPerLine) + return "-type(%s ::\n\t%s)." % (typeName, sTs) + + def prettySpec(fName, fArgs, fValue, fModule = "rabbit_framing", multiLine = False, itemsPerLine = 4): + """If multiLine is True, EACH argument and the value must me a list. +Note to self: Defining a separate type would be better than using multiLine. +""" + if multiLine: + args = ",\n".join([multiLineFormat(arg, + "\t( ", " | ", "\n\t| ", " )", + thingsPerLine = itemsPerLine) + for arg in fArgs]) + vals = multiLineFormat(fValue, + "( ", " | ", "\n\t | ", " )", + thingsPerLine = itemsPerLine) + return "-spec(%s:%s ::\n%s\n\t-> %s)." % (fModule, fName, args, vals) + else: + args = ", ".join(fArgs) + return "-spec(%s:%s :: (%s) -> %s)." % (fModule, fName, args, fValue) + methods = spec.allMethods() printFileHeader() @@ -388,6 +425,41 @@ def genHrl(spec): for c in spec.allClasses(): print "-record('P_%s', {%s})." % (erlangize(c.name), fieldNameList(c.fields)) + 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 "%% Method signatures" + print prettySpec("lookup_method_name/1", + ["amqp_method()"], + "amqp_method_name()") + print prettySpec("method_id/1", + ["amqp_method_name()"], + "amqp_method()") + print prettySpec("method_has_content/1", + ["amqp_method_name()"], + "boolean()") + print prettySpec("is_method_synchronous/1", + ["amqp_method_record()"], + "boolean()") + print prettySpec("method_record/1", + ["amqp_method_name()"], + "amqp_method_record()") + print prettySpec("method_fieldnames/1", + ["amqp_method_name()"], + "[amqp_method_field_name()]") + def generateErl(specPath): genErl(AmqpSpec(specPath)) diff --git a/include/rabbit_framing_spec.hrl b/include/rabbit_framing_spec.hrl index 1a9798998c..447947b77b 100644 --- a/include/rabbit_framing_spec.hrl +++ b/include/rabbit_framing_spec.hrl @@ -46,9 +46,6 @@ %% TODO: make this more precise -type(amqp_properties() :: tuple()). %% TODO: make this more precise --type(amqp_method() :: tuple()). -%% TODO: make this more precise --type(amqp_method_name() :: atom()). -type(channel_number() :: non_neg_integer()). -type(resource_name() :: binary()). -type(routing_key() :: binary()). |
