diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2011-10-19 12:40:18 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2011-10-19 12:40:18 +0100 |
| commit | bd03952d21529a83951b21d86b1c227c0e35916e (patch) | |
| tree | 4637474907994d589a96b4419bfce301fde03a9a /codegen.py | |
| parent | 20aa893754c121c294fdf93a9245aa953be0dcd9 (diff) | |
| parent | 8d40a6229ee9586169f6a19f95db338bbbb10b8a (diff) | |
| download | rabbitmq-server-git-bd03952d21529a83951b21d86b1c227c0e35916e.tar.gz | |
Merge bug17162.
Diffstat (limited to 'codegen.py')
| -rw-r--r-- | codegen.py | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/codegen.py b/codegen.py index 7636c196ac..494be73d68 100644 --- a/codegen.py +++ b/codegen.py @@ -42,7 +42,8 @@ erlangTypeMap = { def convertTable(d): if len(d) == 0: return "[]" - else: raise 'Non-empty table defaults not supported', d + else: + raise Exception('Non-empty table defaults not supported ' + d) erlangDefaultValueTypeConvMap = { bool : lambda x: str(x).lower(), @@ -229,9 +230,32 @@ def genErl(spec): print " %s;" % (recordConstructorExpr,) def genDecodeProperties(c): - print "decode_properties(%d, PropBin) ->" % (c.index) - print " %s = rabbit_binary_parser:parse_properties(%s, PropBin)," % \ - (fieldTempList(c.fields), fieldTypeList(c.fields)) + def presentBin(fields): + ps = ', '.join(['P' + str(f.index) + ':1' for f in fields]) + return '<<' + ps + ', _:%d, R0/binary>>' % (16 - len(fields),) + def mkMacroName(field): + return '?' + field.domain.upper() + '_PROP' + def writePropFieldLine(field, bin_next = None): + i = str(field.index) + if not bin_next: + bin_next = 'R' + str(field.index + 1) + if field.domain in ['octet', 'timestamp']: + print (" {%s, %s} = %s(%s, %s, %s, %s)," % + ('F' + i, bin_next, mkMacroName(field), 'P' + i, + 'R' + i, 'I' + i, 'X' + i)) + else: + print (" {%s, %s} = %s(%s, %s, %s, %s, %s)," % + ('F' + i, bin_next, mkMacroName(field), 'P' + i, + 'R' + i, 'L' + i, 'S' + i, 'X' + i)) + + if len(c.fields) == 0: + print "decode_properties(%d, _) ->" % (c.index,) + else: + print ("decode_properties(%d, %s) ->" % + (c.index, presentBin(c.fields))) + for field in c.fields[:-1]: + writePropFieldLine(field) + writePropFieldLine(c.fields[-1], "<<>>") print " #'P_%s'{%s};" % (erlangize(c.name), fieldMapList(c.fields)) def genFieldPreprocessing(packed): @@ -272,7 +296,7 @@ def genErl(spec): if mCls == 'SOFT_ERROR': genLookupException1(c,'false') elif mCls == 'HARD_ERROR': genLookupException1(c, 'true') elif mCls == '': pass - else: raise 'Unknown constant class', cls + else: raise Exception('Unknown constant class' + cls) def genLookupException1(c,hardErrorBoolStr): n = erlangConstantName(c) @@ -404,6 +428,27 @@ shortstr_size(S) -> Len when Len =< 255 -> Len; _ -> exit(method_field_shortstr_overflow) end. + +-define(SHORTSTR_PROP(P, R, L, S, X), + if P =:= 0 -> {undefined, R}; + true -> <<L:8/unsigned, S:L/binary, X/binary>> = R, + {S, X} + end). +-define(TABLE_PROP(P, R, L, T, X), + if P =:= 0 -> {undefined, R}; + true -> <<L:32/unsigned, T:L/binary, X/binary>> = R, + {rabbit_binary_parser:parse_table(T), X} + end). +-define(OCTET_PROP(P, R, I, X), + if P =:= 0 -> {undefined, R}; + true -> <<I:8/unsigned, X/binary>> = R, + {I, X} + end). +-define(TIMESTAMP_PROP(P, R, I, X), + if P =:= 0 -> {undefined, R}; + true -> <<I:64/unsigned, X/binary>> = R, + {I, X} + end). """ version = "{%d, %d, %d}" % (spec.major, spec.minor, spec.revision) if version == '{8, 0, 0}': version = '{0, 8, 0}' |
