From 239f0374eed49f6883395b8cb4ba1f4520e7eff3 Mon Sep 17 00:00:00 2001 From: Nathan R Date: Fri, 23 Jul 2021 19:32:49 +0200 Subject: [PATCH] Added a new function newNullObject() to correct an assertion problem --- ccmeta.leg | 116 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/ccmeta.leg b/ccmeta.leg index 57a8cba..4c6a80f 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -40,7 +40,7 @@ _DO(C_aggregate) _DO(C_attribute) _DO(C_postfix) _DO(C_compound) _DO(C_functionDef) \ _DO(C_exprStatement) _DO(C_switch) _DO(C_goto) _DO(C_continue) _DO(C_break) _DO(C_return) \ _DO(C_case) _DO(C_default) _DO(C_label) _DO(C_labelDeclaration) _DO(C_structSpec) \ - _DO(C_structDeclarator) _DO(C_enumSpec) _DO(C_enum) + _DO(C_structDeclarator) _DO(C_enumSpec) _DO(C_enum) _DO(NullObject) typedef enum { t_UNDEFINED=0, @@ -254,6 +254,11 @@ oop newMap(oop value) return map; } +oop newNullObject() { + oop object = newObject(NullObject_proto); + return object; +} + oop new_C_if(oop ifTok, oop lParen, oop condition, oop rParen, oop consequent, oop elseTok, oop alternate) { oop obj = newObject(C_if_proto); @@ -872,6 +877,7 @@ oop new_C_attributeSpec(oop attributeTok, oop llParen, oop lrParen, oop attribut map_set(object, attributeL_symbol, attributeList); map_set(object, rlparen_symbol, rlParen); map_set(object, rrparen_symbol, rrParen); + printf("Fin\n"); return object; } @@ -1070,7 +1076,7 @@ error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 # 6.4.2.1 -idOpt = id #| TODO : End parsing | {$$=0} +idOpt = id | {$$=newNullObject()} id = { $$= new_C_id(yytext) } - ID = #| TODO : &{ !intern(yytext)->isKeyword } @@ -1201,7 +1207,7 @@ primaryExpression = stringLiteral | constant | id # 6.5.2 postfixExpression = o:LPAREN l:typeName p:RPAREN - a:LCURLY r:initializerList ( c:COMMA | {c=0} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) } + a:LCURLY r:initializerList ( c:COMMA | {c=newNullObject()} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) } | l:primaryExpression ( o:LBRACKET r:expression p:RBRACKET { l= new_C_index(l, o, r, p) } | o:LPAREN r:argumentExpressionList p:RPAREN { l= new_C_call(l, o, r, p) } @@ -1223,10 +1229,10 @@ unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) } | o:DEC x:unaryExpression { $$= new_C_prefix(o, x) } | o:unaryOperator x:castExpression { $$= new_C_unary(o, x) } | s:SIZEOF ( l:LPAREN t:typeName r:RPAREN { $$= new_C_sizeOf(s, l, t, r) } - | x:unaryExpression { $$= new_C_sizeOf(s, 0, x, 0) } + | x:unaryExpression { $$= new_C_sizeOf(s, newNullObject(), x, newNullObject()) } ) | s:ALIGNOF ( l:LPAREN t:typeName r:RPAREN { $$= new_C_alignOf(s, l, t, r) } - | x:unaryExpression { $$= new_C_alignOf(s, 0, x, 0) } + | x:unaryExpression { $$= new_C_alignOf(s, newNullObject(), x, newNullObject()) } ) &{gnu} | asmExpr &{gnu} | postfixExpression @@ -1315,13 +1321,13 @@ logicalOrExpression = l:logicalAndExpression conditionalExpression = l:logicalOrExpression ( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= new_C_conditional(l, q, m, c, r) } - | q:QUESTION c:COLON r:conditionalExpression &{gnu} { $$= new_C_conditional(l, q, 0, c, r) } + | q:QUESTION c:COLON r:conditionalExpression &{gnu} { $$= new_C_conditional(l, q, newNullObject(), c, r) } | { $$= l } ) # 6.5.16 -assignmentExpressionOpt = assignmentExpression | {$$=0} +assignmentExpressionOpt = assignmentExpression | {$$=newNullObject()} assignmentExpression = l:unaryExpression o:assignmentOperator r:assignmentExpression { $$= new_C_binary(l, o, r) } | conditionalExpression @@ -1336,7 +1342,7 @@ expression = l:assignmentExpression ( o:COMMA r:assignmentExpression { l= new_C_binary(l, o, r) } )* { $$= l } -expressionOpt = expression | { $$= 0 } +expressionOpt = expression | { $$= newNullObject() } constantExpression = conditionalExpression @@ -1396,15 +1402,15 @@ typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UN structOrUnionSpecifier = s:structOrUnion # An attribute specifier list may appear as part of a struct, union or enum specifier. It may go # either immediately after the struct, union or enum keyword... - ( a:attributeSpecifiers &{gnu} | {a=0} ) + ( a:attributeSpecifiers &{gnu} | {a=newNullObject()} ) ( i:idOpt ( @{ C_scopeBegin() } l:LCURLY d:structDeclarationList r:RCURLY @{ C_scopeEnd() } | &{ C_scopeAbort() } ) # ..., or after the closing brace. - ( b:attributeSpecifiers &{gnu} | {b=0} ) - | i:id {l=d=r=b=0} + ( b:attributeSpecifiers &{gnu} | {b=newNullObject()} ) + | i:id {l=d=r=b=newNullObject()} ) { $$= new_C_structSpec(s, a, i, l, d, r, b) } structOrUnion = STRUCT | UNION @@ -1412,7 +1418,7 @@ structOrUnion = STRUCT | UNION structDeclarationList = d:structDeclaration { listWith(d) } ( d:structDeclaration { listAppend(d) } )* { $$= listEnd() } - | &{gnu} { $$= 0 } + | &{gnu} { $$= newNullObject() } structDeclaration = s:specifierQualifierList d:structDeclaratorList t:SEMI ( &SEMI { listWith(t) } @@ -1430,10 +1436,10 @@ specifierQualifierList = @{ int specified= 0 } { listBegin() } structDeclaratorList = d:structDeclarator { listWith(d) } ( c:COMMA d:structDeclarator { listAppend2(c, d) } )* { $$= listEnd() } - | &{gnu} { $$= 0 } + | &{gnu} { $$= newNullObject() } -structDeclarator = ( c:COLON e:constantExpression { d= new_C_structDeclarator(0, c, e) } - | d:declarator ( c:COLON e:constantExpression | {c=e=0} ) { d= new_C_structDeclarator(d, c, e) } +structDeclarator = ( c:COLON e:constantExpression { d= new_C_structDeclarator(newNullObject(), c, e) } + | d:declarator ( c:COLON e:constantExpression | {c=e=newNullObject()} ) { d= new_C_structDeclarator(d, c, e) } ) # An attribute specifier list may appear immediately before the comma, = or semicolon terminating the declaration of an identifier ( a:attributeSpecifiers { d= new_C_attribution(d, a) } @@ -1443,7 +1449,7 @@ structDeclarator = ( c:COLON e:constantExpression { d= new_C_st enumSpecifier = e:ENUM ( i:idOpt l:LCURLY m:enumeratorList r:RCURLY { $$= new_C_enumSpec(e, i, l, m, r) } - | i:id { $$= new_C_enumSpec(e, i, 0, 0, 0) } + | i:id { $$= new_C_enumSpec(e, i, newNullObject(), newNullObject(), newNullObject()) } ) enumeratorList = e:enumerator { listWith(e) } @@ -1457,7 +1463,7 @@ enumerator = i:id # enumeration constant, before =, if present. ( a:attributeSpecifier &{gnu} { i= new_C_attribution(i, a) } )* - ( a:ASSIGN e:constantExpression | {a=e=0} ) { $$= new_C_enumerator(i, a, e) } + ( a:ASSIGN e:constantExpression | {a=e=newNullObject()} ) { $$= new_C_enumerator(i, a, e) } # 6.7.3 @@ -1489,22 +1495,22 @@ directDeclarator = ( l:LPAREN d:declarator r:RPAREN { d= new_C_subexpr(l, d, @{ C_scopeEnd() } | l:LPAREN p:identifierListOpt r:RPAREN { d= new_C_call (d, l, p, r) } @{ C_scopeEnd() } - | l:LBRACKET ( s:STATIC q:typeQualifierListOpt {t=0} e:assignmentExpression - | {s=0} q:typeQualifierList t:STATIC e:assignmentExpressionOpt - | {s=0} q:typeQualifierListOpt t:STAR {e=0} - | {s=0} q:typeQualifierListOpt {t=0} e:assignmentExpressionOpt ) r:RBRACKET { d= new_C_array(d, l, s, q, t, e, r) } + | l:LBRACKET ( s:STATIC q:typeQualifierListOpt {t=newNullObject()} e:assignmentExpression + | {s=newNullObject()} q:typeQualifierList t:STATIC e:assignmentExpressionOpt + | {s=newNullObject()} q:typeQualifierListOpt t:STAR {e=newNullObject()} + | {s=newNullObject()} q:typeQualifierListOpt {t=newNullObject()} e:assignmentExpressionOpt ) r:RBRACKET { d= new_C_array(d, l, s, q, t, e, r) } @{ C_scopeEnd() } | &{ C_scopeAbort() } ) )* { $$= d } -typeQualifierListOpt = typeQualifierList | {$$=0} +typeQualifierListOpt = typeQualifierList | {$$=newNullObject()} typeQualifierList = { listBegin() } ( t:typeQualifier { listAppend(t) } )* { $$= listEnd() } -parameterTypeListOpt = parameterTypeList | {$$=0} +parameterTypeListOpt = parameterTypeList | {$$=newNullObject()} parameterTypeList = p:parameterList ( c:COMMA v:ELLIPSIS { List_addLast(p, c); List_addLast(p, v) } @@ -1527,7 +1533,7 @@ parameterDeclarationSpecifiers | s:functionSpecifier { listAppend(s) } )+ { $$= listEnd() } -identifierListOpt = identifierList | {$$=0} +identifierListOpt = identifierList | {$$=newNullObject()} identifierList = i:id { listWith(i) } ( c:COMMA i:id { listAppend2(c, i) } @@ -1535,9 +1541,9 @@ identifierList = i:id { listWith(i) } # 6.7.6 -typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, 0) } +typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, newNullObject()) } -abstractDeclaratorOpt = abstractDeclarator | {$$=0} +abstractDeclaratorOpt = abstractDeclarator | {$$=newNullObject()} abstractDeclarator = p:STAR q:typeQualifierList d:abstractDeclaratorOpt { $$= new_C_deref(p, q, d) } | p:BXOR q:typeQualifierList d:abstractDeclaratorOpt &{apl} { $$= new_C_block(p, q, d) } @@ -1545,13 +1551,13 @@ abstractDeclarator = p:STAR q:typeQualifierList d:abstractDeclaratorOpt { $$= directAbstractDeclarator= @{int nonEmpty= 0} ( l:LPAREN d:abstractDeclarator r:RPAREN @{++nonEmpty} { d= new_C_subexpr(l, d, r) } - | {d=0} + | {d=newNullObject()} ) ( l:LPAREN p:parameterTypeListOpt r:RPAREN @{++nonEmpty} { d= new_C_call (d, l, p, r) } | l:LBRACKET - ( s:STATIC q:typeQualifierListOpt {t=0} e:assignmentExpression - | {s=0} q:typeQualifierList t:STATIC e:assignmentExpressionOpt - | {s=0} q:typeQualifierListOpt t:STAR {e=0} - | {s=0} q:typeQualifierListOpt {t=0} e:assignmentExpressionOpt + ( s:STATIC q:typeQualifierListOpt {t=newNullObject()} e:assignmentExpression + | {s=newNullObject()} q:typeQualifierList t:STATIC e:assignmentExpressionOpt + | {s=newNullObject()} q:typeQualifierListOpt t:STAR {e=newNullObject()} + | {s=newNullObject()} q:typeQualifierListOpt {t=newNullObject()} e:assignmentExpressionOpt ) r:RBRACKET @{++nonEmpty} { d= new_C_array(d, l, s, q, t, e, r) } )* &{nonEmpty} { $$= d } @@ -1559,13 +1565,13 @@ directAbstractDeclarator= @{int nonEmpty= 0} typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } - | t:TYPEOF l:LPAREN - ( x:expression r:RPAREN { $$= new_C_typeOf(t, l, 0, x, r) } - | x:typeName r:RPAREN { $$= new_C_typeOf(t, l, x, 0, r) } + ( x:expression r:RPAREN { $$= new_C_typeOf(t, l, newNullObject(), x, r) } + | x:typeName r:RPAREN { $$= new_C_typeOf(t, l, x, newNullObject(), r) } ) &{gnu} # 6.7.8 -initializer = l:LCURLY i:initializerList ( c:COMMA | {c=0} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } +initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) } | assignmentExpression initializerList = { listBegin() } @@ -1575,16 +1581,16 @@ initializerList = { listBegin() } ( d:designation { listAppend(d) } )? i:initializer { listAppend(i) } )* { $$= listEnd() } - | &{gnu} { $$= 0 } + | &{gnu} { $$= newNullObject() } -designation = ( d:designatorList ( a:ASSIGN | {a=0} &{gnu} ) +designation = ( d:designatorList ( a:ASSIGN | {a=newNullObject()} &{gnu} ) | d:id a:COLON &{gnu} ) { $$= new_C_designation(d, a) } designatorList = { listBegin() } - ( l:LBRACKET x:constantExpression r:RBRACKET { listAppend(new_C_index(0, l, x, r)) } - | l:LBRACKET x:constantRange r:RBRACKET &{gnu} { listAppend(new_C_index(0, l, x, r)) } - | l:DOT x:id { listAppend(new_C_binary(0, l, x)) } + ( l:LBRACKET x:constantExpression r:RBRACKET { listAppend(new_C_index(newNullObject(), l, x, r)) } + | l:LBRACKET x:constantRange r:RBRACKET &{gnu} { listAppend(new_C_index(newNullObject(), l, x, r)) } + | l:DOT x:id { listAppend(new_C_binary(newNullObject(), l, x)) } )+ { $$= listEnd() } ### A.2.3 Statements @@ -1602,7 +1608,7 @@ statement = expressionStatement labeledStatement = i:id c:COLON # an attribute specifier list may appear after the colon following a label, other than a case or default label - ( a:attributeSpecifiers &{gnu} | {a=0} ) + ( a:attributeSpecifiers &{gnu} | {a=newNullObject()} ) s:statement { $$= new_C_label(i, c, a, s) } | c:CASE x:constantExpression d:COLON s:statement { $$= new_C_case(c, x, d, s) } | c:CASE x:constantRange d:COLON s:statement &{gnu} { $$= new_C_case(c, x, d, s) } @@ -1631,7 +1637,7 @@ expressionStatement = SEMI # 6.8.4 selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement - ( e:ELSE t:statement | {e=t=0} ) { $$= new_C_if(i, l, x, r, s, e, t) } + ( e:ELSE t:statement | {e=t=newNullObject()} ) { $$= new_C_if(i, l, x, r, s, e, t) } | s:SWITCH l:LPAREN x:expression r:RPAREN t:statement { $$= new_C_switch(s, l, x, r, t) } # 6.8.5 @@ -1641,11 +1647,11 @@ iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$= | f:FOR l:LPAREN a:expressionOpt t:SEMI b:expressionOpt u:SEMI c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, t, b, u, c, r, s) } | f:FOR l:LPAREN a:declaration b:expressionOpt u:SEMI - c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, 0, b, u, c, r, s) } + c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, newNullObject(), b, u, c, r, s) } # 6.8.6 -jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, 0, i, t) } +jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, newNullObject(), i, t) } | c:CONTINUE t:SEMI { $$= new_C_continue(c, t) } | b:BREAK t:SEMI { $$= new_C_break(b, t) } | r:RETURN x:expressionOpt t:SEMI { $$= new_C_return(r, x, t) } @@ -1659,7 +1665,6 @@ translationUnit = externalDeclaration+ externalDeclaration = { yylval = newComment(yytext); } | ( SEMI &{gnu} - | c:constant { yylval = c; } #################| TODO | declaration | functionDefinition #| | meta @@ -1667,7 +1672,7 @@ externalDeclaration = { yylval = newComment(yytext); } ) { yylval= $$; } functionDefinition = @{ C_declarationBegin() } - ( s:functionDeclarationSpecifiers | &{gnu} {s=0} ) + ( s:functionDeclarationSpecifiers | &{gnu} {s=newNullObject()} ) d:declarator l:declarationListOpt c:compoundStatement { $$= new_C_functionDef(s, d, l, c) } @@ -1683,7 +1688,7 @@ functionDeclarationSpecifiers | s:functionSpecifier { listAppend(s) } )+ { $$= listEnd() } -declarationListOpt = declarationList | {$$=0} +declarationListOpt = declarationList | {$$=newNullObject()} declarationList = d:declaration { listWith(d); //TODO $$= listWith(d) } ( d:declaration { listAppend(d) } @@ -1722,7 +1727,7 @@ attribute = n:name ( l:LPAREN { listBegin() } )* )? r:RPAREN { p= listEnd() } - | {l=p=r=0} + | {l=p=r=newNullObject()} ) { $$= new_C_attribute(n, l, p, r) } constantRange = a:constantExpression e:ELLIPSIS b:constantExpression { $$= new_C_range(a, e, b) } @@ -1737,7 +1742,7 @@ localLabelDeclaration = l:LABEL &{gnu} { listBegin() } asm = a:ASM l:LPAREN s:stringLiteral r:RPAREN { $$= new_C_asm(a, l, s, r) } -asmExpr = a:ASM ( v:VOLATILE | {v=0} ) ( g:GOTO | {g=0} ) +asmExpr = a:ASM ( v:VOLATILE | {v=newNullObject()} ) ( g:GOTO | {g=newNullObject()} ) l:LPAREN s:stringLiteral { listBegin() } ( c:COLON { listAppend(c) } ( p:asmExprArgs { listAppend(p) } @@ -1761,7 +1766,7 @@ asmExprArgs = a:asmExprArg { listWith(a) } ( c:COMMA a:asmExprArg { listAppend2(c, a) } )* { $$= listEnd() } -asmExprArg = s:stringLiteral ( l:LPAREN e:expression r:RPAREN | {l=e=r=0} ){ $$= new_C_asmExprArg(s, l, e, r) } +asmExprArg = s:stringLiteral ( l:LPAREN e:expression r:RPAREN | {l=e=r=newNullObject()} ){ $$= new_C_asmExprArg(s, l, e, r) } stringLiteralList = s:stringLiteral { listWith(s) } ( c:COMMA s:stringLiteral { listAppend2(c, s) } @@ -3017,6 +3022,8 @@ void outputNode(oop node) case t_C_id: outputNode(map_get(node, identifier_symbol)); break; + case t_NullObject: + break; case t_C_if: outputNode(map_get(node, if_symbol)); outputNode(map_get(node, lparen_symbol)); @@ -3353,6 +3360,8 @@ void outputTree(oop node, int depth) printSpace(depth); switch (proto_number) { case t_Comment: + printf("COMMENT : "); + outputValue(map_get(node, text_symbol)); break; case t_Token: printf("TOKEN : "); @@ -3374,6 +3383,9 @@ void outputTree(oop node, int depth) printf("ID : "); outputValue(map_get(node, identifier_symbol)); break; + case t_NullObject: + printf("\r"); + break; case t_C_if: outputTree(map_get(node, if_symbol), depth); outputTree(map_get(node, lparen_symbol), depth+3); @@ -3542,12 +3554,13 @@ void outputTree(oop node, int depth) outputTree(map_get(node, semicolon_symbol), depth+3); break; case t_C_return: + printf("Salut"); outputTree(map_get(node, returnTok_symbol), depth); outputTree(map_get(node, expression_symbol), depth+3); outputTree(map_get(node, semicolon_symbol), depth+3); break; case t_C_exprStatement: - printf("EXPRESSION :"); + printf("EXPRESSION :\n"); outputTree(map_get(node, expression_symbol), depth+3); outputTree(map_get(node, semicolon_symbol), depth+3); break; @@ -3558,7 +3571,7 @@ void outputTree(oop node, int depth) outputTree(map_get(node, rparen_symbol), depth+3); break; case t_C_asmExpr: - printf("ASM EXPR :"); + printf("ASM EXPR :\n"); outputTree(map_get(node, asmTok_symbol), depth+3); outputTree(map_get(node, volatileTok_symbol), depth+3); outputTree(map_get(node, gotoTok_symbol), depth+3); @@ -3744,6 +3757,7 @@ int main(int argc, char **argv) while (yyparse()) { //outputNode(yylval); outputTree(yylval, 0); + printf("\n"); } return 0;