Ignore:
Timestamp:
Apr 6, 2020, 4:46:28 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
e3bc51c
Parents:
71d6bd8 (diff), 057298e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into new-ast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r71d6bd8 r7030dab  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 21:48:23 2019
    13 // Update Count     : 4364
     12// Last Modified On : Fri Mar  6 17:26:45 2020
     13// Update Count     : 4474
    1414//
    1515
     
    5151using namespace std;
    5252
     53#include "SynTree/Declaration.h"
    5354#include "ParseNode.h"
    5455#include "TypedefTable.h"
    5556#include "TypeData.h"
    56 #include "LinkageSpec.h"
     57#include "SynTree/LinkageSpec.h"
    5758#include "Common/SemanticError.h"                                               // error_str
    5859#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     
    165166} // rebindForall
    166167
    167 NameExpr * build_postfix_name( const string * name ) {
    168         NameExpr * new_name = build_varref( new string( "?`" + *name ) );
    169         delete name;
    170         return new_name;
     168string * build_postfix_name( string * name ) {
     169        *name = string("__postfix_func_") + *name;
     170        return name;
    171171} // build_postfix_name
    172172
     
    210210        } // if
    211211} // forCtrl
    212 
    213212
    214213bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
     
    237236        ExpressionNode * en;
    238237        DeclarationNode * decl;
    239         DeclarationNode::Aggregate aggKey;
    240         DeclarationNode::TypeClass tclass;
     238        AggregateDecl::Aggregate aggKey;
     239        TypeDecl::Kind tclass;
    241240        StatementNode * sn;
    242241        WaitForStmt * wfs;
     
    279278%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    280279%token SIZEOF OFFSETOF
    281 // %token SUSPEND RESUME                                                                        // CFA
     280// %token RESUME                                                                        // CFA
     281%token SUSPEND                                                                  // CFA
    282282%token ATTRIBUTE EXTENSION                                                              // GCC
    283283%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    323323%type<op> ptrref_operator                               unary_operator                          assignment_operator
    324324%type<en> primary_expression                    postfix_expression                      unary_expression
    325 %type<en> cast_expression                               exponential_expression          multiplicative_expression       additive_expression
     325%type<en> cast_expression_list                  cast_expression                         exponential_expression          multiplicative_expression       additive_expression
    326326%type<en> shift_expression                              relational_expression           equality_expression
    327327%type<en> AND_expression                                exclusive_OR_expression         inclusive_OR_expression
     
    365365%type<decl> abstract_parameter_declaration
    366366
    367 %type<aggKey> aggregate_key
     367%type<aggKey> aggregate_key aggregate_data aggregate_control
    368368%type<decl> aggregate_type aggregate_type_nobody
    369369
     
    579579        | '(' compound_statement ')'                                            // GCC, lambda expression
    580580                { $$ = 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 ) ); }
    591581        | type_name '.' identifier                                                      // CFA, nested type
    592582                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    642632        | postfix_expression '(' argument_expression_list ')'
    643633                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
     634        | postfix_expression '`' identifier                                     // CFA, postfix call
     635                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
     636        | constant '`' identifier                                                       // CFA, postfix call
     637                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }
     638        | string_literal '`' identifier                                         // CFA, postfix call
     639                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }
    644640        | postfix_expression '.' identifier
    645641                { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); }
     
    650646        | postfix_expression '.' '[' field_name_list ']'        // CFA, tuple field selector
    651647                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     648        | postfix_expression '.' aggregate_control
     649                { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }
    652650        | postfix_expression ARROW identifier
    653651                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    664662        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    665663                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    666         | '^' primary_expression '{' argument_expression_list '}' // CFA
     664        | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call
    667665                {
    668666                        Token fn;
     
    677675        | argument_expression
    678676        | argument_expression_list ',' argument_expression
    679                 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }
     677                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    680678        ;
    681679
     
    689687field_name_list:                                                                                // CFA, tuple field selector
    690688        field
    691         | field_name_list ',' field                                     { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     689        | field_name_list ',' field                                     { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    692690        ;
    693691
     
    793791        | '(' type_no_function ')' cast_expression
    794792                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    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 ) ); }
     793        | '(' aggregate_control '&' ')' cast_expression         // CFA
     794                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    804795                // VIRTUAL cannot be opt because of look ahead issues
    805796        | '(' VIRTUAL ')' cast_expression                                       // CFA
     
    928919        conditional_expression
    929920        | unary_expression assignment_operator assignment_expression
    930                 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
     921                {
     922                        if ( $2 == OperKinds::AtAssn ) {
     923                                SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr;
     924                        } else {
     925                                $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) );
     926                        } // if
     927                }
    931928        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
    932929                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
     
    965962                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    966963        | '[' push assignment_expression pop ',' tuple_expression_list ']'
    967                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
     964                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); }
    968965        ;
    969966
     
    971968        assignment_expression_opt
    972969        | tuple_expression_list ',' assignment_expression_opt
    973                 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     970                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    974971        ;
    975972
     
    11951192                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11961193                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1194        | '=' comma_expression                                                                  // CFA
     1195                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1196                                                OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    11971197        | comma_expression inclexcl comma_expression            // CFA
    11981198                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12021202                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12031203                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     1204        | comma_expression ';' '=' comma_expression                             // CFA
     1205                { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
     1206                                                OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    12041207        | comma_expression ';' comma_expression inclexcl comma_expression // CFA
    12051208                { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12631266        | RETURN '{' initializer_list_opt comma_opt '}' ';'
    12641267                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    1265         // | SUSPEND ';'
    1266         //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
    1267         // | SUSPEND compound_statement ';'
    1268         //      { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; }
     1268        | SUSPEND ';'
     1269                { $$ = new StatementNode( build_suspend( nullptr ) ); }
     1270        | SUSPEND compound_statement
     1271                { $$ = new StatementNode( build_suspend( $2 ) ); }
     1272        | SUSPEND COROUTINE ';'
     1273                { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); }
     1274        | SUSPEND COROUTINE compound_statement
     1275                { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); }
     1276        | SUSPEND GENERATOR ';'
     1277                { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); }
     1278        | SUSPEND GENERATOR compound_statement
     1279                { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); }
    12691280        | THROW assignment_expression_opt ';'                           // handles rethrow
    12701281                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    13061317        WAITFOR '(' cast_expression ')'
    13071318                { $$ = $3; }
    1308         | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    1309                 { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     1319//      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
     1320//              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
     1321        | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
     1322                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
     1323        ;
     1324
     1325cast_expression_list:
     1326        cast_expression
     1327        | cast_expression_list ',' cast_expression
     1328                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    13101329        ;
    13111330
     
    14181437        asm_operand
    14191438        | asm_operands_list ',' asm_operand
    1420                 { $$ = (ExpressionNode *)$1->set_last( $3 ); }
     1439                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    14211440        ;
    14221441
     
    14341453                { $$ = new ExpressionNode( $1 ); }
    14351454        | asm_clobbers_list_opt ',' string_literal
    1436                 // set_last returns ParseNode *
    1437                 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
     1455                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); }
    14381456        ;
    14391457
     
    15861604                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    15871605                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1588         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
     1606        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
    15891607                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    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 ); }
     1608                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
     1609        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt
     1610                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); }
    15931611        ;
    15941612
     
    20592077
    20602078aggregate_key:
     2079        aggregate_data
     2080        | aggregate_control
     2081        ;
     2082
     2083aggregate_data:
    20612084        STRUCT
    2062                 { yyy = true; $$ = DeclarationNode::Struct; }
     2085                { yyy = true; $$ = AggregateDecl::Struct; }
    20632086        | UNION
    2064                 { yyy = true; $$ = DeclarationNode::Union; }
    2065         | EXCEPTION
    2066                 { yyy = true; $$ = DeclarationNode::Exception; }
    2067         | GENERATOR
    2068                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     2087                { yyy = true; $$ = AggregateDecl::Union; }
     2088        | EXCEPTION                                                                                     // CFA
     2089                { yyy = true; $$ = AggregateDecl::Exception; }
     2090        ;
     2091
     2092aggregate_control:                                                                              // CFA
     2093        GENERATOR
     2094                { yyy = true; $$ = AggregateDecl::Generator; }
     2095        | MONITOR GENERATOR
     2096                { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20692097        | COROUTINE
    2070                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     2098                { yyy = true; $$ = AggregateDecl::Coroutine; }
    20712099        | MONITOR
    2072                 { yyy = true; $$ = DeclarationNode::Monitor; }
     2100                { yyy = true; $$ = AggregateDecl::Monitor; }
     2101        | MONITOR COROUTINE
     2102                { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20732103        | THREAD
    2074                 { yyy = true; $$ = DeclarationNode::Thread; }
     2104                { yyy = true; $$ = AggregateDecl::Thread; }
     2105        | MONITOR THREAD
     2106                { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20752107        ;
    20762108
     
    20962128                        distInl( $3 );
    20972129                }
     2130        | INLINE aggregate_control ';'                                          // CFA
     2131                { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }
    20982132        | typedef_declaration ';'                                                       // CFA
    20992133        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
     
    23482382        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    23492383        | initializer_list_opt ',' designation initializer
    2350                 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
     2384                { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
    23512385        ;
    23522386
     
    23702404        designator
    23712405        | designator_list designator
    2372                 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); }
     2406                { $$ = (ExpressionNode *)($1->set_last( $2 )); }
    23732407        //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    23742408        ;
     
    24262460        | type_specifier identifier_parameter_declarator
    24272461        | assertion_list
    2428                 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
     2462                { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    24292463        ;
    24302464
    24312465type_class:                                                                                             // CFA
    24322466        OTYPE
    2433                 { $$ = DeclarationNode::Otype; }
     2467                { $$ = TypeDecl::Otype; }
    24342468        | DTYPE
    2435                 { $$ = DeclarationNode::Dtype; }
     2469                { $$ = TypeDecl::Dtype; }
    24362470        | FTYPE
    2437                 { $$ = DeclarationNode::Ftype; }
     2471                { $$ = TypeDecl::Ftype; }
    24382472        | TTYPE
    2439                 { $$ = DeclarationNode::Ttype; }
     2473                { $$ = TypeDecl::Ttype; }
    24402474        ;
    24412475
     
    24672501                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }
    24682502        | type_list ',' type
    2469                 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); }
     2503                { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }
    24702504        | type_list ',' assignment_expression
    24712505                { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; }
     
    25782612                {
    25792613                        linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2580                         linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
     2614                        linkage = LinkageSpec::update( yylloc, linkage, $2 );
    25812615                }
    25822616          '{' up external_definition_list_opt down '}'
Note: See TracChangeset for help on using the changeset viewer.