Changeset f271bdd
- Timestamp:
- Aug 4, 2018, 10:44:06 AM (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, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 1f32235, 4084928e, 51fcdbc7
- Parents:
- ac3362c
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rac3362c rf271bdd 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 20 14:56:30 201813 // Update Count : 85 012 // Last Modified On : Sat Aug 4 09:39:40 2018 13 // Update Count : 853 14 14 // 15 15 … … 132 132 void printOneLine( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} 133 133 134 Expression *get_expr() const { return expr.get(); } 134 135 template<typename T> 135 136 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); } … … 390 391 Statement * build_expr( ExpressionNode * ctl ); 391 392 392 struct IfCt l {393 IfCt l( DeclarationNode * decl, ExpressionNode * condition ) :393 struct IfCtrl { 394 IfCtrl( DeclarationNode * decl, ExpressionNode * condition ) : 394 395 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {} 395 396 … … 398 399 }; 399 400 400 struct ForCt l {401 ForCt l( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :401 struct ForCtrl { 402 ForCtrl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) : 402 403 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 403 ForCt l( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :404 ForCtrl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) : 404 405 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 405 406 … … 409 410 }; 410 411 411 Expression * build_if_control( IfCt l * ctl, std::list< Statement * > & init );412 Statement * build_if( IfCt l * ctl, StatementNode * then_stmt, StatementNode * else_stmt );412 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ); 413 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 413 414 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 414 415 Statement * build_case( ExpressionNode * ctl ); 415 416 Statement * build_default(); 416 Statement * build_while( IfCt l * ctl, StatementNode * stmt );417 Statement * build_while( IfCtrl * ctl, StatementNode * stmt ); 417 418 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ); 418 Statement * build_for( ForCt l * forctl, StatementNode * stmt );419 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ); 419 420 Statement * build_branch( BranchStmt::Type kind ); 420 421 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); -
src/Parser/StatementNode.cc
rac3362c rf271bdd 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 5 08:58:34201813 // Update Count : 36 212 // Last Modified On : Sat Aug 4 09:39:25 2018 13 // Update Count : 363 14 14 // 15 15 … … 78 78 } // build_expr 79 79 80 Expression * build_if_control( IfCt l * ctl, std::list< Statement * > & init ) {80 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ) { 81 81 if ( ctl->init != 0 ) { 82 82 buildMoveList( ctl->init, init ); … … 100 100 } // build_if_control 101 101 102 Statement * build_if( IfCt l * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {102 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) { 103 103 Statement * thenb, * elseb = nullptr; 104 104 std::list< Statement * > branches; … … 145 145 } // build_default 146 146 147 Statement * build_while( IfCt l * ctl, StatementNode * stmt ) {147 Statement * build_while( IfCtrl * ctl, StatementNode * stmt ) { 148 148 std::list< Statement * > branches; 149 149 buildMoveList< Statement, StatementNode >( stmt, branches ); … … 164 164 } // build_do_while 165 165 166 Statement * build_for( ForCt l * forctl, StatementNode * stmt ) {166 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ) { 167 167 std::list< Statement * > branches; 168 168 buildMoveList< Statement, StatementNode >( stmt, branches ); -
src/Parser/parser.yy
rac3362c rf271bdd 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 25 15:54:35201813 // Update Count : 3 84112 // Last Modified On : Sat Aug 4 09:38:36 2018 13 // Update Count : 3986 14 14 // 15 15 … … 186 186 } // fieldDecl 187 187 188 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, ExpressionNode * comp, ExpressionNode * inc ) { 189 return new ForCtrl( 190 distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 191 new ExpressionNode( build_binary_val( OperKinds::LThan, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ), 192 new ExpressionNode( build_binary_val( OperKinds::PlusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) ); 193 } // forCtrl 194 195 188 196 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? 189 197 … … 217 225 WaitForStmt * wfs; 218 226 Expression * constant; 219 IfCt l * ifctl;220 ForCt l * fctl;227 IfCtrl * ifctl; 228 ForCtrl * fctl; 221 229 LabelNode * label; 222 230 InitializerNode * in; … … 1049 1057 if_control_expression: 1050 1058 comma_expression 1051 { $$ = new IfCt l( nullptr, $1 ); }1059 { $$ = new IfCtrl( nullptr, $1 ); } 1052 1060 | c_declaration // no semi-colon 1053 { $$ = new IfCt l( $1, nullptr ); }1061 { $$ = new IfCtrl( $1, nullptr ); } 1054 1062 | cfa_declaration // no semi-colon 1055 { $$ = new IfCt l( $1, nullptr ); }1063 { $$ = new IfCtrl( $1, nullptr ); } 1056 1064 | declaration comma_expression // semi-colon separated 1057 { $$ = new IfCt l( $1, $2 ); }1065 { $$ = new IfCtrl( $1, $2 ); } 1058 1066 ; 1059 1067 … … 1111 1119 WHILE '(' push if_control_expression ')' statement pop 1112 1120 { $$ = new StatementNode( build_while( $4, $6 ) ); } 1121 | WHILE '(' ')' statement // CFA => while ( 1 ) 1122 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); } 1113 1123 | DO statement WHILE '(' comma_expression ')' ';' 1114 1124 { $$ = new StatementNode( build_do_while( $5, $2 ) ); } 1125 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1126 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); } 1115 1127 | FOR '(' push for_control_expression ')' statement pop 1116 1128 { $$ = new StatementNode( build_for( $4, $6 ) ); } … … 1118 1130 1119 1131 for_control_expression: 1120 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1121 { $$ = new ForCtl( $1, $3, $5 ); } 1122 | declaration comma_expression_opt ';' comma_expression_opt // C99 1123 { $$ = new ForCtl( $1, $2, $4 ); } 1132 comma_expression_opt // CFA 1133 { 1134 if ( ! $1 ) { // => for ( ;; ) 1135 $$ = new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ); 1136 } else { 1137 $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), $1->clone(), 1138 new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); 1139 } // if 1140 } 1141 | constant_expression '~' constant_expression // CFA 1142 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1143 | constant_expression '~' constant_expression '~' constant_expression // CFA 1144 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $3, $5 ); } 1145 | comma_expression_opt ';' comma_expression // CFA 1146 { 1147 if ( ! $1 ) { 1148 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr; 1149 } else if ( ! $3 ) { 1150 SemanticError( yylloc, "Missing loop range." ); $$ = nullptr; 1151 } else { 1152 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) { 1153 $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), $3->clone(), 1154 new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); 1155 } else { 1156 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr; 1157 } // if 1158 } // if 1159 } 1160 | comma_expression_opt ';' constant_expression '~' constant_expression // CFA 1161 { 1162 if ( ! $1 ) { 1163 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr; 1164 } else { 1165 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) { 1166 $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); 1167 } else { 1168 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr; 1169 } // if 1170 } // if 1171 } 1172 | comma_expression_opt ';' constant_expression '~' constant_expression '~' constant_expression // CFA 1173 { 1174 if ( ! $1 ) { 1175 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr; 1176 } else { 1177 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) { 1178 $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $5, $7 ); 1179 } else { 1180 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr; 1181 } // if 1182 } // if 1183 } 1184 | comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1185 { $$ = new ForCtrl( $1, $3, $5 ); } 1186 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1187 { $$ = new ForCtrl( $1, $2, $4 ); } 1124 1188 ; 1125 1189
Note: See TracChangeset
for help on using the changeset viewer.