Changeset c653b37 for src/Parser


Ignore:
Timestamp:
Jun 28, 2018, 4:04:11 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
e3b2474
Parents:
a12c81f3 (diff), 944ce47 (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:/u/cforall/software/cfa/cfa-cc

Location:
src/Parser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypedefTable.cc

    ra12c81f3 rc653b37  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 13:17:56 2018
    13 // Update Count     : 192
     12// Last Modified On : Fri Jun 22 06:14:39 2018
     13// Update Count     : 206
    1414//
    1515
     
    7878        debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
    7979        auto ret = kindTable.insertAt( scope, identifier, kind );
    80         if ( ! ret.second ) ret.first->second = kind;           // exists => update
     80        //if ( ! ret.second ) ret.first->second = kind;         // exists => update
     81        assert( ret.first->second == kind );                            // exists
    8182} // TypedefTable::addToScope
    8283
    8384void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) {
    84         assert( kindTable.currentScope() >= 1 );
    85         auto scope = kindTable.currentScope() - 1;
    86         debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
     85        assert( kindTable.currentScope() >= 1 + level );
     86        auto scope = kindTable.currentScope() - 1 - level;
     87        debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << endl );
    8788        auto ret = kindTable.insertAt( scope, identifier, kind );
    8889        if ( ! ret.second ) ret.first->second = kind;           // exists => update
     
    9192void TypedefTable::enterScope() {
    9293        kindTable.beginScope();
    93         debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl );
    94         debugPrint( print() );
     94        debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() );
    9595} // TypedefTable::enterScope
    9696
    9797void TypedefTable::leaveScope() {
    98         debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl );
    99         debugPrint( print() );
     98        debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl; print() );
    10099        kindTable.endScope();
    101100} // TypedefTable::leaveScope
     
    114113                --scope;
    115114                debugPrint( cerr << endl << "[" << scope << "]" );
    116         }
     115        } // while
    117116        debugPrint( cerr << endl );
    118 }
     117} // TypedefTable::print
    119118
    120119// Local Variables: //
  • src/Parser/TypedefTable.h

    ra12c81f3 rc653b37  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 12:10:17 2018
    13 // Update Count     : 85
     12// Last Modified On : Fri Jun 22 05:29:58 2018
     13// Update Count     : 86
    1414//
    1515
     
    2525        typedef ScopedMap< std::string, int > KindTable;
    2626        KindTable kindTable;   
     27        unsigned int level = 0;
    2728  public:
    2829        ~TypedefTable();
     
    3738        void leaveScope();
    3839
     40        void up() { level += 1; }
     41        void down() { level -= 1; }
     42
    3943        void print( void ) const;
    4044}; // TypedefTable
  • src/Parser/lex.ll

    ra12c81f3 rc653b37  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu Jun  7 08:27:40 2018
    13  * Update Count     : 679
     12 * Last Modified On : Wed Jun 20 09:08:28 2018
     13 * Update Count     : 682
    1414 */
    1515
     
    2525//**************************** Includes and Defines ****************************
    2626
     27// trigger before each matching rule's action
     28#define YY_USER_ACTION \
     29        yylloc.first_line = yylineno; \
     30        yylloc.first_column = column; \
     31        column += yyleng; \
     32        yylloc.last_column = column; \
     33        yylloc.last_line = yylineno; \
     34        yylloc.filename = yyfilename ? yyfilename : "";
    2735unsigned int column = 0;                                                                // position of the end of the last token parsed
    28 #define YY_USER_ACTION yylloc.first_line = yylineno; yylloc.first_column = column; column += yyleng; yylloc.last_column = column; yylloc.last_line = yylineno; yylloc.filename = yyfilename ? yyfilename : "";                          // trigger before each matching rule's action
    2936
    3037#include <string>
     
    4956#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
    5057#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
    51 #define QKEYWORD_RETURN(x)      typedefTable.isKind( yytext ); RETURN_VAL(x); // quasi-keyword
     58#define QKEYWORD_RETURN(x)      RETURN_VAL(x);                          // quasi-keyword
    5259#define IDENTIFIER_RETURN()     RETURN_VAL( typedefTable.isKind( yytext ) )
    5360#define ATTRIBUTE_RETURN()      RETURN_VAL( ATTR_IDENTIFIER )
  • src/Parser/parser.yy

    ra12c81f3 rc653b37  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun  7 10:07:12 2018
    13 // Update Count     : 3527
     12// Last Modified On : Sun Jun 24 10:41:10 2018
     13// Update Count     : 3587
    1414//
    1515
     
    136136} // build_postfix_name
    137137
    138 bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
     138bool forall = false, xxx = false, yyy = false;                  // aggregate have one or more forall qualifiers ?
    139139
    140140// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    304304%type<en> enumerator_value_opt
    305305
    306 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
     306%type<decl> external_definition external_definition_list external_definition_list_opt
     307
     308%type<decl> exception_declaration
    307309
    308310%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    503505                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    504506        | type_name '.' no_attr_identifier                                      // CFA, nested type
    505                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    506                 { $$ = nullptr; }
     507                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    507508        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    508                 // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    509                 { $$ = nullptr; }
     509                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    510510        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    511511                {
     
    18211821        ;
    18221822
     1823fred:
     1824        // empty
     1825                { yyy = false; }
     1826        ;
     1827
    18231828aggregate_type:                                                                                 // struct, union
    18241829        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    18251830                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1826         | aggregate_key attribute_list_opt no_attr_identifier
     1831        | aggregate_key attribute_list_opt no_attr_identifier fred
    18271832                {
    18281833                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1829                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18301834                        forall = false;                                                         // reset
    18311835                }
    18321836          '{' field_declaration_list_opt '}'
    1833                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1834         | aggregate_key attribute_list_opt type_name
     1837                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
     1838        | aggregate_key attribute_list_opt type_name fred
    18351839                {
    18361840                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
    1837                         //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
    18381841                        forall = false;                                                         // reset
    18391842                }
    18401843          '{' field_declaration_list_opt '}'
    1841                 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $6, true )->addQualifiers( $2 ); }
     1844                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); }
    18421845        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18431846                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     
    18461849
    18471850aggregate_type_nobody:                                                                  // struct, union - {...}
    1848         aggregate_key attribute_list_opt no_attr_identifier
     1851        aggregate_key attribute_list_opt no_attr_identifier fred
    18491852                {
    18501853                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
    1851                         //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18521854                        forall = false;                                                         // reset
    18531855                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18541856                }
    1855         | aggregate_key attribute_list_opt type_name
     1857        | aggregate_key attribute_list_opt type_name fred
    18561858                {
    18571859                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18671869aggregate_key:
    18681870        STRUCT
    1869                 { $$ = DeclarationNode::Struct; }
     1871                { yyy = true; $$ = DeclarationNode::Struct; }
    18701872        | UNION
    1871                 { $$ = DeclarationNode::Union; }
     1873                { yyy = true; $$ = DeclarationNode::Union; }
    18721874        | EXCEPTION
    1873                 { $$ = DeclarationNode::Exception; }
     1875                { yyy = true; $$ = DeclarationNode::Exception; }
    18741876        | COROUTINE
    1875                 { $$ = DeclarationNode::Coroutine; }
     1877                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18761878        | MONITOR
    1877                 { $$ = DeclarationNode::Monitor; }
     1879                { yyy = true; $$ = DeclarationNode::Monitor; }
    18781880        | THREAD
    1879                 { $$ = DeclarationNode::Thread; }
     1881                { yyy = true; $$ = DeclarationNode::Thread; }
    18801882        ;
    18811883
     
    23202322
    23212323translation_unit:
    2322         // empty
    2323                 {}                                                                                              // empty input file
     2324        // empty, input file
    23242325        | external_definition_list
    23252326                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    23352336        ;
    23362337
    2337         // SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope.
    2338         // However, external_definition_list creates a new scope around each external_definition, but the pop loses all the
    2339         // types in the extern "X" and distribution at the end of the block. This version of external_definition_list does
    2340 
    2341         // not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of
    2342         // external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level.
    2343 external_definition_list_no_pop_push:
    2344         external_definition
    2345         | external_definition_list_no_pop_push
    2346                 { forall = xxx; }
    2347           external_definition
    2348                 { $$ = $1 ? $1->appendList( $3 ) : $3; }
    2349         ;
    2350 
    23512338external_definition_list_opt:
    23522339        // empty
    23532340                { $$ = nullptr; }
    2354         | external_definition_list_no_pop_push
     2341        | external_definition_list
     2342        ;
     2343
     2344up:
     2345                { typedefTable.up(); }
     2346        ;
     2347
     2348down:
     2349                { typedefTable.down(); }
    23552350        ;
    23562351
     
    23722367                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23732368                }
    2374           '{' external_definition_list_opt '}'
     2369          '{' up external_definition_list_opt down '}'
    23752370                {
    23762371                        linkage = linkageStack.top();
    23772372                        linkageStack.pop();
    2378                         $$ = $5;
     2373                        $$ = $6;
    23792374                }
    23802375        | type_qualifier_list
    2381                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2382           '{' external_definition_list_opt '}'                          // CFA, namespace
    2383                 {
    2384                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2376                {
     2377                        if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2378                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2379                }
     2380          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2381                {
     2382                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23852383                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23862384                                        iter->addQualifiers( $1->clone() );
     
    23892387                        xxx = false;
    23902388                        delete $1;
    2391                         $$ = $4;
     2389                        $$ = $5;
    23922390                }
    23932391        | declaration_qualifier_list
    2394                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2395           '{' external_definition_list_opt '}'                          // CFA, namespace
    2396                 {
    2397                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2392                {
     2393                        if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2394                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2395                }
     2396          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2397                {
     2398                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23982399                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23992400                                        iter->addQualifiers( $1->clone() );
     
    24022403                        xxx = false;
    24032404                        delete $1;
    2404                         $$ = $4;
     2405                        $$ = $5;
    24052406                }
    24062407        | declaration_qualifier_list type_qualifier_list
    24072408                {
    2408                         // forall must be in the type_qualifier_list
    2409                         if ( $2->type->forall ) xxx = forall = true; // remember generic type
    2410                 }
    2411           '{' external_definition_list_opt '}'                          // CFA, namespace
    2412                 {
    2413                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2409                        if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2410                        if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type
     2411                }
     2412          '{' up external_definition_list_opt down '}'          // CFA, namespace
     2413                {
     2414                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    24142415                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    24152416                                        iter->addQualifiers( $1->clone() );
     
    24202421                        delete $1;
    24212422                        delete $2;
    2422                         $$ = $5;
     2423                        $$ = $6;
    24232424                }
    24242425        ;
Note: See TracChangeset for help on using the changeset viewer.