Ignore:
Timestamp:
Jun 30, 2016, 4:32:56 PM (10 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ea29e73
Parents:
1b5c81ed (diff), 84d4d6f (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 gc_noraii

Conflicts:

Jenkinsfile
src/SymTab/Validate.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r1b5c81ed rf80e0218  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // cfa.y -- 
    8 // 
     7// cfa.y --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 16:58:43 2016
    13 // Update Count     : 1519
    14 // 
     12// Last Modified On : Mon Jun 27 17:47:56 2016
     13// Update Count     : 1627
     14//
    1515
    1616// This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C
     
    3131// two levels of extensions. The first extensions cover most of the GCC C extensions, except for:
    3232//
    33 // 1. nested functions
    34 // 2. generalized lvalues
    35 // 3. designation with and without '=' (use ':' instead)
    36 // 4. attributes not allowed in parenthesis of declarator
     33// 1. designation with and without '=' (use ':' instead)
     34// 2. attributes not allowed in parenthesis of declarator
    3735//
    3836// All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall
     
    7977%token TYPEOF LABEL                                                                             // GCC
    8078%token ENUM STRUCT UNION
    81 %token OTYPE FTYPE DTYPE TRAIT                                          // CFA
     79%token OTYPE FTYPE DTYPE TRAIT                                                  // CFA
    8280%token SIZEOF OFFSETOF
    8381%token ATTRIBUTE EXTENSION                                                              // GCC
     
    131129%type<constant> constant
    132130%type<en> tuple                                                 tuple_expression_list
    133 %type<en> unary_operator                                assignment_operator
     131%type<en> ptrref_operator                               unary_operator                          assignment_operator
    134132%type<en> primary_expression                    postfix_expression                      unary_expression
    135133%type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression
     
    226224%type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression
    227225%type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr
    228 %type<decl> type_parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier
     226%type<decl> type_parameter_redeclarator type_ptr variable_type_redeclarator typedef_type_specifier
    229227%type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name
    230228
     
    352350        primary_expression
    353351        | postfix_expression '[' push assignment_expression pop ']'
    354                 // CFA, comma_expression disallowed in the context because it results in a commom user error: subscripting a
     352                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    355353                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    356354                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
     
    423421unary_expression:
    424422        postfix_expression
    425         // first location where constant/string can have operator applied: sizeof 3/sizeof "abc"
    426         // still requires semantics checks, e.g., ++3, 3--, *3, &&3
     423                // first location where constant/string can have operator applied: sizeof 3/sizeof "abc" still requires
     424                // semantics checks, e.g., ++3, 3--, *3, &&3
    427425        | constant
    428426                { $$ = $1; }
    429427        | string_literal_list
    430428                { $$ = $1; }
     429        | EXTENSION cast_expression                                                     // GCC
     430                { $$ = $2->set_extension( true ); }
     431        | ptrref_operator cast_expression                                       // CFA
     432                { $$ = new CompositeExprNode( $1, $2 ); }
     433                // '*' ('&') is separated from unary_operator because of shift/reduce conflict in:
     434                //              { * X; }         // dereference X
     435                //              { * int X; } // CFA declaration of pointer to int
     436        | unary_operator cast_expression
     437                { $$ = new CompositeExprNode( $1, $2 ); }
    431438        | ICR unary_expression
    432439                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); }
    433440        | DECR unary_expression
    434441                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); }
    435         | EXTENSION cast_expression                                                     // GCC
    436                 { $$ = $2; }
    437         | unary_operator cast_expression
    438                 { $$ = new CompositeExprNode( $1, $2 ); }
    439         | '!' cast_expression
    440                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neg ), $2 ); }
    441         | '*' cast_expression                                                           // CFA
    442                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PointTo ), $2 ); }
    443                 // '*' is is separated from unary_operator because of shift/reduce conflict in:
    444                 //              { * X; } // dereference X
    445                 //              { * int X; } // CFA declaration of pointer to int
    446                 // '&' must be moved here if C++ reference variables are supported.
    447442        | SIZEOF unary_expression
    448443                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); }
     
    461456        | ALIGNOF '(' type_name_no_function ')'                         // GCC, type alignment
    462457                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); }
    463         | ANDAND no_attr_identifier                                                     // GCC, address of label
    464                 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); }
     458//      | ANDAND IDENTIFIER                                                                     // GCC, address of label
     459//              { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); }
     460        ;
     461
     462ptrref_operator:
     463        '*'                                                                                     { $$ = new OperatorNode( OperatorNode::PointTo ); }
     464        | '&'                                                                           { $$ = new OperatorNode( OperatorNode::AddressOf ); }
     465                // GCC, address of label must be handled by semantic check for ref,ref,label
     466        | ANDAND                                                                        { $$ = new OperatorNode( OperatorNode::And ); }
    465467        ;
    466468
    467469unary_operator:
    468         '&'                                                                                     { $$ = new OperatorNode( OperatorNode::AddressOf ); }
    469         | '+'                                                                           { $$ = new OperatorNode( OperatorNode::UnPlus ); }
     470        '+'                                                                                     { $$ = new OperatorNode( OperatorNode::UnPlus ); }
    470471        | '-'                                                                           { $$ = new OperatorNode( OperatorNode::UnMinus ); }
     472        | '!'                                                                           { $$ = new OperatorNode( OperatorNode::Neg ); }
    471473        | '~'                                                                           { $$ = new OperatorNode( OperatorNode::BitNeg ); }
    472474        ;
     
    646648                        Token fn; fn.str = new std::string( "^?{}" ); // location undefined
    647649                        $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ),
    648                                 (ExpressionNode *)(new CompositeExprNode( new OperatorNode( OperatorNode::AddressOf ), $2 ))->set_link( $4 ) ), 0 );
     650                                (ExpressionNode *)( $2 )->set_link( $4 ) ), 0 );
    649651                }
    650652        ;
    651653
    652654labeled_statement:
    653         no_attr_identifier ':' attribute_list_opt statement
     655                // labels cannot be identifiers 0 or 1
     656        IDENTIFIER ':' attribute_list_opt statement
    654657                {
    655658                        $$ = $4->add_label( $1 );
     
    679682                { $$ = new StatementNode( $1 ); }
    680683        | EXTENSION declaration                                                         // GCC
    681                 { $$ = new StatementNode( $2 ); }
     684                { $$ = new StatementNode( $2 )/*->set_extension( true )*/; }
    682685        | function_definition
    683686                { $$ = new StatementNode( $1 ); }
     
    804807
    805808jump_statement:
    806         GOTO no_attr_identifier ';'
     809        GOTO IDENTIFIER ';'
    807810                { $$ = new StatementNode( StatementNode::Goto, $2 ); }
    808811        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
     
    813816                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    814817                { $$ = new StatementNode( StatementNode::Continue ); }
    815         | CONTINUE no_attr_identifier ';'                                       // CFA, multi-level continue
     818        | CONTINUE IDENTIFIER ';'                                       // CFA, multi-level continue
    816819                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    817820                // the target of the transfer appears only at the start of an iteration statement.
     
    820823                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    821824                { $$ = new StatementNode( StatementNode::Break ); }
    822         | BREAK no_attr_identifier ';'                                          // CFA, multi-level exit
     825        | BREAK IDENTIFIER ';'                                          // CFA, multi-level exit
    823826                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    824827                // the target of the transfer appears only at the start of an iteration statement.
     
    14691472        new_field_declaring_list ';'                                            // CFA, new style field declaration
    14701473        | EXTENSION new_field_declaring_list ';'                        // GCC
    1471                 { $$ = $2; }
     1474                { $$ = $2/*->set_extension( true )*/; }
    14721475        | field_declaring_list ';'
    14731476        | EXTENSION field_declaring_list ';'                            // GCC
    1474                 { $$ = $2; }
     1477                { $$ = $2/*->set_extension( true )*/; }
    14751478        ;
    14761479
     
    15001503                // A semantic check is required to ensure bit_subrange only appears on base type int.
    15011504                { $$ = $1->addBitfield( $2 ); }
    1502         | type_redeclarator bit_subrange_size_opt
     1505        | variable_type_redeclarator bit_subrange_size_opt
    15031506                // A semantic check is required to ensure bit_subrange only appears on base type int.
    15041507                { $$ = $1->addBitfield( $2 ); }
     
    17021705                { $$ = $2; }
    17031706        | ATassign initializer
    1704                 { $$ = $2; }
     1707                { $$ = $2->set_maybeConstructed( false ); }
    17051708        ;
    17061709
     
    17441747
    17451748designator:
    1746         // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0
    1747         // only ".0" and ".1" allowed => semantic check
     1749                // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1"
     1750                // allowed => semantic check
    17481751        FLOATINGconstant
    17491752                { $$ = new DesignatorNode( new VarRefNode( $1 ) ); }
     
    19881991                }
    19891992        | EXTENSION external_definition
    1990                 { $$ = $2; }
     1993                { $$ = $2/*->set_extension( true )*/; }
    19911994        ;
    19921995
     
    19941997        function_definition
    19951998                // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of
    1996                 // code with functions missing a type-specifier on the return type.  Parsing is possible because
    1997                 // function_definition does not appear in the context of an expression (nested functions would preclude this
    1998                 // concession). A function prototype declaration must still have a type_specifier.  OBSOLESCENT (see 1)
     1999                // legacy code with global functions missing the type-specifier for the return type, and assuming "int".
     2000                // Parsing is possible because function_definition does not appear in the context of an expression (nested
     2001                // functions preclude this concession, i.e., all nested function must have a return type). A function prototype
     2002                // declaration must still have a type_specifier.  OBSOLESCENT (see 1)
    19992003        | function_declarator compound_statement
    20002004                {
     
    20742078declarator:
    20752079        variable_declarator
     2080        | variable_type_redeclarator
    20762081        | function_declarator
    2077         | type_redeclarator
    20782082        ;
    20792083
     
    21752179
    21762180variable_ptr:
    2177         '*' variable_declarator
     2181        ptrref_operator variable_declarator
    21782182                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2179         | '*' type_qualifier_list variable_declarator
     2183        | ptrref_operator type_qualifier_list variable_declarator
    21802184                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    21812185        | '(' variable_ptr ')'
     
    22012205        ;
    22022206
    2203 // This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot be nested,
    2204 // there is no context where a function definition can redefine a typedef name. To allow nested functions requires
    2205 // further separation of variable and function declarators in type_redeclarator.  The pattern precludes returning
    2206 // arrays and functions versus pointers to arrays and functions.
     2207// This pattern parses a function declarator that is not redefining a typedef name. For non-nested functions, there is
     2208// no context where a function definition can redefine a typedef name, i.e., the typedef and function name cannot exist
     2209// is the same scope.  The pattern precludes returning arrays and functions versus pointers to arrays and functions.
    22072210
    22082211function_declarator:
     
    22242227
    22252228function_ptr:
    2226         '*' function_declarator
     2229        ptrref_operator function_declarator
    22272230                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2228         | '*' type_qualifier_list function_declarator
     2231        | ptrref_operator type_qualifier_list function_declarator
    22292232                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    22302233        | '(' function_ptr ')'
     
    22612264
    22622265old_function_ptr:
    2263         '*' old_function_declarator
     2266        ptrref_operator old_function_declarator
    22642267                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2265         | '*' type_qualifier_list old_function_declarator
     2268        | ptrref_operator type_qualifier_list old_function_declarator
    22662269                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    22672270        | '(' old_function_ptr ')'
     
    22882291// and functions versus pointers to arrays and functions.
    22892292
    2290 type_redeclarator:
     2293variable_type_redeclarator:
    22912294        paren_type attribute_list_opt
    22922295                { $$ = $1->addQualifiers( $2 ); }
     
    23052308
    23062309type_ptr:
    2307         '*' type_redeclarator
     2310        ptrref_operator variable_type_redeclarator
    23082311                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2309         | '*' type_qualifier_list type_redeclarator
     2312        | ptrref_operator type_qualifier_list variable_type_redeclarator
    23102313                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    23112314        | '(' type_ptr ')'
     
    23492352
    23502353identifier_parameter_ptr:
    2351         '*' identifier_parameter_declarator
     2354        ptrref_operator identifier_parameter_declarator
    23522355                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2353         | '*' type_qualifier_list identifier_parameter_declarator
     2356        | ptrref_operator type_qualifier_list identifier_parameter_declarator
    23542357                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    23552358        | '(' identifier_parameter_ptr ')'
     
    23902393//              not as redundant parentheses around the identifier."
    23912394//
    2392 // which precludes the following cases:
     2395// For example:
    23932396//
    23942397//              typedef float T;
     
    24272430
    24282431type_parameter_ptr:
    2429         '*' type_parameter_redeclarator
     2432        ptrref_operator type_parameter_redeclarator
    24302433                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2431         | '*' type_qualifier_list type_parameter_redeclarator
     2434        | ptrref_operator type_qualifier_list type_parameter_redeclarator
    24322435                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    24332436        | '(' type_parameter_ptr ')'
     
    24672470
    24682471abstract_ptr:
    2469         '*'
     2472        ptrref_operator
    24702473                { $$ = DeclarationNode::newPointer( 0 ); }
    2471         | '*' type_qualifier_list
     2474        | ptrref_operator type_qualifier_list
    24722475                { $$ = DeclarationNode::newPointer( $2 ); }
    2473         | '*' abstract_declarator
     2476        | ptrref_operator abstract_declarator
    24742477                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2475         | '*' type_qualifier_list abstract_declarator
     2478        | ptrref_operator type_qualifier_list abstract_declarator
    24762479                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    24772480        | '(' abstract_ptr ')'
     
    25362539
    25372540abstract_parameter_ptr:
    2538         '*'
     2541        ptrref_operator
    25392542                { $$ = DeclarationNode::newPointer( 0 ); }
    2540         | '*' type_qualifier_list
     2543        | ptrref_operator type_qualifier_list
    25412544                { $$ = DeclarationNode::newPointer( $2 ); }
    2542         | '*' abstract_parameter_declarator
     2545        | ptrref_operator abstract_parameter_declarator
    25432546                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2544         | '*' type_qualifier_list abstract_parameter_declarator
     2547        | ptrref_operator type_qualifier_list abstract_parameter_declarator
    25452548                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    25462549        | '(' abstract_parameter_ptr ')'
     
    26142617
    26152618variable_abstract_ptr:
    2616         '*'
     2619        ptrref_operator
    26172620                { $$ = DeclarationNode::newPointer( 0 ); }
    2618         | '*' type_qualifier_list
     2621        | ptrref_operator type_qualifier_list
    26192622                { $$ = DeclarationNode::newPointer( $2 ); }
    2620         | '*' variable_abstract_declarator
     2623        | ptrref_operator variable_abstract_declarator
    26212624                { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); }
    2622         | '*' type_qualifier_list variable_abstract_declarator
     2625        | ptrref_operator type_qualifier_list variable_abstract_declarator
    26232626                { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); }
    26242627        | '(' variable_abstract_ptr ')'
     
    26592662
    26602663new_identifier_parameter_ptr:                                                   // CFA
    2661         '*' type_specifier
     2664        ptrref_operator type_specifier
    26622665                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2663         | type_qualifier_list '*' type_specifier
     2666        | type_qualifier_list ptrref_operator type_specifier
    26642667                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2665         | '*' new_abstract_function
     2668        | ptrref_operator new_abstract_function
    26662669                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2667         | type_qualifier_list '*' new_abstract_function
     2670        | type_qualifier_list ptrref_operator new_abstract_function
    26682671                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2669         | '*' new_identifier_parameter_declarator_tuple
     2672        | ptrref_operator new_identifier_parameter_declarator_tuple
    26702673                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2671         | type_qualifier_list '*' new_identifier_parameter_declarator_tuple
     2674        | type_qualifier_list ptrref_operator new_identifier_parameter_declarator_tuple
    26722675                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    26732676        ;
     
    27462749
    27472750new_abstract_ptr:                                                                               // CFA
    2748         '*' type_specifier
     2751        ptrref_operator type_specifier
    27492752                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2750         | type_qualifier_list '*' type_specifier
     2753        | type_qualifier_list ptrref_operator type_specifier
    27512754                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2752         | '*' new_abstract_function
     2755        | ptrref_operator new_abstract_function
    27532756                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2754         | type_qualifier_list '*' new_abstract_function
     2757        | type_qualifier_list ptrref_operator new_abstract_function
    27552758                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    2756         | '*' new_abstract_declarator_tuple
     2759        | ptrref_operator new_abstract_declarator_tuple
    27572760                { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0 ) ); }
    2758         | type_qualifier_list '*' new_abstract_declarator_tuple
     2761        | type_qualifier_list ptrref_operator new_abstract_declarator_tuple
    27592762                { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1 ) ); }
    27602763        ;
Note: See TracChangeset for help on using the changeset viewer.