Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r615a096 rfb04321  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 08:46:05 2017
    13 // Update Count     : 1017
     12// Last Modified On : Thu Mar 16 09:10:57 2017
     13// Update Count     : 1007
    1414//
    1515
     
    1919#include <algorithm>
    2020#include <cassert>
     21#include <strings.h>                                                                    // ffs
    2122
    2223#include "TypeData.h"
     
    242243
    243244DeclarationNode * 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         newnode->type->aggregate.name = name;
     248        if ( name ) {
     249                newnode->type->aggregate.name = name;
     250        } else {                                                                                        // anonymous aggregate ?
     251                newnode->type->aggregate.name = new string( anonymous.newName() );
     252        } // if
    249253        newnode->type->aggregate.actuals = actuals;
    250254        newnode->type->aggregate.fields = fields;
     
    254258
    255259DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants, bool body ) {
    256         assert( name );
    257260        DeclarationNode * newnode = new DeclarationNode;
    258261        newnode->type = new TypeData( TypeData::Enum );
    259         newnode->type->enumeration.name = name;
     262        if ( name ) {
     263                newnode->type->enumeration.name = name;
     264        } else {                                                                                        // anonymous aggregate ?
     265                newnode->type->enumeration.name = new string( anonymous.newName() );
     266        } // if
    260267        newnode->type->enumeration.constants = constants;
    261268        newnode->type->enumeration.body = body;
     
    429436        const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    430437
    431         if ( (qsrc & qdst).any() ) {                                            // duplicates ?
     438        if ( (qsrc.val & qdst.val) != 0 ) {                                     // duplicates ?
    432439                for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates
    433440                        if ( qsrc[i] && qdst[i] ) {
    434                                 appendError( error, string( "duplicate " ) + Type::QualifiersNames[i] );
     441                                appendError( error, string( "duplicate " ) + Type::Qualifiers::Names[i] );
    435442                        } // if
    436443                } // for
     
    439446
    440447void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
    441         if ( (funcSpecs & src->funcSpecs).any() ) {                     // duplicates ?
     448        if ( (funcSpecs.val & src->funcSpecs.val) != 0 ) {      // duplicates ?
    442449                for ( unsigned int i = 0; i < Type::NumFuncSpecifier; i += 1 ) { // find duplicates
    443450                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
    444                                 appendError( error, string( "duplicate " ) + Type::FuncSpecifiersNames[i] );
     451                                appendError( error, string( "duplicate " ) + Type::FuncSpecifiers::Names[i] );
    445452                        } // if
    446453                } // for
     
    448455
    449456        if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ?
    450                 if ( (storageClasses & src->storageClasses ).any() ) { // duplicates ?
     457                if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ?
    451458                        for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates
    452459                                if ( storageClasses[i] && src->storageClasses[i] ) {
    453                                         appendError( error, string( "duplicate " ) + Type::StorageClassesNames[i] );
     460                                        appendError( error, string( "duplicate " ) + Type::StorageClasses::Names[i] );
    454461                                } // if
    455462                        } // for
    456463                        // src is the new item being added and has a single bit
    457464                } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ?
    458                         appendError( error, string( "conflicting " ) + Type::StorageClassesNames[storageClasses.ffs()] +
    459                                                  " & " + Type::StorageClassesNames[src->storageClasses.ffs()] );
    460                         src->storageClasses.reset();                            // FIX to preserve invariant of one basic storage specifier
     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
    461468                } // if
    462469        } // if
     
    466473
    467474DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
    468         funcSpecs |= q->funcSpecs;
    469         storageClasses |= q->storageClasses;
     475        funcSpecs.val |= q->funcSpecs.val;
     476        storageClasses.val |= q->storageClasses.val;
    470477
    471478        for ( Attribute *attr: reverseIterate( q->attributes ) ) {
     
    490497                src = nullptr;
    491498        } else {
    492                 dst->qualifiers |= src->qualifiers;
     499                dst->qualifiers += src->qualifiers;
    493500        } // if
    494501} // addQualifiersToType
     
    548555                switch ( dst->kind ) {
    549556                  case TypeData::Unknown:
    550                         src->qualifiers |= dst->qualifiers;
     557                        src->qualifiers += dst->qualifiers;
    551558                        dst = src;
    552559                        src = nullptr;
    553560                        break;
    554561                  case TypeData::Basic:
    555                         dst->qualifiers |= src->qualifiers;
     562                        dst->qualifiers += src->qualifiers;
    556563                        if ( src->kind != TypeData::Unknown ) {
    557564                                assert( src->kind == TypeData::Basic );
     
    589596                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    590597                                } // if
    591                                 dst->base->qualifiers |= src->qualifiers;
     598                                dst->base->qualifiers += src->qualifiers;
    592599                                src = nullptr;
    593600                                break;
     
    621628                                                type->aggInst.hoistType = o->type->enumeration.body;
    622629                                        } // if
    623                                         type->qualifiers |= o->type->qualifiers;
     630                                        type->qualifiers += o->type->qualifiers;
    624631                                } else {
    625632                                        type = o->type;
     
    777784                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
    778785                                } // if
    779                                 p->type->base->qualifiers |= type->qualifiers;
     786                                p->type->base->qualifiers += type->qualifiers;
    780787                                break;
    781788
     
    814821                                lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
    815822                        } // if
    816                         lastArray->base->qualifiers |= type->qualifiers;
     823                        lastArray->base->qualifiers += type->qualifiers;
    817824                        break;
    818825                  default:
Note: See TracChangeset for help on using the changeset viewer.