Skip to content

Commit 854d0db

Browse files
committed
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.
1 parent 1d11a13 commit 854d0db

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

cpp/ql/src/Architecture/Refactoring Opportunities/ClassesWithManyFields.ql

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,39 @@ predicate masterVde(VariableDeclarationEntry master, VariableDeclarationEntry vd
4646
exists(VariableDeclarationEntry previous | previousVde(previous, vde) and masterVde(master, previous))
4747
}
4848

49-
class VariableDeclarationGroup extends @var_decl {
49+
class VariableDeclarationGroup extends VariableDeclarationEntry {
5050
VariableDeclarationGroup() {
51-
not previousVde(_, mkElement(this))
51+
not previousVde(_, this)
5252
}
5353
Class getClass() {
54-
vdeInfo(mkElement(this), result, _, _)
54+
vdeInfo(this, result, _, _)
5555
}
5656

5757
// pragma[noopt] since otherwise the two locationInfo relations get join-ordered
5858
// after each other
5959
pragma[noopt]
6060
predicate hasLocationInfo(string path, int startline, int startcol, int endline, int endcol) {
61-
exists(Element thisElement, VariableDeclarationEntry last, Location lstart, Location lend |
62-
thisElement = mkElement(this) and
63-
masterVde(thisElement, last) and
61+
exists(VariableDeclarationEntry last, Location lstart, Location lend |
62+
masterVde(this, last) and
6463
this instanceof VariableDeclarationGroup and
6564
not previousVde(last, _) and
66-
exists(VariableDeclarationEntry vde | vde=mkElement(this) and vde instanceof VariableDeclarationEntry and vde.getLocation() = lstart) and
65+
this.getLocation() = lstart and
6766
last.getLocation() = lend and
6867
lstart.hasLocationInfo(path, startline, startcol, _, _) and
6968
lend.hasLocationInfo(path, _, _, endline, endcol)
7069
)
7170
}
7271

73-
string toString() {
74-
if previousVde(mkElement(this), _) then
72+
string describeGroup() {
73+
if previousVde(this, _) then
7574
result = "group of "
7675
+ strictcount(string name
7776
| exists(VariableDeclarationEntry vde
78-
| masterVde(mkElement(this), vde) and
77+
| masterVde(this, vde) and
7978
name = vde.getName()))
8079
+ " fields here"
8180
else
82-
result = "declaration of " + mkElement(this).(VariableDeclarationEntry).getVariable().getName()
81+
result = "declaration of " + this.getVariable().getName()
8382
}
8483
}
8584

@@ -111,4 +110,4 @@ where n = strictcount(string fieldName
111110
c = vdg.getClass() and
112111
if c.hasOneVariableGroup() then suffix = "" else suffix = " - see $@"
113112
select c, kindstr(c) + " " + c.getName() + " has " + n + " fields, which is too many" + suffix + ".",
114-
vdg, vdg.toString()
113+
vdg, vdg.describeGroup()
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| 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 |
2-
| 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 |
3-
| 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 |
4-
| 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 |
5-
| 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 |
6-
| 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 |
7-
| 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 |
1+
| 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 |
2+
| 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 |
3+
| 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 |
4+
| 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 |
5+
| 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 |
6+
| 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 |
7+
| 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 |

0 commit comments

Comments
 (0)