1
1
import python
2
2
3
- /** Gets the comment on the line above for a given `ast_node ` */
4
- Comment comment_for ( AstNode ast_node ) {
5
- exists ( int line | line = ast_node .getLocation ( ) .getStartLine ( ) - 1 |
3
+ /** Gets the comment on the line above `ast ` */
4
+ Comment commentFor ( AstNode ast ) {
5
+ exists ( int line | line = ast .getLocation ( ) .getStartLine ( ) - 1 |
6
6
result
7
7
.getLocation ( )
8
- .hasLocationInfo ( ast_node .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) , line , _, line , _)
8
+ .hasLocationInfo ( ast .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) , line , _, line , _)
9
9
)
10
10
}
11
11
12
- /** Gets the value from `tag:value` in the comment for `ast_node ` */
13
- string getAnnotation ( AstNode ast_node , string tag ) {
14
- exists ( Comment comment , string match , string the_regex |
15
- the_regex = "([\\w]+):([\\w.]+)" and
16
- comment = comment_for ( ast_node ) and
17
- match = comment .getText ( ) .regexpFind ( the_regex , _, _) and
18
- tag = match .regexpCapture ( the_regex , 1 ) and
19
- result = match .regexpCapture ( the_regex , 2 )
12
+ /** Gets the value from `tag:value` in the comment for `ast ` */
13
+ string getAnnotation ( AstNode ast , string tag ) {
14
+ exists ( Comment comment , string match , string theRegex |
15
+ theRegex = "([\\w]+):([\\w.]+)" and
16
+ comment = commentFor ( ast ) and
17
+ match = comment .getText ( ) .regexpFind ( theRegex , _, _) and
18
+ tag = match .regexpCapture ( theRegex , 1 ) and
19
+ result = match .regexpCapture ( theRegex , 2 )
20
20
)
21
21
}
22
22
@@ -42,7 +42,7 @@ predicate missingAnnotationForCall(string name, Function callable) {
42
42
}
43
43
44
44
/** There is an obvious problem with the annotation `name` */
45
- predicate name_in_error_state ( string name ) {
45
+ predicate nameInErrorState ( string name ) {
46
46
missingAnnotationForCallable ( name , _)
47
47
or
48
48
nonUniqueAnnotationForCallable ( name , _)
@@ -52,7 +52,7 @@ predicate name_in_error_state(string name) {
52
52
53
53
/** Source code has annotation with `name` showing that `call` will call `callable` */
54
54
predicate annotatedCallEdge ( string name , Call call , Function callable ) {
55
- not name_in_error_state ( name ) and
55
+ not nameInErrorState ( name ) and
56
56
call = annotatedCall ( name ) and
57
57
callable = annotatedCallable ( name )
58
58
}
@@ -112,13 +112,13 @@ abstract class CallGraphResolver extends TCallGraphResolver {
112
112
exists ( string name |
113
113
message = "Call resolved to the callable named '" + name + "' but was not annotated as such" and
114
114
callable = annotatedCallable ( name ) and
115
- not name_in_error_state ( name )
115
+ not nameInErrorState ( name )
116
116
)
117
117
or
118
118
exists ( string name |
119
119
message = "Annotated call resolved to unannotated callable" and
120
120
call = annotatedCall ( name ) and
121
- not name_in_error_state ( name ) and
121
+ not nameInErrorState ( name ) and
122
122
not exists ( | callable = annotatedCallable ( _) )
123
123
)
124
124
)
@@ -130,9 +130,9 @@ abstract class CallGraphResolver extends TCallGraphResolver {
130
130
/** A call graph resolver based on the existing points-to analysis */
131
131
class PointsToResolver extends CallGraphResolver , TPointsToResolver {
132
132
override predicate callEdge ( Call call , Function callable ) {
133
- exists ( PythonFunctionValue func_value |
134
- func_value .getScope ( ) = callable and
135
- call = func_value .getACall ( ) .getNode ( )
133
+ exists ( PythonFunctionValue funcValue |
134
+ funcValue .getScope ( ) = callable and
135
+ call = funcValue .getACall ( ) .getNode ( )
136
136
)
137
137
}
138
138
0 commit comments