Changeset 1a3eab8 for src/Parser
- Timestamp:
- Apr 30, 2018, 11:59:07 AM (8 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:
- 7b45636
- Parents:
- c0453ca3 (diff), b9c432f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 6 edited
-
DeclarationNode.cc (modified) (2 diffs)
-
ParseNode.h (modified) (3 diffs)
-
StatementNode.cc (modified) (17 diffs)
-
TypeData.cc (modified) (2 diffs)
-
lex.ll (modified) (2 diffs)
-
parser.yy (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rc0453ca3 r1a3eab8 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Apr 20 22:37:20 201813 // Update Count : 106 312 // Last Modified On : Thu Apr 26 13:45:10 2018 13 // Update Count : 1064 14 14 // 15 15 … … 783 783 DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) { 784 784 if ( p ) { 785 assert( p->type->kind == TypeData::Pointer || TypeData::Reference );785 assert( p->type->kind == TypeData::Pointer || p->type->kind == TypeData::Reference ); 786 786 setBase( p->type ); 787 787 p->type = nullptr; -
src/Parser/ParseNode.h
rc0453ca3 r1a3eab8 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
rc0453ca3 r1a3eab8 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/TypeData.cc
rc0453ca3 r1a3eab8 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Apr 17 23:00:52201813 // Update Count : 60 212 // Last Modified On : Thu Apr 26 13:46:07 2018 13 // Update Count : 603 14 14 // 15 15 … … 62 62 enumeration.constants = nullptr; 63 63 enumeration.body = false; 64 break; 64 65 case Aggregate: 65 66 // aggregate = new Aggregate_t; -
src/Parser/lex.ll
rc0453ca3 r1a3eab8 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
rc0453ca3 r1a3eab8 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 17 17:10:30201813 // Update Count : 3 14412 // Last Modified On : Sun Apr 29 14:20:17 2018 13 // Update Count : 3206 14 14 // 15 15 … … 133 133 } // build_postfix_name 134 134 135 bool forall = false ;// aggregate have one or more forall qualifiers ?135 bool forall = false, xxx = false; // aggregate have one or more forall qualifiers ? 136 136 137 137 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 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 … … 282 283 %type<decl> aggregate_type aggregate_type_nobody 283 284 284 %type<decl> assertion assertion_list _opt285 %type<decl> assertion assertion_list assertion_list_opt 285 286 286 287 %type<en> bit_subrange_size_opt bit_subrange_size … … 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 … … 1866 1869 { 1867 1870 typedefTable.makeTypedef( *$3 ); 1871 if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update 1872 forall = false; // reset 1868 1873 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1869 1874 } … … 2235 2240 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2236 2241 | type_specifier identifier_parameter_declarator 2242 | assertion_list 2243 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2237 2244 ; 2238 2245 … … 2251 2258 // empty 2252 2259 { $$ = nullptr; } 2253 | assertion_list_opt assertion 2260 | assertion_list 2261 ; 2262 2263 assertion_list: // CFA 2264 assertion 2265 | assertion_list assertion 2254 2266 { $$ = $1 ? $1->appendList( $2 ) : $2; } 2255 2267 ; … … 2378 2390 external_definition_list: 2379 2391 external_definition 2380 | external_definition_list push external_definition2381 { $$ = $1 ? $1->appendList( $ 3 ) : $3; }2392 | external_definition_list { forall = xxx; } push external_definition 2393 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2382 2394 ; 2383 2395 … … 2411 2423 $$ = $2; 2412 2424 } 2413 | type_qualifier_list '{' external_definition_list '}' // CFA, namespace 2425 | type_qualifier_list 2426 { 2427 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2428 } 2429 push '{' external_definition_list '}' // CFA, namespace 2430 { 2431 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2432 iter->addQualifiers( $1->clone() ); 2433 } // for 2434 xxx = false; 2435 delete $1; 2436 $$ = $5; 2437 } 2438 | declaration_qualifier_list 2439 { 2440 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2441 } 2442 push '{' external_definition_list '}' // CFA, namespace 2443 { 2444 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2445 iter->addQualifiers( $1->clone() ); 2446 } // for 2447 xxx = false; 2448 delete $1; 2449 $$ = $5; 2450 } 2451 | declaration_qualifier_list type_qualifier_list 2452 { 2453 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2454 } 2455 push '{' external_definition_list '}' // CFA, namespace 2456 { 2457 for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2458 iter->addQualifiers( $1->clone() ); 2459 iter->addQualifiers( $2->clone() ); 2460 } // for 2461 xxx = false; 2462 delete $1; 2463 delete $2; 2464 $$ = $6; 2465 } 2414 2466 ; 2415 2467 … … 2437 2489 with_clause_opt: 2438 2490 // empty 2439 { $$ = nullptr; }2491 { $$ = nullptr; forall = false; } 2440 2492 | WITH '(' tuple_expression_list ')' 2441 { $$ = $3; }2493 { $$ = $3; forall = false; } 2442 2494 ; 2443 2495
Note:
See TracChangeset
for help on using the changeset viewer.