Ignore:
Timestamp:
Apr 4, 2023, 10:12:57 PM (16 months ago)
Author:
Mike Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, master
Children:
9bb8ee42
Parents:
ff71057 (diff), bb7422a (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/DeclarationNode.cc

    rff71057 re02e13f  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Mar 14 11:56:00 2023
    13 // Update Count     : 1406
     12// Last Modified On : Tue Apr  4 10:28:00 2023
     13// Update Count     : 1392
    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
    2333#include "Common/SemanticError.h"  // for SemanticError
    2434#include "Common/UniqueName.h"     // for UniqueName
    25 #include "Common/utility.h"        // for maybeClone, maybeBuild, CodeLocation
     35#include "Common/utility.h"        // for maybeClone
    2636#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::...
    3337#include "TypeData.h"              // for TypeData, TypeData::Aggregate_t
    3438#include "TypedefTable.h"          // for TypedefTable
     
    6165UniqueName DeclarationNode::anonymous( "__anonymous" );
    6266
    63 extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
     67extern ast::Linkage::Spec linkage;                                              // defined in parser.yy
    6468
    6569DeclarationNode::DeclarationNode() :
     
    6771
    6872//      variable.name = nullptr;
    69         variable.tyClass = TypeDecl::NUMBER_OF_KINDS;
     73        variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS;
    7074        variable.assertions = nullptr;
    7175        variable.initializer = nullptr;
     
    105109        newnode->hasEllipsis = hasEllipsis;
    106110        newnode->linkage = linkage;
    107         newnode->asmName = maybeClone( asmName );
    108         cloneAll( attributes, newnode->attributes );
     111        newnode->asmName = maybeCopy( asmName );
     112        newnode->attributes = attributes;
    109113        newnode->initializer = maybeClone( initializer );
    110114        newnode->extension = extension;
     
    118122
    119123        newnode->assert.condition = maybeClone( assert.condition );
    120         newnode->assert.message = maybeClone( assert.message );
     124        newnode->assert.message = maybeCopy( assert.message );
    121125        return newnode;
    122126} // DeclarationNode::clone
     
    128132        } // if
    129133
    130         if ( linkage != LinkageSpec::Cforall ) {
    131                 os << LinkageSpec::name( linkage ) << " ";
    132         } // if
    133 
    134         storageClasses.print( os );
    135         funcSpecs.print( os );
     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 );
    136140
    137141        if ( type ) {
     
    154158        if ( ! attributes.empty() ) {
    155159                os << string( indent + 2, ' ' ) << "with attributes " << endl;
    156                 for ( Attribute * attr: reverseIterate( attributes ) ) {
     160                for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) {
    157161                        os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
    158162                } // for
     
    169173}
    170174
    171 DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) {
     175DeclarationNode * DeclarationNode::newStorageClass( ast::Storage::Classes sc ) {
    172176        DeclarationNode * newnode = new DeclarationNode;
    173177        newnode->storageClasses = sc;
     
    175179} // DeclarationNode::newStorageClass
    176180
    177 DeclarationNode * DeclarationNode::newFuncSpecifier( Type::FuncSpecifiers fs ) {
     181DeclarationNode * DeclarationNode::newFuncSpecifier( ast::Function::Specs fs ) {
    178182        DeclarationNode * newnode = new DeclarationNode;
    179183        newnode->funcSpecs = fs;
     
    181185} // DeclarationNode::newFuncSpecifier
    182186
    183 DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) {
     187DeclarationNode * DeclarationNode::newTypeQualifier( ast::CV::Qualifiers tq ) {
    184188        DeclarationNode * newnode = new DeclarationNode;
    185189        newnode->type = new TypeData();
     
    241245}
    242246
    243 DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     247DeclarationNode * DeclarationNode::newAggregate( ast::AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    244248        DeclarationNode * newnode = new DeclarationNode;
    245249        newnode->type = new TypeData( TypeData::Aggregate );
     
    271275} // DeclarationNode::newEnum
    272276
    273 
    274 
    275277DeclarationNode * DeclarationNode::newName( const string * name ) {
    276278        DeclarationNode * newnode = new DeclarationNode;
     
    324326} // DeclarationNode::newFromTypeGen
    325327
    326 DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) {
     328DeclarationNode * DeclarationNode::newTypeParam( ast::TypeDecl::Kind tc, const string * name ) {
    327329        DeclarationNode * newnode = newName( name );
    328330        newnode->type = nullptr;
     
    336338        newnode->type = new TypeData( TypeData::Aggregate );
    337339        newnode->type->aggregate.name = name;
    338         newnode->type->aggregate.kind = AggregateDecl::Trait;
     340        newnode->type->aggregate.kind = ast::AggregateDecl::Trait;
    339341        newnode->type->aggregate.params = params;
    340342        newnode->type->aggregate.fields = asserts;
     
    346348        newnode->type = new TypeData( TypeData::AggregateInst );
    347349        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    348         newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait;
     350        newnode->type->aggInst.aggregate->aggregate.kind = ast::AggregateDecl::Trait;
    349351        newnode->type->aggInst.aggregate->aggregate.name = name;
    350352        newnode->type->aggInst.params = params;
     
    381383        newnode->type->array.dimension = size;
    382384        newnode->type->array.isStatic = isStatic;
    383         if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
     385        if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ast::ConstantExpr *>() ) {
    384386                newnode->type->array.isVarLen = false;
    385387        } else {
     
    451453        DeclarationNode * newnode = new DeclarationNode;
    452454        newnode->type = nullptr;
    453         std::list< Expression * > exprs;
     455        std::vector<ast::ptr<ast::Expr>> exprs;
    454456        buildList( expr, exprs );
    455         newnode->attributes.push_back( new Attribute( *name, exprs ) );
     457        newnode->attributes.push_back(
     458                new ast::Attribute( *name, std::move( exprs ) ) );
    456459        delete name;
    457460        return newnode;
     
    470473}
    471474
    472 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression * message ) {
     475DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, ast::Expr * message ) {
    473476        DeclarationNode * newnode = new DeclarationNode;
    474477        newnode->assert.condition = condition;
     
    477480}
    478481
    479 
    480 void appendError( string & dst, const string & src ) {
     482static void appendError( string & dst, const string & src ) {
    481483        if ( src.empty() ) return;
    482484        if ( dst.empty() ) { dst = src; return; }
     
    485487
    486488void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
    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
     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() );
    495498        } // for
    496499} // DeclarationNode::checkQualifiers
    497500
    498501void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
    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
     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                }
    521533        } // if
    522534
     
    528540        storageClasses |= q->storageClasses;
    529541
    530         for ( Attribute * attr: reverseIterate( q->attributes ) ) {
    531                 attributes.push_front( attr->clone() );
    532         } // for
     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
    533549        return this;
    534550} // DeclarationNode::copySpecifiers
     
    716732
    717733DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
    718         if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
     734        if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {
    719735                if ( variable.assertions ) {
    720736                        variable.assertions->appendList( assertions );
     
    798814DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
    799815        if ( a ) {
    800                 for ( Attribute *attr: reverseIterate( a->attributes ) ) {
    801                         attributes.push_front( attr );
    802                 } // for
     816                spliceBegin( attributes, a->attributes );
    803817                a->attributes.clear();
    804818        } // if
     
    921935
    922936DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) {
    923         assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
     937        assertf( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );
    924938        variable.initializer = init;
    925939        return this;
     
    985999}
    9861000
    987 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) {
     1001void buildList( const DeclarationNode * firstNode,
     1002                std::vector<ast::ptr<ast::Decl>> & outputList ) {
    9881003        SemanticErrorException errors;
    989         std::back_insert_iterator< std::list< Declaration * > > out( outputList );
     1004        std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList );
    9901005
    9911006        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    9921007                try {
    9931008                        bool extracted = false, anon = false;
    994                         AggregateDecl * unionDecl = nullptr;
     1009                        ast::AggregateDecl * unionDecl = nullptr;
    9951010
    9961011                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
     
    10291044                                } // if
    10301045
    1031                                 Declaration * decl = extr->build();
     1046                                ast::Decl * decl = extr->build();
    10321047                                if ( decl ) {
    10331048                                        // Remember the declaration if it is a union aggregate ?
    1034                                         unionDecl = dynamic_cast<UnionDecl *>( decl );
     1049                                        unionDecl = dynamic_cast<ast::UnionDecl *>( decl );
    10351050
    10361051                                        decl->location = cur->location;
     
    10511066                        } // if
    10521067
    1053                         Declaration * decl = cur->build();
     1068                        ast::Decl * decl = cur->build();
    10541069                        if ( decl ) {
    1055                                 if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) {
     1070                                if ( auto typedefDecl = dynamic_cast<ast::TypedefDecl *>( decl ) ) {
    10561071                                        if ( unionDecl ) {                                      // is the typedef alias a union aggregate ?
    10571072                                                // This code handles a special issue with the attribute transparent_union.
     
    10651080
    10661081                                                // If typedef is an alias for a union, then its alias type was hoisted above and remembered.
    1067                                                 if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) {
     1082                                                if ( auto unionInstType = typedefDecl->base.as<ast::UnionInstType>() ) {
     1083                                                        auto instType = ast::mutate( unionInstType );
    10681084                                                        // Remove all transparent_union attributes from typedef and move to alias union.
    1069                                                         list<Attribute *>::iterator attr;
    1070                                                         for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order
     1085                                                        for ( auto attr = instType->attributes.begin() ; attr != instType->attributes.end() ; ) { // forward order
     1086                                                                assert( *attr );
    10711087                                                                if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
    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
     1088                                                                        unionDecl->attributes.emplace_back( attr->release() );
     1089                                                                        attr = instType->attributes.erase( attr );
    10761090                                                                } else {
    1077                                                                         attr++;                         // advance iterator
     1091                                                                        attr++;
    10781092                                                                } // if
    10791093                                                        } // for
     1094                                                        typedefDecl->base = instType;
    10801095                                                } // if
    10811096                                        } // if
     
    10901105                                if ( ! (extracted && decl->name == "" && ! anon && ! cur->get_inLine()) ) {
    10911106                                        if ( decl->name == "" ) {
    1092                                                 if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>( decl ) ) {
    1093                                                         if ( ReferenceToType * aggr = dynamic_cast<ReferenceToType *>( dwt->get_type() ) ) {
     1107                                                if ( auto dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
     1108                                                        if ( auto aggr = dynamic_cast<ast::BaseInstType const *>( dwt->get_type() ) ) {
    10941109                                                                if ( aggr->name.find("anonymous") == std::string::npos ) {
    10951110                                                                        if ( ! cur->get_inLine() ) {
     
    11171132
    11181133// currently only builds assertions, function parameters, and return values
    1119 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ) {
     1134void buildList( const DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ) {
    11201135        SemanticErrorException errors;
    1121         std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
     1136        std::back_insert_iterator<std::vector<ast::ptr<ast::DeclWithType>>> out( outputList );
    11221137
    11231138        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    11241139                try {
    1125                         Declaration * decl = cur->build();
     1140                        ast::Decl * decl = cur->build();
    11261141                        assert( decl );
    1127                         if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     1142                        if ( ast::DeclWithType * dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {
    11281143                                dwt->location = cur->location;
    11291144                                *out++ = dwt;
    1130                         } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     1145                        } else if ( ast::StructDecl * agg = dynamic_cast<ast::StructDecl *>( decl ) ) {
    11311146                                // e.g., int foo(struct S) {}
    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;
     1147                                auto inst = new ast::StructInstType( agg->name );
     1148                                auto obj = new ast::ObjectDecl( cur->location, "", inst );
     1149                                obj->linkage = linkage;
    11351150                                *out++ = obj;
    11361151                                delete agg;
    1137                         } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     1152                        } else if ( ast::UnionDecl * agg = dynamic_cast<ast::UnionDecl *>( decl ) ) {
    11381153                                // e.g., int foo(union U) {}
    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;
     1154                                auto inst = new ast::UnionInstType( agg->name );
     1155                                auto obj = new ast::ObjectDecl( cur->location,
     1156                                        "", inst, nullptr, ast::Storage::Classes(),
     1157                                        linkage );
    11421158                                *out++ = obj;
    1143                         } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) {
     1159                        } else if ( ast::EnumDecl * agg = dynamic_cast<ast::EnumDecl *>( decl ) ) {
    11441160                                // e.g., int foo(enum E) {}
    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;
     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                                );
    11481169                                *out++ = obj;
    11491170                        } // if
     
    11581179} // buildList
    11591180
    1160 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) {
     1181void buildTypeList( const DeclarationNode * firstNode,
     1182                std::vector<ast::ptr<ast::Type>> & outputList ) {
    11611183        SemanticErrorException errors;
    1162         std::back_insert_iterator< std::list< Type * > > out( outputList );
     1184        std::back_insert_iterator<std::vector<ast::ptr<ast::Type>>> out( outputList );
    11631185        const DeclarationNode * cur = firstNode;
    11641186
     
    11771199} // buildTypeList
    11781200
    1179 Declaration * DeclarationNode::build() const {
     1201ast::Decl * DeclarationNode::build() const {
    11801202        if ( ! error.empty() ) SemanticError( this, error + " in declaration of " );
    11811203
    11821204        if ( asmStmt ) {
    1183                 return new AsmDecl( strict_dynamic_cast<AsmStmt *>( asmStmt->build() ) );
     1205                auto stmt = strict_dynamic_cast<ast::AsmStmt *>( asmStmt->build() );
     1206                return new ast::AsmDecl( stmt->location, stmt );
    11841207        } // if
    11851208        if ( directiveStmt ) {
    1186                 return new DirectiveDecl( strict_dynamic_cast<DirectiveStmt *>( directiveStmt->build() ) );
    1187         } // if
    1188 
    1189         if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
     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 ) {
    11901214                // otype is internally converted to dtype + otype parameters
    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." );
     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." );
    11931217                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    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() );
     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 );
    11961227                return ret;
    11971228        } // if
     
    12151246                } // if
    12161247                bool isDelete = initializer && initializer->get_isDelete();
    1217                 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild(initializer), attributes )->set_extension( extension );
     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 );
    12181259                if ( isDelete ) {
    1219                         DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );
     1260                        auto dwt = strict_dynamic_cast<ast::DeclWithType *>( decl );
    12201261                        dwt->isDeleted = true;
    12211262                }
     
    12241265
    12251266        if ( assert.condition ) {
    1226                 return new StaticAssertDecl( maybeBuild( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );
     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 );
    12271270        }
    12281271
     
    12351278        } // if
    12361279        if ( enumInLine ) {
    1237                 return new InlineMemberDecl( *name, storageClasses, linkage, nullptr );
     1280                return new ast::InlineMemberDecl( location,
     1281                        *name, (ast::Type*)nullptr, storageClasses, linkage );
    12381282        } // if
    12391283        assertf( name, "ObjectDecl must a have name\n" );
    1240         return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild( bitfieldWidth ), nullptr, maybeBuild( initializer ) ))->set_asmName( asmName )->set_extension( extension );
    1241 }
    1242 
    1243 Type * DeclarationNode::buildType() const {
     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
     1297ast::Type * DeclarationNode::buildType() const {
    12441298        assert( type );
    12451299
     
    12471301        case TypeData::Enum:
    12481302        case TypeData::Aggregate: {
    1249                 ReferenceToType * ret = buildComAggInst( type, attributes, linkage );
    1250                 buildList( type->aggregate.actuals, ret->get_parameters() );
     1303                ast::BaseInstType * ret =
     1304                        buildComAggInst( type, copy( attributes ), linkage );
     1305                buildList( type->aggregate.actuals, ret->params );
    12511306                return ret;
    12521307        }
    12531308        case TypeData::Symbolic: {
    1254                 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
    1255                 buildList( type->symbolic.actuals, ret->get_parameters() );
     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 );
    12561316                return ret;
    12571317        }
    12581318        default:
    1259                 Type * simpletypes = typebuild( type );
    1260                 simpletypes->get_attributes() = attributes;             // copy because member is const
     1319                ast::Type * simpletypes = typebuild( type );
     1320                // copy because member is const
     1321                simpletypes->attributes = attributes;
    12611322                return simpletypes;
    12621323        } // switch
Note: See TracChangeset for help on using the changeset viewer.