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

cleanup: Simplify pretty-printer. #51

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/Language/Cimple/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data NodeF lexeme a
| Case a a
| Default a
| Label lexeme a
| ExprStmt a
-- Variable declarations
| VLA a lexeme a
| VarDeclStmt a (Maybe a)
Expand Down Expand Up @@ -89,6 +90,7 @@ data NodeF lexeme a
| EnumConsts (Maybe lexeme) [a]
| EnumDecl lexeme [a] lexeme
| Enumerator lexeme (Maybe a)
| AggregateDecl a
| Typedef a lexeme
| TypedefFunction a
| Struct lexeme [a]
Expand Down
4 changes: 4 additions & 0 deletions src/Language/Cimple/MapAst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ instance MapAst itext otext (Node (Lexeme itext)) where
Fix <$> (Default <$> recurse stmt)
Label label stmt ->
Fix <$> (Label <$> recurse label <*> recurse stmt)
ExprStmt expr ->
Fix <$> (ExprStmt <$> recurse expr)
VLA ty name size ->
Fix <$> (VLA <$> recurse ty <*> recurse name <*> recurse size)
VarDeclStmt decl ini ->
Expand Down Expand Up @@ -220,6 +222,8 @@ instance MapAst itext otext (Node (Lexeme itext)) where
Fix <$> (EnumDecl <$> recurse name <*> recurse members <*> recurse tyName)
Enumerator name value ->
Fix <$> (Enumerator <$> recurse name <*> recurse value)
AggregateDecl struct ->
Fix <$> (AggregateDecl <$> recurse struct)
Typedef ty name ->
Fix <$> (Typedef <$> recurse ty <*> recurse name)
TypedefFunction ty ->
Expand Down
10 changes: 5 additions & 5 deletions src/Language/Cimple/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ Stmt
| ForStmt { $1 }
| WhileStmt { $1 }
| DoWhileStmt { $1 }
| AssignExpr ';' { $1 }
| ExprStmt ';' { $1 }
| FunctionCall ';' { $1 }
| AssignExpr ';' { Fix $ ExprStmt $1 }
| ExprStmt ';' { Fix $ ExprStmt $1 }
| FunctionCall ';' { Fix $ ExprStmt $1 }
| break ';' { Fix $ Break }
| goto ID_CONST ';' { Fix $ Goto $2 }
| ID_CONST ':' Stmt { Fix $ Label $1 $3 }
Expand All @@ -349,7 +349,7 @@ ForStmt

ForInit :: { StringNode }
ForInit
: AssignExpr ';' { $1 }
: AssignExpr ';' { Fix $ ExprStmt $1 }
| VarDeclStmt { $1 }

ForNext :: { StringNode }
Expand Down Expand Up @@ -572,7 +572,7 @@ EnumeratorName

AggregateDecl :: { StringNode }
AggregateDecl
: AggregateType ';' { $1 }
: AggregateType ';' { Fix $ AggregateDecl $1 }
| typedef AggregateType ID_SUE_TYPE ';' { Fix $ Typedef $2 $3 }

AggregateType :: { StringNode }
Expand Down
Loading