Changes in src/Parser/DeclarationNode.cc [f39096c:c1c1112]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rf39096c rc1c1112 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 18 23:48:23201613 // Update Count : 18212 // Last Modified On : Thu Aug 25 20:42:25 2016 13 // Update Count : 232 14 14 // 15 15 … … 50 50 newnode->isInline = isInline; 51 51 newnode->isNoreturn = isNoreturn; 52 newnode->bitfieldWidth = maybeClone( bitfieldWidth );52 newnode->bitfieldWidth = bitfieldWidth; 53 53 newnode->hasEllipsis = hasEllipsis; 54 newnode->initializer = maybeClone( initializer );54 newnode->initializer = 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 .push_back( q );152 newnode->type->qualifiers[ q ] = 1; 153 153 return newnode; 154 154 } // DeclarationNode::newQualifier 155 155 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 } 156 DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) { 157 DeclarationNode *newnode = new DeclarationNode; 158 newnode->type = new TypeData( TypeData::Unknown ); 159 newnode->type->forall = forall; 160 return newnode; 161 } // DeclarationNode::newForall 162 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; 163 171 return newnode; 164 172 } // DeclarationNode::newStorageClass 165 173 166 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {174 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) { 167 175 DeclarationNode *newnode = new DeclarationNode; 168 176 newnode->type = new TypeData( TypeData::Basic ); … … 171 179 } // DeclarationNode::newBasicType 172 180 173 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) { 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 ) { 174 189 DeclarationNode *newnode = new DeclarationNode; 175 190 newnode->type = new TypeData( TypeData::Builtin ); … … 178 193 } // DeclarationNode::newBuiltinType 179 194 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 ) { 188 DeclarationNode *newnode = new DeclarationNode; 189 newnode->type = new TypeData( TypeData::Unknown ); 190 newnode->type->forall = forall; 191 return newnode; 192 } // DeclarationNode::newForall 193 194 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { 195 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 195 196 DeclarationNode *newnode = new DeclarationNode; 196 197 newnode->type = new TypeData( TypeData::SymbolicInst ); … … 201 202 } // DeclarationNode::newFromTypedef 202 203 203 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {204 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) { 204 205 DeclarationNode *newnode = new DeclarationNode; 205 206 newnode->type = new TypeData( TypeData::Aggregate ); … … 369 370 src = 0; 370 371 } else { 371 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 372 } // if 373 } // if 374 } 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 375 393 376 394 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { … … 380 398 if ( ! type ) { 381 399 type = new TypeData; 400 } else { 401 checkQualifiers( q->type, type ); 382 402 } // if 383 403 addQualifiersToType( q->type, type ); … … 405 425 isInline = isInline || q->isInline; 406 426 isNoreturn = isNoreturn || q->isNoreturn; 407 if (storageClass == NoStorageClass) {427 if ( storageClass == NoStorageClass ) { 408 428 storageClass = q->storageClass; 409 } 410 else if (q->storageClass != NoStorageClass) { 429 } else if ( q->storageClass != NoStorageClass ) { 411 430 q->error = "invalid combination of storage classes in declaration of "; 412 } 413 if (error.empty()) error = q->error;431 } // if 432 if ( error.empty() ) error = q->error; 414 433 return this; 415 434 } … … 430 449 switch ( dst->kind ) { 431 450 case TypeData::Unknown: 432 src->qualifiers .splice( src->qualifiers.end(), dst->qualifiers );451 src->qualifiers |= dst->qualifiers; 433 452 dst = src; 434 453 src = 0; 435 454 break; 436 455 case TypeData::Basic: 437 dst->qualifiers .splice( dst->qualifiers.end(), src->qualifiers );456 dst->qualifiers |= src->qualifiers; 438 457 if ( src->kind != TypeData::Unknown ) { 439 458 assert( src->kind == TypeData::Basic ); … … 451 470 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 452 471 } // if 453 dst->base->qualifiers .splice( dst->base->qualifiers.end(), src->qualifiers );472 dst->base->qualifiers |= src->qualifiers; 454 473 src = 0; 455 474 break; … … 480 499 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 481 500 } // if 482 type->qualifiers .splice( type->qualifiers.end(), o->type->qualifiers );501 type->qualifiers |= o->type->qualifiers; 483 502 } else { 484 503 type = o->type; … … 615 634 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 616 635 } // if 617 p->type->base->qualifiers .splice( p->type->base->qualifiers.end(), type->qualifiers );636 p->type->base->qualifiers |= type->qualifiers; 618 637 break; 619 638 … … 652 671 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 653 672 } // if 654 lastArray->base->qualifiers .splice( lastArray->base->qualifiers.end(), type->qualifiers );673 lastArray->base->qualifiers |= type->qualifiers; 655 674 break; 656 675 default: … … 804 823 *out++ = decl; 805 824 } // if 806 delete extr;807 825 } // if 808 826 Declaration *decl = cur->build(); … … 875 893 876 894 Declaration *DeclarationNode::build() const { 877 if ( !error.empty() ) throw SemanticError( error, this );895 if ( ! error.empty() ) throw SemanticError( error, this ); 878 896 if ( type ) { 879 897 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.