Changeset 08d5507b for src/Parser
- Timestamp:
- Mar 14, 2017, 11:29:34 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 4da6a6c, e496303
- Parents:
- 68ac32e
- Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r68ac32e r08d5507b 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 7 17:28:56201713 // Update Count : 9 3712 // Last Modified On : Tue Mar 14 10:19:38 2017 13 // Update Count : 964 14 14 // 15 15 … … 90 90 newnode->type = maybeClone( type ); 91 91 newnode->storageClasses = storageClasses; 92 newnode->funcSpecs = funcSpecs; 92 93 newnode->bitfieldWidth = maybeClone( bitfieldWidth ); 93 newnode->funcSpecs = funcSpecs;94 94 newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) ); 95 95 newnode->hasEllipsis = hasEllipsis; … … 117 117 118 118 void DeclarationNode::print_StorageClass( std::ostream & output, StorageClasses storageClasses ) { 119 if ( storageClasses. any() ) { // function specifiers?119 if ( storageClasses.val != 0 ) { // storage classes ? 120 120 for ( unsigned int i = 0; i < DeclarationNode::NoStorageClass; i += 1 ) { 121 121 if ( storageClasses[i] ) { … … 127 127 128 128 void DeclarationNode::print_FuncSpec( std::ostream & output, DeclarationNode::FuncSpecifiers funcSpec ) { 129 if ( funcSpec. any() ) { // function specifiers?129 if ( funcSpec.val != 0 ) { // function specifiers ? 130 130 for ( unsigned int i = 0; i < DeclarationNode::NoFuncSpecifier; i += 1 ) { 131 131 if ( funcSpec[i] ) { … … 202 202 203 203 204 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {205 DeclarationNode * newnode = new DeclarationNode; 206 newnode->storageClasses [ sc ] = true;204 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClasses sc ) { 205 DeclarationNode * newnode = new DeclarationNode; 206 newnode->storageClasses = sc; 207 207 return newnode; 208 208 } // DeclarationNode::newStorageClass 209 209 210 DeclarationNode * DeclarationNode::newFuncSpecifier( DeclarationNode::FuncSpecifier fs ) {211 DeclarationNode * newnode = new DeclarationNode; 212 newnode->funcSpecs [ fs ] = true;210 DeclarationNode * DeclarationNode::newFuncSpecifier( DeclarationNode::FuncSpecifiers fs ) { 211 DeclarationNode * newnode = new DeclarationNode; 212 newnode->funcSpecs = fs; 213 213 return newnode; 214 214 } // DeclarationNode::newFuncSpecifier … … 459 459 const TypeData::TypeQualifiers qsrc = src->typeQualifiers, qdst = dst->typeQualifiers; // optimization 460 460 461 if ( (qsrc & qdst).any() ) { // common qualifier?462 for ( unsigned int i = 0; i < NoTypeQualifier; i += 1 ) { // find common qualifiers461 if ( (qsrc & qdst).any() ) { // duplicates ? 462 for ( unsigned int i = 0; i < NoTypeQualifier; i += 1 ) { // find duplicates 463 463 if ( qsrc[i] && qdst[i] ) { 464 464 appendError( error, string( "duplicate " ) + DeclarationNode::typeQualifierNames[i] ); … … 469 469 470 470 void DeclarationNode::checkSpecifiers( DeclarationNode * src ) { 471 if ( (funcSpecs & src->funcSpecs).any() ) { // common specifier?472 for ( unsigned int i = 0; i < NoFuncSpecifier; i += 1 ) { // find common specifier471 if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) { // duplicates ? 472 for ( unsigned int i = 0; i < NoFuncSpecifier; i += 1 ) { // find duplicates 473 473 if ( funcSpecs[i] && src->funcSpecs[i] ) { 474 474 appendError( error, string( "duplicate " ) + DeclarationNode::funcSpecifierNames[i] ); … … 477 477 } // if 478 478 479 if ( storageClasses != 0 && src->storageClasses!= 0 ) { // any reason to check ?480 if ( (storageClasses & src->storageClasses).any()) { // duplicates ?479 if ( storageClasses.val != 0 && src->storageClasses.val != 0 ) { // any reason to check ? 480 if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ? 481 481 for ( unsigned int i = 0; i < NoStorageClass; i += 1 ) { // find duplicates 482 482 if ( storageClasses[i] && src->storageClasses[i] ) { … … 485 485 } // for 486 486 // src is the new item being added and has a single bit 487 } else if ( ! src->storageClasses [ Threadlocal ]) { // conflict ?488 appendError( error, string( "conflicting " ) + storageClassNames[ffs( storageClasses. to_ulong()) - 1] +489 " & " + storageClassNames[ffs( src->storageClasses. to_ulong()) - 1] );490 src->storageClasses. reset(); // FIX to preserve invariant of one basic storage specifier487 } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ? 488 appendError( error, string( "conflicting " ) + storageClassNames[ffs( storageClasses.val ) - 1] + 489 " & " + storageClassNames[ffs( src->storageClasses.val ) - 1] ); 490 src->storageClasses.val = 0; // FIX to preserve invariant of one basic storage specifier 491 491 } // if 492 492 } // if … … 496 496 497 497 DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) { 498 funcSpecs = funcSpecs | q->funcSpecs;499 storageClasses = storageClasses | q->storageClasses;498 funcSpecs.val = funcSpecs.val | q->funcSpecs.val; 499 storageClasses.val = storageClasses.val | q->storageClasses.val; 500 500 501 501 for ( Attribute *attr: reverseIterate( q->attributes ) ) { … … 1058 1058 // inline _Noreturn int g( int i ); // allowed 1059 1059 // inline _Noreturn int i; // disallowed 1060 if ( type->kind != TypeData::Function && funcSpecs. any()) {1060 if ( type->kind != TypeData::Function && funcSpecs.val != 0 ) { 1061 1061 throw SemanticError( "invalid function specifier for ", this ); 1062 1062 } // if … … 1068 1068 // inlne _Noreturn struct S { ... }; // disallowed 1069 1069 // inlne _Noreturn enum E { ... }; // disallowed 1070 if ( funcSpecs. any()) {1070 if ( funcSpecs.val != 0 ) { 1071 1071 throw SemanticError( "invalid function specifier for ", this ); 1072 1072 } // if -
src/Parser/ParseNode.h
r68ac32e r08d5507b 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 7 08:10:53201713 // Update Count : 7 2612 // Last Modified On : Tue Mar 14 11:05:05 2017 13 // Update Count : 752 14 14 // 15 15 … … 204 204 // These must remain in the same order as the corresponding DeclarationNode names. 205 205 206 enum StorageClass { Extern, Static, Auto, Register, Threadlocal, NoStorageClass, 207 ExternClass = 1 << Extern, StaticClass = 1 << Static, AutoClass = 1 << Auto, RegisterClass = 1 << Register, ThreadlocalClass = 1 << Threadlocal }; 208 enum FuncSpecifier { Inline, Noreturn, Fortran, NoFuncSpecifier, 209 InlineSpec = 1 << Inline, NoreturnSpec = 1 << Noreturn, FortranSpec = 1 << Fortran }; 206 enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NoStorageClass = 5 }; 207 union StorageClasses { 208 unsigned int val; 209 struct { 210 bool is_extern : 1; 211 bool is_static : 1; 212 bool is_auto : 1; 213 bool is_register : 1; 214 bool is_threadlocal : 1; 215 }; 216 StorageClasses() : val( 0 ) {} 217 StorageClasses( unsigned int val ) : val( val ) {} 218 bool operator[]( unsigned int i ) const { return val & (1 << i); } 219 }; // StorageClasses 220 221 enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NoFuncSpecifier = 3 }; 222 union FuncSpecifiers { 223 unsigned int val; 224 struct { 225 bool is_inline : 1; 226 bool is_noreturn : 1; 227 bool is_fortran : 1; 228 }; 229 FuncSpecifiers() : val( 0 ) {} 230 FuncSpecifiers( unsigned int val ) : val( val ) {} 231 bool operator[]( unsigned int i ) const { return val & (1 << i); } 232 }; // FuncSpecifiers 233 210 234 enum TypeQualifier { Const, Restrict, Volatile, Lvalue, Mutex, Atomic, NoTypeQualifier }; 211 235 enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType }; … … 228 252 static const char * builtinTypeNames[]; 229 253 230 static DeclarationNode * newStorageClass( StorageClass );231 static DeclarationNode * newFuncSpecifier( FuncSpecifier );254 static DeclarationNode * newStorageClass( StorageClasses ); 255 static DeclarationNode * newFuncSpecifier( FuncSpecifiers ); 232 256 static DeclarationNode * newTypeQualifier( TypeQualifier ); 233 257 static DeclarationNode * newBasicType( BasicType ); … … 326 350 TypeData * type; 327 351 328 typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;329 352 StorageClasses storageClasses; 330 353 static void print_StorageClass( std::ostream & output, StorageClasses storageClasses ); 331 354 332 typedef std::bitset< DeclarationNode::NoFuncSpecifier > FuncSpecifiers;333 355 FuncSpecifiers funcSpecs; 334 356 static void print_FuncSpec( std::ostream & output, FuncSpecifiers funcSpecs );
Note: See TracChangeset
for help on using the changeset viewer.