Changeset bf4ac09


Ignore:
Timestamp:
Mar 15, 2017, 9:25:42 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

change type of Qualifiers to bit fields

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    r572547c rbf4ac09  
    1010// Created On       : Sun May 17 21:53:34 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  6 23:33:01 2017
    13 // Update Count     : 4
     12// Last Modified On : Tue Mar 14 23:13:28 2017
     13// Update Count     : 7
    1414//
    1515
     
    5858                        assert( type );
    5959                        Type * castType = type->clone();
    60                         castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false);
     60//                      castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false);
     61                        castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
    6162                        castType->set_isLvalue( true ); // xxx - might not need this
    6263                        dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
  • src/SynTree/Type.cc

    r572547c rbf4ac09  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 11:26:24 2017
    13 // Update Count     : 12
     12// Last Modified On : Wed Mar 15 21:22:16 2017
     13// Update Count     : 15
    1414//
    1515
     
    5959}
    6060
    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 }
     61const char * Type::QualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };
    7862
    7963void Type::print( std::ostream &os, int indent ) const {
  • src/SynTree/Type.h

    r572547c rbf4ac09  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  1 09:11:45 2017
    13 // Update Count     : 41
     12// Last Modified On : Wed Mar 15 21:23:08 2017
     13// Update Count     : 84
    1414//
    1515
     
    2424class Type : public BaseSyntaxNode {
    2525  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
    49112
    50113        Type( const Qualifiers &tq, const std::list< Attribute * > & attributes );
     
    506569};
    507570
    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.isConst
    545                 && isVolatile == other.isVolatile
    546 //              && isRestrict == other.isRestrict
    547 //              && isLvalue == other.isLvalue
    548                 && isAtomic == other.isAtomic;
    549 }
    550 
    551 inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) {
    552         return isConst != other.isConst
    553                 || isVolatile != other.isVolatile
    554 //              || isRestrict != other.isRestrict
    555 //              || isLvalue != other.isLvalue
    556                 || isAtomic != other.isAtomic;
    557 }
    558 
    559 inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) {
    560         return isConst <= other.isConst
    561                 && isVolatile <= other.isVolatile
    562 //              && isRestrict <= other.isRestrict
    563 //              && isLvalue >= other.isLvalue
    564                 && isAtomic == other.isAtomic;
    565 }
    566 
    567 inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) {
    568         return isConst >= other.isConst
    569                 && isVolatile >= other.isVolatile
    570 //              && isRestrict >= other.isRestrict
    571 //              && isLvalue <= other.isLvalue
    572                 && 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 
    583571std::ostream & operator<<( std::ostream & out, const Type * type );
    584572
  • src/Tuples/TupleAssignment.cc

    r572547c rbf4ac09  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  6 23:40:14 2017
    13 // Update Count     : 5
     12// Last Modified On : Wed Mar 15 08:00:44 2017
     13// Update Count     : 6
    1414//
    1515
     
    199199                                Type * type = InitTweak::getPointerBase( castType );
    200200                                assert( type );
    201                                 type->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false);
     201                                type->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
    202202                                type->set_isLvalue( true ); // xxx - might not need this
    203203                                expr = new CastExpr( expr, castType );
  • src/Tuples/TupleExpansion.cc

    r572547c rbf4ac09  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 07:43:56 2017
    13 // Update Count     : 12
     12// Last Modified On : Wed Mar 15 07:58:00 2017
     13// Update Count     : 14
    1414//
    1515
     
    305305        Type * makeTupleType( const std::list< Expression * > & exprs ) {
    306306                // produce the TupleType which aggregates the types of the exprs
    307                 TupleType *tupleType = new TupleType( Type::Qualifiers(true, true, true, true, true, true) );
     307                TupleType *tupleType = new TupleType( Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex ) );
    308308                Type::Qualifiers &qualifiers = tupleType->get_qualifiers();
    309309                for ( Expression * expr : exprs ) {
Note: See TracChangeset for help on using the changeset viewer.