Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rc744563a rf1da02c  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 21 14:47:29 2020
    13 // Update Count     : 4468
     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
     
    955965                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    956966        | '[' push assignment_expression pop ',' tuple_expression_list ']'
    957                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); }
     967                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
    958968        ;
    959969
     
    961971        assignment_expression_opt
    962972        | tuple_expression_list ',' assignment_expression_opt
    963                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     973                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    964974        ;
    965975
     
    11851195                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11861196                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1187         | '=' comma_expression                                                                  // CFA
    1188                 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1189                                                 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11901197        | comma_expression inclexcl comma_expression            // CFA
    11911198                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    11951202                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11961203                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1197         | comma_expression ';' '=' comma_expression                             // CFA
    1198                 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    1199                                                 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    12001204        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    12011205                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    13021306        WAITFOR '(' cast_expression ')'
    13031307                { $$ = $3; }
    1304 //      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1305 //              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    1306         | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
    1307                 { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    1308         ;
    1309 
    1310 cast_expression_list:
    1311         cast_expression
    1312         | cast_expression_list ',' cast_expression
    1313                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     1308        | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1309                { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    13141310        ;
    13151311
     
    14221418        asm_operand
    14231419        | asm_operands_list ',' asm_operand
    1424                 { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     1420                { $$ = (ExpressionNode *)$1->set_last( $3 ); }
    14251421        ;
    14261422
    14271423asm_operand:                                                                                    // GCC
    14281424        string_literal '(' constant_expression ')'
    1429                 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); }
    1430         | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    1431                 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); }
     1425                { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ), $1, maybeMoveBuild< Expression >( $3 ) ) ); }
     1426        | '[' constant_expression ']' string_literal '(' constant_expression ')'
     1427                { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( $2 ), $4, maybeMoveBuild< Expression >( $6 ) ) ); }
    14321428        ;
    14331429
     
    14381434                { $$ = new ExpressionNode( $1 ); }
    14391435        | asm_clobbers_list_opt ',' string_literal
    1440                 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
     1436                // set_last returns ParseNode *
     1437                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    14411438        ;
    14421439
     
    15891586                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    15901587                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1591         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 ')'
    15921589                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1593                 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
    1594         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    1595                 { $$ = 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 ); }
    15961593        ;
    15971594
     
    20622059
    20632060aggregate_key:
    2064         aggregate_data
    2065         | aggregate_control
    2066         ;
    2067 
    2068 aggregate_data:
    20692061        STRUCT
    2070                 { yyy = true; $$ = AggregateDecl::Struct; }
     2062                { yyy = true; $$ = DeclarationNode::Struct; }
    20712063        | UNION
    2072                 { yyy = true; $$ = AggregateDecl::Union; }
    2073         | EXCEPTION                                                                                     // CFA
    2074                 { yyy = true; $$ = AggregateDecl::Exception; }
    2075         ;
    2076 
    2077 aggregate_control:                                                                              // CFA
    2078         GENERATOR
    2079                 { yyy = true; $$ = AggregateDecl::Coroutine; }
     2064                { yyy = true; $$ = DeclarationNode::Union; }
     2065        | EXCEPTION
     2066                { yyy = true; $$ = DeclarationNode::Exception; }
     2067        | GENERATOR
     2068                { yyy = true; $$ = DeclarationNode::Coroutine; }
    20802069        | COROUTINE
    2081                 { yyy = true; $$ = AggregateDecl::Coroutine; }
     2070                { yyy = true; $$ = DeclarationNode::Coroutine; }
    20822071        | MONITOR
    2083                 { yyy = true; $$ = AggregateDecl::Monitor; }
     2072                { yyy = true; $$ = DeclarationNode::Monitor; }
    20842073        | THREAD
    2085                 { yyy = true; $$ = AggregateDecl::Thread; }
     2074                { yyy = true; $$ = DeclarationNode::Thread; }
    20862075        ;
    20872076
     
    21072096                        distInl( $3 );
    21082097                }
    2109         | INLINE aggregate_control ';'                                          // CFA
    2110                 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
    21112098        | typedef_declaration ';'                                                       // CFA
    21122099        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
     
    23612348        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    23622349        | initializer_list_opt ',' designation initializer
    2363                 { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
     2350                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    23642351        ;
    23652352
     
    23832370        designator
    23842371        | designator_list designator
    2385                 { $$ = (ExpressionNode *)($1->set_last( $2 )); }
     2372                { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
    23862373        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    23872374        ;
     
    24392426        | type_specifier identifier_parameter_declarator
    24402427        | assertion_list
    2441                 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
     2428                { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    24422429        ;
    24432430
    24442431type_class:                                                                                             // CFA
    24452432        OTYPE
    2446                 { $$ = TypeDecl::Otype; }
     2433                { $$ = DeclarationNode::Otype; }
    24472434        | DTYPE
    2448                 { $$ = TypeDecl::Dtype; }
     2435                { $$ = DeclarationNode::Dtype; }
    24492436        | FTYPE
    2450                 { $$ = TypeDecl::Ftype; }
     2437                { $$ = DeclarationNode::Ftype; }
    24512438        | TTYPE
    2452                 { $$ = TypeDecl::Ttype; }
     2439                { $$ = DeclarationNode::Ttype; }
    24532440        ;
    24542441
     
    24802467                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    24812468        | type_list ',' type
    2482                 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }
     2469                { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
    24832470        | type_list ',' assignment_expression
    24842471                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     
    25912578                {
    25922579                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2593                         linkage = LinkageSpec::update( yylloc, linkage, $2 );
     2580                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    25942581                }
    25952582          '{' up external_definition_list_opt down '}'
Note: See TracChangeset for help on using the changeset viewer.