Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ra025ea8 r948fdef  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct 24 08:21:14 2020
    13 // Update Count     : 4624
     12// Last Modified On : Sat Feb  1 10:04:40 2020
     13// Update Count     : 4440
    1414//
    1515
     
    166166} // rebindForall
    167167
    168 string * build_postfix_name( string * name ) {
    169         *name = string("__postfix_func_") + *name;
    170         return name;
     168NameExpr * build_postfix_name( const string * name ) {
     169        NameExpr * new_name = build_varref( new string( "?`" + *name ) );
     170        delete name;
     171        return new_name;
    171172} // build_postfix_name
    172173
     
    204205                        return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
    205206                } else {
    206                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
     207                        SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
    207208                } // if
    208209        } else {
    209                 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
     210                SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); return nullptr;
    210211        } // if
    211212} // forCtrl
     
    278279%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    279280%token SIZEOF OFFSETOF
    280 // %token RESUME                                                                                        // CFA
    281 %token SUSPEND                                                                                  // CFA
     281// %token SUSPEND RESUME                                                                        // CFA
    282282%token ATTRIBUTE EXTENSION                                                              // GCC
    283283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    329329%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    330330%type<en> comma_expression                              comma_expression_opt
    331 %type<en> argument_expression_list_opt  argument_expression                     default_initialize_opt
     331%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    332332%type<ifctl> if_control_expression
    333333%type<fctl> for_control_expression              for_control_expression_list
     
    370370%type<decl> assertion assertion_list assertion_list_opt
    371371
    372 %type<en> bit_subrange_size_opt bit_subrange_size
     372%type<en>   bit_subrange_size_opt bit_subrange_size
    373373
    374374%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
     
    624624                // equivalent to the old x[i,j].
    625625                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    626         | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
     626        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    627627                {
    628628                        Token fn;
     
    630630                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    631631                }
    632         | postfix_expression '(' argument_expression_list_opt ')'
     632        | postfix_expression '(' argument_expression_list ')'
    633633                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    634634        | postfix_expression '`' identifier                                     // CFA, postfix call
    635                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
     635                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
    636636        | constant '`' identifier                                                       // CFA, postfix call
    637                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
     637                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
    638638        | string_literal '`' identifier                                         // CFA, postfix call
    639                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
     639                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }
    640640        | postfix_expression '.' identifier
    641641                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
     
    662662        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    663663                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    664         | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call
     664        | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call
    665665                {
    666666                        Token fn;
     
    670670        ;
    671671
    672 argument_expression_list_opt:
     672argument_expression_list:
    673673        // empty
    674674                { $$ = nullptr; }
    675675        | argument_expression
    676         | argument_expression_list_opt ',' argument_expression
     676        | argument_expression_list ',' argument_expression
    677677                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    678678        ;
     
    793793        | '(' aggregate_control '&' ')' cast_expression         // CFA
    794794                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
     795                // VIRTUAL cannot be opt because of look ahead issues
    795796        | '(' VIRTUAL ')' cast_expression                                       // CFA
    796797                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     
    918919        conditional_expression
    919920        | unary_expression assignment_operator assignment_expression
    920                 {
    921 //                      if ( $2 == OperKinds::AtAssn ) {
    922 //                              SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr;
    923 //                      } else {
    924                                 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) );
    925 //                      } // if
    926                 }
     921                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
    927922        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
    928923                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
     
    965960
    966961tuple_expression_list:
    967         assignment_expression
    968         | '@'                                                                                           // CFA
    969                 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
    970         | tuple_expression_list ',' assignment_expression
     962        assignment_expression_opt
     963        | tuple_expression_list ',' assignment_expression_opt
    971964                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    972         | tuple_expression_list ',' '@'
    973                 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
    974965        ;
    975966
     
    10801071        IF '(' if_control_expression ')' statement                      %prec THEN
    10811072                // explicitly deal with the shift/reduce conflict on if/else
    1082                 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), nullptr ) ); }
     1073                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    10831074        | IF '(' if_control_expression ')' statement ELSE statement
    1084                 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound( $7 ) ) ); }
     1075                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    10851076        ;
    10861077
     
    11301121
    11311122case_clause:                                                                                    // CFA
    1132         case_label_list statement                                       { $$ = $1->append_last_case( maybe_build_compound( $2 ) ); }
     1123        case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    11331124        ;
    11341125
     
    11481139iteration_statement:
    11491140        WHILE '(' push if_control_expression ')' statement pop
    1150                 { $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 ) ) ); }
     1141                { $$ = new StatementNode( build_while( $4, $6 ) ); }
    11511142        | WHILE '(' ')' statement                                                       // CFA => while ( 1 )
    1152                 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
     1143                { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); }
    11531144        | DO statement WHILE '(' comma_expression ')' ';'
    1154                 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
     1145                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
    11551146        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    1156                 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
     1147                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); }
    11571148        | FOR '(' push for_control_expression_list ')' statement pop
    1158                 { $$ = new StatementNode( build_for( $4, maybe_build_compound( $6 ) ) ); }
     1149                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    11591150        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
    1160                 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
     1151                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4 ) ); }
    11611152        ;
    11621153
     
    11951186                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11961187                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1197         | '=' comma_expression                                                          // CFA
     1188        | '=' comma_expression                                                                  // CFA
    11981189                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11991190                                                OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12021193        | comma_expression inclexcl comma_expression '~' comma_expression // CFA
    12031194                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); }
    1204         | comma_expression ';'                                                          // CFA
    1205                 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); }
    12061195        | comma_expression ';' comma_expression                         // CFA
    12071196                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12081197                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1209         | comma_expression ';' '=' comma_expression                     // CFA
     1198        | comma_expression ';' '=' comma_expression                             // CFA
    12101199                { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12111200                                                OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12711260        | RETURN '{' initializer_list_opt comma_opt '}' ';'
    12721261                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    1273         | SUSPEND ';'
    1274                 { $$ = new StatementNode( build_suspend( nullptr ) ); }
    1275         | SUSPEND compound_statement
    1276                 { $$ = new StatementNode( build_suspend( $2 ) ); }
    1277         | SUSPEND COROUTINE ';'
    1278                 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); }
    1279         | SUSPEND COROUTINE compound_statement
    1280                 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); }
    1281         | SUSPEND GENERATOR ';'
    1282                 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); }
    1283         | SUSPEND GENERATOR compound_statement
    1284                 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); }
     1262        // | SUSPEND ';'
     1263        //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1264        // | SUSPEND compound_statement ';'
     1265        //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
    12851266        | THROW assignment_expression_opt ';'                           // handles rethrow
    12861267                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    13051286// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
    13061287mutex_statement:
    1307         MUTEX '(' argument_expression_list_opt ')' statement
     1288        MUTEX '(' argument_expression_list ')' statement
    13081289                { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; }
    13091290        ;
     
    13221303        WAITFOR '(' cast_expression ')'
    13231304                { $$ = $3; }
    1324 //      | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'
     1305//      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    13251306//              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    1326         | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
     1307        | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
    13271308                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    13281309        ;
     
    13311312        cast_expression
    13321313        | cast_expression_list ',' cast_expression
    1333                 // { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    1334                 { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; }
     1314                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    13351315        ;
    13361316
     
    13411321waitfor_clause:
    13421322        when_clause_opt waitfor statement                                       %prec THEN
    1343                 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); }
     1323                { $$ = build_waitfor( $2, $3, $1 ); }
    13441324        | when_clause_opt waitfor statement WOR waitfor_clause
    1345                 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); }
     1325                { $$ = build_waitfor( $2, $3, $1, $5 ); }
    13461326        | when_clause_opt timeout statement                                     %prec THEN
    1347                 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); }
     1327                { $$ = build_waitfor_timeout( $2, $3, $1 ); }
    13481328        | when_clause_opt ELSE statement
    1349                 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }
     1329                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    13501330                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    13511331        | when_clause_opt timeout statement WOR ELSE statement
    13521332                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    13531333        | when_clause_opt timeout statement WOR when_clause ELSE statement
    1354                 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); }
     1334                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
    13551335        ;
    13561336
     
    16101590                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    16111591                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1612         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
     1592        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    16131593                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1614                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
    1615         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    1616                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
     1594                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1595        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1596                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    16171597        ;
    16181598
     
    16751655
    16761656typedef_expression:
    1677                 // deprecated GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
     1657                // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
    16781658        TYPEDEF identifier '=' assignment_expression
    16791659                {
    1680                         SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
     1660                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     1661                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
    16811662                }
    16821663        | typedef_expression pop ',' push identifier '=' assignment_expression
    16831664                {
    1684                         SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr;
    1685                 }
    1686         ;
     1665                        // $$ = DeclarationNode::newName( 0 );                  // unimplemented
     1666                        SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1667                }
     1668        ;
     1669
     1670//c_declaration:
     1671//      declaring_list pop ';'
     1672//      | typedef_declaration pop ';'
     1673//      | typedef_expression pop ';'                                            // GCC, naming expression type
     1674//      | sue_declaration_specifier pop ';'
     1675//      ;
     1676//
     1677//declaring_list:
     1678//              // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static
     1679//              // storage-class
     1680//       declarator asm_name_opt initializer_opt
     1681//              {
     1682//                      typedefTable.addToEnclosingScope( IDENTIFIER );
     1683//                      $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 );
     1684//              }
     1685//      | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
     1686//              {
     1687//                      typedefTable.addToEnclosingScope( IDENTIFIER );
     1688//                      $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) );
     1689//              }
     1690//      ;
    16871691
    16881692c_declaration:
     
    16901694                { $$ = distAttr( $1, $2 ); }
    16911695        | typedef_declaration
    1692         | typedef_expression                                                            // deprecated GCC, naming expression type
     1696        | typedef_expression                                                            // GCC, naming expression type
    16931697        | sue_declaration_specifier
    16941698        ;
     
    20692073                { yyy = true; $$ = AggregateDecl::Union; }
    20702074        | EXCEPTION                                                                                     // CFA
    2071                 // { yyy = true; $$ = AggregateDecl::Exception; }
    2072                 { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2075                { yyy = true; $$ = AggregateDecl::Exception; }
    20732076        ;
    20742077
    20752078aggregate_control:                                                                              // CFA
    2076         MONITOR
    2077                 { yyy = true; $$ = AggregateDecl::Monitor; }
    2078         | MUTEX STRUCT
    2079                 { yyy = true; $$ = AggregateDecl::Monitor; }
    2080         | GENERATOR
    2081                 { yyy = true; $$ = AggregateDecl::Generator; }
    2082         | MUTEX GENERATOR
    2083                 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2079        GENERATOR
     2080                { yyy = true; $$ = AggregateDecl::Coroutine; }
    20842081        | COROUTINE
    20852082                { yyy = true; $$ = AggregateDecl::Coroutine; }
    2086         | MUTEX COROUTINE
    2087                 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2083        | MONITOR
     2084                { yyy = true; $$ = AggregateDecl::Monitor; }
    20882085        | THREAD
    20892086                { yyy = true; $$ = AggregateDecl::Thread; }
    2090         | MUTEX THREAD
    2091                 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20922087        ;
    20932088
     
    24122407// Overloading: function, data, and operator identifiers may be overloaded.
    24132408//
    2414 // Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
     2409// Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
    24152410//     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
    24162411//     definitions of new types. Type declarations with storage class "extern" provide opaque types.
     
    24412436        type_class identifier_or_type_name
    24422437                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    2443         type_initializer_opt assertion_list_opt
     2438          type_initializer_opt assertion_list_opt
    24442439                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    24452440        | type_specifier identifier_parameter_declarator
     
    24682463        assertion
    24692464        | assertion_list assertion
    2470                 { $$ = $1->appendList( $2 ); }
     2465                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    24712466        ;
    24722467
     
    27552750        | attr_name
    27562751                { $$ = DeclarationNode::newAttribute( $1 ); }
    2757         | attr_name '(' argument_expression_list_opt ')'
     2752        | attr_name '(' argument_expression_list ')'
    27582753                { $$ = DeclarationNode::newAttribute( $1, $3 ); }
    27592754        ;
Note: See TracChangeset for help on using the changeset viewer.