Changeset 32a2a99 for src/Parser/DeclarationNode.cc
- Timestamp:
- Aug 30, 2016, 4:25:55 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 90e2334, fa463f1
- Parents:
- a2a8d2a6 (diff), ced2e989 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
ra2a8d2a6 r32a2a99 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 : Sun Aug 28 22:12:44 2016 13 // Update Count : 278 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 .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( 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 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: … … 782 801 DeclarationNode *DeclarationNode::extractAggregate() const { 783 802 if ( type ) { 784 TypeData *ret = type ->extractAggregate();803 TypeData *ret = typeextractAggregate( type ); 785 804 if ( ret ) { 786 805 DeclarationNode *newnode = new DeclarationNode; … … 875 894 876 895 Declaration *DeclarationNode::build() const { 877 if ( !error.empty() ) throw SemanticError( error, this );896 if ( ! error.empty() ) throw SemanticError( error, this ); 878 897 if ( type ) { 879 return type->buildDecl(name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );898 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 880 899 } // if 881 900 if ( ! isInline && ! isNoreturn ) { … … 890 909 switch ( type->kind ) { 891 910 case TypeData::Enum: 892 return new EnumInstType( type->buildQualifiers(), type->enumeration->name );911 return new EnumInstType( buildQualifiers( type ), type->enumeration->name ); 893 912 case TypeData::Aggregate: { 894 913 ReferenceToType *ret; 895 914 switch ( type->aggregate->kind ) { 896 915 case DeclarationNode::Struct: 897 ret = new StructInstType( type->buildQualifiers(), type->aggregate->name );916 ret = new StructInstType( buildQualifiers( type ), type->aggregate->name ); 898 917 break; 899 918 case DeclarationNode::Union: 900 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name ); 901 920 break; 902 921 case DeclarationNode::Trait: 903 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name ); 904 923 break; 905 924 default: … … 910 929 } 911 930 case TypeData::Symbolic: { 912 TypeInstType *ret = new TypeInstType( type->buildQualifiers(), type->symbolic->name, false );931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false ); 913 932 buildList( type->symbolic->actuals, ret->get_parameters() ); 914 933 return ret; 915 934 } 916 935 default: 917 return type ->build();936 return typebuild( type ); 918 937 } // switch 919 938 }
Note:
See TracChangeset
for help on using the changeset viewer.