diff options
author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2010-06-09 12:17:43 +0100 |
---|---|---|
committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2010-06-09 12:17:43 +0100 |
commit | 9cf6fd9972755d6de621b82aa6d87a5d27dbca82 (patch) | |
tree | c4e6939d3bea657ca7bbeff5befbd67d8a7f1378 /codegen.py | |
parent | f6ff05e9208e5566e080d807ba2807889a97d5e2 (diff) | |
download | rabbitmq-server-9cf6fd9972755d6de621b82aa6d87a5d27dbca82.tar.gz |
removed duplicated code
Diffstat (limited to 'codegen.py')
-rw-r--r-- | codegen.py | 61 |
1 files changed, 21 insertions, 40 deletions
@@ -93,6 +93,27 @@ class PackedMethodBitField: def full(self): return self.count() == 8 +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): + """Pretty print a type signature made up of many alternative subtypes""" + sTs = multiLineFormat(subTypes, + "( ", " | ", "\n\t| ", " )", + thingsPerLine = typesPerLine) + return "-type(%s ::\n\t%s)." % (typeName, sTs) + def printFileHeader(): print """%% Autogenerated code. Do not edit. %% @@ -385,26 +406,6 @@ 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) - methods = spec.allMethods() printFileHeader() @@ -450,26 +451,6 @@ def genHrl(spec): # ["%i" % ci for ci in classIds]) def genSpec(spec): - 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) - methods = spec.allMethods() printFileHeader() |