diff options
author | Adrian Thurston <thurston@complang.org> | 2012-07-02 10:28:14 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-07-02 10:28:14 -0400 |
commit | 4aa97741c466dd8946ee9206c12afa7743fc7615 (patch) | |
tree | ed074f1698a9bda8ee7d92c8fef25162c01a4ce3 | |
parent | 061b9cc63c351d6462dddccc5021360384266959 (diff) | |
download | colm-4aa97741c466dd8946ee9206c12afa7743fc7615.tar.gz |
added a static member constructor for LangStmt
-rw-r--r-- | src/lmparse.kl | 42 | ||||
-rw-r--r-- | src/parsetree.h | 176 |
2 files changed, 164 insertions, 54 deletions
diff --git a/src/lmparse.kl b/src/lmparse.kl index 209b0a8e..3a3b8013 100644 --- a/src/lmparse.kl +++ b/src/lmparse.kl @@ -210,7 +210,7 @@ global_def: KW_Export var_def opt_def_init LangVarRef *varRef = new LangVarRef( $2->objField->loc, new QualItemVect, $2->objField->name ); - $$->stmt = new LangStmt( $2->objField->loc, + $$->stmt = LangStmt::cons( $2->objField->loc, $3->assignType, varRef, $3->expr ); } }; @@ -237,7 +237,7 @@ global_def: KW_Global var_def opt_def_init LangVarRef *varRef = new LangVarRef( $2->objField->loc, new QualItemVect, $2->objField->name ); - $$->stmt = new LangStmt( $2->objField->loc, + $$->stmt = LangStmt::cons( $2->objField->loc, $3->assignType, varRef, $3->expr ); } }; @@ -1367,33 +1367,33 @@ statement: var_def opt_def_init LangVarRef *varRef = new LangVarRef( $1->objField->loc, new QualItemVect, $1->objField->name ); - $$->stmt = new LangStmt( $1->objField->loc, + $$->stmt = LangStmt::cons( $1->objField->loc, $2->assignType, varRef, $2->expr ); } }; statement: var_ref '=' code_expr final { - $$->stmt = new LangStmt( $2->loc, LangStmt::AssignType, $1->varRef, $3->expr ); + $$->stmt = LangStmt::cons( $2->loc, LangStmt::AssignType, $1->varRef, $3->expr ); }; statement: KW_Print '(' code_expr_list ')' final { - $$->stmt = new LangStmt( $1->loc, LangStmt::PrintType, $3->exprVect ); + $$->stmt = LangStmt::cons( $1->loc, LangStmt::PrintType, $3->exprVect ); }; statement: KW_PrintXMLAC '(' code_expr_list ')' final { - $$->stmt = new LangStmt( $1->loc, LangStmt::PrintXMLACType, $3->exprVect ); + $$->stmt = LangStmt::cons( $1->loc, LangStmt::PrintXMLACType, $3->exprVect ); }; statement: KW_PrintXML '(' code_expr_list ')' final { - $$->stmt = new LangStmt( $1->loc, LangStmt::PrintXMLType, $3->exprVect ); + $$->stmt = LangStmt::cons( $1->loc, LangStmt::PrintXMLType, $3->exprVect ); }; statement: KW_PrintStream '(' code_expr_list ')' final { - $$->stmt = new LangStmt( $1->loc, LangStmt::PrintStreamType, $3->exprVect ); + $$->stmt = LangStmt::cons( $1->loc, LangStmt::PrintStreamType, $3->exprVect ); }; statement: code_expr final { - $$->stmt = new LangStmt( InputLoc(), LangStmt::ExprType, $1->expr ); + $$->stmt = LangStmt::cons( InputLoc(), LangStmt::ExprType, $1->expr ); }; statement: if_stmt final { @@ -1401,11 +1401,11 @@ statement: if_stmt }; statement: KW_Reject final { - $$->stmt = new LangStmt( $1->loc, LangStmt::RejectType ); + $$->stmt = LangStmt::cons( $1->loc, LangStmt::RejectType ); }; statement: KW_While scope_push code_expr block_or_single scope_pop final { - $$->stmt = new LangStmt( LangStmt::WhileType, $3->expr, $4->stmtList ); + $$->stmt = LangStmt::cons( LangStmt::WhileType, $3->expr, $4->stmtList ); }; for_scope: TK_Word ':' type_ref KW_In iter_call block_or_single @@ -1420,7 +1420,7 @@ for_scope: TK_Word ':' type_ref KW_In iter_call block_or_single ObjField *iterField = new ObjField( $1->loc, (TypeRef*)0, $1->data ); pd->curLocalFrame->insertField( $1->data, iterField ); - $$->stmt = new LangStmt( $1->loc, LangStmt::ForIterType, + $$->stmt = LangStmt::cons( $1->loc, LangStmt::ForIterType, iterField, $3->typeRef, $5->langTerm, $6->stmtList ); }; @@ -1431,15 +1431,15 @@ statement: KW_For scope_push for_scope scope_pop statement: KW_Return code_expr final { - $$->stmt = new LangStmt( $1->loc, LangStmt::ReturnType, $2->expr ); + $$->stmt = LangStmt::cons( $1->loc, LangStmt::ReturnType, $2->expr ); }; statement: KW_Break final { - $$->stmt = new LangStmt( LangStmt::BreakType ); + $$->stmt = LangStmt::cons( LangStmt::BreakType ); }; statement: KW_Yield var_ref final { - $$->stmt = new LangStmt( LangStmt::YieldType, $2->varRef ); + $$->stmt = LangStmt::cons( LangStmt::YieldType, $2->varRef ); }; statement: var_ref TK_LtLt accumulate final { @@ -1448,7 +1448,7 @@ statement: var_ref TK_LtLt accumulate ParserText *parserText = new ParserText( $2->loc, nspace, region, replItemList ); pd->parserTextList.append( parserText ); - $$->stmt = new LangStmt( LangStmt::ParserType, $1->varRef, parserText ); + $$->stmt = LangStmt::cons( LangStmt::ParserType, $1->varRef, parserText ); }; statement: KW_Send var_ref accumulate final { @@ -1457,7 +1457,7 @@ statement: KW_Send var_ref accumulate ParserText *parserText = new ParserText( $1->loc, nspace, region, replItemList ); pd->parserTextList.append( parserText ); - $$->stmt = new LangStmt( LangStmt::ParserType, $2->varRef, parserText ); + $$->stmt = LangStmt::cons( LangStmt::ParserType, $2->varRef, parserText ); }; nonterm opt_require_stmt uses statement; @@ -1465,7 +1465,7 @@ nonterm opt_require_stmt uses statement; opt_require_stmt: scope_push require_pattern lang_stmt_list scope_pop final { - $$->stmt = new LangStmt( LangStmt::IfType, $2->expr, $3->stmtList, 0 ); + $$->stmt = LangStmt::cons( LangStmt::IfType, $2->expr, $3->stmtList, 0 ); }; opt_require_stmt: final { @@ -1522,7 +1522,7 @@ nonterm if_stmt uses statement; if_stmt: KW_If scope_push code_expr block_or_single scope_pop elsif_list final { - $$->stmt = new LangStmt( LangStmt::IfType, $3->expr, $4->stmtList, $6->stmt ); + $$->stmt = LangStmt::cons( LangStmt::IfType, $3->expr, $4->stmtList, $6->stmt ); }; nonterm elsif_list @@ -1551,7 +1551,7 @@ nonterm elsif_clause elsif_clause: KW_Elsif scope_push code_expr block_or_single scope_pop final { - $$->stmt = new LangStmt( LangStmt::IfType, $3->expr, $4->stmtList, 0 ); + $$->stmt = LangStmt::cons( LangStmt::IfType, $3->expr, $4->stmtList, 0 ); }; nonterm optional_else @@ -1562,7 +1562,7 @@ nonterm optional_else optional_else: KW_Else scope_push block_or_single scope_pop final { - $$->stmt = new LangStmt( LangStmt::ElseType, $3->stmtList ); + $$->stmt = LangStmt::cons( LangStmt::ElseType, $3->stmtList ); }; optional_else: diff --git a/src/parsetree.h b/src/parsetree.h index 7f70dbfe..96f96fdf 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -2318,53 +2318,163 @@ struct LangStmt ParserType }; - LangStmt( const InputLoc &loc, Type type, FieldInitVect *fieldInitVect ) : - loc(loc), type(type), varRef(0), expr(0), fieldInitVect(fieldInitVect), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type, FieldInitVect *fieldInitVect ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->varRef = (0); + s->expr = (0); + s->fieldInitVect = (fieldInitVect); + s->next = (0); + return s; + } - LangStmt( const InputLoc &loc, Type type, ExprVect *exprPtrVect ) : - loc(loc), type(type), varRef(0), expr(0), exprPtrVect(exprPtrVect), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type, ExprVect *exprPtrVect ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->varRef = (0); + s->expr = (0); + s->exprPtrVect = (exprPtrVect); + s->next = (0); + return s; + } - LangStmt( const InputLoc &loc, Type type, LangExpr *expr ) : - loc(loc), type(type), varRef(0), expr(expr), exprPtrVect(0), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type, LangExpr *expr ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->varRef = (0); + s->expr = (expr); + s->exprPtrVect = (0); + s->next = (0); + return s; + } - LangStmt( Type type, LangVarRef *varRef ) : - type(type), varRef(varRef), expr(0), exprPtrVect(0), next(0) {} + static LangStmt *cons( Type type, LangVarRef *varRef ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->varRef = (varRef); + s->expr = (0); + s->exprPtrVect = (0); + s->next = (0); + return s; + } - LangStmt( const InputLoc &loc, Type type, ObjField *objField ) : - loc(loc), type(type), varRef(0), objField(objField), expr(0), - exprPtrVect(0), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type, ObjField *objField ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->varRef = (0); + s->objField = (objField); + s->expr = (0); + s->exprPtrVect = (0); + s->next = (0); + return s; + } - LangStmt( const InputLoc &loc, Type type, LangVarRef *varRef, LangExpr *expr ) : - loc(loc), type(type), varRef(varRef), expr(expr), exprPtrVect(0), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type, LangVarRef *varRef, LangExpr *expr ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->varRef = (varRef); + s->expr = (expr); + s->exprPtrVect = (0); + s->next = (0); + return s; + } - LangStmt( Type type, LangExpr *expr, StmtList *stmtList ) : - type(type), expr(expr), stmtList(stmtList), next(0) {} + static LangStmt *cons( Type type, LangExpr *expr, StmtList *stmtList ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->expr = (expr); + s->stmtList = (stmtList); + s->next = (0); + return s; + } - LangStmt( Type type, StmtList *stmtList ) : - type(type), stmtList(stmtList), next(0) {} + static LangStmt *cons( Type type, StmtList *stmtList ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->stmtList = (stmtList); + s->next = (0); + return s; + } - LangStmt( Type type, LangExpr *expr, StmtList *stmtList, LangStmt *elsePart ) : - type(type), expr(expr), stmtList(stmtList), elsePart(elsePart), next(0) {} + static LangStmt *cons( Type type, LangExpr *expr, StmtList *stmtList, LangStmt *elsePart ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->expr = (expr); + s->stmtList = (stmtList); + s->elsePart = (elsePart); + s->next = (0); + return s; + } - LangStmt( const InputLoc &loc, Type type ) : - loc(loc), type(type), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->next = (0); + return s; + } - LangStmt( Type type, LangVarRef *varRef, Replacement *replacement ) : - type(type), varRef(varRef), expr(0), replacement(replacement), - exprPtrVect(0), next(0) {} + static LangStmt *cons( Type type, LangVarRef *varRef, Replacement *replacement ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->varRef = (varRef); + s->expr = (0); + s->replacement = (replacement); + s->exprPtrVect = (0); + s->next = (0); + return s; + } - LangStmt( Type type, LangVarRef *varRef, ParserText *parserText ) : - type(type), varRef(varRef), expr(0), parserText(parserText), - exprPtrVect(0), next(0) {} + static LangStmt *cons( Type type, LangVarRef *varRef, ParserText *parserText ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->varRef = (varRef); + s->expr = (0); + s->parserText = (parserText); + s->exprPtrVect = (0); + s->next = (0); + return s; + } /* ForIterType */ - LangStmt( const InputLoc &loc, Type type, ObjField *objField, - TypeRef *typeRef, LangTerm *langTerm, StmtList *stmtList ) : - loc(loc), type(type), langTerm(langTerm), objField(objField), typeRef(typeRef), - stmtList(stmtList), next(0) {} + static LangStmt *cons( const InputLoc &loc, Type type, ObjField *objField, + TypeRef *typeRef, LangTerm *langTerm, StmtList *stmtList ) + { + LangStmt *s = new LangStmt; + s->loc = (loc); + s->type = (type); + s->langTerm = (langTerm); + s->objField = (objField); + s->typeRef = (typeRef); + s->stmtList = (stmtList); + s->next = (0); + return s; + } - LangStmt( Type type ) : - type(type), next(0) {} + static LangStmt *cons( Type type ) + { + LangStmt *s = new LangStmt; + s->type = (type); + s->next = (0); + return s; + } void resolve( Compiler *pd ) const; void resolveParserItems( Compiler *pd ) const; |