-
Notifications
You must be signed in to change notification settings - Fork 0
/
astblock_old.h
88 lines (66 loc) · 2.5 KB
/
astblock_old.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef ASTFUNCTION_H
#define ASTFUNCTION_H
#include "astexpr.h"
#define TO_STRING_INDENT_CHAR ' '
#define TO_STRING_INDENT_REPEAT 4
#define TO_STRING_EXPR_BREAK "\n"
class AstBlock : public AstExpr
{
public:
typedef unsigned int Flags;
static constexpr Flags implicit_out = 1;
/*
friend AstFunction::BindFlag operator|(AstFunction::BindFlag a, AstFunction::BindFlag b);
friend AstFunction::BindFlag operator&(AstFunction::BindFlag a, AstFunction::BindFlag b);
friend AstFunction::BindFlag operator^(AstFunction::BindFlag a, AstFunction::BindFlag b);
friend AstFunction::BindFlag operator~(AstFunction::BindFlag a);
friend AstFunction::BindFlag operator|=(AstFunction::BindFlag &a, AstFunction::BindFlag b);
friend AstFunction::BindFlag operator&=(AstFunction::BindFlag &a, AstFunction::BindFlag b);
friend AstFunction::BindFlag operator^=(AstFunction::BindFlag &a, AstFunction::BindFlag b);
*/
AstBlock()
{}
void add_expr(AstExpr *expr)
{
exprs.push_back(expr);
}
void set_bind(const Flags flags);
void apply_bind(AstBlock *scope);
void set_stack_start(unsigned int stack_size);
unsigned int hoist_ident(std::string symbol, bool declare);
Stream *execute(Context *context);
std::string to_string(unsigned int indent = 0)
{
std::string indent_block = std::string(indent * TO_STRING_INDENT_REPEAT, TO_STRING_INDENT_CHAR);
indent++;
std::string indent_expr = std::string(indent * TO_STRING_INDENT_REPEAT, TO_STRING_INDENT_CHAR);
std::string str = TO_STRING_EXPR_BREAK;
std::vector<AstExpr*>::iterator i = exprs.begin();
while (i != exprs.end())
{
str += indent_expr;
str += (*i)->to_string(indent);
str += TO_STRING_EXPR_BREAK;
i++;
}
switch (bind)
{
case AstBlock::BindInOut | AstBlock::BindImplicitRel | AstBlock::BindIdentDecl:
return "{" + str + indent_block + "}";
case AstBlock::BindImplicitRel | AstBlock::BindAutoOut:
return "[" + str + indent_block + "]";
case AstBlock::BindAutoOut:
return "(" + str + indent_block + ")";
default:
return std::string("<< Unknown block type >>");
}
}
protected:
Flags bind = BindNone;
AstBlock *parent_scope;
bool bind_ident_decl;
unsigned int stack_start;
std::vector<std::string> declared_symbols;
std::vector<AstExpr*> exprs;
};
#endif // ASTFUNCTION_H