Changes in / [9d23c2d:3f840e3]
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r9d23c2d r3f840e3 525 525 } 526 526 527 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 528 529 tgt->location = src->location; 530 tgt->env = convertTypeSubstitution(src->env); 527 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 528 529 tgt->location = src->location; 530 531 tgt->result = get<Type>().accept1(src->result); 532 tgt->env = convertTypeSubstitution(src->env); 533 531 534 tgt->extension = src->extension; 532 533 535 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 536 534 537 return tgt; 535 }536 537 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {538 539 tgt->result = get<Type>().accept1(src->result);540 return visitBaseExpr_skipResultType(src, tgt);541 538 } 542 539 … … 631 628 632 629 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 633 auto expr = visitBaseExpr _skipResultType( node,630 auto expr = visitBaseExpr( node, 634 631 new VirtualCastExpr( 635 632 get<Expression>().accept1(node->arg), 636 get<Type>().accept1(node->result)633 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr 637 634 ) 638 635 ); … … 852 849 853 850 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 854 auto expr = visitBaseExpr( node, 855 new TypeExpr( 856 get<Type>().accept1(node->type) 857 ) 858 ); 859 this->node = expr; 851 (void)node; 860 852 return nullptr; 861 853 } 862 854 863 855 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 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; 856 (void)node; 872 857 return nullptr; 873 858 } 874 859 875 860 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 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; 861 (void)node; 886 862 return nullptr; 887 863 } 888 864 889 865 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 890 auto expr = visitBaseExpr( node, 891 new ConstructorExpr( 892 get<Expression>().accept1(node->callExpr) 893 ) 894 ); 895 this->node = expr; 866 (void)node; 896 867 return nullptr; 897 868 } 898 869 899 870 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 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; 871 (void)node; 907 872 return nullptr; 908 873 } 909 874 910 875 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 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; 876 (void)node; 918 877 return nullptr; 919 878 } 920 879 921 880 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 922 auto expr = visitBaseExpr( node, 923 new UntypedTupleExpr( 924 get<Expression>().acceptL(node->exprs) 925 ) 926 ); 927 this->node = expr; 881 (void)node; 928 882 return nullptr; 929 883 } 930 884 931 885 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 932 auto expr = visitBaseExpr( node, 933 new UntypedTupleExpr( 934 get<Expression>().acceptL(node->exprs) 935 ) 936 ); 937 this->node = expr; 886 (void)node; 938 887 return nullptr; 939 888 } 940 889 941 890 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 942 auto expr = visitBaseExpr( node, 943 new TupleIndexExpr( 944 get<Expression>().accept1(node->tuple), 945 node->index 946 ) 947 ); 948 this->node = expr; 891 (void)node; 949 892 return nullptr; 950 893 } 951 894 952 895 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 953 auto expr = visitBaseExpr( node, 954 new TupleAssignExpr( 955 get<StmtExpr>().accept1(node->stmtExpr) 956 ) 957 ); 958 this->node = expr; 896 (void)node; 959 897 return nullptr; 960 898 } 961 899 962 900 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 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; 901 (void)node; 972 902 return nullptr; 973 903 } 974 904 975 905 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 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; 906 (void)node; 985 907 return nullptr; 986 908 } 987 909 988 910 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 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; 911 (void)node; 1003 912 return nullptr; 1004 913 } 1005 914 1006 915 const ast::Expr * visit( const ast::InitExpr * node ) override final { 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; 916 (void)node; 1014 917 return nullptr; 1015 918 } 1016 919 1017 920 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 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; 921 (void)node; 1027 922 return nullptr; 1028 923 } 1029 924 1030 925 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 1031 auto expr = visitBaseExpr( node, 1032 new DefaultArgExpr( 1033 get<Expression>().accept1(node->expr) 1034 ) 1035 ); 1036 this->node = expr; 926 (void)node; 1037 927 return nullptr; 1038 928 } 1039 929 1040 930 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 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; 931 (void)node; 1055 932 return nullptr; 1056 933 } … … 1819 1696 } 1820 1697 1821 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1822 1698 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1699 1700 nw->result = GET_ACCEPT_1(result, Type); 1823 1701 nw->env = convertTypeSubstitution(old->env); 1824 1702 … … 1827 1705 1828 1706 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);;1835 1707 } 1836 1708 … … 1900 1772 1901 1773 virtual void visit( VirtualCastExpr * old ) override final { 1902 this->node = visitBaseExpr _SkipResultType( old,1774 this->node = visitBaseExpr( old, 1903 1775 new ast::VirtualCastExpr( 1904 1776 old->location, 1905 1777 GET_ACCEPT_1(arg, Expr), 1906 GET_ACCEPT_1(result, Type)1778 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr 1907 1779 ) 1908 1780 ); … … 2129 2001 } 2130 2002 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 ); 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 2316 2069 } 2317 2070 -
src/AST/Expr.cpp
r9d23c2d r3f840e3 335 335 } 336 336 337 TupleAssignExpr::TupleAssignExpr(338 const CodeLocation & loc, const Type * result, const StmtExpr * s )339 : Expr( loc, result ), stmtExpr() {340 stmtExpr = s;341 }342 343 337 // --- StmtExpr 344 338 -
src/AST/Expr.hpp
r9d23c2d r3f840e3 30 30 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 31 31 32 class ConverterOldToNew;33 34 32 namespace ast { 35 33 … … 530 528 std::vector<ptr<ObjectDecl>> tempDecls; 531 529 std::vector<ptr<ObjectDecl>> returnDecls; 532 std::vector<ptr< Expr>> dtors;530 std::vector<ptr<ObjectDecl>> dtors; 533 531 534 532 ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call ) … … 637 635 638 636 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 639 640 friend class ::ConverterOldToNew;641 642 637 private: 643 638 TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; } 644 TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );645 646 639 MUTATE_FRIEND 647 640 }; -
src/SynTree/Expression.h
r9d23c2d r3f840e3 741 741 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 742 742 virtual void print( std::ostream & os, Indenter indent = {} ) const; 743 744 friend class ConverterNewToOld;745 private:746 TupleAssignExpr( StmtExpr * stmts );747 743 }; 748 744 -
src/SynTree/TupleExpr.cc
r9d23c2d r3f840e3 105 105 } 106 106 107 TupleAssignExpr::TupleAssignExpr(108 StmtExpr * s )109 : Expression(), stmtExpr(s) {110 }111 112 113 107 TupleAssignExpr::~TupleAssignExpr() { 114 108 delete stmtExpr;
Note: See TracChangeset
for help on using the changeset viewer.