Changeset 47498bd for src/Parser


Ignore:
Timestamp:
Jun 19, 2018, 2:11:38 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
9a7a3b6
Parents:
704d11e
Message:

Add nodes for global scope type

Location:
src/Parser
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r704d11e r47498bd  
    253253        return newnode;
    254254} // DeclarationNode::newFromTypedef
     255
     256DeclarationNode * DeclarationNode::newFromGlobalScope() {
     257        DeclarationNode * newnode = new DeclarationNode;
     258        newnode->type = new TypeData( TypeData::GlobalScope );
     259        return newnode;
     260}
    255261
    256262DeclarationNode * DeclarationNode::newQualifiedType( DeclarationNode * parent, DeclarationNode * child) {
     
    9981004                try {
    9991005                        Declaration * decl = cur->build();
    1000                         if ( decl ) {
    1001                                 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    1002                                         dwt->location = cur->location;
    1003                                         * out++ = dwt;
    1004                                 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    1005                                         StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
    1006                                         auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1007                                         obj->location = cur->location;
    1008                                         * out++ = obj;
    1009                                         delete agg;
    1010                                 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    1011                                         UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
    1012                                         auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1013                                         obj->location = cur->location;
    1014                                         * out++ = obj;
    1015                                 } // if
     1006                        assert( decl );
     1007                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     1008                                dwt->location = cur->location;
     1009                                * out++ = dwt;
     1010                        } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     1011                                // xxx - this might be where anonymous struct members are added - should be conditional on struct name
     1012                                StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
     1013                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1014                                obj->location = cur->location;
     1015                                * out++ = obj;
     1016                                delete agg;
     1017                        } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     1018                                UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
     1019                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1020                                obj->location = cur->location;
     1021                                * out++ = obj;
    10161022                        } // if
    10171023                } catch( SemanticErrorException &e ) {
  • src/Parser/ParseNode.h

    r704d11e r47498bd  
    231231        static DeclarationNode * newForall( DeclarationNode * );
    232232        static DeclarationNode * newFromTypedef( const std::string * );
     233        static DeclarationNode * newFromGlobalScope();
    233234        static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * );
    234235        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
  • src/Parser/TypeData.cc

    r704d11e r47498bd  
    3737          case Reference:
    3838          case EnumConstant:
     39          case GlobalScope:
    3940                // nothing else to initialize
    4041                break;
     
    112113          case Reference:
    113114          case EnumConstant:
     115          case GlobalScope:
    114116                // nothing to destroy
    115117                break;
     
    180182          case Pointer:
    181183          case Reference:
     184          case GlobalScope:
    182185                // nothing else to copy
    183186                break;
  • src/Parser/TypeData.h

    r704d11e r47498bd  
    2727struct TypeData {
    2828        enum Kind { Basic, Pointer, Array, Reference, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic,
    29                                 SymbolicInst, Tuple, Typeof, Builtin, Unknown };
     29                                SymbolicInst, Tuple, Typeof, Builtin, GlobalScope, Unknown };
    3030
    3131        struct Aggregate_t {
     
    8888        DeclarationNode * forall;
    8989
    90         // Basic_t basic;
    9190        Aggregate_t aggregate;
    9291        AggInst_t aggInst;
    9392        Array_t array;
    9493        Enumeration_t enumeration;
    95         // Variable_t variable;
    9694        Function_t function;
    9795        Symbolic_t symbolic;
  • src/Parser/parser.yy

    r704d11e r47498bd  
    17921792                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17931793        | '.' TYPEDEFname
    1794                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1794                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }
    17951795        | type_name '.' TYPEDEFname
    17961796                { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }
    17971797        | typegen_name
    17981798        | '.' typegen_name
    1799                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     1799                { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }
    18001800        | type_name '.' typegen_name
    18011801                { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }
Note: See TracChangeset for help on using the changeset viewer.