Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r3d7e53b r284da8c  
    254254} // DeclarationNode::newFromTypedef
    255255
    256 DeclarationNode * DeclarationNode::newFromGlobalScope() {
    257         DeclarationNode * newnode = new DeclarationNode;
    258         newnode->type = new TypeData( TypeData::GlobalScope );
    259         return newnode;
    260 }
    261 
    262 DeclarationNode * DeclarationNode::newQualifiedType( DeclarationNode * parent, DeclarationNode * child) {
    263         DeclarationNode * newnode = new DeclarationNode;
    264         newnode->type = new TypeData( TypeData::Qualified );
    265         newnode->type->qualified.parent = parent->type;
    266         newnode->type->qualified.child = child->type;
    267         parent->type = nullptr;
    268         child->type = nullptr;
    269         delete parent;
    270         delete child;
    271         return newnode;
    272 }
    273 
    274256DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     257        assert( name );
    275258        DeclarationNode * newnode = new DeclarationNode;
    276259        newnode->type = new TypeData( TypeData::Aggregate );
    277260        newnode->type->aggregate.kind = kind;
    278         newnode->type->aggregate.name =  name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     261        newnode->type->aggregate.name = name;
    279262        newnode->type->aggregate.actuals = actuals;
    280263        newnode->type->aggregate.fields = fields;
     
    282265        newnode->type->aggregate.tagged = false;
    283266        newnode->type->aggregate.parent = nullptr;
    284         newnode->type->aggregate.anon = name == nullptr;
    285267        return newnode;
    286268} // DeclarationNode::newAggregate
    287269
    288270DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {
     271        assert( name );
    289272        DeclarationNode * newnode = new DeclarationNode;
    290273        newnode->type = new TypeData( TypeData::Enum );
    291         newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     274        newnode->type->enumeration.name = name;
    292275        newnode->type->enumeration.constants = constants;
    293276        newnode->type->enumeration.body = body;
    294         newnode->type->enumeration.anon = name == nullptr;
    295277        return newnode;
    296278} // DeclarationNode::newEnum
     
    971953        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    972954                try {
    973                         bool extracted = false;
    974                         bool anon = false;
    975955                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    976956                                // handle the case where a structure declaration is contained within an object or type declaration
    977957                                Declaration * decl = extr->build();
    978958                                if ( decl ) {
    979                                         // hoist the structure declaration
    980959                                        decl->location = cur->location;
    981960                                        * out++ = decl;
    982 
    983                                         // need to remember the cases where a declaration contains an anonymous aggregate definition
    984                                         extracted = true;
    985                                         assert( extr->type );
    986                                         if ( extr->type->kind == TypeData::Aggregate ) {
    987                                                 anon = extr->type->aggregate.anon;
    988                                         } else if ( extr->type->kind == TypeData::Enum ) {
    989                                                 // xxx - is it useful to have an implicit anonymous enum member?
    990                                                 anon = extr->type->enumeration.anon;
    991                                         }
    992961                                } // if
    993962                                delete extr;
     
    996965                        Declaration * decl = cur->build();
    997966                        if ( decl ) {
    998                                 // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.:
    999                                 // struct S {
    1000                                 //   struct T { int x; }; // no anonymous member
    1001                                 //   struct { int y; };   // anonymous member
    1002                                 //   struct T;            // anonymous member
    1003                                 // };
    1004                                 if ( ! (extracted && decl->name == "" && ! anon) ) {
    1005                                         decl->location = cur->location;
    1006                                         * out++ = decl;
    1007                                 }
     967                                decl->location = cur->location;
     968                                * out++ = decl;
    1008969                        } // if
    1009970                } catch( SemanticErrorException &e ) {
     
    1017978} // buildList
    1018979
    1019 // currently only builds assertions, function parameters, and return values
    1020980void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
    1021981        SemanticErrorException errors;
     
    1025985                try {
    1026986                        Declaration * decl = cur->build();
    1027                         assert( decl );
    1028                         if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    1029                                 dwt->location = cur->location;
    1030                                 * out++ = dwt;
    1031                         } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    1032                                 // e.g., int foo(struct S) {}
    1033                                 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
    1034                                 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1035                                 obj->location = cur->location;
    1036                                 * out++ = obj;
    1037                                 delete agg;
    1038                         } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    1039                                 // e.g., int foo(union U) {}
    1040                                 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
    1041                                 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1042                                 obj->location = cur->location;
    1043                                 * out++ = obj;
    1044                         } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) {
    1045                                 // e.g., int foo(enum E) {}
    1046                                 EnumInstType * inst = new EnumInstType( Type::Qualifiers(), agg->name );
    1047                                 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1048                                 obj->location = cur->location;
    1049                                 * out++ = obj;
     987                        if ( decl ) {
     988                                if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     989                                        dwt->location = cur->location;
     990                                        * out++ = dwt;
     991                                } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     992                                        StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
     993                                        auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     994                                        obj->location = cur->location;
     995                                        * out++ = obj;
     996                                        delete agg;
     997                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     998                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
     999                                        auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1000                                        obj->location = cur->location;
     1001                                        * out++ = obj;
     1002                                } // if
    10501003                        } // if
    10511004                } catch( SemanticErrorException &e ) {
Note: See TracChangeset for help on using the changeset viewer.