Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r9867cdb r665f432  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar  6 17:26:45 2020
    13 // Update Count     : 4474
     12// Last Modified On : Sun Aug  4 21:48:23 2019
     13// Update Count     : 4364
    1414//
    1515
     
    5151using namespace std;
    5252
    53 #include "SynTree/Declaration.h"
    5453#include "ParseNode.h"
    5554#include "TypedefTable.h"
    5655#include "TypeData.h"
    57 #include "SynTree/LinkageSpec.h"
     56#include "LinkageSpec.h"
    5857#include "Common/SemanticError.h"                                               // error_str
    5958#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     
    166165} // rebindForall
    167166
    168 string * build_postfix_name( string * name ) {
    169         *name = string("__postfix_func_") + *name;
    170         return name;
     167NameExpr * build_postfix_name( const string * name ) {
     168        NameExpr * new_name = build_varref( new string( "?`" + *name ) );
     169        delete name;
     170        return new_name;
    171171} // build_postfix_name
    172172
     
    210210        } // if
    211211} // forCtrl
     212
    212213
    213214bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
     
    236237        ExpressionNode * en;
    237238        DeclarationNode * decl;
    238         AggregateDecl::Aggregate aggKey;
    239         TypeDecl::Kind tclass;
     239        DeclarationNode::Aggregate aggKey;
     240        DeclarationNode::TypeClass tclass;
    240241        StatementNode * sn;
    241242        WaitForStmt * wfs;
     
    322323%type<op> ptrref_operator                               unary_operator                          assignment_operator
    323324%type<en> primary_expression                    postfix_expression                      unary_expression
    324 %type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
     325%type<en> cast_expression                               exponential_expression          multiplicative_expression       additive_expression
    325326%type<en> shift_expression                              relational_expression           equality_expression
    326327%type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
     
    364365%type<decl> abstract_parameter_declaration
    365366
    366 %type<aggKey> aggregate_key aggregate_data aggregate_control
     367%type<aggKey> aggregate_key
    367368%type<decl> aggregate_type aggregate_type_nobody
    368369
     
    578579        | '(' compound_statement ')'                                            // GCC, lambda expression
    579580                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); }
     581        | constant '`' IDENTIFIER                                                       // CFA, postfix call
     582                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
     583        | string_literal '`' IDENTIFIER                                         // CFA, postfix call
     584                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }
     585        | IDENTIFIER '`' IDENTIFIER                                                     // CFA, postfix call
     586                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); }
     587        | tuple '`' IDENTIFIER                                                          // CFA, postfix call
     588                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }
     589        | '(' comma_expression ')' '`' IDENTIFIER                       // CFA, postfix call
     590                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    580591        | type_name '.' identifier                                                      // CFA, nested type
    581592                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    631642        | postfix_expression '(' argument_expression_list ')'
    632643                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    633         | postfix_expression '`' identifier                                     // CFA, postfix call
    634                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
    635         | constant '`' identifier                                                       // CFA, postfix call
    636                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
    637         | string_literal '`' identifier                                         // CFA, postfix call
    638                 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
    639644        | postfix_expression '.' identifier
    640645                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
     
    645650        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
    646651                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    647         | postfix_expression '.' aggregate_control
    648                 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }
    649652        | postfix_expression ARROW identifier
    650653                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    661664        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    662665                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    663         | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call
     666        | '^' primary_expression '{' argument_expression_list '}' // CFA
    664667                {
    665668                        Token fn;
     
    674677        | argument_expression
    675678        | argument_expression_list ',' argument_expression
    676                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     679                { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
    677680        ;
    678681
     
    686689field_name_list:                                                                                // CFA, tuple field selector
    687690        field
    688         | field_name_list ',' field                                     { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     691        | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    689692        ;
    690693
     
    790793        | '(' type_no_function ')' cast_expression
    791794                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    792         | '(' aggregate_control '&' ')' cast_expression         // CFA
    793                 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
     795                // keyword cast cannot be grouped because of reduction in aggregate_key
     796        | '(' GENERATOR '&' ')' cast_expression                         // CFA
     797                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     798        | '(' COROUTINE '&' ')' cast_expression                         // CFA
     799                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }
     800        | '(' THREAD '&' ')' cast_expression                            // CFA
     801                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); }
     802        | '(' MONITOR '&' ')' cast_expression                           // CFA
     803                { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); }
    794804                // VIRTUAL cannot be opt because of look ahead issues
    795805        | '(' VIRTUAL ')' cast_expression                                       // CFA
     
    918928        conditional_expression
    919929        | 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                 }
     930                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
    927931        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
    928932                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
     
    961965                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    962966        | '[' push assignment_expression pop ',' tuple_expression_list ']'
    963                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); }
     967                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
    964968        ;
    965969
     
    967971        assignment_expression_opt
    968972        | tuple_expression_list ',' assignment_expression_opt
    969                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     973                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    970974        ;
    971975
     
    11911195                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11921196                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1193         | '=' comma_expression                                                                  // CFA
    1194                 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1195                                                 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11961197        | comma_expression inclexcl comma_expression            // CFA
    11971198                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12011202                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12021203                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1203         | comma_expression ';' '=' comma_expression                             // CFA
    1204                 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1205                                                 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    12061204        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    12071205                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    13081306        WAITFOR '(' cast_expression ')'
    13091307                { $$ = $3; }
    1310 //      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1311 //              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    1312         | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
    1313                 { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    1314         ;
    1315 
    1316 cast_expression_list:
    1317         cast_expression
    1318         | cast_expression_list ',' cast_expression
    1319                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     1308        | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1309                { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    13201310        ;
    13211311
     
    14281418        asm_operand
    14291419        | asm_operands_list ',' asm_operand
    1430                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     1420                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    14311421        ;
    14321422
     
    14441434                { $$ = new ExpressionNode( $1 ); }
    14451435        | asm_clobbers_list_opt ',' string_literal
    1446                 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
     1436                // set_last returns ParseNode *
     1437                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    14471438        ;
    14481439
     
    15951586                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    15961587                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1597         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
     1588        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    15981589                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1599                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
    1600         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    1601                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
     1590                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
     1591        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1592                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    16021593        ;
    16031594
     
    20682059
    20692060aggregate_key:
    2070         aggregate_data
    2071         | aggregate_control
    2072         ;
    2073 
    2074 aggregate_data:
    20752061        STRUCT
    2076                 { yyy = true; $$ = AggregateDecl::Struct; }
     2062                { yyy = true; $$ = DeclarationNode::Struct; }
    20772063        | UNION
    2078                 { yyy = true; $$ = AggregateDecl::Union; }
    2079         | EXCEPTION                                                                                     // CFA
    2080                 { yyy = true; $$ = AggregateDecl::Exception; }
    2081         ;
    2082 
    2083 aggregate_control:                                                                              // CFA
    2084         GENERATOR
    2085                 { SemanticError( yylloc, "generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    2086         | MONITOR GENERATOR
    2087                 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2064                { yyy = true; $$ = DeclarationNode::Union; }
     2065        | EXCEPTION
     2066                { yyy = true; $$ = DeclarationNode::Exception; }
     2067        | GENERATOR
     2068                { yyy = true; $$ = DeclarationNode::Coroutine; }
    20882069        | COROUTINE
    2089                 { yyy = true; $$ = AggregateDecl::Coroutine; }
     2070                { yyy = true; $$ = DeclarationNode::Coroutine; }
    20902071        | MONITOR
    2091                 { yyy = true; $$ = AggregateDecl::Monitor; }
    2092         | MONITOR COROUTINE
    2093                 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2072                { yyy = true; $$ = DeclarationNode::Monitor; }
    20942073        | THREAD
    2095                 { yyy = true; $$ = AggregateDecl::Thread; }
    2096         | MONITOR THREAD
    2097                 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2074                { yyy = true; $$ = DeclarationNode::Thread; }
    20982075        ;
    20992076
     
    21192096                        distInl( $3 );
    21202097                }
    2121         | INLINE aggregate_control ';'                                          // CFA
    2122                 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
    21232098        | typedef_declaration ';'                                                       // CFA
    21242099        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
     
    23732348        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    23742349        | initializer_list_opt ',' designation initializer
    2375                 { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
     2350                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    23762351        ;
    23772352
     
    23952370        designator
    23962371        | designator_list designator
    2397                 { $$ = (ExpressionNode *)($1->set_last( $2 )); }
     2372                { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
    23982373        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    23992374        ;
     
    24512426        | type_specifier identifier_parameter_declarator
    24522427        | assertion_list
    2453                 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
     2428                { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    24542429        ;
    24552430
    24562431type_class:                                                                                             // CFA
    24572432        OTYPE
    2458                 { $$ = TypeDecl::Otype; }
     2433                { $$ = DeclarationNode::Otype; }
    24592434        | DTYPE
    2460                 { $$ = TypeDecl::Dtype; }
     2435                { $$ = DeclarationNode::Dtype; }
    24612436        | FTYPE
    2462                 { $$ = TypeDecl::Ftype; }
     2437                { $$ = DeclarationNode::Ftype; }
    24632438        | TTYPE
    2464                 { $$ = TypeDecl::Ttype; }
     2439                { $$ = DeclarationNode::Ttype; }
    24652440        ;
    24662441
     
    24922467                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    24932468        | type_list ',' type
    2494                 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }
     2469                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    24952470        | type_list ',' assignment_expression
    24962471                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     
    26032578                {
    26042579                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2605                         linkage = LinkageSpec::update( yylloc, linkage, $2 );
     2580                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    26062581                }
    26072582          '{' up external_definition_list_opt down '}'
Note: See TracChangeset for help on using the changeset viewer.