Merge pull request #3814 from nickrolfe/71-this

C++: add MemberFunction::getTypeOfThis()
This commit is contained in:
Matthew Gretton-Dann
2020-06-30 13:31:14 +01:00
committed by GitHub
14 changed files with 5266 additions and 756 deletions

View File

@@ -2,15 +2,7 @@ uniqueEnclosingCallable
| C.cpp:37:24:37:33 | 0 | Node should have one enclosing callable but has 0. |
| C.cpp:37:24:37:33 | new | Node should have one enclosing callable but has 0. |
uniqueTypeBound
| complex.cpp:22:11:22:17 | constructor init of field f [post-this] | Node should have one type bound but has 0. |
| complex.cpp:22:11:22:17 | constructor init of field f [pre-this] | Node should have one type bound but has 0. |
| complex.cpp:25:7:25:7 | constructor init of field inner [post-this] | Node should have one type bound but has 0. |
| complex.cpp:25:7:25:7 | constructor init of field inner [pre-this] | Node should have one type bound but has 0. |
uniqueTypeRepr
| complex.cpp:22:11:22:17 | constructor init of field f [post-this] | Node should have one type representation but has 0. |
| complex.cpp:22:11:22:17 | constructor init of field f [pre-this] | Node should have one type representation but has 0. |
| complex.cpp:25:7:25:7 | constructor init of field inner [post-this] | Node should have one type representation but has 0. |
| complex.cpp:25:7:25:7 | constructor init of field inner [pre-this] | Node should have one type representation but has 0. |
uniqueNodeLocation
missingLocation
uniqueNodeToString

View File

@@ -231,8 +231,10 @@
| file://:0:0:0:0 | const lambda [] type at line 9, col. 5 * |
| file://:0:0:0:0 | const lambda [] type at line 9, col. 15 |
| file://:0:0:0:0 | const lambda [] type at line 9, col. 15 & |
| file://:0:0:0:0 | const lambda [] type at line 9, col. 15 * |
| file://:0:0:0:0 | const lambda [] type at line 15, col. 5 |
| file://:0:0:0:0 | const lambda [] type at line 15, col. 5 & |
| file://:0:0:0:0 | const lambda [] type at line 15, col. 5 * |
| file://:0:0:0:0 | const lambda [] type at line 22, col. 19 |
| file://:0:0:0:0 | const lambda [] type at line 22, col. 19 & |
| file://:0:0:0:0 | const lambda [] type at line 22, col. 19 * |
@@ -277,8 +279,10 @@
| file://:0:0:0:0 | lambda [] type at line 9, col. 5 * |
| file://:0:0:0:0 | lambda [] type at line 9, col. 15 & |
| file://:0:0:0:0 | lambda [] type at line 9, col. 15 && |
| file://:0:0:0:0 | lambda [] type at line 9, col. 15 * |
| file://:0:0:0:0 | lambda [] type at line 15, col. 5 & |
| file://:0:0:0:0 | lambda [] type at line 15, col. 5 && |
| file://:0:0:0:0 | lambda [] type at line 15, col. 5 * |
| file://:0:0:0:0 | lambda [] type at line 22, col. 19 & |
| file://:0:0:0:0 | lambda [] type at line 22, col. 19 && |
| file://:0:0:0:0 | lambda [] type at line 22, col. 19 * |

View File

@@ -0,0 +1,129 @@
int global;
class C {
int x;
public:
void f1() {
// Implicit dereference of `this.`
x++;
}
void f2() {
// Explicit dereference of `this.`
this->x++;
}
int f3() const {
// We expect the type of `this` to be const-qualified.
return x;
}
int f4() volatile {
// We expect the type of `this` to be volatile-qualified.
return x;
}
int f5() const volatile {
// We expect the type of `this` to be qualified as both const and volatile.
return x;
}
void f6() {
// No use of `this`, but we still expect to be able to get its type.
global++;
}
float f7() const & {
// We expect the type of `this` to be const-qualified.
return x;
}
float f8() && {
// We expect the type of `this` to be unqualified.
return x;
}
};
// We want to test that D* is in the database even when there's no use of it,
// not even through an implicit dereference of `this`.
class D {
void f() {
global++;
}
};
template<typename T>
class InstantiatedTemplateClass {
int x;
public:
void f1() {
// Implicit dereference of `this.`
x++;
}
void f2() {
// Explicit dereference of `this.`
this->x++;
}
int f3() const {
// We expect the type of `this` to be const-qualified.
return x;
}
int f4() volatile {
// We expect the type of `this` to be volatile-qualified.
return x;
}
int f5() const volatile {
// We expect the type of `this` to be qualified as both const and volatile.
return x;
}
void f6() {
// No use of `this`, but we still expect to be able to get its type.
global++;
}
float f7() const & {
// We expect the type of `this` to be const-qualified.
return x;
}
float f8() && {
// We expect the type of `this` to be unqualified.
return x;
}
};
void instantiate() {
InstantiatedTemplateClass<int> x;
x.f1();
x.f2();
x.f3();
x.f4();
x.f5();
x.f6();
x.f7();
float val = InstantiatedTemplateClass<int>().f8();
}
// Since there are no instantiations of this class, we don't expect
// MemberFunction::getTypeOfThis() to hold.
template<typename T>
class UninstantiatedTemplateClass {
int x;
public:
void f1() {
x++;
}
};

View File

@@ -0,0 +1,48 @@
thisExprType
| test.cpp:11:5:11:5 | this | file://:0:0:0:0 | C * |
| test.cpp:16:5:16:8 | this | file://:0:0:0:0 | C * |
| test.cpp:21:12:21:12 | this | file://:0:0:0:0 | const C * |
| test.cpp:26:12:26:12 | this | file://:0:0:0:0 | volatile C * |
| test.cpp:31:12:31:12 | this | file://:0:0:0:0 | const volatile C * |
| test.cpp:41:12:41:12 | this | file://:0:0:0:0 | const C * |
| test.cpp:46:12:46:12 | this | file://:0:0:0:0 | C * |
| test.cpp:66:5:66:5 | this | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |
| test.cpp:66:5:66:5 | this | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
| test.cpp:71:5:71:8 | this | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |
| test.cpp:71:5:71:8 | this | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
| test.cpp:76:12:76:12 | this | file://:0:0:0:0 | const InstantiatedTemplateClass<T> * |
| test.cpp:76:12:76:12 | this | file://:0:0:0:0 | const InstantiatedTemplateClass<int> * |
| test.cpp:81:12:81:12 | this | file://:0:0:0:0 | volatile InstantiatedTemplateClass<T> * |
| test.cpp:81:12:81:12 | this | file://:0:0:0:0 | volatile InstantiatedTemplateClass<int> * |
| test.cpp:86:12:86:12 | this | file://:0:0:0:0 | const volatile InstantiatedTemplateClass<T> * |
| test.cpp:86:12:86:12 | this | file://:0:0:0:0 | const volatile InstantiatedTemplateClass<int> * |
| test.cpp:96:12:96:12 | this | file://:0:0:0:0 | const InstantiatedTemplateClass<T> * |
| test.cpp:96:12:96:12 | this | file://:0:0:0:0 | const InstantiatedTemplateClass<int> * |
| test.cpp:101:12:101:12 | this | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |
| test.cpp:101:12:101:12 | this | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
#select
| test.cpp:9:8:9:9 | f1 | file://:0:0:0:0 | C * |
| test.cpp:14:8:14:9 | f2 | file://:0:0:0:0 | C * |
| test.cpp:19:7:19:8 | f3 | file://:0:0:0:0 | const C * |
| test.cpp:24:7:24:8 | f4 | file://:0:0:0:0 | volatile C * |
| test.cpp:29:7:29:8 | f5 | file://:0:0:0:0 | const volatile C * |
| test.cpp:34:8:34:9 | f6 | file://:0:0:0:0 | C * |
| test.cpp:39:9:39:10 | f7 | file://:0:0:0:0 | const C * |
| test.cpp:44:9:44:10 | f8 | file://:0:0:0:0 | C * |
| test.cpp:53:8:53:8 | f | file://:0:0:0:0 | D * |
| test.cpp:64:8:64:8 | f1 | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
| test.cpp:64:8:64:9 | f1 | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |
| test.cpp:69:8:69:8 | f2 | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
| test.cpp:69:8:69:9 | f2 | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |
| test.cpp:74:7:74:7 | f3 | file://:0:0:0:0 | const InstantiatedTemplateClass<int> * |
| test.cpp:74:7:74:8 | f3 | file://:0:0:0:0 | const InstantiatedTemplateClass<T> * |
| test.cpp:79:7:79:7 | f4 | file://:0:0:0:0 | volatile InstantiatedTemplateClass<int> * |
| test.cpp:79:7:79:8 | f4 | file://:0:0:0:0 | volatile InstantiatedTemplateClass<T> * |
| test.cpp:84:7:84:7 | f5 | file://:0:0:0:0 | const volatile InstantiatedTemplateClass<int> * |
| test.cpp:84:7:84:8 | f5 | file://:0:0:0:0 | const volatile InstantiatedTemplateClass<T> * |
| test.cpp:89:8:89:8 | f6 | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
| test.cpp:89:8:89:9 | f6 | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |
| test.cpp:94:9:94:9 | f7 | file://:0:0:0:0 | const InstantiatedTemplateClass<int> * |
| test.cpp:94:9:94:10 | f7 | file://:0:0:0:0 | const InstantiatedTemplateClass<T> * |
| test.cpp:99:9:99:9 | f8 | file://:0:0:0:0 | InstantiatedTemplateClass<int> * |
| test.cpp:99:9:99:10 | f8 | file://:0:0:0:0 | InstantiatedTemplateClass<T> * |

View File

@@ -0,0 +1,6 @@
import cpp
query predicate thisExprType(ThisExpr e, Type t) { t = e.getType() }
from MemberFunction f
select f, f.getTypeOfThis()

View File

@@ -9,25 +9,9 @@ uniqueEnclosingCallable
| misc.c:210:24:210:28 | ... + ... | Node should have one enclosing callable but has 0. |
| misc.c:210:28:210:28 | 1 | Node should have one enclosing callable but has 0. |
uniqueTypeBound
| bad_asts.cpp:19:10:19:10 | constructor init of field x [post-this] | Node should have one type bound but has 0. |
| bad_asts.cpp:19:10:19:10 | constructor init of field x [pre-this] | Node should have one type bound but has 0. |
| bad_asts.cpp:19:10:19:10 | constructor init of field y [post-this] | Node should have one type bound but has 0. |
| bad_asts.cpp:19:10:19:10 | constructor init of field y [pre-this] | Node should have one type bound but has 0. |
| cpp17.cpp:15:5:15:45 | call to unknown function | Node should have one type bound but has 0. |
| ir.cpp:784:15:784:15 | constructor init of field middlevb2_s [post-this] | Node should have one type bound but has 0. |
| ir.cpp:784:15:784:15 | constructor init of field middlevb2_s [pre-this] | Node should have one type bound but has 0. |
| static_init_templates.cpp:240:7:240:7 | constructor init of field mcc [post-this] | Node should have one type bound but has 0. |
| static_init_templates.cpp:240:7:240:7 | constructor init of field mcc [pre-this] | Node should have one type bound but has 0. |
uniqueTypeRepr
| bad_asts.cpp:19:10:19:10 | constructor init of field x [post-this] | Node should have one type representation but has 0. |
| bad_asts.cpp:19:10:19:10 | constructor init of field x [pre-this] | Node should have one type representation but has 0. |
| bad_asts.cpp:19:10:19:10 | constructor init of field y [post-this] | Node should have one type representation but has 0. |
| bad_asts.cpp:19:10:19:10 | constructor init of field y [pre-this] | Node should have one type representation but has 0. |
| cpp17.cpp:15:5:15:45 | call to unknown function | Node should have one type representation but has 0. |
| ir.cpp:784:15:784:15 | constructor init of field middlevb2_s [post-this] | Node should have one type representation but has 0. |
| ir.cpp:784:15:784:15 | constructor init of field middlevb2_s [pre-this] | Node should have one type representation but has 0. |
| static_init_templates.cpp:240:7:240:7 | constructor init of field mcc [post-this] | Node should have one type representation but has 0. |
| static_init_templates.cpp:240:7:240:7 | constructor init of field mcc [pre-this] | Node should have one type representation but has 0. |
uniqueNodeLocation
| break_labels.c:2:11:2:11 | i | Node should have one location but has 4. |
| break_labels.c:2:11:2:11 | x | Node should have one location but has 4. |

View File

@@ -54,6 +54,7 @@
| file://:0:0:0:0 | char8_t |
| file://:0:0:0:0 | char16_t |
| file://:0:0:0:0 | char32_t |
| file://:0:0:0:0 | composite<B> * |
| file://:0:0:0:0 | composite<int> & |
| file://:0:0:0:0 | composite<int> && |
| file://:0:0:0:0 | composite<int> * |
@@ -156,6 +157,7 @@
| file://:0:0:0:0 | restrict |
| file://:0:0:0:0 | rule & |
| file://:0:0:0:0 | rule && |
| file://:0:0:0:0 | rule * |
| file://:0:0:0:0 | sealed |
| file://:0:0:0:0 | selectany |
| file://:0:0:0:0 | short |