Changeset 738e304
- Timestamp:
- Mar 15, 2017, 10:46:40 PM (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:
- 905eca1
- Parents:
- f2e40a9f
- git-author:
- Peter A. Buhr <pabuhr@…> (03/15/17 22:42:52)
- git-committer:
- Peter A. Buhr <pabuhr@…> (03/15/17 22:46:40)
- Location:
- src/Parser
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rf2e40a9f r738e304 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 14 22:42:54201713 // Update Count : 9 7412 // Last Modified On : Wed Mar 15 22:31:36 2017 13 // Update Count : 983 14 14 // 15 15 … … 35 35 const char * DeclarationNode::storageClassNames[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" }; 36 36 const char * DeclarationNode::funcSpecifierNames[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" }; 37 const char * DeclarationNode::typeQualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };38 37 const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" }; 39 38 const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" }; … … 214 213 } // DeclarationNode::newFuncSpecifier 215 214 216 DeclarationNode * DeclarationNode::newTypeQualifier( Type Qualifiers tq ) {215 DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) { 217 216 DeclarationNode * newnode = new DeclarationNode; 218 217 newnode->type = new TypeData(); 219 newnode->type-> typeQualifiers = tq;218 newnode->type->qualifiers = tq; 220 219 return newnode; 221 220 } // DeclarationNode::newQualifier … … 457 456 458 457 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) { 459 const Type Qualifiers qsrc = src->typeQualifiers, qdst = dst->typeQualifiers; // optimization458 const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 460 459 461 460 if ( (qsrc.val & qdst.val) != 0 ) { // duplicates ? 462 for ( unsigned int i = 0; i < NumTypeQualifier; i += 1 ) { // find duplicates461 for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates 463 462 if ( qsrc[i] && qdst[i] ) { 464 appendError( error, string( "duplicate " ) + DeclarationNode::typeQualifierNames[i] );463 appendError( error, string( "duplicate " ) + Type::QualifierNames[i] ); 465 464 } // if 466 465 } // for … … 469 468 470 469 void DeclarationNode::checkSpecifiers( DeclarationNode * src ) { 471 if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) { 470 if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) { // duplicates ? 472 471 for ( unsigned int i = 0; i < NumFuncSpecifier; i += 1 ) { // find duplicates 473 472 if ( funcSpecs[i] && src->funcSpecs[i] ) { … … 496 495 497 496 DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) { 498 funcSpecs.val = funcSpecs.val |q->funcSpecs.val;499 storageClasses.val = storageClasses.val |q->storageClasses.val;497 funcSpecs.val |= q->funcSpecs.val; 498 storageClasses.val |= q->storageClasses.val; 500 499 501 500 for ( Attribute *attr: reverseIterate( q->attributes ) ) { … … 520 519 src = nullptr; 521 520 } else { 522 dst-> typeQualifiers.val |= src->typeQualifiers.val;521 dst->qualifiers += src->qualifiers; 523 522 } // if 524 523 } // addQualifiersToType … … 578 577 switch ( dst->kind ) { 579 578 case TypeData::Unknown: 580 src-> typeQualifiers.val |= dst->typeQualifiers.val;579 src->qualifiers += dst->qualifiers; 581 580 dst = src; 582 581 src = nullptr; 583 582 break; 584 583 case TypeData::Basic: 585 dst-> typeQualifiers.val |= src->typeQualifiers.val;584 dst->qualifiers += src->qualifiers; 586 585 if ( src->kind != TypeData::Unknown ) { 587 586 assert( src->kind == TypeData::Basic ); … … 619 618 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 620 619 } // if 621 dst->base-> typeQualifiers.val |= src->typeQualifiers.val;620 dst->base->qualifiers += src->qualifiers; 622 621 src = nullptr; 623 622 break; … … 651 650 type->aggInst.hoistType = o->type->enumeration.body; 652 651 } // if 653 type-> typeQualifiers.val |= o->type->typeQualifiers.val;652 type->qualifiers += o->type->qualifiers; 654 653 } else { 655 654 type = o->type; … … 807 806 p->type->base->aggInst.params = maybeClone( type->aggregate.actuals ); 808 807 } // if 809 p->type->base-> typeQualifiers.val |= type->typeQualifiers.val;808 p->type->base->qualifiers += type->qualifiers; 810 809 break; 811 810 … … 832 831 833 832 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.val |= type->typeQualifiers.val; 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 833 if ( ! a ) return this; 834 assert( a->type->kind == TypeData::Array ); 835 TypeData * lastArray = findLast( a->type ); 836 if ( type ) { 837 switch ( type->kind ) { 838 case TypeData::Aggregate: 839 case TypeData::Enum: 840 lastArray->base = new TypeData( TypeData::AggregateInst ); 841 lastArray->base->aggInst.aggregate = type; 842 if ( type->kind == TypeData::Aggregate ) { 843 lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals ); 844 } // if 845 lastArray->base->qualifiers += type->qualifiers; 846 break; 847 default: 848 lastArray->base = type; 849 } // switch 850 type = nullptr; 851 } // if 852 delete this; 853 return a; 858 854 } 859 855 -
src/Parser/ParseNode.h
rf2e40a9f r738e304 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 14 22:41:37201713 // Update Count : 7 5812 // Last Modified On : Wed Mar 15 22:17:50 2017 13 // Update Count : 762 14 14 // 15 15 … … 231 231 }; // FuncSpecifiers 232 232 233 enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };234 union TypeQualifiers {235 unsigned int val;236 struct {237 bool is_const : 1;238 bool is_restrict : 1;239 bool is_volatile : 1;240 bool is_lvalue : 1;241 bool is_mutex : 1;242 bool is_atomic : 1;243 };244 TypeQualifiers() : val( 0 ) {}245 TypeQualifiers( unsigned int val ) : val( val ) {}246 bool operator[]( unsigned int i ) const { return val & (1 << i); }247 }; // TypeQualifiers248 249 233 enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType }; 250 234 enum ComplexType { Complex, Imaginary, NoComplexType }; … … 257 241 static const char * storageClassNames[]; 258 242 static const char * funcSpecifierNames[]; 259 static const char * typeQualifierNames[];260 243 static const char * basicTypeNames[]; 261 244 static const char * complexTypeNames[]; … … 268 251 static DeclarationNode * newStorageClass( StorageClasses ); 269 252 static DeclarationNode * newFuncSpecifier( FuncSpecifiers ); 270 static DeclarationNode * newTypeQualifier( Type Qualifiers );253 static DeclarationNode * newTypeQualifier( Type::Qualifiers ); 271 254 static DeclarationNode * newBasicType( BasicType ); 272 255 static DeclarationNode * newComplexType( ComplexType ); -
src/Parser/TypeData.cc
rf2e40a9f r738e304 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 14 22:43:20201713 // Update Count : 5 4912 // Last Modified On : Wed Mar 15 22:22:29 2017 13 // Update Count : 555 14 14 // 15 15 … … 157 157 TypeData * TypeData::clone() const { 158 158 TypeData * newtype = new TypeData( kind ); 159 newtype-> typeQualifiers = typeQualifiers;159 newtype->qualifiers = qualifiers; 160 160 newtype->base = maybeClone( base ); 161 161 newtype->forall = maybeClone( forall ); … … 226 226 227 227 void TypeData::print( ostream &os, int indent ) const { 228 for ( int i = 0; i < DeclarationNode::NumTypeQualifier; i += 1 ) {229 if ( typeQualifiers[i] ) os << DeclarationNode::typeQualifierNames[ i ] << ' ';228 for ( int i = 0; i < Type::NumTypeQualifier; i += 1 ) { 229 if ( qualifiers[i] ) os << Type::QualifierNames[ i ] << ' '; 230 230 } // for 231 231 … … 493 493 494 494 Type::Qualifiers buildQualifiers( const TypeData * td ) { 495 Type::Qualifiers q; 496 q.isConst = td->typeQualifiers.is_const; 497 q.isVolatile = td->typeQualifiers.is_volatile; 498 q.isRestrict = td->typeQualifiers.is_restrict; 499 q.isLvalue = td->typeQualifiers.is_lvalue; 500 q.isAtomic = td->typeQualifiers.is_atomic; 501 return q; 495 return td->qualifiers; 502 496 } // buildQualifiers 503 497 -
src/Parser/TypeData.h
rf2e40a9f r738e304 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 14 16:51:26201713 // Update Count : 18 112 // Last Modified On : Wed Mar 15 22:10:23 2017 13 // Update Count : 183 14 14 // 15 15 … … 75 75 DeclarationNode::BuiltinType builtintype = DeclarationNode::NoBuiltinType; 76 76 77 DeclarationNode::TypeQualifiers typeQualifiers;77 Type::Qualifiers qualifiers; 78 78 DeclarationNode * forall; 79 79 -
src/Parser/parser.yy
rf2e40a9f r738e304 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 9 21:40:20201713 // Update Count : 2 29212 // Last Modified On : Wed Mar 15 22:06:22 2017 13 // Update Count : 2308 14 14 // 15 15 … … 437 437 argument_expression: 438 438 // empty 439 { $$ = nullptr; } // use default argument 439 { $$ = nullptr; } 440 // | '@' // use default argument 441 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 440 442 | assignment_expression 441 443 ; … … 1404 1406 type_qualifier_name: 1405 1407 CONST 1406 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Const ); }1408 { $$ = DeclarationNode::newTypeQualifier( Type::Const ); } 1407 1409 | RESTRICT 1408 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Restrict ); }1410 { $$ = DeclarationNode::newTypeQualifier( Type::Restrict ); } 1409 1411 | VOLATILE 1410 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Volatile ); }1412 { $$ = DeclarationNode::newTypeQualifier( Type::Volatile ); } 1411 1413 | LVALUE // CFA 1412 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Lvalue ); }1414 { $$ = DeclarationNode::newTypeQualifier( Type::Lvalue ); } 1413 1415 | MUTEX 1414 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Mutex ); }1416 { $$ = DeclarationNode::newTypeQualifier( Type::Mutex ); } 1415 1417 | ATOMIC 1416 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Atomic ); }1418 { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); } 1417 1419 | FORALL '(' 1418 1420 { … … 1682 1684 // empty 1683 1685 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name 1686 // '@' // empty 1687 // { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name 1684 1688 | bit_subrange_size // no field name 1685 1689 { $$ = DeclarationNode::newBitfield( $1 ); }
Note: See TracChangeset
for help on using the changeset viewer.