Changes in src/Parser/DeclarationNode.cc [413ad05:f39096c]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r413ad05 rf39096c 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 22:12:44201613 // Update Count : 27812 // Last Modified On : Thu Aug 18 23:48:23 2016 13 // Update Count : 182 14 14 // 15 15 … … 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( const TypeData *src, const 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: … … 801 782 DeclarationNode *DeclarationNode::extractAggregate() const { 802 783 if ( type ) { 803 TypeData *ret = type extractAggregate( type);784 TypeData *ret = type->extractAggregate(); 804 785 if ( ret ) { 805 786 DeclarationNode *newnode = new DeclarationNode; … … 894 875 895 876 Declaration *DeclarationNode::build() const { 896 if ( !error.empty() ) throw SemanticError( error, this );877 if( !error.empty() ) throw SemanticError( error, this ); 897 878 if ( type ) { 898 return buildDecl( type,name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );879 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 899 880 } // if 900 881 if ( ! isInline && ! isNoreturn ) { … … 909 890 switch ( type->kind ) { 910 891 case TypeData::Enum: 911 return new EnumInstType( buildQualifiers( type), type->enumeration->name );892 return new EnumInstType( type->buildQualifiers(), type->enumeration->name ); 912 893 case TypeData::Aggregate: { 913 894 ReferenceToType *ret; 914 895 switch ( type->aggregate->kind ) { 915 896 case DeclarationNode::Struct: 916 ret = new StructInstType( buildQualifiers( type), type->aggregate->name );897 ret = new StructInstType( type->buildQualifiers(), type->aggregate->name ); 917 898 break; 918 899 case DeclarationNode::Union: 919 ret = new UnionInstType( buildQualifiers( type), type->aggregate->name );900 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 920 901 break; 921 902 case DeclarationNode::Trait: 922 ret = new TraitInstType( buildQualifiers( type), type->aggregate->name );903 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name ); 923 904 break; 924 905 default: … … 929 910 } 930 911 case TypeData::Symbolic: { 931 TypeInstType *ret = new TypeInstType( buildQualifiers( type), type->symbolic->name, false );912 TypeInstType *ret = new TypeInstType( type->buildQualifiers(), type->symbolic->name, false ); 932 913 buildList( type->symbolic->actuals, ret->get_parameters() ); 933 914 return ret; 934 915 } 935 916 default: 936 return type build( type);917 return type->build(); 937 918 } // switch 938 919 }
Note:
See TracChangeset
for help on using the changeset viewer.