Changeset 6e8bd43


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
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 13 23:56:59 2017
    13 // Update Count     : 477
     12// Last Modified On : Wed Mar 15 23:31:48 2017
     13// Update Count     : 479
    1414//
    1515
     
    134134
    135135                handleStorageClass( functionDecl );
    136                 DeclarationNode::print_FuncSpec( output, functionDecl->get_funcSpec() );
     136                functionDecl->get_funcSpec().print( output );
    137137
    138138                output << genType( functionDecl->get_functionType(), mangleName( functionDecl ), pretty );
     
    896896        void CodeGenerator::handleStorageClass( DeclarationWithType * decl ) {
    897897                if ( decl->get_storageClasses().val != 0 ) {
    898                         DeclarationNode::print_StorageClass( output, decl->get_storageClasses() );
     898                        decl->get_storageClasses().print( output );
    899899                } // if
    900900        } // CodeGenerator::handleStorageClass
  • 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
  • src/SynTree/FunctionDecl.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 07:54:58 2017
    13 // Update Count     : 68
     12// Last Modified On : Wed Mar 15 23:33:43 2017
     13// Update Count     : 72
    1414//
    1515
     
    6565        printAll( get_attributes(), os, indent );
    6666
    67         DeclarationNode::print_StorageClass( os, get_storageClasses() );
    68         DeclarationNode::print_FuncSpec( os, get_funcSpec() );
     67        get_storageClasses().print( os );
     68        get_funcSpec().print( os );
    6969
    7070        if ( get_type() ) {
     
    9191        // xxx - should printShort print attributes?
    9292
    93         DeclarationNode::print_StorageClass( os, get_storageClasses() );
    94         DeclarationNode::print_FuncSpec( os, get_funcSpec() );
     93        get_storageClasses().print( os );
     94        get_funcSpec().print( os );
    9595
    9696        if ( get_type() ) {
  • src/SynTree/NamedTypeDecl.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 07:39:41 2017
    13 // Update Count     : 10
     12// Last Modified On : Wed Mar 15 23:25:41 2017
     13// Update Count     : 12
    1414//
    1515
     
    3939                os << get_name() << ": ";
    4040        } // if
    41         DeclarationNode::print_StorageClass( os, get_storageClasses() );
     41        get_storageClasses().print( os );
    4242        os << typeString();
    4343        if ( base ) {
     
    6161                os << get_name() << ": ";
    6262        } // if
    63         DeclarationNode::print_StorageClass( os, get_storageClasses() );
     63        get_storageClasses().print( os );
    6464        os << typeString();
    6565        if ( base ) {
  • src/SynTree/ObjectDecl.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar  7 07:55:24 2017
    13 // Update Count     : 54
     12// Last Modified On : Wed Mar 15 23:26:22 2017
     13// Update Count     : 57
    1414//
    1515
     
    4747        printAll( get_attributes(), os, indent );
    4848
    49         DeclarationNode::print_StorageClass( os, get_storageClasses() );
     49        get_storageClasses().print( os );
    5050
    5151        if ( get_type() ) {
     
    8181        // xxx - should printShort print attributes?
    8282
    83         DeclarationNode::print_StorageClass( os, get_storageClasses() );
     83        get_storageClasses().print( os );
    8484
    8585        if ( get_type() ) {
  • src/SynTree/Type.cc

    r905eca1 r6e8bd43  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 21:22:16 2017
    13 // Update Count     : 15
     12// Last Modified On : Wed Mar 15 23:14:35 2017
     13// Update Count     : 19
    1414//
    1515
     
    5959}
    6060
    61 const char * Type::QualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };
     61const char * Type::Qualifiers::Names[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
    6262
    6363void Type::print( std::ostream &os, int indent ) const {
  • src/SynTree/Type.h

    r905eca1 r6e8bd43  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 21:28:09 2017
    13 // Update Count     : 85
     12// Last Modified On : Wed Mar 15 23:28:33 2017
     13// Update Count     : 89
    1414//
    1515
     
    2424class Type : public BaseSyntaxNode {
    2525  public:
    26         static const char * QualifierNames[];
    27 
    2826        enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 };
    2927        union Qualifiers {
     28                static const char * Names[];
    3029                enum { Mask = ~(Restrict | Lvalue) };
    3130                unsigned int val;
     
    3837                        bool isAtomic : 1;
    3938                };
     39
    4040                Qualifiers() : val( 0 ) {}
    4141                Qualifiers( unsigned int val ) : val( val ) {}
     
    8080                                for ( unsigned int i = 0; i < NumTypeQualifier; i += 1 ) {
    8181                                        if ( (*this)[i] ) {
    82                                                 os << QualifierNames[i] << ' ';
     82                                                os << Names[i] << ' ';
    8383                                        } // if
    8484                                } // for
Note: See TracChangeset for help on using the changeset viewer.