Skip to content

Commit ab0505e

Browse files
committed
CPP: Undo autoformat so that things can merge.
1 parent 3f70d91 commit ab0505e

File tree

1 file changed

+52
-70
lines changed

1 file changed

+52
-70
lines changed

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

Lines changed: 52 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,51 @@
99
* statistical
1010
* non-attributable
1111
*/
12-
1312
import cpp
1413

15-
string kindstr(Class c) {
14+
string kindstr(Class c)
15+
{
1616
exists(int kind | usertypes(unresolveElement(c), _, kind) |
17-
kind = 1 and result = "Struct"
18-
or
19-
kind = 2 and result = "Class"
20-
or
21-
kind = 6 and result = "Template class"
17+
(kind = 1 and result = "Struct") or
18+
(kind = 2 and result = "Class") or
19+
(kind = 6 and result = "Template class")
2220
)
2321
}
2422

25-
predicate vdeInfo(VariableDeclarationEntry vde, Class c, File f, int line) {
23+
predicate vdeInfo(VariableDeclarationEntry vde, Class c, File f, int line)
24+
{
2625
c = vde.getVariable().getDeclaringType() and
2726
f = vde.getLocation().getFile() and
2827
line = vde.getLocation().getStartLine()
2928
}
3029

31-
predicate previousVde(VariableDeclarationEntry previous, VariableDeclarationEntry vde) {
30+
predicate previousVde(VariableDeclarationEntry previous, VariableDeclarationEntry vde)
31+
{
3232
exists(Class c, File f, int line | vdeInfo(vde, c, f, line) |
33-
vdeInfo(previous, c, f, line - 3)
34-
or
35-
vdeInfo(previous, c, f, line - 2)
36-
or
37-
vdeInfo(previous, c, f, line - 1)
38-
or
39-
vdeInfo(previous, c, f, line) and
40-
exists(int prevCol, int vdeCol |
41-
prevCol = previous.getLocation().getStartColumn() and
42-
vdeCol = vde.getLocation().getStartColumn()
43-
|
44-
prevCol < vdeCol
45-
or
46-
prevCol = vdeCol and previous.getName() < vde.getName()
47-
)
33+
vdeInfo(previous, c, f, line - 3) or
34+
vdeInfo(previous, c, f, line - 2) or
35+
vdeInfo(previous, c, f, line - 1) or
36+
(vdeInfo(previous, c, f, line) and exists(int prevCol, int vdeCol |
37+
prevCol = previous.getLocation().getStartColumn() and vdeCol = vde.getLocation().getStartColumn() |
38+
prevCol < vdeCol or (prevCol = vdeCol and previous.getName() < vde.getName())
39+
))
4840
)
4941
}
5042

51-
predicate masterVde(VariableDeclarationEntry master, VariableDeclarationEntry vde) {
52-
not previousVde(_, vde) and master = vde
53-
or
54-
exists(VariableDeclarationEntry previous |
55-
previousVde(previous, vde) and masterVde(master, previous)
56-
)
43+
predicate masterVde(VariableDeclarationEntry master, VariableDeclarationEntry vde)
44+
{
45+
(not previousVde(_, vde) and master = vde) or
46+
exists(VariableDeclarationEntry previous | previousVde(previous, vde) and masterVde(master, previous))
5747
}
5848

5949
class VariableDeclarationGroup extends ElementBase {
6050
VariableDeclarationGroup() {
6151
this instanceof VariableDeclarationEntry and
6252
not previousVde(_, this)
6353
}
64-
65-
Class getClass() { vdeInfo(this, result, _, _) }
54+
Class getClass() {
55+
vdeInfo(this, result, _, _)
56+
}
6657

6758
// pragma[noopt] since otherwise the two locationInfo relations get join-ordered
6859
// after each other
@@ -72,26 +63,23 @@ class VariableDeclarationGroup extends ElementBase {
7263
masterVde(this, last) and
7364
this instanceof VariableDeclarationGroup and
7465
not previousVde(last, _) and
75-
exists(VariableDeclarationEntry vde |
76-
vde = this and vde instanceof VariableDeclarationEntry and vde.getLocation() = lstart
77-
) and
66+
exists(VariableDeclarationEntry vde | vde=this and vde instanceof VariableDeclarationEntry and vde.getLocation() = lstart) and
7867
last.getLocation() = lend and
7968
lstart.hasLocationInfo(path, startline, startcol, _, _) and
8069
lend.hasLocationInfo(path, _, _, endline, endcol)
8170
)
8271
}
8372

8473
string describeGroup() {
85-
if previousVde(this, _)
86-
then
87-
result = "group of " +
88-
strictcount(string name |
89-
exists(VariableDeclarationEntry vde |
90-
masterVde(this, vde) and
91-
name = vde.getName()
92-
)
93-
) + " fields here"
94-
else result = "declaration of " + this.(VariableDeclarationEntry).getVariable().getName()
74+
if previousVde(this, _) then
75+
result = "group of "
76+
+ strictcount(string name
77+
| exists(VariableDeclarationEntry vde
78+
| masterVde(this, vde) and
79+
name = vde.getName()))
80+
+ " fields here"
81+
else
82+
result = "declaration of " + this.(VariableDeclarationEntry).getVariable().getName()
9583
}
9684
}
9785

@@ -101,32 +89,26 @@ class ExtClass extends Class {
10189
}
10290

10391
predicate hasLocationInfo(string path, int startline, int startcol, int endline, int endcol) {
104-
if hasOneVariableGroup()
105-
then
106-
exists(VariableDeclarationGroup vdg | vdg.getClass() = this |
107-
vdg.hasLocationInfo(path, startline, startcol, endline, endcol)
108-
)
109-
else getLocation().hasLocationInfo(path, startline, startcol, endline, endcol)
92+
if hasOneVariableGroup() then
93+
exists(VariableDeclarationGroup vdg | vdg.getClass() = this | vdg.hasLocationInfo(path, startline, startcol, endline, endcol))
94+
else
95+
getLocation().hasLocationInfo(path, startline, startcol, endline, endcol)
11096
}
11197
}
11298

11399
from ExtClass c, int n, VariableDeclarationGroup vdg, string suffix
114-
where
115-
n = strictcount(string fieldName |
116-
exists(Field f |
117-
f.getDeclaringType() = c and
118-
fieldName = f.getName() and
119-
// IBOutlet's are a way of building GUIs
120-
// automatically out of ObjC properties.
121-
// We don't want to count those for the
122-
// purposes of this query.
123-
not f.getType().getAnAttribute().hasName("iboutlet")
124-
)
125-
) and
126-
n > 15 and
127-
not c.isConstructedFrom(_) and
128-
c = vdg.getClass() and
129-
if c.hasOneVariableGroup() then suffix = "" else suffix = " - see $@"
130-
select c,
131-
kindstr(c) + " " + c.getName() + " has " + n +
132-
" fields; we suggest refactoring to 15 fields or fewer" + suffix + ".", vdg, vdg.describeGroup()
100+
where n = strictcount(string fieldName
101+
| exists(Field f
102+
| f.getDeclaringType() = c and
103+
fieldName = f.getName() and
104+
// IBOutlet's are a way of building GUIs
105+
// automatically out of ObjC properties.
106+
// We don't want to count those for the
107+
// purposes of this query.
108+
not (f.getType().getAnAttribute().hasName("iboutlet")))) and
109+
n > 15 and
110+
not c.isConstructedFrom(_) and
111+
c = vdg.getClass() and
112+
if c.hasOneVariableGroup() then suffix = "" else suffix = " - see $@"
113+
select c, kindstr(c) + " " + c.getName() + " has " + n + " fields; we suggest refactoring to 15 fields or fewer" + suffix + ".",
114+
vdg, vdg.describeGroup()

0 commit comments

Comments
 (0)