Skip to content

Commit ca25971

Browse files
committed
C++: upgrade script for member_function_this_type
1 parent 3b15d39 commit ca25971

File tree

4 files changed

+4269
-0
lines changed

4 files changed

+4269
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Upgrade script to populate the member_function_this_type table. It's a rough
3+
* approximation of what the extractor would do - for a member function C::f,
4+
* we say its type is C* (if that pointer type exists in the database).
5+
* CV-qualifiers are ignored.
6+
*/
7+
8+
class Class extends @usertype {
9+
Class() {
10+
usertypes(this, _, 1) or
11+
usertypes(this, _, 2) or
12+
usertypes(this, _, 3) or
13+
usertypes(this, _, 6) or
14+
usertypes(this, _, 10) or
15+
usertypes(this, _, 11) or
16+
usertypes(this, _, 12)
17+
}
18+
19+
string toString() { usertypes(this, result, _) }
20+
}
21+
22+
class ClassPointerType extends @derivedtype {
23+
ClassPointerType() { derivedtypes(this, _, 1, _) }
24+
25+
Class getBaseType() { derivedtypes(this, _, _, result) }
26+
27+
string toString() { result = getBaseType().toString() + "*" }
28+
}
29+
30+
class DefinedMemberFunction extends @function {
31+
DefinedMemberFunction() {
32+
exists(@fun_decl fd |
33+
fun_def(fd) and
34+
(
35+
fun_decls(fd, this, _, _, _)
36+
or
37+
exists(@function f | function_instantiation(this, f) and fun_decls(fd, f, _, _, _))
38+
)
39+
)
40+
}
41+
42+
ClassPointerType getTypeOfThis() { member(result.getBaseType(), _, this) }
43+
44+
string toString() { functions(this, result, _) }
45+
}
46+
47+
from DefinedMemberFunction f
48+
select f, f.getTypeOfThis()

0 commit comments

Comments
 (0)