Changeset d78c238
- Timestamp:
- Aug 8, 2022, 5:13:11 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- 5c98a25
- Parents:
- 66406f3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/parser.yy ¶
r66406f3 rd78c238 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 1 15:35:08202213 // Update Count : 5 40512 // Last Modified On : Mon Aug 8 15:45:04 2022 13 // Update Count : 5574 14 14 // 15 15 … … 58 58 59 59 // lex uses __null in a boolean context, it's fine. 60 #pragma GCC diagnostic ignored "-Wparentheses-equality"60 //#pragma GCC diagnostic ignored "-Wparentheses-equality" 61 61 62 62 extern DeclarationNode * parseTree; … … 197 197 } // fieldDecl 198 198 199 #define NEW_ZERO new ExpressionNode( build_constantInteger( *new string( "0" ) ) ) 200 #define NEW_ONE new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) 201 202 ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 203 if ( index->initializer ) { 204 SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." ); 205 } // if 206 if ( index->next ) { 207 SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." ); 208 } // if 209 return new ForCtrl( index->addInitializer( new InitializerNode( start ) ), 210 // NULL comp/inc => leave blank 211 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index->name ) ) ), comp ) ) : nullptr, 212 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 213 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index->name ) ) ), inc ) ) : nullptr ); 214 } // forCtrl 215 199 216 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 200 217 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); … … 206 223 distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 207 224 // NULL comp/inc => leave blank 208 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : 0,225 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : nullptr, 209 226 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 210 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : 0);227 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : nullptr ); 211 228 } // forCtrl 212 229 … … 346 363 %type<ifctl> conditional_declaration 347 364 %type<fctl> for_control_expression for_control_expression_list 348 %type<compop> inclexcl365 %type<compop> updown updowneq downupdowneq 349 366 %type<en> subrange 350 367 %type<decl> asm_name_opt … … 1239 1256 iteration_statement: 1240 1257 WHILE '(' ')' statement %prec THEN // CFA => while ( 1 ) 1241 { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) )), maybe_build_compound( $4 ) ) ); }1258 { $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( $4 ) ) ); } 1242 1259 | WHILE '(' ')' statement ELSE statement // CFA 1243 1260 { 1244 $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) )), maybe_build_compound( $4 ) ) );1261 $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( $4 ) ) ); 1245 1262 SemanticWarning( yylloc, Warning::SuperfluousElse, "" ); 1246 1263 } … … 1250 1267 { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ), $7 ) ); } 1251 1268 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1252 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }1269 { $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound( $2 ) ) ); } 1253 1270 | DO statement WHILE '(' ')' ELSE statement // CFA 1254 1271 { 1255 $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) );1272 $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound( $2 ) ) ); 1256 1273 SemanticWarning( yylloc, Warning::SuperfluousElse, "" ); 1257 1274 } … … 1305 1322 1306 1323 | comma_expression // CFA 1307 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1308 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1309 | '=' comma_expression // CFA 1310 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1311 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1312 | comma_expression inclexcl comma_expression // CFA 1313 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1314 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1324 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); } 1325 | downupdowneq comma_expression // CFA 1326 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), $1 == OperKinds::GThan || $1 == OperKinds::GEThan ? $2->clone() : NEW_ZERO, $1, $2->clone(), NEW_ONE ); } 1327 | comma_expression updowneq comma_expression // CFA 1328 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, NEW_ONE ); } 1329 | '@' updowneq comma_expression // CFA 1330 { $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ), 1331 $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3->clone(), NEW_ONE ); } 1332 | comma_expression updown '@' // CFA 1333 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, NEW_ONE ); } 1334 1335 | comma_expression updowneq comma_expression '~' comma_expression // CFA 1315 1336 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1337 | '@' updowneq comma_expression '~' comma_expression // CFA 1338 { $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ), 1339 $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3->clone(), $5 ); } 1340 | comma_expression updown '@' '~' comma_expression // CFA 1341 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, $5 ); } 1342 | comma_expression updown '@' '~' '@' // CFA 1343 { 1344 if ( $2 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; } 1345 else $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, nullptr, nullptr ); 1346 } 1316 1347 | comma_expression ';' // CFA 1317 1348 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); } 1318 1349 | comma_expression ';' comma_expression // CFA 1319 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1320 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1321 | comma_expression ';' '=' comma_expression // CFA 1322 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1323 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1324 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1325 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1326 | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA 1350 { $$ = forCtrl( $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); } 1351 | comma_expression ';' downupdowneq comma_expression // CFA 1352 { $$ = forCtrl( $4, $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4->clone(), NEW_ONE ); } 1353 | comma_expression ';' comma_expression updowneq comma_expression // CFA 1354 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, NEW_ONE ); } 1355 | comma_expression ';' '@' updowneq comma_expression // CFA 1356 { $$ = forCtrl( $5, $1, $4 == OperKinds::GThan || $4 == OperKinds::GEThan ? $5->clone() : NEW_ZERO, $4, $5->clone(), NEW_ONE ); } 1357 | comma_expression ';' comma_expression updown '@' // CFA 1358 { $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); } 1359 1360 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA 1327 1361 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); } 1362 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA 1363 { $$ = forCtrl( $5, $1, $4 == OperKinds::GThan || $4 == OperKinds::GEThan ? $5->clone() : NEW_ZERO, $4, $5->clone(), $7 ); } 1364 | comma_expression ';' comma_expression updown '@' '~' comma_expression // CFA 1365 { $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, $7 ); } 1366 | comma_expression ';' comma_expression updown '@' '~' '@' // CFA 1367 { 1368 if ( $4 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; } 1369 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, nullptr ); 1370 } 1371 1372 | declaration comma_expression // CFA 1373 { $$ = forCtrl( $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); } 1374 | declaration downupdowneq comma_expression // CFA 1375 { $$ = forCtrl( $1, $2 == OperKinds::GThan || $2 == OperKinds::GEThan ? $3->clone() : NEW_ZERO, $2, $3, NEW_ONE ); } 1376 | declaration comma_expression updowneq comma_expression // CFA 1377 { $$ = forCtrl( $1, $2, $3, $4, NEW_ONE ); } 1378 | declaration '@' updowneq comma_expression // CFA 1379 { $$ = forCtrl( $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4, NEW_ONE ); } 1380 | declaration comma_expression updown '@' // CFA 1381 { $$ = forCtrl( $1, $2, $3, nullptr, NEW_ONE ); } 1382 1383 | declaration comma_expression updowneq comma_expression '~' comma_expression // CFA 1384 { $$ = forCtrl( $1, $2, $3, $4, $6 ); } 1385 | declaration '@' updowneq comma_expression '~' comma_expression // CFA 1386 { $$ = forCtrl( $1, $3 == OperKinds::GThan || $3 == OperKinds::GEThan ? $4->clone() : NEW_ZERO, $3, $4, $6 ); } 1387 | declaration comma_expression updown '@' '~' comma_expression // CFA 1388 { $$ = forCtrl( $1, $2, $3, nullptr, $6 ); } 1389 | declaration comma_expression updown '@' '~' '@' // CFA 1390 { 1391 if ( $3 == OperKinds::GThan ) { SemanticError( yylloc, "Negative range \"-~\" is meaningless when comparison and iterator are empty. Use \"~\"." ); $$ = nullptr; } 1392 else $$ = forCtrl( $1, $2, $3, nullptr, nullptr ); 1393 } 1328 1394 1329 1395 | comma_expression ';' TYPEDEFname // CFA, array type 1330 1396 { 1331 SemanticError( yylloc, "Array interator is currently unimplemented." ); $$ = nullptr; 1332 $$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr ); 1333 } 1334 1335 // There is a S/R conflicit if ~ and -~ are factored out. 1336 | comma_expression ';' comma_expression '~' '@' // CFA 1337 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1338 | comma_expression ';' comma_expression ErangeDown '@' // CFA 1339 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1340 | comma_expression ';' comma_expression '~' '@' '~' comma_expression // CFA 1341 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, $7 ); } 1342 | comma_expression ';' comma_expression ErangeDown '@' '~' comma_expression // CFA 1343 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, $7 ); } 1344 | comma_expression ';' comma_expression '~' '@' '~' '@' // CFA 1345 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, nullptr ); } 1397 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1398 //$$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr ); 1399 } 1400 | comma_expression ';' downupdowneq TYPEDEFname // CFA, array type 1401 { 1402 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1403 } 1346 1404 ; 1347 1405 1348 inclexcl: 1406 downupdowneq: 1407 ErangeDown 1408 { $$ = OperKinds::GThan; } 1409 | ErangeUpEq 1410 { $$ = OperKinds::LEThan; } 1411 | ErangeDownEq 1412 { $$ = OperKinds::GEThan; } 1413 ; 1414 1415 updown: 1349 1416 '~' 1350 1417 { $$ = OperKinds::LThan; } 1418 | ErangeDown 1419 { $$ = OperKinds::GThan; } 1420 ; 1421 1422 updowneq: 1423 updown 1351 1424 | ErangeUpEq 1352 1425 { $$ = OperKinds::LEThan; } 1353 | ErangeDown1354 { $$ = OperKinds::GThan; }1355 1426 | ErangeDownEq 1356 1427 { $$ = OperKinds::GEThan; } … … 2395 2466 '{' enumerator_list comma_opt '}' 2396 2467 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); } 2468 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2469 { SemanticError( yylloc, "Unvalued enumerated type is currently unimplemented." ); $$ = nullptr; } 2397 2470 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2398 2471 {
Note: See TracChangeset
for help on using the changeset viewer.