Changeset d6d747d


Ignore:
Timestamp:
Mar 16, 2017, 12:17:46 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:
1fbab5a, 6f95000
Parents:
fb04321
Message:

more cleanup for bit-field type usage

Location:
src/SynTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Type.cc

    rfb04321 rd6d747d  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:32:44 2017
    13 // Update Count     : 22
     12// Last Modified On : Thu Mar 16 10:25:06 2017
     13// Update Count     : 23
    1414//
    1515
     
    7676        } // if
    7777       
    78         tq.print( os, indent );
     78        tq.print( os );
    7979}
    8080
  • src/SynTree/Type.h

    rfb04321 rd6d747d  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:28:02 2017
    13 // Update Count     : 91
     12// Last Modified On : Thu Mar 16 12:11:50 2017
     13// Update Count     : 116
    1414//
    1515
     
    2424class Type : public BaseSyntaxNode {
    2525  public:
     26        #define CommonBF( N ) \
     27                bool operator[]( unsigned int i ) const { return val & (1 << i); } \
     28                bool any() const { return val != 0; } \
     29                static const char * Names[]; \
     30                void print( std::ostream & os ) const { \
     31                        if ( (*this).any() ) { \
     32                                for ( unsigned int i = 0; i < N; i += 1 ) { \
     33                                        if ( (*this)[i] ) { \
     34                                                os << Names[i] << ' '; \
     35                                        } \
     36                                } \
     37                        } \
     38                }
     39
    2640        // enum must remain in the same order as the corresponding bit fields.
    2741
    2842        enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 };
    2943        union FuncSpecifiers {
    30                 static const char * Names[];
    3144                unsigned int val;
    3245                struct {
     
    3750                FuncSpecifiers() : val( 0 ) {}
    3851                FuncSpecifiers( unsigned int val ) : val( val ) {}
    39                 bool operator[]( unsigned int i ) const { return val & (1 << i); }
    40                 bool any() const { return val != 0; }
    41                 void print( std::ostream & os ) const {
    42                         if ( (*this).any() ) {                                          // any function specifiers ?
    43                                 for ( unsigned int i = 0; i < NumFuncSpecifier; i += 1 ) {
    44                                         if ( (*this)[i] ) {
    45                                                 os << FuncSpecifiers::Names[i] << ' ';
    46                                         } // if
    47                                 } // for
    48                         } // if
    49                 }
     52                CommonBF( NumFuncSpecifier )
    5053        }; // FuncSpecifiers
    5154
    5255        enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 };
    5356        union StorageClasses {
    54                 static const char * Names[];
    5557                unsigned int val;
    5658                struct {
     
    6466                StorageClasses() : val( 0 ) {}
    6567                StorageClasses( unsigned int val ) : val( val ) {}
    66                 bool operator[]( unsigned int i ) const { return val & (1 << i); }
    67                 bool any() const { return val != 0; }
    68                 void print( std::ostream & os ) const {
    69                         if ( (*this).any() ) {                                          // any storage classes ?
    70                                 for ( unsigned int i = 0; i < NumStorageClass; i += 1 ) {
    71                                         if ( (*this)[i] ) {
    72                                                 os << StorageClasses::Names[i] << ' ';
    73                                         } // if
    74                                 } // for
    75                         } // if
    76                 }
     68                CommonBF( NumStorageClass )
    7769        }; // StorageClasses
    7870
    7971        enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };
    8072        union Qualifiers {
    81                 static const char * Names[];
    8273                enum { Mask = ~(Restrict | Lvalue) };
    8374                unsigned int val;
     
    9384                Qualifiers() : val( 0 ) {}
    9485                Qualifiers( unsigned int val ) : val( val ) {}
    95                 bool operator[]( unsigned int i ) const { return val & (1 << i); }
    96                 bool any() const { return val != 0; }
    97                 bool operator==( const Qualifiers other ) const {
     86                bool operator==( Qualifiers other ) const {
    9887                        return (val & Mask) == (other.val & Mask);
    9988                }
    100                 bool operator!=( const Qualifiers other ) const {
     89                bool operator!=( Qualifiers other ) const {
    10190                        return (val & Mask) != (other.val & Mask);
    10291                }
    103                 bool operator<=( const Qualifiers other ) const {
     92                bool operator<=( Qualifiers other ) const {
    10493                        return isConst <= other.isConst && isVolatile <= other.isVolatile &&
    10594                                isMutex == other.isMutex && isAtomic == other.isAtomic;
    10695                }
    107                 bool operator>=( const Qualifiers other ) const {
     96                bool operator>=( Qualifiers other ) const {
    10897                        return isConst >= other.isConst && isVolatile >= other.isVolatile &&
    10998                                isMutex == other.isMutex && isAtomic == other.isAtomic;
    11099                }
    111                 bool operator<( const Qualifiers other ) const {
     100                bool operator<( Qualifiers other ) const {
    112101                        return *this != other && *this <= other;
    113102                }
    114                 bool operator>( const Qualifiers other ) const {
     103                bool operator>( Qualifiers other ) const {
    115104                        return *this != other && *this >= other;
    116105                }
    117                 Qualifiers operator&=( const Type::Qualifiers other ) {
     106                Qualifiers operator&=( Type::Qualifiers other ) {
    118107                        val &= other.val; return *this;
    119108                }
    120                 Qualifiers operator+=( const Qualifiers other ) {
     109                Qualifiers operator+=( Qualifiers other ) {
    121110                        val |= other.val; return *this;
    122111                }
    123                 Qualifiers operator-=( const Qualifiers other ) {
     112                Qualifiers operator-=( Qualifiers other ) {
    124113                        val &= ~other.val; return *this;
    125114                }
    126                 Qualifiers operator+( const Qualifiers other ) const {
     115                Qualifiers operator+( Qualifiers other ) const {
    127116                        Qualifiers q = other;
    128117                        q += *this;
    129118                        return q;
    130119                }
    131                 void print( std::ostream & os, int indent = 0 ) const {
    132                         if ( (*this).any() ) {                                          // any type qualifiers ?
    133                                 for ( unsigned int i = 0; i < NumTypeQualifier; i += 1 ) {
    134                                         if ( (*this)[i] ) {
    135                                                 os << Names[i] << ' ';
    136                                         } // if
    137                                 } // for
    138                         } // if
    139                 }
     120                CommonBF( NumTypeQualifier )
    140121        }; // Qualifiers
    141122
Note: See TracChangeset for help on using the changeset viewer.