Skip to content

Commit

Permalink
fix some expr macro bugs in pp
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed May 7, 2024
1 parent cdeb4b3 commit 7b121c5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions FrontEnd/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@ def EmitTokensCodeBlock(ts: TS, stmts):
ts.EmitColonEnd(beg_colon)


def TokensMacroId(ts: TS, node: cwast.MacroId):
ts.EmitAttr(node.name)


def TokensExprIndex(ts: TS, node: cwast.ExprIndex):
Expand Down Expand Up @@ -533,8 +531,7 @@ def TokensValString(ts: TS, node: cwast.ValString):

_CONCRETE_SYNTAX = {
cwast.Id: lambda ts, n: (ts.EmitAttr(n.name)),
#
cwast.MacroId: TokensMacroId,
cwast.MacroId: lambda ts, n: (ts.EmitAttr(n.name)),
cwast.MacroInvoke: TokensExprMacroInvoke,
#
cwast.TypeAuto: lambda ts, n: ts.EmitAttr("auto"),
Expand Down Expand Up @@ -723,6 +720,15 @@ def EmitTokensStatement(ts: TS, n):
if not ts.LastTokenIsCodeBlock():
ts.EmitNewline()

def EmitTokensExprMacroBlock(ts: TS, stmts):
beg_colon = ts.EmitColonBeg()
for child in stmts:
if child.__class__ in _CONCRETE_SYNTAX:
EmitTokens(ts, child)
ts.EmitNewline()
else:
assert False
ts.EmitColonEnd(beg_colon)

def _EmitTokensToplevel(ts: TS, node):
# extra newline before every toplevel stanza
Expand Down Expand Up @@ -814,7 +820,10 @@ def _EmitTokensToplevel(ts: TS, node):
ts.EmitEnd(beg_paren)
ts.EmitStmtEnd(beg)
#
EmitTokensCodeBlock(ts, node.body_macro)
if node.macro_result_kind in (cwast.MACRO_PARAM_KIND.STMT, cwast.MACRO_PARAM_KIND.STMT_LIST):
EmitTokensCodeBlock(ts, node.body_macro)
else:
EmitTokensExprMacroBlock(ts, node.body_macro)
else:
assert False
#
Expand Down

0 comments on commit 7b121c5

Please sign in to comment.