Changes in src/Parser/parser.yy [1b8f13f0:553772b]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r1b8f13f0 r553772b 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 8 18:08:23 201813 // Update Count : 4 05212 // Last Modified On : Wed May 15 21:25:27 2019 13 // Update Count : 4296 14 14 // 15 15 … … 99 99 // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__. 100 100 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier ); 101 //cur->addType( specifier ); 102 for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 101 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 103 102 cl->cloneBaseType( cur ); 104 103 } // for 105 104 declList->addType( cl ); 106 // delete cl;107 105 return declList; 108 106 } // distAttr … … 175 173 DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) { 176 174 if ( ! fieldList ) { // field declarator ? 177 if ( ! ( typeSpec->type && typeSpec->type->kind == TypeData::Aggregate) ) {175 if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) { 178 176 stringstream ss; 179 177 typeSpec->type->print( ss ); … … 187 185 188 186 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 189 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type-> get_expr());187 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); 190 188 if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) { 191 189 type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) ); … … 193 191 return new ForCtrl( 194 192 distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 195 new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ), 196 new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 197 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) ); 193 // NULL comp/inc => leave blank 194 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : 0, 195 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 196 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : 0 ); 198 197 } // forCtrl 199 198 200 199 ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 201 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index-> get_expr()) ) {200 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->expr.get()) ) { 202 201 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 202 } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->expr.get()) ) { 203 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1 ) ) { 204 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 205 } else { 206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr; 207 } // if 203 208 } else { 204 209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr; … … 260 265 %token RESTRICT // C99 261 266 %token ATOMIC // C11 262 %token FORALL MUTEX VIRTUAL // CFA267 %token FORALL MUTEX VIRTUAL COERCE // CFA 263 268 %token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED 264 269 %token BOOL COMPLEX IMAGINARY // C99 265 %token INT128 FLOAT80 FLOAT128 // GCC 270 %token INT128 uuFLOAT80 uuFLOAT128 // GCC 271 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC 266 272 %token ZERO_T ONE_T // CFA 267 273 %token VALIST // GCC … … 269 275 %token ENUM STRUCT UNION 270 276 %token EXCEPTION // CFA 271 %token COROUTINE MONITOR THREAD// CFA277 %token GENERATOR COROUTINE MONITOR THREAD // CFA 272 278 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 273 279 %token SIZEOF OFFSETOF … … 324 330 %type<en> argument_expression_list argument_expression default_initialize_opt 325 331 %type<ifctl> if_control_expression 326 %type<fctl> for_control_expression 332 %type<fctl> for_control_expression for_control_expression_list 327 333 %type<compop> inclexcl 328 334 %type<en> subrange 329 335 %type<decl> asm_name_opt 330 %type<en> asm_operands_opt asm_operands_listasm_operand336 %type<en> asm_operands_opt asm_operands_list asm_operand 331 337 %type<label> label_list 332 338 %type<en> asm_clobbers_list_opt 333 339 %type<flag> asm_volatile_opt 334 340 %type<en> handler_predicate_opt 335 %type<genexpr> generic_association generic_assoc_list341 %type<genexpr> generic_association generic_assoc_list 336 342 337 343 // statements … … 671 677 // empty 672 678 { $$ = nullptr; } 673 | ' ?' // CFA, default parameter679 | '@' // CFA, default parameter 674 680 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 675 681 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } … … 789 795 | '(' type_no_function ')' cast_expression 790 796 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 797 // keyword cast cannot be grouped because of reduction in aggregate_key 798 | '(' GENERATOR '&' ')' cast_expression // CFA 799 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 791 800 | '(' COROUTINE '&' ')' cast_expression // CFA 792 801 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } … … 800 809 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 801 810 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 811 | '(' RETURN type_no_function ')' cast_expression // CFA 812 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } 813 | '(' COERCE type_no_function ')' cast_expression // CFA 814 { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; } 815 | '(' qualifier_cast_list ')' cast_expression // CFA 816 { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; } 802 817 // | '(' type_no_function ')' tuple 803 818 // { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 819 ; 820 821 qualifier_cast_list: 822 cast_modifier type_qualifier_name 823 | cast_modifier MUTEX 824 | qualifier_cast_list cast_modifier type_qualifier_name 825 | qualifier_cast_list cast_modifier MUTEX 826 ; 827 828 cast_modifier: 829 '-' 830 | '+' 804 831 ; 805 832 … … 984 1011 // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER 985 1012 identifier_or_type_name ':' attribute_list_opt statement 986 { 987 $$ = $4->add_label( $1, $3 ); 988 } 1013 { $$ = $4->add_label( $1, $3 ); } 989 1014 ; 990 1015 … … 1002 1027 statement_decl 1003 1028 | statement_decl_list statement_decl 1004 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; }}1029 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1005 1030 ; 1006 1031 … … 1009 1034 { $$ = new StatementNode( $1 ); } 1010 1035 | EXTENSION declaration // GCC 1011 { 1012 distExt( $2 ); 1013 $$ = new StatementNode( $2 ); 1014 } 1036 { distExt( $2 ); $$ = new StatementNode( $2 ); } 1015 1037 | function_definition 1016 1038 { $$ = new StatementNode( $1 ); } 1017 1039 | EXTENSION function_definition // GCC 1018 { 1019 distExt( $2 ); 1020 $$ = new StatementNode( $2 ); 1021 } 1040 { distExt( $2 ); $$ = new StatementNode( $2 ); } 1022 1041 | statement 1023 1042 ; … … 1026 1045 statement 1027 1046 | statement_list_nodecl statement 1028 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; }}1047 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1029 1048 ; 1030 1049 … … 1138 1157 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1139 1158 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); } 1140 | FOR '(' push for_control_expression ')' statement pop1159 | FOR '(' push for_control_expression_list ')' statement pop 1141 1160 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1142 1161 | FOR '(' ')' statement // CFA => for ( ;; ) … … 1144 1163 ; 1145 1164 1165 for_control_expression_list: 1166 for_control_expression 1167 | for_control_expression_list ':' for_control_expression 1168 // ForCtrl + ForCtrl: 1169 // init + init => multiple declaration statements that are hoisted 1170 // condition + condition => (expression) && (expression) 1171 // change + change => (expression), (expression) 1172 { 1173 $1->init->set_last( $3->init ); 1174 if ( $1->condition ) { 1175 if ( $3->condition ) { 1176 $1->condition->expr.reset( new LogicalExpr( $1->condition->expr.release(), $3->condition->expr.release(), true ) ); 1177 } // if 1178 } else $1->condition = $3->condition; 1179 if ( $1->change ) { 1180 if ( $3->change ) { 1181 $1->change->expr.reset( new CommaExpr( $1->change->expr.release(), $3->change->expr.release() ) ); 1182 } // if 1183 } else $1->change = $3->change; 1184 $$ = $1; 1185 } 1186 ; 1187 1146 1188 for_control_expression: 1147 comma_expression // CFA 1189 ';' comma_expression_opt ';' comma_expression_opt 1190 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); } 1191 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1192 { $$ = new ForCtrl( $1, $3, $5 ); } 1193 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1194 { $$ = new ForCtrl( $1, $2, $4 ); } 1195 1196 | comma_expression // CFA 1148 1197 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1149 1198 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1150 | co nstant_expression inclexcl constant_expression// CFA1199 | comma_expression inclexcl comma_expression // CFA 1151 1200 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1152 | co nstant_expression inclexcl constant_expression '~' constant_expression // CFA1201 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1153 1202 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1154 1203 | comma_expression ';' comma_expression // CFA 1155 1204 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1156 1205 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1157 | comma_expression ';' co nstant_expression inclexcl constant_expression // CFA1206 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1158 1207 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1159 | comma_expression ';' co nstant_expression inclexcl constant_expression '~' constant_expression // CFA1208 | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA 1160 1209 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); } 1161 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1162 { $$ = new ForCtrl( $1, $3, $5 ); } 1163 | ';' comma_expression_opt ';' comma_expression_opt 1164 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); } 1165 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1166 { $$ = new ForCtrl( $1, $2, $4 ); } 1210 1211 // There is a S/R conflicit if ~ and -~ are factored out. 1212 | comma_expression ';' comma_expression '~' '@' // CFA 1213 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1214 | comma_expression ';' comma_expression ErangeDown '@' // CFA 1215 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1216 | comma_expression ';' comma_expression '~' '@' '~' comma_expression // CFA 1217 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, $7 ); } 1218 | comma_expression ';' comma_expression ErangeDown '@' '~' comma_expression // CFA 1219 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::GThan, nullptr, $7 ); } 1220 | comma_expression ';' comma_expression '~' '@' '~' '@' // CFA 1221 { $$ = forCtrl( $3, $1, $3->clone(), OperKinds::LThan, nullptr, nullptr ); } 1167 1222 ; 1168 1223 … … 1771 1826 | FLOAT 1772 1827 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); } 1773 | FLOAT801774 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }1775 | FLOAT1281776 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }1777 1828 | DOUBLE 1778 1829 { $$ = DeclarationNode::newBasicType( DeclarationNode::Double ); } 1830 | uuFLOAT80 1831 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat80 ); } 1832 | uuFLOAT128 1833 { $$ = DeclarationNode::newBasicType( DeclarationNode::uuFloat128 ); } 1834 | uFLOAT16 1835 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat16 ); } 1836 | uFLOAT32 1837 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32 ); } 1838 | uFLOAT32X 1839 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat32x ); } 1840 | uFLOAT64 1841 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64 ); } 1842 | uFLOAT64X 1843 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat64x ); } 1844 | uFLOAT128 1845 { $$ = DeclarationNode::newBasicType( DeclarationNode::uFloat128 ); } 1779 1846 | COMPLEX // C99 1780 1847 { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); } … … 1996 2063 | EXCEPTION 1997 2064 { yyy = true; $$ = DeclarationNode::Exception; } 2065 | GENERATOR 2066 { yyy = true; $$ = DeclarationNode::Coroutine; } 1998 2067 | COROUTINE 1999 2068 { yyy = true; $$ = DeclarationNode::Coroutine; }
Note:
See TracChangeset
for help on using the changeset viewer.