mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Share entity base classes between CIL and source extraction
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
foreach (var childStmt in Stmt.Statements.Select(c => Statement.Create(cx, c, this, child)))
|
||||
foreach (var childStmt in Stmt.Statements.Select(c => Statement.Create(Context, c, this, child)))
|
||||
{
|
||||
child += childStmt.NumberOfStatements;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
var value = Stmt.Value;
|
||||
Expression.Create(cx, value, this, 0);
|
||||
Switch.LabelForValue(cx.GetModel(Stmt).GetConstantValue(value).Value);
|
||||
Expression.Create(Context, value, this, 0);
|
||||
Switch.LabelForValue(Context.GetModel(Stmt).GetConstantValue(value).Value);
|
||||
}
|
||||
|
||||
public static CaseLabel Create(Context cx, CaseSwitchLabelSyntax node, Switch parent, int child)
|
||||
@@ -70,11 +70,11 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expressions.Pattern.Create(cx, Stmt.Pattern, this, 0);
|
||||
Expressions.Pattern.Create(Context, Stmt.Pattern, this, 0);
|
||||
|
||||
if (Stmt.WhenClause != null)
|
||||
{
|
||||
Expression.Create(cx, Stmt.WhenClause.Condition, this, 1);
|
||||
Expression.Create(Context, Stmt.WhenClause.Condition, this, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,26 +19,26 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
if (hasVariableDeclaration) // A catch clause of the form 'catch(Ex ex) { ... }'
|
||||
{
|
||||
var decl = Expressions.VariableDeclaration.Create(cx, Stmt.Declaration, false, this, 0);
|
||||
trapFile.catch_type(this, Type.Create(cx, decl.Type).TypeRef, true);
|
||||
var decl = Expressions.VariableDeclaration.Create(Context, Stmt.Declaration, false, this, 0);
|
||||
trapFile.catch_type(this, Type.Create(Context, decl.Type).TypeRef, true);
|
||||
}
|
||||
else if (isSpecificCatchClause) // A catch clause of the form 'catch(Ex) { ... }'
|
||||
{
|
||||
trapFile.catch_type(this, Type.Create(cx, cx.GetType(Stmt.Declaration.Type)).TypeRef, true);
|
||||
trapFile.catch_type(this, Type.Create(Context, Context.GetType(Stmt.Declaration.Type)).TypeRef, true);
|
||||
}
|
||||
else // A catch clause of the form 'catch { ... }'
|
||||
{
|
||||
var exception = Type.Create(cx, cx.Compilation.GetTypeByMetadataName(systemExceptionName));
|
||||
var exception = Type.Create(Context, Context.Compilation.GetTypeByMetadataName(systemExceptionName));
|
||||
trapFile.catch_type(this, exception, false);
|
||||
}
|
||||
|
||||
if (Stmt.Filter != null)
|
||||
{
|
||||
// For backward compatibility, the catch filter clause is child number 2.
|
||||
Expression.Create(cx, Stmt.Filter.FilterExpression, this, 2);
|
||||
Expression.Create(Context, Stmt.Filter.FilterExpression, this, 2);
|
||||
}
|
||||
|
||||
Create(cx, Stmt.Block, this, 1);
|
||||
Create(Context, Stmt.Block, this, 1);
|
||||
}
|
||||
|
||||
public static Catch Create(Context cx, CatchClauseSyntax node, Try parent, int child)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Statement.Create(cx, Stmt.Block, this, 0);
|
||||
Statement.Create(Context, Stmt.Block, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Stmt.Statement, this, 1);
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
Create(Context, Stmt.Statement, this, 1);
|
||||
Expression.Create(Context, Stmt.Condition, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
else
|
||||
cx.ModelError(Stmt, "Invalid expression statement");
|
||||
Context.ModelError(Stmt, "Invalid expression statement");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
Create(cx, Stmt.Statement, this, 0);
|
||||
VariableDeclarations.Populate(Context, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
Create(Context, Stmt.Statement, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,25 +22,25 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
var child = -1;
|
||||
|
||||
if (Stmt.Declaration != null)
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, child, childIncrement: -1);
|
||||
VariableDeclarations.Populate(Context, Stmt.Declaration, this, child, childIncrement: -1);
|
||||
|
||||
foreach (var init in Stmt.Initializers)
|
||||
{
|
||||
Expression.Create(cx, init, this, child--);
|
||||
Expression.Create(Context, init, this, child--);
|
||||
}
|
||||
|
||||
if (Stmt.Condition != null)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
Expression.Create(Context, Stmt.Condition, this, 0);
|
||||
}
|
||||
|
||||
child = 1;
|
||||
foreach (var inc in Stmt.Incrementors)
|
||||
{
|
||||
Expression.Create(cx, inc, this, child++);
|
||||
Expression.Create(Context, inc, this, child++);
|
||||
}
|
||||
|
||||
Statement.Create(cx, Stmt.Statement, this, 1 + Stmt.Incrementors.Count);
|
||||
Statement.Create(Context, Stmt.Statement, this, 1 + Stmt.Incrementors.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,23 +29,23 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 1);
|
||||
Expression.Create(Context, Stmt.Expression, this, 1);
|
||||
|
||||
var semanticModel = cx.GetModel(Stmt);
|
||||
var semanticModel = Context.GetModel(Stmt);
|
||||
var typeSymbol = semanticModel.GetDeclaredSymbol(Stmt);
|
||||
var type = typeSymbol.GetAnnotatedType();
|
||||
|
||||
var location = cx.CreateLocation(Stmt.Identifier.GetLocation());
|
||||
var location = Context.CreateLocation(Stmt.Identifier.GetLocation());
|
||||
|
||||
Expressions.VariableDeclaration.Create(cx, typeSymbol, type, Stmt.Type, location, Stmt.Type.IsVar, this, 0);
|
||||
Expressions.VariableDeclaration.Create(Context, typeSymbol, type, Stmt.Type, location, Stmt.Type.IsVar, this, 0);
|
||||
|
||||
Statement.Create(cx, Stmt.Statement, this, 2);
|
||||
Statement.Create(Context, Stmt.Statement, this, 2);
|
||||
|
||||
var info = semanticModel.GetForEachStatementInfo(Stmt);
|
||||
|
||||
if (info.Equals(default))
|
||||
{
|
||||
cx.ExtractionError("Could not get foreach statement info", null, cx.CreateLocation(this.ReportingLocation), severity: Util.Logging.Severity.Info);
|
||||
Context.ExtractionError("Could not get foreach statement info", null, Context.CreateLocation(this.ReportingLocation), severity: Util.Logging.Severity.Info);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,31 +53,31 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
if (info.GetEnumeratorMethod != null)
|
||||
{
|
||||
var m = Method.Create(cx, info.GetEnumeratorMethod);
|
||||
var m = Method.Create(Context, info.GetEnumeratorMethod);
|
||||
trapFile.foreach_stmt_desugar(this, m, ForeachSymbolType.GetEnumeratorMethod);
|
||||
}
|
||||
|
||||
if (info.MoveNextMethod != null)
|
||||
{
|
||||
var m = Method.Create(cx, info.MoveNextMethod);
|
||||
var m = Method.Create(Context, info.MoveNextMethod);
|
||||
trapFile.foreach_stmt_desugar(this, m, ForeachSymbolType.MoveNextMethod);
|
||||
}
|
||||
|
||||
if (info.DisposeMethod != null)
|
||||
{
|
||||
var m = Method.Create(cx, info.DisposeMethod);
|
||||
var m = Method.Create(Context, info.DisposeMethod);
|
||||
trapFile.foreach_stmt_desugar(this, m, ForeachSymbolType.DisposeMethod);
|
||||
}
|
||||
|
||||
if (info.CurrentProperty != null)
|
||||
{
|
||||
var p = Property.Create(cx, info.CurrentProperty);
|
||||
var p = Property.Create(Context, info.CurrentProperty);
|
||||
trapFile.foreach_stmt_desugar(this, p, ForeachSymbolType.CurrentProperty);
|
||||
}
|
||||
|
||||
if (info.ElementType != null)
|
||||
{
|
||||
var t = Type.Create(cx, info.ElementType);
|
||||
var t = Type.Create(Context, info.ElementType);
|
||||
trapFile.foreach_stmt_desugar(this, t, ForeachSymbolType.ElementType);
|
||||
}
|
||||
}
|
||||
@@ -97,9 +97,9 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Variable, this, 0);
|
||||
Expression.Create(cx, Stmt.Expression, this, 1);
|
||||
Statement.Create(cx, Stmt.Statement, this, 2);
|
||||
Expression.Create(Context, Stmt.Variable, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 1);
|
||||
Statement.Create(Context, Stmt.Statement, this, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
trapFile.exprorstmt_name(this, target);
|
||||
break;
|
||||
case StmtKind.GOTO_CASE:
|
||||
Expr = Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
ConstantValue = Switch.LabelForValue(cx.GetModel(Stmt).GetConstantValue(Stmt.Expression).Value);
|
||||
Expr = Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
ConstantValue = Switch.LabelForValue(Context.GetModel(Stmt).GetConstantValue(Stmt.Expression).Value);
|
||||
break;
|
||||
case StmtKind.GOTO_DEFAULT:
|
||||
ConstantValue = Switch.DefaultLabel;
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
Expression.Create(Context, Stmt.Condition, this, 0);
|
||||
|
||||
Create(cx, Stmt.Statement, this, 1);
|
||||
Create(Context, Stmt.Statement, this, 1);
|
||||
|
||||
if (Stmt.Else != null)
|
||||
Create(cx, Stmt.Else.Statement, this, 2);
|
||||
Create(Context, Stmt.Else.Statement, this, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
// For compatibility with the Mono extractor, make insert the labelled statement into the same block
|
||||
// as this one. The parent MUST be a block statement.
|
||||
labelledStmt = Statement.Create(cx, Stmt.Statement, parent, child + 1);
|
||||
labelledStmt = Statement.Create(Context, Stmt.Statement, parent, child + 1);
|
||||
}
|
||||
|
||||
public override int NumberOfStatements => 1 + labelledStmt.NumberOfStatements;
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, 0);
|
||||
cx.BindComments(this, Stmt.GetLocation());
|
||||
VariableDeclarations.Populate(Context, Stmt.Declaration, this, 0);
|
||||
Context.BindComments(this, Stmt.GetLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
get
|
||||
{
|
||||
var m = cx.GetModel(Stmt);
|
||||
var m = Context.GetModel(Stmt);
|
||||
return m.GetDeclaredSymbol(Stmt) as IMethodSymbol;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
/// <summary>
|
||||
/// Gets the function defined by this local statement.
|
||||
/// </summary>
|
||||
private Entities.LocalFunction Function => Entities.LocalFunction.Create(cx, Symbol);
|
||||
private Entities.LocalFunction Function => Entities.LocalFunction.Create(Context, Symbol);
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Statement.Create(cx, Stmt.Statement, this, 1);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
Statement.Create(Context, Stmt.Statement, this, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,17 +30,17 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
var childIndex = 0;
|
||||
|
||||
foreach (var section in Stmt.Sections)
|
||||
{
|
||||
foreach (var stmt in section.Labels.Select(label => Case<SwitchLabelSyntax>.Create(cx, label, this, childIndex)))
|
||||
foreach (var stmt in section.Labels.Select(label => Case<SwitchLabelSyntax>.Create(Context, label, this, childIndex)))
|
||||
{
|
||||
childIndex += stmt.NumberOfStatements;
|
||||
}
|
||||
|
||||
foreach (var stmt in section.Statements.Select(s => Create(cx, s, this, childIndex)))
|
||||
foreach (var stmt in section.Statements.Select(s => Create(Context, s, this, childIndex)))
|
||||
{
|
||||
childIndex += stmt.NumberOfStatements;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
var child = 1;
|
||||
foreach (var c in Stmt.Catches)
|
||||
{
|
||||
Catch.Create(cx, c, this, child++);
|
||||
Catch.Create(Context, c, this, child++);
|
||||
}
|
||||
|
||||
Create(cx, Stmt.Block, this, 0);
|
||||
Create(Context, Stmt.Block, this, 0);
|
||||
|
||||
if (Stmt.Finally != null)
|
||||
{
|
||||
Create(cx, Stmt.Finally.Block, this, -1);
|
||||
Create(Context, Stmt.Finally.Block, this, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Statement.Create(cx, Stmt.Block, this, 0);
|
||||
Statement.Create(Context, Stmt.Block, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Stmt.Block, this, 0);
|
||||
Create(Context, Stmt.Block, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Declaration != null)
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
VariableDeclarations.Populate(Context, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
|
||||
if (Stmt.Statement != null)
|
||||
Statement.Create(cx, Stmt.Statement, this, 1);
|
||||
Statement.Create(Context, Stmt.Statement, this, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
Create(cx, Stmt.Statement, this, 1);
|
||||
Expression.Create(Context, Stmt.Condition, this, 0);
|
||||
Create(Context, Stmt.Statement, this, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Expression.Create(Context, Stmt.Expression, this, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user