Changes in src/Parser/DeclarationNode.cc [08d5507b:fb04321]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r08d5507b rfb04321 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Mar 14 10:19:38201713 // Update Count : 96412 // Last Modified On : Thu Mar 16 09:10:57 2017 13 // Update Count : 1007 14 14 // 15 15 … … 33 33 34 34 // These must remain in the same order as the corresponding DeclarationNode enumerations. 35 const char * DeclarationNode::storageClassNames[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };36 const char * DeclarationNode::funcSpecifierNames[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };37 const char * DeclarationNode::typeQualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };38 35 const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" }; 39 36 const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" }; … … 116 113 } 117 114 118 void DeclarationNode::print_StorageClass( std::ostream & output, StorageClasses storageClasses ) {119 if ( storageClasses.val != 0 ) { // storage classes ?120 for ( unsigned int i = 0; i < DeclarationNode::NoStorageClass; i += 1 ) {121 if ( storageClasses[i] ) {122 output << DeclarationNode::storageClassNames[i] << ' ';123 } // if124 } // for125 } // if126 } // print_StorageClass127 128 void DeclarationNode::print_FuncSpec( std::ostream & output, DeclarationNode::FuncSpecifiers funcSpec ) {129 if ( funcSpec.val != 0 ) { // function specifiers ?130 for ( unsigned int i = 0; i < DeclarationNode::NoFuncSpecifier; i += 1 ) {131 if ( funcSpec[i] ) {132 output << DeclarationNode::funcSpecifierNames[i] << ' ';133 } // if134 } // for135 } // if136 } // print_FuncSpec137 138 115 void DeclarationNode::print( std::ostream &os, int indent ) const { 139 116 os << string( indent, ' ' ); … … 148 125 } // if 149 126 150 print_StorageClass( os, storageClasses );151 print_FuncSpec( os, funcSpecs );127 storageClasses.print( os ); 128 funcSpecs.print( os ); 152 129 153 130 if ( type ) { … … 202 179 203 180 204 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClasses sc ) {181 DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) { 205 182 DeclarationNode * newnode = new DeclarationNode; 206 183 newnode->storageClasses = sc; … … 208 185 } // DeclarationNode::newStorageClass 209 186 210 DeclarationNode * DeclarationNode::newFuncSpecifier( DeclarationNode::FuncSpecifiers fs ) {187 DeclarationNode * DeclarationNode::newFuncSpecifier( Type::FuncSpecifiers fs ) { 211 188 DeclarationNode * newnode = new DeclarationNode; 212 189 newnode->funcSpecs = fs; … … 214 191 } // DeclarationNode::newFuncSpecifier 215 192 216 DeclarationNode * DeclarationNode::newTypeQualifier( Type Qualifiertq ) {193 DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) { 217 194 DeclarationNode * newnode = new DeclarationNode; 218 195 newnode->type = new TypeData(); 219 newnode->type-> typeQualifiers[ tq ] = true;196 newnode->type->qualifiers = tq; 220 197 return newnode; 221 198 } // DeclarationNode::newQualifier … … 457 434 458 435 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) { 459 const Type Data::TypeQualifiers qsrc = src->typeQualifiers, qdst = dst->typeQualifiers; // optimization460 461 if ( (qsrc & qdst).any() ) {// duplicates ?462 for ( unsigned int i = 0; i < NoTypeQualifier; i += 1 ) { // find duplicates436 const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 437 438 if ( (qsrc.val & qdst.val) != 0 ) { // duplicates ? 439 for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates 463 440 if ( qsrc[i] && qdst[i] ) { 464 appendError( error, string( "duplicate " ) + DeclarationNode::typeQualifierNames[i] );441 appendError( error, string( "duplicate " ) + Type::Qualifiers::Names[i] ); 465 442 } // if 466 443 } // for … … 469 446 470 447 void DeclarationNode::checkSpecifiers( DeclarationNode * src ) { 471 if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) { // duplicates ?472 for ( unsigned int i = 0; i < NoFuncSpecifier; i += 1 ) { // find duplicates448 if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) { // duplicates ? 449 for ( unsigned int i = 0; i < Type::NumFuncSpecifier; i += 1 ) { // find duplicates 473 450 if ( funcSpecs[i] && src->funcSpecs[i] ) { 474 appendError( error, string( "duplicate " ) + DeclarationNode::funcSpecifierNames[i] );451 appendError( error, string( "duplicate " ) + Type::FuncSpecifiers::Names[i] ); 475 452 } // if 476 453 } // for 477 454 } // if 478 455 479 if ( storageClasses. val != 0 && src->storageClasses.val != 0) { // any reason to check ?456 if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ? 480 457 if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ? 481 for ( unsigned int i = 0; i < NoStorageClass; i += 1 ) { // find duplicates458 for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates 482 459 if ( storageClasses[i] && src->storageClasses[i] ) { 483 appendError( error, string( "duplicate " ) + storageClassNames[i] );460 appendError( error, string( "duplicate " ) + Type::StorageClasses::Names[i] ); 484 461 } // if 485 462 } // for 486 463 // src is the new item being added and has a single bit 487 464 } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ? 488 appendError( error, string( "conflicting " ) + storageClassNames[ffs( storageClasses.val ) - 1] +489 " & " + storageClassNames[ffs( src->storageClasses.val ) - 1] );465 appendError( error, string( "conflicting " ) + Type::StorageClasses::Names[ffs( storageClasses.val ) - 1] + 466 " & " + Type::StorageClasses::Names[ffs( src->storageClasses.val ) - 1] ); 490 467 src->storageClasses.val = 0; // FIX to preserve invariant of one basic storage specifier 491 468 } // if … … 496 473 497 474 DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) { 498 funcSpecs.val = funcSpecs.val |q->funcSpecs.val;499 storageClasses.val = storageClasses.val |q->storageClasses.val;475 funcSpecs.val |= q->funcSpecs.val; 476 storageClasses.val |= q->storageClasses.val; 500 477 501 478 for ( Attribute *attr: reverseIterate( q->attributes ) ) { … … 520 497 src = nullptr; 521 498 } else { 522 dst-> typeQualifiers |= src->typeQualifiers;499 dst->qualifiers += src->qualifiers; 523 500 } // if 524 501 } // addQualifiersToType … … 578 555 switch ( dst->kind ) { 579 556 case TypeData::Unknown: 580 src-> typeQualifiers |= dst->typeQualifiers;557 src->qualifiers += dst->qualifiers; 581 558 dst = src; 582 559 src = nullptr; 583 560 break; 584 561 case TypeData::Basic: 585 dst-> typeQualifiers |= src->typeQualifiers;562 dst->qualifiers += src->qualifiers; 586 563 if ( src->kind != TypeData::Unknown ) { 587 564 assert( src->kind == TypeData::Basic ); … … 619 596 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 620 597 } // if 621 dst->base-> typeQualifiers |= src->typeQualifiers;598 dst->base->qualifiers += src->qualifiers; 622 599 src = nullptr; 623 600 break; … … 651 628 type->aggInst.hoistType = o->type->enumeration.body; 652 629 } // if 653 type-> typeQualifiers |= o->type->typeQualifiers;630 type->qualifiers += o->type->qualifiers; 654 631 } else { 655 632 type = o->type; … … 807 784 p->type->base->aggInst.params = maybeClone( type->aggregate.actuals ); 808 785 } // if 809 p->type->base-> typeQualifiers |= type->typeQualifiers;786 p->type->base->qualifiers += type->qualifiers; 810 787 break; 811 788 … … 832 809 833 810 DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) { 834 if ( a ) { 835 assert( a->type->kind == TypeData::Array ); 836 TypeData * lastArray = findLast( a->type ); 837 if ( type ) { 838 switch ( type->kind ) { 839 case TypeData::Aggregate: 840 case TypeData::Enum: 841 lastArray->base = new TypeData( TypeData::AggregateInst ); 842 lastArray->base->aggInst.aggregate = type; 843 if ( type->kind == TypeData::Aggregate ) { 844 lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals ); 845 } // if 846 lastArray->base->typeQualifiers |= type->typeQualifiers; 847 break; 848 default: 849 lastArray->base = type; 850 } // switch 851 type = nullptr; 852 } // if 853 delete this; 854 return a; 855 } else { 856 return this; 857 } // if 811 if ( ! a ) return this; 812 assert( a->type->kind == TypeData::Array ); 813 TypeData * lastArray = findLast( a->type ); 814 if ( type ) { 815 switch ( type->kind ) { 816 case TypeData::Aggregate: 817 case TypeData::Enum: 818 lastArray->base = new TypeData( TypeData::AggregateInst ); 819 lastArray->base->aggInst.aggregate = type; 820 if ( type->kind == TypeData::Aggregate ) { 821 lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals ); 822 } // if 823 lastArray->base->qualifiers += type->qualifiers; 824 break; 825 default: 826 lastArray->base = type; 827 } // switch 828 type = nullptr; 829 } // if 830 delete this; 831 return a; 858 832 } 859 833 … … 994 968 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 995 969 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 996 auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );970 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 997 971 obj->location = cur->location; 998 972 * out++ = obj; … … 1000 974 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 1001 975 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 1002 auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );976 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1003 977 obj->location = cur->location; 1004 978 * out++ = obj; … … 1047 1021 assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." ); 1048 1022 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1049 TypeDecl * ret = new TypeDecl( *name, DeclarationNode::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );1023 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] ); 1050 1024 buildList( variable.assertions, ret->get_assertions() ); 1051 1025 return ret; … … 1058 1032 // inline _Noreturn int g( int i ); // allowed 1059 1033 // inline _Noreturn int i; // disallowed 1060 if ( type->kind != TypeData::Function && funcSpecs. val != 0) {1034 if ( type->kind != TypeData::Function && funcSpecs.any() ) { 1061 1035 throw SemanticError( "invalid function specifier for ", this ); 1062 1036 } // if … … 1068 1042 // inlne _Noreturn struct S { ... }; // disallowed 1069 1043 // inlne _Noreturn enum E { ... }; // disallowed 1070 if ( funcSpecs. val != 0) {1044 if ( funcSpecs.any() ) { 1071 1045 throw SemanticError( "invalid function specifier for ", this ); 1072 1046 } // if
Note:
See TracChangeset
for help on using the changeset viewer.