C++: Don't use dbtypes in ClassesWithManyFields.ql

This changes the test output because `VariableDeclarationGroup.toString`
changes to be the one inherited from VariableDeclarationEntry. This
should not affect the output as shown by any front end because
the string to be displayed to the user for a `$@` interpolation comes
from the following column instead.
This commit is contained in:
Jonas Jensen
2018-08-28 11:00:35 +02:00
parent 1d11a13230
commit 854d0db552
2 changed files with 18 additions and 19 deletions

View File

@@ -46,40 +46,39 @@ predicate masterVde(VariableDeclarationEntry master, VariableDeclarationEntry vd
exists(VariableDeclarationEntry previous | previousVde(previous, vde) and masterVde(master, previous))
}
class VariableDeclarationGroup extends @var_decl {
class VariableDeclarationGroup extends VariableDeclarationEntry {
VariableDeclarationGroup() {
not previousVde(_, mkElement(this))
not previousVde(_, this)
}
Class getClass() {
vdeInfo(mkElement(this), result, _, _)
vdeInfo(this, result, _, _)
}
// pragma[noopt] since otherwise the two locationInfo relations get join-ordered
// after each other
pragma[noopt]
predicate hasLocationInfo(string path, int startline, int startcol, int endline, int endcol) {
exists(Element thisElement, VariableDeclarationEntry last, Location lstart, Location lend |
thisElement = mkElement(this) and
masterVde(thisElement, last) and
exists(VariableDeclarationEntry last, Location lstart, Location lend |
masterVde(this, last) and
this instanceof VariableDeclarationGroup and
not previousVde(last, _) and
exists(VariableDeclarationEntry vde | vde=mkElement(this) and vde instanceof VariableDeclarationEntry and vde.getLocation() = lstart) and
this.getLocation() = lstart and
last.getLocation() = lend and
lstart.hasLocationInfo(path, startline, startcol, _, _) and
lend.hasLocationInfo(path, _, _, endline, endcol)
)
}
string toString() {
if previousVde(mkElement(this), _) then
string describeGroup() {
if previousVde(this, _) then
result = "group of "
+ strictcount(string name
| exists(VariableDeclarationEntry vde
| masterVde(mkElement(this), vde) and
| masterVde(this, vde) and
name = vde.getName()))
+ " fields here"
else
result = "declaration of " + mkElement(this).(VariableDeclarationEntry).getVariable().getName()
result = "declaration of " + this.getVariable().getName()
}
}
@@ -111,4 +110,4 @@ where n = strictcount(string fieldName
c = vdg.getClass() and
if c.hasOneVariableGroup() then suffix = "" else suffix = " - see $@"
select c, kindstr(c) + " " + c.getName() + " has " + n + " fields, which is too many" + suffix + ".",
vdg, vdg.toString()
vdg, vdg.describeGroup()

View File

@@ -1,7 +1,7 @@
| cwmf.cpp:8:3:9:12 | aa | Struct aa has 20 fields, which is too many. | cwmf.cpp:8:3:9:12 | group of 20 fields here | group of 20 fields here |
| cwmf.cpp:13:3:14:12 | bb | Class bb has 20 fields, which is too many. | cwmf.cpp:13:3:14:12 | group of 20 fields here | group of 20 fields here |
| cwmf.cpp:24:3:25:12 | dd<T> | Template class dd<T> has 20 fields, which is too many. | cwmf.cpp:24:3:25:12 | group of 20 fields here | group of 20 fields here |
| cwmf.cpp:30:3:31:12 | ee<U> | Template class ee<U> has 20 fields, which is too many. | cwmf.cpp:30:3:31:12 | group of 20 fields here | group of 20 fields here |
| cwmf.cpp:41:8:57:22 | MyParticle | Struct MyParticle has 30 fields, which is too many. | cwmf.cpp:41:8:57:22 | group of 30 fields here | group of 30 fields here |
| different_types.h:15:15:33:10 | DifferentTypes2 | Class DifferentTypes2 has 18 fields, which is too many. | different_types.h:15:15:33:10 | group of 18 fields here | group of 18 fields here |
| different_types.h:15:15:33:10 | DifferentTypes2 | Class DifferentTypes2 has 18 fields, which is too many. | different_types.h:15:15:33:10 | group of 18 fields here | group of 18 fields here |
| cwmf.cpp:8:3:9:12 | aa | Struct aa has 20 fields, which is too many. | cwmf.cpp:8:3:9:12 | definition of f1 | group of 20 fields here |
| cwmf.cpp:13:3:14:12 | bb | Class bb has 20 fields, which is too many. | cwmf.cpp:13:3:14:12 | definition of f1 | group of 20 fields here |
| cwmf.cpp:24:3:25:12 | dd<T> | Template class dd<T> has 20 fields, which is too many. | cwmf.cpp:24:3:25:12 | definition of f1 | group of 20 fields here |
| cwmf.cpp:30:3:31:12 | ee<U> | Template class ee<U> has 20 fields, which is too many. | cwmf.cpp:30:3:31:12 | definition of f1 | group of 20 fields here |
| cwmf.cpp:41:8:57:22 | MyParticle | Struct MyParticle has 30 fields, which is too many. | cwmf.cpp:41:8:57:22 | definition of isActive | group of 30 fields here |
| different_types.h:15:15:33:10 | DifferentTypes2 | Class DifferentTypes2 has 18 fields, which is too many. | different_types.h:15:15:33:10 | definition of i1 | group of 18 fields here |
| different_types.h:15:15:33:10 | DifferentTypes2 | Class DifferentTypes2 has 18 fields, which is too many. | different_types.h:15:15:33:10 | definition of i1 | group of 18 fields here |