Changeset 6e8bd43 for src/Parser


Ignore:
Timestamp:
Mar 16, 2017, 7:41:45 AM (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:
64b6913, 68fe077a
Parents:
905eca1
Message:

cleanup interface to qualifiers/specifiers

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 22:31:36 2017
    13 // Update Count     : 983
     12// Last Modified On : Wed Mar 15 23:36:49 2017
     13// Update Count     : 997
    1414//
    1515
     
    3333
    3434// These must remain in the same order as the corresponding DeclarationNode enumerations.
    35 const char * DeclarationNode::storageClassNames[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };
    36 const char * DeclarationNode::funcSpecifierNames[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };
     35const char * DeclarationNode::StorageClasses::Names[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };
     36const char * DeclarationNode::FuncSpecifiers::Names[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };
    3737const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" };
    3838const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" };
     
    115115}
    116116
    117 void DeclarationNode::print_StorageClass( std::ostream & output, StorageClasses storageClasses ) {
    118         if ( storageClasses.val != 0 ) {                                        // storage classes ?
    119                 for ( unsigned int i = 0; i < DeclarationNode::NumStorageClass; i += 1 ) {
    120                         if ( storageClasses[i] ) {
    121                                 output << DeclarationNode::storageClassNames[i] << ' ';
    122                         } // if
    123                 } // for
    124         } // if
    125 } // print_StorageClass
    126 
    127 void DeclarationNode::print_FuncSpec( std::ostream & output, DeclarationNode::FuncSpecifiers funcSpec ) {
    128         if ( funcSpec.val != 0 ) {                                                      // function specifiers ?
    129                 for ( unsigned int i = 0; i < DeclarationNode::NumFuncSpecifier; i += 1 ) {
    130                         if ( funcSpec[i] ) {
    131                                 output << DeclarationNode::funcSpecifierNames[i] << ' ';
    132                         } // if
    133                 } // for
    134         } // if
    135 } // print_FuncSpec
    136 
    137117void DeclarationNode::print( std::ostream &os, int indent ) const {
    138118        os << string( indent, ' ' );
     
    147127        } // if
    148128
    149         print_StorageClass( os, storageClasses );
    150         print_FuncSpec( os, funcSpecs );
     129        storageClasses.print( os );
     130        funcSpecs.print( os );
    151131
    152132        if ( type ) {
     
    461441                for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates
    462442                        if ( qsrc[i] && qdst[i] ) {
    463                                 appendError( error, string( "duplicate " ) + Type::QualifierNames[i] );
     443                                appendError( error, string( "duplicate " ) + Type::Qualifiers::Names[i] );
    464444                        } // if
    465445                } // for
     
    471451                for ( unsigned int i = 0; i < NumFuncSpecifier; i += 1 ) { // find duplicates
    472452                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
    473                                 appendError( error, string( "duplicate " ) + DeclarationNode::funcSpecifierNames[i] );
     453                                appendError( error, string( "duplicate " ) + FuncSpecifiers::Names[i] );
    474454                        } // if
    475455                } // for
    476456        } // if
    477457
    478         if ( storageClasses.val != 0 && src->storageClasses.val != 0 ) { // any reason to check ?
     458        if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ?
    479459                if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ?
    480460                        for ( unsigned int i = 0; i < NumStorageClass; i += 1 ) { // find duplicates
    481461                                if ( storageClasses[i] && src->storageClasses[i] ) {
    482                                         appendError( error, string( "duplicate " ) + storageClassNames[i] );
     462                                        appendError( error, string( "duplicate " ) + StorageClasses::Names[i] );
    483463                                } // if
    484464                        } // for
    485465                        // src is the new item being added and has a single bit
    486466                } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ?
    487                         appendError( error, string( "conflicting " ) + storageClassNames[ffs( storageClasses.val ) - 1] +
    488                                                  " & " + storageClassNames[ffs( src->storageClasses.val ) - 1] );
     467                        appendError( error, string( "conflicting " ) + StorageClasses::Names[ffs( storageClasses.val ) - 1] +
     468                                                 " & " + StorageClasses::Names[ffs( src->storageClasses.val ) - 1] );
    489469                        src->storageClasses.val = 0;                            // FIX to preserve invariant of one basic storage specifier
    490470                } // if
  • src/Parser/ParseNode.h

    r905eca1 r6e8bd43  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 22:17:50 2017
    13 // Update Count     : 762
     12// Last Modified On : Wed Mar 15 23:31:02 2017
     13// Update Count     : 770
    1414//
    1515
     
    205205        enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 };
    206206        union StorageClasses {
     207                static const char * Names[];
    207208                unsigned int val;
    208209                struct {
     
    213214                        bool is_threadlocal : 1;
    214215                };
     216
    215217                StorageClasses() : val( 0 ) {}
    216218                StorageClasses( unsigned int val ) : val( val ) {}
    217219                bool operator[]( unsigned int i ) const { return val & (1 << i); }
     220                bool any() const { return val != 0; }
     221                void print( std::ostream & os ) const {
     222                        if ( (*this).any() ) {                                          // any storage classes ?
     223                                for ( unsigned int i = 0; i < NumStorageClass; i += 1 ) {
     224                                        if ( (*this)[i] ) {
     225                                                os << StorageClasses::Names[i] << ' ';
     226                                        } // if
     227                                } // for
     228                        } // if
     229                }
    218230        }; // StorageClasses
    219231
    220232        enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 };
    221233        union FuncSpecifiers {
     234                static const char * Names[];
    222235                unsigned int val;
    223236                struct {
     
    229242                FuncSpecifiers( unsigned int val ) : val( val ) {}
    230243                bool operator[]( unsigned int i ) const { return val & (1 << i); }
     244                bool any() const { return val != 0; }
     245                void print( std::ostream & os ) const {
     246                        if ( (*this).any() ) {                                          // any function specifiers ?
     247                                for ( unsigned int i = 0; i < NumFuncSpecifier; i += 1 ) {
     248                                        if ( (*this)[i] ) {
     249                                                os << FuncSpecifiers::Names[i] << ' ';
     250                                        } // if
     251                                } // for
     252                        } // if
     253                }
    231254        }; // FuncSpecifiers
    232255
     
    239262        enum BuiltinType { Valist, Zero, One, NoBuiltinType };
    240263
    241         static const char * storageClassNames[];
    242         static const char * funcSpecifierNames[];
    243264        static const char * basicTypeNames[];
    244265        static const char * complexTypeNames[];
     
    348369
    349370        StorageClasses storageClasses;
    350         static void print_StorageClass( std::ostream & output, StorageClasses storageClasses );
    351 
    352371        FuncSpecifiers funcSpecs;
    353         static void print_FuncSpec( std::ostream & output, FuncSpecifiers funcSpecs );
    354372
    355373        ExpressionNode * bitfieldWidth;
  • src/Parser/TypeData.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 22:22:29 2017
    13 // Update Count     : 555
     12// Last Modified On : Wed Mar 15 22:53:04 2017
     13// Update Count     : 557
    1414//
    1515
     
    227227void TypeData::print( ostream &os, int indent ) const {
    228228        for ( int i = 0; i < Type::NumTypeQualifier; i += 1 ) {
    229                 if ( qualifiers[i] ) os << Type::QualifierNames[ i ] << ' ';
     229                if ( qualifiers[i] ) os << Type::Qualifiers::Names[ i ] << ' ';
    230230        } // for
    231231
Note: See TracChangeset for help on using the changeset viewer.