зеркало из https://github.com/github/codeql.git
C#: Refactoring expression and statement population.
This commit is contained in:
Родитель
e41e8d6547
Коммит
486c192dda
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Semmle.Extraction.CIL
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
|
|
|
@ -30,9 +30,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public new Accessor OriginalDefinition => Create(Context, symbol.OriginalDefinition);
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(System.IO.TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers();
|
||||
ContainingType.ExtractGenerics();
|
||||
|
||||
|
@ -62,16 +62,16 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
return;
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.accessors(this, kind, symbol.Name, parent, unboundAccessor));
|
||||
trapFile.Emit(Tuples.accessors(this, kind, symbol.Name, parent, unboundAccessor));
|
||||
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.accessor_location(this, l));
|
||||
trapFile.Emit(Tuples.accessor_location(this, l));
|
||||
|
||||
Overrides();
|
||||
Overrides(trapFile);
|
||||
|
||||
if (symbol.FromSource() && Block == null)
|
||||
{
|
||||
Context.Emit(Tuples.compiler_generated(this));
|
||||
trapFile.Emit(Tuples.compiler_generated(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
|
@ -11,17 +12,27 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
{
|
||||
bool IExpressionParentEntity.IsTopLevelParent => true;
|
||||
|
||||
private readonly AttributeData AttributeData;
|
||||
private readonly IEntity Entity;
|
||||
|
||||
public Attribute(Context cx, AttributeData attribute, IEntity entity)
|
||||
: base(cx)
|
||||
{
|
||||
if (attribute.ApplicationSyntaxReference != null)
|
||||
AttributeData = attribute;
|
||||
Entity = entity;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
if (AttributeData.ApplicationSyntaxReference != null)
|
||||
{
|
||||
// !! Extract attributes from assemblies.
|
||||
// This is harder because the "expression" entities presume the
|
||||
// existence of a syntax tree. This is not the case for compiled
|
||||
// attributes.
|
||||
var syntax = attribute.ApplicationSyntaxReference.GetSyntax() as AttributeSyntax;
|
||||
ExtractAttribute(syntax, attribute.AttributeClass, entity);
|
||||
var syntax = AttributeData.ApplicationSyntaxReference.GetSyntax() as AttributeSyntax;
|
||||
ExtractAttribute(cx.TrapWriter.Writer, syntax, AttributeData.AttributeClass, Entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,18 +40,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
: base(cx)
|
||||
{
|
||||
var info = cx.GetSymbolInfo(attribute);
|
||||
ExtractAttribute(attribute, info.Symbol.ContainingType, entity);
|
||||
ExtractAttribute(cx.TrapWriter.Writer, attribute, info.Symbol.ContainingType, entity);
|
||||
}
|
||||
|
||||
void ExtractAttribute(AttributeSyntax syntax, ITypeSymbol attributeClass, IEntity entity)
|
||||
void ExtractAttribute(System.IO.TextWriter trapFile, AttributeSyntax syntax, ITypeSymbol attributeClass, IEntity entity)
|
||||
{
|
||||
var type = Type.Create(cx, attributeClass);
|
||||
cx.Emit(Tuples.attributes(this, type.TypeRef, entity));
|
||||
trapFile.Emit(Tuples.attributes(this, type.TypeRef, entity));
|
||||
|
||||
cx.Emit(Tuples.attribute_location(this, cx.Create(syntax.Name.GetLocation())));
|
||||
trapFile.Emit(Tuples.attribute_location(this, cx.Create(syntax.Name.GetLocation())));
|
||||
|
||||
if (cx.Extractor.OutputPath != null)
|
||||
cx.Emit(Tuples.attribute_location(this, Assembly.CreateOutputAssembly(cx)));
|
||||
trapFile.Emit(Tuples.attribute_location(this, Assembly.CreateOutputAssembly(cx)));
|
||||
|
||||
TypeMention.Create(cx, syntax.Name, this, type);
|
||||
|
||||
|
@ -54,7 +65,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
var expr = Expression.Create(cx, arg.Expression, this, child++);
|
||||
if (!(arg.NameEquals is null))
|
||||
{
|
||||
cx.Emit(Tuples.expr_argument_name(expr, arg.NameEquals.Name.Identifier.Text));
|
||||
trapFile.Emit(Tuples.expr_argument_name(expr, arg.NameEquals.Name.Identifier.Text));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
CommentBlock(Context cx, ICommentBlock init)
|
||||
: base(cx, init) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.commentblock(this));
|
||||
trapFile.Emit(Tuples.commentblock(this));
|
||||
int child = 0;
|
||||
Context.Emit(Tuples.commentblock_location(this, Context.Create(symbol.Location)));
|
||||
trapFile.Emit(Tuples.commentblock_location(this, Context.Create(symbol.Location)));
|
||||
foreach (var l in symbol.CommentLines)
|
||||
{
|
||||
Context.Emit(Tuples.commentblock_child(this, (CommentLine)l, child++));
|
||||
trapFile.Emit(Tuples.commentblock_child(this, (CommentLine)l, child++));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public void BindTo(Label entity, CommentBinding binding)
|
||||
{
|
||||
Context.Emit(Tuples.commentblock_binding(this, entity, binding));
|
||||
Context.TrapWriter.Writer.Emit(Tuples.commentblock_binding(this, entity, binding));
|
||||
}
|
||||
|
||||
public static CommentBlock Create(Context cx, ICommentBlock block) => CommentBlockFactory.Instance.CreateEntity(cx, block);
|
||||
|
|
|
@ -112,11 +112,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
Extraction.Entities.Location location;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
location = Context.Create(Location);
|
||||
Context.Emit(Tuples.commentline(this, Type == CommentLineType.MultilineContinuation ? CommentLineType.Multiline : Type, Text, RawText));
|
||||
Context.Emit(Tuples.commentline_location(this, location));
|
||||
trapFile.Emit(Tuples.commentline(this, Type == CommentLineType.MultilineContinuation ? CommentLineType.Multiline : Type, Text, RawText));
|
||||
trapFile.Emit(Tuples.commentline_location(this, location));
|
||||
}
|
||||
|
||||
public override Microsoft.CodeAnalysis.Location ReportingLocation => location.symbol;
|
||||
|
|
|
@ -1,57 +1,67 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
class Compilation : FreshEntity
|
||||
{
|
||||
string cwd;
|
||||
string[] args;
|
||||
|
||||
public Compilation(Context cx, string cwd, string[] args) : base(cx)
|
||||
{
|
||||
this.cwd = cwd;
|
||||
this.args = args;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Extraction.Entities.Assembly.CreateOutputAssembly(cx);
|
||||
|
||||
cx.Emit(Tuples.compilations(this, Extraction.Entities.File.PathAsDatabaseString(cwd)));
|
||||
trapFile.Emit(Tuples.compilations(this, Extraction.Entities.File.PathAsDatabaseString(cwd)));
|
||||
|
||||
// Arguments
|
||||
int index = 0;
|
||||
foreach(var arg in args)
|
||||
{
|
||||
cx.Emit(Tuples.compilation_args(this, index++, arg));
|
||||
trapFile.Emit(Tuples.compilation_args(this, index++, arg));
|
||||
}
|
||||
|
||||
// Files
|
||||
index = 0;
|
||||
foreach(var file in cx.Compilation.SyntaxTrees.Select(tree => Extraction.Entities.File.Create(cx, tree.FilePath)))
|
||||
{
|
||||
cx.Emit(Tuples.compilation_compiling_files(this, index++, file));
|
||||
trapFile.Emit(Tuples.compilation_compiling_files(this, index++, file));
|
||||
}
|
||||
|
||||
// References
|
||||
index = 0;
|
||||
foreach(var file in cx.Compilation.References.OfType<PortableExecutableReference>().Select(r => Extraction.Entities.File.Create(cx, r.FilePath)))
|
||||
{
|
||||
cx.Emit(Tuples.compilation_referencing_files(this, index++, file));
|
||||
trapFile.Emit(Tuples.compilation_referencing_files(this, index++, file));
|
||||
}
|
||||
|
||||
// Diagnostics
|
||||
index = 0;
|
||||
foreach(var diag in cx.Compilation.GetDiagnostics().Select(d => new Diagnostic(cx, d)))
|
||||
{
|
||||
cx.Emit(Tuples.diagnostic_for(diag, this, 0, index++));
|
||||
trapFile.Emit(Tuples.diagnostic_for(diag, this, 0, index++));
|
||||
}
|
||||
}
|
||||
|
||||
public void PopulatePerformance(PerformanceMetrics p)
|
||||
{
|
||||
var trapFile = cx.TrapWriter.Writer;
|
||||
int index = 0;
|
||||
foreach(float metric in p.Metrics)
|
||||
{
|
||||
cx.Emit(Tuples.compilation_time(this, -1, index++, metric));
|
||||
trapFile.Emit(Tuples.compilation_time(this, -1, index++, metric));
|
||||
}
|
||||
cx.Emit(Tuples.compilation_finished(this, (float)p.Total.Cpu.TotalSeconds, (float)p.Total.Elapsed.TotalSeconds));
|
||||
trapFile.Emit(Tuples.compilation_finished(this, (float)p.Total.Cpu.TotalSeconds, (float)p.Total.Elapsed.TotalSeconds));
|
||||
}
|
||||
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NoLabel;
|
||||
|
@ -61,10 +71,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
{
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NoLabel;
|
||||
|
||||
readonly Microsoft.CodeAnalysis.Diagnostic diagnostic;
|
||||
|
||||
public Diagnostic(Context cx, Microsoft.CodeAnalysis.Diagnostic diag) : base(cx)
|
||||
{
|
||||
cx.Emit(Tuples.diagnostics(this, (int)diag.Severity, diag.Id, diag.Descriptor.Title.ToString(),
|
||||
diag.GetMessage(), Extraction.Entities.Location.Create(cx, diag.Location)));
|
||||
diagnostic = diag;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.Emit(Tuples.diagnostics(this, (int)diagnostic.Severity, diagnostic.Id, diagnostic.Descriptor.Title.ToString(),
|
||||
diagnostic.GetMessage(), Extraction.Entities.Location.Create(cx, diagnostic.Location)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,24 +14,24 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
Constructor(Context cx, IMethodSymbol init)
|
||||
: base(cx, init) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers();
|
||||
ContainingType.ExtractGenerics();
|
||||
|
||||
Context.Emit(Tuples.constructors(this, symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition));
|
||||
Context.Emit(Tuples.constructor_location(this, Location));
|
||||
trapFile.Emit(Tuples.constructors(this, symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition));
|
||||
trapFile.Emit(Tuples.constructor_location(this, Location));
|
||||
|
||||
if (symbol.IsImplicitlyDeclared)
|
||||
{
|
||||
var lineCounts = new LineCounts() { Total = 2, Code = 1, Comment = 0 };
|
||||
Context.Emit(Tuples.numlines(this, lineCounts));
|
||||
trapFile.Emit(Tuples.numlines(this, lineCounts));
|
||||
}
|
||||
ExtractCompilerGenerated();
|
||||
ExtractCompilerGenerated(trapFile);
|
||||
}
|
||||
|
||||
protected override void ExtractInitializers()
|
||||
protected override void ExtractInitializers(TextWriter trapFile)
|
||||
{
|
||||
// Do not extract initializers for constructed types.
|
||||
if (!IsSourceDeclaration) return;
|
||||
|
@ -76,7 +76,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
return;
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.expr_call(init, target));
|
||||
trapFile.Emit(Tuples.expr_call(init, target));
|
||||
|
||||
int child = 0;
|
||||
foreach (var arg in initializer.ArgumentList.Arguments)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
|
@ -7,14 +8,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
Destructor(Context cx, IMethodSymbol init)
|
||||
: base(cx, init) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers();
|
||||
ContainingType.ExtractGenerics();
|
||||
|
||||
Context.Emit(Tuples.destructors(this, string.Format("~{0}", symbol.ContainingType.Name), ContainingType, OriginalDefinition(Context, this, symbol)));
|
||||
Context.Emit(Tuples.destructor_location(this, Location));
|
||||
trapFile.Emit(Tuples.destructors(this, string.Format("~{0}", symbol.ContainingType.Name), ContainingType, OriginalDefinition(Context, this, symbol)));
|
||||
trapFile.Emit(Tuples.destructor_location(this, Location));
|
||||
}
|
||||
|
||||
static new Destructor OriginalDefinition(Context cx, Destructor original, IMethodSymbol symbol)
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
trapFile.Write(";event");
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractNullability(symbol.NullableAnnotation);
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
Context.Emit(Tuples.events(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition)));
|
||||
|
@ -44,14 +44,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
|
||||
{
|
||||
Context.Emit(Tuples.explicitly_implements(this, explicitInterface.TypeRef));
|
||||
trapFile.Emit(Tuples.explicitly_implements(this, explicitInterface.TypeRef));
|
||||
|
||||
foreach (var syntax in declSyntaxReferences.OfType<EventDeclarationSyntax>())
|
||||
TypeMention.Create(Context, syntax.ExplicitInterfaceSpecifier.Name, this, explicitInterface);
|
||||
}
|
||||
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.event_location(this, l));
|
||||
trapFile.Emit(Tuples.event_location(this, l));
|
||||
|
||||
foreach (var syntaxType in declSyntaxReferences.OfType<VariableDeclaratorSyntax>().
|
||||
Select(d => d.Parent).
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
|
@ -12,9 +13,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
/// </summary>
|
||||
IEventSymbol EventSymbol => symbol.AssociatedSymbol as IEventSymbol;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
ContainingType.ExtractGenerics();
|
||||
|
||||
var @event = EventSymbol;
|
||||
|
@ -43,12 +44,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
return;
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.event_accessors(this, kind, symbol.Name, parent, unboundAccessor));
|
||||
trapFile.Emit(Tuples.event_accessors(this, kind, symbol.Name, parent, unboundAccessor));
|
||||
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.event_accessor_location(this, l));
|
||||
trapFile.Emit(Tuples.event_accessor_location(this, l));
|
||||
|
||||
Overrides();
|
||||
Overrides(trapFile);
|
||||
}
|
||||
|
||||
public new static EventAccessor Create(Context cx, IMethodSymbol symbol) =>
|
||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
|
@ -18,6 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
class Expression : FreshEntity, IExpressionParentEntity
|
||||
{
|
||||
private readonly IExpressionInfo Info;
|
||||
public readonly AnnotatedType Type;
|
||||
public readonly Extraction.Entities.Location Location;
|
||||
public readonly ExprKind Kind;
|
||||
|
@ -25,24 +27,29 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
internal Expression(IExpressionInfo info)
|
||||
: base(info.Context)
|
||||
{
|
||||
Info = info;
|
||||
Location = info.Location;
|
||||
Kind = info.Kind;
|
||||
Type = info.Type;
|
||||
|
||||
if (Type.Type is null)
|
||||
Type = NullType.Create(cx);
|
||||
|
||||
cx.Emit(Tuples.expressions(this, Kind, Type.Type.TypeRef));
|
||||
if (info.Parent.IsTopLevelParent)
|
||||
cx.Emit(Tuples.expr_parent_top_level(this, info.Child, info.Parent));
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
protected sealed override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.Emit(Tuples.expressions(this, Kind, Type.Type.TypeRef));
|
||||
if (Info.Parent.IsTopLevelParent)
|
||||
trapFile.Emit(Tuples.expr_parent_top_level(this, Info.Child, Info.Parent));
|
||||
else
|
||||
cx.Emit(Tuples.expr_parent(this, info.Child, info.Parent));
|
||||
cx.Emit(Tuples.expr_location(this, Location));
|
||||
trapFile.Emit(Tuples.expr_parent(this, Info.Child, Info.Parent));
|
||||
trapFile.Emit(Tuples.expr_location(this, Location));
|
||||
|
||||
if (info.IsCompilerGenerated)
|
||||
cx.Emit(Tuples.expr_compiler_generated(this));
|
||||
if (Info.IsCompilerGenerated)
|
||||
trapFile.Emit(Tuples.expr_compiler_generated(this));
|
||||
|
||||
if (info.ExprValue is string value)
|
||||
if (Info.ExprValue is string value)
|
||||
cx.Emit(Tuples.expr_value(this, value));
|
||||
|
||||
Type.Type.ExtractGenerics();
|
||||
|
@ -117,21 +124,20 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
/// </summary>
|
||||
/// <param name="cx">Context</param>
|
||||
/// <param name="node">The expression.</param>
|
||||
public void OperatorCall(ExpressionSyntax node)
|
||||
public void OperatorCall(TextWriter trapFile, ExpressionSyntax node)
|
||||
{
|
||||
var @operator = cx.GetSymbolInfo(node);
|
||||
if (@operator.Symbol is IMethodSymbol method)
|
||||
{
|
||||
|
||||
var callType = GetCallType(cx, node);
|
||||
if (callType == CallType.Dynamic)
|
||||
{
|
||||
UserOperator.OperatorSymbol(method.Name, out string operatorName);
|
||||
cx.Emit(Tuples.dynamic_member_name(this, operatorName));
|
||||
trapFile.Emit(Tuples.dynamic_member_name(this, operatorName));
|
||||
return;
|
||||
}
|
||||
|
||||
cx.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
|
||||
trapFile.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,18 +209,18 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
throw new InternalError(node, "Unable to locate a ConditionalAccessExpression");
|
||||
}
|
||||
|
||||
public void MakeConditional()
|
||||
public void MakeConditional(TextWriter trapFile)
|
||||
{
|
||||
cx.Emit(Tuples.conditional_access(this));
|
||||
trapFile.Emit(Tuples.conditional_access(this));
|
||||
}
|
||||
|
||||
public void PopulateArguments(BaseArgumentListSyntax args, int child)
|
||||
public void PopulateArguments(TextWriter trapFile, BaseArgumentListSyntax args, int child)
|
||||
{
|
||||
foreach (var arg in args.Arguments)
|
||||
PopulateArgument(arg, child++);
|
||||
PopulateArgument(trapFile, arg, child++);
|
||||
}
|
||||
|
||||
private void PopulateArgument(ArgumentSyntax arg, int child)
|
||||
private void PopulateArgument(TextWriter trapFile, ArgumentSyntax arg, int child)
|
||||
{
|
||||
var expr = Create(cx, arg.Expression, this, child);
|
||||
int mode;
|
||||
|
@ -235,11 +241,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
default:
|
||||
throw new InternalError(arg, "Unknown argument type");
|
||||
}
|
||||
cx.Emit(Tuples.expr_argument(expr, mode));
|
||||
trapFile.Emit(Tuples.expr_argument(expr, mode));
|
||||
|
||||
if (arg.NameColon != null)
|
||||
{
|
||||
cx.Emit(Tuples.expr_argument_name(expr, arg.NameColon.Name.Identifier.Text));
|
||||
trapFile.Emit(Tuples.expr_argument_name(expr, arg.NameColon.Name.Identifier.Text));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,11 +291,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
/// <see cref="Expression.Create(Context, ExpressionSyntax, IEntity, int, ITypeSymbol)"/> will
|
||||
/// still be valid.
|
||||
/// </summary>
|
||||
protected abstract void Populate();
|
||||
protected abstract void PopulateExpression(TextWriter trapFile);
|
||||
|
||||
protected Expression TryPopulate()
|
||||
protected new Expression TryPopulate()
|
||||
{
|
||||
cx.Try(Syntax, null, Populate);
|
||||
cx.Try(Syntax, null, ()=>PopulateExpression(cx.TrapWriter.Writer));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -8,7 +9,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
{
|
||||
ArgList(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.UNKNOWN)) { }
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
@ -18,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public abstract InitializerExpressionSyntax Initializer { get; }
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
var explicitlySized = false;
|
||||
|
@ -98,7 +99,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new ImplicitArrayCreation(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (Syntax.Initializer != null)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -20,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var operatorKind = OperatorKind;
|
||||
if (operatorKind.HasValue)
|
||||
|
@ -31,7 +32,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
var opexpr = new Expression(new ExpressionInfo(cx, Type, Location, operatorKind.Value, simpleAssignExpr, 0, false, null));
|
||||
Create(cx, Syntax.Left, opexpr, 0);
|
||||
Create(cx, Syntax.Right, opexpr, 1);
|
||||
opexpr.OperatorCall(Syntax);
|
||||
opexpr.OperatorCall(trapFile, Syntax);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -40,7 +41,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
if (Kind == ExprKind.ADD_EVENT || Kind == ExprKind.REMOVE_EVENT)
|
||||
{
|
||||
OperatorCall(Syntax);
|
||||
OperatorCall(trapFile, Syntax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Await(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -13,9 +14,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Binary(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
OperatorCall(Syntax);
|
||||
OperatorCall(trapFile, Syntax);
|
||||
CreateDeferred(cx, Syntax.Left, this, 0);
|
||||
CreateDeferred(cx, Syntax.Right, this, 1);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Cast(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
|
||||
|
@ -19,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
else
|
||||
{
|
||||
// Type conversion
|
||||
OperatorCall(Syntax);
|
||||
OperatorCall(trapFile, Syntax);
|
||||
TypeMention.Create(cx, Syntax.Type, this, Type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Checked(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Conditional(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Condition, this, 0);
|
||||
Create(cx, Syntax.WhenTrue, this, 1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Default(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
TypeAccess.Create(cx, Syntax.Type, this, 0);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using Semmle.Extraction.Kinds;
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -19,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
readonly ExpressionSyntax Qualifier;
|
||||
readonly BracketedArgumentListSyntax ArgumentList;
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (Kind == ExprKind.POINTER_INDIRECTION)
|
||||
{
|
||||
|
@ -27,7 +28,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
var add = new Expression(new ExpressionInfo(cx, qualifierInfo.Type, Location, ExprKind.ADD, this, 0, false, null));
|
||||
qualifierInfo.SetParent(add, 0);
|
||||
CreateFromNode(qualifierInfo);
|
||||
PopulateArguments(ArgumentList, 1);
|
||||
PopulateArguments(trapFile, ArgumentList, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
var indexer = symbolInfo.Symbol as IPropertySymbol;
|
||||
if (indexer != null)
|
||||
{
|
||||
cx.Emit(Tuples.expr_access(this, Indexer.Create(cx, indexer)));
|
||||
trapFile.Emit(Tuples.expr_access(this, Indexer.Create(cx, indexer)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +87,10 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new BindingElementAccess(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
base.Populate();
|
||||
MakeConditional();
|
||||
base.PopulateExpression(trapFile);
|
||||
MakeConditional(trapFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new ArrayInitializer(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
foreach (var e in Syntax.Expressions)
|
||||
|
@ -44,10 +45,10 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new ImplicitArrayInitializer(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
ArrayInitializer.Create(new ExpressionNodeInfo(cx, Syntax, this, -1));
|
||||
cx.Emit(Tuples.implicitly_typed_array_creation(this));
|
||||
trapFile.Emit(Tuples.implicitly_typed_array_creation(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +59,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new ObjectInitializer(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
|
||||
|
@ -98,7 +99,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new CollectionInitializer(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
foreach (var i in Syntax.Expressions)
|
||||
|
@ -110,7 +111,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
var invocation = new Expression(new ExpressionInfo(cx, voidType, cx.Create(i.GetLocation()), ExprKind.METHOD_INVOCATION, this, child++, false, null));
|
||||
|
||||
if (addMethod != null)
|
||||
cx.Emit(Tuples.expr_call(invocation, addMethod));
|
||||
trapFile.Emit(Tuples.expr_call(invocation, addMethod));
|
||||
else
|
||||
cx.ModelError(Syntax, "Unable to find an Add() method for collection initializer");
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new InterpolatedString(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
foreach (var c in Syntax.Contents)
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -18,11 +19,11 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Invocation(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (IsNameof(Syntax))
|
||||
{
|
||||
PopulateArguments(Syntax.ArgumentList, 0);
|
||||
PopulateArguments(trapFile, Syntax.ArgumentList, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
// Conditionally qualified method call; `x?.M()`
|
||||
memberName = memberBinding.Name.Identifier.Text;
|
||||
Create(cx, FindConditionalQualifier(memberBinding), this, child++);
|
||||
MakeConditional();
|
||||
MakeConditional(trapFile);
|
||||
break;
|
||||
case SimpleNameSyntax simpleName when (Kind == ExprKind.METHOD_INVOCATION):
|
||||
// Unqualified method call; `M()`
|
||||
|
@ -75,12 +76,12 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
if (isDynamicCall)
|
||||
{
|
||||
if (memberName != null)
|
||||
cx.Emit(Tuples.dynamic_member_name(this, memberName));
|
||||
trapFile.Emit(Tuples.dynamic_member_name(this, memberName));
|
||||
else
|
||||
cx.ModelError(Syntax, "Unable to get name for dynamic call.");
|
||||
}
|
||||
|
||||
PopulateArguments(Syntax.ArgumentList, child);
|
||||
PopulateArguments(trapFile, Syntax.ArgumentList, child);
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -148,7 +149,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
Expressions.TypeAccess.Create(cx, optionalType, this, 1);
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
switch (Syntax.Pattern)
|
||||
|
|
|
@ -5,6 +5,7 @@ using Microsoft.CodeAnalysis;
|
|||
using System.Collections.Generic;
|
||||
using Semmle.Util;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
{
|
||||
bool IStatementParentEntity.IsTopLevelParent => false;
|
||||
|
||||
protected override void Populate() { }
|
||||
protected override void PopulateExpression(TextWriter trapFile) { }
|
||||
|
||||
void VisitParameter(ParameterSyntax p)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ using Semmle.Extraction.Kinds;
|
|||
using Microsoft.CodeAnalysis;
|
||||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Literal(info).TryPopulate();
|
||||
|
||||
protected override void Populate() { }
|
||||
protected override void PopulateExpression(TextWriter trapFile) { }
|
||||
|
||||
static ExprKind GetKind(ExpressionNodeInfo info)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new MakeRef(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
public static Expression Create(ExpressionNodeInfo info, MemberBindingExpressionSyntax node)
|
||||
{
|
||||
var expr = Create(info, FindConditionalQualifier(node), node.Name);
|
||||
expr.MakeConditional();
|
||||
expr.MakeConditional(info.Context.TrapWriter.Writer);
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
@ -33,11 +34,11 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new ExplicitObjectCreation(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (Syntax.ArgumentList != null)
|
||||
{
|
||||
PopulateArguments(Syntax.ArgumentList, 0);
|
||||
PopulateArguments(trapFile, Syntax.ArgumentList, 0);
|
||||
}
|
||||
|
||||
var target = cx.GetModel(Syntax).GetSymbolInfo(Syntax);
|
||||
|
@ -45,14 +46,14 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
if (method != null)
|
||||
{
|
||||
cx.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
|
||||
trapFile.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
|
||||
}
|
||||
|
||||
if (IsDynamicObjectCreation(cx, Syntax))
|
||||
{
|
||||
var name = GetDynamicName(Syntax.Type);
|
||||
if (name.HasValue)
|
||||
cx.Emit(Tuples.dynamic_member_name(this, name.Value.Text));
|
||||
trapFile.Emit(Tuples.dynamic_member_name(this, name.Value.Text));
|
||||
else
|
||||
cx.ModelError(Syntax, "Unable to get name for dynamic object creation.");
|
||||
}
|
||||
|
@ -101,14 +102,14 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
public static Expression Create(ExpressionNodeInfo info) =>
|
||||
new ImplicitObjectCreation(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
var target = cx.GetSymbolInfo(Syntax);
|
||||
var method = (IMethodSymbol)target.Symbol;
|
||||
|
||||
if (method != null)
|
||||
{
|
||||
cx.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
|
||||
trapFile.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
|
||||
}
|
||||
var child = 0;
|
||||
|
||||
|
@ -129,7 +130,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
Property.Create(cx, property);
|
||||
|
||||
var access = new Expression(new ExpressionInfo(cx, type, loc, ExprKind.PROPERTY_ACCESS, assignment, 1, false, null));
|
||||
cx.Emit(Tuples.expr_access(access, propEntity));
|
||||
trapFile.Emit(Tuples.expr_access(access, propEntity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new PointerMemberAccess(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -17,15 +18,15 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info, ExpressionSyntax operand) => new PostfixUnary(info, info.Kind, operand).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Operand, this, 0);
|
||||
OperatorCall(Syntax);
|
||||
OperatorCall(trapFile, Syntax);
|
||||
|
||||
if ((OperatorKind == ExprKind.POST_INCR || OperatorKind == ExprKind.POST_DECR) &&
|
||||
Kind == ExprKind.OPERATOR_INVOCATION)
|
||||
{
|
||||
cx.Emit(Tuples.mutator_invocation_mode(this, 2));
|
||||
trapFile.Emit(Tuples.mutator_invocation_mode(this, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
{
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
if (!(Syntax.LeftOperand is null))
|
||||
Expression.Create(cx, Syntax.LeftOperand, this, 0);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Ref(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new RefType(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new RefValue(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
Create(cx, Syntax.Type, this, 1); // A type-access
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new SizeOf(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
TypeAccess.Create(cx, Syntax.Type, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public Expression SwitchedExpr { get; private set; }
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
SwitchedExpr = Expression.Create(cx, Syntax.GoverningExpression, this, -1);
|
||||
int child = 0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Throw(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
|
@ -12,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
{
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
int child = 0;
|
||||
foreach (var argument in Syntax.Arguments.Select(a => a.Expression))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -8,7 +9,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
{
|
||||
TypeAccess(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.TYPE_ACCESS)) { }
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
switch (Syntax.Kind())
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new TypeOf(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
TypeAccess.Create(cx, Syntax.Type, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -20,15 +21,15 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Operand, this, 0);
|
||||
OperatorCall(Syntax);
|
||||
OperatorCall(trapFile, Syntax);
|
||||
|
||||
if ((OperatorKind == ExprKind.PRE_INCR || OperatorKind == ExprKind.PRE_DECR) &&
|
||||
Kind == ExprKind.OPERATOR_INVOCATION)
|
||||
{
|
||||
cx.Emit(Tuples.mutator_invocation_mode(this, 1));
|
||||
trapFile.Emit(Tuples.mutator_invocation_mode(this, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
{
|
||||
|
@ -9,7 +10,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
|||
|
||||
public static Expression Create(ExpressionNodeInfo info) => new Unchecked(info).TryPopulate();
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Syntax.Expression, this, 0);
|
||||
}
|
||||
|
|
|
@ -25,15 +25,15 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
public override bool NeedsPopulation =>
|
||||
(base.NeedsPopulation && !symbol.IsImplicitlyDeclared) || symbol.ContainingType.IsTupleType;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractMetadataHandle();
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractAttributes();
|
||||
ContainingType.ExtractGenerics();
|
||||
ExtractNullability(symbol.NullableAnnotation);
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
|
||||
Field unboundFieldKey = Field.Create(Context, symbol.OriginalDefinition);
|
||||
Context.Emit(Tuples.fields(this, (symbol.IsConst ? 2 : 1), symbol.Name, ContainingType, Type.Type.TypeRef, unboundFieldKey));
|
||||
trapFile.Emit(Tuples.fields(this, (symbol.IsConst ? 2 : 1), symbol.Name, ContainingType, Type.Type.TypeRef, unboundFieldKey));
|
||||
|
||||
ExtractModifiers();
|
||||
|
||||
|
@ -46,12 +46,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
if (symbol.HasConstantValue)
|
||||
{
|
||||
Context.Emit(Tuples.constant_value(this, Expression.ValueAsString(symbol.ConstantValue)));
|
||||
trapFile.Emit(Tuples.constant_value(this, Expression.ValueAsString(symbol.ConstantValue)));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.field_location(this, l));
|
||||
trapFile.Emit(Tuples.field_location(this, l));
|
||||
|
||||
if (!IsSourceDeclaration || !symbol.FromSource())
|
||||
return;
|
||||
|
@ -86,7 +86,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
{
|
||||
// Mark fields that have explicit initializers.
|
||||
var expr = new Expression(new ExpressionInfo(Context, Type, Context.Create(initializer.EqualsValue.Value.FixedLocation()), Kinds.ExprKind.FIELD_ACCESS, this, child++, false, null));
|
||||
Context.Emit(Tuples.expr_access(expr, this));
|
||||
trapFile.Emit(Tuples.expr_access(expr, this));
|
||||
}
|
||||
|
||||
if (IsSourceDeclaration)
|
||||
|
|
|
@ -12,14 +12,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
Indexer OriginalDefinition => IsSourceDeclaration ? this : Create(Context, symbol.OriginalDefinition);
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractNullability(symbol.NullableAnnotation);
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
Context.Emit(Tuples.indexers(this, symbol.GetName(useMetadataName: true), ContainingType, type.TypeRef, OriginalDefinition));
|
||||
trapFile.Emit(Tuples.indexers(this, symbol.GetName(useMetadataName: true), ContainingType, type.TypeRef, OriginalDefinition));
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.indexer_location(this, l));
|
||||
trapFile.Emit(Tuples.indexer_location(this, l));
|
||||
|
||||
var getter = symbol.GetMethod;
|
||||
var setter = symbol.SetMethod;
|
||||
|
@ -60,7 +60,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
|
||||
{
|
||||
Context.Emit(Tuples.explicitly_implements(this, explicitInterface.TypeRef));
|
||||
trapFile.Emit(Tuples.explicitly_implements(this, explicitInterface.TypeRef));
|
||||
|
||||
foreach (var syntax in declSyntaxReferences)
|
||||
TypeMention.Create(Context, syntax.ExplicitInterfaceSpecifier.Name, this, explicitInterface);
|
||||
|
@ -71,7 +71,6 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
TypeMention.Create(Context, syntax.Type, this, type);
|
||||
}
|
||||
|
||||
|
||||
public static new Indexer Create(Context cx, IPropertySymbol prop) => IndexerFactory.Instance.CreateEntity(cx, prop);
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
|
|
|
@ -32,9 +32,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
public LocalFunction Create(Context cx, IMethodSymbol init) => new LocalFunction(cx, init);
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
|
||||
// There is a "bug" in Roslyn whereby the IMethodSymbol associated with the local function symbol
|
||||
// is always static, so we need to go to the syntax reference of the local function to see whether
|
||||
|
@ -49,8 +49,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
var originalDefinition = IsSourceDeclaration ? this : Create(Context, symbol.OriginalDefinition);
|
||||
var returnType = Type.Create(Context, symbol.ReturnType);
|
||||
Context.Emit(Tuples.local_functions(this, symbol.Name, returnType, originalDefinition));
|
||||
ExtractRefReturn();
|
||||
trapFile.Emit(Tuples.local_functions(this, symbol.Name, returnType, originalDefinition));
|
||||
ExtractRefReturn(trapFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,16 +27,16 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
tw.Write(";localvar");
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
if (symbol is ILocalSymbol local)
|
||||
{
|
||||
ExtractNullability(local.NullableAnnotation);
|
||||
ExtractNullability(trapFile, local.NullableAnnotation);
|
||||
if (local.IsRef)
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.localvars(
|
||||
trapFile.Emit(Tuples.localvars(
|
||||
this,
|
||||
IsRef ? 3 : IsConst ? 2 : 1,
|
||||
symbol.Name,
|
||||
|
@ -44,7 +44,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
Type.Type.TypeRef,
|
||||
Parent));
|
||||
|
||||
Context.Emit(Tuples.localvar_location(this, DeclLocation));
|
||||
trapFile.Emit(Tuples.localvar_location(this, DeclLocation));
|
||||
|
||||
DefineConstantValue();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
public Method(Context cx, IMethodSymbol init)
|
||||
: base(cx, init) { }
|
||||
|
||||
protected void ExtractParameters()
|
||||
protected void ExtractParameters(TextWriter trapFile)
|
||||
{
|
||||
var originalMethod = OriginalDefinition;
|
||||
IEnumerable<IParameterSymbol> parameters = symbol.Parameters;
|
||||
|
@ -56,13 +56,13 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
/// <summary>
|
||||
/// Extracts constructor initializers.
|
||||
/// </summary>
|
||||
protected virtual void ExtractInitializers()
|
||||
protected virtual void ExtractInitializers(TextWriter trapFile)
|
||||
{
|
||||
// Normal methods don't have initializers,
|
||||
// so there's nothing to extract.
|
||||
}
|
||||
|
||||
void ExtractMethodBody()
|
||||
void ExtractMethodBody(TextWriter trapFile)
|
||||
{
|
||||
if (!IsSourceDeclaration)
|
||||
return;
|
||||
|
@ -74,17 +74,17 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
Context.PopulateLater(
|
||||
() =>
|
||||
{
|
||||
ExtractInitializers();
|
||||
ExtractInitializers(trapFile);
|
||||
if (block != null)
|
||||
Statements.Block.Create(Context, block, this, 0);
|
||||
else
|
||||
Expression.Create(Context, expr, this, 0);
|
||||
|
||||
Context.NumberOfLines(symbol, this);
|
||||
Context.NumberOfLines(trapFile, symbol, this);
|
||||
});
|
||||
}
|
||||
|
||||
public void Overrides()
|
||||
public void Overrides(TextWriter trapFile)
|
||||
{
|
||||
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.
|
||||
Where(sym => sym.MethodKind == MethodKind.Ordinary).
|
||||
|
@ -99,7 +99,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
if (symbol.OverriddenMethod != null)
|
||||
{
|
||||
Context.Emit(Tuples.overrides(this, Method.Create(Context, symbol.OverriddenMethod)));
|
||||
trapFile.Emit(Tuples.overrides(this, Method.Create(Context, symbol.OverriddenMethod)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
bool IStatementParentEntity.IsTopLevelParent => true;
|
||||
|
||||
protected void ExtractGenerics()
|
||||
protected void ExtractGenerics(TextWriter trapFile)
|
||||
{
|
||||
var isFullyConstructed = IsBoundGeneric;
|
||||
|
||||
|
@ -340,47 +340,47 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
if (isFullyConstructed)
|
||||
{
|
||||
Context.Emit(Tuples.is_constructed(this));
|
||||
Context.Emit(Tuples.constructed_generic(this, Method.Create(Context, ConstructedFromSymbol)));
|
||||
trapFile.Emit(Tuples.is_constructed(this));
|
||||
trapFile.Emit(Tuples.constructed_generic(this, Method.Create(Context, ConstructedFromSymbol)));
|
||||
foreach (var tp in symbol.GetAnnotatedTypeArguments())
|
||||
{
|
||||
Context.Emit(Tuples.type_arguments(Type.Create(Context, tp.Symbol), child, this));
|
||||
trapFile.Emit(Tuples.type_arguments(Type.Create(Context, tp.Symbol), child, this));
|
||||
var ta = tp.Nullability.GetTypeAnnotation();
|
||||
if (ta != Kinds.TypeAnnotation.None)
|
||||
Context.Emit(Tuples.type_argument_annotation(this, child, ta));
|
||||
trapFile.Emit(Tuples.type_argument_annotation(this, child, ta));
|
||||
child++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Emit(Tuples.is_generic(this));
|
||||
trapFile.Emit(Tuples.is_generic(this));
|
||||
foreach (var typeParam in symbol.TypeParameters.Select(tp => TypeParameter.Create(Context, tp)))
|
||||
{
|
||||
Context.Emit(Tuples.type_parameters(typeParam, child, this));
|
||||
trapFile.Emit(Tuples.type_parameters(typeParam, child, this));
|
||||
child++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void ExtractRefReturn()
|
||||
protected void ExtractRefReturn(TextWriter trapFile)
|
||||
{
|
||||
if (symbol.ReturnsByRef)
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
if (symbol.ReturnsByRefReadonly)
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef));
|
||||
}
|
||||
|
||||
protected void PopulateMethod()
|
||||
protected void PopulateMethod(TextWriter trapFile)
|
||||
{
|
||||
// Common population code for all callables
|
||||
BindComments();
|
||||
ExtractAttributes();
|
||||
ExtractParameters();
|
||||
ExtractMethodBody();
|
||||
ExtractGenerics();
|
||||
ExtractMetadataHandle();
|
||||
ExtractNullability(symbol.ReturnNullableAnnotation);
|
||||
ExtractParameters(trapFile);
|
||||
ExtractMethodBody(trapFile);
|
||||
ExtractGenerics(trapFile);
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractNullability(trapFile, symbol.ReturnNullableAnnotation);
|
||||
}
|
||||
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.PushesLabel;
|
||||
|
|
|
@ -41,9 +41,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public override bool NeedsPopulation => true;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(new Tuple("modifiers", Label, symbol.name));
|
||||
trapFile.Emit(new Tuple("modifiers", Label, symbol.name));
|
||||
}
|
||||
|
||||
public static string AccessbilityModifier(Accessibility access)
|
||||
|
|
|
@ -10,14 +10,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public override Microsoft.CodeAnalysis.Location ReportingLocation => null;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.namespaces(this, symbol.Name));
|
||||
trapFile.Emit(Tuples.namespaces(this, symbol.Name));
|
||||
|
||||
if (symbol.ContainingNamespace != null)
|
||||
{
|
||||
Namespace parent = Create(Context, symbol.ContainingNamespace);
|
||||
Context.Emit(Tuples.parent_namespace(this, parent));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, parent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,29 +3,40 @@ using Microsoft.CodeAnalysis;
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
class NamespaceDeclaration : FreshEntity
|
||||
{
|
||||
private readonly NamespaceDeclaration Parent;
|
||||
private readonly NamespaceDeclarationSyntax Node;
|
||||
|
||||
public NamespaceDeclaration(Context cx, NamespaceDeclarationSyntax node, NamespaceDeclaration parent)
|
||||
: base(cx)
|
||||
{
|
||||
var ns = Namespace.Create(cx, (INamespaceSymbol)cx.GetModel(node).GetSymbolInfo(node.Name).Symbol);
|
||||
cx.Emit(Tuples.namespace_declarations(this, ns));
|
||||
cx.Emit(Tuples.namespace_declaration_location(this, cx.Create(node.Name.GetLocation())));
|
||||
Node = node;
|
||||
Parent = parent;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
var visitor = new Populators.TypeOrNamespaceVisitor(cx, this);
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
var ns = Namespace.Create(cx, (INamespaceSymbol)cx.GetModel(Node).GetSymbolInfo(Node.Name).Symbol);
|
||||
trapFile.Emit(Tuples.namespace_declarations(this, ns));
|
||||
trapFile.Emit(Tuples.namespace_declaration_location(this, cx.Create(Node.Name.GetLocation())));
|
||||
|
||||
foreach (var member in node.Members.Cast<CSharpSyntaxNode>().Concat(node.Usings))
|
||||
var visitor = new Populators.TypeOrNamespaceVisitor(cx, trapFile, this);
|
||||
|
||||
foreach (var member in Node.Members.Cast<CSharpSyntaxNode>().Concat(Node.Usings))
|
||||
{
|
||||
member.Accept(visitor);
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
if (Parent != null)
|
||||
{
|
||||
cx.Emit(Tuples.parent_namespace_declaration(this, parent));
|
||||
trapFile.Emit(Tuples.parent_namespace_declaration(this, Parent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.CSharp.Populators;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
|
@ -23,14 +24,14 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.GetSymbolLocation();
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers();
|
||||
ContainingType.ExtractGenerics();
|
||||
|
||||
var returnType = Type.Create(Context, symbol.ReturnType);
|
||||
Context.Emit(Tuples.methods(this, Name, ContainingType, returnType.TypeRef, OriginalDefinition));
|
||||
trapFile.Emit(Tuples.methods(this, Name, ContainingType, returnType.TypeRef, OriginalDefinition));
|
||||
|
||||
if (IsSourceDeclaration)
|
||||
foreach (var declaration in symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).OfType<MethodDeclarationSyntax>())
|
||||
|
@ -42,10 +43,10 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.method_location(this, l));
|
||||
|
||||
ExtractGenerics();
|
||||
Overrides();
|
||||
ExtractRefReturn();
|
||||
ExtractCompilerGenerated();
|
||||
ExtractGenerics(trapFile);
|
||||
Overrides(trapFile);
|
||||
ExtractRefReturn(trapFile);
|
||||
ExtractCompilerGenerated(trapFile);
|
||||
}
|
||||
|
||||
public new static OrdinaryMethod Create(Context cx, IMethodSymbol method) => OrdinaryMethodFactory.Instance.CreateEntity(cx, method);
|
||||
|
|
|
@ -100,17 +100,17 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
}
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractAttributes();
|
||||
ExtractNullability(symbol.NullableAnnotation);
|
||||
ExtractRefKind(symbol.RefKind);
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
ExtractRefKind(trapFile, symbol.RefKind);
|
||||
|
||||
if (symbol.Name != Original.symbol.Name)
|
||||
Context.ModelError(symbol, "Inconsistent parameter declaration");
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
Context.Emit(Tuples.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent, Original));
|
||||
trapFile.Emit(Tuples.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent, Original));
|
||||
|
||||
foreach (var l in symbol.Locations)
|
||||
Context.Emit(Tuples.param_location(this, Context.Create(l)));
|
||||
|
@ -183,10 +183,10 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
VarargsType(Context cx)
|
||||
: base(cx, null) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.types(this, Kinds.TypeKind.ARGLIST, "__arglist"));
|
||||
Context.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, Context.Compilation.GlobalNamespace)));
|
||||
trapFile.Emit(Tuples.types(this, Kinds.TypeKind.ARGLIST, "__arglist"));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, Context.Compilation.GlobalNamespace)));
|
||||
Modifier.HasModifier(Context, this, "public");
|
||||
}
|
||||
|
||||
|
@ -222,12 +222,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
VarargsParam(Context cx, Method methodKey)
|
||||
: base(cx, null, methodKey, null) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
var typeKey = VarargsType.Create(Context);
|
||||
// !! Maybe originaldefinition is wrong
|
||||
Context.Emit(Tuples.@params(this, "", typeKey, Ordinal, Kind.None, Parent, this));
|
||||
Context.Emit(Tuples.param_location(this, GeneratedLocation.Create(Context)));
|
||||
trapFile.Emit(Tuples.@params(this, "", typeKey, Ordinal, Kind.None, Parent, this));
|
||||
trapFile.Emit(Tuples.param_location(this, GeneratedLocation.Create(Context)));
|
||||
}
|
||||
|
||||
protected override int Ordinal => ((Method)Parent).OriginalDefinition.symbol.Parameters.Length;
|
||||
|
@ -262,11 +262,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
ConstructedType = method.symbol.ReceiverType;
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
var typeKey = Type.Create(Context, ConstructedType);
|
||||
Context.Emit(Tuples.@params(this, Original.symbol.Name, typeKey.TypeRef, 0, Kind.This, Parent, Original));
|
||||
Context.Emit(Tuples.param_location(this, Original.Location));
|
||||
trapFile.Emit(Tuples.@params(this, Original.symbol.Name, typeKey.TypeRef, 0, Kind.This, Parent, Original));
|
||||
trapFile.Emit(Tuples.param_location(this, Original.Location));
|
||||
}
|
||||
|
||||
public override int GetHashCode() => symbol.GetHashCode() + 31 * ConstructedType.GetHashCode();
|
||||
|
|
|
@ -22,17 +22,17 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
trapFile.Write(";property");
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractMetadataHandle();
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractAttributes();
|
||||
ExtractModifiers();
|
||||
BindComments();
|
||||
ExtractNullability(symbol.NullableAnnotation);
|
||||
ExtractRefKind(symbol.RefKind);
|
||||
ExtractNullability(trapFile, symbol.NullableAnnotation);
|
||||
ExtractRefKind(trapFile, symbol.RefKind);
|
||||
|
||||
var type = Type.Create(Context, symbol.Type);
|
||||
Context.Emit(Tuples.properties(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition)));
|
||||
trapFile.Emit(Tuples.properties(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition)));
|
||||
|
||||
var getter = symbol.GetMethod;
|
||||
var setter = symbol.SetMethod;
|
||||
|
@ -50,7 +50,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
|
||||
{
|
||||
Context.Emit(Tuples.explicitly_implements(this, explicitInterface.TypeRef));
|
||||
trapFile.Emit(Tuples.explicitly_implements(this, explicitInterface.TypeRef));
|
||||
|
||||
foreach (var syntax in declSyntaxReferences)
|
||||
TypeMention.Create(Context, syntax.ExplicitInterfaceSpecifier.Name, this, explicitInterface);
|
||||
|
|
|
@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
|
@ -40,6 +41,10 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
abstract class Statement<TSyntax> : Statement where TSyntax : CSharpSyntaxNode
|
||||
{
|
||||
protected readonly TSyntax Stmt;
|
||||
private readonly int Child;
|
||||
private readonly Kinds.StmtKind Kind;
|
||||
private readonly IStatementParentEntity Parent;
|
||||
private readonly Location Location;
|
||||
|
||||
protected override CSharpSyntaxNode GetStatementSyntax() => Stmt;
|
||||
|
||||
|
@ -47,33 +52,29 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
: base(cx)
|
||||
{
|
||||
Stmt = stmt;
|
||||
Parent = parent;
|
||||
Child = child;
|
||||
Location = location;
|
||||
Kind = kind;
|
||||
cx.BindComments(this, location.symbol);
|
||||
cx.Emit(Tuples.statements(this, kind));
|
||||
if (parent.IsTopLevelParent)
|
||||
cx.Emit(Tuples.stmt_parent_top_level(this, child, parent));
|
||||
else
|
||||
cx.Emit(Tuples.stmt_parent(this, child, parent));
|
||||
cx.Emit(Tuples.stmt_location(this, location));
|
||||
}
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
trapFile.Emit(Tuples.statements(this, Kind));
|
||||
if (Parent.IsTopLevelParent)
|
||||
trapFile.Emit(Tuples.stmt_parent_top_level(this, Child, Parent));
|
||||
else
|
||||
trapFile.Emit(Tuples.stmt_parent(this, Child, Parent));
|
||||
cx.Emit(Tuples.stmt_location(this, Location));
|
||||
PopulateStatement(trapFile);
|
||||
}
|
||||
|
||||
protected abstract void PopulateStatement(TextWriter trapFile);
|
||||
|
||||
protected Statement(Context cx, TSyntax stmt, Kinds.StmtKind kind, IStatementParentEntity parent, int child)
|
||||
: this(cx, stmt, kind, parent, child, cx.Create(stmt.FixedLocation())) { }
|
||||
|
||||
/// <summary>
|
||||
/// Populates statement-type specific relations in the trap file. The general relations
|
||||
/// <code>statements</code> and <code>stmt_location</code> are populated by the constructor
|
||||
/// (should not fail), so even if statement-type specific population fails (e.g., in
|
||||
/// standalone extraction), the statement created via
|
||||
/// <see cref="Statement.Create(Context, StatementSyntax, Statement, int)"/> will still
|
||||
/// be valid.
|
||||
/// </summary>
|
||||
protected abstract void Populate();
|
||||
|
||||
protected void TryPopulate()
|
||||
{
|
||||
cx.Try(Stmt, null, Populate);
|
||||
}
|
||||
|
||||
public override string ToString() => Label.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
|
@ -16,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
var child = 0;
|
||||
foreach (var childStmt in Stmt.Statements.Select(c => Statement.Create(cx, c, this, child)))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,6 +16,6 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate() { }
|
||||
protected override void PopulateStatement(TextWriter trapFile) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
CaseLabel(Context cx, CaseSwitchLabelSyntax node, Switch parent, int child)
|
||||
: base(cx, node, parent, child) { }
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
var value = Stmt.Value;
|
||||
Expression.Create(cx, value, this, 0);
|
||||
|
@ -52,7 +53,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
CaseDefault(Context cx, DefaultSwitchLabelSyntax node, Switch parent, int child)
|
||||
: base(cx, node, parent, child) { }
|
||||
|
||||
protected override void Populate() { }
|
||||
protected override void PopulateStatement(TextWriter trapFile) { }
|
||||
|
||||
public static CaseDefault Create(Context cx, DefaultSwitchLabelSyntax node, Switch parent, int child)
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
}
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
switch (Stmt.Pattern)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -12,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
Catch(Context cx, CatchClauseSyntax node, Try parent, int child)
|
||||
: base(cx, node, StmtKind.CATCH, parent, child, cx.Create(node.GetLocation())) { }
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
bool isSpecificCatchClause = Stmt.Declaration != null;
|
||||
bool hasVariableDeclaration = isSpecificCatchClause && Stmt.Declaration.Identifier.RawKind != 0;
|
||||
|
@ -20,16 +21,16 @@ 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);
|
||||
cx.Emit(Tuples.catch_type(this, decl.Type.Type.TypeRef, true));
|
||||
trapFile.Emit(Tuples.catch_type(this, decl.Type.Type.TypeRef, true));
|
||||
}
|
||||
else if (isSpecificCatchClause) // A catch clause of the form 'catch(Ex) { ... }'
|
||||
{
|
||||
cx.Emit(Tuples.catch_type(this, Type.Create(cx, cx.GetType(Stmt.Declaration.Type)).Type.TypeRef, true));
|
||||
trapFile.Emit(Tuples.catch_type(this, Type.Create(cx, cx.GetType(Stmt.Declaration.Type)).Type.TypeRef, true));
|
||||
}
|
||||
else // A catch clause of the form 'catch { ... }'
|
||||
{
|
||||
var exception = Type.Create(cx, cx.Compilation.GetTypeByMetadataName(SystemExceptionName));
|
||||
cx.Emit(Tuples.catch_type(this, exception, false));
|
||||
trapFile.Emit(Tuples.catch_type(this, exception, false));
|
||||
}
|
||||
|
||||
if (Stmt.Filter != null)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Statement.Create(cx, Stmt.Block, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate() { }
|
||||
protected override void PopulateStatement(TextWriter trapFile) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Stmt.Statement, this, 1);
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,6 +16,6 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate() { }
|
||||
protected override void PopulateStatement(TextWriter trapFile) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.CSharp.Entities.Expressions;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
Create(cx, Stmt.Statement, this, 0);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.CSharp.Entities.Expressions;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
int child = -1;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -17,7 +18,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter _)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 1);
|
||||
|
||||
|
@ -44,7 +45,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Variable, this, 0);
|
||||
Expression.Create(cx, Stmt.Expression, this, 1);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -30,7 +31,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
switch (GetKind(Stmt))
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -22,9 +23,9 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
cx.Emit(Tuples.exprorstmt_name(this, Stmt.Identifier.ToString()));
|
||||
trapFile.Emit(Tuples.exprorstmt_name(this, Stmt.Identifier.ToString()));
|
||||
|
||||
// For compatilibty with the Mono extractor, make insert the labelled statement into the same block
|
||||
// as this one. The parent MUST be a block statement.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.CSharp.Entities.Expressions;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -27,7 +28,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, 0);
|
||||
cx.BindComments(this, Stmt.GetLocation());
|
||||
|
|
|
@ -3,6 +3,7 @@ using Semmle.Extraction.Kinds;
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -40,9 +41,9 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
/// </summary>
|
||||
Entities.LocalFunction Function => Entities.LocalFunction.Create(cx, Symbol);
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
cx.Emit(Tuples.local_function_stmts(this, Function));
|
||||
trapFile.Emit(Tuples.local_function_stmts(this, Function));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
Statement.Create(cx, Stmt.Statement, this, 1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
|
@ -27,7 +28,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
int childIndex = 0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
Expression.Create(cx, Stmt.Expression, this, 0);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
var child = 1;
|
||||
foreach (var c in Stmt.Catches)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Statement.Create(cx, Stmt.Block, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Create(cx, Stmt.Block, this, 0);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.CSharp.Entities.Expressions;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -16,7 +17,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Declaration != null)
|
||||
VariableDeclarations.Populate(cx, Stmt.Declaration, this, -1, childIncrement: -1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
Expression.Create(cx, Stmt.Condition, this, 0);
|
||||
Create(cx, Stmt.Statement, this, 1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Kinds;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities.Statements
|
||||
{
|
||||
|
@ -15,7 +16,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
|
|||
return ret;
|
||||
}
|
||||
|
||||
protected override void Populate()
|
||||
protected override void PopulateStatement(TextWriter trapFile)
|
||||
{
|
||||
if (Stmt.Expression != null)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis;
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
@ -27,33 +28,33 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
Attribute.ExtractAttributes(Context, symbol, this);
|
||||
}
|
||||
|
||||
protected void ExtractNullability(NullableAnnotation annotation)
|
||||
protected void ExtractNullability(TextWriter trapFile, NullableAnnotation annotation)
|
||||
{
|
||||
var ta = annotation.GetTypeAnnotation();
|
||||
if (ta != Kinds.TypeAnnotation.None)
|
||||
Context.Emit(Tuples.type_annotation(this, ta));
|
||||
trapFile.Emit(Tuples.type_annotation(this, ta));
|
||||
}
|
||||
|
||||
protected void ExtractRefKind(RefKind kind)
|
||||
protected void ExtractRefKind(TextWriter trapFile, RefKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case RefKind.Out:
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Out));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Out));
|
||||
break;
|
||||
case RefKind.Ref:
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
break;
|
||||
case RefKind.RefReadOnly:
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ExtractCompilerGenerated()
|
||||
protected void ExtractCompilerGenerated(TextWriter trapFile)
|
||||
{
|
||||
if (symbol.IsImplicitlyDeclared)
|
||||
Context.Emit(Tuples.compiler_generated(this));
|
||||
trapFile.Emit(Tuples.compiler_generated(this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -124,12 +125,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public Extraction.Entities.Location Location => Context.Create(ReportingLocation);
|
||||
|
||||
protected void ExtractMetadataHandle()
|
||||
protected void ExtractMetadataHandle(TextWriter trapFile)
|
||||
{
|
||||
var handle = MetadataHandle;
|
||||
|
||||
if (handle.HasValue)
|
||||
Context.Emit(Tuples.metadata_handle(this, Location, MetadataTokens.GetToken(handle.Value)));
|
||||
trapFile.Emit(Tuples.metadata_handle(this, Location, MetadataTokens.GetToken(handle.Value)));
|
||||
}
|
||||
|
||||
public Handle? MetadataHandle
|
||||
|
|
|
@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
|||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Util;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
|
@ -48,19 +49,19 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
}
|
||||
}
|
||||
|
||||
void Populate()
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
switch (Syntax.Kind())
|
||||
{
|
||||
case SyntaxKind.ArrayType:
|
||||
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Create(cx, GetElementType(Syntax), this, GetElementType(Type));
|
||||
return;
|
||||
case SyntaxKind.NullableType:
|
||||
var nts = (NullableTypeSyntax)Syntax;
|
||||
if (Type is NamedType nt)
|
||||
{
|
||||
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Create(cx, nts.ElementType, this, nt.symbol.IsReferenceType ? nt : nt.TypeArguments[0]);
|
||||
}
|
||||
else if(Type is ArrayType array)
|
||||
|
@ -71,25 +72,25 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
case SyntaxKind.TupleType:
|
||||
var tts = (TupleTypeSyntax)Syntax;
|
||||
var tt = (TupleType)Type;
|
||||
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
tts.Elements.Zip(tt.TupleElements, (s, t) => Create(cx, s.Type, this, t.Type)).Enumerate();
|
||||
return;
|
||||
case SyntaxKind.PointerType:
|
||||
var pts = (PointerTypeSyntax)Syntax;
|
||||
var pt = (PointerType)Type;
|
||||
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Create(cx, pts.ElementType, this, pt.PointedAtType);
|
||||
return;
|
||||
case SyntaxKind.GenericName:
|
||||
var gns = (GenericNameSyntax)Syntax;
|
||||
Emit(Loc ?? gns.Identifier.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? gns.Identifier.GetLocation(), Parent, Type);
|
||||
cx.PopulateLater(() => gns.TypeArgumentList.Arguments.Zip(Type.TypeMentions, (s, t) => Create(cx, s, this, t)).Enumerate());
|
||||
return;
|
||||
case SyntaxKind.QualifiedName:
|
||||
if (Type.ContainingType == null)
|
||||
{
|
||||
// namespace qualifier
|
||||
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -100,21 +101,21 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
}
|
||||
return;
|
||||
default:
|
||||
Emit(Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
Emit(trapFile, Loc ?? Syntax.GetLocation(), Parent, Type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Emit(Microsoft.CodeAnalysis.Location loc, IEntity parent, Type type)
|
||||
void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity parent, Type type)
|
||||
{
|
||||
cx.Emit(Tuples.type_mention(this, type.TypeRef, parent));
|
||||
cx.Emit(Tuples.type_mention_location(this, cx.Create(loc)));
|
||||
trapFile.Emit(Tuples.type_mention(this, type.TypeRef, parent));
|
||||
trapFile.Emit(Tuples.type_mention_location(this, cx.Create(loc)));
|
||||
}
|
||||
|
||||
public static TypeMention Create(Context cx, TypeSyntax syntax, IEntity parent, Type type, Microsoft.CodeAnalysis.Location loc = null)
|
||||
{
|
||||
var ret = new TypeMention(cx, syntax, parent, type, loc);
|
||||
cx.Try(syntax, null, () => ret.Populate());
|
||||
cx.Try(syntax, null, () => ret.Populate(cx.TrapWriter.Writer));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
// be extracted in their defining assembly.
|
||||
public override bool NeedsPopulation => true;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.array_element_type(this, Dimension, Rank, element.Type.TypeRef));
|
||||
ExtractType();
|
||||
ExtractNullability(symbol.ElementNullableAnnotation);
|
||||
trapFile.Emit(Tuples.array_element_type(this, Dimension, Rank, element.Type.TypeRef));
|
||||
ExtractType(trapFile);
|
||||
ExtractNullability(trapFile, symbol.ElementNullableAnnotation);
|
||||
}
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
|
|
|
@ -13,13 +13,13 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public override Microsoft.CodeAnalysis.Location ReportingLocation => Context.Compilation.ObjectType.Locations.FirstOrDefault();
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.types(this, Kinds.TypeKind.DYNAMIC, "dynamic"));
|
||||
Context.Emit(Tuples.type_location(this, Location));
|
||||
trapFile.Emit(Tuples.types(this, Kinds.TypeKind.DYNAMIC, "dynamic"));
|
||||
trapFile.Emit(Tuples.type_location(this, Location));
|
||||
|
||||
Context.Emit(Tuples.has_modifiers(this, Modifier.Create(Context, "public")));
|
||||
Context.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, Context.Compilation.GlobalNamespace)));
|
||||
trapFile.Emit(Tuples.has_modifiers(this, Modifier.Create(Context, "public")));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, Context.Compilation.GlobalNamespace)));
|
||||
}
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
public override bool NeedsPopulation => base.NeedsPopulation || symbol.TypeKind == TypeKind.Error;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
if (symbol.TypeKind == TypeKind.Error)
|
||||
{
|
||||
|
@ -29,54 +29,54 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
return;
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.typeref_type((NamedTypeRef)TypeRef, this));
|
||||
trapFile.Emit(Tuples.typeref_type((NamedTypeRef)TypeRef, this));
|
||||
|
||||
if (symbol.IsGenericType)
|
||||
{
|
||||
if (symbol.IsBoundNullable())
|
||||
{
|
||||
// An instance of Nullable<T>
|
||||
Context.Emit(Tuples.nullable_underlying_type(this, Create(Context, symbol.TypeArguments[0]).TypeRef));
|
||||
trapFile.Emit(Tuples.nullable_underlying_type(this, Create(Context, symbol.TypeArguments[0]).TypeRef));
|
||||
}
|
||||
else if (symbol.IsReallyUnbound())
|
||||
{
|
||||
Context.Emit(Tuples.is_generic(this));
|
||||
trapFile.Emit(Tuples.is_generic(this));
|
||||
|
||||
for (int i = 0; i < symbol.TypeParameters.Length; ++i)
|
||||
{
|
||||
TypeParameter.Create(Context, symbol.TypeParameters[i]);
|
||||
var param = symbol.TypeParameters[i];
|
||||
var typeParameter = TypeParameter.Create(Context, param);
|
||||
Context.Emit(Tuples.type_parameters(typeParameter, i, this));
|
||||
trapFile.Emit(Tuples.type_parameters(typeParameter, i, this));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Emit(Tuples.is_constructed(this));
|
||||
Context.Emit(Tuples.constructed_generic(this, Type.Create(Context, symbol.ConstructedFrom).TypeRef));
|
||||
trapFile.Emit(Tuples.is_constructed(this));
|
||||
trapFile.Emit(Tuples.constructed_generic(this, Type.Create(Context, symbol.ConstructedFrom).TypeRef));
|
||||
|
||||
for (int i = 0; i < symbol.TypeArguments.Length; ++i)
|
||||
{
|
||||
var ta = symbol.TypeArgumentsNullableAnnotations[i].GetTypeAnnotation();
|
||||
if (ta != Kinds.TypeAnnotation.None)
|
||||
Context.Emit(Tuples.type_argument_annotation(this, i, ta));
|
||||
Context.Emit(Tuples.type_arguments(TypeArguments[i].TypeRef, i, this));
|
||||
trapFile.Emit(Tuples.type_argument_annotation(this, i, ta));
|
||||
trapFile.Emit(Tuples.type_arguments(TypeArguments[i].TypeRef, i, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExtractType();
|
||||
ExtractType(trapFile);
|
||||
|
||||
if (symbol.EnumUnderlyingType != null)
|
||||
{
|
||||
Context.Emit(Tuples.enum_underlying_type(this, Type.Create(Context, symbol.EnumUnderlyingType).TypeRef));
|
||||
trapFile.Emit(Tuples.enum_underlying_type(this, Type.Create(Context, symbol.EnumUnderlyingType).TypeRef));
|
||||
}
|
||||
|
||||
// Class location
|
||||
if (!symbol.IsGenericType || symbol.IsReallyUnbound())
|
||||
{
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.type_location(this, l));
|
||||
trapFile.Emit(Tuples.type_location(this, l));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,9 +183,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
trapFile.Write(";typeRef");
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.typerefs(this, symbol.Name));
|
||||
trapFile.Emit(Tuples.typerefs(this, symbol.Name));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
NullType(Context cx)
|
||||
: base(cx, null) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.types(this, Kinds.TypeKind.NULL, "null"));
|
||||
trapFile.Emit(Tuples.types(this, Kinds.TypeKind.NULL, "null"));
|
||||
}
|
||||
|
||||
public override void WriteId(TextWriter trapFile)
|
||||
|
|
|
@ -21,10 +21,10 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
// be extracted in their defining assembly.
|
||||
public override bool NeedsPopulation => true;
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
Context.Emit(Tuples.pointer_referent_type(this, PointedAtType.TypeRef));
|
||||
ExtractType();
|
||||
trapFile.Emit(Tuples.pointer_referent_type(this, PointedAtType.TypeRef));
|
||||
ExtractType(trapFile);
|
||||
}
|
||||
|
||||
public Type PointedAtType { get; private set; }
|
||||
|
|
|
@ -36,23 +36,23 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
trapFile.Write(";tuple");
|
||||
}
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
ExtractType();
|
||||
ExtractType(trapFile);
|
||||
ExtractGenerics();
|
||||
|
||||
var underlyingType = NamedType.Create(Context, symbol.TupleUnderlyingType);
|
||||
Context.Emit(Tuples.tuple_underlying_type(this, underlyingType));
|
||||
trapFile.Emit(Tuples.tuple_underlying_type(this, underlyingType));
|
||||
|
||||
int index = 0;
|
||||
foreach (var element in TupleElements)
|
||||
Context.Emit(Tuples.tuple_element(this, index++, element));
|
||||
trapFile.Emit(Tuples.tuple_element(this, index++, element));
|
||||
|
||||
// Note: symbol.Locations seems to be very inconsistent
|
||||
// about what locations are available for a tuple type.
|
||||
// Sometimes it's the source code, and sometimes it's empty.
|
||||
foreach (var l in symbol.Locations)
|
||||
Context.Emit(Tuples.type_location(this, Context.Create(l)));
|
||||
trapFile.Emit(Tuples.type_location(this, Context.Create(l)));
|
||||
}
|
||||
|
||||
readonly Lazy<Field[]> tupleElementsLazy;
|
||||
|
|
|
@ -78,35 +78,35 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
}
|
||||
}
|
||||
|
||||
protected void ExtractType()
|
||||
protected void ExtractType(TextWriter trapFile)
|
||||
{
|
||||
ExtractMetadataHandle();
|
||||
ExtractMetadataHandle(trapFile);
|
||||
ExtractAttributes();
|
||||
|
||||
var tb = new StringWriter();
|
||||
symbol.BuildDisplayName(Context, tb);
|
||||
Context.Emit(Tuples.types(this, GetClassType(Context, symbol), tb.ToString()));
|
||||
trapFile.Emit(Tuples.types(this, GetClassType(Context, symbol), tb.ToString()));
|
||||
|
||||
// Visit base types
|
||||
var baseTypes = new List<Type>();
|
||||
if (symbol.BaseType != null)
|
||||
{
|
||||
Type baseKey = Create(Context, symbol.BaseType);
|
||||
Context.Emit(Tuples.extend(this, baseKey.TypeRef));
|
||||
trapFile.Emit(Tuples.extend(this, baseKey.TypeRef));
|
||||
if (symbol.TypeKind != TypeKind.Struct)
|
||||
baseTypes.Add(baseKey);
|
||||
}
|
||||
|
||||
if (base.symbol.TypeKind == TypeKind.Interface)
|
||||
if (symbol.TypeKind == TypeKind.Interface)
|
||||
{
|
||||
Context.Emit(Tuples.extend(this, Create(Context, Context.Compilation.ObjectType)));
|
||||
trapFile.Emit(Tuples.extend(this, Create(Context, Context.Compilation.ObjectType)));
|
||||
}
|
||||
|
||||
if (!(base.symbol is IArrayTypeSymbol))
|
||||
{
|
||||
foreach (var t in base.symbol.Interfaces.Select(i=>Create(Context, i)))
|
||||
{
|
||||
Context.Emit(Tuples.implement(this, t.TypeRef));
|
||||
trapFile.Emit(Tuples.implement(this, t.TypeRef));
|
||||
baseTypes.Add(t);
|
||||
}
|
||||
}
|
||||
|
@ -115,11 +115,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
if (containingType != null && symbol.Kind != SymbolKind.TypeParameter)
|
||||
{
|
||||
Type originalDefinition = symbol.TypeKind == TypeKind.Error ? this : Create(Context, symbol.OriginalDefinition);
|
||||
Context.Emit(Tuples.nested_types(this, containingType, originalDefinition));
|
||||
trapFile.Emit(Tuples.nested_types(this, containingType, originalDefinition));
|
||||
}
|
||||
else if (symbol.ContainingNamespace != null)
|
||||
{
|
||||
Context.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, symbol.ContainingNamespace)));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, symbol.ContainingNamespace)));
|
||||
}
|
||||
|
||||
if (symbol is IArrayTypeSymbol)
|
||||
|
@ -128,7 +128,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
ITypeSymbol elementType = ((IArrayTypeSymbol)symbol).ElementType;
|
||||
INamespaceSymbol ns = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
|
||||
if (ns != null)
|
||||
Context.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, ns)));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, ns)));
|
||||
}
|
||||
|
||||
if (symbol is IPointerTypeSymbol)
|
||||
|
@ -137,7 +137,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
INamespaceSymbol ns = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
|
||||
|
||||
if (ns != null)
|
||||
Context.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, ns)));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, Namespace.Create(Context, ns)));
|
||||
}
|
||||
|
||||
if (symbol.BaseType != null && symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
|
||||
|
@ -157,11 +157,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
}
|
||||
|
||||
var returnKey = Create(Context, invokeMethod.ReturnType);
|
||||
Context.Emit(Tuples.delegate_return_type(this, returnKey.TypeRef));
|
||||
trapFile.Emit(Tuples.delegate_return_type(this, returnKey.TypeRef));
|
||||
if (invokeMethod.ReturnsByRef)
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.Ref));
|
||||
if (invokeMethod.ReturnsByRefReadonly)
|
||||
Context.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef));
|
||||
trapFile.Emit(Tuples.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef));
|
||||
}
|
||||
|
||||
Modifier.ExtractModifiers(Context, this, symbol);
|
||||
|
@ -251,11 +251,11 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
}
|
||||
}
|
||||
|
||||
public void ExtractRecursive(IEntity parent)
|
||||
public void ExtractRecursive(TextWriter trapFile, IEntity parent)
|
||||
{
|
||||
if (symbol.ContainingSymbol.Kind == SymbolKind.Namespace && !symbol.ContainingNamespace.IsGlobalNamespace)
|
||||
{
|
||||
Context.Emit(Tuples.parent_namespace_declaration(this, (NamespaceDeclaration)parent));
|
||||
trapFile.Emit(Tuples.parent_namespace_declaration(this, (NamespaceDeclaration)parent));
|
||||
}
|
||||
|
||||
ExtractRecursive();
|
||||
|
|
|
@ -21,49 +21,49 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
|
||||
static readonly string valueTypeName = typeof(System.ValueType).ToString();
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
var constraints = new TypeParameterConstraints(Context);
|
||||
Context.Emit(Tuples.type_parameter_constraints(constraints, this));
|
||||
trapFile.Emit(Tuples.type_parameter_constraints(constraints, this));
|
||||
|
||||
if (symbol.HasReferenceTypeConstraint)
|
||||
Context.Emit(Tuples.general_type_parameter_constraints(constraints, 1));
|
||||
trapFile.Emit(Tuples.general_type_parameter_constraints(constraints, 1));
|
||||
|
||||
if (symbol.HasValueTypeConstraint)
|
||||
Context.Emit(Tuples.general_type_parameter_constraints(constraints, 2));
|
||||
trapFile.Emit(Tuples.general_type_parameter_constraints(constraints, 2));
|
||||
|
||||
if (symbol.HasConstructorConstraint)
|
||||
Context.Emit(Tuples.general_type_parameter_constraints(constraints, 3));
|
||||
trapFile.Emit(Tuples.general_type_parameter_constraints(constraints, 3));
|
||||
|
||||
if(symbol.HasUnmanagedTypeConstraint)
|
||||
Context.Emit(Tuples.general_type_parameter_constraints(constraints, 4));
|
||||
trapFile.Emit(Tuples.general_type_parameter_constraints(constraints, 4));
|
||||
|
||||
ITypeSymbol baseType = symbol.HasValueTypeConstraint ?
|
||||
Context.Compilation.GetTypeByMetadataName(valueTypeName) :
|
||||
Context.Compilation.ObjectType;
|
||||
|
||||
if(symbol.ReferenceTypeConstraintNullableAnnotation == NullableAnnotation.Annotated)
|
||||
Context.Emit(Tuples.general_type_parameter_constraints(constraints, 5));
|
||||
trapFile.Emit(Tuples.general_type_parameter_constraints(constraints, 5));
|
||||
|
||||
foreach (var abase in symbol.GetAnnotatedTypeConstraints())
|
||||
{
|
||||
if (abase.Symbol.TypeKind != TypeKind.Interface)
|
||||
baseType = abase.Symbol;
|
||||
var t = Create(Context, abase.Symbol);
|
||||
Context.Emit(Tuples.specific_type_parameter_constraints(constraints, t.TypeRef));
|
||||
trapFile.Emit(Tuples.specific_type_parameter_constraints(constraints, t.TypeRef));
|
||||
if (abase.Nullability.GetTypeAnnotation() != Kinds.TypeAnnotation.None)
|
||||
Context.Emit(Tuples.specific_type_parameter_annotation(constraints, t.TypeRef, abase.Nullability.GetTypeAnnotation()));
|
||||
trapFile.Emit(Tuples.specific_type_parameter_annotation(constraints, t.TypeRef, abase.Nullability.GetTypeAnnotation()));
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.types(this, Semmle.Extraction.Kinds.TypeKind.TYPE_PARAMETER, symbol.Name));
|
||||
Context.Emit(Tuples.extend(this, Create(Context, baseType).TypeRef));
|
||||
trapFile.Emit(Tuples.types(this, Semmle.Extraction.Kinds.TypeKind.TYPE_PARAMETER, symbol.Name));
|
||||
trapFile.Emit(Tuples.extend(this, Create(Context, baseType).TypeRef));
|
||||
|
||||
Namespace parentNs = Namespace.Create(Context, symbol.TypeParameterKind == TypeParameterKind.Method ? Context.Compilation.GlobalNamespace : symbol.ContainingNamespace);
|
||||
Context.Emit(Tuples.parent_namespace(this, parentNs));
|
||||
trapFile.Emit(Tuples.parent_namespace(this, parentNs));
|
||||
|
||||
foreach (var l in symbol.Locations)
|
||||
{
|
||||
Context.Emit(Tuples.type_location(this, Context.Create(l)));
|
||||
trapFile.Emit(Tuples.type_location(this, Context.Create(l)));
|
||||
}
|
||||
|
||||
if (this.IsSourceDeclaration)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
class TypeParameterConstraints : FreshEntity
|
||||
|
@ -6,5 +8,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
: base(cx) { }
|
||||
|
||||
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NoLabel;
|
||||
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
protected UserOperator(Context cx, IMethodSymbol init)
|
||||
: base(cx, init) { }
|
||||
|
||||
public override void Populate()
|
||||
public override void Populate(TextWriter trapFile)
|
||||
{
|
||||
PopulateMethod();
|
||||
PopulateMethod(trapFile);
|
||||
ExtractModifiers();
|
||||
|
||||
var returnType = Type.Create(Context, symbol.ReturnType);
|
||||
Context.Emit(Tuples.operators(this,
|
||||
trapFile.Emit(Tuples.operators(this,
|
||||
symbol.Name,
|
||||
OperatorSymbol(Context, symbol.Name),
|
||||
ContainingType,
|
||||
|
@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
|||
(UserOperator)OriginalDefinition));
|
||||
|
||||
foreach (var l in Locations)
|
||||
Context.Emit(Tuples.operator_location(this, l));
|
||||
trapFile.Emit(Tuples.operator_location(this, l));
|
||||
|
||||
if (IsSourceDeclaration)
|
||||
{
|
||||
|
|
|
@ -4,52 +4,61 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Populators;
|
||||
using Semmle.Extraction.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Entities
|
||||
{
|
||||
class UsingDirective : FreshEntity
|
||||
{
|
||||
readonly UsingDirectiveSyntax node;
|
||||
readonly UsingDirectiveSyntax Node;
|
||||
readonly NamespaceDeclaration Parent;
|
||||
|
||||
public UsingDirective(Context cx, UsingDirectiveSyntax usingDirective, NamespaceDeclaration parent)
|
||||
: base(cx)
|
||||
{
|
||||
node = usingDirective;
|
||||
var info = cx.GetModel(node).GetSymbolInfo(usingDirective.Name);
|
||||
var trapFile = cx.TrapWriter.Writer;
|
||||
Node = usingDirective;
|
||||
Parent = parent;
|
||||
TryPopulate();
|
||||
}
|
||||
|
||||
if (usingDirective.StaticKeyword.Kind() == SyntaxKind.None)
|
||||
protected override void Populate(TextWriter trapFile)
|
||||
{
|
||||
var info = cx.GetModel(Node).GetSymbolInfo(Node.Name);
|
||||
|
||||
if (Node.StaticKeyword.Kind() == SyntaxKind.None)
|
||||
{
|
||||
// A normal using
|
||||
var namespaceSymbol = info.Symbol as INamespaceSymbol;
|
||||
|
||||
if (namespaceSymbol == null)
|
||||
{
|
||||
cx.Extractor.MissingNamespace(usingDirective.Name.ToFullString());
|
||||
cx.ModelError(usingDirective, "Namespace not found");
|
||||
cx.Extractor.MissingNamespace(Node.Name.ToFullString());
|
||||
cx.ModelError(Node, "Namespace not found");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ns = Namespace.Create(cx, namespaceSymbol);
|
||||
cx.Emit(Tuples.using_namespace_directives(this, ns));
|
||||
cx.Emit(Tuples.using_directive_location(this, cx.Create(ReportingLocation)));
|
||||
trapFile.Emit(Tuples.using_namespace_directives(this, ns));
|
||||
trapFile.Emit(Tuples.using_directive_location(this, cx.Create(ReportingLocation)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// A "using static"
|
||||
Type m = Type.Create(cx, (ITypeSymbol)info.Symbol);
|
||||
cx.Emit(Tuples.using_static_directives(this, m.TypeRef));
|
||||
cx.Emit(Tuples.using_directive_location(this, cx.Create(ReportingLocation)));
|
||||
trapFile.Emit(Tuples.using_static_directives(this, m.TypeRef));
|
||||
trapFile.Emit(Tuples.using_directive_location(this, cx.Create(ReportingLocation)));
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
if (Parent != null)
|
||||
{
|
||||
cx.Emit(Tuples.parent_namespace_declaration(this, parent));
|
||||
trapFile.Emit(Tuples.parent_namespace_declaration(this, Parent));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed override Microsoft.CodeAnalysis.Location ReportingLocation => node.GetLocation();
|
||||
public sealed override Microsoft.CodeAnalysis.Location ReportingLocation => Node.GetLocation();
|
||||
|
||||
public IEnumerable<Tuple> GetTuples()
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||
using Semmle.Extraction.CSharp.Entities;
|
||||
using Semmle.Extraction.Entities;
|
||||
using Semmle.Util.Logging;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Populators
|
||||
{
|
||||
|
@ -11,11 +12,13 @@ namespace Semmle.Extraction.CSharp.Populators
|
|||
{
|
||||
protected readonly Context cx;
|
||||
protected readonly IEntity parent;
|
||||
protected readonly TextWriter trapFile;
|
||||
|
||||
public TypeContainerVisitor(Context cx, IEntity parent)
|
||||
public TypeContainerVisitor(Context cx, TextWriter trapFile, IEntity parent)
|
||||
{
|
||||
this.cx = cx;
|
||||
this.parent = parent;
|
||||
this.trapFile = trapFile;
|
||||
}
|
||||
|
||||
public override void DefaultVisit(SyntaxNode node)
|
||||
|
@ -25,27 +28,27 @@ namespace Semmle.Extraction.CSharp.Populators
|
|||
|
||||
public override void VisitDelegateDeclaration(DelegateDeclarationSyntax node)
|
||||
{
|
||||
Entities.NamedType.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(parent);
|
||||
Entities.NamedType.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(trapFile, parent);
|
||||
}
|
||||
|
||||
public override void VisitClassDeclaration(ClassDeclarationSyntax classDecl)
|
||||
{
|
||||
Entities.Type.Create(cx, cx.GetModel(classDecl).GetDeclaredSymbol(classDecl)).ExtractRecursive(parent);
|
||||
Entities.Type.Create(cx, cx.GetModel(classDecl).GetDeclaredSymbol(classDecl)).ExtractRecursive(trapFile, parent);
|
||||
}
|
||||
|
||||
public override void VisitStructDeclaration(StructDeclarationSyntax node)
|
||||
{
|
||||
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(parent);
|
||||
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(trapFile, parent);
|
||||
}
|
||||
|
||||
public override void VisitEnumDeclaration(EnumDeclarationSyntax node)
|
||||
{
|
||||
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(parent);
|
||||
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(trapFile, parent);
|
||||
}
|
||||
|
||||
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
|
||||
{
|
||||
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(parent);
|
||||
Entities.Type.Create(cx, cx.GetModel(node).GetDeclaredSymbol(node)).ExtractRecursive(trapFile, parent);
|
||||
}
|
||||
|
||||
public override void VisitAttributeList(AttributeListSyntax node)
|
||||
|
@ -63,8 +66,8 @@ namespace Semmle.Extraction.CSharp.Populators
|
|||
|
||||
class TypeOrNamespaceVisitor : TypeContainerVisitor
|
||||
{
|
||||
public TypeOrNamespaceVisitor(Context cx, IEntity parent)
|
||||
: base(cx, parent) { }
|
||||
public TypeOrNamespaceVisitor(Context cx, TextWriter trapFile, IEntity parent)
|
||||
: base(cx, trapFile, parent) { }
|
||||
|
||||
public override void VisitUsingDirective(UsingDirectiveSyntax usingDirective)
|
||||
{
|
||||
|
@ -82,7 +85,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
|||
class CompilationUnitVisitor : TypeOrNamespaceVisitor
|
||||
{
|
||||
public CompilationUnitVisitor(Context cx)
|
||||
: base(cx, null) { }
|
||||
: base(cx, cx.TrapWriter.Writer, null) { }
|
||||
|
||||
public override void VisitExternAliasDirective(ExternAliasDirectiveSyntax node)
|
||||
{
|
||||
|
@ -120,7 +123,7 @@ namespace Semmle.Extraction.CSharp.Populators
|
|||
public static void Extract(Context cx, SyntaxNode unit)
|
||||
{
|
||||
// Ensure that the file itself is populated in case the source file is totally empty
|
||||
File.Create(cx, unit.SyntaxTree.FilePath);
|
||||
Semmle.Extraction.Entities.File.Create(cx, unit.SyntaxTree.FilePath);
|
||||
|
||||
((CSharpSyntaxNode)unit).Accept(new CompilationUnitVisitor(cx));
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ using Microsoft.CodeAnalysis;
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Semmle.Util;
|
||||
using System.IO;
|
||||
|
||||
namespace Semmle.Extraction.CSharp.Populators
|
||||
{
|
||||
|
@ -47,18 +48,18 @@ namespace Semmle.Extraction.CSharp.Populators
|
|||
}
|
||||
}
|
||||
|
||||
public static void NumberOfLines(this Context cx, ISymbol symbol, IEntity callable)
|
||||
public static void NumberOfLines(this Context cx, TextWriter trapFile, ISymbol symbol, IEntity callable)
|
||||
{
|
||||
foreach (var decl in symbol.DeclaringSyntaxReferences)
|
||||
{
|
||||
cx.NumberOfLines((CSharpSyntaxNode)decl.GetSyntax(), callable);
|
||||
cx.NumberOfLines(trapFile, (CSharpSyntaxNode)decl.GetSyntax(), callable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void NumberOfLines(this Context cx, CSharpSyntaxNode node, IEntity callable)
|
||||
public static void NumberOfLines(this Context cx, TextWriter trapFile, CSharpSyntaxNode node, IEntity callable)
|
||||
{
|
||||
var lineCounts = node.Accept(new AstLineCounter());
|
||||
cx.Emit(Tuples.numlines(callable, lineCounts));
|
||||
trapFile.Emit(Tuples.numlines(callable, lineCounts));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,8 +387,8 @@ namespace Semmle.Extraction
|
|||
}
|
||||
|
||||
var a = duplicationGuard ?
|
||||
(Action)(() => WithDuplicationGuard(new Key(entity, this.Create(entity.ReportingLocation)), entity.Populate)) :
|
||||
(Action)(() => this.Try(null, optionalSymbol, entity.Populate));
|
||||
(Action)(() => WithDuplicationGuard(new Key(entity, this.Create(entity.ReportingLocation)), () => entity.Populate(TrapWriter.Writer))) :
|
||||
(Action)(() => this.Try(null, optionalSymbol, () => entity.Populate(TrapWriter.Writer)));
|
||||
|
||||
if (deferred)
|
||||
populateQueue.Enqueue(a);
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче