mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
Merge pull request #16104 from hvitved/csharp/more-compiler-generated
C#: Mark more expressions as compiler generated
This commit is contained in:
@@ -32,7 +32,10 @@ private predicate shouldPrint(Element e, Location l) {
|
||||
}
|
||||
|
||||
private predicate isImplicitExpression(ControlFlowElement element) {
|
||||
element.(Expr).isImplicit() and not exists(element.getAChild())
|
||||
element.(Expr).isImplicit() and
|
||||
not element instanceof CastExpr and
|
||||
not element.(OperatorCall).getTarget() instanceof ImplicitConversionOperator and
|
||||
not element instanceof ElementInitializer
|
||||
}
|
||||
|
||||
private predicate isFilteredCompilerGenerated(Declaration d) {
|
||||
@@ -291,18 +294,6 @@ class ControlFlowElementNode extends ElementNode {
|
||||
controlFlowElement = element and
|
||||
// Removing implicit expressions
|
||||
not isImplicitExpression(element) and
|
||||
// Removing extra nodes that are generated for an `AssignOperation`
|
||||
not exists(AssignOperation ao |
|
||||
ao.hasExpandedAssignment() and
|
||||
(
|
||||
ao.getExpandedAssignment() = controlFlowElement or
|
||||
ao.getExpandedAssignment().getRValue() = controlFlowElement or
|
||||
ao.getExpandedAssignment().getRValue().(BinaryOperation).getLeftOperand() =
|
||||
controlFlowElement.getParent*() or
|
||||
ao.getExpandedAssignment().getRValue().(OperatorCall).getChild(0) =
|
||||
controlFlowElement.getParent*()
|
||||
)
|
||||
) and
|
||||
not isNotNeeded(element.getParent+()) and
|
||||
// LambdaExpr is both a Callable and a ControlFlowElement,
|
||||
// print it with the more specific CallableNode
|
||||
@@ -429,7 +420,7 @@ final class DeclarationWithAccessorsNode extends ElementNode {
|
||||
result.(ParametersNode).getParameterizable() = declaration
|
||||
or
|
||||
childIndex = 2 and
|
||||
result.(ElementNode).getElement() = declaration.(Property).getInitializer().getParent()
|
||||
result.(ElementNode).getElement() = declaration.(Property).getInitializer()
|
||||
or
|
||||
result.(ElementNode).getElement() =
|
||||
rank[childIndex - 2](Element a, string file, int line, int column, string name |
|
||||
@@ -462,12 +453,7 @@ final class FieldNode extends ElementNode {
|
||||
result.(AttributesNode).getAttributable() = field
|
||||
or
|
||||
childIndex = 1 and
|
||||
field.hasInitializer() and
|
||||
(
|
||||
if field.getDeclaringType() instanceof Enum
|
||||
then result.(ElementNode).getElement() = field.getInitializer()
|
||||
else result.(ElementNode).getElement() = field.getInitializer().getParent()
|
||||
)
|
||||
result.(ElementNode).getElement() = field.getInitializer()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ class Field extends Variable, AssignableMember, Attributable, TopLevelExprParent
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
override Expr getInitializer() { result = this.getChildExpr(0).getChildExpr(0) }
|
||||
final override Expr getInitializer() { result = this.getChildExpr(0).getChildExpr(0) }
|
||||
|
||||
/**
|
||||
* Holds if this field has an initial value. For example, the initial
|
||||
@@ -515,6 +515,4 @@ class EnumConstant extends MemberConstant {
|
||||
* ```
|
||||
*/
|
||||
predicate hasExplicitValue() { exists(this.getInitializer()) }
|
||||
|
||||
override Expr getInitializer() { result = this.getChildExpr(0) }
|
||||
}
|
||||
|
||||
@@ -67,7 +67,11 @@ class Expr extends ControlFlowElement, @expr {
|
||||
* Holds if this expression is generated by the compiler and does not appear
|
||||
* explicitly in the source code.
|
||||
*/
|
||||
predicate isImplicit() { compiler_generated(this) }
|
||||
final predicate isImplicit() {
|
||||
compiler_generated(this) or
|
||||
this =
|
||||
any(AssignOperation op).getExpandedAssignment().getRValue().getChildExpr(0).getAChildExpr+()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an expression that is the result of stripping (recursively) all
|
||||
|
||||
Reference in New Issue
Block a user