Changeset 6f95000 for src/Parser


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

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

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rd6d747d r6f95000  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 09:10:57 2017
    13 // Update Count     : 1007
     12// Last Modified On : Thu Mar 16 17:16:31 2017
     13// Update Count     : 1014
    1414//
    1515
     
    1919#include <algorithm>
    2020#include <cassert>
    21 #include <strings.h>                                                                    // ffs
    2221
    2322#include "TypeData.h"
     
    243242
    244243DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     244        assert( name );
    245245        DeclarationNode * newnode = new DeclarationNode;
    246246        newnode->type = new TypeData( TypeData::Aggregate );
    247247        newnode->type->aggregate.kind = kind;
    248         if ( name ) {
    249                 newnode->type->aggregate.name = name;
    250         } else {                                                                                        // anonymous aggregate ?
    251                 newnode->type->aggregate.name = new string( anonymous.newName() );
    252         } // if
     248        newnode->type->aggregate.name = name;
    253249        newnode->type->aggregate.actuals = actuals;
    254250        newnode->type->aggregate.fields = fields;
     
    258254
    259255DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants, bool body ) {
     256        assert( name );
    260257        DeclarationNode * newnode = new DeclarationNode;
    261258        newnode->type = new TypeData( TypeData::Enum );
    262         if ( name ) {
    263                 newnode->type->enumeration.name = name;
    264         } else {                                                                                        // anonymous aggregate ?
    265                 newnode->type->enumeration.name = new string( anonymous.newName() );
    266         } // if
     259        newnode->type->enumeration.name = name;
    267260        newnode->type->enumeration.constants = constants;
    268261        newnode->type->enumeration.body = body;
     
    436429        const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    437430
    438         if ( (qsrc.val & qdst.val) != 0 ) {                                     // duplicates ?
     431        if ( (qsrc & qdst).any() ) {                                            // duplicates ?
    439432                for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates
    440433                        if ( qsrc[i] && qdst[i] ) {
     
    446439
    447440void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
    448         if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) {      // duplicates ?
     441        if ( (funcSpecs & src->funcSpecs).any() ) {                     // duplicates ?
    449442                for ( unsigned int i = 0; i < Type::NumFuncSpecifier; i += 1 ) { // find duplicates
    450443                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
     
    455448
    456449        if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ?
    457                 if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ?
     450                if ( (storageClasses & src->storageClasses ).any() ) { // duplicates ?
    458451                        for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates
    459452                                if ( storageClasses[i] && src->storageClasses[i] ) {
     
    463456                        // src is the new item being added and has a single bit
    464457                } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ?
    465                         appendError( error, string( "conflicting " ) + Type::StorageClasses::Names[ffs( storageClasses.val ) - 1] +
    466                                                  " & " + Type::StorageClasses::Names[ffs( src->storageClasses.val ) - 1] );
    467                         src->storageClasses.val = 0;                            // FIX to preserve invariant of one basic storage specifier
     458                        appendError( error, string( "conflicting " ) + Type::StorageClasses::Names[storageClasses.ffs()] +
     459                                                 " & " + Type::StorageClasses::Names[src->storageClasses.ffs()] );
     460                        src->storageClasses.reset();                            // FIX to preserve invariant of one basic storage specifier
    468461                } // if
    469462        } // if
     
    473466
    474467DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
    475         funcSpecs.val |= q->funcSpecs.val;
    476         storageClasses.val |= q->storageClasses.val;
     468        funcSpecs |= q->funcSpecs;
     469        storageClasses |= q->storageClasses;
    477470
    478471        for ( Attribute *attr: reverseIterate( q->attributes ) ) {
     
    497490                src = nullptr;
    498491        } else {
    499                 dst->qualifiers += src->qualifiers;
     492                dst->qualifiers |= src->qualifiers;
    500493        } // if
    501494} // addQualifiersToType
     
    555548                switch ( dst->kind ) {
    556549                  case TypeData::Unknown:
    557                         src->qualifiers += dst->qualifiers;
     550                        src->qualifiers |= dst->qualifiers;
    558551                        dst = src;
    559552                        src = nullptr;
    560553                        break;
    561554                  case TypeData::Basic:
    562                         dst->qualifiers += src->qualifiers;
     555                        dst->qualifiers |= src->qualifiers;
    563556                        if ( src->kind != TypeData::Unknown ) {
    564557                                assert( src->kind == TypeData::Basic );
     
    596589                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    597590                                } // if
    598                                 dst->base->qualifiers += src->qualifiers;
     591                                dst->base->qualifiers |= src->qualifiers;
    599592                                src = nullptr;
    600593                                break;
     
    628621                                                type->aggInst.hoistType = o->type->enumeration.body;
    629622                                        } // if
    630                                         type->qualifiers += o->type->qualifiers;
     623                                        type->qualifiers |= o->type->qualifiers;
    631624                                } else {
    632625                                        type = o->type;
     
    784777                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
    785778                                } // if
    786                                 p->type->base->qualifiers += type->qualifiers;
     779                                p->type->base->qualifiers |= type->qualifiers;
    787780                                break;
    788781
     
    821814                                lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
    822815                        } // if
    823                         lastArray->base->qualifiers += type->qualifiers;
     816                        lastArray->base->qualifiers |= type->qualifiers;
    824817                        break;
    825818                  default:
  • src/Parser/parser.yy

    rd6d747d r6f95000  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:36:17 2017
    13 // Update Count     : 2310
     12// Last Modified On : Thu Mar 16 12:57:03 2017
     13// Update Count     : 2316
    1414//
    1515
     
    16081608aggregate_type:                                                                                 // struct, union
    16091609        aggregate_key attribute_list_opt '{' field_declaration_list '}'
    1610                 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $4, true )->addQualifiers( $2 ); }
     1610                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    16111611        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    16121612                { typedefTable.makeTypedef( *$3 ); }
     
    16141614                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    16151615        | aggregate_key attribute_list_opt '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    1616                 { $$ = DeclarationNode::newAggregate( $1, nullptr, $4, $7, false )->addQualifiers( $2 ); }
     1616                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    16171617        | aggregate_type_nobody
    16181618        ;
     
    16841684        // empty
    16851685                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
    1686         // '@' // empty
    1687         //      { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
     1686        // '@'
     1687        //      { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name
    16881688        | bit_subrange_size                                                                     // no field name
    16891689                { $$ = DeclarationNode::newBitfield( $1 ); }
     
    17111711enum_type:                                                                                              // enum
    17121712        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    1713                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     1713                { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
    17141714        | ENUM attribute_list_opt no_attr_identifier_or_type_name
    17151715                { typedefTable.makeTypedef( *$3 ); }
Note: See TracChangeset for help on using the changeset viewer.