Changeset 68fe077a for src/Parser


Ignore:
Timestamp:
Mar 16, 2017, 8:23:42 AM (8 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:
26ba208
Parents:
6e8bd43
git-author:
Peter A. Buhr <pabuhr@…> (03/16/17 08:19:39)
git-committer:
Peter A. Buhr <pabuhr@…> (03/16/17 08:23:42)
Message:

move type StorageClasses? from DeclarationNode? to Type

Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Parser/DeclarationNode.cc

    r6e8bd43 r68fe077a  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 23:36:49 2017
    13 // Update Count     : 997
     12// Last Modified On : Thu Mar 16 07:59:40 2017
     13// Update Count     : 1003
    1414//
    1515
     
    3333
    3434// These must remain in the same order as the corresponding DeclarationNode enumerations.
    35 const char * DeclarationNode::StorageClasses::Names[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };
    3635const char * DeclarationNode::FuncSpecifiers::Names[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };
    3736const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" };
     
    181180
    182181
    183 DeclarationNode * DeclarationNode::newStorageClass( StorageClasses sc ) {
     182DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) {
    184183        DeclarationNode * newnode = new DeclarationNode;
    185184        newnode->storageClasses = sc;
     
    458457        if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ?
    459458                if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ?
    460                         for ( unsigned int i = 0; i < NumStorageClass; i += 1 ) { // find duplicates
     459                        for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates
    461460                                if ( storageClasses[i] && src->storageClasses[i] ) {
    462                                         appendError( error, string( "duplicate " ) + StorageClasses::Names[i] );
     461                                        appendError( error, string( "duplicate " ) + Type::StorageClasses::Names[i] );
    463462                                } // if
    464463                        } // for
    465464                        // src is the new item being added and has a single bit
    466465                } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ?
    467                         appendError( error, string( "conflicting " ) + StorageClasses::Names[ffs( storageClasses.val ) - 1] +
    468                                                  " & " + StorageClasses::Names[ffs( src->storageClasses.val ) - 1] );
     466                        appendError( error, string( "conflicting " ) + Type::StorageClasses::Names[ffs( storageClasses.val ) - 1] +
     467                                                 " & " + Type::StorageClasses::Names[ffs( src->storageClasses.val ) - 1] );
    469468                        src->storageClasses.val = 0;                            // FIX to preserve invariant of one basic storage specifier
    470469                } // if
     
    970969                                } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    971970                                        StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    972                                         auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );
     971                                        auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    973972                                        obj->location = cur->location;
    974973                                        * out++ = obj;
     
    976975                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    977976                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    978                                         auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );
     977                                        auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    979978                                        obj->location = cur->location;
    980979                                        * out++ = obj;
     
    10231022                assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
    10241023                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1025                 TypeDecl * ret = new TypeDecl( *name, DeclarationNode::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
     1024                TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
    10261025                buildList( variable.assertions, ret->get_assertions() );
    10271026                return ret;
  • TabularUnified src/Parser/ParseNode.h

    r6e8bd43 r68fe077a  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 23:31:02 2017
    13 // Update Count     : 770
     12// Last Modified On : Thu Mar 16 07:46:33 2017
     13// Update Count     : 772
    1414//
    1515
     
    201201class DeclarationNode : public ParseNode {
    202202  public:
    203         // These must remain in the same order as the corresponding DeclarationNode names.
    204 
    205         enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 };
    206         union StorageClasses {
    207                 static const char * Names[];
    208                 unsigned int val;
    209                 struct {
    210                         bool is_extern : 1;
    211                         bool is_static : 1;
    212                         bool is_auto : 1;
    213                         bool is_register : 1;
    214                         bool is_threadlocal : 1;
    215                 };
    216 
    217                 StorageClasses() : val( 0 ) {}
    218                 StorageClasses( unsigned int val ) : val( val ) {}
    219                 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                 }
    230         }; // StorageClasses
    231 
    232203        enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 };
    233204        union FuncSpecifiers {
     
    270241        static const char * builtinTypeNames[];
    271242
    272         static DeclarationNode * newStorageClass( StorageClasses );
     243        static DeclarationNode * newStorageClass( Type::StorageClasses );
    273244        static DeclarationNode * newFuncSpecifier( FuncSpecifiers );
    274245        static DeclarationNode * newTypeQualifier( Type::Qualifiers );
     
    368339        TypeData * type;
    369340
    370         StorageClasses storageClasses;
     341        Type::StorageClasses storageClasses;
    371342        FuncSpecifiers funcSpecs;
    372343
  • TabularUnified src/Parser/TypeData.cc

    r6e8bd43 r68fe077a  
    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:53:04 2017
    13 // Update Count     : 557
     12// Last Modified On : Thu Mar 16 07:54:50 2017
     13// Update Count     : 558
    1414//
    1515
     
    398398                        // add dtor:  void ^?{}(T *)
    399399                        FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false );
    400                         dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    401                         td->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) );
     400                        dtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     401                        td->get_assertions().push_front( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) );
    402402
    403403                        // add copy ctor:  void ?{}(T *, T)
    404404                        FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false );
    405                         copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    406                         copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
    407                         td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) );
     405                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     406                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
     407                        td->get_assertions().push_front( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) );
    408408
    409409                        // add default ctor:  void ?{}(T *)
    410410                        FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false );
    411                         ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    412                         td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) );
     411                        ctorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     412                        td->get_assertions().push_front( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) );
    413413
    414414                        // add assignment operator:  T * ?=?(T *, T)
    415415                        FunctionType * assignType = new FunctionType( Type::Qualifiers(), false );
    416                         assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    417                         assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
    418                         assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
    419                         td->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) );
     416                        assignType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     417                        assignType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
     418                        assignType->get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
     419                        td->get_assertions().push_front( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) );
    420420                } // if
    421421        } // for
     
    726726} // buildAggInst
    727727
    728 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClasses scs ) {
     728NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs ) {
    729729        assert( td->kind == TypeData::Symbolic );
    730730        NamedTypeDecl * ret;
     
    778778} // buildTypeof
    779779
    780 Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClasses scs, Expression * bitfieldWidth, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
     780Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
    781781        if ( td->kind == TypeData::Function ) {
    782782                if ( td->function.idList ) {                                    // KR function ?
     
    814814                        break;
    815815                  default:
    816                         ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", DeclarationNode::StorageClasses(), nullptr, DeclarationNode::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );
     816                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, DeclarationNode::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );
    817817                } // switch
    818818        } else {
    819                 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
     819                ft->get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    820820        } // if
    821821        return ft;
  • TabularUnified src/Parser/TypeData.h

    r6e8bd43 r68fe077a  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 22:10:23 2017
    13 // Update Count     : 183
     12// Last Modified On : Thu Mar 16 07:53:41 2017
     13// Update Count     : 184
    1414//
    1515
     
    109109TupleType * buildTuple( const TypeData * );
    110110TypeofType * buildTypeof( const TypeData * );
    111 Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClasses, Expression *, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
     111Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
    112112FunctionType * buildFunction( const TypeData * );
    113113void buildKRFunction( const TypeData::Function_t & function );
  • TabularUnified src/Parser/parser.yy

    r6e8bd43 r68fe077a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 15 22:06:22 2017
    13 // Update Count     : 2308
     12// Last Modified On : Thu Mar 16 08:00:59 2017
     13// Update Count     : 2309
    1414//
    1515
     
    14491449storage_class:
    14501450        EXTERN
    1451                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }
     1451                { $$ = DeclarationNode::newStorageClass( Type::Extern ); }
    14521452        | STATIC
    1453                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Static ); }
     1453                { $$ = DeclarationNode::newStorageClass( Type::Static ); }
    14541454        | AUTO
    1455                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Auto ); }
     1455                { $$ = DeclarationNode::newStorageClass( Type::Auto ); }
    14561456        | REGISTER
    1457                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); }
     1457                { $$ = DeclarationNode::newStorageClass( Type::Register ); }
    14581458        | THREADLOCAL                                                                           // C11
    1459                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); }
     1459                { $$ = DeclarationNode::newStorageClass( Type::Threadlocal ); }
    14601460                // Put function specifiers here to simplify parsing rules, but separate them semantically.
    14611461        | INLINE                                                                                        // C99
Note: See TracChangeset for help on using the changeset viewer.