Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (4 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (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

    r29d8c02 r74ec742  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 14 16:35:29 2022
    13 // Update Count     : 5276
     12// Last Modified On : Sat May 14 09:16:22 2022
     13// Update Count     : 5401
    1414//
    1515
     
    5454#include "Common/SemanticError.h"                                               // error_str
    5555#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
     56
     57#include "SynTree/Attribute.h"     // for Attribute
    5658
    5759extern DeclarationNode * parseTree;
     
    9395} // appendStr
    9496
    95 DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) {
    96         // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__.
    97         DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier );
     97DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) {
     98        // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__.
     99        assert( declList );
     100//      printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
     101        DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec );
     102//      printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
     103//      cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
     104
    98105        for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    99106                cl->cloneBaseType( cur );
    100107        } // for
    101108        declList->addType( cl );
     109//      printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 );
    102110        return declList;
    103111} // distAttr
     
    111119
    112120void distInl( DeclarationNode * declaration ) {
    113         // distribute EXTENSION across all declarations
     121        // distribute INLINE across all declarations
    114122        for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    115123                iter->set_inLine( true );
     
    171179                if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) {
    172180                        stringstream ss;
    173                         typeSpec->type->print( ss );
     181                        // printf( "fieldDecl1 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
    174182                        SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() );
    175183                        return nullptr;
    176184                } // if
     185                // printf( "fieldDecl2 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout );
    177186                fieldList = DeclarationNode::newName( nullptr );
    178187        } // if
    179         return distAttr( typeSpec, fieldList );                         // mark all fields in list
     188//      return distAttr( typeSpec, fieldList );                         // mark all fields in list
     189
     190        // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 );
     191        DeclarationNode * temp = distAttr( typeSpec, fieldList );                               // mark all fields in list
     192        // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 );
     193        return temp;
    180194} // fieldDecl
    181195
     
    12211235
    12221236iteration_statement:
    1223         WHILE '(' ')' statement                                                         // CFA => while ( 1 )
     1237        WHILE '(' ')' statement                                                         %prec THEN // CFA => while ( 1 )
    12241238                { $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
     1239        | WHILE '(' ')' statement ELSE statement                        // CFA
     1240                {
     1241                        $$ = new StatementNode( build_while( new CondCtl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) );
     1242                        SemanticWarning( yylloc, Warning::SuperfluousElse );
     1243                }
    12251244        | WHILE '(' conditional_declaration ')' statement       %prec THEN
    12261245                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
     
    12291248        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    12301249                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
    1231         | DO statement WHILE '(' comma_expression ')' ';'       %prec THEN
     1250        | DO statement WHILE '(' ')' ELSE statement                     // CFA
     1251                {
     1252                        $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) );
     1253                        SemanticWarning( yylloc, Warning::SuperfluousElse );
     1254                }
     1255        | DO statement WHILE '(' comma_expression ')' ';'
    12321256                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
    12331257        | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
    12341258                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); }
    1235         | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     1259        | FOR '(' ')' statement                                                         %prec THEN // CFA => for ( ;; )
    12361260                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
     1261        | FOR '(' ')' statement ELSE statement                          // CFA
     1262                {
     1263                        $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) );
     1264                        SemanticWarning( yylloc, Warning::SuperfluousElse );
     1265                }
    12371266        | FOR '(' for_control_expression_list ')' statement     %prec THEN
    12381267                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
     
    16051634declaration:                                                                                    // old & new style declarations
    16061635        c_declaration ';'
     1636                {
     1637                        // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );
     1638                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1639                        //   printf( "\tattr %s\n", attr->name.c_str() );
     1640                        // } // for
     1641                }
    16071642        | cfa_declaration ';'                                                           // CFA
    16081643        | static_assert                                                                         // C11
     
    18101845        basic_type_specifier
    18111846        | sue_type_specifier
     1847                {
     1848                        // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     1849                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     1850                        //   printf( "\tattr %s\n", attr->name.c_str() );
     1851                        // } // for
     1852                }
    18121853        | type_type_specifier
    18131854        ;
     
    20262067sue_declaration_specifier:                                                              // struct, union, enum + storage class + type specifier
    20272068        sue_type_specifier
     2069                {
     2070                        // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2071                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2072                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2073                        // } // for
     2074                }
    20282075        | declaration_qualifier_list sue_type_specifier
    20292076                { $$ = $2->addQualifiers( $1 ); }
     
    20362083sue_type_specifier:                                                                             // struct, union, enum + type specifier
    20372084        elaborated_type
     2085                {
     2086                        // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2087                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2088                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2089                        // } // for
     2090                }
    20382091        | type_qualifier_list
    20392092                { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type
     
    21082161elaborated_type:                                                                                // struct, union, enum
    21092162        aggregate_type
     2163                {
     2164                        // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2165                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2166                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2167                        // } // for
     2168                }
    21102169        | enum_type
    21112170        ;
     
    21272186                }
    21282187          '{' field_declaration_list_opt '}' type_parameters_opt
    2129                 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); }
     2188                {
     2189                        // printf( "aggregate_type1 %s\n", $3.str->c_str() );
     2190                        // if ( $2 )
     2191                        //      for ( Attribute * attr: reverseIterate( $2->attributes ) ) {
     2192                        //              printf( "copySpecifiers12 %s\n", attr->name.c_str() );
     2193                        //      } // for
     2194                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     2195                        // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2196                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2197                        //      printf( "aggregate_type3 %s\n", attr->name.c_str() );
     2198                        // } // for
     2199                }
    21302200        | aggregate_key attribute_list_opt TYPEDEFname          // unqualified type name
    21312201                {
     
    21352205          '{' field_declaration_list_opt '}' type_parameters_opt
    21362206                {
     2207                        // printf( "AGG3\n" );
    21372208                        DeclarationNode::newFromTypedef( $3 );
    21382209                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    21452216          '{' field_declaration_list_opt '}' type_parameters_opt
    21462217                {
     2218                        // printf( "AGG4\n" );
    21472219                        DeclarationNode::newFromTypeGen( $3, nullptr );
    21482220                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    22212293field_declaration:
    22222294        type_specifier field_declaring_list_opt ';'
    2223                 { $$ = fieldDecl( $1, $2 ); }
     2295                {
     2296                        // printf( "type_specifier1 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2297                        $$ = fieldDecl( $1, $2 );
     2298                        // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
     2299                        // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
     2300                        //   printf( "\tattr %s\n", attr->name.c_str() );
     2301                        // } // for
     2302                }
    22242303        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    22252304                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     
    23032382        ;
    23042383
    2305 enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );                                                                                         // enum
     2384enum_type:
    23062385        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    23072386                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     
    23182397                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23192398
    2320                         $$ = DeclarationNode::newEnum( nullptr, $7, true ) ->addQualifiers( $5 )  -> addEnumBase( $3 );
    2321                 }
    2322         | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
     2399                        $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 );
     2400                }
     2401        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    23232402                {
    23242403                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    23272406          '{' enumerator_list comma_opt '}'
    23282407                {
    2329                         $$ = DeclarationNode::newEnum( $6, $10, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2408                        $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    23302409                }
    23312410        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23332412                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23342413                        typedefTable.makeTypedef( *$6->name );
    2335                         $$ = DeclarationNode::newEnum( $6->name, $9, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2414                        $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    23362415                }
    23372416        | enum_type_nobody
     
    28302909        // empty
    28312910                { $$ = nullptr; forall = false; }
    2832         | WITH '(' tuple_expression_list ')'
    2833                 { $$ = $3; forall = false; }
     2911        | WITH '(' tuple_expression_list ')' attribute_list_opt
     2912                {
     2913                        $$ = $3; forall = false;
     2914                        if ( $5 ) {
     2915                                SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
     2916                                $$ = nullptr;
     2917                        } // if
     2918                }
    28342919        ;
    28352920
Note: See TracChangeset for help on using the changeset viewer.