-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactModifyVar.jrag
72 lines (66 loc) · 2.49 KB
/
ReactModifyVar.jrag
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
/*
* ReactiveDominoJ is a practical implementation of an expand event system
* supporting reactive programming. This project is an implementation of its
* compiler built on top of DominoJ and JastAddJ.
*
* Copyright (c) 2013-, YungYu Zhuang. All rights reserved.
*
* The contents of this file are licensed under the modified BSD License
* (please see the LICENSE file for the full text).
*/
/*
* Collect the information about read fields and written fields in the preprocess.
*/
aspect ReactModifyVar {
/*
* every VarAccess has to
* add itself to the field set for the method if it is a read field,
* or add the method to the writer set for the field if it is a written field.
*/
public void VarAccess.crossprocess() {
if(!decl().hostType().compilationUnit().fromSource()) return;
if(!(decl() instanceof FieldDeclaration)) return;
FieldDeclaration decl = (FieldDeclaration)decl();
if(decl.generated) return;
// get host method
ASTNode p = getParent();
while(!(p instanceof MethodDecl)) {
p = p.getParent();
if(p instanceof ClassDecl) return;
}
MethodDecl md = (MethodDecl)p;
// check if it written
boolean isRead = true;
p = getParent();
while(!(p.getParent() instanceof Stmt)) {
p = p.getParent();
}
if(p instanceof AssignExpr) {
Expr e = ((AssignExpr)p).getDest();
boolean isThis = true;
if(e instanceof Dot) {
e = ((Dot)e).extractLast();
if(!(((Dot)e.getParent()).getLeft() instanceof ThisAccess)) {
isThis = false;
}
}
if(e == this) {
isRead = false;
if(isThis) {
// only write accesses to fields on "this" object are tracked.
decl.addWriteMethod(md);
} else {
//System.out.println("ignore write access: " + name() + " in method " + md.name());
}
}
}
if(isRead) { // is read
if(getParent() instanceof Dot && !(((Dot)getParent()).getLeft() instanceof ThisAccess)) {
// only read accesses to fields on "this" object are tracked.
//System.out.println("ignore read access: " + name() + " in method " + md.name());
return;
}
md.addReadField(decl);
}
}
}