-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPyxlTags.qll
More file actions
71 lines (55 loc) · 1.86 KB
/
PyxlTags.qll
File metadata and controls
71 lines (55 loc) · 1.86 KB
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
import python
/**
* A Tag in Pyxl (which gets converted to a call in Python).
*/
class PyxlTag extends Call {
PyxlTag() { pyxl_tag(this, _) }
string getPyxlTagName() { pyxl_tag(this, result) }
/** Gets the pyxl or Python node that is enclosed by this one in the pyxl source */
Expr getEnclosedNode() { none() }
/** Gets the Python code (if any) that is contained in this pyxl node */
Expr getEnclosedPythonCode() {
result = this.getEnclosedNode() and not result instanceof PyxlTag
or
result = this.getEnclosedNode().(PyxlTag).getEnclosedPythonCode()
}
}
private predicate pyxl_tag(Call c, string name) {
exists(Attribute tag, Name html |
tag = c.getFunc() and
html = tag.getObject() and
name = tag.getName() and
html.getId() = "html"
)
}
class PyxlHtmlTag extends PyxlTag {
PyxlHtmlTag() { this.getPyxlTagName().matches("x\\_%") }
string getTagName() { result = this.getPyxlTagName().suffix(2) }
/** Html tags get transformed into a call. This node is the callee function and the enclosed node is an argument. */
override Expr getEnclosedNode() {
exists(Call c |
c.getFunc() = this and
result = c.getAnArg()
)
}
}
class PyxlIfTag extends PyxlTag {
PyxlIfTag() { this.getPyxlTagName() = "_push_condition" }
override Expr getEnclosedNode() { result = this.getAnArg() }
}
class PyxlEndIfTag extends PyxlTag {
PyxlEndIfTag() { this.getPyxlTagName() = "_leave_if" }
override Expr getEnclosedNode() { result = this.getAnArg() }
}
class PyxlRawHtml extends PyxlTag {
PyxlRawHtml() { this.getPyxlTagName() = "rawhtml" }
/** Gets the text for this raw html, if it is simple text. */
string getText() {
exists(Unicode text |
text = this.getValue() and
result = text.getS()
)
}
Expr getValue() { result = this.getArg(0) }
override Expr getEnclosedNode() { result = this.getAnArg() }
}