Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rbb7422a r0d0931d  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr  4 10:28:00 2023
    13 // Update Count     : 1392
     12// Last Modified On : Tue Mar 14 11:56:00 2023
     13// Update Count     : 1406
    1414//
    1515
     
    2121#include <string>                  // for string, operator+, allocator, char...
    2222
    23 #include "AST/Attribute.hpp"       // for Attribute
    24 #include "AST/Copy.hpp"            // for shallowCopy
    25 #include "AST/Decl.hpp"            // for Decl
    26 #include "AST/Expr.hpp"            // for Expr
    27 #include "AST/Print.hpp"           // for print
    28 #include "AST/Stmt.hpp"            // for AsmStmt, DirectiveStmt
    29 #include "AST/StorageClasses.hpp"  // for Storage::Class
    30 #include "AST/Type.hpp"            // for Type
    31 #include "Common/CodeLocation.h"   // for CodeLocation
    32 #include "Common/Iterate.hpp"      // for reverseIterate
    3323#include "Common/SemanticError.h"  // for SemanticError
    3424#include "Common/UniqueName.h"     // for UniqueName
    35 #include "Common/utility.h"        // for maybeClone
     25#include "Common/utility.h"        // for maybeClone, maybeBuild, CodeLocation
    3626#include "Parser/ParseNode.h"      // for DeclarationNode, ExpressionNode
     27#include "SynTree/LinkageSpec.h"   // for Spec, linkageName, Cforall
     28#include "SynTree/Attribute.h"     // for Attribute
     29#include "SynTree/Declaration.h"   // for TypeDecl, ObjectDecl, InlineMemberDecl, Declaration
     30#include "SynTree/Expression.h"    // for Expression, ConstantExpr
     31#include "SynTree/Statement.h"     // for AsmStmt
     32#include "SynTree/Type.h"          // for Type, Type::StorageClasses, Type::...
    3733#include "TypeData.h"              // for TypeData, TypeData::Aggregate_t
    3834#include "TypedefTable.h"          // for TypedefTable
     
    6561UniqueName DeclarationNode::anonymous( "__anonymous" );
    6662
    67 extern ast::Linkage::Spec linkage;                                              // defined in parser.yy
     63extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
    6864
    6965DeclarationNode::DeclarationNode() :
     
    7167
    7268//      variable.name = nullptr;
    73         variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS;
     69        variable.tyClass = TypeDecl::NUMBER_OF_KINDS;
    7470        variable.assertions = nullptr;
    7571        variable.initializer = nullptr;
     
    109105        newnode->hasEllipsis = hasEllipsis;
    110106        newnode->linkage = linkage;
    111         newnode->asmName = maybeCopy( asmName );
    112         newnode->attributes = attributes;
     107        newnode->asmName = maybeClone( asmName );
     108        cloneAll( attributes, newnode->attributes );
    113109        newnode->initializer = maybeClone( initializer );
    114110        newnode->extension = extension;
     
    122118
    123119        newnode->assert.condition = maybeClone( assert.condition );
    124         newnode->assert.message = maybeCopy( assert.message );
     120        newnode->assert.message = maybeClone( assert.message );
    125121        return newnode;
    126122} // DeclarationNode::clone
     
    132128        } // if
    133129
    134         if ( linkage != ast::Linkage::Cforall ) {
    135                 os << ast::Linkage::name( linkage ) << " ";
    136         } // if
    137 
    138         ast::print( os, storageClasses );
    139         ast::print( os, funcSpecs );
     130        if ( linkage != LinkageSpec::Cforall ) {
     131                os << LinkageSpec::name( linkage ) << " ";
     132        } // if
     133
     134        storageClasses.print( os );
     135        funcSpecs.print( os );
    140136
    141137        if ( type ) {
     
    158154        if ( ! attributes.empty() ) {
    159155                os << string( indent + 2, ' ' ) << "with attributes " << endl;
    160                 for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) {
     156                for ( Attribute * attr: reverseIterate( attributes ) ) {
    161157                        os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
    162158                } // for
     
    173169}
    174170
    175 DeclarationNode * DeclarationNode::newStorageClass( ast::Storage::Classes sc ) {
     171DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) {
    176172        DeclarationNode * newnode = new DeclarationNode;
    177173        newnode->storageClasses = sc;
     
    179175} // DeclarationNode::newStorageClass
    180176
    181 DeclarationNode * DeclarationNode::newFuncSpecifier( ast::Function::Specs fs ) {
     177DeclarationNode * DeclarationNode::newFuncSpecifier( Type::FuncSpecifiers fs ) {
    182178        DeclarationNode * newnode = new DeclarationNode;
    183179        newnode->funcSpecs = fs;
     
    185181} // DeclarationNode::newFuncSpecifier
    186182
    187 DeclarationNode * DeclarationNode::newTypeQualifier( ast::CV::Qualifiers tq ) {
     183DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) {
    188184        DeclarationNode * newnode = new DeclarationNode;
    189185        newnode->type = new TypeData();
     
    245241}
    246242
    247 DeclarationNode * DeclarationNode::newAggregate( ast::AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     243DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    248244        DeclarationNode * newnode = new DeclarationNode;
    249245        newnode->type = new TypeData( TypeData::Aggregate );
     
    275271} // DeclarationNode::newEnum
    276272
     273
     274
    277275DeclarationNode * DeclarationNode::newName( const string * name ) {
    278276        DeclarationNode * newnode = new DeclarationNode;
     
    326324} // DeclarationNode::newFromTypeGen
    327325
    328 DeclarationNode * DeclarationNode::newTypeParam( ast::TypeDecl::Kind tc, const string * name ) {
     326DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) {
    329327        DeclarationNode * newnode = newName( name );
    330328        newnode->type = nullptr;
     
    338336        newnode->type = new TypeData( TypeData::Aggregate );
    339337        newnode->type->aggregate.name = name;
    340         newnode->type->aggregate.kind = ast::AggregateDecl::Trait;
     338        newnode->type->aggregate.kind = AggregateDecl::Trait;
    341339        newnode->type->aggregate.params = params;
    342340        newnode->type->aggregate.fields = asserts;
     
    348346        newnode->type = new TypeData( TypeData::AggregateInst );
    349347        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    350         newnode->type->aggInst.aggregate->aggregate.kind = ast::AggregateDecl::Trait;
     348        newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait;
    351349        newnode->type->aggInst.aggregate->aggregate.name = name;
    352350        newnode->type->aggInst.params = params;
     
    383381        newnode->type->array.dimension = size;
    384382        newnode->type->array.isStatic = isStatic;
    385         if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ast::ConstantExpr *>() ) {
     383        if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
    386384                newnode->type->array.isVarLen = false;
    387385        } else {
     
    453451        DeclarationNode * newnode = new DeclarationNode;
    454452        newnode->type = nullptr;
    455         std::vector<ast::ptr<ast::Expr>> exprs;
     453        std::list< Expression * > exprs;
    456454        buildList( expr, exprs );
    457         newnode->attributes.push_back(
    458                 new ast::Attribute( *name, std::move( exprs ) ) );
     455        newnode->attributes.push_back( new Attribute( *name, exprs ) );
    459456        delete name;
    460457        return newnode;
     
    473470}
    474471
    475 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, ast::Expr * message ) {
     472DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression * message ) {
    476473        DeclarationNode * newnode = new DeclarationNode;
    477474        newnode->assert.condition = condition;
     
    480477}
    481478
    482 static void appendError( string & dst, const string & src ) {
     479
     480void appendError( string & dst, const string & src ) {
    483481        if ( src.empty() ) return;
    484482        if ( dst.empty() ) { dst = src; return; }
     
    487485
    488486void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
    489         const ast::CV::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    490         const ast::CV::Qualifiers duplicates = qsrc & qdst;
    491 
    492         if ( duplicates.any() ) {
    493                 std::stringstream str;
    494                 str << "duplicate ";
    495                 ast::print( str, duplicates );
    496                 str << "qualifier(s)";
    497                 appendError( error, str.str() );
     487        const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
     488
     489        if ( (qsrc & qdst).any() ) {                                            // duplicates ?
     490                for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates
     491                        if ( qsrc[i] && qdst[i] ) {
     492                                appendError( error, string( "duplicate " ) + Type::QualifiersNames[i] );
     493                        } // if
     494                } // for
    498495        } // for
    499496} // DeclarationNode::checkQualifiers
    500497
    501498void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
    502         ast::Function::Specs fsDups = funcSpecs & src->funcSpecs;
    503         if ( fsDups.any() ) {
    504                 std::stringstream str;
    505                 str << "duplicate ";
    506                 ast::print( str, fsDups );
    507                 str << "function specifier(s)";
    508                 appendError( error, str.str() );
    509         } // if
    510 
    511         // Skip if everything is unset.
    512         if ( storageClasses.any() && src->storageClasses.any() ) {
    513                 ast::Storage::Classes dups = storageClasses & src->storageClasses;
    514                 // Check for duplicates.
    515                 if ( dups.any() ) {
    516                         std::stringstream str;
    517                         str << "duplicate ";
    518                         ast::print( str, dups );
    519                         str << "storage class(es)";
    520                         appendError( error, str.str() );
    521                 // Check for conflicts.
    522                 } else if ( !src->storageClasses.is_threadlocal_any() ) {
    523                         std::stringstream str;
    524                         str << "conflicting ";
    525                         ast::print( str, ast::Storage::Classes( 1 << storageClasses.ffs() ) );
    526                         str << "& ";
    527                         ast::print( str, ast::Storage::Classes( 1 << src->storageClasses.ffs() ) );
    528                         str << "storage classes";
    529                         appendError( error, str.str() );
    530                         // FIX to preserve invariant of one basic storage specifier
    531                         src->storageClasses.reset();
    532                 }
     499        if ( (funcSpecs & src->funcSpecs).any() ) {                     // duplicates ?
     500                for ( unsigned int i = 0; i < Type::NumFuncSpecifier; i += 1 ) { // find duplicates
     501                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
     502                                appendError( error, string( "duplicate " ) + Type::FuncSpecifiersNames[i] );
     503                        } // if
     504                } // for
     505        } // if
     506
     507        if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ?
     508                if ( (storageClasses & src->storageClasses ).any() ) { // duplicates ?
     509                        for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates
     510                                if ( storageClasses[i] && src->storageClasses[i] ) {
     511                                        appendError( error, string( "duplicate " ) + Type::StorageClassesNames[i] );
     512                                } // if
     513                        } // for
     514                        // src is the new item being added and has a single bit
     515                } else if ( ! src->storageClasses.is_threadlocal_any() ) { // conflict ?
     516                        appendError( error, string( "conflicting " )
     517                                + Type::StorageClassesNames[storageClasses.ffs()]
     518                                + " & " + Type::StorageClassesNames[src->storageClasses.ffs()] );
     519                        src->storageClasses.reset();                            // FIX to preserve invariant of one basic storage specifier
     520                } // if
    533521        } // if
    534522
     
    540528        storageClasses |= q->storageClasses;
    541529
    542         std::vector<ast::ptr<ast::Attribute>> tmp;
    543         tmp.reserve( q->attributes.size() );
    544         for ( auto const & attr : q->attributes ) {
    545                 tmp.emplace_back( ast::shallowCopy( attr.get() ) );
    546         }
    547         spliceBegin( attributes, tmp );
    548 
     530        for ( Attribute * attr: reverseIterate( q->attributes ) ) {
     531                attributes.push_front( attr->clone() );
     532        } // for
    549533        return this;
    550534} // DeclarationNode::copySpecifiers
     
    732716
    733717DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
    734         if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
     718        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    735719                if ( variable.assertions ) {
    736720                        variable.assertions->appendList( assertions );
     
    814798DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
    815799        if ( a ) {
    816                 spliceBegin( attributes, a->attributes );
     800                for ( Attribute *attr: reverseIterate( a->attributes ) ) {
     801                        attributes.push_front( attr );
     802                } // for
    817803                a->attributes.clear();
    818804        } // if
     
    935921
    936922DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
    937         assertf( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
     923        assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
    938924        variable.initializer = init;
    939925        return this;
     
    999985}
    1000986
    1001 void buildList( const DeclarationNode * firstNode,
    1002                 std::vector<ast::ptr<ast::Decl>> & outputList ) {
     987void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) {
    1003988        SemanticErrorException errors;
    1004         std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList );
     989        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    1005990
    1006991        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    1007992                try {
    1008993                        bool extracted = false, anon = false;
    1009                         ast::AggregateDecl * unionDecl = nullptr;
     994                        AggregateDecl * unionDecl = nullptr;
    1010995
    1011996                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
     
    10441029                                } // if
    10451030
    1046                                 ast::Decl * decl = extr->build();
     1031                                Declaration * decl = extr->build();
    10471032                                if ( decl ) {
    10481033                                        // Remember the declaration if it is a union aggregate ?
    1049                                         unionDecl = dynamic_cast<ast::UnionDecl *>( decl );
     1034                                        unionDecl = dynamic_cast<UnionDecl *>( decl );
    10501035
    10511036                                        decl->location = cur->location;
     
    10661051                        } // if
    10671052
    1068                         ast::Decl * decl = cur->build();
     1053                        Declaration * decl = cur->build();
    10691054                        if ( decl ) {
    1070                                 if ( auto typedefDecl = dynamic_cast<ast::TypedefDecl *>( decl ) ) {
     1055                                if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) {
    10711056                                        if ( unionDecl ) {                                      // is the typedef alias a union aggregate ?
    10721057                                                // This code handles a special issue with the attribute transparent_union.
     
    10801065
    10811066                                                // If typedef is an alias for a union, then its alias type was hoisted above and remembered.
    1082                                                 if ( auto unionInstType = typedefDecl->base.as<ast::UnionInstType>() ) {
    1083                                                         auto instType = ast::mutate( unionInstType );
     1067                                                if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) {
    10841068                                                        // Remove all transparent_union attributes from typedef and move to alias union.
    1085                                                         for ( auto attr = instType->attributes.begin() ; attr != instType->attributes.end() ; ) { // forward order
    1086                                                                 assert( *attr );
     1069                                                        list<Attribute *>::iterator attr;
     1070                                                        for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order
    10871071                                                                if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
    1088                                                                         unionDecl->attributes.emplace_back( attr->release() );
    1089                                                                         attr = instType->attributes.erase( attr );
     1072                                                                        list<Attribute *>::iterator cur = attr; // remember current node
     1073                                                                        attr++;                         // advance iterator
     1074                                                                        unionDecl->attributes.emplace_back( *cur ); // move current
     1075                                                                        unionInstType->attributes.erase( cur ); // remove current
    10901076                                                                } else {
    1091                                                                         attr++;
     1077                                                                        attr++;                         // advance iterator
    10921078                                                                } // if
    10931079                                                        } // for
    1094                                                         typedefDecl->base = instType;
    10951080                                                } // if
    10961081                                        } // if
     
    11051090                                if ( ! (extracted && decl->name == "" && ! anon && ! cur->get_inLine()) ) {
    11061091                                        if ( decl->name == "" ) {
    1107                                                 if ( auto dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
    1108                                                         if ( auto aggr = dynamic_cast<ast::BaseInstType const *>( dwt->get_type() ) ) {
     1092                                                if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>( decl ) ) {
     1093                                                        if ( ReferenceToType * aggr = dynamic_cast<ReferenceToType *>( dwt->get_type() ) ) {
    11091094                                                                if ( aggr->name.find("anonymous") == std::string::npos ) {
    11101095                                                                        if ( ! cur->get_inLine() ) {
     
    11321117
    11331118// currently only builds assertions, function parameters, and return values
    1134 void buildList( const DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ) {
     1119void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ) {
    11351120        SemanticErrorException errors;
    1136         std::back_insert_iterator<std::vector<ast::ptr<ast::DeclWithType>>> out( outputList );
     1121        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    11371122
    11381123        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    11391124                try {
    1140                         ast::Decl * decl = cur->build();
     1125                        Declaration * decl = cur->build();
    11411126                        assert( decl );
    1142                         if ( ast::DeclWithType * dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
     1127                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    11431128                                dwt->location = cur->location;
    11441129                                *out++ = dwt;
    1145                         } else if ( ast::StructDecl * agg = dynamic_cast<ast::StructDecl *>( decl ) ) {
     1130                        } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    11461131                                // e.g., int foo(struct S) {}
    1147                                 auto inst = new ast::StructInstType( agg->name );
    1148                                 auto obj = new ast::ObjectDecl( cur->location, "", inst );
    1149                                 obj->linkage = linkage;
     1132                                StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
     1133                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1134                                obj->location = cur->location;
    11501135                                *out++ = obj;
    11511136                                delete agg;
    1152                         } else if ( ast::UnionDecl * agg = dynamic_cast<ast::UnionDecl *>( decl ) ) {
     1137                        } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    11531138                                // e.g., int foo(union U) {}
    1154                                 auto inst = new ast::UnionInstType( agg->name );
    1155                                 auto obj = new ast::ObjectDecl( cur->location,
    1156                                         "", inst, nullptr, ast::Storage::Classes(),
    1157                                         linkage );
     1139                                UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
     1140                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1141                                obj->location = cur->location;
    11581142                                *out++ = obj;
    1159                         } else if ( ast::EnumDecl * agg = dynamic_cast<ast::EnumDecl *>( decl ) ) {
     1143                        } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) {
    11601144                                // e.g., int foo(enum E) {}
    1161                                 auto inst = new ast::EnumInstType( agg->name );
    1162                                 auto obj = new ast::ObjectDecl( cur->location,
    1163                                         "",
    1164                                         inst,
    1165                                         nullptr,
    1166                                         ast::Storage::Classes(),
    1167                                         linkage
    1168                                 );
     1145                                EnumInstType * inst = new EnumInstType( Type::Qualifiers(), agg->name );
     1146                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1147                                obj->location = cur->location;
    11691148                                *out++ = obj;
    11701149                        } // if
     
    11791158} // buildList
    11801159
    1181 void buildTypeList( const DeclarationNode * firstNode,
    1182                 std::vector<ast::ptr<ast::Type>> & outputList ) {
     1160void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) {
    11831161        SemanticErrorException errors;
    1184         std::back_insert_iterator<std::vector<ast::ptr<ast::Type>>> out( outputList );
     1162        std::back_insert_iterator< std::list< Type * > > out( outputList );
    11851163        const DeclarationNode * cur = firstNode;
    11861164
     
    11991177} // buildTypeList
    12001178
    1201 ast::Decl * DeclarationNode::build() const {
     1179Declaration * DeclarationNode::build() const {
    12021180        if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
    12031181
    12041182        if ( asmStmt ) {
    1205                 auto stmt = strict_dynamic_cast<ast::AsmStmt *>( asmStmt->build() );
    1206                 return new ast::AsmDecl( stmt->location, stmt );
     1183                return new AsmDecl( strict_dynamic_cast<AsmStmt *>( asmStmt->build() ) );
    12071184        } // if
    12081185        if ( directiveStmt ) {
    1209                 auto stmt = strict_dynamic_cast<ast::DirectiveStmt *>( directiveStmt->build() );
    1210                 return new ast::DirectiveDecl( stmt->location, stmt );
    1211         } // if
    1212 
    1213         if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
     1186                return new DirectiveDecl( strict_dynamic_cast<DirectiveStmt *>( directiveStmt->build() ) );
     1187        } // if
     1188
     1189        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    12141190                // otype is internally converted to dtype + otype parameters
    1215                 static const ast::TypeDecl::Kind kindMap[] = { ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Ftype, ast::TypeDecl::Ttype, ast::TypeDecl::Dimension };
    1216                 static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == ast::TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
     1191                static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::Dimension };
     1192                static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );
    12171193                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1218                 ast::TypeDecl * ret = new ast::TypeDecl( location,
    1219                         *name,
    1220                         ast::Storage::Classes(),
    1221                         (ast::Type *)nullptr,
    1222                         kindMap[ variable.tyClass ],
    1223                         variable.tyClass == ast::TypeDecl::Otype || variable.tyClass == ast::TypeDecl::DStype,
    1224                         variable.initializer ? variable.initializer->buildType() : nullptr
    1225                 );
    1226                 buildList( variable.assertions, ret->assertions );
     1194                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::DStype, variable.initializer ? variable.initializer->buildType() : nullptr );
     1195                buildList( variable.assertions, ret->get_assertions() );
    12271196                return ret;
    12281197        } // if
     
    12461215                } // if
    12471216                bool isDelete = initializer && initializer->get_isDelete();
    1248                 ast::Decl * decl = buildDecl(
    1249                         type,
    1250                         name ? *name : string( "" ),
    1251                         storageClasses,
    1252                         maybeBuild( bitfieldWidth ),
    1253                         funcSpecs,
    1254                         linkage,
    1255                         asmName,
    1256                         isDelete ? nullptr : maybeBuild( initializer ),
    1257                         copy( attributes )
    1258                 )->set_extension( extension );
     1217                Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild(initializer), attributes )->set_extension( extension );
    12591218                if ( isDelete ) {
    1260                         auto dwt = strict_dynamic_cast<ast::DeclWithType *>( decl );
     1219                        DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );
    12611220                        dwt->isDeleted = true;
    12621221                }
     
    12651224
    12661225        if ( assert.condition ) {
    1267                 auto cond = maybeBuild( assert.condition );
    1268                 auto msg = strict_dynamic_cast<ast::ConstantExpr *>( maybeCopy( assert.message ) );
    1269                 return new ast::StaticAssertDecl( location, cond, msg );
     1226                return new StaticAssertDecl( maybeBuild( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );
    12701227        }
    12711228
     
    12781235        } // if
    12791236        if ( enumInLine ) {
    1280                 return new ast::InlineMemberDecl( location,
    1281                         *name, (ast::Type*)nullptr, storageClasses, linkage );
     1237                return new InlineMemberDecl( *name, storageClasses, linkage, nullptr );
    12821238        } // if
    12831239        assertf( name, "ObjectDecl must a have name\n" );
    1284         auto ret = new ast::ObjectDecl( location,
    1285                 *name,
    1286                 (ast::Type*)nullptr,
    1287                 maybeBuild( initializer ),
    1288                 storageClasses,
    1289                 linkage,
    1290                 maybeBuild( bitfieldWidth )
    1291         );
    1292         ret->asmName = asmName;
    1293         ret->extension = extension;
    1294         return ret;
    1295 }
    1296 
    1297 ast::Type * DeclarationNode::buildType() const {
     1240        return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild( bitfieldWidth ), nullptr, maybeBuild( initializer ) ))->set_asmName( asmName )->set_extension( extension );
     1241}
     1242
     1243Type * DeclarationNode::buildType() const {
    12981244        assert( type );
    12991245
     
    13011247        case TypeData::Enum:
    13021248        case TypeData::Aggregate: {
    1303                 ast::BaseInstType * ret =
    1304                         buildComAggInst( type, copy( attributes ), linkage );
    1305                 buildList( type->aggregate.actuals, ret->params );
     1249                ReferenceToType * ret = buildComAggInst( type, attributes, linkage );
     1250                buildList( type->aggregate.actuals, ret->get_parameters() );
    13061251                return ret;
    13071252        }
    13081253        case TypeData::Symbolic: {
    1309                 ast::TypeInstType * ret = new ast::TypeInstType(
    1310                         *type->symbolic.name,
    1311                         // This is just a default, the true value is not known yet.
    1312                         ast::TypeDecl::Dtype,
    1313                         buildQualifiers( type ),
    1314                         copy( attributes ) );
    1315                 buildList( type->symbolic.actuals, ret->params );
     1254                TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
     1255                buildList( type->symbolic.actuals, ret->get_parameters() );
    13161256                return ret;
    13171257        }
    13181258        default:
    1319                 ast::Type * simpletypes = typebuild( type );
    1320                 // copy because member is const
    1321                 simpletypes->attributes = attributes;
     1259                Type * simpletypes = typebuild( type );
     1260                simpletypes->get_attributes() = attributes;             // copy because member is const
    13221261                return simpletypes;
    13231262        } // switch
Note: See TracChangeset for help on using the changeset viewer.