Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r553772b r1b8f13f0  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 15 21:25:27 2019
    13 // Update Count     : 4296
     12// Last Modified On : Thu Nov  8 18:08:23 2018
     13// Update Count     : 4052
    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         for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
     101        //cur->addType( specifier );
     102        for ( cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    102103                cl->cloneBaseType( cur );
    103104        } // for
    104105        declList->addType( cl );
     106//      delete cl;
    105107        return declList;
    106108} // distAttr
     
    173175DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) {
    174176        if ( ! fieldList ) {                                                            // field declarator ?
    175                 if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) {
     177                if ( ! ( typeSpec->type && typeSpec->type->kind == TypeData::Aggregate ) ) {
    176178                        stringstream ss;
    177179                        typeSpec->type->print( ss );
     
    185187
    186188ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    187         ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
     189        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->get_expr());
    188190        if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) {
    189191        type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression >(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
     
    191193        return new ForCtrl(
    192194                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    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 );
     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 ) ) );
    197198} // forCtrl
    198199
    199200ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    200         if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->expr.get()) ) {
     201        if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->get_expr()) ) {
    201202                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
    208203        } else {
    209204                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
     
    265260%token RESTRICT                                                                                 // C99
    266261%token ATOMIC                                                                                   // C11
    267 %token FORALL MUTEX VIRTUAL COERCE                                              // CFA
     262%token FORALL MUTEX VIRTUAL                                                             // CFA
    268263%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    269264%token BOOL COMPLEX IMAGINARY                                                   // C99
    270 %token INT128 uuFLOAT80 uuFLOAT128                                              // GCC
    271 %token uFLOAT16 uFLOAT32 uFLOAT32X uFLOAT64 uFLOAT64X uFLOAT128 // GCC
     265%token INT128 FLOAT80 FLOAT128                                                  // GCC
    272266%token ZERO_T ONE_T                                                                             // CFA
    273267%token VALIST                                                                                   // GCC
     
    275269%token ENUM STRUCT UNION
    276270%token EXCEPTION                                                                                // CFA
    277 %token GENERATOR COROUTINE MONITOR THREAD                               // CFA
     271%token COROUTINE MONITOR THREAD                                                 // CFA
    278272%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    279273%token SIZEOF OFFSETOF
     
    330324%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    331325%type<ifctl> if_control_expression
    332 %type<fctl> for_control_expression              for_control_expression_list
     326%type<fctl> for_control_expression
    333327%type<compop> inclexcl
    334328%type<en> subrange
    335329%type<decl> asm_name_opt
    336 %type<en> asm_operands_opt                              asm_operands_list                       asm_operand
     330%type<en> asm_operands_opt asm_operands_list asm_operand
    337331%type<label> label_list
    338332%type<en> asm_clobbers_list_opt
    339333%type<flag> asm_volatile_opt
    340334%type<en> handler_predicate_opt
    341 %type<genexpr> generic_association              generic_assoc_list
     335%type<genexpr> generic_association generic_assoc_list
    342336
    343337// statements
     
    677671        // empty
    678672                { $$ = nullptr; }
    679         | '@'                                                                                           // CFA, default parameter
     673        | '?'                                                                                           // CFA, default parameter
    680674                { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; }
    681675                // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
     
    795789        | '(' type_no_function ')' cast_expression
    796790                { $$ = 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 ) ); }
    800791        | '(' COROUTINE '&' ')' cast_expression                         // CFA
    801792                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     
    809800        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    810801                { $$ = 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; }
    817802//      | '(' type_no_function ')' tuple
    818803//              { $$ = 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         | '+'
    831804        ;
    832805
     
    1011984                // labels cannot be identifiers 0 or 1 or ATTR_IDENTIFIER
    1012985        identifier_or_type_name ':' attribute_list_opt statement
    1013                 { $$ = $4->add_label( $1, $3 ); }
     986                {
     987                        $$ = $4->add_label( $1, $3 );
     988                }
    1014989        ;
    1015990
     
    10271002        statement_decl
    10281003        | statement_decl_list statement_decl
    1029                 { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
     1004                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    10301005        ;
    10311006
     
    10341009                { $$ = new StatementNode( $1 ); }
    10351010        | EXTENSION declaration                                                         // GCC
    1036                 { distExt( $2 ); $$ = new StatementNode( $2 ); }
     1011                {
     1012                        distExt( $2 );
     1013                        $$ = new StatementNode( $2 );
     1014                }
    10371015        | function_definition
    10381016                { $$ = new StatementNode( $1 ); }
    10391017        | EXTENSION function_definition                                         // GCC
    1040                 { distExt( $2 ); $$ = new StatementNode( $2 ); }
     1018                {
     1019                        distExt( $2 );
     1020                        $$ = new StatementNode( $2 );
     1021                }
    10411022        | statement
    10421023        ;
     
    10451026        statement
    10461027        | statement_list_nodecl statement
    1047                 { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
     1028                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    10481029        ;
    10491030
     
    11571138        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    11581139                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); }
    1159         | FOR '(' push for_control_expression_list ')' statement pop
     1140        | FOR '(' push for_control_expression ')' statement pop
    11601141                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    11611142        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     
    11631144        ;
    11641145
    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 
    11881146for_control_expression:
    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
     1147        comma_expression                                                                        // CFA
    11971148                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11981149                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1199         | comma_expression inclexcl comma_expression            // CFA
     1150        | constant_expression inclexcl constant_expression      // CFA
    12001151                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1201         | comma_expression inclexcl comma_expression '~' comma_expression // CFA
     1152        | constant_expression inclexcl constant_expression '~' constant_expression // CFA
    12021153                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    12031154        | comma_expression ';' comma_expression                         // CFA
    12041155                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12051156                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1206         | comma_expression ';' comma_expression inclexcl comma_expression // CFA
     1157        | comma_expression ';' constant_expression inclexcl constant_expression // CFA
    12071158                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1208         | comma_expression ';' comma_expression inclexcl comma_expression '~' comma_expression // CFA
     1159        | comma_expression ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA
    12091160                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, $7 ); }
    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 ); }
     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 ); }
    12221167        ;
    12231168
     
    18261771        | FLOAT
    18271772                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float ); }
     1773        | FLOAT80
     1774                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float80 ); }
     1775        | FLOAT128
     1776                { $$ = DeclarationNode::newBasicType( DeclarationNode::Float128 ); }
    18281777        | DOUBLE
    18291778                { $$ = 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 ); }
    18461779        | COMPLEX                                                                                       // C99
    18471780                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
     
    20631996        | EXCEPTION
    20641997                { yyy = true; $$ = DeclarationNode::Exception; }
    2065         | GENERATOR
    2066                 { yyy = true; $$ = DeclarationNode::Coroutine; }
    20671998        | COROUTINE
    20681999                { yyy = true; $$ = DeclarationNode::Coroutine; }
Note: See TracChangeset for help on using the changeset viewer.