mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C++: Simplify normalizeExpr
This has a comparable but different set of FPs as the previous version. But arguably it's an improvement.
This commit is contained in:
@@ -12,32 +12,15 @@
|
||||
import cpp
|
||||
import semmle.code.cpp.commons.Exclusions
|
||||
|
||||
/**
|
||||
* Holds if `te` is an implicit `this`.
|
||||
*
|
||||
* ThisExpr.isCompilerGenerated() is currently not being extracted, so use a heuristic.
|
||||
*/
|
||||
predicate isCompilerGenerated(ThisExpr te) {
|
||||
exists(int line, int colStart, int colEnd |
|
||||
te.getLocation().hasLocationInfo(_, line, colStart, line, colEnd)
|
||||
|
|
||||
colStart = colEnd
|
||||
or
|
||||
exists(Call c | c.getQualifier() = te | c.getLocation() = te.getLocation())
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the sub-expression of 'e' with the earliest-starting Location */
|
||||
Expr normalizeExpr(Expr e) {
|
||||
if forex(Expr q | q = e.(Call).getQualifier() | not isCompilerGenerated(q))
|
||||
then result = normalizeExpr(e.(Call).getQualifier())
|
||||
else
|
||||
if forex(Expr q | q = e.(FieldAccess).getQualifier() | not isCompilerGenerated(q))
|
||||
then result = normalizeExpr(e.(FieldAccess).getQualifier())
|
||||
else
|
||||
if e.hasExplicitConversion()
|
||||
then result = normalizeExpr(e.getFullyConverted())
|
||||
else result = e
|
||||
result =
|
||||
min(Expr child |
|
||||
child.getParentWithConversions*() = e.getFullyConverted() and
|
||||
not child.getParentWithConversions*() = any(Call c).getAnArgument()
|
||||
|
|
||||
child order by child.getLocation().getStartColumn(), count(child.getParentWithConversions*())
|
||||
)
|
||||
}
|
||||
|
||||
predicate isParenthesized(CommaExpr ce) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
| test.cpp:49:2:49:8 | (void)... | The indentation level may be misleading (for some tab sizes). |
|
||||
| test.cpp:52:8:52:8 | x | The indentation level may be misleading (for some tab sizes). |
|
||||
| test.cpp:52:2:52:15 | (void)... | The indentation level may be misleading (for some tab sizes). |
|
||||
| test.cpp:160:3:160:9 | (void)... | The indentation level may be misleading (for some tab sizes). |
|
||||
| test.cpp:166:5:166:7 | ... ++ | The indentation level may be misleading (for some tab sizes). |
|
||||
| test.cpp:176:6:178:6 | ... ? ... : ... | The indentation level may be misleading (for some tab sizes). |
|
||||
|
||||
Reference in New Issue
Block a user