Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,504 changes: 1,504 additions & 0 deletions csharp/downgrades/a5765bf26f38b38424eeb97f83104b5f5b41db0d/old.dbscheme

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: Remove `@parameter` from `@control_flow_element`
compatibility: full
5 changes: 4 additions & 1 deletion csharp/ql/lib/printCfg.ql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import csharp
import semmle.code.csharp.controlflow.internal.ControlFlowGraph

external string selectedSourceFile();

Expand All @@ -22,14 +23,16 @@ external int selectedSourceColumn();
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

module ViewCfgQueryInput implements ControlFlow::ViewCfgQueryInputSig<File> {
private import semmle.code.csharp.controlflow.ControlFlowGraph

predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate cfgScopeSpan(
Callable scope, File file, int startLine, int startColumn, int endLine, int endColumn
Ast::Callable scope, File file, int startLine, int startColumn, int endLine, int endColumn
) {
file = scope.getFile() and
scope.getLocation().getStartLine() = startLine and
Expand Down
48 changes: 40 additions & 8 deletions csharp/ql/lib/semmle/code/csharp/Assignable.qll
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@
def = TPatternDefinition(result)
or
def = TAssignOperationDefinition(result)
or
def = TParameterDefaultDefinition(_, result)
}

/** A local variable declaration at the top-level of a pattern. */
Expand Down Expand Up @@ -308,10 +310,17 @@
exists(Callable c | p = c.getAParameter() |
c.hasBody()
or
// Same as `c.(Constructor).hasInitializer()`, but avoids negative recursion warning
c.getAChildExpr() instanceof @constructor_init_expr
c.(Constructor).hasInitializer()
)
} or
TParameterDefaultDefinition(Parameter p, Expr default) {

Check warning on line 316 in csharp/ql/lib/semmle/code/csharp/Assignable.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for newtype-branch Assignable::AssignableInternal::Cached::TParameterDefaultDefinition
exists(Callable c | p = c.getAParameter() |
c.hasBody()
or
c.(Constructor).hasInitializer()
) and
default = p.getDefaultValue()
} or
TAddressOfDefinition(AddressOfExpr aoe) or
TPatternDefinition(TopLevelPatternDecl tlpd) or
TAssignOperationDefinition(AssignOperation ao) {
Expand Down Expand Up @@ -349,6 +358,8 @@
any(AssignableDefinitions::PatternDefinition pd | result = pd.getDeclaration().getVariable())
or
def = any(AssignableDefinitions::InitializerDefinition init | result = init.getAssignable())
or
def = TParameterDefaultDefinition(result, _)
}

// Not defined by dispatch in order to avoid too conservative negative recursion error
Expand Down Expand Up @@ -492,11 +503,6 @@
exists(Ssa::ExplicitDefinition def | result = def.getAFirstReadAtNode(cfn) |
this = def.getADefinition()
)
or
exists(Ssa::ImplicitParameterDefinition def | result = def.getAFirstReadAtNode(cfn) |
this.(AssignableDefinitions::ImplicitParameterDefinition).getParameter() =
def.getParameter()
)
)
}

Expand Down Expand Up @@ -688,7 +694,33 @@

override string toString() { result = p.toString() }

override Location getLocation() { result = this.getTarget().getLocation() }
override Location getLocation() { result = p.getLocation() }
}

/**
* A default value assigned to a parameter.
*/
class ParameterDefaultDefinition extends AssignableDefinition, TParameterDefaultDefinition {
Parameter p;
Expr default;

ParameterDefaultDefinition() { this = TParameterDefaultDefinition(p, default) }

/** Gets the underlying parameter. */
Parameter getParameter() { result = p }

/** Gets the default value expression for the parameter. */
Expr getDefaultValue() { result = default }

override Expr getSource() { result = default }

override Expr getElement() { result = default }

override Callable getEnclosingCallable() { result = p.getCallable() }

override string toString() { result = p.toString() + " = ..." }

override Location getLocation() { result = default.getLocation() }
}

/**
Expand Down
10 changes: 2 additions & 8 deletions csharp/ql/lib/semmle/code/csharp/ExprOrStmtParent.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private import internal.Location
* An element that can have a child statement or expression.
*/
class ExprOrStmtParent extends Element, @exprorstmt_parent {
final override ControlFlowElement getChild(int i) {
override ControlFlowElement getChild(int i) {
result = this.getChildExpr(i) or
result = this.getChildStmt(i)
}
Expand Down Expand Up @@ -42,14 +42,8 @@ class ExprOrStmtParent extends Element, @exprorstmt_parent {
*
* An element that can have a child top-level expression.
*/
class TopLevelExprParent extends Element, @top_level_expr_parent {
class TopLevelExprParent extends ExprOrStmtParent, @top_level_expr_parent {
final override Expr getChild(int i) { result = this.getChildExpr(i) }

/** Gets the `i`th child expression of this element (zero-based). */
final Expr getChildExpr(int i) { expr_parent_top_level_adjusted(result, i, this) }

/** Gets a child expression of this element, if any. */
final Expr getAChildExpr() { result = this.getChildExpr(_) }
}

/** INTERNAL: Do not use. */
Expand Down
4 changes: 3 additions & 1 deletion csharp/ql/lib/semmle/code/csharp/PrintAst.qll
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ class ControlFlowElementNode extends ElementNode {
not isNotNeeded(element.getParent+()) and
// LambdaExpr is both a Callable and a ControlFlowElement,
// print it with the more specific CallableNode
not element instanceof Callable
not element instanceof Callable and
// Handled in `ParameterNode`
not element instanceof Parameter
}

override PrintAstNode getChild(int childIndex) {
Expand Down
4 changes: 3 additions & 1 deletion csharp/ql/lib/semmle/code/csharp/Variable.qll
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class LocalScopeVariable extends Variable, @local_scope_variable {
* }
* ```
*/
class Parameter extends LocalScopeVariable, Attributable, TopLevelExprParent, @parameter {
class Parameter extends LocalScopeVariable, Attributable, TopLevelExprParent, ControlFlowElement,
@parameter
{
/** Gets the raw position of this parameter, including the `this` parameter at index 0. */
final int getRawPosition() { this = this.getDeclaringElement().getRawParameter(result) }

Expand Down
Loading
Loading