Ignore:
Timestamp:
Nov 23, 2017, 1:31:49 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f7a4f89
Parents:
9f10d1f2 (diff), a8b27c6 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r9f10d1f2 r88ef2af  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Oct 25 12:28:54 2017
    13 // Update Count     : 2893
     12// Last Modified On : Mon Nov 20 09:45:36 2017
     13// Update Count     : 2945
    1414//
    1515
     
    114114        } // for
    115115} // distExt
     116
     117// There is an ambiguity for inline generic-routine return-types and generic routines.
     118//   forall( otype T ) struct S { int i; } bar( T ) {}
     119// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
     120//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
     121
     122void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
     123        if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
     124                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
     125                declSpec->type->aggregate.params = nullptr;
     126        } // if
     127} // rebindForall
    116128
    117129bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     
    348360
    349361
    350 // Handle single shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string
    351 // is ambiguous:
    352 // .---------.                          matches IF '(' comma_expression ')' statement . (reduce)
    353 // if ( C ) S1 else S2
    354 // `-----------------'          matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
     362// Handle shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string is ambiguous:
     363//   .---------.                                matches IF '(' comma_expression ')' statement . (reduce)
     364//   if ( C ) S1 else S2
     365//   `-----------------'                matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
    355366// Similar issues exit with the waitfor statement.
    356367
     
    361372%precedence TIMEOUT     // token precedence for start of TIMEOUT in WAITFOR statement
    362373%precedence ELSE        // token precedence for start of else clause in IF/WAITFOR statement
     374
     375// Handle shift/reduce conflict for generic type by shifting the '(' token. For example, this string is ambiguous:
     376//   forall( otype T ) struct Foo { T v; };
     377//       .-----.                                matches pointer to function returning a generic (which is impossible without a type)
     378//   Foo ( *fp )( int );
     379//   `---'                                              matches start of TYPEGENname '('
     380// Must be:
     381// Foo( int ) ( *fp )( int );
     382
     383// Order of these lines matters (low-to-high precedence).
     384%precedence TYPEGENname
     385%precedence '('
    363386
    364387%locations                      // support location tracking for error messages
     
    17651788
    17661789typegen_name:                                                                                   // CFA
    1767         TYPEGENname '(' ')'
     1790        TYPEGENname
     1791                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
     1792        | TYPEGENname '(' ')'
    17681793                { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
    17691794        | TYPEGENname '(' type_list ')'
     
    18091834                }
    18101835        | aggregate_key attribute_list_opt typegen_name         // CFA
    1811                 { $$ = $3->addQualifiers( $2 ); }
     1836                {
     1837                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     1838                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
     1839                        // delete newFromTypeGen.
     1840                        $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 );
     1841                        $3->type->symbolic.name = nullptr;
     1842                        $3->type->symbolic.actuals = nullptr;
     1843                        delete $3;
     1844                }
    18121845        ;
    18131846
     
    23802413        | declaration_specifier function_declarator with_clause_opt compound_statement
    23812414                {
     2415                        rebindForall( $1, $2 );
    23822416                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23832417                        typedefTable.leaveScope();
     
    24062440        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24072441                {
     2442                        rebindForall( $1, $2 );
    24082443                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24092444                        typedefTable.leaveScope();
Note: See TracChangeset for help on using the changeset viewer.