Changeset dc56b9d for src/Parser


Ignore:
Timestamp:
Sep 20, 2022, 9:24:55 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
b6c3688
Parents:
1c893ae (diff), 53a768d (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

Location:
src/Parser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Parser/DeclarationNode.cc

    r1c893ae rdc56b9d  
    254254} // DeclarationNode::newAggregate
    255255
    256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {
     256DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base) {
    257257        DeclarationNode * newnode = new DeclarationNode;
    258258        newnode->type = new TypeData( TypeData::Enum );
     
    261261        newnode->type->enumeration.body = body;
    262262        newnode->type->enumeration.anon = name == nullptr;
     263        newnode->type->enumeration.typed = typed;
    263264        if ( base && base->type)  {
    264265                newnode->type->base = base->type;
    265266        } // if
    266267
    267         // Check: if base has TypeData
    268268        return newnode;
    269269} // DeclarationNode::newEnum
     
    285285
    286286DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) {
    287         if ( init ) { // list init {} or a singleInit
    288                 if ( init->get_expression() ) { // singleInit
     287        if ( init ) {
     288                if ( init->get_expression() ) {
    289289                        return newEnumConstant( name, init->get_expression() );
    290                 } else { // TODO: listInit
     290                } else {
    291291                        DeclarationNode * newnode = newName( name );
    292292                        newnode->initializer = init;
     
    294294                } // if
    295295        } else {
    296                 return newName( name ); // Not explicitly inited enum value;
     296                return newName( name );
    297297        } // if
    298298} // DeclarationNode::newEnumValueGeneric
  • TabularUnified src/Parser/ExpressionNode.cc

    r1c893ae rdc56b9d  
    509509} // build_varref
    510510
     511QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) {
     512        Declaration * newDecl = maybeBuild< Declaration >(decl_node);
     513        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) {
     514                const Type * t = newDeclWithType->get_type();
     515                if ( t ) {
     516                        if ( const TypeInstType * typeInst = dynamic_cast<const TypeInstType *>( t ) ) {
     517                                newDecl= new EnumDecl( typeInst->name );
     518                        }
     519                }
     520        }
     521        auto ret =  new QualifiedNameExpr( newDecl, name->name );
     522        if ( auto e = dynamic_cast<EnumDecl*>(newDecl) ) {
     523                auto enumInst = new EnumInstType( Type::Qualifiers(), e );
     524                auto obj = new ObjectDecl( name->name, Type::StorageClasses(), LinkageSpec::Cforall, nullptr, enumInst, nullptr );
     525                ret->set_var( obj );
     526        }
     527        return ret;
     528}
     529
     530QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl_node, const NameExpr * name ) {
     531        EnumDecl * newDecl = const_cast< EnumDecl * >( decl_node );
     532        return new QualifiedNameExpr( newDecl, name->name );
     533}
     534
    511535DimensionExpr * build_dimensionref( const string * name ) {
    512536        DimensionExpr * expr = new DimensionExpr( *name );
  • TabularUnified src/Parser/ParseNode.h

    r1c893ae rdc56b9d  
    183183
    184184NameExpr * build_varref( const std::string * name );
     185QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name );
     186QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl, const NameExpr * name );
    185187DimensionExpr * build_dimensionref( const std::string * name );
    186188
     
    235237        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    236238        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    237         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, DeclarationNode * base = nullptr );
     239        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base = nullptr );
    238240        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    239241        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
  • TabularUnified src/Parser/TypeData.cc

    r1c893ae rdc56b9d  
    546546                return buildAggInst( td );
    547547          case TypeData::EnumConstant:
    548                 // the name gets filled in later -- by SymTab::Validate
    549548                return new EnumInstType( buildQualifiers( td ), "" );
    550549          case TypeData::SymbolicInst:
     
    921920        assert( td->kind == TypeData::Enum );
    922921        Type * baseType = td->base ? typebuild(td->base) : nullptr;
    923         EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );
     922        EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, td->enumeration.typed, linkage, baseType );
    924923        buildList( td->enumeration.constants, ret->get_members() );
    925924        list< Declaration * >::iterator members = ret->get_members().begin();
    926925        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    927                 if ( cur->has_enumeratorValue() ) {
     926                if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) {
     927                        SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." );
     928                } else if ( cur->has_enumeratorValue() ) {
    928929                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    929930                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
    930931                } else if ( !cur->initializer ) {
    931932                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) {
    932                                 SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." );
     933                                SemanticError( td->location, "Enumerators of an non-integer typed enum must be explicitly initialized." );
    933934                        }
    934935                }
  • TabularUnified src/Parser/TypeData.h

    r1c893ae rdc56b9d  
    5959                bool body;
    6060                bool anon;
     61                bool typed;
    6162        };
    6263
  • TabularUnified src/Parser/parser.yy

    r1c893ae rdc56b9d  
    637637                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
    638638        | type_name '.' identifier                                                      // CFA, nested type
    639                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     639                { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); }
    640640        | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
    641641                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    25382538enum_type:
    25392539        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2540                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     2540                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    25412541        | ENUM attribute_list_opt identifier
    25422542                { typedefTable.makeTypedef( *$3 ); }
    25432543          '{' enumerator_list comma_opt '}'
    2544                 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
     2544                { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); }
    25452545        | ENUM attribute_list_opt typedef_name                          // unqualified type name
    25462546          '{' enumerator_list comma_opt '}'
    2547                 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
    2548         | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    2549                 { SemanticError( yylloc, "Unvalued enumerated type is currently unimplemented." ); $$ = nullptr; }
     2547                { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); }
    25502548        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    25512549                {
     
    25532551                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    25542552
    2555                         $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 );
     2553                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
     2554                }
     2555        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
     2556                {
     2557                        $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 );
    25562558                }
    25572559        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     
    25622564          '{' enumerator_list comma_opt '}'
    25632565                {
    2564                         $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    2565                 }
     2566                        $$ = DeclarationNode::newEnum( $6, $10, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
     2567                }
     2568        | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt
     2569          '{' enumerator_list comma_opt '}'
     2570                {
     2571                        $$ = DeclarationNode::newEnum( $5, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 );
     2572                }       
    25662573        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
    25672574                {
    2568                         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." ); }
    2569                         typedefTable.makeTypedef( *$6->name );
    2570                         $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
     2575                        $$ = DeclarationNode::newEnum( $6->name, $9, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
     2576                }
     2577        | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     2578                {
     2579                        $$ = DeclarationNode::newEnum( $5->name, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 );
    25712580                }
    25722581        | enum_type_nobody
     
    25752584enum_type_nobody:                                                                               // enum - {...}
    25762585        ENUM attribute_list_opt identifier
    2577                 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }
    2578         | ENUM attribute_list_opt type_name                                     // qualified type name
    2579                 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }
     2586                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }
     2587        | ENUM attribute_list_opt type_name     
     2588                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }
    25802589        ;
    25812590
Note: See TracChangeset for help on using the changeset viewer.