Skip to content

Commit

Permalink
another bug fix and more generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
billhails committed Apr 2, 2024
1 parent 819c6ce commit 8a524a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/anf_pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ void ppAexpPrimApp(AexpPrimApp *x) {
case AEXPPRIMOP_TYPE_MOD:
eprintf("mod ");
break;
case AEXPPRIMOP_TYPE_CMP:
eprintf("cmp ");
break;
default:
cant_happen("unrecognized op in ppAexpPrimApp (%d)", x->type);
cant_happen("unrecognized op %s", aexpPrimOpName(x->type));
}
ppAexp(x->exp1);
if (x->exp2 != NULL) {
Expand Down
43 changes: 34 additions & 9 deletions tools/makeAST.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,30 @@ def printCopyField(self, field, depth, prefix=''):
pad(depth)
print(f'x->{field} = o->{field}; // SimpleEnum.printCopyField')

def getNameFunctionDeclaration(self):
name = self.getName();
camel = name[0].lower() + name[1:]
return f"char * {camel}Name(enum {name} type)"

def printNameFunctionDeclaration(self):
decl = self.getNameFunctionDeclaration()
print(f"{decl}; // SimpleEnum.printNameFunctionDeclaration")

def printNameFunctionBody(self):
decl = self.getNameFunctionDeclaration()
comment = '// SimpleEnum.printNameFunctionDeclaration'
print(f"{decl} {{ {comment}")
print(f" switch(type) {{ {comment}")
for field in self.fields:
field.printNameFunctionLine()
print(f" default: {{ {comment}")
print(f" static char buf[64]; {comment}")
print(f' sprintf(buf, "%d", type); {comment}')
print(f" return buf; {comment}");
print(f" }} {comment}")
print(f" }} {comment}")
print(f"}} {comment}")
print("")


class DiscriminatedUnionEnum(Base):
Expand Down Expand Up @@ -1780,17 +1804,18 @@ def printNameFunctionDeclaration(self):

def printNameFunctionBody(self):
decl = self.getNameFunctionDeclaration()
print(f"{decl} {{ // DiscriminatedUnionEnum.printNameFunctionDeclaration")
print(" switch(type) {")
comment = '// DiscriminatedUnionEnum.printNameFunctionDeclaration'
print(f"{decl} {{ {comment}")
print(f" switch(type) {{ {comment}")
for field in self.fields:
field.printNameFunctionLine()
print(" default: {")
print(" static char buf[64];")
print(' sprintf(buf, "%d", type);')
print(" return buf;");
print(" }")
print(" }")
print("}")
print(f" default: {{ {comment}")
print(f" static char buf[64]; {comment}")
print(f' sprintf(buf, "%d", type); {comment}')
print(f" return buf; {comment}");
print(f" }} {comment}")
print(f" }} {comment}")
print(f"}} {comment}")
print("")

def getTypeDeclaration(self):
Expand Down

0 comments on commit 8a524a5

Please sign in to comment.