- Timestamp:
- Apr 29, 2018, 8:58:08 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 5e5dbc2
- Parents:
- db98cd5
- Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rdb98cd5 r61fc4f6 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 22 17:49:31201813 // Update Count : 8 2712 // Last Modified On : Sun Apr 29 14:04:05 2018 13 // Update Count : 830 14 14 // 15 15 … … 332 332 bool hasEllipsis; 333 333 LinkageSpec::Spec linkage; 334 Expression * asmName;334 Expression * asmName; 335 335 std::list< Attribute * > attributes; 336 336 InitializerNode * initializer; … … 417 417 Statement * build_compound( StatementNode * first ); 418 418 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 419 Statement * build_dirstmt( std::string * directive ); 419 420 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 420 421 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); -
src/Parser/StatementNode.cc
rdb98cd5 r61fc4f6 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 8 14:31:32201813 // Update Count : 3 4812 // Last Modified On : Sun Apr 29 14:21:45 2018 13 // Update Count : 353 14 14 // 15 15 … … 33 33 34 34 35 StatementNode::StatementNode( DeclarationNode * decl ) {35 StatementNode::StatementNode( DeclarationNode * decl ) { 36 36 assert( decl ); 37 DeclarationNode * agg = decl->extractAggregate();37 DeclarationNode * agg = decl->extractAggregate(); 38 38 if ( agg ) { 39 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );39 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) ); 40 40 set_next( nextStmt ); 41 41 if ( decl->get_next() ) { … … 53 53 } // StatementNode::StatementNode 54 54 55 StatementNode * StatementNode::append_last_case( StatementNode *stmt ) {56 StatementNode * prev = this;55 StatementNode * StatementNode::append_last_case( StatementNode * stmt ) { 56 StatementNode * prev = this; 57 57 // find end of list and maintain previous pointer 58 58 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr);59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr); 60 60 assert( dynamic_cast< CaseStmt * >(node->stmt.get()) ); 61 61 prev = curr; 62 62 } // for 63 63 // convert from StatementNode list to Statement list 64 StatementNode * node = dynamic_cast< StatementNode * >(prev);64 StatementNode * node = dynamic_cast< StatementNode * >(prev); 65 65 std::list< Statement * > stmts; 66 66 buildMoveList( stmt, stmts ); … … 71 71 } 72 72 73 Statement * build_expr( ExpressionNode *ctl ) {74 Expression * e = maybeMoveBuild< Expression >( ctl );73 Statement * build_expr( ExpressionNode * ctl ) { 74 Expression * e = maybeMoveBuild< Expression >( ctl ); 75 75 76 76 if ( e ) … … 80 80 } 81 81 82 Statement * build_if( IfCtl * ctl, StatementNode *then_stmt, StatementNode *else_stmt ) {83 Statement * thenb, *elseb = 0;82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 83 Statement * thenb, * elseb = 0; 84 84 std::list< Statement * > branches; 85 85 buildMoveList< Statement, StatementNode >( then_stmt, branches ); … … 116 116 } 117 117 118 Statement * build_switch( bool isSwitch, ExpressionNode *ctl, StatementNode *stmt ) {118 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) { 119 119 std::list< Statement * > branches; 120 120 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 131 131 return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches ); 132 132 } 133 Statement * build_case( ExpressionNode *ctl ) {133 Statement * build_case( ExpressionNode * ctl ) { 134 134 std::list< Statement * > branches; 135 135 return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches ); 136 136 } 137 Statement * build_default() {137 Statement * build_default() { 138 138 std::list< Statement * > branches; 139 139 return new CaseStmt( nullptr, branches, true ); 140 140 } 141 141 142 Statement * build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) {142 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) { 143 143 std::list< Statement * > branches; 144 144 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 147 147 } 148 148 149 Statement * build_for( ForCtl *forctl, StatementNode *stmt ) {149 Statement * build_for( ForCtl * forctl, StatementNode * stmt ) { 150 150 std::list< Statement * > branches; 151 151 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 157 157 } // if 158 158 159 Expression * cond = 0;159 Expression * cond = 0; 160 160 if ( forctl->condition != 0 ) 161 161 cond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) ); 162 162 163 Expression * incr = 0;163 Expression * incr = 0; 164 164 if ( forctl->change != 0 ) 165 165 incr = maybeMoveBuild< Expression >(forctl->change); … … 169 169 } 170 170 171 Statement * build_branch( BranchStmt::Type kind ) {171 Statement * build_branch( BranchStmt::Type kind ) { 172 172 Statement * ret = new BranchStmt( "", kind ); 173 173 return ret; 174 174 } 175 Statement * build_branch( std::string *identifier, BranchStmt::Type kind ) {176 Statement * ret = new BranchStmt( * identifier, kind );175 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) { 176 Statement * ret = new BranchStmt( * identifier, kind ); 177 177 delete identifier; // allocated by lexer 178 178 return ret; 179 179 } 180 Statement * build_computedgoto( ExpressionNode *ctl ) {180 Statement * build_computedgoto( ExpressionNode * ctl ) { 181 181 return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto ); 182 182 } 183 183 184 Statement * build_return( ExpressionNode *ctl ) {184 Statement * build_return( ExpressionNode * ctl ) { 185 185 std::list< Expression * > exps; 186 186 buildMoveList( ctl, exps ); … … 188 188 } 189 189 190 Statement * build_throw( ExpressionNode *ctl ) {190 Statement * build_throw( ExpressionNode * ctl ) { 191 191 std::list< Expression * > exps; 192 192 buildMoveList( ctl, exps ); … … 195 195 } 196 196 197 Statement * build_resume( ExpressionNode *ctl ) {197 Statement * build_resume( ExpressionNode * ctl ) { 198 198 std::list< Expression * > exps; 199 199 buildMoveList( ctl, exps ); … … 202 202 } 203 203 204 Statement * build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) {204 Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) { 205 205 (void)ctl; 206 206 (void)target; … … 208 208 } 209 209 210 Statement * build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) {210 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) { 211 211 std::list< CatchStmt * > branches; 212 212 buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches ); 213 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));214 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );213 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 214 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 215 215 return new TryStmt( tryBlock, branches, finallyBlock ); 216 216 } 217 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) {217 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) { 218 218 std::list< Statement * > branches; 219 219 buildMoveList< Statement, StatementNode >( body, branches ); … … 221 221 return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 222 222 } 223 Statement * build_finally( StatementNode *stmt ) {223 Statement * build_finally( StatementNode * stmt ) { 224 224 std::list< Statement * > branches; 225 225 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 304 304 } 305 305 306 Statement * build_compound( StatementNode *first ) {307 CompoundStmt * cs = new CompoundStmt();306 Statement * build_compound( StatementNode * first ) { 307 CompoundStmt * cs = new CompoundStmt(); 308 308 buildMoveList( first, cs->get_kids() ); 309 309 return cs; 310 310 } 311 311 312 Statement * build_asmstmt( bool voltile, Expression *instruction, ExpressionNode *output, ExpressionNode *input, ExpressionNode *clobber, LabelNode *gotolabels ) {312 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 313 313 std::list< Expression * > out, in; 314 314 std::list< ConstantExpr * > clob; … … 318 318 buildMoveList( clobber, clob ); 319 319 return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels ); 320 } 321 322 Statement * build_dirstmt( string * directive ) { 323 cout << *directive << endl; 324 return nullptr; 320 325 } 321 326 -
src/Parser/lex.ll
rdb98cd5 r61fc4f6 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Fri Apr 6 15:16:15201813 * Update Count : 67 012 * Last Modified On : Sun Apr 29 14:10:49 2018 13 * Update Count : 675 14 14 */ 15 15 … … 174 174 } 175 175 176 /* ignore preprocessor directives (for now) */177 ^{h_white}*"#"[^\n]*"\n" ;176 /* ignore preprocessor-style directives (for now) */ 177 ^{h_white}*"#"[^\n]*"\n" { RETURN_VAL( DIRECTIVE ); } 178 178 179 179 /* ignore C style comments (ALSO HANDLED BY CPP) */ -
src/Parser/parser.yy
rdb98cd5 r61fc4f6 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Apr 28 09:37:03201813 // Update Count : 320 112 // Last Modified On : Sun Apr 29 14:20:17 2018 13 // Update Count : 3206 14 14 // 15 15 … … 208 208 %token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname 209 209 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 210 %token<tok> DIRECTIVE 210 211 // Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and 211 212 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically … … 875 876 { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; } 876 877 | asm_statement 878 | DIRECTIVE 879 { $$ = new StatementNode( build_dirstmt( $1 ) ); } 877 880 ; 878 881
Note: See TracChangeset
for help on using the changeset viewer.