Skip to content

Commit 28606c5

Browse files
committed
C++: Simplify normalizeExpr
This has a comparable but different set of FPs as the previous version. But arguably it's an improvement.
1 parent 9a94222 commit 28606c5

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,15 @@
1212
import cpp
1313
import semmle.code.cpp.commons.Exclusions
1414

15-
/**
16-
* Holds if `te` is an implicit `this`.
17-
*
18-
* ThisExpr.isCompilerGenerated() is currently not being extracted, so use a heuristic.
19-
*/
20-
predicate isCompilerGenerated(ThisExpr te) {
21-
exists(int line, int colStart, int colEnd |
22-
te.getLocation().hasLocationInfo(_, line, colStart, line, colEnd)
23-
|
24-
colStart = colEnd
25-
or
26-
exists(Call c | c.getQualifier() = te | c.getLocation() = te.getLocation())
27-
)
28-
}
29-
3015
/** Gets the sub-expression of 'e' with the earliest-starting Location */
3116
Expr normalizeExpr(Expr e) {
32-
if forex(Expr q | q = e.(Call).getQualifier() | not isCompilerGenerated(q))
33-
then result = normalizeExpr(e.(Call).getQualifier())
34-
else
35-
if forex(Expr q | q = e.(FieldAccess).getQualifier() | not isCompilerGenerated(q))
36-
then result = normalizeExpr(e.(FieldAccess).getQualifier())
37-
else
38-
if e.hasExplicitConversion()
39-
then result = normalizeExpr(e.getFullyConverted())
40-
else result = e
17+
result =
18+
min(Expr child |
19+
child.getParentWithConversions*() = e.getFullyConverted() and
20+
not child.getParentWithConversions*() = any(Call c).getAnArgument()
21+
|
22+
child order by child.getLocation().getStartColumn(), count(child.getParentWithConversions*())
23+
)
4124
}
4225

4326
predicate isParenthesized(CommaExpr ce) {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
| test.cpp:49:2:49:8 | (void)... | The indentation level may be misleading (for some tab sizes). |
2-
| test.cpp:52:8:52:8 | x | The indentation level may be misleading (for some tab sizes). |
2+
| test.cpp:52:2:52:15 | (void)... | The indentation level may be misleading (for some tab sizes). |
33
| test.cpp:160:3:160:9 | (void)... | The indentation level may be misleading (for some tab sizes). |
44
| test.cpp:166:5:166:7 | ... ++ | The indentation level may be misleading (for some tab sizes). |
55
| test.cpp:176:6:178:6 | ... ? ... : ... | The indentation level may be misleading (for some tab sizes). |

0 commit comments

Comments
 (0)