Line |
Branch |
Exec |
Source |
1 |
|
|
#ifndef LYTHON_CPP_GEN_HEADER |
2 |
|
|
#define LYTHON_CPP_GEN_HEADER |
3 |
|
|
|
4 |
|
|
#include "ast/magic.h" |
5 |
|
|
#include "ast/ops.h" |
6 |
|
|
#include "ast/visitor.h" |
7 |
|
|
#include "sema/bindings.h" |
8 |
|
|
#include "sema/builtin.h" |
9 |
|
|
#include "sema/errors.h" |
10 |
|
|
#include "utilities/strings.h" |
11 |
|
|
|
12 |
|
|
namespace lython { |
13 |
|
|
|
14 |
|
|
struct CPPGenVisitorTrait { |
15 |
|
|
using StmtRet = void; |
16 |
|
|
using ExprRet = void; |
17 |
|
|
using ModRet = void; |
18 |
|
|
using PatRet = void; |
19 |
|
|
using IsConst = std::false_type; |
20 |
|
|
using Trace = std::true_type; |
21 |
|
|
|
22 |
|
|
enum |
23 |
|
|
{ MaxRecursionDepth = LY_MAX_VISITOR_RECURSION_DEPTH }; |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
|
/* |
27 |
|
|
*/ |
28 |
|
|
struct CPPGen: BaseVisitor<CPPGen, false, CPPGenVisitorTrait> { |
29 |
|
|
using Super = BaseVisitor<CPPGen, false, CPPGenVisitorTrait>; |
30 |
|
|
|
31 |
|
|
using StmtRet = Super::StmtRet; |
32 |
|
|
using ExprRet = Super::ExprRet; |
33 |
|
|
using ModRet = Super::ModRet; |
34 |
|
|
using PatRet = Super::PatRet; |
35 |
|
|
|
36 |
|
|
#define TYPE_GEN(rtype) using rtype##_t = Super::rtype##_t; |
37 |
|
|
|
38 |
|
|
#define X(name, _) |
39 |
|
|
#define SSECTION(name) |
40 |
|
|
#define EXPR(name, fun) TYPE_GEN(name) |
41 |
|
|
#define STMT(name, fun) TYPE_GEN(name) |
42 |
|
|
#define MOD(name, fun) TYPE_GEN(name) |
43 |
|
|
#define MATCH(name, fun) TYPE_GEN(name) |
44 |
|
|
|
45 |
|
|
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH) |
46 |
|
|
|
47 |
|
|
#undef X |
48 |
|
|
#undef SSECTION |
49 |
|
|
#undef EXPR |
50 |
|
|
#undef STMT |
51 |
|
|
#undef MOD |
52 |
|
|
#undef MATCH |
53 |
|
|
#undef TYPE_GEN |
54 |
|
|
|
55 |
|
|
#define FUNCTION_GEN(name, fun, ret) virtual ret fun(name##_t* n, int depth); |
56 |
|
|
|
57 |
|
|
#define X(name, _) |
58 |
|
|
#define SSECTION(name) |
59 |
|
|
#define MOD(name, fun) FUNCTION_GEN(name, fun, ModRet) |
60 |
|
|
#define EXPR(name, fun) FUNCTION_GEN(name, fun, ExprRet) |
61 |
|
|
#define STMT(name, fun) FUNCTION_GEN(name, fun, StmtRet) |
62 |
|
|
#define MATCH(name, fun) FUNCTION_GEN(name, fun, PatRet) |
63 |
|
|
|
64 |
|
|
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH) |
65 |
|
|
|
66 |
|
|
#undef X |
67 |
|
|
#undef SSECTION |
68 |
|
|
#undef EXPR |
69 |
|
|
#undef STMT |
70 |
|
|
#undef MOD |
71 |
|
|
#undef MATCH |
72 |
|
|
|
73 |
|
|
#undef FUNCTION_GEN |
74 |
|
|
|
75 |
|
|
Bindings bindings; |
76 |
|
|
bool forwardpass = false; |
77 |
|
|
Array<StmtNode*> nested; |
78 |
|
|
Array<String> namespaces; |
79 |
|
|
Dict<StringRef, bool> flags; |
80 |
|
|
|
81 |
|
|
virtual ~CPPGen() {} |
82 |
|
|
}; |
83 |
|
|
|
84 |
|
|
} // namespace lython |
85 |
|
|
|
86 |
|
|
#endif |
87 |
|
|
|