Changeset bf4ac09 for src/SynTree
- Timestamp:
- Mar 15, 2017, 9:25:42 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:
- f2e40a9f
- Parents:
- 572547c
- Location:
- src/SynTree
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Type.cc
r572547c rbf4ac09 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 2 11:26:24201713 // Update Count : 1 212 // Last Modified On : Wed Mar 15 21:22:16 2017 13 // Update Count : 15 14 14 // 15 15 … … 59 59 } 60 60 61 void Type::Qualifiers::print( std::ostream &os, int indent ) const { 62 if ( isConst ) { 63 os << "const "; 64 } // if 65 if ( isVolatile ) { 66 os << "volatile "; 67 } // if 68 if ( isRestrict ) { 69 os << "restrict "; 70 } // if 71 if ( isLvalue ) { 72 os << "lvalue "; 73 } // if 74 if ( isAtomic ) { 75 os << "_Atomic "; 76 } // if 77 } 61 const char * Type::QualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" }; 78 62 79 63 void Type::print( std::ostream &os, int indent ) const { -
src/SynTree/Type.h
r572547c rbf4ac09 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 1 09:11:45201713 // Update Count : 4112 // Last Modified On : Wed Mar 15 21:23:08 2017 13 // Update Count : 84 14 14 // 15 15 … … 24 24 class Type : public BaseSyntaxNode { 25 25 public: 26 struct Qualifiers { 27 Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isMutex( false ) {} 28 Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isMutex ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isMutex( isMutex ) {} 29 30 Qualifiers &operator&=( const Qualifiers &other ); 31 Qualifiers &operator+=( const Qualifiers &other ); 32 Qualifiers &operator-=( const Qualifiers &other ); 33 Qualifiers operator+( const Type::Qualifiers &other ); 34 bool operator==( const Qualifiers &other ); 35 bool operator!=( const Qualifiers &other ); 36 bool operator<=( const Qualifiers &other ); 37 bool operator>=( const Qualifiers &other ); 38 bool operator<( const Qualifiers &other ); 39 bool operator>( const Qualifiers &other ); 40 void print( std::ostream &os, int indent = 0 ) const; 41 42 bool isConst; 43 bool isVolatile; 44 bool isRestrict; 45 bool isLvalue; 46 bool isAtomic; 47 bool isMutex; 48 }; 26 // struct Qualifiers { 27 // Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isMutex( false ) {} 28 // Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isMutex ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isMutex( isMutex ) {} 29 30 // Qualifiers &operator&=( const Qualifiers &other ); 31 // Qualifiers &operator+=( const Qualifiers &other ); 32 // Qualifiers &operator-=( const Qualifiers &other ); 33 // Qualifiers operator+( const Type::Qualifiers &other ); 34 // bool operator==( const Qualifiers &other ); 35 // bool operator!=( const Qualifiers &other ); 36 // bool operator<=( const Qualifiers &other ); 37 // bool operator>=( const Qualifiers &other ); 38 // bool operator<( const Qualifiers &other ); 39 // bool operator>( const Qualifiers &other ); 40 // void print( std::ostream &os, int indent = 0 ) const; 41 42 // bool isConst; 43 // bool isVolatile; 44 // bool isRestrict; 45 // bool isLvalue; 46 // bool isAtomic; 47 // bool isMutex; 48 // }; 49 50 static const char * QualifierNames[]; 51 52 enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 }; 53 union Qualifiers { 54 enum { Mask = ~(Restrict | Lvalue) }; 55 unsigned int val; 56 struct { 57 bool isConst : 1; 58 bool isRestrict : 1; 59 bool isVolatile : 1; 60 bool isLvalue : 1; 61 bool isMutex : 1; 62 bool isAtomic : 1; 63 }; 64 Qualifiers() : val( 0 ) {} 65 Qualifiers( unsigned int val ) : val( val ) {} 66 bool operator[]( unsigned int i ) const { return val & (1 << i); } 67 bool any() const { return val != 0; } 68 bool operator==( const Qualifiers other ) const { 69 return (val & Mask) == (other.val & Mask); 70 } 71 bool operator!=( const Qualifiers other ) const { 72 return (val & Mask) != (other.val & Mask); 73 } 74 bool operator<=( const Qualifiers other ) const { 75 return isConst <= other.isConst && isVolatile <= other.isVolatile && 76 isMutex == other.isMutex && isAtomic == other.isAtomic; 77 } 78 bool operator>=( const Qualifiers other ) const { 79 return isConst >= other.isConst && isVolatile >= other.isVolatile && 80 isMutex == other.isMutex && isAtomic == other.isAtomic; 81 } 82 bool operator<( const Qualifiers other ) const { 83 return *this != other && *this <= other; 84 } 85 bool operator>( const Qualifiers other ) const { 86 return *this != other && *this >= other; 87 } 88 Qualifiers operator&=( const Type::Qualifiers other ) { 89 val &= other.val; return *this; 90 } 91 Qualifiers operator+=( const Qualifiers other ) { 92 val |= other.val; return *this; 93 } 94 Qualifiers operator-=( const Qualifiers other ) { 95 val &= ~other.val; return *this; 96 } 97 Qualifiers operator+( const Qualifiers other ) const { 98 Qualifiers q = other; 99 q += *this; 100 return q; 101 } 102 void print( std::ostream &os, int indent = 0 ) const { 103 if ( (*this).any() ) { // any type qualifiers ? 104 for ( unsigned int i = 0; i < NumTypeQualifier; i += 1 ) { 105 if ( (*this)[i] ) { 106 os << QualifierNames[i] << ' '; 107 } // if 108 } // for 109 } // if 110 } 111 }; // Qualifiers 49 112 50 113 Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ); … … 506 569 }; 507 570 508 inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) {509 isConst &= other.isConst;510 isVolatile &= other.isVolatile;511 isRestrict &= other.isRestrict;512 isLvalue &= other.isLvalue;513 isAtomic &= other.isAtomic;514 isMutex &= other.isMutex;515 return *this;516 }517 518 inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) {519 isConst |= other.isConst;520 isVolatile |= other.isVolatile;521 isRestrict |= other.isRestrict;522 isLvalue |= other.isLvalue;523 isAtomic |= other.isAtomic;524 isMutex |= other.isMutex;525 return *this;526 }527 528 inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) {529 if ( other.isConst ) isConst = 0;530 if ( other.isVolatile ) isVolatile = 0;531 if ( other.isRestrict ) isRestrict = 0;532 if ( other.isAtomic ) isAtomic = 0;533 if ( other.isMutex ) isMutex = 0;534 return *this;535 }536 537 inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) {538 Qualifiers q = other;539 q += *this;540 return q;541 }542 543 inline bool Type::Qualifiers::operator==( const Qualifiers &other ) {544 return isConst == other.isConst545 && isVolatile == other.isVolatile546 // && isRestrict == other.isRestrict547 // && isLvalue == other.isLvalue548 && isAtomic == other.isAtomic;549 }550 551 inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {552 return isConst != other.isConst553 || isVolatile != other.isVolatile554 // || isRestrict != other.isRestrict555 // || isLvalue != other.isLvalue556 || isAtomic != other.isAtomic;557 }558 559 inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {560 return isConst <= other.isConst561 && isVolatile <= other.isVolatile562 // && isRestrict <= other.isRestrict563 // && isLvalue >= other.isLvalue564 && isAtomic == other.isAtomic;565 }566 567 inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {568 return isConst >= other.isConst569 && isVolatile >= other.isVolatile570 // && isRestrict >= other.isRestrict571 // && isLvalue <= other.isLvalue572 && isAtomic == other.isAtomic;573 }574 575 inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) {576 return operator!=( other ) && operator<=( other );577 }578 579 inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) {580 return operator!=( other ) && operator>=( other );581 }582 583 571 std::ostream & operator<<( std::ostream & out, const Type * type ); 584 572
Note: See TracChangeset
for help on using the changeset viewer.