Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special-case empty { ... } sequences for prettier name mangling. #104

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions design/mvp/canonical-abi/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,27 +1144,42 @@ def mangle_valtype(t):
case Result(ok,error) : return mangle_resulttype(ok,error)

def mangle_recordtype(fields):
mangled_fields = (f.label + ': ' + mangle_valtype(f.t) for f in fields)
return 'record { ' + ', '.join(mangled_fields) + ' }'
if len(fields) == 0:
return 'record {}'
else:
mangled_fields = (f.label + ': ' + mangle_valtype(f.t) for f in fields)
return 'record { ' + ', '.join(mangled_fields) + ' }'

def mangle_tupletype(ts):
return 'tuple<' + ', '.join(mangle_valtype(t) for t in ts) + '>'

def mangle_flags(labels):
return 'flags { ' + ', '.join(labels) + ' }'
if len(labels) == 0:
return 'flags {}'
else:
return 'flags { ' + ', '.join(labels) + ' }'

def mangle_varianttype(cases):
mangled_cases = ('{label}{payload}'.format(
label = c.label,
payload = '' if c.t is None else '(' + mangle_valtype(c.t) + ')')
for c in cases)
return 'variant { ' + ', '.join(mangled_cases) + ' }'
if len(cases) == 0:
return 'variant {}'
else:
mangled_cases = ('{label}{payload}'.format(
label = c.label,
payload = '' if c.t is None else '(' + mangle_valtype(c.t) + ')')
for c in cases)
return 'variant { ' + ', '.join(mangled_cases) + ' }'

def mangle_enumtype(labels):
return 'enum { ' + ', '.join(labels) + ' }'
if len(labels) == 0:
return 'enum {}'
else:
return 'enum { ' + ', '.join(labels) + ' }'

def mangle_uniontype(ts):
return 'union { ' + ', '.join(mangle_valtype(t) for t in ts) + ' }'
if len(ts) == 0:
return 'union {}'
else:
return 'union { ' + ', '.join(mangle_valtype(t) for t in ts) + ' }'

def mangle_optiontype(t):
return 'option<' + mangle_valtype(t) + '>'
Expand Down