Ignore:
Timestamp:
Jun 19, 2019, 4:51:14 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c0f9efe
Parents:
17a0ede2
Message:

Convert now handles attributes on types.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r17a0ede2 r1ae47de  
    10751075        }
    10761076
     1077        const ast::Type * visitType( const ast::Type * node, Type * type ) {
     1078                // Some types do this in their constructor so add a check.
     1079                if ( !node->attributes.empty() && type->attributes.empty() ) {
     1080                        type->attributes = get<Attribute>().acceptL( node->attributes );
     1081                }
     1082                this->node = type;
     1083                return nullptr;
     1084        }
     1085
    10771086        const ast::Type * visit( const ast::VoidType * node ) override final {
    1078                 this->node = new VoidType{ cv( node ) };
    1079                 return nullptr;
     1087                return visitType( node, new VoidType{ cv( node ) } );
    10801088        }
    10811089
     
    10861094                        Validate::SizeType = type;
    10871095                }
    1088                 this->node = type;
    1089                 return nullptr;
     1096                return visitType( node, type );
    10901097        }
    10911098
    10921099        const ast::Type * visit( const ast::PointerType * node ) override final {
    1093                 this->node = new PointerType{
     1100                return visitType( node, new PointerType{
    10941101                        cv( node ),
    10951102                        get<Type>().accept1( node->base ),
     
    10971104                        (bool)node->isVarLen,
    10981105                        (bool)node->isStatic
    1099                 };
    1100                 return nullptr;
     1106                } );
    11011107        }
    11021108
    11031109        const ast::Type * visit( const ast::ArrayType * node ) override final {
    1104                 this->node = new ArrayType{
     1110                return visitType( node, new ArrayType{
    11051111                        cv( node ),
    11061112                        get<Type>().accept1( node->base ),
     
    11081114                        (bool)node->isVarLen,
    11091115                        (bool)node->isStatic
    1110                 };
    1111                 return nullptr;
     1116                } );
    11121117        }
    11131118
    11141119        const ast::Type * visit( const ast::ReferenceType * node ) override final {
    1115                 this->node = new ReferenceType{
     1120                return visitType( node, new ReferenceType{
    11161121                        cv( node ),
    11171122                        get<Type>().accept1( node->base )
    1118                 };
    1119                 return nullptr;
     1123                } );
    11201124        }
    11211125
    11221126        const ast::Type * visit( const ast::QualifiedType * node ) override final {
    1123                 this->node = new QualifiedType{
     1127                return visitType( node, new QualifiedType{
    11241128                        cv( node ),
    11251129                        get<Type>().accept1( node->parent ),
    11261130                        get<Type>().accept1( node->child )
    1127                 };
    1128                 return nullptr;
     1131                } );
    11291132        }
    11301133
     
    11371140                ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    11381141                ty->forall = get<TypeDecl>().acceptL( node->forall );
    1139                 this->node = ty;
    1140                 return nullptr;
    1141         }
    1142 
    1143         void postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
     1142                return visitType( node, ty );
     1143        }
     1144
     1145        const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
    11441146                ty->forall = get<TypeDecl>().acceptL( old->forall );
    11451147                ty->parameters = get<Expression>().acceptL( old->params );
    11461148                ty->hoistType = old->hoistType;
     1149                return visitType( old, ty );
    11471150        }
    11481151
     
    11621165                        };
    11631166                }
    1164                 postvisit( node, ty );
    1165                 this->node = ty;
    1166                 return nullptr;
     1167                return postvisit( node, ty );
    11671168        }
    11681169
     
    11821183                        };
    11831184                }
    1184                 postvisit( node, ty );
    1185                 this->node = ty;
    1186                 return nullptr;
     1185                return postvisit( node, ty );
    11871186        }
    11881187
     
    12021201                        };
    12031202                }
    1204                 postvisit( node, ty );
    1205                 this->node = ty;
    1206                 return nullptr;
     1203                return postvisit( node, ty );
    12071204        }
    12081205
     
    12221219                        };
    12231220                }
    1224                 postvisit( node, ty );
    1225                 this->node = ty;
    1226                 return nullptr;
     1221                return postvisit( node, ty );
    12271222        }
    12281223
     
    12441239                        };
    12451240                }
    1246                 postvisit( node, ty );
    1247                 this->node = ty;
    1248                 return nullptr;
     1241                return postvisit( node, ty );
    12491242        }
    12501243
    12511244        const ast::Type * visit( const ast::TupleType * node ) override final {
    1252                 this->node = new TupleType{
     1245                return visitType( node, new TupleType{
    12531246                        cv( node ),
    12541247                        get<Type>().acceptL( node->types )
    12551248                        // members generated by TupleType c'tor
    1256                 };
    1257                 return nullptr;
     1249                } );
    12581250        }
    12591251
    12601252        const ast::Type * visit( const ast::TypeofType * node ) override final {
    1261                 this->node = new TypeofType{
     1253                return visitType( node, new TypeofType{
    12621254                        cv( node ),
    12631255                        get<Expression>().accept1( node->expr ),
    12641256                        (bool)node->kind
    1265                 };
    1266                 return nullptr;
     1257                } );
    12671258        }
    12681259
    12691260        const ast::Type * visit( const ast::VarArgsType * node ) override final {
    1270                 this->node = new VarArgsType{ cv( node ) };
    1271                 return nullptr;
     1261                return visitType( node, new VarArgsType{ cv( node ) } );
    12721262        }
    12731263
    12741264        const ast::Type * visit( const ast::ZeroType * node ) override final {
    1275                 this->node = new ZeroType{ cv( node ) };
    1276                 return nullptr;
     1265                return visitType( node, new ZeroType{ cv( node ) } );
    12771266        }
    12781267
    12791268        const ast::Type * visit( const ast::OneType * node ) override final {
    1280                 this->node = new OneType{ cv( node ) };
    1281                 return nullptr;
    1282         }
    1283 
    1284         const ast::Type * visit( const ast::GlobalScopeType * ) override final {
    1285                 this->node = new GlobalScopeType{};
    1286                 return nullptr;
     1269                return visitType( node, new OneType{ cv( node ) } );
     1270        }
     1271
     1272        const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
     1273                return visitType( node, new GlobalScopeType{} );
    12871274        }
    12881275
     
    24422429        }
    24432430
     2431        void visitType( Type * old, ast::Type * type ) {
     2432                // Some types do this in their constructor so add a check.
     2433                if ( !old->attributes.empty() && type->attributes.empty() ) {
     2434                        type->attributes = GET_ACCEPT_V(attributes, Attribute);
     2435                }
     2436                this->node = type;
     2437        }
     2438
    24442439        virtual void visit( VoidType * old ) override final {
    2445                 this->node = new ast::VoidType{ cv( old ) };
     2440                visitType( old, new ast::VoidType{ cv( old ) } );
    24462441        }
    24472442
     
    24522447                        sizeType = type;
    24532448                }
    2454                 this->node = type;
     2449                visitType( old, type );
    24552450        }
    24562451
    24572452        virtual void visit( PointerType * old ) override final {
    2458                 this->node = new ast::PointerType{
     2453                visitType( old, new ast::PointerType{
    24592454                        GET_ACCEPT_1( base, Type ),
    24602455                        GET_ACCEPT_1( dimension, Expr ),
     
    24622457                        (ast::DimensionFlag)old->isStatic,
    24632458                        cv( old )
    2464                 };
     2459                } );
    24652460        }
    24662461
    24672462        virtual void visit( ArrayType * old ) override final {
    2468                 this->node = new ast::ArrayType{
     2463                visitType( old, new ast::ArrayType{
    24692464                        GET_ACCEPT_1( base, Type ),
    24702465                        GET_ACCEPT_1( dimension, Expr ),
     
    24722467                        (ast::DimensionFlag)old->isStatic,
    24732468                        cv( old )
    2474                 };
     2469                } );
    24752470        }
    24762471
    24772472        virtual void visit( ReferenceType * old ) override final {
    2478                 this->node = new ast::ReferenceType{
     2473                visitType( old, new ast::ReferenceType{
    24792474                        GET_ACCEPT_1( base, Type ),
    24802475                        cv( old )
    2481                 };
     2476                } );
    24822477        }
    24832478
    24842479        virtual void visit( QualifiedType * old ) override final {
    2485                 this->node = new ast::QualifiedType{
     2480                visitType( old, new ast::QualifiedType{
    24862481                        GET_ACCEPT_1( parent, Type ),
    24872482                        GET_ACCEPT_1( child, Type ),
    24882483                        cv( old )
    2489                 };
     2484                } );
    24902485        }
    24912486
     
    24982493                ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    24992494                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    2500                 this->node = ty;
     2495                visitType( old, ty );
    25012496        }
    25022497
     
    25052500                ty->params = GET_ACCEPT_V( parameters, Expr );
    25062501                ty->hoistType = old->hoistType;
     2502                visitType( old, ty );
    25072503        }
    25082504
     
    25232519                }
    25242520                postvisit( old, ty );
    2525                 this->node = ty;
    25262521        }
    25272522
     
    25422537                }
    25432538                postvisit( old, ty );
    2544                 this->node = ty;
    25452539        }
    25462540
     
    25612555                }
    25622556                postvisit( old, ty );
    2563                 this->node = ty;
    25642557        }
    25652558
     
    25802573                }
    25812574                postvisit( old, ty );
    2582                 this->node = ty;
    25832575        }
    25842576
     
    26012593                }
    26022594                postvisit( old, ty );
    2603                 this->node = ty;
    26042595        }
    26052596
    26062597        virtual void visit( TupleType * old ) override final {
    2607                 this->node = new ast::TupleType{
     2598                visitType( old, new ast::TupleType{
    26082599                        GET_ACCEPT_V( types, Type ),
    26092600                        // members generated by TupleType c'tor
    26102601                        cv( old )
    2611                 };
     2602                } );
    26122603        }
    26132604
    26142605        virtual void visit( TypeofType * old ) override final {
    2615                 this->node = new ast::TypeofType{
     2606                visitType( old, new ast::TypeofType{
    26162607                        GET_ACCEPT_1( expr, Expr ),
    26172608                        (ast::TypeofType::Kind)old->is_basetypeof,
    26182609                        cv( old )
    2619                 };
     2610                } );
    26202611        }
    26212612
     
    26252616
    26262617        virtual void visit( VarArgsType * old ) override final {
    2627                 this->node = new ast::VarArgsType{ cv( old ) };
     2618                visitType( old, new ast::VarArgsType{ cv( old ) } );
    26282619        }
    26292620
    26302621        virtual void visit( ZeroType * old ) override final {
    2631                 this->node = new ast::ZeroType{ cv( old ) };
     2622                visitType( old, new ast::ZeroType{ cv( old ) } );
    26322623        }
    26332624
    26342625        virtual void visit( OneType * old ) override final {
    2635                 this->node = new ast::OneType{ cv( old ) };
    2636         }
    2637 
    2638         virtual void visit( GlobalScopeType * ) override final {
    2639                 this->node = new ast::GlobalScopeType{};
     2626                visitType( old, new ast::OneType{ cv( old ) } );
     2627        }
     2628
     2629        virtual void visit( GlobalScopeType * old ) override final {
     2630                visitType( old, new ast::GlobalScopeType{} );
    26402631        }
    26412632
Note: See TracChangeset for help on using the changeset viewer.