Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r1b8f13f0 r553772b  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov  8 18:08:23 2018
    13 // Update Count     : 4052
     12// Last Modified On : Wed May 15 21:25:27 2019
     13// Update Count     : 4296
    1414//
    1515
     
    9999        // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
    100100        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() ) ) {
    103102                cl->cloneBaseType( cur );
    104103        } // for
    105104        declList->addType( cl );
    106 //      delete cl;
    107105        return declList;
    108106} // distAttr
     
    175173DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) {
    176174        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) ) ) {
    178176                        stringstream ss;
    179177                        typeSpec->type->print( ss );
     
    187185
    188186ForCtrl * 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());
    190188        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    191189        type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     
    193191        return new ForCtrl(
    194192                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 );
    198197} // forCtrl
    199198
    200199ForCtrl * 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()) ) {
    202201                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
    203208        } else {
    204209                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     
    260265%token RESTRICT                                                                                 // C99
    261266%token ATOMIC                                                                                   // C11
    262 %token FORALL MUTEX VIRTUAL                                                             // CFA
     267%token FORALL MUTEX VIRTUAL COERCE                                              // CFA
    263268%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    264269%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
    266272%token ZERO_T ONE_T                                                                             // CFA
    267273%token VALIST                                                                                   // GCC
     
    269275%token ENUM STRUCT UNION
    270276%token EXCEPTION                                                                                // CFA
    271 %token COROUTINE MONITOR THREAD                                                 // CFA
     277%token GENERATOR COROUTINE MONITOR THREAD                               // CFA
    272278%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    273279%token SIZEOF OFFSETOF
     
    324330%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    325331%type<ifctl> if_control_expression
    326 %type<fctl> for_control_expression
     332%type<fctl> for_control_expression              for_control_expression_list
    327333%type<compop> inclexcl
    328334%type<en> subrange
    329335%type<decl> asm_name_opt
    330 %type<en> asm_operands_opt asm_operands_list asm_operand
     336%type<en> asm_operands_opt                              asm_operands_list                       asm_operand
    331337%type<label> label_list
    332338%type<en> asm_clobbers_list_opt
    333339%type<flag> asm_volatile_opt
    334340%type<en> handler_predicate_opt
    335 %type<genexpr> generic_association generic_assoc_list
     341%type<genexpr> generic_association              generic_assoc_list
    336342
    337343// statements
     
    671677        // empty
    672678                { $$ = nullptr; }
    673         | '?'                                                                                           // CFA, default parameter
     679        | '@'                                                                                           // CFA, default parameter
    674680                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    675681                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     
    789795        | '(' type_no_function ')' cast_expression
    790796                { $$ = 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 ) ); }
    791800        | '(' COROUTINE '&' ')' cast_expression                         // CFA
    792801                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     
    800809        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    801810                { $$ = 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; }
    802817//      | '(' type_no_function ')' tuple
    803818//              { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
     819        ;
     820
     821qualifier_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
     828cast_modifier:
     829        '-'
     830        | '+'
    804831        ;
    805832
     
    9841011                // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
    9851012        identifier_or_type_name ':' attribute_list_opt statement
    986                 {
    987                         $$ = $4->add_label( $1, $3 );
    988                 }
     1013                { $$ = $4->add_label( $1, $3 ); }
    9891014        ;
    9901015
     
    10021027        statement_decl
    10031028        | statement_decl_list statement_decl
    1004                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     1029                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    10051030        ;
    10061031
     
    10091034                { $$ = new StatementNode( $1 ); }
    10101035        | EXTENSION declaration                                                         // GCC
    1011                 {
    1012                         distExt( $2 );
    1013                         $$ = new StatementNode( $2 );
    1014                 }
     1036                { distExt( $2 ); $$ = new StatementNode( $2 ); }
    10151037        | function_definition
    10161038                { $$ = new StatementNode( $1 ); }
    10171039        | EXTENSION function_definition                                         // GCC
    1018                 {
    1019                         distExt( $2 );
    1020                         $$ = new StatementNode( $2 );
    1021                 }
     1040                { distExt( $2 ); $$ = new StatementNode( $2 ); }
    10221041        | statement
    10231042        ;
     
    10261045        statement
    10271046        | statement_list_nodecl statement
    1028                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     1047                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    10291048        ;
    10301049
     
    11381157        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    11391158                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); }
    1140         | FOR '(' push for_control_expression ')' statement pop
     1159        | FOR '(' push for_control_expression_list ')' statement pop
    11411160                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    11421161        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     
    11441163        ;
    11451164
     1165for_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
    11461188for_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
    11481197                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11491198                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1150         | constant_expression inclexcl constant_expression      // CFA
     1199        | comma_expression inclexcl comma_expression            // CFA
    11511200                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1152         | constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1201        | comma_expression inclexcl comma_expression '~' comma_expression // CFA
    11531202                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    11541203        | comma_expression ';' comma_expression                         // CFA
    11551204                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11561205                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1157         | comma_expression ';' constant_expression inclexcl constant_expression // CFA
     1206        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    11581207                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1159         | comma_expression ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
     1208        | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA
    11601209                { $$ = 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 ); }
    11671222        ;
    11681223
     
    17711826        | FLOAT
    17721827                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
    1773         | FLOAT80
    1774                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }
    1775         | FLOAT128
    1776                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }
    17771828        | DOUBLE
    17781829                { $$ = 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 ); }
    17791846        | COMPLEX                                                                                       // C99
    17801847                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     
    19962063        | EXCEPTION
    19972064                { yyy = true; $$ = DeclarationNode::Exception; }
     2065        | GENERATOR
     2066                { yyy = true; $$ = DeclarationNode::Coroutine; }
    19982067        | COROUTINE
    19992068                { yyy = true; $$ = DeclarationNode::Coroutine; }
Note: See TracChangeset for help on using the changeset viewer.