Changeset fe26fbf for src/Parser/parser.yy
- Timestamp:
- Feb 7, 2017, 1:01:34 PM (9 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, resolv-new, with_gc
- Children:
- 35b1bf4
- Parents:
- dbe8f244 (diff), b4d65c7 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rdbe8f244 rfe26fbf 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 18 15:51:25201713 // Update Count : 21 3512 // Last Modified On : Mon Feb 6 16:00:29 2017 13 // Update Count : 2181 14 14 // 15 15 … … 32 32 // 33 33 // 1. designation with and without '=' (use ':' instead) 34 // 2. attributes not allowed in parenthesis of declarator 34 35 // 35 36 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall … … 65 66 to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) ); 66 67 } // appendStr 68 69 DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) { 70 // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__. 71 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier ); 72 //cur->addType( specifier ); 73 for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 74 cl->cloneBaseType( cur ); 75 } // for 76 declList->addType( cl ); 77 // delete cl; 78 return declList; 79 } // distAttr 80 81 void distExt( DeclarationNode * declaration ) { 82 // distribute EXTENSION across all declarations 83 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 84 iter->set_extension( true ); 85 } // for 86 } // distExt 67 87 %} 68 88 … … 119 139 { 120 140 Token tok; 121 ParseNode * pn;122 ExpressionNode * en;123 DeclarationNode * decl;141 ParseNode * pn; 142 ExpressionNode * en; 143 DeclarationNode * decl; 124 144 DeclarationNode::Aggregate aggKey; 125 145 DeclarationNode::TypeClass tclass; 126 StatementNode * sn;127 ConstantExpr * constant;128 ForCtl * fctl;129 LabelNode * label;130 InitializerNode * in;146 StatementNode * sn; 147 ConstantExpr * constant; 148 ForCtl * fctl; 149 LabelNode * label; 150 InitializerNode * in; 131 151 OperKinds op; 132 std::string * str;152 std::string * str; 133 153 bool flag; 134 154 } … … 152 172 %type<fctl> for_control_expression 153 173 %type<en> subrange 154 %type< constant> asm_name_opt174 %type<decl> asm_name_opt 155 175 %type<en> asm_operands_opt asm_operands_list asm_operand 156 176 %type<label> label_list … … 171 191 172 192 // declarations 173 %type<decl> abstract_ array abstract_declarator abstract_function abstract_parameter_array174 %type<decl> abstract_parameter_declarat ion abstract_parameter_declarator abstract_parameter_function175 %type<decl> abstract_parameter_ ptr abstract_ptr193 %type<decl> abstract_declarator abstract_ptr abstract_array abstract_function array_dimension multi_array_dimension 194 %type<decl> abstract_parameter_declarator abstract_parameter_ptr abstract_parameter_array abstract_parameter_function array_parameter_dimension array_parameter_1st_dimension 195 %type<decl> abstract_parameter_declaration 176 196 177 197 %type<aggKey> aggregate_key 178 %type<decl> aggregate_name 179 180 %type<decl> array_dimension array_parameter_1st_dimension array_parameter_dimension multi_array_dimension 198 %type<decl> aggregate_type 181 199 182 200 %type<decl> assertion assertion_list_opt … … 191 209 %type<decl> declaration_specifier declarator declaring_list 192 210 193 %type<decl> elaborated_type _name194 195 %type<decl> enumerator_list enum_ name211 %type<decl> elaborated_type 212 213 %type<decl> enumerator_list enum_type 196 214 %type<en> enumerator_value_opt 197 215 … … 206 224 %type<decl> identifier_parameter_ptr identifier_list 207 225 208 %type<decl> new_abstract_array new_abstract_declarator_no_tuple new_abstract_declarator_tuple 209 %type<decl> new_abstract_function new_abstract_parameter_declaration new_abstract_parameter_list 210 %type<decl> new_abstract_ptr new_abstract_tuple 211 212 %type<decl> new_array_parameter_1st_dimension 213 214 %type<decl> new_trait_declaring_list new_declaration new_field_declaring_list 215 %type<decl> new_function_declaration new_function_return new_function_specifier 216 217 %type<decl> new_identifier_parameter_array new_identifier_parameter_declarator_no_tuple 218 %type<decl> new_identifier_parameter_declarator_tuple new_identifier_parameter_ptr 219 220 %type<decl> new_parameter_declaration new_parameter_list new_parameter_type_list new_parameter_type_list_opt 221 222 %type<decl> new_typedef_declaration new_variable_declaration new_variable_specifier 223 224 %type<decl> old_declaration old_declaration_list old_declaration_list_opt old_function_array 225 %type<decl> old_function_declarator old_function_no_ptr old_function_ptr 226 %type<decl> cfa_abstract_array cfa_abstract_declarator_no_tuple cfa_abstract_declarator_tuple 227 %type<decl> cfa_abstract_function cfa_abstract_parameter_declaration cfa_abstract_parameter_list 228 %type<decl> cfa_abstract_ptr cfa_abstract_tuple 229 230 %type<decl> cfa_array_parameter_1st_dimension 231 232 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list 233 %type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier 234 235 %type<decl> cfa_identifier_parameter_array cfa_identifier_parameter_declarator_no_tuple 236 %type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr 237 238 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt 239 240 %type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier 241 242 %type<decl> c_declaration 243 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 244 %type<decl> KR_declaration_list KR_declaration_list_opt 226 245 227 246 %type<decl> parameter_declaration parameter_list parameter_type_list … … 237 256 %type<decl> type_declarator type_declarator_name type_declaring_list 238 257 239 %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression 240 %type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr 241 %type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier 258 %type<decl> typedef typedef_type_specifier typedef_declaration typedef_declaration_specifier typedef_expression 259 260 %type<decl> variable_type_redeclarator type_ptr type_array type_function 261 262 %type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function 242 263 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name 243 264 … … 249 270 %type<decl> type_qualifier type_qualifier_name type_qualifier_list type_qualifier_list_opt type_specifier 250 271 251 %type<decl> variable_ abstract_array variable_abstract_declarator variable_abstract_function252 %type<decl> variable_abstract_ ptr variable_array variable_declarator variable_function variable_ptr272 %type<decl> variable_declarator variable_ptr variable_array variable_function 273 %type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function 253 274 254 275 %type<decl> attribute_list_opt attribute_list attribute_name_list attribute attribute_name … … 659 680 tuple: // CFA, tuple 660 681 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with 661 // comma_expression in new_identifier_parameter_array and new_abstract_array682 // comma_expression in cfa_identifier_parameter_array and cfa_abstract_array 662 683 // '[' ']' 663 684 // { $$ = new ExpressionNode( build_tuple() ); } … … 723 744 push push 724 745 local_label_declaration_opt // GCC, local labels 725 block_item_list pop '}' // C99, intermix declarations and statements 746 block_item_list // C99, intermix declarations and statements 747 pop '}' 726 748 { $$ = new StatementNode( build_compound( $5 ) ); } 727 749 ; … … 737 759 { $$ = new StatementNode( $1 ); } 738 760 | EXTENSION declaration // GCC 739 { // mark all fields in list 740 for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) 741 iter->set_extension( true ); 761 { 762 distExt( $2 ); 742 763 $$ = new StatementNode( $2 ); 743 764 } 744 765 | function_definition 745 766 { $$ = new StatementNode( $1 ); } 767 | EXTENSION function_definition // GCC 768 { 769 distExt( $2 ); 770 $$ = new StatementNode( $2 ); 771 } 746 772 | statement pop 747 773 ; … … 960 986 | type_specifier variable_abstract_declarator 961 987 { $$ = $2->addType( $1 ); } 962 | new_abstract_declarator_tuple no_attr_identifier // CFA988 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 963 989 { 964 990 typedefTable.addToEnclosingScope( TypedefTable::ID ); 965 991 $$ = $1->addName( $2 ); 966 992 } 967 | new_abstract_declarator_tuple // CFA993 | cfa_abstract_declarator_tuple // CFA 968 994 ; 969 995 … … 1044 1070 ; 1045 1071 1046 old_declaration_list_opt: // used to declare parameter types in K&R style functions1072 KR_declaration_list_opt: // used to declare parameter types in K&R style functions 1047 1073 pop 1048 1074 { $$ = nullptr; } 1049 | old_declaration_list1050 ; 1051 1052 old_declaration_list:1053 old_declaration1054 | old_declaration_list push old_declaration1075 | KR_declaration_list 1076 ; 1077 1078 KR_declaration_list: 1079 c_declaration 1080 | KR_declaration_list push c_declaration 1055 1081 { $$ = $1->appendList( $3 ); } 1056 1082 ; … … 1072 1098 1073 1099 declaration: // CFA, new & old style declarations 1074 new_declaration1075 | old_declaration1100 cfa_declaration 1101 | c_declaration 1076 1102 ; 1077 1103 … … 1087 1113 // [10] * char y; char *y[10]; // array of 10 pointers to char 1088 1114 1089 new_declaration: // CFA1090 new_variable_declaration pop ';'1091 | new_typedef_declaration pop ';'1092 | new_function_declaration pop ';'1115 cfa_declaration: // CFA 1116 cfa_variable_declaration pop ';' 1117 | cfa_typedef_declaration pop ';' 1118 | cfa_function_declaration pop ';' 1093 1119 | type_declaring_list pop ';' 1094 1120 | trait_specifier pop ';' 1095 1121 ; 1096 1122 1097 new_variable_declaration: // CFA1098 new_variable_specifier initializer_opt1123 cfa_variable_declaration: // CFA 1124 cfa_variable_specifier initializer_opt 1099 1125 { 1100 1126 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1101 1127 $$ = $1->addInitializer( $2 ); 1102 1128 } 1103 | declaration_qualifier_list new_variable_specifier initializer_opt1129 | declaration_qualifier_list cfa_variable_specifier initializer_opt 1104 1130 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 1105 1131 // them as a type_qualifier cannot appear in that context. … … 1108 1134 $$ = $2->addQualifiers( $1 )->addInitializer( $3 );; 1109 1135 } 1110 | new_variable_declaration pop ',' push identifier_or_type_name initializer_opt1136 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1111 1137 { 1112 1138 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); … … 1115 1141 ; 1116 1142 1117 new_variable_specifier: // CFA1143 cfa_variable_specifier: // CFA 1118 1144 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1119 1145 // storage-class 1120 new_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt1146 cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt 1121 1147 { 1122 1148 typedefTable.setNextIdentifier( *$2 ); 1123 1149 $$ = $1->addName( $2 )->addAsmName( $3 ); 1124 1150 } 1125 | new_abstract_tuple identifier_or_type_name asm_name_opt1151 | cfa_abstract_tuple identifier_or_type_name asm_name_opt 1126 1152 { 1127 1153 typedefTable.setNextIdentifier( *$2 ); 1128 1154 $$ = $1->addName( $2 )->addAsmName( $3 ); 1129 1155 } 1130 | type_qualifier_list new_abstract_tuple identifier_or_type_name asm_name_opt1156 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt 1131 1157 { 1132 1158 typedefTable.setNextIdentifier( *$3 ); … … 1135 1161 ; 1136 1162 1137 new_function_declaration: // CFA1138 new_function_specifier1163 cfa_function_declaration: // CFA 1164 cfa_function_specifier 1139 1165 { 1140 1166 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1141 1167 $$ = $1; 1142 1168 } 1143 | type_qualifier_list new_function_specifier1169 | type_qualifier_list cfa_function_specifier 1144 1170 { 1145 1171 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1146 1172 $$ = $2->addQualifiers( $1 ); 1147 1173 } 1148 | declaration_qualifier_list new_function_specifier1174 | declaration_qualifier_list cfa_function_specifier 1149 1175 { 1150 1176 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1151 1177 $$ = $2->addQualifiers( $1 ); 1152 1178 } 1153 | declaration_qualifier_list type_qualifier_list new_function_specifier1179 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 1154 1180 { 1155 1181 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1156 1182 $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); 1157 1183 } 1158 | new_function_declaration pop ',' push identifier_or_type_name1184 | cfa_function_declaration pop ',' push identifier_or_type_name 1159 1185 { 1160 1186 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); … … 1163 1189 ; 1164 1190 1165 new_function_specifier: // CFA1166 // '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict1191 cfa_function_specifier: // CFA 1192 // '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict 1167 1193 // { 1168 1194 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true ); 1169 1195 // } 1170 // '[' ']' identifier '(' push new_parameter_type_list_opt pop ')'1196 // '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')' 1171 1197 // { 1172 1198 // typedefTable.setNextIdentifier( *$5 ); 1173 1199 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1174 1200 // } 1175 // | '[' ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')'1201 // | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')' 1176 1202 // { 1177 1203 // typedefTable.setNextIdentifier( *$5 ); … … 1181 1207 // identifier_or_type_name must be broken apart because of the sequence: 1182 1208 // 1183 // '[' ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'1209 // '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')' 1184 1210 // '[' ']' type_specifier 1185 1211 // 1186 1212 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1187 1213 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1188 new_abstract_tuple identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'1189 // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator).1214 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1215 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1190 1216 { 1191 1217 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); 1192 1218 } 1193 | new_function_return identifier_or_type_name '(' push new_parameter_type_list_opt pop ')'1219 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1194 1220 { 1195 1221 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); … … 1197 1223 ; 1198 1224 1199 new_function_return: // CFA1200 '[' push new_parameter_list pop ']'1225 cfa_function_return: // CFA 1226 '[' push cfa_parameter_list pop ']' 1201 1227 { $$ = DeclarationNode::newTuple( $3 ); } 1202 | '[' push new_parameter_list pop ',' push new_abstract_parameter_list pop ']'1203 // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to lookahead to the1228 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 1229 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1204 1230 // ']'. 1205 1231 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1206 1232 ; 1207 1233 1208 new_typedef_declaration: // CFA1209 TYPEDEF new_variable_specifier1234 cfa_typedef_declaration: // CFA 1235 TYPEDEF cfa_variable_specifier 1210 1236 { 1211 1237 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1212 1238 $$ = $2->addTypedef(); 1213 1239 } 1214 | TYPEDEF new_function_specifier1240 | TYPEDEF cfa_function_specifier 1215 1241 { 1216 1242 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1217 1243 $$ = $2->addTypedef(); 1218 1244 } 1219 | new_typedef_declaration pop ',' push no_attr_identifier1245 | cfa_typedef_declaration pop ',' push no_attr_identifier 1220 1246 { 1221 1247 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); … … 1260 1286 { 1261 1287 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); 1262 $$ = DeclarationNode::newName( 0 ); // XXX1288 $$ = DeclarationNode::newName( 0 ); // unimplemented 1263 1289 } 1264 1290 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1265 1291 { 1266 1292 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); 1267 $$ = DeclarationNode::newName( 0 ); // XXX 1268 } 1269 ; 1270 1271 old_declaration: 1272 declaring_list pop ';' 1293 $$ = DeclarationNode::newName( 0 ); // unimplemented 1294 } 1295 ; 1296 1297 //c_declaration: 1298 // declaring_list pop ';' 1299 // | typedef_declaration pop ';' 1300 // | typedef_expression pop ';' // GCC, naming expression type 1301 // | sue_declaration_specifier pop ';' 1302 // ; 1303 // 1304 //declaring_list: 1305 // // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1306 // // storage-class 1307 // declarator asm_name_opt initializer_opt 1308 // { 1309 // typedefTable.addToEnclosingScope( TypedefTable::ID ); 1310 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1311 // } 1312 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1313 // { 1314 // typedefTable.addToEnclosingScope( TypedefTable::ID ); 1315 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1316 // } 1317 // ; 1318 1319 c_declaration: 1320 declaration_specifier declaring_list pop ';' 1321 { 1322 $$ = distAttr( $1, $2 ); 1323 } 1273 1324 | typedef_declaration pop ';' 1274 1325 | typedef_expression pop ';' // GCC, naming expression type … … 1279 1330 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1280 1331 // storage-class 1281 declarat ion_specifier declarator asm_name_opt initializer_opt1332 declarator asm_name_opt initializer_opt 1282 1333 { 1283 1334 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1284 $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4);1335 $$ = $1->addAsmName( $2 )->addInitializer( $3 ); 1285 1336 } 1286 1337 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1287 1338 { 1288 1339 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1289 $$ = $1->appendList( $ 1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 )) );1340 $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); 1290 1341 } 1291 1342 ; … … 1474 1525 1475 1526 sue_type_specifier: 1476 elaborated_type _name// struct, union, enum1477 | type_qualifier_list elaborated_type _name1527 elaborated_type // struct, union, enum 1528 | type_qualifier_list elaborated_type 1478 1529 { $$ = $2->addQualifiers( $1 ); } 1479 1530 | sue_type_specifier type_qualifier … … 1500 1551 ; 1501 1552 1502 elaborated_type _name:1503 aggregate_ name1504 | enum_ name1505 ; 1506 1507 aggregate_ name:1508 aggregate_key '{' field_declaration_list '}'1509 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $ 3, true); }1510 | aggregate_key no_attr_identifier_or_type_name1511 { 1512 typedefTable.makeTypedef( *$ 2);1513 $$ = DeclarationNode::newAggregate( $1, $ 2, nullptr, nullptr, false);1514 } 1515 | aggregate_key no_attr_identifier_or_type_name1516 { typedefTable.makeTypedef( *$ 2); }1517 1518 { $$ = DeclarationNode::newAggregate( $1, $ 2, nullptr, $5, true); }1519 | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA1520 { $$ = DeclarationNode::newAggregate( $1, nullptr, $ 3, $6, false); }1521 | aggregate_key typegen_name// CFA, S/R conflict1522 { $$ = $ 2; }1553 elaborated_type: 1554 aggregate_type 1555 | enum_type 1556 ; 1557 1558 aggregate_type: 1559 aggregate_key attribute_list_opt '{' field_declaration_list '}' 1560 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $4, true )->addQualifiers( $2 ); } 1561 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1562 { 1563 typedefTable.makeTypedef( *$3 ); 1564 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1565 } 1566 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1567 { typedefTable.makeTypedef( *$3 ); } 1568 '{' field_declaration_list '}' 1569 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1570 | aggregate_key attribute_list_opt '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1571 { $$ = DeclarationNode::newAggregate( $1, nullptr, $4, $7, false )->addQualifiers( $2 ); } 1572 | aggregate_key attribute_list_opt typegen_name // CFA, S/R conflict 1573 { $$ = $3->addQualifiers( $2 ); } 1523 1574 ; 1524 1575 1525 1576 aggregate_key: 1526 STRUCT attribute_list_opt1577 STRUCT 1527 1578 { $$ = DeclarationNode::Struct; } 1528 | UNION attribute_list_opt1579 | UNION 1529 1580 { $$ = DeclarationNode::Union; } 1530 1581 ; … … 1538 1589 1539 1590 field_declaration: 1540 new_field_declaring_list ';' // CFA, new style field declaration 1541 | EXTENSION new_field_declaring_list ';' // GCC 1542 { $$ = $2->set_extension( true ); } 1543 | field_declaring_list ';' 1544 | EXTENSION field_declaring_list ';' // GCC 1545 { // mark all fields in list 1546 for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) 1547 iter->set_extension( true ); 1591 cfa_field_declaring_list ';' // CFA, new style field declaration 1592 | EXTENSION cfa_field_declaring_list ';' // GCC 1593 { 1594 distExt( $2 ); // mark all fields in list 1548 1595 $$ = $2; 1549 1596 } 1550 ; 1551 1552 new_field_declaring_list: // CFA, new style field declaration 1553 new_abstract_declarator_tuple // CFA, no field name 1554 | new_abstract_declarator_tuple no_attr_identifier_or_type_name 1597 | type_specifier field_declaring_list ';' 1598 { 1599 $$ = distAttr( $1, $2 ); } 1600 | EXTENSION type_specifier field_declaring_list ';' // GCC 1601 { 1602 distExt( $3 ); // mark all fields in list 1603 $$ = distAttr( $2, $3 ); 1604 } 1605 ; 1606 1607 cfa_field_declaring_list: // CFA, new style field declaration 1608 cfa_abstract_declarator_tuple // CFA, no field name 1609 | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name 1555 1610 { $$ = $1->addName( $2 ); } 1556 | new_field_declaring_list ',' no_attr_identifier_or_type_name1611 | cfa_field_declaring_list ',' no_attr_identifier_or_type_name 1557 1612 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 1558 | new_field_declaring_list ',' // CFA, no field name1613 | cfa_field_declaring_list ',' // CFA, no field name 1559 1614 { $$ = $1->appendList( $1->cloneType( 0 ) ); } 1560 1615 ; 1561 1616 1562 1617 field_declaring_list: 1563 type_specifier field_declarator 1564 { $$ = $2->addType( $1 ); } 1618 field_declarator 1565 1619 | field_declaring_list ',' attribute_list_opt field_declarator 1566 { $$ = $1->appendList( $ 1->cloneBaseType( $4) ); }1620 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1567 1621 ; 1568 1622 … … 1593 1647 ; 1594 1648 1595 enum_key: 1596 ENUM attribute_list_opt 1597 ; 1598 1599 enum_name: 1600 enum_key '{' enumerator_list comma_opt '}' 1601 { $$ = DeclarationNode::newEnum( nullptr, $3 ); } 1602 | enum_key no_attr_identifier_or_type_name 1603 { 1604 typedefTable.makeTypedef( *$2 ); 1605 $$ = DeclarationNode::newEnum( $2, 0 ); 1606 } 1607 | enum_key no_attr_identifier_or_type_name 1608 { typedefTable.makeTypedef( *$2 ); } 1609 '{' enumerator_list comma_opt '}' 1610 { $$ = DeclarationNode::newEnum( $2, $5 ); } 1649 enum_type: 1650 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 1651 { $$ = DeclarationNode::newEnum( nullptr, $4 )->addQualifiers( $2 ); } 1652 | ENUM attribute_list_opt no_attr_identifier_or_type_name 1653 { 1654 typedefTable.makeTypedef( *$3 ); 1655 $$ = DeclarationNode::newEnum( $3, 0 )->addQualifiers( $2 ); 1656 } 1657 | ENUM attribute_list_opt no_attr_identifier_or_type_name 1658 { typedefTable.makeTypedef( *$3 ); } 1659 '{' enumerator_list comma_opt '}' 1660 { $$ = DeclarationNode::newEnum( $3, $6 )->addQualifiers( $2 ); } 1611 1661 ; 1612 1662 … … 1627 1677 // Minimum of one parameter after which ellipsis is allowed only at the end. 1628 1678 1629 new_parameter_type_list_opt: // CFA1679 cfa_parameter_type_list_opt: // CFA 1630 1680 // empty 1631 1681 { $$ = nullptr; } 1632 | new_parameter_type_list1633 ; 1634 1635 new_parameter_type_list: // CFA, abstract + real1636 new_abstract_parameter_list1637 | new_parameter_list1638 | new_parameter_list pop ',' push new_abstract_parameter_list1682 | cfa_parameter_type_list 1683 ; 1684 1685 cfa_parameter_type_list: // CFA, abstract + real 1686 cfa_abstract_parameter_list 1687 | cfa_parameter_list 1688 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list 1639 1689 { $$ = $1->appendList( $5 ); } 1640 | new_abstract_parameter_list pop ',' push ELLIPSIS1690 | cfa_abstract_parameter_list pop ',' push ELLIPSIS 1641 1691 { $$ = $1->addVarArgs(); } 1642 | new_parameter_list pop ',' push ELLIPSIS1692 | cfa_parameter_list pop ',' push ELLIPSIS 1643 1693 { $$ = $1->addVarArgs(); } 1644 1694 ; 1645 1695 1646 new_parameter_list: // CFA1647 // To obtain LR(1) between new_parameter_list and new_abstract_tuple, the last new_abstract_parameter_list is1648 // factored out from new_parameter_list, flattening the rules to get lookahead to the ']'.1649 new_parameter_declaration1650 | new_abstract_parameter_list pop ',' push new_parameter_declaration1696 cfa_parameter_list: // CFA 1697 // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is 1698 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'. 1699 cfa_parameter_declaration 1700 | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 1651 1701 { $$ = $1->appendList( $5 ); } 1652 | new_parameter_list pop ',' push new_parameter_declaration1702 | cfa_parameter_list pop ',' push cfa_parameter_declaration 1653 1703 { $$ = $1->appendList( $5 ); } 1654 | new_parameter_list pop ',' push new_abstract_parameter_list pop ',' push new_parameter_declaration1704 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 1655 1705 { $$ = $1->appendList( $5 )->appendList( $9 ); } 1656 1706 ; 1657 1707 1658 new_abstract_parameter_list: // CFA, new & old style abstract1659 new_abstract_parameter_declaration1660 | new_abstract_parameter_list pop ',' push new_abstract_parameter_declaration1708 cfa_abstract_parameter_list: // CFA, new & old style abstract 1709 cfa_abstract_parameter_declaration 1710 | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration 1661 1711 { $$ = $1->appendList( $5 ); } 1662 1712 ; … … 1686 1736 // for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes. 1687 1737 1688 new_parameter_declaration: // CFA, new & old style parameter declaration1738 cfa_parameter_declaration: // CFA, new & old style parameter declaration 1689 1739 parameter_declaration 1690 | new_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt1740 | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt 1691 1741 { $$ = $1->addName( $2 ); } 1692 | new_abstract_tuple identifier_or_type_name assignment_opt1693 // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).1742 | cfa_abstract_tuple identifier_or_type_name assignment_opt 1743 // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator). 1694 1744 { $$ = $1->addName( $2 ); } 1695 | type_qualifier_list new_abstract_tuple identifier_or_type_name assignment_opt1745 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name assignment_opt 1696 1746 { $$ = $2->addName( $3 )->addQualifiers( $1 ); } 1697 | new_function_specifier1698 ; 1699 1700 new_abstract_parameter_declaration: // CFA, new & old style parameter declaration1747 | cfa_function_specifier 1748 ; 1749 1750 cfa_abstract_parameter_declaration: // CFA, new & old style parameter declaration 1701 1751 abstract_parameter_declaration 1702 | new_identifier_parameter_declarator_no_tuple1703 | new_abstract_tuple1704 // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator).1705 | type_qualifier_list new_abstract_tuple1752 | cfa_identifier_parameter_declarator_no_tuple 1753 | cfa_abstract_tuple 1754 // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator). 1755 | type_qualifier_list cfa_abstract_tuple 1706 1756 { $$ = $2->addQualifiers( $1 ); } 1707 | new_abstract_function1757 | cfa_abstract_function 1708 1758 ; 1709 1759 … … 1757 1807 1758 1808 type_name_no_function: // sizeof, alignof, cast (constructor) 1759 new_abstract_declarator_tuple // CFA 1760 | type_specifier 1761 | type_specifier variable_abstract_declarator 1762 { $$ = $2->addType( $1 ); } 1763 ; 1764 1765 type_name: // typeof, assertion 1766 new_abstract_declarator_tuple // CFA 1767 | new_abstract_function // CFA 1809 cfa_abstract_declarator_tuple // CFA 1768 1810 | type_specifier 1769 1811 | type_specifier abstract_declarator 1770 1812 { $$ = $2->addType( $1 ); } 1813 ; 1814 1815 type_name: // typeof, assertion 1816 type_name_no_function 1817 | cfa_abstract_function // CFA 1771 1818 ; 1772 1819 … … 1982 2029 1983 2030 trait_declaration: // CFA 1984 new_trait_declaring_list pop ';'2031 cfa_trait_declaring_list pop ';' 1985 2032 | trait_declaring_list pop ';' 1986 2033 ; 1987 2034 1988 new_trait_declaring_list: // CFA1989 new_variable_specifier2035 cfa_trait_declaring_list: // CFA 2036 cfa_variable_specifier 1990 2037 { 1991 2038 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 1992 2039 $$ = $1; 1993 2040 } 1994 | new_function_specifier2041 | cfa_function_specifier 1995 2042 { 1996 2043 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 1997 2044 $$ = $1; 1998 2045 } 1999 | new_trait_declaring_list pop ',' push identifier_or_type_name2046 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 2000 2047 { 2001 2048 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); … … 2043 2090 | asm_statement // GCC, global assembler statement 2044 2091 {} 2045 | EXTERN STRINGliteral 2092 | EXTERN STRINGliteral // C++-style linkage specifier 2046 2093 { 2047 2094 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2048 2095 linkage = LinkageSpec::linkageCheck( $2 ); 2049 2096 } 2050 '{' external_definition_list_opt '}' // C++-style linkage specifier2097 '{' external_definition_list_opt '}' 2051 2098 { 2052 2099 linkage = linkageStack.top(); … … 2054 2101 $$ = $5; 2055 2102 } 2056 | EXTENSION external_definition 2057 { // mark all fields in list 2058 for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) 2059 iter->set_extension( true ); 2103 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown 2104 { 2105 distExt( $2 ); // mark all fields in list 2060 2106 $$ = $2; 2061 2107 } … … 2075 2121 $$ = $1->addFunctionBody( $2 ); 2076 2122 } 2077 | old_function_declarator push old_declaration_list_opt compound_statement2123 | KR_function_declarator push KR_declaration_list_opt compound_statement 2078 2124 { 2079 2125 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 2084 2130 2085 2131 function_definition: 2086 new_function_declaration compound_statement // CFA2132 cfa_function_declaration compound_statement // CFA 2087 2133 { 2088 2134 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 2116 2162 2117 2163 // Old-style K&R function definition, OBSOLESCENT (see 4) 2118 | declaration_specifier old_function_declarator push old_declaration_list_opt compound_statement2164 | declaration_specifier KR_function_declarator push KR_declaration_list_opt compound_statement 2119 2165 { 2120 2166 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 2122 2168 $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addType( $1 ); 2123 2169 } 2124 | type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement2170 | type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement 2125 2171 { 2126 2172 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 2130 2176 2131 2177 // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4) 2132 | declaration_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement2178 | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement 2133 2179 { 2134 2180 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 2136 2182 $$ = $2->addOldDeclList( $4 )->addFunctionBody( $5 )->addQualifiers( $1 ); 2137 2183 } 2138 | declaration_qualifier_list type_qualifier_list old_function_declarator push old_declaration_list_opt compound_statement2184 | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt compound_statement 2139 2185 { 2140 2186 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 2159 2205 { $$ = nullptr; } 2160 2206 | ASM '(' string_literal ')' attribute_list_opt 2161 { $$ = $3; } 2207 { 2208 DeclarationNode * name = new DeclarationNode(); 2209 name->asmName = $3; 2210 $$ = name->addQualifiers( $5 ); 2211 } 2162 2212 ; 2163 2213 … … 2182 2232 attribute_name 2183 2233 | attribute_name_list ',' attribute_name 2184 { $$ = $ 1->addQualifiers( $3 ); }2234 { $$ = $3->addQualifiers( $1 ); } 2185 2235 ; 2186 2236 … … 2257 2307 | ptrref_operator type_qualifier_list variable_declarator 2258 2308 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2259 | '(' variable_ptr ')' 2260 { $$ = $2 ; }2309 | '(' variable_ptr ')' attribute_list_opt 2310 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis 2261 2311 ; 2262 2312 … … 2318 2368 ; 2319 2369 2320 // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a typedef name 2321 // (see function_declarator for additional comments). The pattern precludes returning arrays and functions versus 2322 // pointers to arrays and functions. 2323 2324 old_function_declarator: 2325 old_function_no_ptr 2326 | old_function_ptr 2327 | old_function_array 2328 ; 2329 2330 old_function_no_ptr: 2370 // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) 2371 // 2372 // f( a, b, c ) int a, *b, c[]; {} 2373 // 2374 // that is not redefining a typedef name (see function_declarator for additional comments). The pattern precludes 2375 // returning arrays and functions versus pointers to arrays and functions. 2376 2377 KR_function_declarator: 2378 KR_function_no_ptr 2379 | KR_function_ptr 2380 | KR_function_array 2381 ; 2382 2383 KR_function_no_ptr: 2331 2384 paren_identifier '(' identifier_list ')' // function_declarator handles empty parameter 2332 2385 { $$ = $1->addIdList( $3 ); } 2333 | '(' old_function_ptr ')' '(' identifier_list')'2334 { $$ = $2->add IdList( $5); }2335 | '(' old_function_no_ptr ')' // redundant parenthesis2386 | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')' 2387 { $$ = $2->addParamList( $6 ); } 2388 | '(' KR_function_no_ptr ')' // redundant parenthesis 2336 2389 { $$ = $2; } 2337 2390 ; 2338 2391 2339 old_function_ptr:2340 ptrref_operator old_function_declarator2392 KR_function_ptr: 2393 ptrref_operator KR_function_declarator 2341 2394 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2342 | ptrref_operator type_qualifier_list old_function_declarator2395 | ptrref_operator type_qualifier_list KR_function_declarator 2343 2396 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2344 | '(' old_function_ptr ')'2397 | '(' KR_function_ptr ')' 2345 2398 { $$ = $2; } 2346 2399 ; 2347 2400 2348 old_function_array:2349 '(' old_function_ptr ')' array_dimension2401 KR_function_array: 2402 '(' KR_function_ptr ')' array_dimension 2350 2403 { $$ = $2->addArray( $4 ); } 2351 | '(' old_function_array ')' multi_array_dimension // redundant parenthesis2404 | '(' KR_function_array ')' multi_array_dimension // redundant parenthesis 2352 2405 { $$ = $2->addArray( $4 ); } 2353 | '(' old_function_array ')'// redundant parenthesis2406 | '(' KR_function_array ')' // redundant parenthesis 2354 2407 { $$ = $2; } 2355 2408 ; … … 2386 2439 | ptrref_operator type_qualifier_list variable_type_redeclarator 2387 2440 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2388 | '(' type_ptr ')' 2389 { $$ = $2 ; }2441 | '(' type_ptr ')' attribute_list_opt 2442 { $$ = $2->addQualifiers( $4 ); } 2390 2443 ; 2391 2444 … … 2410 2463 ; 2411 2464 2412 // This pattern parses a declaration for a parameter variable o r function prototype that is not redefining a typedef2413 // name and allows the C99 array options, which can only appear in a parameter list. The pattern precludes declaring an2414 // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to2415 // arrays and functions.2465 // This pattern parses a declaration for a parameter variable of a function prototype or actual that is not redefining a 2466 // typedef name and allows the C99 array options, which can only appear in a parameter list. The pattern precludes 2467 // declaring an array of functions versus a pointer to an array of functions, and returning arrays and functions versus 2468 // pointers to arrays and functions. 2416 2469 2417 2470 identifier_parameter_declarator: … … 2430 2483 | ptrref_operator type_qualifier_list identifier_parameter_declarator 2431 2484 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2432 | '(' identifier_parameter_ptr ')' 2433 { $$ = $2 ; }2485 | '(' identifier_parameter_ptr ')' attribute_list_opt 2486 { $$ = $2->addQualifiers( $4 ); } 2434 2487 ; 2435 2488 … … 2460 2513 // int f( int foo ); // redefine typedef name in new scope 2461 2514 // 2462 // and allows the C99 array options, which can only appear in a parameter list. In addition, the pattern handles the 2463 // special meaning of parenthesis around a typedef name: 2464 // 2465 // ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in 2466 // parentheses is taken to be an abstract declarator that specifies a function with a single parameter, 2467 // not as redundant parentheses around the identifier." 2468 // 2469 // For example: 2470 // 2471 // typedef float T; 2472 // int f( int ( T [5] ) ); // see abstract_parameter_declarator 2473 // int g( int ( T ( int ) ) ); // see abstract_parameter_declarator 2474 // int f( int f1( T a[5] ) ); // see identifier_parameter_declarator 2475 // int g( int g1( T g2( int p ) ) ); // see identifier_parameter_declarator 2476 // 2477 // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and 2478 // not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of 2479 // functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and 2480 // functions. 2515 // and allows the C99 array options, which can only appear in a parameter list. 2481 2516 2482 2517 type_parameter_redeclarator: … … 2508 2543 | ptrref_operator type_qualifier_list type_parameter_redeclarator 2509 2544 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2510 | '(' type_parameter_ptr ')' 2511 { $$ = $2 ; }2545 | '(' type_parameter_ptr ')' attribute_list_opt 2546 { $$ = $2->addQualifiers( $4 ); } 2512 2547 ; 2513 2548 … … 2530 2565 // 2531 2566 // sizeof( int ); 2567 // sizeof( int * ); 2532 2568 // sizeof( int [10] ); 2569 // sizeof( int (*)() ); 2570 // sizeof( int () ); 2533 2571 // 2534 2572 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays … … 2552 2590 | ptrref_operator type_qualifier_list abstract_declarator 2553 2591 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2554 | '(' abstract_ptr ')' 2555 { $$ = $2 ; }2592 | '(' abstract_ptr ')' attribute_list_opt 2593 { $$ = $2->addQualifiers( $4 ); } 2556 2594 ; 2557 2595 … … 2598 2636 // identifier to which the type applies, e.g.: 2599 2637 // 2600 // int f( int ); // abstract variable parameter; no parameter name specified 2638 // int f( int ); // not handled here 2639 // int f( int * ); // abstract function-prototype parameter; no parameter name specified 2640 // int f( int (*)() ); // abstract function-prototype parameter; no parameter name specified 2601 2641 // int f( int (int) ); // abstract function-prototype parameter; no parameter name specified 2602 2642 // 2603 2643 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2604 // and functions versus pointers to arrays and functions. 2644 // and functions versus pointers to arrays and functions. In addition, the pattern handles the 2645 // special meaning of parenthesis around a typedef name: 2646 // 2647 // ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in 2648 // parentheses is taken to be an abstract declarator that specifies a function with a single parameter, 2649 // not as redundant parentheses around the identifier." 2650 // 2651 // For example: 2652 // 2653 // typedef float T; 2654 // int f( int ( T [5] ) ); // see abstract_parameter_declarator 2655 // int g( int ( T ( int ) ) ); // see abstract_parameter_declarator 2656 // int f( int f1( T a[5] ) ); // see identifier_parameter_declarator 2657 // int g( int g1( T g2( int p ) ) ); // see identifier_parameter_declarator 2658 // 2659 // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and 2660 // not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of 2661 // functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and 2662 // functions. 2605 2663 2606 2664 abstract_parameter_declarator: … … 2614 2672 abstract_parameter_ptr: 2615 2673 ptrref_operator 2616 { $$ = DeclarationNode::newPointer( 0); }2674 { $$ = DeclarationNode::newPointer( nullptr ); } 2617 2675 | ptrref_operator type_qualifier_list 2618 2676 { $$ = DeclarationNode::newPointer( $2 ); } 2619 2677 | ptrref_operator abstract_parameter_declarator 2620 { $$ = $2->addPointer( DeclarationNode::newPointer( 0) ); }2678 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr ) ); } 2621 2679 | ptrref_operator type_qualifier_list abstract_parameter_declarator 2622 2680 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2623 | '(' abstract_parameter_ptr ')' 2624 { $$ = $2 ; }2681 | '(' abstract_parameter_ptr ')' attribute_list_opt 2682 { $$ = $2->addQualifiers( $4 ); } 2625 2683 ; 2626 2684 … … 2674 2732 ; 2675 2733 2676 // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type applies, 2677 // e.g.: 2678 // 2679 // sizeof( int ); // abstract variable; no identifier name specified 2680 // 2681 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2682 // and functions versus pointers to arrays and functions. 2734 // This pattern parses a declaration of an abstract variable, but does not allow "int ()" for a function pointer. 2735 // 2736 // struct S { 2737 // int; 2738 // int *; 2739 // int [10]; 2740 // int (*)(); 2741 // }; 2683 2742 2684 2743 variable_abstract_declarator: … … 2699 2758 | ptrref_operator type_qualifier_list variable_abstract_declarator 2700 2759 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2701 | '(' variable_abstract_ptr ')' 2702 { $$ = $2 ; }2760 | '(' variable_abstract_ptr ')' attribute_list_opt 2761 { $$ = $2->addQualifiers( $4 ); } 2703 2762 ; 2704 2763 … … 2723 2782 // identifier or typedef name and allows the C99 array options, which can only appear in a parameter list. 2724 2783 2725 new_identifier_parameter_declarator_tuple: // CFA2726 new_identifier_parameter_declarator_no_tuple2727 | new_abstract_tuple2728 | type_qualifier_list new_abstract_tuple2784 cfa_identifier_parameter_declarator_tuple: // CFA 2785 cfa_identifier_parameter_declarator_no_tuple 2786 | cfa_abstract_tuple 2787 | type_qualifier_list cfa_abstract_tuple 2729 2788 { $$ = $2->addQualifiers( $1 ); } 2730 2789 ; 2731 2790 2732 new_identifier_parameter_declarator_no_tuple: // CFA2733 new_identifier_parameter_ptr2734 | new_identifier_parameter_array2735 ; 2736 2737 new_identifier_parameter_ptr: // CFA2791 cfa_identifier_parameter_declarator_no_tuple: // CFA 2792 cfa_identifier_parameter_ptr 2793 | cfa_identifier_parameter_array 2794 ; 2795 2796 cfa_identifier_parameter_ptr: // CFA 2738 2797 ptrref_operator type_specifier 2739 2798 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2740 2799 | type_qualifier_list ptrref_operator type_specifier 2741 2800 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2742 | ptrref_operator new_abstract_function2801 | ptrref_operator cfa_abstract_function 2743 2802 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2744 | type_qualifier_list ptrref_operator new_abstract_function2803 | type_qualifier_list ptrref_operator cfa_abstract_function 2745 2804 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2746 | ptrref_operator new_identifier_parameter_declarator_tuple2805 | ptrref_operator cfa_identifier_parameter_declarator_tuple 2747 2806 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2748 | type_qualifier_list ptrref_operator new_identifier_parameter_declarator_tuple2807 | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple 2749 2808 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2750 2809 ; 2751 2810 2752 new_identifier_parameter_array: // CFA2811 cfa_identifier_parameter_array: // CFA 2753 2812 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to 2754 2813 // shift/reduce conflict with new-style empty (void) function return type. 2755 2814 '[' ']' type_specifier 2756 2815 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2757 | new_array_parameter_1st_dimension type_specifier2816 | cfa_array_parameter_1st_dimension type_specifier 2758 2817 { $$ = $2->addNewArray( $1 ); } 2759 2818 | '[' ']' multi_array_dimension type_specifier 2760 2819 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2761 | new_array_parameter_1st_dimension multi_array_dimension type_specifier2820 | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier 2762 2821 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } 2763 2822 | multi_array_dimension type_specifier 2764 2823 { $$ = $2->addNewArray( $1 ); } 2765 2824 2766 | '[' ']' new_identifier_parameter_ptr2825 | '[' ']' cfa_identifier_parameter_ptr 2767 2826 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2768 | new_array_parameter_1st_dimension new_identifier_parameter_ptr2827 | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr 2769 2828 { $$ = $2->addNewArray( $1 ); } 2770 | '[' ']' multi_array_dimension new_identifier_parameter_ptr2829 | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr 2771 2830 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2772 | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr2831 | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr 2773 2832 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } 2774 | multi_array_dimension new_identifier_parameter_ptr2833 | multi_array_dimension cfa_identifier_parameter_ptr 2775 2834 { $$ = $2->addNewArray( $1 ); } 2776 2835 ; 2777 2836 2778 new_array_parameter_1st_dimension:2837 cfa_array_parameter_1st_dimension: 2779 2838 '[' push type_qualifier_list '*' pop ']' // remaining C99 2780 2839 { $$ = DeclarationNode::newVarArray( $3 ); } … … 2798 2857 // These rules need LR(3): 2799 2858 // 2800 // new_abstract_tuple identifier_or_type_name2801 // '[' new_parameter_list ']' identifier_or_type_name '(' new_parameter_type_list_opt ')'2859 // cfa_abstract_tuple identifier_or_type_name 2860 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')' 2802 2861 // 2803 2862 // since a function return type can be syntactically identical to a tuple type: … … 2807 2866 // 2808 2867 // Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce 2809 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary2810 // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are2811 // duplicated when appearing with new_function_specifier.2812 2813 new_abstract_declarator_tuple: // CFA2814 new_abstract_tuple2815 | type_qualifier_list new_abstract_tuple2868 // cfa_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary 2869 // lookahead. To accomplish this, cfa_abstract_declarator has an entry point without tuple, and tuple declarations are 2870 // duplicated when appearing with cfa_function_specifier. 2871 2872 cfa_abstract_declarator_tuple: // CFA 2873 cfa_abstract_tuple 2874 | type_qualifier_list cfa_abstract_tuple 2816 2875 { $$ = $2->addQualifiers( $1 ); } 2817 | new_abstract_declarator_no_tuple2818 ; 2819 2820 new_abstract_declarator_no_tuple: // CFA2821 new_abstract_ptr2822 | new_abstract_array2823 ; 2824 2825 new_abstract_ptr: // CFA2876 | cfa_abstract_declarator_no_tuple 2877 ; 2878 2879 cfa_abstract_declarator_no_tuple: // CFA 2880 cfa_abstract_ptr 2881 | cfa_abstract_array 2882 ; 2883 2884 cfa_abstract_ptr: // CFA 2826 2885 ptrref_operator type_specifier 2827 2886 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2828 2887 | type_qualifier_list ptrref_operator type_specifier 2829 2888 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2830 | ptrref_operator new_abstract_function2889 | ptrref_operator cfa_abstract_function 2831 2890 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2832 | type_qualifier_list ptrref_operator new_abstract_function2891 | type_qualifier_list ptrref_operator cfa_abstract_function 2833 2892 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2834 | ptrref_operator new_abstract_declarator_tuple2893 | ptrref_operator cfa_abstract_declarator_tuple 2835 2894 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); } 2836 | type_qualifier_list ptrref_operator new_abstract_declarator_tuple2895 | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple 2837 2896 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); } 2838 2897 ; 2839 2898 2840 new_abstract_array: // CFA2899 cfa_abstract_array: // CFA 2841 2900 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with 2842 2901 // empty (void) function return type. … … 2847 2906 | multi_array_dimension type_specifier 2848 2907 { $$ = $2->addNewArray( $1 ); } 2849 | '[' ']' new_abstract_ptr2908 | '[' ']' cfa_abstract_ptr 2850 2909 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2851 | '[' ']' multi_array_dimension new_abstract_ptr2910 | '[' ']' multi_array_dimension cfa_abstract_ptr 2852 2911 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2853 | multi_array_dimension new_abstract_ptr2912 | multi_array_dimension cfa_abstract_ptr 2854 2913 { $$ = $2->addNewArray( $1 ); } 2855 2914 ; 2856 2915 2857 new_abstract_tuple: // CFA2858 '[' push new_abstract_parameter_list pop ']'2916 cfa_abstract_tuple: // CFA 2917 '[' push cfa_abstract_parameter_list pop ']' 2859 2918 { $$ = DeclarationNode::newTuple( $3 ); } 2860 2919 ; 2861 2920 2862 new_abstract_function: // CFA2863 // '[' ']' '(' new_parameter_type_list_opt ')'2921 cfa_abstract_function: // CFA 2922 // '[' ']' '(' cfa_parameter_type_list_opt ')' 2864 2923 // { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 2865 new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'2924 cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')' 2866 2925 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2867 | new_function_return '(' push new_parameter_type_list_opt pop ')'2926 | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')' 2868 2927 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2869 2928 ;
Note:
See TracChangeset
for help on using the changeset viewer.