Changeset 6f95000 for src/SynTree


Ignore:
Timestamp:
Mar 16, 2017, 6:14:27 PM (8 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:
395fc37
Parents:
d6d747d
Message:

more cleanup for bit-field type usage and create struct forward for typedef

Location:
src/SynTree
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Type.cc

    rd6d747d r6f95000  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 10:25:06 2017
    13 // Update Count     : 23
     12// Last Modified On : Thu Mar 16 16:25:49 2017
     13// Update Count     : 27
    1414//
    1515
     
    1919#include "Declaration.h"
    2020#include "Attribute.h"
     21#include "InitTweak/InitTweak.h"
    2122#include "Common/utility.h"
    2223
     
    6465const char * Type::Qualifiers::Names[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
    6566
     67Type *Type::stripDeclarator() {
     68        Type * type = this;
     69        while ( Type * at = InitTweak::getPointerBase( type ) ) {
     70                type = at;
     71        }
     72        return type;
     73}
     74
    6675void Type::print( std::ostream &os, int indent ) const {
    6776        if ( ! forall.empty() ) {
  • src/SynTree/Type.h

    rd6d747d r6f95000  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 12:11:50 2017
    13 // Update Count     : 116
     12// Last Modified On : Thu Mar 16 17:44:11 2017
     13// Update Count     : 135
    1414//
    1515
     
    2121#include "SynTree.h"
    2222#include "Visitor.h"
     23#include <strings.h>                                                                    // ffs
    2324
    2425class Type : public BaseSyntaxNode {
    2526  public:
    26         #define CommonBF( N ) \
     27        // Simulate inheritance because union does not allow it.
     28        #define BFCommon( BFType, N ) \
    2729                bool operator[]( unsigned int i ) const { return val & (1 << i); } \
    2830                bool any() const { return val != 0; } \
     31                void reset() { val = 0; } \
     32                int ffs() { return ::ffs( val ) - 1; } \
    2933                static const char * Names[]; \
     34                BFType operator&=( BFType other ) { \
     35                        val &= other.val; return *this; \
     36                } \
     37                BFType operator&( BFType other ) const { \
     38                        BFType q = other; \
     39                        q &= *this; \
     40                        return q; \
     41                } \
     42                BFType operator|=( BFType other ) { \
     43                        val |= other.val; return *this; \
     44                } \
     45                BFType operator|( BFType other ) const { \
     46                        BFType q = other; \
     47                        q |= *this; \
     48                        return q; \
     49                } \
     50                BFType operator-=( BFType other ) { \
     51                        val &= ~other.val; return *this; \
     52                } \
    3053                void print( std::ostream & os ) const { \
    3154                        if ( (*this).any() ) { \
     
    5073                FuncSpecifiers() : val( 0 ) {}
    5174                FuncSpecifiers( unsigned int val ) : val( val ) {}
    52                 CommonBF( NumFuncSpecifier )
     75                bool operator==( FuncSpecifiers other ) const { return val == other.val; }
     76                bool operator!=( FuncSpecifiers other ) const { return val != other.val; }
     77                BFCommon( FuncSpecifiers, NumFuncSpecifier )
    5378        }; // FuncSpecifiers
    5479
     
    6691                StorageClasses() : val( 0 ) {}
    6792                StorageClasses( unsigned int val ) : val( val ) {}
    68                 CommonBF( NumStorageClass )
     93                bool operator==( StorageClasses other ) const { return val == other.val; }
     94                bool operator!=( StorageClasses other ) const { return val != other.val; }
     95                BFCommon( StorageClasses, NumStorageClass )
    6996        }; // StorageClasses
    7097
     
    92119                bool operator<=( Qualifiers other ) const {
    93120                        return isConst <= other.isConst && isVolatile <= other.isVolatile &&
    94                                 isMutex == other.isMutex && isAtomic == other.isAtomic;
     121                                isMutex >= other.isMutex && isAtomic == other.isAtomic;
    95122                }
    96                 bool operator>=( Qualifiers other ) const {
    97                         return isConst >= other.isConst && isVolatile >= other.isVolatile &&
    98                                 isMutex == other.isMutex && isAtomic == other.isAtomic;
    99                 }
    100                 bool operator<( Qualifiers other ) const {
    101                         return *this != other && *this <= other;
    102                 }
    103                 bool operator>( Qualifiers other ) const {
    104                         return *this != other && *this >= other;
    105                 }
    106                 Qualifiers operator&=( Type::Qualifiers other ) {
    107                         val &= other.val; return *this;
    108                 }
    109                 Qualifiers operator+=( Qualifiers other ) {
    110                         val |= other.val; return *this;
    111                 }
    112                 Qualifiers operator-=( Qualifiers other ) {
    113                         val &= ~other.val; return *this;
    114                 }
    115                 Qualifiers operator+( Qualifiers other ) const {
    116                         Qualifiers q = other;
    117                         q += *this;
    118                         return q;
    119                 }
    120                 CommonBF( NumTypeQualifier )
     123                bool operator<( Qualifiers other ) const { return *this != other && *this <= other; }
     124                bool operator>=( Qualifiers other ) const { return ! (*this < other); }
     125                bool operator>( Qualifiers other ) const { return *this != other && *this >= other; }
     126                BFCommon( Qualifiers, NumTypeQualifier )
    121127        }; // Qualifiers
    122128
     
    147153        virtual bool isVoid() const { return size() == 0; }
    148154        virtual Type * getComponent( unsigned i ) { assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i ); return this; }
     155
     156        Type *stripDeclarator();
    149157
    150158        virtual bool isComplete() const { return true; }
  • src/SynTree/TypeSubstitution.cc

    rd6d747d r6f95000  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Apr 26 11:15:29 2016
    13 // Update Count     : 3
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Mar 16 15:54:35 2017
     13// Update Count     : 4
    1414//
    1515
     
    127127                subCount++;
    128128                Type *newtype = i->second->clone();
    129                 newtype->get_qualifiers() += inst->get_qualifiers();
     129                newtype->get_qualifiers() |= inst->get_qualifiers();
    130130                delete inst;
    131131                return newtype;
Note: See TracChangeset for help on using the changeset viewer.