FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/ast/ast_visitor.cpp at master · Xsankor/daScript · GitHub
Xsankor
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
src
/
ast
/
ast_visitor.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (84 loc) · 2.87 KB
Breadcrumbs
daScript
/
src
/
ast
/
ast_visitor.cpp
Copy path
File metadata and controls
88 lines (84 loc) · 2.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/ast/ast_visitor.h
"
#
include
"
daScript/ast/ast_expressions.h
"
namespace
das
{
struct
AstContextVisitor
: Visitor {
AstContextVisitor
( Expression * expr )
: refExpr(expr) { }
AstContext astc, astr;
Expression * refExpr =
nullptr
;
int32_t
count =
0
;
//
expression
virtual
void
preVisitExpression
( Expression * expr )
override
{
Visitor::preVisitExpression
(expr);
if
( expr==refExpr ) {
count ++;
if
( count==
1
) {
astr = astc;
astr.
valid
=
true
;
}
}
}
//
function
virtual
void
preVisit
( Function * f )
override
{
Visitor::preVisit
(f);
astc.
func
= f;
}
virtual
FunctionPtr
visit
( Function * that )
override
{
//
if any of this asserts failed, there is logic error in how we pop
DAS_ASSERT
(astc.
loop
.
size
()==
0
);
DAS_ASSERT
(astc.
scopes
.
size
()==
0
);
DAS_ASSERT
(astc.
blocks
.
size
()==
0
);
DAS_ASSERT
(astc.
with
.
size
()==
0
);
astc.
func
.
reset
();
return
Visitor::visit
(that);
}
//
ExprWith
virtual
void
preVisit
( ExprWith * expr )
override
{
Visitor::preVisit
(expr);
astc.
with
.
push_back
(expr);
}
virtual
ExpressionPtr
visit
( ExprWith * expr )
override
{
astc.
with
.
pop_back
();
return
Visitor::visit
(expr);
}
//
ExprFor
virtual
void
preVisit
( ExprFor * expr )
override
{
Visitor::preVisit
(expr);
astc.
loop
.
push_back
(expr);
}
virtual
ExpressionPtr
visit
( ExprFor * expr )
override
{
astc.
loop
.
pop_back
();
return
Visitor::visit
(expr);
}
//
ExprWhile
virtual
void
preVisit
( ExprWhile * expr )
override
{
Visitor::preVisit
(expr);
astc.
loop
.
push_back
(expr);
}
virtual
ExpressionPtr
visit
( ExprWhile * expr )
override
{
astc.
loop
.
pop_back
();
return
Visitor::visit
(expr);
}
//
ExprBlock
virtual
void
preVisit
( ExprBlock * block )
override
{
Visitor::preVisit
(block);
if
( block->
isClosure
) {
astc.
blocks
.
push_back
(block);
}
astc.
scopes
.
push_back
(block);
}
virtual
ExpressionPtr
visit
( ExprBlock * block )
override
{
astc.
scopes
.
pop_back
();
if
( block->
isClosure
) {
astc.
blocks
.
pop_back
();
}
return
Visitor::visit
(block);
}
};
AstContext
generateAstContext
(
const
ProgramPtr & prog, Expression * expr ) {
AstContextVisitor
acv
(expr);
prog->
visit
(acv);
return
acv.
count
==
1
? acv.
astr
:
AstContext
();
}
}
Back
|
FazBrowse Home
|
New Git URL