| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ast/visitor.h" | ||
| 2 | |||
| 3 | namespace lython { | ||
| 4 | |||
| 5 | struct void_t {}; | ||
| 6 | |||
| 7 | struct TraverseTrait { | ||
| 8 | using StmtRet = void_t; | ||
| 9 | using ExprRet = void_t; | ||
| 10 | using ModRet = void_t; | ||
| 11 | using PatRet = void_t; | ||
| 12 | using Trace = std::false_type; | ||
| 13 | |||
| 14 | enum | ||
| 15 | { MaxRecursionDepth = LY_MAX_VISITOR_RECURSION_DEPTH }; | ||
| 16 | }; | ||
| 17 | |||
| 18 | // Generic visitor for simple tree operation | ||
| 19 | struct Traverse: public BaseVisitor<Traverse, false, TraverseTrait> { | ||
| 20 | using Super = BaseVisitor<Traverse, false, TraverseTrait>; | ||
| 21 | |||
| 22 | virtual void_t boolop(BoolOp* n, int depth) { return void_t(); } | ||
| 23 | virtual void_t namedexpr(NamedExpr* n, int depth) { return void_t(); } | ||
| 24 | virtual void_t binop(BinOp* n, int depth) { return void_t(); } | ||
| 25 | virtual void_t unaryop(UnaryOp* n, int depth) { return void_t(); } | ||
| 26 | virtual void_t lambda(Lambda* n, int depth) { return void_t(); } | ||
| 27 | virtual void_t ifexp(IfExp* n, int depth) { return void_t(); } | ||
| 28 | virtual void_t dictexpr(DictExpr* n, int depth) { return void_t(); } | ||
| 29 | virtual void_t setexpr(SetExpr* n, int depth) { return void_t(); } | ||
| 30 | virtual void_t listcomp(ListComp* n, int depth) { return void_t(); } | ||
| 31 | virtual void_t generateexpr(GeneratorExp* n, int depth) { return void_t(); } | ||
| 32 | virtual void_t setcomp(SetComp* n, int depth) { return void_t(); } | ||
| 33 | virtual void_t dictcomp(DictComp* n, int depth) { return void_t(); } | ||
| 34 | virtual void_t await(Await* n, int depth) { return void_t(); } | ||
| 35 | virtual void_t yield(Yield* n, int depth) { return void_t(); } | ||
| 36 | virtual void_t yieldfrom(YieldFrom* n, int depth) { return void_t(); } | ||
| 37 | virtual void_t compare(Compare* n, int depth) { return void_t(); } | ||
| 38 | virtual void_t call(Call* n, int depth) { return void_t(); } | ||
| 39 | virtual void_t joinedstr(JoinedStr* n, int depth) { return void_t(); } | ||
| 40 | virtual void_t formattedvalue(FormattedValue* n, int depth) { return void_t(); } | ||
| 41 | virtual void_t constant(Constant* n, int depth) { return void_t(); } | ||
| 42 | virtual void_t attribute(Attribute* n, int depth) { return void_t(); } | ||
| 43 | virtual void_t subscript(Subscript* n, int depth) { return void_t(); } | ||
| 44 | virtual void_t starred(Starred* n, int depth) { return void_t(); } | ||
| 45 | virtual void_t name(Name* n, int depth) { return void_t(); } | ||
| 46 | virtual void_t listexpr(ListExpr* n, int depth) { | ||
| 47 | ✗ | for (auto* i: n->elts) { | |
| 48 | ✗ | Super::exec(i, depth); | |
| 49 | } | ||
| 50 | ✗ | return void_t(); | |
| 51 | } | ||
| 52 | virtual void_t tupleexpr(TupleExpr* n, int depth) { | ||
| 53 |
2/2✓ Branch 5 taken 52 times.
✓ Branch 6 taken 20 times.
|
72 | for (auto* i: n->elts) { |
| 54 |
1/1✓ Branch 1 taken 52 times.
|
52 | Super::exec(i, depth); |
| 55 | } | ||
| 56 | 20 | return void_t(); | |
| 57 | } | ||
| 58 | virtual void_t slice(Slice* n, int depth) { return void_t(); } | ||
| 59 | virtual void_t dicttype(DictType* n, int depth) { return void_t(); } | ||
| 60 | virtual void_t arraytype(ArrayType* n, int depth) { return void_t(); } | ||
| 61 | virtual void_t tupletype(TupleType* n, int depth) { return void_t(); } | ||
| 62 | virtual void_t arrow(Arrow* n, int depth) { return void_t(); } | ||
| 63 | virtual void_t classtype(ClassType* n, int depth) { return void_t(); } | ||
| 64 | virtual void_t settype(SetType* n, int depth) { return void_t(); } | ||
| 65 | virtual void_t builtintype(BuiltinType* n, int depth) { return void_t(); } | ||
| 66 | virtual void_t functiondef(FunctionDef* n, int depth) { return void_t(); } | ||
| 67 | virtual void_t classdef(ClassDef* n, int depth) { return void_t(); } | ||
| 68 | virtual void_t returnstmt(Return* n, int depth) { return void_t(); } | ||
| 69 | virtual void_t deletestmt(Delete* n, int depth) { return void_t(); } | ||
| 70 | virtual void_t assign(Assign* n, int depth) { return void_t(); } | ||
| 71 | virtual void_t augassign(AugAssign* n, int depth) { return void_t(); } | ||
| 72 | virtual void_t annassign(AnnAssign* n, int depth) { return void_t(); } | ||
| 73 | virtual void_t forstmt(For* n, int depth) { return void_t(); } | ||
| 74 | virtual void_t whilestmt(While* n, int depth) { return void_t(); } | ||
| 75 | virtual void_t ifstmt(If* n, int depth) { return void_t(); } | ||
| 76 | virtual void_t with(With* n, int depth) { return void_t(); } | ||
| 77 | virtual void_t raise(Raise* n, int depth) { return void_t(); } | ||
| 78 | virtual void_t trystmt(Try* n, int depth) { return void_t(); } | ||
| 79 | virtual void_t assertstmt(Assert* n, int depth) { return void_t(); } | ||
| 80 | virtual void_t import(Import* n, int depth) { return void_t(); } | ||
| 81 | virtual void_t importfrom(ImportFrom* n, int depth) { return void_t(); } | ||
| 82 | virtual void_t global(Global* n, int depth) { return void_t(); } | ||
| 83 | virtual void_t nonlocal(Nonlocal* n, int depth) { return void_t(); } | ||
| 84 | virtual void_t exprstmt(Expr* n, int depth) { return void_t(); } | ||
| 85 | virtual void_t pass(Pass* n, int depth) { return void_t(); } | ||
| 86 | virtual void_t breakstmt(Break* n, int depth) { return void_t(); } | ||
| 87 | virtual void_t continuestmt(Continue* n, int depth) { return void_t(); } | ||
| 88 | virtual void_t match(Match* n, int depth) { return void_t(); } | ||
| 89 | virtual void_t inlinestmt(Inline* n, int depth) { return void_t(); } | ||
| 90 | virtual void_t matchvalue(MatchValue* n, int depth) { return void_t(); } | ||
| 91 | virtual void_t matchsingleton(MatchSingleton* n, int depth) { return void_t(); } | ||
| 92 | virtual void_t matchsequence(MatchSequence* n, int depth) { return void_t(); } | ||
| 93 | virtual void_t matchmapping(MatchMapping* n, int depth) { return void_t(); } | ||
| 94 | virtual void_t matchclass(MatchClass* n, int depth) { return void_t(); } | ||
| 95 | virtual void_t matchstar(MatchStar* n, int depth) { return void_t(); } | ||
| 96 | virtual void_t matchas(MatchAs* n, int depth) { return void_t(); } | ||
| 97 | virtual void_t matchor(MatchOr* n, int depth) { return void_t(); } | ||
| 98 | |||
| 99 | virtual void_t module(Module* n, int depth) { return void_t(); } | ||
| 100 | virtual void_t interactive(Interactive* n, int depth) { return void_t(); } | ||
| 101 | virtual void_t functiontype(FunctionType* n, int depth) { return void_t(); } | ||
| 102 | virtual void_t comment(Comment* n, int depth) { return void_t(); } | ||
| 103 | virtual void_t invalidstmt(InvalidStatement* n, int depth) { return void_t(); } | ||
| 104 | virtual void_t expression(Expression* n, int depth) { return void_t(); } | ||
| 105 | }; | ||
| 106 | |||
| 107 | struct SetContext: public Traverse { | ||
| 108 | using Super = Traverse; | ||
| 109 | |||
| 110 | ExprContext ctx; | ||
| 111 | |||
| 112 | virtual void_t attribute(Attribute* n, int depth) override { | ||
| 113 | 17 | n->ctx = ctx; | |
| 114 | 17 | return Super::attribute(n, depth); | |
| 115 | } | ||
| 116 | |||
| 117 | virtual void_t subscript(Subscript* n, int depth) override { | ||
| 118 | ✗ | n->ctx = ctx; | |
| 119 | ✗ | return Super::subscript(n, depth); | |
| 120 | } | ||
| 121 | |||
| 122 | virtual void_t starred(Starred* n, int depth) override { | ||
| 123 | 1 | n->ctx = ctx; | |
| 124 | 1 | return Super::starred(n, depth); | |
| 125 | } | ||
| 126 | |||
| 127 | virtual void_t name(Name* n, int depth) override { | ||
| 128 | 815 | n->ctx = ctx; | |
| 129 | 815 | return Super::name(n, depth); | |
| 130 | } | ||
| 131 | |||
| 132 | virtual void_t listexpr(ListExpr* n, int depth) override { | ||
| 133 | ✗ | n->ctx = ctx; | |
| 134 | ✗ | return Super::listexpr(n, depth); | |
| 135 | } | ||
| 136 | |||
| 137 | virtual void_t tupleexpr(TupleExpr* n, int depth) override { | ||
| 138 | 20 | n->ctx = ctx; | |
| 139 | 20 | return Super::tupleexpr(n, depth); | |
| 140 | } | ||
| 141 | }; | ||
| 142 | |||
| 143 | void set_context(Node* n, ExprContext ctx) { | ||
| 144 | 801 | SetContext ctx_visitor; | |
| 145 | 801 | ctx_visitor.ctx = ctx; | |
| 146 |
1/1✓ Branch 1 taken 801 times.
|
801 | ctx_visitor.exec<void_t>(n, 0); |
| 147 | 801 | } | |
| 148 | |||
| 149 | } // namespace lython | ||
| 150 |