FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/ast/ast_annotations.cpp at master · rburkholder/daScript · GitHub
rburkholder
/
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_annotations.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
149 lines (141 loc) · 6.32 KB
Breadcrumbs
daScript
/
src
/
ast
/
ast_annotations.cpp
Copy path
File metadata and controls
149 lines (141 loc) · 6.32 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/ast/ast.h
"
#
include
"
daScript/ast/ast_visitor.h
"
namespace
das
{
class
FinAnnotationVisitor
:
public
Visitor
{
public:
FinAnnotationVisitor
(
const
ProgramPtr & prog ) {
program = prog;
}
protected:
ProgramPtr program;
protected:
virtual
bool
canVisitStructureFieldInit
( Structure * )
override
{
return
false
; }
virtual
bool
canVisitArgumentInit
( Function * ,
const
VariablePtr &, Expression * )
override
{
return
false
; }
virtual
bool
canVisitQuoteSubexpression
( ExprQuote * )
override
{
return
false
; }
virtual
void
preVisit
( Structure * var )
override
{
Visitor::preVisit
(var);
for
(
const
auto
& pA : var->
annotations
) {
if
(pA->
annotation
->
rtti_isStructureAnnotation
()) {
auto
sa = static_pointer_cast<StructureAnnotation>(pA->
annotation
);
string err =
"
"
;
if
(!sa->
look
(var, *program->
thisModuleGroup
, pA->
arguments
, err)) {
program->
error
(
"
can't finalize structure annotation [
"
+ sa->
name
+
"
]
"
,err,
"
"
,
var->
at
, CompilationError::invalid_annotation);
}
}
}
}
virtual
void
preVisit
( Function * fn )
override
{
Visitor::preVisit
(fn);
for
(
const
auto
& an : fn->
annotations
) {
auto
fna = static_pointer_cast<FunctionAnnotation>(an->
annotation
);
string err =
"
"
;
if
( !fna->
finalize
(fn, *program->
thisModuleGroup
, an->
arguments
, program->
options
, err) ) {
program->
error
(
"
can't finalize annotation [
"
+ fna->
name
+
"
]
"
,err,
"
"
,
fn->
at
, CompilationError::invalid_annotation);
}
}
}
virtual
void
preVisit
( ExprBlock * block )
override
{
Visitor::preVisit
(block);
if
( block->
annotations
.
size
() ) {
for
(
const
auto
& an : block->
annotations
) {
auto
fna = static_pointer_cast<FunctionAnnotation>(an->
annotation
);
string err =
"
"
;
if
( !fna->
finalize
(block, *program->
thisModuleGroup
, an->
arguments
, program->
options
, err) ) {
program->
error
(
"
can't finalize annotation [
"
+ fna->
name
+
"
]
"
,err,
"
"
,
block->
at
, CompilationError::invalid_annotation);
}
}
if
( block->
annotationDataSid
|| block->
annotationData
) {
if
( block->
annotationDataSid
&& block->
annotationData
) {
program->
thisModule
->
annotationData
[block->
annotationDataSid
] = block->
annotationData
;
}
else
{
program->
error
(
"
internal error. both annotationData and Sid must be provided
"
,
"
"
,
"
"
,
block->
at
, CompilationError::invalid_annotation);
}
}
}
}
void
skipMakeBlock
(
const
ExpressionPtr & expr ) {
if
( expr->
rtti_isMakeBlock
() ) {
auto
mkb = static_pointer_cast<ExprMakeBlock>(expr);
auto
blk = static_pointer_cast<ExprBlock>(mkb->
block
);
blk->
aotSkipMakeBlock
=
true
;
}
}
virtual
void
preVisit
( ExprCall * call )
override
{
Visitor::preVisit
(call);
if
( call->
func
->
aotTemplate
) {
for
(
auto
& arg : call->
arguments
) {
skipMakeBlock
(arg);
}
}
}
virtual
void
preVisit
( ExprOp1 * op1 )
override
{
Visitor::preVisit
(op1);
skipMakeBlock
(op1->
subexpr
);
}
virtual
void
preVisit
( ExprOp2 * op2 )
override
{
Visitor::preVisit
(op2);
skipMakeBlock
(op2->
left
);
skipMakeBlock
(op2->
right
);
}
virtual
void
preVisit
( ExprOp3 * op3 )
override
{
Visitor::preVisit
(op3);
skipMakeBlock
(op3->
left
);
skipMakeBlock
(op3->
right
);
}
};
void
Program::finalizeAnnotations
() {
FinAnnotationVisitor
fin
(
this
);
visit
(fin);
}
bool
Program::patchAnnotations
() {
bool
astChanged =
false
;
thisModule->
functions
.
foreach
([&](
auto
fn){
for
(
auto
& ann : fn->
annotations
) {
if
( ann->
annotation
->
rtti_isFunctionAnnotation
() ) {
auto
fann = static_pointer_cast<FunctionAnnotation>(ann->
annotation
);
string err;
if
( !fann->
patch
(fn, *thisModuleGroup, ann->
arguments
, options, err, astChanged) ) {
error
(
"
function annotation patch failed
\n
"
, err,
"
"
, fn->
at
, CompilationError::annotation_failed );
}
if
( astChanged )
return
true
;
}
}
return
false
;
});
if
( astChanged )
goto
done;
thisModule->
structures
.
find_first
([&](
auto
st){
for
(
auto
& ann : st->
annotations
) {
if
( ann->
annotation
->
rtti_isStructureAnnotation
() ) {
auto
sann = static_pointer_cast<StructureAnnotation>(ann->
annotation
);
string err;
if
( !sann->
patch
(st, *thisModuleGroup, ann->
arguments
, err, astChanged) ) {
error
(
"
structure annotation patch failed
\n
"
, err,
"
"
, st->
at
, CompilationError::annotation_failed );
}
if
( astChanged )
return
true
;
}
}
return
false
;
});
done:;
return
astChanged;
}
void
Program::fixupAnnotations
() {
thisModule->
functions
.
foreach
([&](
auto
fn){
for
(
auto
& ann : fn->
annotations
) {
if
( ann->
annotation
->
rtti_isFunctionAnnotation
() ) {
auto
fann = static_pointer_cast<FunctionAnnotation>(ann->
annotation
);
string err;
if
( !fann->
fixup
(fn, *thisModuleGroup, ann->
arguments
, options, err) ) {
error
(
"
function annotation patch failed
\n
"
, err,
"
"
, fn->
at
, CompilationError::annotation_failed );
}
}
}
});
}
}
Back
|
FazBrowse Home
|
New Git URL