Changes in src/Parser/DeclarationNode.cc [c1c1112:f39096c]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rc1c1112 rf39096c 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 25 20:42:25201613 // Update Count : 23212 // Last Modified On : Thu Aug 18 23:48:23 2016 13 // Update Count : 182 14 14 // 15 15 … … 50 50 newnode->isInline = isInline; 51 51 newnode->isNoreturn = isNoreturn; 52 newnode->bitfieldWidth = bitfieldWidth;52 newnode->bitfieldWidth = maybeClone( bitfieldWidth ); 53 53 newnode->hasEllipsis = hasEllipsis; 54 newnode->initializer = initializer;54 newnode->initializer = maybeClone( initializer ); 55 55 newnode->set_next( maybeClone( get_next() ) ); 56 56 newnode->linkage = linkage; … … 93 93 } // if 94 94 95 if ( storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' ';96 if ( isInline) os << DeclarationNode::storageName[Inline] << ' ';97 if ( isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' ';95 if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' '; 96 if(isInline) os << DeclarationNode::storageName[Inline] << ' '; 97 if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' '; 98 98 if ( type ) { 99 99 type->print( os, indent ); … … 147 147 } // DeclarationNode::newFunction 148 148 149 DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) {149 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { 150 150 DeclarationNode *newnode = new DeclarationNode; 151 151 newnode->type = new TypeData(); 152 newnode->type->qualifiers [ q ] = 1;152 newnode->type->qualifiers.push_back( q ); 153 153 return newnode; 154 154 } // DeclarationNode::newQualifier 155 155 156 DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) { 156 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 157 DeclarationNode *newnode = new DeclarationNode; 158 switch (sc) { 159 case Inline: newnode->isInline = true; break; 160 case Noreturn: newnode->isNoreturn = true; break; 161 default: newnode->storageClass = sc; break; 162 } 163 return newnode; 164 } // DeclarationNode::newStorageClass 165 166 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { 167 DeclarationNode *newnode = new DeclarationNode; 168 newnode->type = new TypeData( TypeData::Basic ); 169 newnode->type->basic->typeSpec.push_back( bt ); 170 return newnode; 171 } // DeclarationNode::newBasicType 172 173 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) { 174 DeclarationNode *newnode = new DeclarationNode; 175 newnode->type = new TypeData( TypeData::Builtin ); 176 newnode->type->builtin->type = bt; 177 return newnode; 178 } // DeclarationNode::newBuiltinType 179 180 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { 181 DeclarationNode *newnode = new DeclarationNode; 182 newnode->type = new TypeData( TypeData::Basic ); 183 newnode->type->basic->modifiers.push_back( mod ); 184 return newnode; 185 } // DeclarationNode::newModifier 186 187 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { 157 188 DeclarationNode *newnode = new DeclarationNode; 158 189 newnode->type = new TypeData( TypeData::Unknown ); … … 161 192 } // DeclarationNode::newForall 162 193 163 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 164 DeclarationNode *newnode = new DeclarationNode; 165 //switch (sc) { 166 // case Inline: newnode->isInline = true; break; 167 // case Noreturn: newnode->isNoreturn = true; break; 168 // default: newnode->storageClass = sc; break; 169 //} 170 newnode->storageClass = sc; 171 return newnode; 172 } // DeclarationNode::newStorageClass 173 174 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) { 175 DeclarationNode *newnode = new DeclarationNode; 176 newnode->type = new TypeData( TypeData::Basic ); 177 newnode->type->basic->typeSpec.push_back( bt ); 178 return newnode; 179 } // DeclarationNode::newBasicType 180 181 DeclarationNode * DeclarationNode::newModifier( Modifier mod ) { 182 DeclarationNode *newnode = new DeclarationNode; 183 newnode->type = new TypeData( TypeData::Basic ); 184 newnode->type->basic->modifiers.push_back( mod ); 185 return newnode; 186 } // DeclarationNode::newModifier 187 188 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) { 189 DeclarationNode *newnode = new DeclarationNode; 190 newnode->type = new TypeData( TypeData::Builtin ); 191 newnode->type->builtin->type = bt; 192 return newnode; 193 } // DeclarationNode::newBuiltinType 194 195 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 194 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { 196 195 DeclarationNode *newnode = new DeclarationNode; 197 196 newnode->type = new TypeData( TypeData::SymbolicInst ); … … 202 201 } // DeclarationNode::newFromTypedef 203 202 204 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {203 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) { 205 204 DeclarationNode *newnode = new DeclarationNode; 206 205 newnode->type = new TypeData( TypeData::Aggregate ); … … 370 369 src = 0; 371 370 } else { 372 dst->qualifiers |= src->qualifiers; 373 } // if 374 } // if 375 } 376 377 void DeclarationNode::checkQualifiers( TypeData *src, TypeData *dst ) { 378 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; 379 380 if ( (qsrc & qdst).any() ) { // common bits between qualifier masks ? 381 error = "duplicate qualifier "; 382 int j = 0; // separator detector 383 for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) { 384 if ( qsrc[i] & qdst[i] ) { // find specific qualifiers in common 385 if ( j > 0 ) error += ", "; 386 error += DeclarationNode::qualifierName[i]; 387 j += 1; 388 } // if 389 } // for 390 error += " in declaration of "; 391 } // if 392 } // DeclarationNode::checkQualifiers 371 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 372 } // if 373 } // if 374 } 393 375 394 376 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { … … 398 380 if ( ! type ) { 399 381 type = new TypeData; 400 } else {401 checkQualifiers( q->type, type );402 382 } // if 403 383 addQualifiersToType( q->type, type ); … … 425 405 isInline = isInline || q->isInline; 426 406 isNoreturn = isNoreturn || q->isNoreturn; 427 if ( storageClass == NoStorageClass) {407 if(storageClass == NoStorageClass) { 428 408 storageClass = q->storageClass; 429 } else if ( q->storageClass != NoStorageClass ) { 409 } 410 else if (q->storageClass != NoStorageClass) { 430 411 q->error = "invalid combination of storage classes in declaration of "; 431 } // if432 if ( error.empty()) error = q->error;412 } 413 if(error.empty()) error = q->error; 433 414 return this; 434 415 } … … 449 430 switch ( dst->kind ) { 450 431 case TypeData::Unknown: 451 src->qualifiers |= dst->qualifiers;432 src->qualifiers.splice( src->qualifiers.end(), dst->qualifiers ); 452 433 dst = src; 453 434 src = 0; 454 435 break; 455 436 case TypeData::Basic: 456 dst->qualifiers |= src->qualifiers;437 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 457 438 if ( src->kind != TypeData::Unknown ) { 458 439 assert( src->kind == TypeData::Basic ); … … 470 451 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 471 452 } // if 472 dst->base->qualifiers |= src->qualifiers;453 dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers ); 473 454 src = 0; 474 455 break; … … 499 480 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 500 481 } // if 501 type->qualifiers |= o->type->qualifiers;482 type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers ); 502 483 } else { 503 484 type = o->type; … … 634 615 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 635 616 } // if 636 p->type->base->qualifiers |= type->qualifiers;617 p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers ); 637 618 break; 638 619 … … 671 652 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 672 653 } // if 673 lastArray->base->qualifiers |= type->qualifiers;654 lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers ); 674 655 break; 675 656 default: … … 823 804 *out++ = decl; 824 805 } // if 806 delete extr; 825 807 } // if 826 808 Declaration *decl = cur->build(); … … 893 875 894 876 Declaration *DeclarationNode::build() const { 895 if ( !error.empty() ) throw SemanticError( error, this );877 if( !error.empty() ) throw SemanticError( error, this ); 896 878 if ( type ) { 897 879 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
Note:
See TracChangeset
for help on using the changeset viewer.