Changeset 20de6fb


Ignore:
Timestamp:
May 22, 2019, 1:02:13 PM (5 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
9d23c2d
Parents:
ed5e798
Message:

finished draft past of converting expressions

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    red5e798 r20de6fb  
    525525        }
    526526
     527        Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) {
     528
     529                tgt->location  = src->location;
     530                tgt->env       = convertTypeSubstitution(src->env);
     531                tgt->extension = src->extension;
     532
     533                convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
     534                return tgt;
     535        }
     536
    527537        Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {
    528538
    529                 tgt->location = src->location;
    530 
    531539                tgt->result = get<Type>().accept1(src->result);
    532                 tgt->env    = convertTypeSubstitution(src->env);
    533 
    534                 tgt->extension = src->extension;
    535                 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
    536 
    537                 return tgt;
     540                return visitBaseExpr_skipResultType(src, tgt);
    538541        }
    539542
     
    628631
    629632        const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
    630                 auto expr = visitBaseExpr( node,
     633                auto expr = visitBaseExpr_skipResultType( node,
    631634                        new VirtualCastExpr(
    632635                                get<Expression>().accept1(node->arg),
    633                                 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr
     636                                get<Type>().accept1(node->result)
    634637                        )
    635638                );
     
    849852
    850853        const ast::Expr * visit( const ast::TypeExpr * node ) override final {
    851                 (void)node;
     854                auto expr = visitBaseExpr( node,
     855                        new TypeExpr(
     856                                get<Type>().accept1(node->type)
     857                        )
     858                );
     859                this->node = expr;
    852860                return nullptr;
    853861        }
    854862
    855863        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    856                 (void)node;
     864                auto expr = visitBaseExpr( node,
     865                        new AsmExpr(
     866                                get<Expression>().accept1(node->inout),
     867                                get<Expression>().accept1(node->constraint),
     868                                get<Expression>().accept1(node->operand)
     869                        )
     870                );
     871                this->node = expr;
    857872                return nullptr;
    858873        }
    859874
    860875        const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
    861                 (void)node;
     876                auto rslt = new ImplicitCopyCtorExpr(
     877                        get<ApplicationExpr>().accept1(node->callExpr)
     878                );
     879
     880                rslt->tempDecls = get<ObjectDecl>().acceptL(node->tempDecls);
     881                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
     882                rslt->dtors = get<Expression>().acceptL(node->dtors);
     883
     884                auto expr = visitBaseExpr( node, rslt );
     885                this->node = expr;
    862886                return nullptr;
    863887        }
    864888
    865889        const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
    866                 (void)node;
     890                auto expr = visitBaseExpr( node,
     891                        new ConstructorExpr(
     892                                get<Expression>().accept1(node->callExpr)
     893                        )
     894                );
     895                this->node = expr;
    867896                return nullptr;
    868897        }
    869898
    870899        const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
    871                 (void)node;
     900                auto expr = visitBaseExpr_skipResultType( node,
     901                        new CompoundLiteralExpr(
     902                                get<Type>().accept1(node->result),
     903                                get<Initializer>().accept1(node->init)
     904                        )
     905                );
     906                this->node = expr;
    872907                return nullptr;
    873908        }
    874909
    875910        const ast::Expr * visit( const ast::RangeExpr * node ) override final {
    876                 (void)node;
     911                auto expr = visitBaseExpr( node,
     912                        new RangeExpr(
     913                                get<Expression>().accept1(node->low),
     914                                get<Expression>().accept1(node->high)
     915                        )
     916                );
     917                this->node = expr;
    877918                return nullptr;
    878919        }
    879920
    880921        const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
    881                 (void)node;
     922                auto expr = visitBaseExpr( node,
     923                        new UntypedTupleExpr(
     924                                get<Expression>().acceptL(node->exprs)
     925                        )
     926                );
     927                this->node = expr;
    882928                return nullptr;
    883929        }
    884930
    885931        const ast::Expr * visit( const ast::TupleExpr * node ) override final {
    886                 (void)node;
     932                auto expr = visitBaseExpr( node,
     933                        new UntypedTupleExpr(
     934                                get<Expression>().acceptL(node->exprs)
     935                        )
     936                );
     937                this->node = expr;
    887938                return nullptr;
    888939        }
    889940
    890941        const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
    891                 (void)node;
     942                auto expr = visitBaseExpr( node,
     943                        new TupleIndexExpr(
     944                                get<Expression>().accept1(node->tuple),
     945                                node->index
     946                        )
     947                );
     948                this->node = expr;
    892949                return nullptr;
    893950        }
    894951
    895952        const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
    896                 (void)node;
     953                auto expr = visitBaseExpr( node,
     954                        new TupleAssignExpr(
     955                                get<StmtExpr>().accept1(node->stmtExpr)
     956                        )
     957                );
     958                this->node = expr;
    897959                return nullptr;
    898960        }
    899961
    900962        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    901                 (void)node;
     963                auto rslt = new StmtExpr(
     964                        get<CompoundStmt>().accept1(node->stmts)
     965                );
     966
     967                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
     968                rslt->dtors       = get<Expression>().acceptL(node->dtors);
     969
     970                auto expr = visitBaseExpr( node, rslt );
     971                this->node = expr;
    902972                return nullptr;
    903973        }
    904974
    905975        const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
    906                 (void)node;
     976                auto rslt = new UniqueExpr(
     977                        get<Expression>().accept1(node->expr)
     978                );
     979
     980                rslt->object = get<ObjectDecl>  ().accept1(node->object);
     981                rslt->var    = get<VariableExpr>().accept1(node->var);
     982
     983                auto expr = visitBaseExpr( node, rslt );
     984                this->node = expr;
    907985                return nullptr;
    908986        }
    909987
    910988        const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
    911                 (void)node;
     989                std::list<InitAlternative> initAlts;
     990                for (auto ia : node->initAlts) {
     991                        initAlts.push_back(InitAlternative(
     992                                get<Type>       ().accept1(ia.type),
     993                                get<Designation>().accept1(ia.designation)
     994                        ));
     995                }
     996                auto expr = visitBaseExpr( node,
     997                        new UntypedInitExpr(
     998                                get<Expression>().accept1(node->expr),
     999                                initAlts
     1000                        )
     1001                );
     1002                this->node = expr;
    9121003                return nullptr;
    9131004        }
    9141005
    9151006        const ast::Expr * visit( const ast::InitExpr * node ) override final {
    916                 (void)node;
     1007                auto expr = visitBaseExpr( node,
     1008                        new InitExpr(
     1009                                get<Expression>().accept1(node->expr),
     1010                                get<Designation>().accept1(node->designation)
     1011                        )
     1012                );
     1013                this->node = expr;
    9171014                return nullptr;
    9181015        }
    9191016
    9201017        const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
    921                 (void)node;
     1018                auto expr = visitBaseExpr( node,
     1019                        new DeletedExpr(
     1020                                get<Expression>().accept1(node->expr),
     1021                                inCache(node->deleteStmt) ?
     1022                                        this->node :
     1023                                        get<BaseSyntaxNode>().accept1(node->deleteStmt)
     1024                        )
     1025                );
     1026                this->node = expr;
    9221027                return nullptr;
    9231028        }
    9241029
    9251030        const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
    926                 (void)node;
     1031                auto expr = visitBaseExpr( node,
     1032                        new DefaultArgExpr(
     1033                                get<Expression>().accept1(node->expr)
     1034                        )
     1035                );
     1036                this->node = expr;
    9271037                return nullptr;
    9281038        }
    9291039
    9301040        const ast::Expr * visit( const ast::GenericExpr * node ) override final {
    931                 (void)node;
     1041                std::list<GenericExpr::Association> associations;
     1042                for (auto association : node->associations) {
     1043                        associations.push_back(GenericExpr::Association(
     1044                                get<Type>      ().accept1(association.type),
     1045                                get<Expression>().accept1(association.expr)
     1046                        ));
     1047                }
     1048                auto expr = visitBaseExpr( node,
     1049                        new GenericExpr(
     1050                                get<Expression>().accept1(node->control),
     1051                                associations
     1052                        )
     1053                );
     1054                this->node = expr;
    9321055                return nullptr;
    9331056        }
     
    16961819        }
    16971820
    1698         ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
    1699 
    1700                 nw->result = GET_ACCEPT_1(result, Type);
     1821        ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) {
     1822
    17011823                nw->env    = convertTypeSubstitution(old->env);
    17021824
     
    17051827
    17061828                return nw;
     1829        }
     1830
     1831        ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
     1832
     1833                nw->result = GET_ACCEPT_1(result, Type);
     1834                return visitBaseExpr_SkipResultType(old, nw);;
    17071835        }
    17081836
     
    17721900
    17731901        virtual void visit( VirtualCastExpr * old ) override final {
    1774                 this->node = visitBaseExpr( old,
     1902                this->node = visitBaseExpr_SkipResultType( old,
    17751903                        new ast::VirtualCastExpr(
    17761904                                old->location,
    17771905                                GET_ACCEPT_1(arg, Expr),
    1778                                 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr
     1906                                GET_ACCEPT_1(result, Type)
    17791907                        )
    17801908                );
     
    20012129        }
    20022130
    2003         virtual void visit( TypeExpr * ) override final {
    2004 
    2005         }
    2006 
    2007         virtual void visit( AsmExpr * ) override final {
    2008 
    2009         }
    2010 
    2011         virtual void visit( ImplicitCopyCtorExpr * ) override final {
    2012 
    2013         }
    2014 
    2015         virtual void visit( ConstructorExpr *  ) override final {
    2016 
    2017         }
    2018 
    2019         virtual void visit( CompoundLiteralExpr * ) override final {
    2020 
    2021         }
    2022 
    2023         virtual void visit( RangeExpr * ) override final {
    2024 
    2025         }
    2026 
    2027         virtual void visit( UntypedTupleExpr * ) override final {
    2028 
    2029         }
    2030 
    2031         virtual void visit( TupleExpr * ) override final {
    2032 
    2033         }
    2034 
    2035         virtual void visit( TupleIndexExpr * ) override final {
    2036 
    2037         }
    2038 
    2039         virtual void visit( TupleAssignExpr * ) override final {
    2040 
    2041         }
    2042 
    2043         virtual void visit( StmtExpr *  ) override final {
    2044 
    2045         }
    2046 
    2047         virtual void visit( UniqueExpr *  ) override final {
    2048 
    2049         }
    2050 
    2051         virtual void visit( UntypedInitExpr *  ) override final {
    2052 
    2053         }
    2054 
    2055         virtual void visit( InitExpr *  ) override final {
    2056 
    2057         }
    2058 
    2059         virtual void visit( DeletedExpr * ) override final {
    2060 
    2061         }
    2062 
    2063         virtual void visit( DefaultArgExpr * ) override final {
    2064 
    2065         }
    2066 
    2067         virtual void visit( GenericExpr * ) override final {
    2068 
     2131        virtual void visit( TypeExpr * old ) override final {
     2132                this->node = visitBaseExpr( old,
     2133                        new ast::TypeExpr(
     2134                                old->location,
     2135                                GET_ACCEPT_1(type, Type)
     2136                        )
     2137                );
     2138        }
     2139
     2140        virtual void visit( AsmExpr * old ) override final {
     2141                this->node = visitBaseExpr( old,
     2142                        new ast::AsmExpr(
     2143                                old->location,
     2144                                GET_ACCEPT_1(inout, Expr),
     2145                                GET_ACCEPT_1(constraint, Expr),
     2146                                GET_ACCEPT_1(operand, Expr)
     2147                        )
     2148                );
     2149        }
     2150
     2151        virtual void visit( ImplicitCopyCtorExpr * old ) override final {
     2152                auto rslt = new ast::ImplicitCopyCtorExpr(
     2153                        old->location,
     2154                        GET_ACCEPT_1(callExpr, ApplicationExpr)
     2155                );
     2156
     2157                rslt->tempDecls = GET_ACCEPT_V(tempDecls, ObjectDecl);
     2158                rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl);
     2159                rslt->dtors = GET_ACCEPT_V(dtors, Expr);
     2160
     2161                this->node = visitBaseExpr( old, rslt );
     2162        }
     2163
     2164        virtual void visit( ConstructorExpr * old ) override final {
     2165                this->node = visitBaseExpr( old,
     2166                        new ast::ConstructorExpr(
     2167                                old->location,
     2168                                GET_ACCEPT_1(callExpr, Expr)
     2169                        )
     2170                );
     2171        }
     2172
     2173        virtual void visit( CompoundLiteralExpr * old ) override final {
     2174                this->node = visitBaseExpr_SkipResultType( old,
     2175                        new ast::CompoundLiteralExpr(
     2176                                old->location,
     2177                                GET_ACCEPT_1(result, Type),
     2178                                GET_ACCEPT_1(initializer, Init)
     2179                        )
     2180                );
     2181        }
     2182
     2183        virtual void visit( RangeExpr * old ) override final {
     2184                this->node = visitBaseExpr( old,
     2185                        new ast::RangeExpr(
     2186                                old->location,
     2187                                GET_ACCEPT_1(low, Expr),
     2188                                GET_ACCEPT_1(high, Expr)
     2189                        )
     2190                );
     2191        }
     2192
     2193        virtual void visit( UntypedTupleExpr * old ) override final {
     2194                this->node = visitBaseExpr( old,
     2195                        new ast::UntypedTupleExpr(
     2196                                old->location,
     2197                                GET_ACCEPT_V(exprs, Expr)
     2198                        )
     2199                );
     2200        }
     2201
     2202        virtual void visit( TupleExpr * old ) override final {
     2203                this->node = visitBaseExpr( old,
     2204                        new ast::TupleExpr(
     2205                                old->location,
     2206                                GET_ACCEPT_V(exprs, Expr)
     2207                        )
     2208                );
     2209        }
     2210
     2211        virtual void visit( TupleIndexExpr * old ) override final {
     2212                this->node = visitBaseExpr( old,
     2213                        new ast::TupleIndexExpr(
     2214                                old->location,
     2215                                GET_ACCEPT_1(tuple, Expr),
     2216                                old->index
     2217                        )
     2218                );
     2219        }
     2220
     2221        virtual void visit( TupleAssignExpr * old ) override final {
     2222                this->node = visitBaseExpr_SkipResultType( old,
     2223                        new ast::TupleAssignExpr(
     2224                                old->location,
     2225                                GET_ACCEPT_1(result, Type),
     2226                                GET_ACCEPT_1(stmtExpr, StmtExpr)
     2227                        )
     2228                );
     2229        }
     2230
     2231        virtual void visit( StmtExpr * old ) override final {
     2232                auto rslt = new ast::StmtExpr(
     2233                        old->location,
     2234                        GET_ACCEPT_1(statements, CompoundStmt)
     2235                );
     2236                rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl);
     2237                rslt->dtors       = GET_ACCEPT_V(dtors      , Expr);
     2238
     2239                this->node = visitBaseExpr_SkipResultType( old, rslt );
     2240        }
     2241
     2242        virtual void visit( UniqueExpr * old ) override final {
     2243                auto rslt = new ast::UniqueExpr(
     2244                        old->location,
     2245                        GET_ACCEPT_1(expr, Expr)
     2246                );
     2247                rslt->object = GET_ACCEPT_1(object, ObjectDecl);
     2248                rslt->var    = GET_ACCEPT_1(var   , VariableExpr);
     2249
     2250                this->node = visitBaseExpr( old, rslt );
     2251        }
     2252
     2253        virtual void visit( UntypedInitExpr * old ) override final {
     2254                std::vector<ast::InitAlternative> initAlts;
     2255                for (auto ia : old->initAlts) {
     2256                        initAlts.push_back(ast::InitAlternative(
     2257                                getAccept1< ast::Type, Type * >( ia.type ),
     2258                                getAccept1< ast::Designation, Designation * >( ia.designation )
     2259                        ));
     2260                }
     2261                this->node = visitBaseExpr( old,
     2262                        new ast::UntypedInitExpr(
     2263                                old->location,
     2264                                GET_ACCEPT_1(expr, Expr),
     2265                                std::move(initAlts)
     2266                        )
     2267                );
     2268        }
     2269
     2270        virtual void visit( InitExpr * old ) override final {
     2271                this->node = visitBaseExpr( old,
     2272                        new ast::InitExpr(
     2273                                old->location,
     2274                                GET_ACCEPT_1(expr, Expr),
     2275                                GET_ACCEPT_1(designation, Designation)
     2276                        )
     2277                );
     2278        }
     2279
     2280        virtual void visit( DeletedExpr * old ) override final {
     2281                this->node = visitBaseExpr( old,
     2282                        new ast::DeletedExpr(
     2283                                old->location,
     2284                                GET_ACCEPT_1(expr, Expr),
     2285                                inCache(old->deleteStmt) ?
     2286                                        this->node :
     2287                                        GET_ACCEPT_1(deleteStmt, Node)
     2288                        )
     2289                );
     2290        }
     2291
     2292        virtual void visit( DefaultArgExpr * old ) override final {
     2293                this->node = visitBaseExpr( old,
     2294                        new ast::DefaultArgExpr(
     2295                                old->location,
     2296                                GET_ACCEPT_1(expr, Expr)
     2297                        )
     2298                );
     2299        }
     2300
     2301        virtual void visit( GenericExpr * old ) override final {
     2302                std::vector<ast::GenericExpr::Association> associations;
     2303                for (auto association : old->associations) {
     2304                        associations.push_back(ast::GenericExpr::Association(
     2305                                getAccept1< ast::Type, Type * >( association.type ),
     2306                                getAccept1< ast::Expr, Expression * >( association.expr )
     2307                        ));
     2308                }
     2309                this->node = visitBaseExpr( old,
     2310                        new ast::GenericExpr(
     2311                                old->location,
     2312                                GET_ACCEPT_1(control, Expr),
     2313                                std::move(associations)
     2314                        )
     2315                );
    20692316        }
    20702317
  • src/AST/Expr.cpp

    red5e798 r20de6fb  
    335335}
    336336
     337TupleAssignExpr::TupleAssignExpr(
     338        const CodeLocation & loc, const Type * result, const StmtExpr * s )
     339: Expr( loc, result ), stmtExpr() {
     340        stmtExpr = s;
     341}
     342
    337343// --- StmtExpr
    338344
  • src/AST/Expr.hpp

    red5e798 r20de6fb  
    3030#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
    3131
     32class ConverterOldToNew;
     33
    3234namespace ast {
    3335
     
    528530        std::vector<ptr<ObjectDecl>> tempDecls;
    529531        std::vector<ptr<ObjectDecl>> returnDecls;
    530         std::vector<ptr<ObjectDecl>> dtors;
     532        std::vector<ptr<Expr>> dtors;
    531533
    532534        ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call )
     
    635637
    636638        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     639
     640        friend class ::ConverterOldToNew;
     641
    637642private:
    638643        TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; }
     644    TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );
     645
    639646        MUTATE_FRIEND
    640647};
  • src/SynTree/Expression.h

    red5e798 r20de6fb  
    741741        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    742742        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     743
     744        friend class ConverterNewToOld;
     745  private:
     746    TupleAssignExpr( StmtExpr * stmts );
    743747};
    744748
  • src/SynTree/TupleExpr.cc

    red5e798 r20de6fb  
    105105}
    106106
     107TupleAssignExpr::TupleAssignExpr(
     108        StmtExpr * s )
     109: Expression(), stmtExpr(s) {
     110}
     111
     112
    107113TupleAssignExpr::~TupleAssignExpr() {
    108114        delete stmtExpr;
Note: See TracChangeset for help on using the changeset viewer.