Changeset 41e16b1
- Timestamp:
- May 31, 2018, 10:22:19 PM (6 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:
- 00ac42e, 2a08c25, 7de7b52
- Parents:
- 597c34a3 (diff), 518e97d (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. - Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/Mutate.cc
r597c34a3 r41e16b1 27 27 #include "SynTree/Visitor.h" // for acceptAll 28 28 29 using namespace std; 29 namespace ControlStruct { 30 void fixLabels( std::list< Declaration * > & translationUnit ) { 31 PassVisitor<LabelFixer> lfix; 32 acceptAll( translationUnit, lfix ); 33 } 30 34 31 namespace ControlStruct { 32 void mutate( std::list< Declaration * > translationUnit ) { 33 // hoist initialization out of for statements 35 void hoistControlDecls( std::list< Declaration * > & translationUnit ) { 34 36 PassVisitor<ForExprMutator> formut; 35 36 // normalizes label definitions and generates multi-level exit labels37 PassVisitor<LabelFixer> lfix;38 39 37 mutateAll( translationUnit, formut ); 40 acceptAll( translationUnit, lfix );41 38 } 42 39 } // namespace CodeGen -
src/ControlStruct/Mutate.h
r597c34a3 r41e16b1 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Mutate.h -- 7 // Mutate.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 20 20 class Declaration; 21 21 22 /// Desugars Cforall control structures 22 23 namespace ControlStruct { 23 /// Desugars Cforall control structures 24 void mutate( std::list< Declaration* > translationUnit ); 24 /// normalizes label definitions and generates multi-level exit labels 25 void fixLabels( std::list< Declaration * > & translationUnit ); 26 27 /// hoist initialization out of for statements 28 void hoistControlDecls( std::list< Declaration * > & translationUnit ); 25 29 } // namespace ControlStruct 26 30 -
src/Parser/TypedefTable.cc
r597c34a3 r41e16b1 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 22 08:40:01201813 // Update Count : 1 2112 // Last Modified On : Wed May 30 18:04:38 2018 13 // Update Count : 148 14 14 // 15 15 … … 20 20 #if 0 21 21 #include <iostream> 22 #define debugPrint( x ) cerr << x22 #define debugPrint( code ) code 23 23 #else 24 #define debugPrint( x)24 #define debugPrint( code ) 25 25 #endif 26 26 … … 29 29 TypedefTable::~TypedefTable() { 30 30 if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) { 31 //std::cerr << "scope failure " << kindTable.currentScope() << endl;31 std::cerr << "scope failure " << kindTable.currentScope() << endl; 32 32 } // if 33 33 } // TypedefTable::~TypedefTable … … 54 54 void TypedefTable::makeTypedef( const string & name ) { 55 55 if ( ! typedefTable.exists( name ) ) { 56 typedefTable.addToEnclosingScope( name, TYPEDEFname );56 typedefTable.addToEnclosingScope( name, TYPEDEFname /*, "MTD"*/ ); 57 57 } // if 58 58 } // TypedefTable::makeTypedef 59 59 60 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) { 60 void TypedefTable::addToScope( const std::string & identifier, int kind /*, const char * locn*/ ) { 61 auto scope = kindTable.currentScope(); 62 debugPrint( cerr << "Adding at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl ); 63 auto ret = kindTable.insertAt( scope, identifier, kind ); 64 if ( ! ret.second ) ret.first->second = kind; // exists => update 65 } // TypedefTable::addToScope 66 67 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind /*, const char * locn*/ ) { 61 68 assert( kindTable.currentScope() >= 1 ); 62 69 auto scope = kindTable.currentScope() - 1; 63 debugPrint( "Adding" << identifier << " as kind " << kind << " scope " << scope << endl );70 debugPrint( cerr << "Adding2 at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl ); 64 71 auto ret = kindTable.insertAt( scope, identifier, kind ); 65 72 if ( ! ret.second ) ret.first->second = kind; // exists => update … … 68 75 void TypedefTable::enterScope() { 69 76 kindTable.beginScope(); 70 debugPrint( "Entering scope " << kindTable.currentScope() << endl ); 77 debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl ); 78 debugPrint( print() ); 71 79 } // TypedefTable::enterScope 72 80 73 81 void TypedefTable::leaveScope() { 74 debugPrint( "Leaving scope " << kindTable.currentScope() << endl ); 82 debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl ); 83 debugPrint( print() ); 75 84 kindTable.endScope(); 76 85 } // TypedefTable::leaveScope 77 86 78 // void TypedefTable::print( void ) const { 79 // for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) { 80 // debugPrint( (*i ).first << ": " ); 81 // list< Entry > declList = (*i).second; 82 // for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) { 83 // debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " ); 84 // } 85 // debugPrint( endl ); 86 // } // for 87 // } 87 void TypedefTable::print( void ) const { 88 KindTable::size_type scope = kindTable.currentScope(); 89 debugPrint( cerr << "[" << scope << "]" ); 90 for ( KindTable::const_iterator i = kindTable.begin(); i != kindTable.end(); i++ ) { 91 while ( i.get_level() != scope ) { 92 --scope; 93 debugPrint( cerr << endl << "[" << scope << "]" ); 94 } // while 95 debugPrint( cerr << " " << (*i).first << ":" << (*i).second ); 96 } // for 97 while ( scope > 0 ) { 98 --scope; 99 debugPrint( cerr << endl << "[" << scope << "]" ); 100 } 101 debugPrint( cerr << endl ); 102 } 88 103 89 104 // Local Variables: // -
src/Parser/TypedefTable.h
r597c34a3 r41e16b1 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 22 08:39:29 201813 // Update Count : 7712 // Last Modified On : Wed May 30 17:02:49 2018 13 // Update Count : 82 14 14 // 15 15 … … 32 32 void changeKind( const std::string & identifier, int kind ); 33 33 void makeTypedef( const std::string & name ); 34 void addToEnclosingScope( const std::string & identifier, int kind ); 34 void addToScope( const std::string & identifier, int kind /*, const char **/ ); 35 void addToEnclosingScope( const std::string & identifier, int kind /*, const char */ ); 35 36 36 37 void enterScope(); 37 38 void leaveScope(); 39 40 void print( void ) const; 38 41 }; // TypedefTable 39 42 -
src/Parser/parser.yy
r597c34a3 r41e16b1 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 28 17:01:36201813 // Update Count : 3 38312 // Last Modified On : Thu May 31 15:11:40 2018 13 // Update Count : 3444 14 14 // 15 15 … … 265 265 %type<sn> statement labeled_statement compound_statement 266 266 %type<sn> statement_decl statement_decl_list statement_list_nodecl 267 %type<sn> selection_statement 267 %type<sn> selection_statement if_statement 268 268 %type<sn> switch_clause_list_opt switch_clause_list 269 269 %type<en> case_value … … 332 332 %type<decl> c_declaration static_assert 333 333 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 334 %type<decl> KR_ declaration_list KR_declaration_list_opt334 %type<decl> KR_parameter_list KR_parameter_list_opt 335 335 336 336 %type<decl> parameter_declaration parameter_list parameter_type_list_opt … … 404 404 //************************* Namespace Management ******************************** 405 405 406 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols 407 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical. While it is possible to write a purely 408 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. 409 // Hence, this grammar uses the ANSI style. 410 // 411 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those 412 // introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types. This latter 413 // type name creates a third class of identifiers that must be distinguished by the scanner. 414 // 415 // Since the scanner cannot distinguish among the different classes of identifiers without some context information, it 416 // accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read. Semantic 417 // actions during the parser update this data structure when the class of identifiers change. 418 // 419 // Because the Cforall language is block-scoped, an identifier can change its class in a local scope; it must revert to 420 // its original class at the end of the block. Since type names can be local to a particular declaration, each 421 // declaration is itself a scope. This requires distinguishing between type names that are local to the current 422 // declaration scope and those that persist past the end of the declaration (i.e., names defined in "typedef" or "otype" 423 // declarations). 424 // 425 // The non-terminals "push" and "pop" denote the opening and closing of scopes. Every push must have a matching pop, 426 // although it is regrettable the matching pairs do not always occur within the same rule. These non-terminals may 427 // appear in more contexts than strictly necessary from a semantic point of view. 406 // The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname", 407 // which are lexically identical. 408 // 409 // typedef int foo; // identifier foo must now be scanned as TYPEDEFname 410 // foo f; // to allow it to appear in this context 411 // 412 // While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship 413 // between syntactic and semantic constructs. Cforall compounds this problem by introducing type names local to the 414 // scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type 415 // generators" -- parameterized types. This latter type name creates a third class of identifiers, "TYPEGENname", which 416 // must be distinguished by the lexical scanner. 417 // 418 // Since the scanner cannot distinguish among the different classes of identifiers without some context information, 419 // there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named 420 // scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For 421 // each context that introduces a name scope, a new level is created in the type table and that level is popped on 422 // exiting the scope. Since type names can be local to a particular declaration, each declaration is itself a scope. 423 // This requires distinguishing between type names that are local to the current declaration scope and those that 424 // persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations). 425 // 426 // The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in 427 // the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push 428 // around the list separator. 429 // 430 // int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) ); 431 // push pop push pop 428 432 429 433 push: … … 854 858 // | '[' push assignment_expression pop ']' 855 859 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 856 '[' push ',' tuple_expression_list pop']'857 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $ 4) ) ); }858 | '[' push assignment_expression ',' tuple_expression_list pop']'859 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $ 5) ) ); }860 '[' ',' tuple_expression_list ']' 861 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 862 | '[' push assignment_expression pop ',' tuple_expression_list ']' 863 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); } 860 864 ; 861 865 … … 909 913 '{' '}' 910 914 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 911 | '{' 912 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also 913 // requires its own scope. 914 push push 915 | '{' push 915 916 local_label_declaration_opt // GCC, local labels 916 917 statement_decl_list // C99, intermix declarations and statements 917 918 pop '}' 918 { $$ = new StatementNode( build_compound( $ 5) ); }919 { $$ = new StatementNode( build_compound( $4 ) ); } 919 920 ; 920 921 921 922 statement_decl_list: // C99 922 923 statement_decl 923 | statement_decl_list pushstatement_decl924 { if ( $1 != 0 ) { $1->set_last( $ 3); $$ = $1; } }924 | statement_decl_list statement_decl 925 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 925 926 ; 926 927 … … 940 941 $$ = new StatementNode( $2 ); 941 942 } 942 | statement pop943 | statement 943 944 ; 944 945 … … 955 956 956 957 selection_statement: 957 IF '(' push if_control_expression ')' statement %prec THEN 958 // explicitly deal with the shift/reduce conflict on if/else 959 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); } 960 | IF '(' push if_control_expression ')' statement ELSE statement 961 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 958 // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving 959 // the inherent S/R conflict with THEN/ELSE. 960 push if_statement pop 961 { $$ = $2; } 962 962 | SWITCH '(' comma_expression ')' case_clause 963 963 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 964 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA964 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 965 965 { 966 966 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); … … 974 974 | CHOOSE '(' comma_expression ')' case_clause // CFA 975 975 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 976 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA976 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 977 977 { 978 978 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); … … 981 981 ; 982 982 983 if_statement: 984 IF '(' if_control_expression ')' statement %prec THEN 985 // explicitly deal with the shift/reduce conflict on if/else 986 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 987 | IF '(' if_control_expression ')' statement ELSE statement 988 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 989 ; 990 991 983 992 if_control_expression: 984 comma_expression pop993 comma_expression 985 994 { $$ = new IfCtl( nullptr, $1 ); } 986 | c_declaration pop// no semi-colon995 | c_declaration // no semi-colon 987 996 { $$ = new IfCtl( $1, nullptr ); } 988 | cfa_declaration pop// no semi-colon997 | cfa_declaration // no semi-colon 989 998 { $$ = new IfCtl( $1, nullptr ); } 990 999 | declaration comma_expression // semi-colon separated … … 1047 1056 | DO statement WHILE '(' comma_expression ')' ';' 1048 1057 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1049 | FOR '(' push for_control_expression ')' statement 1058 | FOR '(' push for_control_expression ')' statement pop 1050 1059 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1051 1060 ; 1052 1061 1053 1062 for_control_expression: 1054 comma_expression_opt pop';' comma_expression_opt ';' comma_expression_opt1055 { $$ = new ForCtl( $1, $ 4, $6); }1063 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1064 { $$ = new ForCtl( $1, $3, $5 ); } 1056 1065 | declaration comma_expression_opt ';' comma_expression_opt // C99 1057 1066 { $$ = new ForCtl( $1, $2, $4 ); } … … 1175 1184 1176 1185 handler_clause: 1177 handler_key '(' push pushexception_declaration pop handler_predicate_opt ')' compound_statement pop1178 { $$ = new StatementNode( build_catch( $1, $ 5, $7, $9) ); }1179 | handler_clause handler_key '(' push pushexception_declaration pop handler_predicate_opt ')' compound_statement pop1180 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $ 6, $8, $10) ) ); }1186 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1187 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); } 1188 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1189 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); } 1181 1190 ; 1182 1191 … … 1282 1291 1283 1292 declaration_list_opt: // used at beginning of switch statement 1284 pop// empty1293 // empty 1285 1294 { $$ = nullptr; } 1286 1295 | declaration_list … … 1289 1298 declaration_list: 1290 1299 declaration 1291 | declaration_list pushdeclaration1292 { $$ = $1->appendList( $ 3); }1293 ; 1294 1295 KR_ declaration_list_opt: // used to declare parameter types in K&R style functions1300 | declaration_list declaration 1301 { $$ = $1->appendList( $2 ); } 1302 ; 1303 1304 KR_parameter_list_opt: // used to declare parameter types in K&R style functions 1296 1305 // empty 1297 1306 { $$ = nullptr; } 1298 | KR_ declaration_list1299 ; 1300 1301 KR_ declaration_list:1307 | KR_parameter_list 1308 ; 1309 1310 KR_parameter_list: 1302 1311 push c_declaration pop ';' 1303 1312 { $$ = $2; } 1304 | KR_ declaration_list push c_declaration pop ';'1313 | KR_parameter_list push c_declaration pop ';' 1305 1314 { $$ = $1->appendList( $3 ); } 1306 1315 ; … … 1322 1331 1323 1332 declaration: // old & new style declarations 1324 c_declaration pop';'1325 | cfa_declaration pop ';'// CFA1333 c_declaration ';' 1334 | cfa_declaration ';' // CFA 1326 1335 | static_assert 1327 1336 ; … … 1431 1440 TYPEDEF cfa_variable_specifier 1432 1441 { 1433 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1442 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ ); 1434 1443 $$ = $2->addTypedef(); 1435 1444 } 1436 1445 | TYPEDEF cfa_function_specifier 1437 1446 { 1438 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1447 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ ); 1439 1448 $$ = $2->addTypedef(); 1440 1449 } 1441 1450 | cfa_typedef_declaration pop ',' push no_attr_identifier 1442 1451 { 1443 typedefTable.addToEnclosingScope( *$5, TYPEDEFname );1452 typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ ); 1444 1453 $$ = $1->appendList( $1->cloneType( $5 ) ); 1445 1454 } … … 1452 1461 TYPEDEF type_specifier declarator 1453 1462 { 1454 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1463 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ ); 1455 1464 $$ = $3->addType( $2 )->addTypedef(); 1456 1465 } 1457 1466 | typedef_declaration pop ',' push declarator 1458 1467 { 1459 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );1468 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ ); 1460 1469 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1461 1470 } 1462 1471 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1463 1472 { 1464 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1473 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ ); 1465 1474 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1466 1475 } 1467 1476 | type_specifier TYPEDEF declarator 1468 1477 { 1469 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1478 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ ); 1470 1479 $$ = $3->addType( $1 )->addTypedef(); 1471 1480 } 1472 1481 | type_specifier TYPEDEF type_qualifier_list declarator 1473 1482 { 1474 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1483 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ ); 1475 1484 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1476 1485 } … … 1599 1608 1600 1609 forall: 1601 FORALL '(' push type_parameter_list pop')' // CFA1602 { $$ = DeclarationNode::newForall( $ 4); }1610 FORALL '(' type_parameter_list ')' // CFA 1611 { $$ = DeclarationNode::newForall( $3 ); } 1603 1612 ; 1604 1613 … … 2192 2201 type_parameter: // CFA 2193 2202 type_class no_attr_identifier_or_type_name 2194 { typedefTable.addTo EnclosingScope( *$2, TYPEDEFname); }2203 { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); } 2195 2204 type_initializer_opt assertion_list_opt 2196 2205 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2228 2237 | '|' '{' push trait_declaration_list pop '}' 2229 2238 { $$ = $4; } 2230 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'2231 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }2239 // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')' 2240 // { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; } 2232 2241 ; 2233 2242 … … 2261 2270 no_attr_identifier_or_type_name 2262 2271 { 2263 typedefTable.addToEnclosingScope( *$1, TYPEDEFname );2272 typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ ); 2264 2273 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2265 2274 } 2266 | no_attr_identifier_or_type_name '(' push type_parameter_list pop')'2267 { 2268 typedefTable.addToEnclosingScope( *$1, TYPEGENname );2269 $$ = DeclarationNode::newTypeDecl( $1, $ 4);2275 | no_attr_identifier_or_type_name '(' type_parameter_list ')' 2276 { 2277 typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ ); 2278 $$ = DeclarationNode::newTypeDecl( $1, $3 ); 2270 2279 } 2271 2280 ; 2272 2281 2273 2282 trait_specifier: // CFA 2274 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop')' '{' '}'2275 { $$ = DeclarationNode::newTrait( $2, $ 5, 0 ); }2276 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop')' '{' push trait_declaration_list pop '}'2277 { $$ = DeclarationNode::newTrait( $2, $ 5, $10); }2283 TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2284 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 2285 | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2286 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 2278 2287 ; 2279 2288 … … 2313 2322 2314 2323 external_definition_list: 2315 external_definition 2324 push external_definition pop 2325 { $$ = $2; } 2316 2326 | external_definition_list 2317 2327 { forall = xxx; } 2318 push external_definition 2328 push external_definition pop 2319 2329 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2320 2330 ; … … 2338 2348 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2339 2349 } 2340 '{' external_definition_list_opt '}' 2350 // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope. However, 2351 // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The 2352 // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt. This 2353 // trick works for nested extern "X"s, as each one undoes itself in the nesting. 2354 '{' pop external_definition_list_opt push '}' 2341 2355 { 2342 2356 linkage = linkageStack.top(); 2343 2357 linkageStack.pop(); 2344 $$ = $ 5;2358 $$ = $6; 2345 2359 } 2346 2360 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown … … 2351 2365 | type_qualifier_list 2352 2366 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2353 push '{' external_definition_list '}'// CFA, namespace2354 { 2355 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2367 '{' external_definition_list push '}' // CFA, namespace 2368 { 2369 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2356 2370 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2357 2371 iter->addQualifiers( $1->clone() ); … … 2360 2374 xxx = false; 2361 2375 delete $1; 2362 $$ = $ 5;2376 $$ = $4; 2363 2377 } 2364 2378 | declaration_qualifier_list 2365 2379 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2366 push '{' external_definition_list '}'// CFA, namespace2367 { 2368 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2380 '{' external_definition_list '}' // CFA, namespace 2381 { 2382 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2369 2383 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2370 2384 iter->addQualifiers( $1->clone() ); … … 2373 2387 xxx = false; 2374 2388 delete $1; 2375 $$ = $ 5;2389 $$ = $4; 2376 2390 } 2377 2391 | declaration_qualifier_list type_qualifier_list … … 2380 2394 if ( $2->type->forall ) xxx = forall = true; // remember generic type 2381 2395 } 2382 push '{' external_definition_list '}'// CFA, namespace2383 { 2384 for ( DeclarationNode * iter = $ 6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2396 '{' external_definition_list '}' // CFA, namespace 2397 { 2398 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2385 2399 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2386 2400 iter->addQualifiers( $1->clone() ); … … 2391 2405 delete $1; 2392 2406 delete $2; 2393 $$ = $ 6;2407 $$ = $5; 2394 2408 } 2395 2409 ; … … 2404 2418 | function_declarator compound_statement 2405 2419 { $$ = $1->addFunctionBody( $2 ); } 2406 | KR_function_declarator KR_ declaration_list_opt compound_statement2420 | KR_function_declarator KR_parameter_list_opt compound_statement 2407 2421 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2408 2422 ; … … 2444 2458 2445 2459 // Old-style K&R function definition, OBSOLESCENT (see 4) 2446 | declaration_specifier KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2460 | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2447 2461 { 2448 2462 rebindForall( $1, $2 ); … … 2450 2464 } 2451 2465 // handles default int return type, OBSOLESCENT (see 1) 2452 | type_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2466 | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2453 2467 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2454 2468 // handles default int return type, OBSOLESCENT (see 1) 2455 | declaration_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2469 | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2456 2470 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2457 2471 // handles default int return type, OBSOLESCENT (see 1) 2458 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2472 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2459 2473 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2460 2474 ; … … 2701 2715 typedef 2702 2716 // hide type name in enclosing scope by variable name 2703 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }2717 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); } 2704 2718 | '(' paren_type ')' 2705 2719 { $$ = $2; } … … 3191 3205 '[' push cfa_abstract_parameter_list pop ']' 3192 3206 { $$ = DeclarationNode::newTuple( $3 ); } 3193 | '[' push type_specifier_nobody ELLIPSIS ']'3207 | '[' push type_specifier_nobody ELLIPSIS pop ']' 3194 3208 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3195 | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'3209 | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']' 3196 3210 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3197 3211 ; -
src/ResolvExpr/Alternative.cc
r597c34a3 r41e16b1 27 27 28 28 namespace ResolvExpr { 29 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0) {}29 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {} 30 30 31 31 Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) … … 48 48 } 49 49 50 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( other.env) {50 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) { 51 51 other.expr = nullptr; 52 52 } … … 58 58 cvtCost = other.cvtCost; 59 59 expr = other.expr; 60 env = other.env;60 env = std::move( other.env ); 61 61 other.expr = nullptr; 62 62 return *this; -
src/ResolvExpr/AlternativeFinder.cc
r597c34a3 r41e16b1 299 299 // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value 300 300 std::unique_ptr<Expression> aggrExpr( alt.expr->clone() ); 301 alt.env.apply( aggrExpr-> get_result());302 Type * aggrType = aggrExpr-> get_result();301 alt.env.apply( aggrExpr->result ); 302 Type * aggrType = aggrExpr->result; 303 303 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 304 304 aggrType = aggrType->stripReferences(); … … 306 306 } 307 307 308 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr-> get_result()) ) {308 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->result ) ) { 309 309 NameExpr nameExpr( "" ); 310 310 addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 311 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr-> get_result()) ) {311 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->result ) ) { 312 312 NameExpr nameExpr( "" ); 313 313 addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); … … 320 320 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ); 321 321 if ( ! nameExpr ) return; 322 const std::string & name = nameExpr-> get_name();322 const std::string & name = nameExpr->name; 323 323 std::list< Declaration* > members; 324 324 aggInst->lookup( name, members ); 325 325 326 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 327 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 328 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 329 renameTypes( alternatives.back().expr ); 330 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 326 for ( Declaration * decl : members ) { 327 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) { 328 // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so 329 // can't construct in place and use vector::back 330 Alternative newAlt( new MemberExpr( dwt, expr->clone() ), env, newCost ); 331 renameTypes( newAlt.expr ); 332 addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 333 alternatives.push_back( std::move(newAlt) ); 331 334 } else { 332 335 assert( false ); … … 1379 1382 Cost cost = Cost::zero; 1380 1383 Expression * newExpr = data.combine( cost ); 1381 alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) ); 1384 1385 // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so 1386 // can't construct in place and use vector::back 1387 Alternative newAlt( newExpr, env, Cost::zero, cost ); 1382 1388 PRINT( 1383 1389 std::cerr << "decl is "; … … 1388 1394 std::cerr << std::endl; 1389 1395 ) 1390 renameTypes( alternatives.back().expr ); 1391 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 1396 renameTypes( newAlt.expr ); 1397 addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 1398 alternatives.push_back( std::move(newAlt) ); 1392 1399 } // for 1393 1400 } -
src/ResolvExpr/TypeEnvironment.cc
r597c34a3 r41e16b1 50 50 } 51 51 52 EqvClass::EqvClass() : type( 0), allowWidening( true ) {52 EqvClass::EqvClass() : type( nullptr ), allowWidening( true ) { 53 53 } 54 54 … … 159 159 160 160 void TypeEnvironment::print( std::ostream &os, Indenter indent ) const { 161 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i) {162 i->print( os, indent );161 for ( const EqvClass & theClass : env ) { 162 theClass.print( os, indent ); 163 163 } // for 164 164 } -
src/SymTab/Validate.cc
r597c34a3 r41e16b1 48 48 #include "CodeGen/CodeGenerator.h" // for genName 49 49 #include "CodeGen/OperatorTable.h" // for isCtorDtor, isCtorDtorAssign 50 #include "ControlStruct/Mutate.h" // for ForExprMutator 50 51 #include "Common/PassVisitor.h" // for PassVisitor, WithDeclsToAdd 51 52 #include "Common/ScopedMap.h" // for ScopedMap … … 76 77 class SwitchStmt; 77 78 78 79 79 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } 80 80 … … 275 275 Concurrency::applyKeywords( translationUnit ); 276 276 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution 277 ControlStruct::hoistControlDecls( translationUnit ); // hoist initialization out of for statements; must happen before autogenerateRoutines 277 278 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 278 279 Concurrency::implementMutexFuncs( translationUnit ); -
src/SynTree/ReferenceToType.cc
r597c34a3 r41e16b1 50 50 51 51 namespace { 52 void doLookup( const std::list< Declaration * > &members, const std::string &name, std::list< Declaration* > &foundDecls ) {53 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i) {54 if ( (*i)->get_name()== name ) {55 foundDecls.push_back( *i);52 void doLookup( const std::list< Declaration * > & members, const std::string & name, std::list< Declaration* > & foundDecls ) { 53 for ( Declaration * decl : members ) { 54 if ( decl->name == name ) { 55 foundDecls.push_back( decl ); 56 56 } // if 57 57 } // for … … 60 60 61 61 StructInstType::StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes ) : 62 Parent( tq, baseStruct-> get_name(), attributes ), baseStruct( baseStruct ) {}62 Parent( tq, baseStruct->name, attributes ), baseStruct( baseStruct ) {} 63 63 64 64 std::string StructInstType::typeString() const { return "struct"; } … … 84 84 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 85 85 assert( baseStruct ); 86 doLookup( baseStruct-> get_members(), name, foundDecls );86 doLookup( baseStruct->members, name, foundDecls ); 87 87 } 88 88 … … 103 103 104 104 UnionInstType::UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes ) : 105 Parent( tq, baseUnion-> get_name(), attributes ), baseUnion( baseUnion ) {}105 Parent( tq, baseUnion->name, attributes ), baseUnion( baseUnion ) {} 106 106 107 107 std::string UnionInstType::typeString() const { return "union"; } … … 127 127 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const { 128 128 assert( baseUnion ); 129 doLookup( baseUnion-> get_members(), name, foundDecls );129 doLookup( baseUnion->members, name, foundDecls ); 130 130 } 131 131 -
src/main.cc
r597c34a3 r41e16b1 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 7 14:35:57201813 // Update Count : 49 212 // Last Modified On : Wed May 30 17:53:14 2018 13 // Update Count : 496 14 14 // 15 15 … … 264 264 } // if 265 265 266 PASS( " mutate", ControlStruct::mutate( translationUnit ) );266 PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) ); 267 267 PASS( "fixNames", CodeGen::fixNames( translationUnit ) ); 268 268 PASS( "genInit", InitTweak::genInit( translationUnit ) ); … … 573 573 yyin = input; 574 574 yylineno = 1; 575 typedefTable.enterScope();576 575 int parseStatus = yyparse(); 577 576 -
tools/prettyprinter/lex.ll
r597c34a3 r41e16b1 10 10 * Created On : Sat Dec 15 11:45:59 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sun Apr 15 21:28:33201813 * Update Count : 27 112 * Last Modified On : Thu May 31 08:49:58 2018 13 * Update Count : 274 14 14 */ 15 15 … … 77 77 } 78 78 79 <INITIAL,C_CODE>"//"[^\n]* "\n" {// C++ style comments79 <INITIAL,C_CODE>"//"[^\n]* { // C++ style comments 80 80 #if defined(DEBUG_ALL) | defined(DEBUG_COMMENT) 81 81 cerr << "\"//\"[^\\n]*\"\n\" : " << yytext << endl;
Note: See TracChangeset
for help on using the changeset viewer.