Changeset 738e304


Ignore:
Timestamp:
Mar 15, 2017, 10:46:40 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:
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)
Message:

merge qualifier types and use the one in Type

Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rf2e40a9f r738e304  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 14 22:42:54 2017
    13 // Update Count     : 974
     12// Last Modified On : Wed Mar 15 22:31:36 2017
     13// Update Count     : 983
    1414//
    1515
     
    3535const char * DeclarationNode::storageClassNames[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };
    3636const char * DeclarationNode::funcSpecifierNames[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };
    37 const char * DeclarationNode::typeQualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };
    3837const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" };
    3938const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" };
     
    214213} // DeclarationNode::newFuncSpecifier
    215214
    216 DeclarationNode * DeclarationNode::newTypeQualifier( TypeQualifiers tq ) {
     215DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) {
    217216        DeclarationNode * newnode = new DeclarationNode;
    218217        newnode->type = new TypeData();
    219         newnode->type->typeQualifiers = tq;
     218        newnode->type->qualifiers = tq;
    220219        return newnode;
    221220} // DeclarationNode::newQualifier
     
    457456
    458457void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
    459         const TypeQualifiers qsrc = src->typeQualifiers, qdst = dst->typeQualifiers; // optimization
     458        const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    460459
    461460        if ( (qsrc.val & qdst.val) != 0 ) {                                     // duplicates ?
    462                 for ( unsigned int i = 0; i < NumTypeQualifier; i += 1 ) { // find duplicates
     461                for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates
    463462                        if ( qsrc[i] && qdst[i] ) {
    464                                 appendError( error, string( "duplicate " ) + DeclarationNode::typeQualifierNames[i] );
     463                                appendError( error, string( "duplicate " ) + Type::QualifierNames[i] );
    465464                        } // if
    466465                } // for
     
    469468
    470469void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
    471         if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) {                // duplicates ?
     470        if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) {      // duplicates ?
    472471                for ( unsigned int i = 0; i < NumFuncSpecifier; i += 1 ) { // find duplicates
    473472                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
     
    496495
    497496DeclarationNode * 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;
    500499
    501500        for ( Attribute *attr: reverseIterate( q->attributes ) ) {
     
    520519                src = nullptr;
    521520        } else {
    522                 dst->typeQualifiers.val |= src->typeQualifiers.val;
     521                dst->qualifiers += src->qualifiers;
    523522        } // if
    524523} // addQualifiersToType
     
    578577                switch ( dst->kind ) {
    579578                  case TypeData::Unknown:
    580                         src->typeQualifiers.val |= dst->typeQualifiers.val;
     579                        src->qualifiers += dst->qualifiers;
    581580                        dst = src;
    582581                        src = nullptr;
    583582                        break;
    584583                  case TypeData::Basic:
    585                         dst->typeQualifiers.val |= src->typeQualifiers.val;
     584                        dst->qualifiers += src->qualifiers;
    586585                        if ( src->kind != TypeData::Unknown ) {
    587586                                assert( src->kind == TypeData::Basic );
     
    619618                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    620619                                } // if
    621                                 dst->base->typeQualifiers.val |= src->typeQualifiers.val;
     620                                dst->base->qualifiers += src->qualifiers;
    622621                                src = nullptr;
    623622                                break;
     
    651650                                                type->aggInst.hoistType = o->type->enumeration.body;
    652651                                        } // if
    653                                         type->typeQualifiers.val |= o->type->typeQualifiers.val;
     652                                        type->qualifiers += o->type->qualifiers;
    654653                                } else {
    655654                                        type = o->type;
     
    807806                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
    808807                                } // if
    809                                 p->type->base->typeQualifiers.val |= type->typeQualifiers.val;
     808                                p->type->base->qualifiers += type->qualifiers;
    810809                                break;
    811810
     
    832831
    833832DeclarationNode * 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;
    858854}
    859855
  • src/Parser/ParseNode.h

    rf2e40a9f r738e304  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 14 22:41:37 2017
    13 // Update Count     : 758
     12// Last Modified On : Wed Mar 15 22:17:50 2017
     13// Update Count     : 762
    1414//
    1515
     
    231231        }; // FuncSpecifiers
    232232
    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         }; // TypeQualifiers
    248 
    249233        enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType };
    250234        enum ComplexType { Complex, Imaginary, NoComplexType };
     
    257241        static const char * storageClassNames[];
    258242        static const char * funcSpecifierNames[];
    259         static const char * typeQualifierNames[];
    260243        static const char * basicTypeNames[];
    261244        static const char * complexTypeNames[];
     
    268251        static DeclarationNode * newStorageClass( StorageClasses );
    269252        static DeclarationNode * newFuncSpecifier( FuncSpecifiers );
    270         static DeclarationNode * newTypeQualifier( TypeQualifiers );
     253        static DeclarationNode * newTypeQualifier( Type::Qualifiers );
    271254        static DeclarationNode * newBasicType( BasicType );
    272255        static DeclarationNode * newComplexType( ComplexType );
  • src/Parser/TypeData.cc

    rf2e40a9f r738e304  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 14 22:43:20 2017
    13 // Update Count     : 549
     12// Last Modified On : Wed Mar 15 22:22:29 2017
     13// Update Count     : 555
    1414//
    1515
     
    157157TypeData * TypeData::clone() const {
    158158        TypeData * newtype = new TypeData( kind );
    159         newtype->typeQualifiers = typeQualifiers;
     159        newtype->qualifiers = qualifiers;
    160160        newtype->base = maybeClone( base );
    161161        newtype->forall = maybeClone( forall );
     
    226226
    227227void 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 ] << ' ';
    230230        } // for
    231231
     
    493493
    494494Type::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;
    502496} // buildQualifiers
    503497
  • src/Parser/TypeData.h

    rf2e40a9f r738e304  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 14 16:51:26 2017
    13 // Update Count     : 181
     12// Last Modified On : Wed Mar 15 22:10:23 2017
     13// Update Count     : 183
    1414//
    1515
     
    7575        DeclarationNode::BuiltinType builtintype = DeclarationNode::NoBuiltinType;
    7676
    77         DeclarationNode::TypeQualifiers typeQualifiers;
     77        Type::Qualifiers qualifiers;
    7878        DeclarationNode * forall;
    7979
  • src/Parser/parser.yy

    rf2e40a9f r738e304  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar  9 21:40:20 2017
    13 // Update Count     : 2292
     12// Last Modified On : Wed Mar 15 22:06:22 2017
     13// Update Count     : 2308
    1414//
    1515
     
    437437argument_expression:
    438438        // empty
    439                 { $$ = nullptr; }                                                               // use default argument
     439                { $$ = nullptr; }
     440        // | '@'                                                                                                // use default argument
     441        //      { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); }
    440442        | assignment_expression
    441443        ;
     
    14041406type_qualifier_name:
    14051407        CONST
    1406                 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Const ); }
     1408                { $$ = DeclarationNode::newTypeQualifier( Type::Const ); }
    14071409        | RESTRICT
    1408                 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Restrict ); }
     1410                { $$ = DeclarationNode::newTypeQualifier( Type::Restrict ); }
    14091411        | VOLATILE
    1410                 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Volatile ); }
     1412                { $$ = DeclarationNode::newTypeQualifier( Type::Volatile ); }
    14111413        | LVALUE                                                                                        // CFA
    1412                 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Lvalue ); }
     1414                { $$ = DeclarationNode::newTypeQualifier( Type::Lvalue ); }
    14131415        | MUTEX
    1414                 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Mutex ); }
     1416                { $$ = DeclarationNode::newTypeQualifier( Type::Mutex ); }
    14151417        | ATOMIC
    1416                 { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Atomic ); }
     1418                { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); }
    14171419        | FORALL '('
    14181420                {
     
    16821684        // empty
    16831685                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
     1686        // '@' // empty
     1687        //      { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
    16841688        | bit_subrange_size                                                                     // no field name
    16851689                { $$ = DeclarationNode::newBitfield( $1 ); }
Note: See TracChangeset for help on using the changeset viewer.