[b87a5ed] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
[974906e2] | 7 | // DeclarationNode.cc --
|
---|
[b87a5ed] | 8 | //
|
---|
| 9 | // Author : Rodolfo G. Esteves
|
---|
| 10 | // Created On : Sat May 16 12:34:05 2015
|
---|
[8e9cbb2] | 11 | // Last Modified By : Peter A. Buhr
|
---|
[a7c90d4] | 12 | // Last Modified On : Tue Mar 7 08:02:09 2017
|
---|
| 13 | // Update Count : 936
|
---|
[b87a5ed] | 14 | //
|
---|
| 15 |
|
---|
[51b73452] | 16 | #include <string>
|
---|
| 17 | #include <list>
|
---|
| 18 | #include <iterator>
|
---|
| 19 | #include <algorithm>
|
---|
| 20 | #include <cassert>
|
---|
[a7c90d4] | 21 | #include <strings.h> // ffs
|
---|
[51b73452] | 22 |
|
---|
| 23 | #include "TypeData.h"
|
---|
[bdd516a] | 24 |
|
---|
[44a81853] | 25 | #include "SynTree/Attribute.h"
|
---|
[68cd1ce] | 26 | #include "SynTree/Declaration.h"
|
---|
| 27 | #include "SynTree/Expression.h"
|
---|
[51b73452] | 28 |
|
---|
[de62360d] | 29 | #include "TypedefTable.h"
|
---|
| 30 | extern TypedefTable typedefTable;
|
---|
| 31 |
|
---|
[51b73452] | 32 | using namespace std;
|
---|
| 33 |
|
---|
[bdd516a] | 34 | // These must remain in the same order as the corresponding DeclarationNode enumerations.
|
---|
[a7c90d4] | 35 | const char * DeclarationNode::storageClassNames[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };
|
---|
[dd020c0] | 36 | const char * DeclarationNode::funcSpecifierNames[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };
|
---|
[a7c90d4] | 37 | const char * DeclarationNode::typeQualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };
|
---|
[dd020c0] | 38 | const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" };
|
---|
| 39 | const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" };
|
---|
| 40 | const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
|
---|
| 41 | const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" };
|
---|
| 42 | const char * DeclarationNode::aggregateNames[] = { "struct", "union", "context", "NoAggregateNames" };
|
---|
| 43 | const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };
|
---|
| 44 | const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "NoBuiltinTypeNames" };
|
---|
[51b73452] | 45 |
|
---|
| 46 | UniqueName DeclarationNode::anonymous( "__anonymous" );
|
---|
| 47 |
|
---|
[8b7ee09] | 48 | extern LinkageSpec::Spec linkage; // defined in parser.yy
|
---|
[51b73452] | 49 |
|
---|
[7d05e7e] | 50 | DeclarationNode::DeclarationNode() :
|
---|
[2298f728] | 51 | type( nullptr ),
|
---|
[58dd019] | 52 | bitfieldWidth( nullptr ),
|
---|
[7d05e7e] | 53 | hasEllipsis( false ),
|
---|
| 54 | linkage( ::linkage ),
|
---|
[58dd019] | 55 | asmName( nullptr ),
|
---|
| 56 | initializer( nullptr ),
|
---|
[e994912] | 57 | extension( false ),
|
---|
| 58 | asmStmt( nullptr ) {
|
---|
[2298f728] | 59 |
|
---|
[faddbd8] | 60 | // variable.name = nullptr;
|
---|
| 61 | variable.tyClass = NoTypeClass;
|
---|
[28307be] | 62 | variable.assertions = nullptr;
|
---|
[7d05e7e] | 63 |
|
---|
[faddbd8] | 64 | // attr.name = nullptr;
|
---|
[7d05e7e] | 65 | attr.expr = nullptr;
|
---|
| 66 | attr.type = nullptr;
|
---|
[28307be] | 67 | }
|
---|
| 68 |
|
---|
| 69 | DeclarationNode::~DeclarationNode() {
|
---|
[faddbd8] | 70 | // delete attr.name;
|
---|
[28307be] | 71 | delete attr.expr;
|
---|
| 72 | delete attr.type;
|
---|
[2298f728] | 73 |
|
---|
[faddbd8] | 74 | // delete variable.name;
|
---|
[2298f728] | 75 | delete variable.assertions;
|
---|
| 76 |
|
---|
[28307be] | 77 | delete type;
|
---|
| 78 | delete bitfieldWidth;
|
---|
[e994912] | 79 |
|
---|
| 80 | delete asmStmt;
|
---|
[58dd019] | 81 | // asmName, no delete, passed to next stage
|
---|
[28307be] | 82 | delete initializer;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[ba7aa2d] | 85 | DeclarationNode * DeclarationNode::clone() const {
|
---|
| 86 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[c0aa336] | 87 | newnode->set_next( maybeClone( get_next() ) );
|
---|
[2298f728] | 88 | newnode->name = name ? new string( *name ) : nullptr;
|
---|
[c0aa336] | 89 |
|
---|
| 90 | newnode->type = maybeClone( type );
|
---|
[a7c90d4] | 91 | newnode->storageClasses = storageClasses;
|
---|
[c0aa336] | 92 | newnode->bitfieldWidth = maybeClone( bitfieldWidth );
|
---|
[a7c90d4] | 93 | newnode->funcSpecs = funcSpecs;
|
---|
[c0aa336] | 94 | newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) );
|
---|
[b87a5ed] | 95 | newnode->hasEllipsis = hasEllipsis;
|
---|
| 96 | newnode->linkage = linkage;
|
---|
[58dd019] | 97 | newnode->asmName = maybeClone( asmName );
|
---|
[c0aa336] | 98 | cloneAll( attributes, newnode->attributes );
|
---|
| 99 | newnode->initializer = maybeClone( initializer );
|
---|
| 100 | newnode->extension = extension;
|
---|
[e994912] | 101 | newnode->asmStmt = maybeClone( asmStmt );
|
---|
[c0aa336] | 102 | newnode->error = error;
|
---|
[3848e0e] | 103 |
|
---|
[faddbd8] | 104 | // newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
|
---|
[28307be] | 105 | newnode->variable.tyClass = variable.tyClass;
|
---|
[fb114fa1] | 106 | newnode->variable.assertions = maybeClone( variable.assertions );
|
---|
[3848e0e] | 107 |
|
---|
[faddbd8] | 108 | // newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
|
---|
[28307be] | 109 | newnode->attr.expr = maybeClone( attr.expr );
|
---|
| 110 | newnode->attr.type = maybeClone( attr.type );
|
---|
| 111 | return newnode;
|
---|
| 112 | } // DeclarationNode::clone
|
---|
[3848e0e] | 113 |
|
---|
| 114 | bool DeclarationNode::get_hasEllipsis() const {
|
---|
[b87a5ed] | 115 | return hasEllipsis;
|
---|
[3848e0e] | 116 | }
|
---|
| 117 |
|
---|
[a7c90d4] | 118 | void DeclarationNode::print_StorageClass( std::ostream & output, StorageClasses storageClasses ) {
|
---|
| 119 | if ( storageClasses.any() ) { // function specifiers?
|
---|
| 120 | for ( unsigned int i = 0; i < DeclarationNode::NoStorageClass; i += 1 ) {
|
---|
| 121 | if ( storageClasses[i] ) {
|
---|
| 122 | output << DeclarationNode::storageClassNames[i] << ' ';
|
---|
| 123 | } // if
|
---|
| 124 | } // for
|
---|
| 125 | } // if
|
---|
| 126 | } // print_StorageClass
|
---|
| 127 |
|
---|
| 128 | void DeclarationNode::print_FuncSpec( std::ostream & output, DeclarationNode::FuncSpecifiers funcSpec ) {
|
---|
[dd020c0] | 129 | if ( funcSpec.any() ) { // function specifiers?
|
---|
| 130 | for ( unsigned int i = 0; i < DeclarationNode::NoFuncSpecifier; i += 1 ) {
|
---|
| 131 | if ( funcSpec[i] ) {
|
---|
| 132 | output << DeclarationNode::funcSpecifierNames[i] << ' ';
|
---|
| 133 | } // if
|
---|
| 134 | } // for
|
---|
| 135 | } // if
|
---|
| 136 | } // print_FuncSpec
|
---|
| 137 |
|
---|
[3848e0e] | 138 | void DeclarationNode::print( std::ostream &os, int indent ) const {
|
---|
[59db689] | 139 | os << string( indent, ' ' );
|
---|
[2298f728] | 140 | if ( name ) {
|
---|
| 141 | os << *name << ": ";
|
---|
[b87a5ed] | 142 | } else {
|
---|
[2298f728] | 143 | os << "unnamed: ";
|
---|
[68cd1ce] | 144 | } // if
|
---|
[51b73452] | 145 |
|
---|
[b87a5ed] | 146 | if ( linkage != LinkageSpec::Cforall ) {
|
---|
[faddbd8] | 147 | os << LinkageSpec::linkageName( linkage ) << " ";
|
---|
[68cd1ce] | 148 | } // if
|
---|
[3848e0e] | 149 |
|
---|
[a7c90d4] | 150 | print_StorageClass( os, storageClasses );
|
---|
| 151 | print_FuncSpec( os, funcSpecs );
|
---|
[dd020c0] | 152 |
|
---|
[b87a5ed] | 153 | if ( type ) {
|
---|
| 154 | type->print( os, indent );
|
---|
| 155 | } else {
|
---|
| 156 | os << "untyped entity ";
|
---|
[68cd1ce] | 157 | } // if
|
---|
[3848e0e] | 158 |
|
---|
[b87a5ed] | 159 | if ( bitfieldWidth ) {
|
---|
[59db689] | 160 | os << endl << string( indent + 2, ' ' ) << "with bitfield width ";
|
---|
[b87a5ed] | 161 | bitfieldWidth->printOneLine( os );
|
---|
[68cd1ce] | 162 | } // if
|
---|
[3848e0e] | 163 |
|
---|
[2298f728] | 164 | if ( initializer ) {
|
---|
[59db689] | 165 | os << endl << string( indent + 2, ' ' ) << "with initializer ";
|
---|
[b87a5ed] | 166 | initializer->printOneLine( os );
|
---|
[974906e2] | 167 | os << " maybe constructed? " << initializer->get_maybeConstructed();
|
---|
| 168 |
|
---|
[68cd1ce] | 169 | } // if
|
---|
[3848e0e] | 170 |
|
---|
[b87a5ed] | 171 | os << endl;
|
---|
[51b73452] | 172 | }
|
---|
| 173 |
|
---|
[3848e0e] | 174 | void DeclarationNode::printList( std::ostream &os, int indent ) const {
|
---|
[b87a5ed] | 175 | ParseNode::printList( os, indent );
|
---|
| 176 | if ( hasEllipsis ) {
|
---|
| 177 | os << string( indent, ' ' ) << "and a variable number of other arguments" << endl;
|
---|
[68cd1ce] | 178 | } // if
|
---|
[51b73452] | 179 | }
|
---|
| 180 |
|
---|
[fb114fa1] | 181 | DeclarationNode * DeclarationNode::newFunction( string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
|
---|
[ba7aa2d] | 182 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[2298f728] | 183 | newnode->name = name;
|
---|
[b87a5ed] | 184 | newnode->type = new TypeData( TypeData::Function );
|
---|
[8f6f47d7] | 185 | newnode->type->function.params = param;
|
---|
| 186 | newnode->type->function.newStyle = newStyle;
|
---|
| 187 | newnode->type->function.body = body;
|
---|
[c0aa336] | 188 |
|
---|
[2298f728] | 189 | // ignore unnamed routine declarations: void p( int (*)(int) );
|
---|
| 190 | if ( newnode->name ) {
|
---|
| 191 | typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
|
---|
| 192 | } // if
|
---|
[3848e0e] | 193 |
|
---|
[b87a5ed] | 194 | if ( ret ) {
|
---|
| 195 | newnode->type->base = ret->type;
|
---|
[2298f728] | 196 | ret->type = nullptr;
|
---|
[b87a5ed] | 197 | delete ret;
|
---|
[68cd1ce] | 198 | } // if
|
---|
[51b73452] | 199 |
|
---|
[b87a5ed] | 200 | return newnode;
|
---|
[984dce6] | 201 | } // DeclarationNode::newFunction
|
---|
[3848e0e] | 202 |
|
---|
[dd020c0] | 203 |
|
---|
| 204 | DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
|
---|
[ba7aa2d] | 205 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[a7c90d4] | 206 | newnode->storageClasses[ sc ] = true;
|
---|
[b87a5ed] | 207 | return newnode;
|
---|
[dd020c0] | 208 | } // DeclarationNode::newStorageClass
|
---|
[3848e0e] | 209 |
|
---|
[dd020c0] | 210 | DeclarationNode * DeclarationNode::newFuncSpecifier( DeclarationNode::FuncSpecifier fs ) {
|
---|
[ba7aa2d] | 211 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[a7c90d4] | 212 | newnode->funcSpecs[ fs ] = true;
|
---|
[c1c1112] | 213 | return newnode;
|
---|
[dd020c0] | 214 | } // DeclarationNode::newFuncSpecifier
|
---|
[c1c1112] | 215 |
|
---|
[dd020c0] | 216 | DeclarationNode * DeclarationNode::newTypeQualifier( TypeQualifier tq ) {
|
---|
[ba7aa2d] | 217 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[dd020c0] | 218 | newnode->type = new TypeData();
|
---|
| 219 | newnode->type->typeQualifiers[ tq ] = true;
|
---|
[b87a5ed] | 220 | return newnode;
|
---|
[dd020c0] | 221 | } // DeclarationNode::newQualifier
|
---|
[3848e0e] | 222 |
|
---|
[c1c1112] | 223 | DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
|
---|
[ba7aa2d] | 224 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 225 | newnode->type = new TypeData( TypeData::Basic );
|
---|
[5b639ee] | 226 | newnode->type->basictype = bt;
|
---|
[b87a5ed] | 227 | return newnode;
|
---|
[984dce6] | 228 | } // DeclarationNode::newBasicType
|
---|
[3848e0e] | 229 |
|
---|
[5b639ee] | 230 | DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
|
---|
[ba7aa2d] | 231 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 232 | newnode->type = new TypeData( TypeData::Basic );
|
---|
[5b639ee] | 233 | newnode->type->complextype = ct;
|
---|
[b87a5ed] | 234 | return newnode;
|
---|
[5b639ee] | 235 | } // DeclarationNode::newComplexType
|
---|
| 236 |
|
---|
| 237 | DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
|
---|
[ba7aa2d] | 238 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[5b639ee] | 239 | newnode->type = new TypeData( TypeData::Basic );
|
---|
| 240 | newnode->type->signedness = sn;
|
---|
| 241 | return newnode;
|
---|
| 242 | } // DeclarationNode::newSignedNess
|
---|
| 243 |
|
---|
| 244 | DeclarationNode * DeclarationNode::newLength( Length lnth ) {
|
---|
[ba7aa2d] | 245 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[5b639ee] | 246 | newnode->type = new TypeData( TypeData::Basic );
|
---|
| 247 | newnode->type->length = lnth;
|
---|
| 248 | return newnode;
|
---|
| 249 | } // DeclarationNode::newLength
|
---|
[3848e0e] | 250 |
|
---|
[dd020c0] | 251 | DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {
|
---|
| 252 | DeclarationNode * newnode = new DeclarationNode;
|
---|
| 253 | newnode->type = new TypeData( TypeData::Unknown );
|
---|
| 254 | newnode->type->forall = forall;
|
---|
| 255 | return newnode;
|
---|
| 256 | } // DeclarationNode::newForall
|
---|
| 257 |
|
---|
[fb114fa1] | 258 | DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
|
---|
[ba7aa2d] | 259 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 260 | newnode->type = new TypeData( TypeData::SymbolicInst );
|
---|
[fb114fa1] | 261 | newnode->type->symbolic.name = name;
|
---|
[8f6f47d7] | 262 | newnode->type->symbolic.isTypedef = true;
|
---|
[2298f728] | 263 | newnode->type->symbolic.params = nullptr;
|
---|
[b87a5ed] | 264 | return newnode;
|
---|
[984dce6] | 265 | } // DeclarationNode::newFromTypedef
|
---|
[3848e0e] | 266 |
|
---|
[fb114fa1] | 267 | DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
|
---|
[ba7aa2d] | 268 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 269 | newnode->type = new TypeData( TypeData::Aggregate );
|
---|
[8f6f47d7] | 270 | newnode->type->aggregate.kind = kind;
|
---|
[2298f728] | 271 | if ( name ) {
|
---|
[fb114fa1] | 272 | newnode->type->aggregate.name = name;
|
---|
[2298f728] | 273 | } else { // anonymous aggregate ?
|
---|
| 274 | newnode->type->aggregate.name = new string( anonymous.newName() );
|
---|
[8f6f47d7] | 275 | } // if
|
---|
| 276 | newnode->type->aggregate.actuals = actuals;
|
---|
| 277 | newnode->type->aggregate.fields = fields;
|
---|
| 278 | newnode->type->aggregate.body = body;
|
---|
[b87a5ed] | 279 | return newnode;
|
---|
[984dce6] | 280 | } // DeclarationNode::newAggregate
|
---|
[3848e0e] | 281 |
|
---|
[ca1a547] | 282 | DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants, bool body ) {
|
---|
[ba7aa2d] | 283 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 284 | newnode->type = new TypeData( TypeData::Enum );
|
---|
[2298f728] | 285 | if ( name ) {
|
---|
[fb114fa1] | 286 | newnode->type->enumeration.name = name;
|
---|
[2298f728] | 287 | } else { // anonymous aggregate ?
|
---|
| 288 | newnode->type->enumeration.name = new string( anonymous.newName() );
|
---|
[68cd1ce] | 289 | } // if
|
---|
[8f6f47d7] | 290 | newnode->type->enumeration.constants = constants;
|
---|
[ca1a547] | 291 | newnode->type->enumeration.body = body;
|
---|
[b87a5ed] | 292 | return newnode;
|
---|
[984dce6] | 293 | } // DeclarationNode::newEnum
|
---|
[3848e0e] | 294 |
|
---|
[fb114fa1] | 295 | DeclarationNode * DeclarationNode::newEnumConstant( string * name, ExpressionNode * constant ) {
|
---|
[ba7aa2d] | 296 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[2298f728] | 297 | newnode->name = name;
|
---|
[4f147cc] | 298 | newnode->enumeratorValue.reset( constant );
|
---|
[2298f728] | 299 | typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
|
---|
[b87a5ed] | 300 | return newnode;
|
---|
[984dce6] | 301 | } // DeclarationNode::newEnumConstant
|
---|
[3848e0e] | 302 |
|
---|
[fb114fa1] | 303 | DeclarationNode * DeclarationNode::newName( string * name ) {
|
---|
[ba7aa2d] | 304 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[2298f728] | 305 | newnode->name = name;
|
---|
[b87a5ed] | 306 | return newnode;
|
---|
[984dce6] | 307 | } // DeclarationNode::newName
|
---|
[3848e0e] | 308 |
|
---|
[fb114fa1] | 309 | DeclarationNode * DeclarationNode::newFromTypeGen( string * name, ExpressionNode * params ) {
|
---|
[ba7aa2d] | 310 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 311 | newnode->type = new TypeData( TypeData::SymbolicInst );
|
---|
[fb114fa1] | 312 | newnode->type->symbolic.name = name;
|
---|
[8f6f47d7] | 313 | newnode->type->symbolic.isTypedef = false;
|
---|
| 314 | newnode->type->symbolic.actuals = params;
|
---|
[b87a5ed] | 315 | return newnode;
|
---|
[984dce6] | 316 | } // DeclarationNode::newFromTypeGen
|
---|
[3848e0e] | 317 |
|
---|
[fb114fa1] | 318 | DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, string * name ) {
|
---|
[ba7aa2d] | 319 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[2298f728] | 320 | newnode->type = nullptr;
|
---|
[148f7290] | 321 | assert( ! newnode->name );
|
---|
[faddbd8] | 322 | // newnode->variable.name = name;
|
---|
| 323 | newnode->name = name;
|
---|
[28307be] | 324 | newnode->variable.tyClass = tc;
|
---|
[faddbd8] | 325 | newnode->variable.assertions = nullptr;
|
---|
[b87a5ed] | 326 | return newnode;
|
---|
[984dce6] | 327 | } // DeclarationNode::newTypeParam
|
---|
[3848e0e] | 328 |
|
---|
[fb114fa1] | 329 | DeclarationNode * DeclarationNode::newTrait( const string * name, DeclarationNode * params, DeclarationNode * asserts ) {
|
---|
[ba7aa2d] | 330 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 331 | newnode->type = new TypeData( TypeData::Aggregate );
|
---|
[2298f728] | 332 | newnode->type->aggregate.name = name;
|
---|
[8f6f47d7] | 333 | newnode->type->aggregate.kind = Trait;
|
---|
| 334 | newnode->type->aggregate.params = params;
|
---|
| 335 | newnode->type->aggregate.fields = asserts;
|
---|
[b87a5ed] | 336 | return newnode;
|
---|
[984dce6] | 337 | } // DeclarationNode::newTrait
|
---|
[3848e0e] | 338 |
|
---|
[fb114fa1] | 339 | DeclarationNode * DeclarationNode::newTraitUse( const string * name, ExpressionNode * params ) {
|
---|
[ba7aa2d] | 340 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 341 | newnode->type = new TypeData( TypeData::AggregateInst );
|
---|
[8f6f47d7] | 342 | newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
|
---|
| 343 | newnode->type->aggInst.aggregate->aggregate.kind = Trait;
|
---|
[2298f728] | 344 | newnode->type->aggInst.aggregate->aggregate.name = name;
|
---|
[8f6f47d7] | 345 | newnode->type->aggInst.params = params;
|
---|
[b87a5ed] | 346 | return newnode;
|
---|
[984dce6] | 347 | } // DeclarationNode::newTraitUse
|
---|
[3848e0e] | 348 |
|
---|
[fb114fa1] | 349 | DeclarationNode * DeclarationNode::newTypeDecl( string * name, DeclarationNode * typeParams ) {
|
---|
[ba7aa2d] | 350 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 351 | newnode->type = new TypeData( TypeData::Symbolic );
|
---|
[8f6f47d7] | 352 | newnode->type->symbolic.isTypedef = false;
|
---|
| 353 | newnode->type->symbolic.params = typeParams;
|
---|
[fb114fa1] | 354 | newnode->type->symbolic.name = name;
|
---|
[b87a5ed] | 355 | return newnode;
|
---|
[984dce6] | 356 | } // DeclarationNode::newTypeDecl
|
---|
[3848e0e] | 357 |
|
---|
[ba7aa2d] | 358 | DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers ) {
|
---|
| 359 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 360 | newnode->type = new TypeData( TypeData::Pointer );
|
---|
| 361 | return newnode->addQualifiers( qualifiers );
|
---|
[984dce6] | 362 | } // DeclarationNode::newPointer
|
---|
[3848e0e] | 363 |
|
---|
[ba7aa2d] | 364 | DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) {
|
---|
| 365 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 366 | newnode->type = new TypeData( TypeData::Array );
|
---|
[8f6f47d7] | 367 | newnode->type->array.dimension = size;
|
---|
| 368 | newnode->type->array.isStatic = isStatic;
|
---|
[2298f728] | 369 | if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
|
---|
[8f6f47d7] | 370 | newnode->type->array.isVarLen = false;
|
---|
[71bd8c6] | 371 | } else {
|
---|
[8f6f47d7] | 372 | newnode->type->array.isVarLen = true;
|
---|
[71bd8c6] | 373 | } // if
|
---|
[b87a5ed] | 374 | return newnode->addQualifiers( qualifiers );
|
---|
[984dce6] | 375 | } // DeclarationNode::newArray
|
---|
[3848e0e] | 376 |
|
---|
[ba7aa2d] | 377 | DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) {
|
---|
| 378 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 379 | newnode->type = new TypeData( TypeData::Array );
|
---|
[2298f728] | 380 | newnode->type->array.dimension = nullptr;
|
---|
[8f6f47d7] | 381 | newnode->type->array.isStatic = false;
|
---|
| 382 | newnode->type->array.isVarLen = true;
|
---|
[b87a5ed] | 383 | return newnode->addQualifiers( qualifiers );
|
---|
[3848e0e] | 384 | }
|
---|
| 385 |
|
---|
[ba7aa2d] | 386 | DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) {
|
---|
| 387 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 388 | newnode->bitfieldWidth = size;
|
---|
| 389 | return newnode;
|
---|
[3848e0e] | 390 | }
|
---|
| 391 |
|
---|
[ba7aa2d] | 392 | DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) {
|
---|
| 393 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 394 | newnode->type = new TypeData( TypeData::Tuple );
|
---|
[8f6f47d7] | 395 | newnode->type->tuple = members;
|
---|
[b87a5ed] | 396 | return newnode;
|
---|
[3848e0e] | 397 | }
|
---|
| 398 |
|
---|
[ba7aa2d] | 399 | DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr ) {
|
---|
| 400 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 401 | newnode->type = new TypeData( TypeData::Typeof );
|
---|
[8f6f47d7] | 402 | newnode->type->typeexpr = expr;
|
---|
[b87a5ed] | 403 | return newnode;
|
---|
[3848e0e] | 404 | }
|
---|
| 405 |
|
---|
[8f6f47d7] | 406 | DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
|
---|
[ba7aa2d] | 407 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[8f6f47d7] | 408 | newnode->type = new TypeData( TypeData::Builtin );
|
---|
| 409 | newnode->builtin = bt;
|
---|
[148f7290] | 410 | newnode->type->builtintype = newnode->builtin;
|
---|
[8f6f47d7] | 411 | return newnode;
|
---|
| 412 | } // DeclarationNode::newBuiltinType
|
---|
| 413 |
|
---|
[fb114fa1] | 414 | DeclarationNode * DeclarationNode::newAttr( string * name, ExpressionNode * expr ) {
|
---|
[ba7aa2d] | 415 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[2298f728] | 416 | newnode->type = nullptr;
|
---|
[faddbd8] | 417 | // newnode->attr.name = name;
|
---|
| 418 | newnode->name = name;
|
---|
[28307be] | 419 | newnode->attr.expr = expr;
|
---|
[b87a5ed] | 420 | return newnode;
|
---|
[3848e0e] | 421 | }
|
---|
| 422 |
|
---|
[fb114fa1] | 423 | DeclarationNode * DeclarationNode::newAttr( string * name, DeclarationNode * type ) {
|
---|
[ba7aa2d] | 424 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[2298f728] | 425 | newnode->type = nullptr;
|
---|
[faddbd8] | 426 | // newnode->attr.name = name;
|
---|
| 427 | newnode->name = name;
|
---|
[28307be] | 428 | newnode->attr.type = type;
|
---|
[b87a5ed] | 429 | return newnode;
|
---|
[3848e0e] | 430 | }
|
---|
| 431 |
|
---|
[44a81853] | 432 | DeclarationNode * DeclarationNode::newAttribute( string * name, ExpressionNode * expr ) {
|
---|
| 433 | DeclarationNode * newnode = new DeclarationNode;
|
---|
| 434 | newnode->type = nullptr;
|
---|
| 435 | std::list< Expression * > exprs;
|
---|
| 436 | buildList( expr, exprs );
|
---|
| 437 | newnode->attributes.push_back( new Attribute( *name, exprs ) );
|
---|
| 438 | delete name;
|
---|
| 439 | return newnode;
|
---|
| 440 | }
|
---|
| 441 |
|
---|
[e994912] | 442 | DeclarationNode * DeclarationNode::newAsmStmt( StatementNode * stmt ) {
|
---|
| 443 | DeclarationNode * newnode = new DeclarationNode;
|
---|
| 444 | newnode->asmStmt = stmt;
|
---|
| 445 | return newnode;
|
---|
| 446 | }
|
---|
| 447 |
|
---|
[5b639ee] | 448 | void appendError( string & dst, const string & src ) {
|
---|
| 449 | if ( src.empty() ) return;
|
---|
| 450 | if ( dst.empty() ) { dst = src; return; }
|
---|
| 451 | dst += ", " + src;
|
---|
| 452 | } // appendError
|
---|
| 453 |
|
---|
[ba7aa2d] | 454 | void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
|
---|
[a7c90d4] | 455 | const TypeData::TypeQualifiers qsrc = src->typeQualifiers, qdst = dst->typeQualifiers; // optimization
|
---|
[c1c1112] | 456 |
|
---|
[a7c90d4] | 457 | if ( (qsrc & qdst).any() ) { // common qualifier ?
|
---|
[dd020c0] | 458 | for ( unsigned int i = 0; i < NoTypeQualifier; i += 1 ) { // find common qualifiers
|
---|
[5b639ee] | 459 | if ( qsrc[i] && qdst[i] ) {
|
---|
[dd020c0] | 460 | appendError( error, string( "duplicate " ) + DeclarationNode::typeQualifierNames[i] );
|
---|
[c1c1112] | 461 | } // if
|
---|
| 462 | } // for
|
---|
[a7c90d4] | 463 | } // for
|
---|
[c1c1112] | 464 | } // DeclarationNode::checkQualifiers
|
---|
| 465 |
|
---|
[a7c90d4] | 466 | void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
|
---|
| 467 | if ( (funcSpecs & src->funcSpecs).any() ) { // common specifier ?
|
---|
[dd020c0] | 468 | for ( unsigned int i = 0; i < NoFuncSpecifier; i += 1 ) { // find common specifier
|
---|
[a7c90d4] | 469 | if ( funcSpecs[i] && src->funcSpecs[i] ) {
|
---|
[dd020c0] | 470 | appendError( error, string( "duplicate " ) + DeclarationNode::funcSpecifierNames[i] );
|
---|
| 471 | } // if
|
---|
| 472 | } // for
|
---|
| 473 | } // if
|
---|
| 474 |
|
---|
[a7c90d4] | 475 | if ( storageClasses != 0 && src->storageClasses != 0 ) { // any reason to check ?
|
---|
| 476 | if ( (storageClasses & src->storageClasses).any() ) { // duplicates ?
|
---|
| 477 | for ( unsigned int i = 0; i < NoStorageClass; i += 1 ) { // find duplicates
|
---|
| 478 | if ( storageClasses[i] && src->storageClasses[i] ) {
|
---|
| 479 | appendError( error, string( "duplicate " ) + storageClassNames[i] );
|
---|
| 480 | } // if
|
---|
| 481 | } // for
|
---|
| 482 | // src is the new item being added and has a single bit
|
---|
| 483 | } else if ( ! src->storageClasses[ Threadlocal ] ) { // conflict ?
|
---|
| 484 | appendError( error, string( "conflicting " ) + storageClassNames[ffs( storageClasses.to_ulong() ) - 1] +
|
---|
| 485 | " & " + storageClassNames[ffs( src->storageClasses.to_ulong() ) - 1] );
|
---|
| 486 | src->storageClasses.reset(); // FIX to preserve invariant of one basic storage specifier
|
---|
[b6424d9] | 487 | } // if
|
---|
| 488 | } // if
|
---|
[dd020c0] | 489 |
|
---|
[a7c90d4] | 490 | appendError( error, src->error );
|
---|
| 491 | } // DeclarationNode::checkSpecifiers
|
---|
[b6424d9] | 492 |
|
---|
[a7c90d4] | 493 | DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
|
---|
| 494 | funcSpecs = funcSpecs | q->funcSpecs;
|
---|
| 495 | storageClasses = storageClasses | q->storageClasses;
|
---|
[c0aa336] | 496 |
|
---|
| 497 | for ( Attribute *attr: reverseIterate( q->attributes ) ) {
|
---|
| 498 | attributes.push_front( attr->clone() );
|
---|
| 499 | } // for
|
---|
[b6424d9] | 500 | return this;
|
---|
[a7c90d4] | 501 | } // DeclarationNode::copySpecifiers
|
---|
[b6424d9] | 502 |
|
---|
[ba7aa2d] | 503 | static void addQualifiersToType( TypeData *&src, TypeData * dst ) {
|
---|
[101e0bd] | 504 | if ( src->forall && dst->kind == TypeData::Function ) {
|
---|
| 505 | if ( dst->forall ) {
|
---|
| 506 | dst->forall->appendList( src->forall );
|
---|
| 507 | } else {
|
---|
| 508 | dst->forall = src->forall;
|
---|
| 509 | } // if
|
---|
[2298f728] | 510 | src->forall = nullptr;
|
---|
[101e0bd] | 511 | } // if
|
---|
| 512 | if ( dst->base ) {
|
---|
| 513 | addQualifiersToType( src, dst->base );
|
---|
| 514 | } else if ( dst->kind == TypeData::Function ) {
|
---|
| 515 | dst->base = src;
|
---|
[2298f728] | 516 | src = nullptr;
|
---|
[101e0bd] | 517 | } else {
|
---|
[dd020c0] | 518 | dst->typeQualifiers |= src->typeQualifiers;
|
---|
[101e0bd] | 519 | } // if
|
---|
| 520 | } // addQualifiersToType
|
---|
| 521 |
|
---|
[ba7aa2d] | 522 | DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
|
---|
[2298f728] | 523 | if ( ! q ) { delete q; return this; }
|
---|
[101e0bd] | 524 |
|
---|
[a7c90d4] | 525 | checkSpecifiers( q );
|
---|
| 526 | copySpecifiers( q );
|
---|
[101e0bd] | 527 |
|
---|
[1b772749] | 528 | if ( ! q->type ) {
|
---|
| 529 | delete q;
|
---|
| 530 | return this;
|
---|
| 531 | } // if
|
---|
[101e0bd] | 532 |
|
---|
| 533 | if ( ! type ) {
|
---|
[1b772749] | 534 | type = q->type; // reuse this structure
|
---|
| 535 | q->type = nullptr;
|
---|
| 536 | delete q;
|
---|
[101e0bd] | 537 | return this;
|
---|
| 538 | } // if
|
---|
| 539 |
|
---|
| 540 | if ( q->type->forall ) {
|
---|
| 541 | if ( type->forall ) {
|
---|
| 542 | type->forall->appendList( q->type->forall );
|
---|
| 543 | } else {
|
---|
| 544 | if ( type->kind == TypeData::Aggregate ) {
|
---|
| 545 | type->aggregate.params = q->type->forall;
|
---|
| 546 | // change implicit typedef from TYPEDEFname to TYPEGENname
|
---|
[2298f728] | 547 | typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG );
|
---|
[c1c1112] | 548 | } else {
|
---|
[101e0bd] | 549 | type->forall = q->type->forall;
|
---|
[68cd1ce] | 550 | } // if
|
---|
| 551 | } // if
|
---|
[2298f728] | 552 | q->type->forall = nullptr;
|
---|
[68cd1ce] | 553 | } // if
|
---|
[6ef2d81] | 554 |
|
---|
[a7c90d4] | 555 | checkQualifiers( type, q->type );
|
---|
[6ef2d81] | 556 | addQualifiersToType( q->type, type );
|
---|
| 557 |
|
---|
[b87a5ed] | 558 | delete q;
|
---|
| 559 | return this;
|
---|
[101e0bd] | 560 | } // addQualifiers
|
---|
[3848e0e] | 561 |
|
---|
| 562 | static void addTypeToType( TypeData *&src, TypeData *&dst ) {
|
---|
[101e0bd] | 563 | if ( src->forall && dst->kind == TypeData::Function ) {
|
---|
| 564 | if ( dst->forall ) {
|
---|
| 565 | dst->forall->appendList( src->forall );
|
---|
[b87a5ed] | 566 | } else {
|
---|
[101e0bd] | 567 | dst->forall = src->forall;
|
---|
| 568 | } // if
|
---|
[2298f728] | 569 | src->forall = nullptr;
|
---|
[101e0bd] | 570 | } // if
|
---|
| 571 | if ( dst->base ) {
|
---|
| 572 | addTypeToType( src, dst->base );
|
---|
| 573 | } else {
|
---|
| 574 | switch ( dst->kind ) {
|
---|
| 575 | case TypeData::Unknown:
|
---|
[dd020c0] | 576 | src->typeQualifiers |= dst->typeQualifiers;
|
---|
[101e0bd] | 577 | dst = src;
|
---|
[2298f728] | 578 | src = nullptr;
|
---|
[101e0bd] | 579 | break;
|
---|
| 580 | case TypeData::Basic:
|
---|
[dd020c0] | 581 | dst->typeQualifiers |= src->typeQualifiers;
|
---|
[101e0bd] | 582 | if ( src->kind != TypeData::Unknown ) {
|
---|
| 583 | assert( src->kind == TypeData::Basic );
|
---|
| 584 |
|
---|
| 585 | if ( dst->basictype == DeclarationNode::NoBasicType ) {
|
---|
| 586 | dst->basictype = src->basictype;
|
---|
| 587 | } else if ( src->basictype != DeclarationNode::NoBasicType )
|
---|
[dd020c0] | 588 | throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: ", src );
|
---|
[101e0bd] | 589 |
|
---|
| 590 | if ( dst->complextype == DeclarationNode::NoComplexType ) {
|
---|
| 591 | dst->complextype = src->complextype;
|
---|
| 592 | } else if ( src->complextype != DeclarationNode::NoComplexType )
|
---|
[dd020c0] | 593 | throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: ", src );
|
---|
[101e0bd] | 594 |
|
---|
| 595 | if ( dst->signedness == DeclarationNode::NoSignedness ) {
|
---|
| 596 | dst->signedness = src->signedness;
|
---|
| 597 | } else if ( src->signedness != DeclarationNode::NoSignedness )
|
---|
[dd020c0] | 598 | throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: ", src );
|
---|
[101e0bd] | 599 |
|
---|
| 600 | if ( dst->length == DeclarationNode::NoLength ) {
|
---|
| 601 | dst->length = src->length;
|
---|
| 602 | } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
|
---|
| 603 | dst->length = DeclarationNode::LongLong;
|
---|
| 604 | } else if ( src->length != DeclarationNode::NoLength )
|
---|
[dd020c0] | 605 | throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: ", src );
|
---|
[101e0bd] | 606 | } // if
|
---|
| 607 | break;
|
---|
| 608 | default:
|
---|
| 609 | switch ( src->kind ) {
|
---|
| 610 | case TypeData::Aggregate:
|
---|
| 611 | case TypeData::Enum:
|
---|
| 612 | dst->base = new TypeData( TypeData::AggregateInst );
|
---|
| 613 | dst->base->aggInst.aggregate = src;
|
---|
| 614 | if ( src->kind == TypeData::Aggregate ) {
|
---|
| 615 | dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
|
---|
[68cd1ce] | 616 | } // if
|
---|
[dd020c0] | 617 | dst->base->typeQualifiers |= src->typeQualifiers;
|
---|
[2298f728] | 618 | src = nullptr;
|
---|
[b87a5ed] | 619 | break;
|
---|
| 620 | default:
|
---|
[101e0bd] | 621 | if ( dst->forall ) {
|
---|
| 622 | dst->forall->appendList( src->forall );
|
---|
| 623 | } else {
|
---|
| 624 | dst->forall = src->forall;
|
---|
| 625 | } // if
|
---|
[2298f728] | 626 | src->forall = nullptr;
|
---|
[101e0bd] | 627 | dst->base = src;
|
---|
[2298f728] | 628 | src = nullptr;
|
---|
[68cd1ce] | 629 | } // switch
|
---|
[101e0bd] | 630 | } // switch
|
---|
[68cd1ce] | 631 | } // if
|
---|
[3848e0e] | 632 | }
|
---|
| 633 |
|
---|
[ba7aa2d] | 634 | DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
|
---|
[b87a5ed] | 635 | if ( o ) {
|
---|
[a7c90d4] | 636 | checkSpecifiers( o );
|
---|
| 637 | copySpecifiers( o );
|
---|
[b87a5ed] | 638 | if ( o->type ) {
|
---|
| 639 | if ( ! type ) {
|
---|
| 640 | if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
|
---|
| 641 | type = new TypeData( TypeData::AggregateInst );
|
---|
[8f6f47d7] | 642 | type->aggInst.aggregate = o->type;
|
---|
[b87a5ed] | 643 | if ( o->type->kind == TypeData::Aggregate ) {
|
---|
[43c89a7] | 644 | type->aggInst.hoistType = o->type->aggregate.body;
|
---|
[8f6f47d7] | 645 | type->aggInst.params = maybeClone( o->type->aggregate.actuals );
|
---|
[43c89a7] | 646 | } else {
|
---|
| 647 | type->aggInst.hoistType = o->type->enumeration.body;
|
---|
[68cd1ce] | 648 | } // if
|
---|
[dd020c0] | 649 | type->typeQualifiers |= o->type->typeQualifiers;
|
---|
[b87a5ed] | 650 | } else {
|
---|
| 651 | type = o->type;
|
---|
[68cd1ce] | 652 | } // if
|
---|
[2298f728] | 653 | o->type = nullptr;
|
---|
[b87a5ed] | 654 | } else {
|
---|
| 655 | addTypeToType( o->type, type );
|
---|
[68cd1ce] | 656 | } // if
|
---|
| 657 | } // if
|
---|
[b87a5ed] | 658 | if ( o->bitfieldWidth ) {
|
---|
| 659 | bitfieldWidth = o->bitfieldWidth;
|
---|
[68cd1ce] | 660 | } // if
|
---|
[71bd8c6] | 661 |
|
---|
| 662 | // there may be typedefs chained onto the type
|
---|
[1d4580a] | 663 | if ( o->get_next() ) {
|
---|
| 664 | set_last( o->get_next()->clone() );
|
---|
[1db21619] | 665 | } // if
|
---|
[68cd1ce] | 666 | } // if
|
---|
[b87a5ed] | 667 | delete o;
|
---|
| 668 | return this;
|
---|
[3848e0e] | 669 | }
|
---|
| 670 |
|
---|
[ba7aa2d] | 671 | DeclarationNode * DeclarationNode::addTypedef() {
|
---|
| 672 | TypeData * newtype = new TypeData( TypeData::Symbolic );
|
---|
[2298f728] | 673 | newtype->symbolic.params = nullptr;
|
---|
[8f6f47d7] | 674 | newtype->symbolic.isTypedef = true;
|
---|
[2298f728] | 675 | newtype->symbolic.name = name ? new string( *name ) : nullptr;
|
---|
[b87a5ed] | 676 | newtype->base = type;
|
---|
| 677 | type = newtype;
|
---|
| 678 | return this;
|
---|
[3848e0e] | 679 | }
|
---|
| 680 |
|
---|
[ba7aa2d] | 681 | DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
|
---|
[faddbd8] | 682 | if ( variable.tyClass != NoTypeClass ) {
|
---|
[2298f728] | 683 | if ( variable.assertions ) {
|
---|
| 684 | variable.assertions->appendList( assertions );
|
---|
| 685 | } else {
|
---|
| 686 | variable.assertions = assertions;
|
---|
| 687 | } // if
|
---|
| 688 | return this;
|
---|
| 689 | } // if
|
---|
| 690 |
|
---|
[b87a5ed] | 691 | assert( type );
|
---|
| 692 | switch ( type->kind ) {
|
---|
| 693 | case TypeData::Symbolic:
|
---|
[8f6f47d7] | 694 | if ( type->symbolic.assertions ) {
|
---|
| 695 | type->symbolic.assertions->appendList( assertions );
|
---|
[b87a5ed] | 696 | } else {
|
---|
[8f6f47d7] | 697 | type->symbolic.assertions = assertions;
|
---|
[68cd1ce] | 698 | } // if
|
---|
[b87a5ed] | 699 | break;
|
---|
| 700 | default:
|
---|
| 701 | assert( false );
|
---|
[68cd1ce] | 702 | } // switch
|
---|
[974906e2] | 703 |
|
---|
[b87a5ed] | 704 | return this;
|
---|
[51b73452] | 705 | }
|
---|
| 706 |
|
---|
[fb114fa1] | 707 | DeclarationNode * DeclarationNode::addName( string * newname ) {
|
---|
[2298f728] | 708 | assert( ! name );
|
---|
| 709 | name = newname;
|
---|
[b87a5ed] | 710 | return this;
|
---|
[51b73452] | 711 | }
|
---|
| 712 |
|
---|
[c0aa336] | 713 | DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) {
|
---|
[58dd019] | 714 | assert( ! asmName );
|
---|
[c0aa336] | 715 | asmName = newname ? newname->asmName : nullptr;
|
---|
| 716 | return this->addQualifiers( newname );
|
---|
[58dd019] | 717 | }
|
---|
| 718 |
|
---|
[ba7aa2d] | 719 | DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) {
|
---|
[b87a5ed] | 720 | bitfieldWidth = size;
|
---|
| 721 | return this;
|
---|
[51b73452] | 722 | }
|
---|
| 723 |
|
---|
[ba7aa2d] | 724 | DeclarationNode * DeclarationNode::addVarArgs() {
|
---|
[b87a5ed] | 725 | assert( type );
|
---|
| 726 | hasEllipsis = true;
|
---|
| 727 | return this;
|
---|
[51b73452] | 728 | }
|
---|
| 729 |
|
---|
[ba7aa2d] | 730 | DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) {
|
---|
[b87a5ed] | 731 | assert( type );
|
---|
| 732 | assert( type->kind == TypeData::Function );
|
---|
[2298f728] | 733 | assert( ! type->function.body );
|
---|
[8f6f47d7] | 734 | type->function.body = body;
|
---|
[b87a5ed] | 735 | return this;
|
---|
[51b73452] | 736 | }
|
---|
| 737 |
|
---|
[ba7aa2d] | 738 | DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) {
|
---|
[b87a5ed] | 739 | assert( type );
|
---|
| 740 | assert( type->kind == TypeData::Function );
|
---|
[2298f728] | 741 | assert( ! type->function.oldDeclList );
|
---|
[8f6f47d7] | 742 | type->function.oldDeclList = list;
|
---|
[b87a5ed] | 743 | return this;
|
---|
[51b73452] | 744 | }
|
---|
| 745 |
|
---|
[c0aa336] | 746 | DeclarationNode * DeclarationNode::setBase( TypeData * newType ) {
|
---|
[b87a5ed] | 747 | if ( type ) {
|
---|
[ba7aa2d] | 748 | TypeData * prevBase = type;
|
---|
| 749 | TypeData * curBase = type->base;
|
---|
[2298f728] | 750 | while ( curBase != nullptr ) {
|
---|
[b87a5ed] | 751 | prevBase = curBase;
|
---|
| 752 | curBase = curBase->base;
|
---|
[68cd1ce] | 753 | } // while
|
---|
[b87a5ed] | 754 | prevBase->base = newType;
|
---|
| 755 | } else {
|
---|
| 756 | type = newType;
|
---|
[68cd1ce] | 757 | } // if
|
---|
[c0aa336] | 758 | return this;
|
---|
[3848e0e] | 759 | }
|
---|
| 760 |
|
---|
[c0aa336] | 761 | DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
|
---|
| 762 | if ( a ) {
|
---|
| 763 | for ( Attribute *attr: reverseIterate( a->attributes ) ) {
|
---|
| 764 | attributes.push_front( attr );
|
---|
| 765 | } // for
|
---|
| 766 | a->attributes.clear();
|
---|
| 767 | } // if
|
---|
| 768 | return this;
|
---|
| 769 | } // copyAttribute
|
---|
| 770 |
|
---|
[ba7aa2d] | 771 | DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
|
---|
[b87a5ed] | 772 | if ( p ) {
|
---|
| 773 | assert( p->type->kind == TypeData::Pointer );
|
---|
[c0aa336] | 774 | setBase( p->type );
|
---|
[2298f728] | 775 | p->type = nullptr;
|
---|
[c0aa336] | 776 | copyAttribute( p );
|
---|
[b87a5ed] | 777 | delete p;
|
---|
[68cd1ce] | 778 | } // if
|
---|
[b87a5ed] | 779 | return this;
|
---|
[3848e0e] | 780 | }
|
---|
| 781 |
|
---|
[ba7aa2d] | 782 | DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) {
|
---|
[b87a5ed] | 783 | if ( a ) {
|
---|
| 784 | assert( a->type->kind == TypeData::Array );
|
---|
[c0aa336] | 785 | setBase( a->type );
|
---|
[2298f728] | 786 | a->type = nullptr;
|
---|
[c0aa336] | 787 | copyAttribute( a );
|
---|
[b87a5ed] | 788 | delete a;
|
---|
[68cd1ce] | 789 | } // if
|
---|
[b87a5ed] | 790 | return this;
|
---|
[51b73452] | 791 | }
|
---|
| 792 |
|
---|
[ba7aa2d] | 793 | DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
|
---|
[b87a5ed] | 794 | if ( p ) {
|
---|
| 795 | assert( p->type->kind == TypeData::Pointer );
|
---|
| 796 | if ( type ) {
|
---|
| 797 | switch ( type->kind ) {
|
---|
| 798 | case TypeData::Aggregate:
|
---|
| 799 | case TypeData::Enum:
|
---|
| 800 | p->type->base = new TypeData( TypeData::AggregateInst );
|
---|
[8f6f47d7] | 801 | p->type->base->aggInst.aggregate = type;
|
---|
[b87a5ed] | 802 | if ( type->kind == TypeData::Aggregate ) {
|
---|
[8f6f47d7] | 803 | p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
|
---|
[68cd1ce] | 804 | } // if
|
---|
[dd020c0] | 805 | p->type->base->typeQualifiers |= type->typeQualifiers;
|
---|
[b87a5ed] | 806 | break;
|
---|
| 807 |
|
---|
| 808 | default:
|
---|
| 809 | p->type->base = type;
|
---|
[68cd1ce] | 810 | } // switch
|
---|
[2298f728] | 811 | type = nullptr;
|
---|
[68cd1ce] | 812 | } // if
|
---|
[b87a5ed] | 813 | delete this;
|
---|
| 814 | return p;
|
---|
| 815 | } else {
|
---|
| 816 | return this;
|
---|
[68cd1ce] | 817 | } // if
|
---|
[51b73452] | 818 | }
|
---|
| 819 |
|
---|
[ba7aa2d] | 820 | static TypeData * findLast( TypeData * a ) {
|
---|
[b87a5ed] | 821 | assert( a );
|
---|
[ba7aa2d] | 822 | TypeData * cur = a;
|
---|
[a32b204] | 823 | while ( cur->base ) {
|
---|
[b87a5ed] | 824 | cur = cur->base;
|
---|
[68cd1ce] | 825 | } // while
|
---|
[b87a5ed] | 826 | return cur;
|
---|
[3848e0e] | 827 | }
|
---|
| 828 |
|
---|
[ba7aa2d] | 829 | DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
|
---|
[b87a5ed] | 830 | if ( a ) {
|
---|
| 831 | assert( a->type->kind == TypeData::Array );
|
---|
[ba7aa2d] | 832 | TypeData * lastArray = findLast( a->type );
|
---|
[974906e2] | 833 | if ( type ) {
|
---|
[b87a5ed] | 834 | switch ( type->kind ) {
|
---|
| 835 | case TypeData::Aggregate:
|
---|
| 836 | case TypeData::Enum:
|
---|
| 837 | lastArray->base = new TypeData( TypeData::AggregateInst );
|
---|
[8f6f47d7] | 838 | lastArray->base->aggInst.aggregate = type;
|
---|
[b87a5ed] | 839 | if ( type->kind == TypeData::Aggregate ) {
|
---|
[8f6f47d7] | 840 | lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
|
---|
[68cd1ce] | 841 | } // if
|
---|
[dd020c0] | 842 | lastArray->base->typeQualifiers |= type->typeQualifiers;
|
---|
[b87a5ed] | 843 | break;
|
---|
| 844 | default:
|
---|
| 845 | lastArray->base = type;
|
---|
[68cd1ce] | 846 | } // switch
|
---|
[2298f728] | 847 | type = nullptr;
|
---|
[68cd1ce] | 848 | } // if
|
---|
[b87a5ed] | 849 | delete this;
|
---|
| 850 | return a;
|
---|
| 851 | } else {
|
---|
| 852 | return this;
|
---|
[68cd1ce] | 853 | } // if
|
---|
[51b73452] | 854 | }
|
---|
[3848e0e] | 855 |
|
---|
[ba7aa2d] | 856 | DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) {
|
---|
| 857 | TypeData * ftype = new TypeData( TypeData::Function );
|
---|
[8f6f47d7] | 858 | ftype->function.params = params;
|
---|
[c0aa336] | 859 | setBase( ftype );
|
---|
[b87a5ed] | 860 | return this;
|
---|
[3848e0e] | 861 | }
|
---|
| 862 |
|
---|
[ba7aa2d] | 863 | static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) {
|
---|
[b87a5ed] | 864 | if ( type ) {
|
---|
| 865 | if ( type->kind != TypeData::Function ) {
|
---|
| 866 | type->base = addIdListToType( type->base, ids );
|
---|
| 867 | } else {
|
---|
[8f6f47d7] | 868 | type->function.idList = ids;
|
---|
[68cd1ce] | 869 | } // if
|
---|
[b87a5ed] | 870 | return type;
|
---|
[3848e0e] | 871 | } else {
|
---|
[ba7aa2d] | 872 | TypeData * newtype = new TypeData( TypeData::Function );
|
---|
[8f6f47d7] | 873 | newtype->function.idList = ids;
|
---|
[b87a5ed] | 874 | return newtype;
|
---|
[68cd1ce] | 875 | } // if
|
---|
[2298f728] | 876 | } // addIdListToType
|
---|
[974906e2] | 877 |
|
---|
[ba7aa2d] | 878 | DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
|
---|
[b87a5ed] | 879 | type = addIdListToType( type, ids );
|
---|
| 880 | return this;
|
---|
[3848e0e] | 881 | }
|
---|
| 882 |
|
---|
[ba7aa2d] | 883 | DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
|
---|
[b87a5ed] | 884 | initializer = init;
|
---|
| 885 | return this;
|
---|
[3848e0e] | 886 | }
|
---|
| 887 |
|
---|
[ba7aa2d] | 888 | DeclarationNode * DeclarationNode::cloneType( string * newName ) {
|
---|
| 889 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 890 | newnode->type = maybeClone( type );
|
---|
[a7c90d4] | 891 | newnode->copySpecifiers( this );
|
---|
[ba7aa2d] | 892 | assert( newName );
|
---|
[2298f728] | 893 | newnode->name = newName;
|
---|
[b87a5ed] | 894 | return newnode;
|
---|
[3848e0e] | 895 | }
|
---|
| 896 |
|
---|
[2298f728] | 897 | DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
|
---|
| 898 | if ( ! o ) return nullptr;
|
---|
| 899 |
|
---|
[a7c90d4] | 900 | o->copySpecifiers( this );
|
---|
[2298f728] | 901 | if ( type ) {
|
---|
| 902 | TypeData * srcType = type;
|
---|
| 903 |
|
---|
[c0aa336] | 904 | // search for the base type by scanning off pointers and array designators
|
---|
[2298f728] | 905 | while ( srcType->base ) {
|
---|
| 906 | srcType = srcType->base;
|
---|
| 907 | } // while
|
---|
| 908 |
|
---|
| 909 | TypeData * newType = srcType->clone();
|
---|
| 910 | if ( newType->kind == TypeData::AggregateInst ) {
|
---|
| 911 | // don't duplicate members
|
---|
| 912 | if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
|
---|
| 913 | delete newType->aggInst.aggregate->enumeration.constants;
|
---|
| 914 | newType->aggInst.aggregate->enumeration.constants = nullptr;
|
---|
[b87a5ed] | 915 | } else {
|
---|
[2298f728] | 916 | assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
|
---|
| 917 | delete newType->aggInst.aggregate->aggregate.fields;
|
---|
| 918 | newType->aggInst.aggregate->aggregate.fields = nullptr;
|
---|
[68cd1ce] | 919 | } // if
|
---|
[43c89a7] | 920 | // don't hoist twice
|
---|
| 921 | newType->aggInst.hoistType = false;
|
---|
[68cd1ce] | 922 | } // if
|
---|
[2298f728] | 923 |
|
---|
| 924 | newType->forall = maybeClone( type->forall );
|
---|
| 925 | if ( ! o->type ) {
|
---|
| 926 | o->type = newType;
|
---|
| 927 | } else {
|
---|
| 928 | addTypeToType( newType, o->type );
|
---|
| 929 | delete newType;
|
---|
| 930 | } // if
|
---|
[68cd1ce] | 931 | } // if
|
---|
[b87a5ed] | 932 | return o;
|
---|
[51b73452] | 933 | }
|
---|
| 934 |
|
---|
[ba7aa2d] | 935 | DeclarationNode * DeclarationNode::extractAggregate() const {
|
---|
[b87a5ed] | 936 | if ( type ) {
|
---|
[ba7aa2d] | 937 | TypeData * ret = typeextractAggregate( type );
|
---|
[b87a5ed] | 938 | if ( ret ) {
|
---|
[ba7aa2d] | 939 | DeclarationNode * newnode = new DeclarationNode;
|
---|
[b87a5ed] | 940 | newnode->type = ret;
|
---|
| 941 | return newnode;
|
---|
[843054c2] | 942 | } // if
|
---|
| 943 | } // if
|
---|
[2298f728] | 944 | return nullptr;
|
---|
[3848e0e] | 945 | }
|
---|
| 946 |
|
---|
[ba7aa2d] | 947 | void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {
|
---|
[b87a5ed] | 948 | SemanticError errors;
|
---|
[7880579] | 949 | std::back_insert_iterator< std::list< Declaration * > > out( outputList );
|
---|
[2298f728] | 950 |
|
---|
[3a5131ed] | 951 | for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
|
---|
[b87a5ed] | 952 | try {
|
---|
[ba7aa2d] | 953 | if ( DeclarationNode * extr = cur->extractAggregate() ) {
|
---|
[b87a5ed] | 954 | // handle the case where a structure declaration is contained within an object or type declaration
|
---|
[ba7aa2d] | 955 | Declaration * decl = extr->build();
|
---|
[b87a5ed] | 956 | if ( decl ) {
|
---|
[294647b] | 957 | decl->location = cur->location;
|
---|
[ba7aa2d] | 958 | * out++ = decl;
|
---|
[843054c2] | 959 | } // if
|
---|
[f39096c] | 960 | delete extr;
|
---|
[843054c2] | 961 | } // if
|
---|
[2298f728] | 962 |
|
---|
[ba7aa2d] | 963 | Declaration * decl = cur->build();
|
---|
[b87a5ed] | 964 | if ( decl ) {
|
---|
[294647b] | 965 | decl->location = cur->location;
|
---|
[ba7aa2d] | 966 | * out++ = decl;
|
---|
[843054c2] | 967 | } // if
|
---|
[b87a5ed] | 968 | } catch( SemanticError &e ) {
|
---|
[294647b] | 969 | e.set_location( cur->location );
|
---|
[b87a5ed] | 970 | errors.append( e );
|
---|
[843054c2] | 971 | } // try
|
---|
| 972 | } // while
|
---|
[2298f728] | 973 |
|
---|
[b87a5ed] | 974 | if ( ! errors.isEmpty() ) {
|
---|
| 975 | throw errors;
|
---|
[843054c2] | 976 | } // if
|
---|
[2298f728] | 977 | } // buildList
|
---|
[3848e0e] | 978 |
|
---|
[ba7aa2d] | 979 | void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
|
---|
[b87a5ed] | 980 | SemanticError errors;
|
---|
[7880579] | 981 | std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
|
---|
[43c89a7] | 982 |
|
---|
[3a5131ed] | 983 | for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
|
---|
[b87a5ed] | 984 | try {
|
---|
[ba7aa2d] | 985 | Declaration * decl = cur->build();
|
---|
[b87a5ed] | 986 | if ( decl ) {
|
---|
[ba7aa2d] | 987 | if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
|
---|
[294647b] | 988 | dwt->location = cur->location;
|
---|
[ba7aa2d] | 989 | * out++ = dwt;
|
---|
| 990 | } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
|
---|
| 991 | StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
|
---|
[a7c90d4] | 992 | auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );
|
---|
[294647b] | 993 | obj->location = cur->location;
|
---|
[43c89a7] | 994 | * out++ = obj;
|
---|
[b87a5ed] | 995 | delete agg;
|
---|
[ba7aa2d] | 996 | } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
|
---|
| 997 | UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
|
---|
[a7c90d4] | 998 | auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );
|
---|
[294647b] | 999 | obj->location = cur->location;
|
---|
| 1000 | * out++ = obj;
|
---|
[843054c2] | 1001 | } // if
|
---|
| 1002 | } // if
|
---|
[b87a5ed] | 1003 | } catch( SemanticError &e ) {
|
---|
[294647b] | 1004 | e.set_location( cur->location );
|
---|
[b87a5ed] | 1005 | errors.append( e );
|
---|
[843054c2] | 1006 | } // try
|
---|
[3a5131ed] | 1007 | } // for
|
---|
| 1008 |
|
---|
[b87a5ed] | 1009 | if ( ! errors.isEmpty() ) {
|
---|
| 1010 | throw errors;
|
---|
[843054c2] | 1011 | } // if
|
---|
[2298f728] | 1012 | } // buildList
|
---|
[3848e0e] | 1013 |
|
---|
[ba7aa2d] | 1014 | void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
|
---|
[b87a5ed] | 1015 | SemanticError errors;
|
---|
[7880579] | 1016 | std::back_insert_iterator< std::list< Type * > > out( outputList );
|
---|
[ba7aa2d] | 1017 | const DeclarationNode * cur = firstNode;
|
---|
[2298f728] | 1018 |
|
---|
[a32b204] | 1019 | while ( cur ) {
|
---|
[b87a5ed] | 1020 | try {
|
---|
[ba7aa2d] | 1021 | * out++ = cur->buildType();
|
---|
[b87a5ed] | 1022 | } catch( SemanticError &e ) {
|
---|
[138e29e] | 1023 | e.set_location( cur->location );
|
---|
[b87a5ed] | 1024 | errors.append( e );
|
---|
[843054c2] | 1025 | } // try
|
---|
[7880579] | 1026 | cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
|
---|
[843054c2] | 1027 | } // while
|
---|
[2298f728] | 1028 |
|
---|
[b87a5ed] | 1029 | if ( ! errors.isEmpty() ) {
|
---|
| 1030 | throw errors;
|
---|
[843054c2] | 1031 | } // if
|
---|
[2298f728] | 1032 | } // buildTypeList
|
---|
[51b73452] | 1033 |
|
---|
[ba7aa2d] | 1034 | Declaration * DeclarationNode::build() const {
|
---|
[7d05e7e] | 1035 | if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
|
---|
[2298f728] | 1036 |
|
---|
[e994912] | 1037 | if ( asmStmt ) {
|
---|
| 1038 | return new AsmDecl( safe_dynamic_cast<AsmStmt *>( asmStmt->build() ) );
|
---|
| 1039 | } // if
|
---|
| 1040 |
|
---|
[faddbd8] | 1041 | if ( variable.tyClass != NoTypeClass ) {
|
---|
[8f60f0b] | 1042 | static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype };
|
---|
| 1043 | assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
|
---|
| 1044 | assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
|
---|
[a7c90d4] | 1045 | TypeDecl * ret = new TypeDecl( *name, DeclarationNode::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
|
---|
[2298f728] | 1046 | buildList( variable.assertions, ret->get_assertions() );
|
---|
| 1047 | return ret;
|
---|
| 1048 | } // if
|
---|
| 1049 |
|
---|
[843054c2] | 1050 | if ( type ) {
|
---|
[dd020c0] | 1051 | // Function specifiers can only appear on a function definition/declaration.
|
---|
| 1052 | //
|
---|
| 1053 | // inline _Noreturn int f(); // allowed
|
---|
| 1054 | // inline _Noreturn int g( int i ); // allowed
|
---|
| 1055 | // inline _Noreturn int i; // disallowed
|
---|
[a7c90d4] | 1056 | if ( type->kind != TypeData::Function && funcSpecs.any() ) {
|
---|
[dd020c0] | 1057 | throw SemanticError( "invalid function specifier for ", this );
|
---|
| 1058 | } // if
|
---|
[a7c90d4] | 1059 | return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
|
---|
[843054c2] | 1060 | } // if
|
---|
[2298f728] | 1061 |
|
---|
[dd020c0] | 1062 | // SUE's cannot have function specifiers, either
|
---|
| 1063 | //
|
---|
| 1064 | // inlne _Noreturn struct S { ... }; // disallowed
|
---|
| 1065 | // inlne _Noreturn enum E { ... }; // disallowed
|
---|
[a7c90d4] | 1066 | if ( funcSpecs.any() ) {
|
---|
[dd020c0] | 1067 | throw SemanticError( "invalid function specifier for ", this );
|
---|
[843054c2] | 1068 | } // if
|
---|
[dd020c0] | 1069 | assertf( name, "ObjectDecl must a have name\n" );
|
---|
[a7c90d4] | 1070 | return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_asmName( asmName )->set_extension( extension );
|
---|
[51b73452] | 1071 | }
|
---|
| 1072 |
|
---|
[ba7aa2d] | 1073 | Type * DeclarationNode::buildType() const {
|
---|
[b87a5ed] | 1074 | assert( type );
|
---|
[974906e2] | 1075 |
|
---|
[faddbd8] | 1076 | if ( attr.expr ) {
|
---|
[c0aa336] | 1077 | return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
|
---|
[faddbd8] | 1078 | } else if ( attr.type ) {
|
---|
[c0aa336] | 1079 | return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
|
---|
[2298f728] | 1080 | } // if
|
---|
| 1081 |
|
---|
[b87a5ed] | 1082 | switch ( type->kind ) {
|
---|
[43c89a7] | 1083 | case TypeData::Enum:
|
---|
[b87a5ed] | 1084 | case TypeData::Aggregate: {
|
---|
[43c89a7] | 1085 | ReferenceToType * ret = buildComAggInst( type, attributes );
|
---|
[8f6f47d7] | 1086 | buildList( type->aggregate.actuals, ret->get_parameters() );
|
---|
[b87a5ed] | 1087 | return ret;
|
---|
| 1088 | }
|
---|
| 1089 | case TypeData::Symbolic: {
|
---|
[c0aa336] | 1090 | TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
|
---|
[8f6f47d7] | 1091 | buildList( type->symbolic.actuals, ret->get_parameters() );
|
---|
[b87a5ed] | 1092 | return ret;
|
---|
| 1093 | }
|
---|
| 1094 | default:
|
---|
[c0aa336] | 1095 | Type * simpletypes = typebuild( type );
|
---|
| 1096 | simpletypes->get_attributes() = attributes; // copy because member is const
|
---|
| 1097 | return simpletypes;
|
---|
[b87a5ed] | 1098 | } // switch
|
---|
[3848e0e] | 1099 | }
|
---|
| 1100 |
|
---|
[b87a5ed] | 1101 | // Local Variables: //
|
---|
| 1102 | // tab-width: 4 //
|
---|
| 1103 | // mode: c++ //
|
---|
| 1104 | // compile-command: "make install" //
|
---|
| 1105 | // End: //
|
---|