-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathlocations_default.ql
More file actions
68 lines (64 loc) · 2.29 KB
/
locations_default.ql
File metadata and controls
68 lines (64 loc) · 2.29 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
class AstNode extends @ruby_ast_node {
string toString() { none() }
}
class Location extends @location {
string toString() { none() }
}
class File extends @file {
string toString() { none() }
}
private predicate body_statement(AstNode body, int index, Location loc) {
exists(AstNode node, AstNode child | ruby_ast_node_info(child, _, _, loc) |
ruby_class_def(node, _) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "end") and
ruby_class_child(node, index, child)
or
ruby_do_block_def(node) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "end") and
ruby_do_block_child(node, index, child)
or
ruby_method_def(node, _) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "end") and
ruby_method_child(node, index, child)
or
ruby_module_def(node, _) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "end") and
ruby_module_child(node, index, child)
or
ruby_singleton_class_def(node, _) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "end") and
ruby_singleton_class_child(node, index, child)
or
ruby_singleton_method_def(node, _, _) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "end") and
ruby_singleton_method_child(node, index, child)
or
ruby_block_def(node) and
ruby_ast_node_info(body, node, _, _) and
ruby_tokeninfo(body, _, "}") and
ruby_block_child(node, index, child)
)
}
from Location loc, File file, int start_line, int start_column, int end_line, int end_column
where
locations_default(loc, file, start_line, start_column, end_line, end_column) and
not exists(AstNode node | ruby_ast_node_info(node, _, _, loc) and body_statement(node, _, _))
or
exists(AstNode node |
ruby_ast_node_info(node, _, _, loc) and
exists(Location first |
body_statement(node, 0, first) and
locations_default(first, pragma[only_bind_into](file), start_line, start_column, _, _)
) and
exists(Location last |
last = max(Location l, int i | body_statement(node, i, l) | l order by i) and
locations_default(last, pragma[only_bind_into](file), _, _, end_line, end_column)
)
)
select loc, file, start_line, start_column, end_line, end_column