C#: Rename CachedEntity.symbol to Symbol

This commit is contained in:
Tamas Vajk
2021-02-11 14:24:24 +01:00
parent 67289a498f
commit 199e937e9e
40 changed files with 327 additions and 334 deletions

View File

@@ -29,9 +29,9 @@ namespace Semmle.Extraction.CSharp.Entities
/// <summary>
/// Gets the property symbol associated with this accessor.
/// </summary>
private IPropertySymbol PropertySymbol => GetPropertySymbol(symbol);
private IPropertySymbol PropertySymbol => GetPropertySymbol(Symbol);
public new Accessor OriginalDefinition => Create(Context, symbol.OriginalDefinition);
public new Accessor OriginalDefinition => Create(Context, Symbol.OriginalDefinition);
public override void Populate(TextWriter trapFile)
{
@@ -42,42 +42,42 @@ namespace Semmle.Extraction.CSharp.Entities
var prop = PropertySymbol;
if (prop == null)
{
Context.ModelError(symbol, "Unhandled accessor associated symbol");
Context.ModelError(Symbol, "Unhandled accessor associated symbol");
return;
}
var parent = Property.Create(Context, prop);
int kind;
Accessor unboundAccessor;
if (SymbolEqualityComparer.Default.Equals(symbol, prop.GetMethod))
if (SymbolEqualityComparer.Default.Equals(Symbol, prop.GetMethod))
{
kind = 1;
unboundAccessor = Create(Context, prop.OriginalDefinition.GetMethod);
}
else if (SymbolEqualityComparer.Default.Equals(symbol, prop.SetMethod))
else if (SymbolEqualityComparer.Default.Equals(Symbol, prop.SetMethod))
{
kind = 2;
unboundAccessor = Create(Context, prop.OriginalDefinition.SetMethod);
}
else
{
Context.ModelError(symbol, "Unhandled accessor kind");
Context.ModelError(Symbol, "Unhandled accessor kind");
return;
}
trapFile.accessors(this, kind, symbol.Name, parent, unboundAccessor);
trapFile.accessors(this, kind, Symbol.Name, parent, unboundAccessor);
foreach (var l in Locations)
trapFile.accessor_location(this, l);
Overrides(trapFile);
if (symbol.FromSource() && Block == null)
if (Symbol.FromSource() && Block == null)
{
trapFile.compiler_generated(this);
}
if (symbol.IsInitOnly)
if (Symbol.IsInitOnly)
{
trapFile.init_only_accessors(this);
}

View File

@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
var type = Type.Create(Context, symbol.AttributeClass);
var type = Type.Create(Context, Symbol.AttributeClass);
trapFile.attributes(this, type.TypeRef, entity);
trapFile.attribute_location(this, Location);
@@ -69,10 +69,10 @@ namespace Semmle.Extraction.CSharp.Entities
var ctorArguments = attributeSyntax?.ArgumentList?.Arguments.Where(a => a.NameEquals == null).ToList();
var childIndex = 0;
for (var i = 0; i < symbol.ConstructorArguments.Length; i++)
for (var i = 0; i < Symbol.ConstructorArguments.Length; i++)
{
var constructorArgument = symbol.ConstructorArguments[i];
var paramName = symbol.AttributeConstructor?.Parameters[i].Name;
var constructorArgument = Symbol.ConstructorArguments[i];
var paramName = Symbol.AttributeConstructor?.Parameters[i].Name;
var argSyntax = ctorArguments?.SingleOrDefault(a => a.NameColon != null && a.NameColon.Name.Identifier.Text == paramName);
if (argSyntax == null && // couldn't find named argument
@@ -89,7 +89,7 @@ namespace Semmle.Extraction.CSharp.Entities
childIndex++);
}
foreach (var namedArgument in symbol.NamedArguments)
foreach (var namedArgument in Symbol.NamedArguments)
{
var expr = CreateExpressionFromArgument(
namedArgument.Value,

View File

@@ -13,8 +13,8 @@ namespace Semmle.Extraction.CSharp.Entities
{
trapFile.commentblock(this);
var child = 0;
trapFile.commentblock_location(this, Context.CreateLocation(symbol.Location));
foreach (var l in symbol.CommentLines)
trapFile.commentblock_location(this, Context.CreateLocation(Symbol.Location));
foreach (var l in Symbol.CommentLines)
{
trapFile.commentblock_child(this, (CommentLine)l, child++);
}
@@ -24,11 +24,11 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
trapFile.WriteSubId(Context.CreateLocation(symbol.Location));
trapFile.WriteSubId(Context.CreateLocation(Symbol.Location));
trapFile.Write(";commentblock");
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.Location;
public override Microsoft.CodeAnalysis.Location ReportingLocation => Symbol.Location;
public void BindTo(Label entity, CommentBinding binding)
{

View File

@@ -13,10 +13,10 @@ namespace Semmle.Extraction.CSharp.Entities
RawText = raw;
}
public Microsoft.CodeAnalysis.Location Location => symbol.Item1;
public Microsoft.CodeAnalysis.Location Location => Symbol.Item1;
public CommentLineType Type { get; private set; }
public string Text { get { return symbol.Item2; } }
public string Text { get { return Symbol.Item2; } }
public string RawText { get; private set; }
private Location location;
@@ -28,7 +28,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.commentline_location(this, location);
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => location.symbol;
public override Microsoft.CodeAnalysis.Location ReportingLocation => location.Symbol;
public override bool NeedsPopulation => true;

View File

@@ -19,10 +19,10 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateModifiers(trapFile);
ContainingType.PopulateGenerics();
trapFile.constructors(this, symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition);
trapFile.constructors(this, Symbol.ContainingType.Name, ContainingType, (Constructor)OriginalDefinition);
trapFile.constructor_location(this, Location);
if (symbol.IsImplicitlyDeclared)
if (Symbol.IsImplicitlyDeclared)
{
var lineCounts = new LineCounts() { Total = 2, Code = 1, Comment = 0 };
trapFile.numlines(this, lineCounts);
@@ -48,10 +48,10 @@ namespace Semmle.Extraction.CSharp.Entities
switch (initializer.Kind())
{
case SyntaxKind.BaseConstructorInitializer:
initializerType = symbol.ContainingType.BaseType;
initializerType = Symbol.ContainingType.BaseType;
break;
case SyntaxKind.ThisConstructorInitializer:
initializerType = symbol.ContainingType;
initializerType = Symbol.ContainingType;
break;
default:
Context.ModelError(initializer, "Unknown initializer");
@@ -73,7 +73,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (target == null)
{
Context.ModelError(symbol, "Unable to resolve call");
Context.ModelError(Symbol, "Unable to resolve call");
return;
}
@@ -90,7 +90,7 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
return symbol.DeclaringSyntaxReferences
return Symbol.DeclaringSyntaxReferences
.Select(r => r.GetSyntax())
.OfType<ConstructorDeclarationSyntax>()
.FirstOrDefault();
@@ -114,15 +114,15 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
if (symbol.IsStatic)
if (Symbol.IsStatic)
trapFile.Write("static");
trapFile.WriteSubId(ContainingType);
AddParametersToId(Context, trapFile, symbol);
AddParametersToId(Context, trapFile, Symbol);
trapFile.Write(";constructor");
}
private ConstructorDeclarationSyntax GetSyntax() =>
symbol.DeclaringSyntaxReferences.Select(r => r.GetSyntax()).OfType<ConstructorDeclarationSyntax>().FirstOrDefault();
Symbol.DeclaringSyntaxReferences.Select(r => r.GetSyntax()).OfType<ConstructorDeclarationSyntax>().FirstOrDefault();
public override Microsoft.CodeAnalysis.Location FullLocation => ReportingLocation;
@@ -136,12 +136,12 @@ namespace Semmle.Extraction.CSharp.Entities
return syn.Identifier.GetLocation();
}
if (symbol.IsImplicitlyDeclared)
if (Symbol.IsImplicitlyDeclared)
{
return ContainingType.ReportingLocation;
}
return symbol.ContainingType.Locations.FirstOrDefault();
return Symbol.ContainingType.Locations.FirstOrDefault();
}
}

View File

@@ -17,11 +17,11 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
return symbol.DeclaringSyntaxReferences
return Symbol.DeclaringSyntaxReferences
.Select(r => r.GetSyntax())
.OfType<ConversionOperatorDeclarationSyntax>()
.Select(s => s.FixedLocation())
.Concat(symbol.Locations)
.Concat(Symbol.Locations)
.FirstOrDefault();
}
}

View File

@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateModifiers(trapFile);
ContainingType.PopulateGenerics();
trapFile.destructors(this, string.Format("~{0}", symbol.ContainingType.Name), ContainingType, OriginalDefinition(Context, this, symbol));
trapFile.destructors(this, string.Format("~{0}", Symbol.ContainingType.Name), ContainingType, OriginalDefinition(Context, this, Symbol));
trapFile.destructor_location(this, Location);
}

View File

@@ -14,20 +14,20 @@ namespace Semmle.Extraction.CSharp.Entities
{
trapFile.WriteSubId(ContainingType);
trapFile.Write('.');
Method.AddExplicitInterfaceQualifierToId(Context, trapFile, symbol.ExplicitInterfaceImplementations);
trapFile.Write(symbol.Name);
Method.AddExplicitInterfaceQualifierToId(Context, trapFile, Symbol.ExplicitInterfaceImplementations);
trapFile.Write(Symbol.Name);
trapFile.Write(";event");
}
public override void Populate(TextWriter trapFile)
{
PopulateNullability(trapFile, symbol.GetAnnotatedType());
PopulateNullability(trapFile, Symbol.GetAnnotatedType());
var type = Type.Create(Context, symbol.Type);
trapFile.events(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition));
var type = Type.Create(Context, Symbol.Type);
trapFile.events(this, Symbol.GetName(), ContainingType, type.TypeRef, Create(Context, Symbol.OriginalDefinition));
var adder = symbol.AddMethod;
var remover = symbol.RemoveMethod;
var adder = Symbol.AddMethod;
var remover = Symbol.RemoveMethod;
if (!(adder is null))
Method.Create(Context, adder);
@@ -39,10 +39,10 @@ namespace Semmle.Extraction.CSharp.Entities
BindComments();
var declSyntaxReferences = IsSourceDeclaration
? symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).ToArray()
? Symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).ToArray()
: Enumerable.Empty<SyntaxNode>();
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
foreach (var explicitInterface in Symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
{
trapFile.explicitly_implements(this, explicitInterface.TypeRef);

View File

@@ -11,7 +11,7 @@ namespace Semmle.Extraction.CSharp.Entities
/// <summary>
/// Gets the event symbol associated with this accessor.
/// </summary>
private IEventSymbol EventSymbol => symbol.AssociatedSymbol as IEventSymbol;
private IEventSymbol EventSymbol => Symbol.AssociatedSymbol as IEventSymbol;
public override void Populate(TextWriter trapFile)
{
@@ -21,30 +21,30 @@ namespace Semmle.Extraction.CSharp.Entities
var @event = EventSymbol;
if (@event == null)
{
Context.ModelError(symbol, "Unhandled event accessor associated symbol");
Context.ModelError(Symbol, "Unhandled event accessor associated symbol");
return;
}
var parent = Event.Create(Context, @event);
int kind;
EventAccessor unboundAccessor;
if (SymbolEqualityComparer.Default.Equals(symbol, @event.AddMethod))
if (SymbolEqualityComparer.Default.Equals(Symbol, @event.AddMethod))
{
kind = 1;
unboundAccessor = Create(Context, @event.OriginalDefinition.AddMethod);
}
else if (SymbolEqualityComparer.Default.Equals(symbol, @event.RemoveMethod))
else if (SymbolEqualityComparer.Default.Equals(Symbol, @event.RemoveMethod))
{
kind = 2;
unboundAccessor = Create(Context, @event.OriginalDefinition.RemoveMethod);
}
else
{
Context.ModelError(symbol, "Undhandled event accessor kind");
Context.ModelError(Symbol, "Undhandled event accessor kind");
return;
}
trapFile.event_accessors(this, kind, symbol.Name, parent, unboundAccessor);
trapFile.event_accessors(this, kind, Symbol.Name, parent, unboundAccessor);
foreach (var l in Locations)
trapFile.event_accessor_location(this, l);

View File

@@ -57,7 +57,7 @@ namespace Semmle.Extraction.CSharp.Entities
type.PopulateGenerics();
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => Location.symbol;
public override Microsoft.CodeAnalysis.Location ReportingLocation => Location.Symbol;
bool IExpressionParentEntity.IsTopLevelParent => false;

View File

@@ -55,7 +55,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
{
// Implicit `this` qualifier; add explicitly
if (Context.GetModel(Syntax).GetEnclosingSymbol(Location.symbol.SourceSpan.Start) is IMethodSymbol callingMethod)
if (Context.GetModel(Syntax).GetEnclosingSymbol(Location.Symbol.SourceSpan.Start) is IMethodSymbol callingMethod)
This.CreateImplicit(Context, callingMethod.ContainingType, Location, this, child++);
else
Context.ModelError(Syntax, "Couldn't determine implicit this type");

View File

@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
private Field(Context cx, IFieldSymbol init)
: base(cx, init)
{
type = new Lazy<Type>(() => Entities.Type.Create(cx, symbol.Type));
type = new Lazy<Type>(() => Entities.Type.Create(cx, Symbol.Type));
}
public static Field Create(Context cx, IFieldSymbol field) => FieldFactory.Instance.CreateEntityFromSymbol(cx, field);
@@ -22,43 +22,43 @@ namespace Semmle.Extraction.CSharp.Entities
// Do not populate backing fields.
// Populate Tuple fields.
public override bool NeedsPopulation =>
(base.NeedsPopulation && !symbol.IsImplicitlyDeclared) || symbol.ContainingType.IsTupleType;
(base.NeedsPopulation && !Symbol.IsImplicitlyDeclared) || Symbol.ContainingType.IsTupleType;
public override void Populate(TextWriter trapFile)
{
PopulateMetadataHandle(trapFile);
PopulateAttributes();
ContainingType.PopulateGenerics();
PopulateNullability(trapFile, symbol.GetAnnotatedType());
PopulateNullability(trapFile, Symbol.GetAnnotatedType());
var unboundFieldKey = Field.Create(Context, symbol.OriginalDefinition);
trapFile.fields(this, (symbol.IsConst ? 2 : 1), symbol.Name, ContainingType, Type.TypeRef, unboundFieldKey);
var unboundFieldKey = Field.Create(Context, Symbol.OriginalDefinition);
trapFile.fields(this, (Symbol.IsConst ? 2 : 1), Symbol.Name, ContainingType, Type.TypeRef, unboundFieldKey);
PopulateModifiers(trapFile);
if (symbol.IsVolatile)
if (Symbol.IsVolatile)
Modifier.HasModifier(Context, trapFile, this, "volatile");
if (symbol.IsConst)
if (Symbol.IsConst)
{
Modifier.HasModifier(Context, trapFile, this, "const");
if (symbol.HasConstantValue)
if (Symbol.HasConstantValue)
{
trapFile.constant_value(this, Expression.ValueAsString(symbol.ConstantValue));
trapFile.constant_value(this, Expression.ValueAsString(Symbol.ConstantValue));
}
}
foreach (var l in Locations)
trapFile.field_location(this, l);
if (!IsSourceDeclaration || !symbol.FromSource())
if (!IsSourceDeclaration || !Symbol.FromSource())
return;
Context.BindComments(this, Location.symbol);
Context.BindComments(this, Location.Symbol);
var child = 0;
foreach (var initializer in symbol.DeclaringSyntaxReferences
foreach (var initializer in Symbol.DeclaringSyntaxReferences
.Select(n => n.GetSyntax())
.OfType<VariableDeclaratorSyntax>()
.Where(n => n.Initializer != null))
@@ -69,21 +69,21 @@ namespace Semmle.Extraction.CSharp.Entities
var fieldAccess = AddInitializerAssignment(trapFile, initializer.Initializer.Value, loc, null, ref child);
if (!symbol.IsStatic)
if (!Symbol.IsStatic)
{
This.CreateImplicit(Context, symbol.ContainingType, Location, fieldAccess, -1);
This.CreateImplicit(Context, Symbol.ContainingType, Location, fieldAccess, -1);
}
});
}
foreach (var initializer in symbol.DeclaringSyntaxReferences
foreach (var initializer in Symbol.DeclaringSyntaxReferences
.Select(n => n.GetSyntax())
.OfType<EnumMemberDeclarationSyntax>()
.Where(n => n.EqualsValue != null))
{
// Mark fields that have explicit initializers.
var constValue = symbol.HasConstantValue
? Expression.ValueAsString(symbol.ConstantValue)
var constValue = Symbol.HasConstantValue
? Expression.ValueAsString(Symbol.ConstantValue)
: null;
var loc = Context.CreateLocation(initializer.GetLocation());
@@ -93,7 +93,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (IsSourceDeclaration)
{
foreach (var syntax in symbol.DeclaringSyntaxReferences
foreach (var syntax in Symbol.DeclaringSyntaxReferences
.Select(d => d.GetSyntax())
.OfType<VariableDeclaratorSyntax>()
.Select(d => d.Parent)
@@ -107,7 +107,7 @@ namespace Semmle.Extraction.CSharp.Entities
private Expression AddInitializerAssignment(TextWriter trapFile, ExpressionSyntax initializer, Extraction.Entities.Location loc,
string constValue, ref int child)
{
var type = symbol.GetAnnotatedType();
var type = Symbol.GetAnnotatedType();
var simpleAssignExpr = new Expression(new ExpressionInfo(Context, type, loc, ExprKind.SIMPLE_ASSIGN, this, child++, false, constValue));
Expression.CreateFromNode(new ExpressionNodeInfo(Context, initializer, simpleAssignExpr, 0));
var access = new Expression(new ExpressionInfo(Context, type, Location, ExprKind.FIELD_ACCESS, simpleAssignExpr, 1, false, constValue));
@@ -124,7 +124,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.Write(" ");
trapFile.WriteSubId(ContainingType);
trapFile.Write('.');
trapFile.Write(symbol.Name);
trapFile.Write(Symbol.Name);
trapFile.Write(";field");
}

View File

@@ -10,22 +10,22 @@ namespace Semmle.Extraction.CSharp.Entities
protected Indexer(Context cx, IPropertySymbol init)
: base(cx, init) { }
private Indexer OriginalDefinition => IsSourceDeclaration ? this : Create(Context, symbol.OriginalDefinition);
private Indexer OriginalDefinition => IsSourceDeclaration ? this : Create(Context, Symbol.OriginalDefinition);
public override void Populate(TextWriter trapFile)
{
PopulateNullability(trapFile, symbol.GetAnnotatedType());
PopulateNullability(trapFile, Symbol.GetAnnotatedType());
var type = Type.Create(Context, symbol.Type);
trapFile.indexers(this, symbol.GetName(useMetadataName: true), ContainingType, type.TypeRef, OriginalDefinition);
var type = Type.Create(Context, Symbol.Type);
trapFile.indexers(this, Symbol.GetName(useMetadataName: true), ContainingType, type.TypeRef, OriginalDefinition);
foreach (var l in Locations)
trapFile.indexer_location(this, l);
var getter = symbol.GetMethod;
var setter = symbol.SetMethod;
var getter = Symbol.GetMethod;
var setter = Symbol.SetMethod;
if (getter is null && setter is null)
Context.ModelError(symbol, "No indexer accessor defined");
Context.ModelError(Symbol, "No indexer accessor defined");
if (!(getter is null))
Method.Create(Context, getter);
@@ -33,10 +33,10 @@ namespace Semmle.Extraction.CSharp.Entities
if (!(setter is null))
Method.Create(Context, setter);
for (var i = 0; i < symbol.Parameters.Length; ++i)
for (var i = 0; i < Symbol.Parameters.Length; ++i)
{
var original = Parameter.Create(Context, symbol.OriginalDefinition.Parameters[i], OriginalDefinition);
Parameter.Create(Context, symbol.Parameters[i], this, original);
var original = Parameter.Create(Context, Symbol.OriginalDefinition.Parameters[i], OriginalDefinition);
Parameter.Create(Context, Symbol.Parameters[i], this, original);
}
if (IsSourceDeclaration)
@@ -46,7 +46,7 @@ namespace Semmle.Extraction.CSharp.Entities
{
// The expression may need to reference parameters in the getter.
// So we need to arrange that the expression is populated after the getter.
Context.PopulateLater(() => Expression.CreateFromNode(new ExpressionNodeInfo(Context, expressionBody, this, 0).SetType(symbol.GetAnnotatedType())));
Context.PopulateLater(() => Expression.CreateFromNode(new ExpressionNodeInfo(Context, expressionBody, this, 0).SetType(Symbol.GetAnnotatedType())));
}
}
@@ -54,11 +54,11 @@ namespace Semmle.Extraction.CSharp.Entities
BindComments();
var declSyntaxReferences = IsSourceDeclaration
? symbol.DeclaringSyntaxReferences.
? Symbol.DeclaringSyntaxReferences.
Select(d => d.GetSyntax()).OfType<IndexerDeclarationSyntax>().ToArray()
: Enumerable.Empty<IndexerDeclarationSyntax>();
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
foreach (var explicitInterface in Symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
{
trapFile.explicitly_implements(this, explicitInterface.TypeRef);
@@ -77,9 +77,9 @@ namespace Semmle.Extraction.CSharp.Entities
{
trapFile.WriteSubId(ContainingType);
trapFile.Write('.');
trapFile.Write(symbol.MetadataName);
trapFile.Write(Symbol.MetadataName);
trapFile.Write('(');
trapFile.BuildList(",", symbol.Parameters, (p, tb0) => tb0.WriteSubId(Type.Create(Context, p.Type)));
trapFile.BuildList(",", Symbol.Parameters, (p, tb0) => tb0.WriteSubId(Type.Create(Context, p.Type)));
trapFile.Write(");indexer");
}
@@ -87,11 +87,11 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
return symbol.DeclaringSyntaxReferences
return Symbol.DeclaringSyntaxReferences
.Select(r => r.GetSyntax())
.OfType<IndexerDeclarationSyntax>()
.Select(s => s.GetLocation())
.Concat(symbol.Locations)
.Concat(Symbol.Locations)
.First();
}
}

View File

@@ -34,10 +34,10 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateMethod(trapFile);
PopulateModifiers(trapFile);
var originalDefinition = IsSourceDeclaration ? this : Create(Context, symbol.OriginalDefinition);
var returnType = Type.Create(Context, symbol.ReturnType);
trapFile.local_functions(this, symbol.Name, returnType, originalDefinition);
ExtractRefReturn(trapFile, symbol, this);
var originalDefinition = IsSourceDeclaration ? this : Create(Context, Symbol.OriginalDefinition);
var returnType = Type.Create(Context, Symbol.ReturnType);
trapFile.local_functions(this, Symbol.Name, returnType, originalDefinition);
ExtractRefReturn(trapFile, Symbol, this);
}
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NeedsLabel;

View File

@@ -23,12 +23,12 @@ namespace Semmle.Extraction.CSharp.Entities
public void PopulateManual(Expression parent, bool isVar)
{
var trapFile = Context.TrapWriter.Writer;
var (kind, type) = symbol is ILocalSymbol l
var (kind, type) = Symbol is ILocalSymbol l
? (l.IsRef ? 3 : l.IsConst ? 2 : 1, l.GetAnnotatedType())
: (1, parent.Type);
trapFile.localvars(this, kind, symbol.Name, isVar ? 1 : 0, Type.Create(Context, type).TypeRef, parent);
trapFile.localvars(this, kind, Symbol.Name, isVar ? 1 : 0, Type.Create(Context, type).TypeRef, parent);
if (symbol is ILocalSymbol local)
if (Symbol is ILocalSymbol local)
{
PopulateNullability(trapFile, local.GetAnnotatedType());
if (local.IsRef)
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CSharp.Entities
private void DefineConstantValue(TextWriter trapFile)
{
if (symbol is ILocalSymbol local && local.HasConstantValue)
if (Symbol is ILocalSymbol local && local.HasConstantValue)
{
trapFile.constant_value(this, Expression.ValueAsString(local.ConstantValue));
}

View File

@@ -16,8 +16,8 @@ namespace Semmle.Extraction.CSharp.Entities
protected void PopulateParameters()
{
var originalMethod = OriginalDefinition;
IEnumerable<IParameterSymbol> parameters = symbol.Parameters;
IEnumerable<IParameterSymbol> originalParameters = originalMethod.symbol.Parameters;
IEnumerable<IParameterSymbol> parameters = Symbol.Parameters;
IEnumerable<IParameterSymbol> originalParameters = originalMethod.Symbol.Parameters;
if (IsReducedExtension)
{
@@ -25,14 +25,14 @@ namespace Semmle.Extraction.CSharp.Entities
{
// Non-generic reduced extensions must be extracted exactly like the
// non-reduced counterparts
parameters = symbol.ReducedFrom.Parameters;
parameters = Symbol.ReducedFrom.Parameters;
}
else
{
// Constructed reduced extensions are special because their non-reduced
// counterparts are not constructed. Therefore, we need to manually add
// the `this` parameter based on the type of the receiver
var originalThisParamSymbol = originalMethod.symbol.Parameters.First();
var originalThisParamSymbol = originalMethod.Symbol.Parameters.First();
var originalThisParam = Parameter.Create(Context, originalThisParamSymbol, originalMethod);
ConstructedExtensionParameter.Create(Context, this, originalThisParam);
originalParameters = originalParameters.Skip(1);
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CSharp.Entities
Parameter.Create(Context, p.paramSymbol, this, original);
}
if (symbol.IsVararg)
if (Symbol.IsVararg)
{
// Mono decided that "__arglist" should be an explicit parameter,
// so now we need to populate it.
@@ -101,7 +101,7 @@ namespace Semmle.Extraction.CSharp.Entities
public void Overrides(TextWriter trapFile)
{
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations
foreach (var explicitInterface in Symbol.ExplicitInterfaceImplementations
.Where(sym => sym.MethodKind == MethodKind.Ordinary)
.Select(impl => Type.Create(Context, impl.ContainingType)))
{
@@ -109,14 +109,14 @@ namespace Semmle.Extraction.CSharp.Entities
if (IsSourceDeclaration)
{
foreach (var syntax in symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).OfType<MethodDeclarationSyntax>())
foreach (var syntax in Symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).OfType<MethodDeclarationSyntax>())
TypeMention.Create(Context, syntax.ExplicitInterfaceSpecifier.Name, this, explicitInterface);
}
}
if (symbol.OverriddenMethod != null)
if (Symbol.OverriddenMethod != null)
{
trapFile.overrides(this, Method.Create(Context, symbol.OverriddenMethod));
trapFile.overrides(this, Method.Create(Context, Symbol.OverriddenMethod));
}
}
@@ -125,22 +125,22 @@ namespace Semmle.Extraction.CSharp.Entities
/// </summary>
private static void BuildMethodId(Method m, TextWriter trapFile)
{
m.symbol.ReturnType.BuildOrWriteId(m.Context, trapFile, m.symbol);
m.Symbol.ReturnType.BuildOrWriteId(m.Context, trapFile, m.Symbol);
trapFile.Write(" ");
trapFile.WriteSubId(m.ContainingType);
AddExplicitInterfaceQualifierToId(m.Context, trapFile, m.symbol.ExplicitInterfaceImplementations);
AddExplicitInterfaceQualifierToId(m.Context, trapFile, m.Symbol.ExplicitInterfaceImplementations);
trapFile.Write(".");
trapFile.Write(m.symbol.Name);
trapFile.Write(m.Symbol.Name);
if (m.symbol.IsGenericMethod)
if (m.Symbol.IsGenericMethod)
{
if (SymbolEqualityComparer.Default.Equals(m.symbol, m.symbol.OriginalDefinition))
if (SymbolEqualityComparer.Default.Equals(m.Symbol, m.Symbol.OriginalDefinition))
{
trapFile.Write('`');
trapFile.Write(m.symbol.TypeParameters.Length);
trapFile.Write(m.Symbol.TypeParameters.Length);
}
else
{
@@ -149,13 +149,13 @@ namespace Semmle.Extraction.CSharp.Entities
// Type arguments with different nullability can result in
// a constructed method with different nullability of its parameters and return type,
// so we need to create a distinct database entity for it.
trapFile.BuildList(",", m.symbol.GetAnnotatedTypeArguments(), (ta, tb0) => { ta.Symbol.BuildOrWriteId(m.Context, tb0, m.symbol); trapFile.Write((int)ta.Nullability); });
trapFile.BuildList(",", m.Symbol.GetAnnotatedTypeArguments(), (ta, tb0) => { ta.Symbol.BuildOrWriteId(m.Context, tb0, m.Symbol); trapFile.Write((int)ta.Nullability); });
trapFile.Write('>');
}
}
AddParametersToId(m.Context, trapFile, m.symbol);
switch (m.symbol.MethodKind)
AddParametersToId(m.Context, trapFile, m.Symbol);
switch (m.Symbol.MethodKind)
{
case MethodKind.PropertyGet:
trapFile.Write(";getter");
@@ -224,7 +224,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.AppendList(",", explicitInterfaceImplementations.Select(impl => cx.CreateEntity(impl.ContainingType)));
}
public virtual string Name => symbol.Name;
public virtual string Name => Symbol.Name;
/// <summary>
/// Creates a method of the appropriate subtype.
@@ -278,28 +278,28 @@ namespace Semmle.Extraction.CSharp.Entities
public Method OriginalDefinition =>
IsReducedExtension
? Create(Context, symbol.ReducedFrom)
: Create(Context, symbol.OriginalDefinition);
? Create(Context, Symbol.ReducedFrom)
: Create(Context, Symbol.OriginalDefinition);
public override Microsoft.CodeAnalysis.Location FullLocation => ReportingLocation;
public override bool IsSourceDeclaration => symbol.IsSourceDeclaration();
public override bool IsSourceDeclaration => Symbol.IsSourceDeclaration();
/// <summary>
/// Whether this method has type parameters.
/// </summary>
public bool IsGeneric => symbol.IsGenericMethod;
public bool IsGeneric => Symbol.IsGenericMethod;
/// <summary>
/// Whether this method has unbound type parameters.
/// </summary>
public bool IsUnboundGeneric => IsGeneric && SymbolEqualityComparer.Default.Equals(symbol.ConstructedFrom, symbol);
public bool IsUnboundGeneric => IsGeneric && SymbolEqualityComparer.Default.Equals(Symbol.ConstructedFrom, Symbol);
public bool IsBoundGeneric => IsGeneric && !IsUnboundGeneric;
private bool IsReducedExtension => symbol.MethodKind == MethodKind.ReducedExtension;
private bool IsReducedExtension => Symbol.MethodKind == MethodKind.ReducedExtension;
protected IMethodSymbol ConstructedFromSymbol => symbol.ConstructedFrom.ReducedFrom ?? symbol.ConstructedFrom;
protected IMethodSymbol ConstructedFromSymbol => Symbol.ConstructedFrom.ReducedFrom ?? Symbol.ConstructedFrom;
bool IExpressionParentEntity.IsTopLevelParent => true;
@@ -316,19 +316,19 @@ namespace Semmle.Extraction.CSharp.Entities
if (isFullyConstructed)
{
trapFile.constructed_generic(this, Method.Create(Context, ConstructedFromSymbol));
foreach (var tp in symbol.GetAnnotatedTypeArguments())
foreach (var tp in Symbol.GetAnnotatedTypeArguments())
{
trapFile.type_arguments(Type.Create(Context, tp.Symbol), child, this);
child++;
}
var nullability = new Nullability(symbol);
var nullability = new Nullability(Symbol);
if (!nullability.IsOblivious)
trapFile.type_nullability(this, NullabilityEntity.Create(Context, nullability));
}
else
{
foreach (var typeParam in symbol.TypeParameters.Select(tp => TypeParameter.Create(Context, tp)))
foreach (var typeParam in Symbol.TypeParameters.Select(tp => TypeParameter.Create(Context, tp)))
{
trapFile.type_parameters(typeParam, child, this);
child++;
@@ -354,7 +354,7 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateMethodBody(trapFile);
PopulateGenerics(trapFile);
PopulateMetadataHandle(trapFile);
PopulateNullability(trapFile, symbol.GetAnnotatedReturnType());
PopulateNullability(trapFile, Symbol.GetAnnotatedReturnType());
}
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.PushesLabel;

View File

@@ -12,7 +12,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
trapFile.Write(symbol);
trapFile.Write(Symbol);
trapFile.Write(";modifier");
}
@@ -20,7 +20,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
trapFile.modifiers(Label, symbol);
trapFile.modifiers(Label, Symbol);
}
public static string AccessbilityModifier(Accessibility access)

View File

@@ -12,11 +12,11 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
trapFile.namespaces(this, symbol.Name);
trapFile.namespaces(this, Symbol.Name);
if (symbol.ContainingNamespace != null)
if (Symbol.ContainingNamespace != null)
{
var parent = Create(Context, symbol.ContainingNamespace);
var parent = Create(Context, Symbol.ContainingNamespace);
trapFile.parent_namespace(this, parent);
}
}
@@ -25,11 +25,11 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
if (!symbol.IsGlobalNamespace)
if (!Symbol.IsGlobalNamespace)
{
trapFile.WriteSubId(Create(Context, symbol.ContainingNamespace));
trapFile.WriteSubId(Create(Context, Symbol.ContainingNamespace));
trapFile.Write('.');
trapFile.Write(symbol.Name);
trapFile.Write(Symbol.Name);
}
trapFile.Write(";namespace");
}
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override int GetHashCode() => QualifiedName.GetHashCode();
private string QualifiedName => symbol.ToDisplayString();
private string QualifiedName => Symbol.ToDisplayString();
public override bool Equals(object obj)
{

View File

@@ -11,20 +11,20 @@ namespace Semmle.Extraction.CSharp.Entities
private OrdinaryMethod(Context cx, IMethodSymbol init)
: base(cx, init) { }
public override string Name => symbol.GetName();
public override string Name => Symbol.GetName();
protected override IMethodSymbol BodyDeclaringSymbol => symbol.PartialImplementationPart ?? symbol;
protected override IMethodSymbol BodyDeclaringSymbol => Symbol.PartialImplementationPart ?? Symbol;
public IMethodSymbol SourceDeclaration
{
get
{
var reducedFrom = symbol.ReducedFrom ?? symbol;
var reducedFrom = Symbol.ReducedFrom ?? Symbol;
return reducedFrom.OriginalDefinition;
}
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.GetSymbolLocation();
public override Microsoft.CodeAnalysis.Location ReportingLocation => Symbol.GetSymbolLocation();
public override void Populate(TextWriter trapFile)
{
@@ -32,12 +32,12 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateModifiers(trapFile);
ContainingType.PopulateGenerics();
var returnType = Type.Create(Context, symbol.ReturnType);
var returnType = Type.Create(Context, Symbol.ReturnType);
trapFile.methods(this, Name, ContainingType, returnType.TypeRef, OriginalDefinition);
if (IsSourceDeclaration)
{
foreach (var declaration in symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).OfType<MethodDeclarationSyntax>())
foreach (var declaration in Symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).OfType<MethodDeclarationSyntax>())
{
Context.BindComments(this, declaration.Identifier.GetLocation());
TypeMention.Create(Context, declaration.ReturnType, this, returnType);
@@ -49,7 +49,7 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateGenerics(trapFile);
Overrides(trapFile);
ExtractRefReturn(trapFile, symbol, this);
ExtractRefReturn(trapFile, Symbol, this);
ExtractCompilerGenerated(trapFile);
}

View File

@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities
Original = original ?? this;
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.GetSymbolLocation();
public override Microsoft.CodeAnalysis.Location ReportingLocation => Symbol.GetSymbolLocation();
public enum Kind
{
@@ -35,9 +35,9 @@ namespace Semmle.Extraction.CSharp.Entities
// actually numbered from 1.
// This is to be consistent from the original (unreduced) extension method.
var isReducedExtension =
symbol.ContainingSymbol is IMethodSymbol method &&
Symbol.ContainingSymbol is IMethodSymbol method &&
method.MethodKind == MethodKind.ReducedExtension;
return symbol.Ordinal + (isReducedExtension ? 1 : 0);
return Symbol.Ordinal + (isReducedExtension ? 1 : 0);
}
}
@@ -45,7 +45,7 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
switch (symbol.RefKind)
switch (Symbol.RefKind)
{
case RefKind.Out:
return Kind.Out;
@@ -54,12 +54,12 @@ namespace Semmle.Extraction.CSharp.Entities
case RefKind.In:
return Kind.In;
default:
if (symbol.IsParams)
if (Symbol.IsParams)
return Kind.Params;
if (Ordinal == 0)
{
if (symbol.ContainingSymbol is IMethodSymbol method && method.IsExtensionMethod)
if (Symbol.ContainingSymbol is IMethodSymbol method && method.IsExtensionMethod)
return Kind.This;
}
return Kind.None;
@@ -76,7 +76,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
if (Parent == null)
Parent = Method.Create(Context, symbol.ContainingSymbol as IMethodSymbol);
Parent = Method.Create(Context, Symbol.ContainingSymbol as IMethodSymbol);
trapFile.WriteSubId(Parent);
trapFile.Write('_');
trapFile.Write(Ordinal);
@@ -92,42 +92,42 @@ namespace Semmle.Extraction.CSharp.Entities
// Very rarely, two parameters have the same name according to the data model.
// This breaks our database constraints.
// Generate an impossible name to ensure that it doesn't conflict.
var conflictingCount = symbol.ContainingSymbol.GetParameters().Count(p => p.Ordinal < symbol.Ordinal && p.Name == symbol.Name);
return conflictingCount > 0 ? symbol.Name + "`" + conflictingCount : symbol.Name;
var conflictingCount = Symbol.ContainingSymbol.GetParameters().Count(p => p.Ordinal < Symbol.Ordinal && p.Name == Symbol.Name);
return conflictingCount > 0 ? Symbol.Name + "`" + conflictingCount : Symbol.Name;
}
}
public override void Populate(TextWriter trapFile)
{
PopulateAttributes();
PopulateNullability(trapFile, symbol.GetAnnotatedType());
PopulateRefKind(trapFile, symbol.RefKind);
PopulateNullability(trapFile, Symbol.GetAnnotatedType());
PopulateRefKind(trapFile, Symbol.RefKind);
if (symbol.Name != Original.symbol.Name)
Context.ModelError(symbol, "Inconsistent parameter declaration");
if (Symbol.Name != Original.Symbol.Name)
Context.ModelError(Symbol, "Inconsistent parameter declaration");
var type = Type.Create(Context, symbol.Type);
var type = Type.Create(Context, Symbol.Type);
trapFile.@params(this, Name, type.TypeRef, Ordinal, ParamKind, Parent, Original);
foreach (var l in symbol.Locations)
foreach (var l in Symbol.Locations)
trapFile.param_location(this, Context.CreateLocation(l));
if (!symbol.Locations.Any() &&
symbol.ContainingSymbol is IMethodSymbol ms &&
if (!Symbol.Locations.Any() &&
Symbol.ContainingSymbol is IMethodSymbol ms &&
ms.Name == WellKnownMemberNames.TopLevelStatementsEntryPointMethodName &&
ms.ContainingType.Name == WellKnownMemberNames.TopLevelStatementsEntryPointTypeName)
{
trapFile.param_location(this, Context.CreateLocation());
}
if (!IsSourceDeclaration || !symbol.FromSource())
if (!IsSourceDeclaration || !Symbol.FromSource())
return;
BindComments();
if (IsSourceDeclaration)
{
foreach (var syntax in symbol.DeclaringSyntaxReferences
foreach (var syntax in Symbol.DeclaringSyntaxReferences
.Select(d => d.GetSyntax())
.OfType<ParameterSyntax>()
.Where(s => s.Type != null))
@@ -136,21 +136,21 @@ namespace Semmle.Extraction.CSharp.Entities
}
}
if (symbol.HasExplicitDefaultValue && Context.Defines(symbol))
if (Symbol.HasExplicitDefaultValue && Context.Defines(Symbol))
{
// This is a slight bug in the dbscheme
// We should really define param_default(param, string)
// And use parameter child #0 to encode the default expression.
var defaultValue = GetParameterDefaultValue(symbol);
var defaultValue = GetParameterDefaultValue(Symbol);
if (defaultValue == null)
{
// In case this parameter belongs to an accessor of an indexer, we need
// to get the default value from the corresponding parameter belonging
// to the indexer itself
var method = (IMethodSymbol)symbol.ContainingSymbol;
var method = (IMethodSymbol)Symbol.ContainingSymbol;
if (method != null)
{
var i = method.Parameters.IndexOf(symbol);
var i = method.Parameters.IndexOf(Symbol);
var indexer = (IPropertySymbol)method.AssociatedSymbol;
if (indexer != null)
defaultValue = GetParameterDefaultValue(indexer.Parameters[i]);
@@ -167,7 +167,7 @@ namespace Semmle.Extraction.CSharp.Entities
}
}
public override bool IsSourceDeclaration => symbol.IsSourceDeclaration();
public override bool IsSourceDeclaration => Symbol.IsSourceDeclaration();
bool IExpressionParentEntity.IsTopLevelParent => true;
@@ -239,7 +239,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.param_location(this, GeneratedLocation.Create(Context));
}
protected override int Ordinal => ((Method)Parent).OriginalDefinition.symbol.Parameters.Length;
protected override int Ordinal => ((Method)Parent).OriginalDefinition.Symbol.Parameters.Length;
public override int GetHashCode()
{
@@ -266,20 +266,20 @@ namespace Semmle.Extraction.CSharp.Entities
private readonly ITypeSymbol constructedType;
private ConstructedExtensionParameter(Context cx, Method method, Parameter original)
: base(cx, original.symbol, method, original)
: base(cx, original.Symbol, method, original)
{
constructedType = method.symbol.ReceiverType;
constructedType = method.Symbol.ReceiverType;
}
public override void Populate(TextWriter trapFile)
{
var typeKey = Type.Create(Context, constructedType);
trapFile.@params(this, Original.symbol.Name, typeKey.TypeRef, 0, Kind.This, Parent, Original);
trapFile.@params(this, Original.Symbol.Name, typeKey.TypeRef, 0, Kind.This, Parent, Original);
trapFile.param_location(this, Original.Location);
}
public static ConstructedExtensionParameter Create(Context cx, Method method, Parameter parameter) =>
ExtensionParamFactory.Instance.CreateEntity(cx, (new SymbolEqualityWrapper(parameter.symbol), new SymbolEqualityWrapper(method.symbol.ReceiverType)), (method, parameter));
ExtensionParamFactory.Instance.CreateEntity(cx, (new SymbolEqualityWrapper(parameter.Symbol), new SymbolEqualityWrapper(method.Symbol.ReceiverType)), (method, parameter));
private class ExtensionParamFactory : ICachedEntityFactory<(Method, Parameter), ConstructedExtensionParameter>
{

View File

@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
protected Property(Context cx, IPropertySymbol init)
: base(cx, init)
{
type = new Lazy<Type>(() => Type.Create(base.Context, symbol.Type));
type = new Lazy<Type>(() => Type.Create(base.Context, Symbol.Type));
}
private readonly Lazy<Type> type;
@@ -27,8 +27,8 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.Write(" ");
trapFile.WriteSubId(ContainingType);
trapFile.Write('.');
Method.AddExplicitInterfaceQualifierToId(Context, trapFile, symbol.ExplicitInterfaceImplementations);
trapFile.Write(symbol.Name);
Method.AddExplicitInterfaceQualifierToId(Context, trapFile, Symbol.ExplicitInterfaceImplementations);
trapFile.Write(Symbol.Name);
trapFile.Write(";property");
}
@@ -38,14 +38,14 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateAttributes();
PopulateModifiers(trapFile);
BindComments();
PopulateNullability(trapFile, symbol.GetAnnotatedType());
PopulateRefKind(trapFile, symbol.RefKind);
PopulateNullability(trapFile, Symbol.GetAnnotatedType());
PopulateRefKind(trapFile, Symbol.RefKind);
var type = Type;
trapFile.properties(this, symbol.GetName(), ContainingType, type.TypeRef, Create(Context, symbol.OriginalDefinition));
trapFile.properties(this, Symbol.GetName(), ContainingType, type.TypeRef, Create(Context, Symbol.OriginalDefinition));
var getter = symbol.GetMethod;
var setter = symbol.SetMethod;
var getter = Symbol.GetMethod;
var setter = Symbol.SetMethod;
if (!(getter is null))
Method.Create(Context, getter);
@@ -54,11 +54,11 @@ namespace Semmle.Extraction.CSharp.Entities
Method.Create(Context, setter);
var declSyntaxReferences = IsSourceDeclaration ?
symbol.DeclaringSyntaxReferences.
Symbol.DeclaringSyntaxReferences.
Select(d => d.GetSyntax()).OfType<PropertyDeclarationSyntax>().ToArray()
: Enumerable.Empty<PropertyDeclarationSyntax>();
foreach (var explicitInterface in symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
foreach (var explicitInterface in Symbol.ExplicitInterfaceImplementations.Select(impl => Type.Create(Context, impl.ContainingType)))
{
trapFile.explicitly_implements(this, explicitInterface.TypeRef);
@@ -69,7 +69,7 @@ namespace Semmle.Extraction.CSharp.Entities
foreach (var l in Locations)
trapFile.property_location(this, l);
if (IsSourceDeclaration && symbol.FromSource())
if (IsSourceDeclaration && Symbol.FromSource())
{
var expressionBody = ExpressionBody;
if (expressionBody != null)
@@ -85,14 +85,14 @@ namespace Semmle.Extraction.CSharp.Entities
Context.PopulateLater(() =>
{
var loc = Context.CreateLocation(initializer.GetLocation());
var annotatedType = AnnotatedTypeSymbol.CreateNotAnnotated(symbol.Type);
var annotatedType = AnnotatedTypeSymbol.CreateNotAnnotated(Symbol.Type);
var simpleAssignExpr = new Expression(new ExpressionInfo(Context, annotatedType, loc, ExprKind.SIMPLE_ASSIGN, this, child++, false, null));
Expression.CreateFromNode(new ExpressionNodeInfo(Context, initializer.Value, simpleAssignExpr, 0));
var access = new Expression(new ExpressionInfo(Context, annotatedType, Location, ExprKind.PROPERTY_ACCESS, simpleAssignExpr, 1, false, null));
trapFile.expr_access(access, this);
if (!symbol.IsStatic)
if (!Symbol.IsStatic)
{
This.CreateImplicit(Context, symbol.ContainingType, Location, access, -1);
This.CreateImplicit(Context, Symbol.ContainingType, Location, access, -1);
}
});
}
@@ -106,11 +106,11 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
return symbol.DeclaringSyntaxReferences
return Symbol.DeclaringSyntaxReferences
.Select(r => r.GetSyntax())
.OfType<PropertyDeclarationSyntax>()
.Select(s => s.GetLocation())
.Concat(symbol.Locations)
.Concat(Symbol.Locations)
.First();
}
}

View File

@@ -15,7 +15,7 @@ namespace Semmle.Extraction.CSharp.Entities
{
Stmt = stmt;
this.location = location;
cx.BindComments(this, location.symbol);
cx.BindComments(this, location.Symbol);
}
protected Statement(Context cx, TSyntax stmt, Kinds.StmtKind kind, IStatementParentEntity parent, int child)

View File

@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
{
get
{
return parent.symbol
return parent.Symbol
?.DeclaringSyntaxReferences
.FirstOrDefault()
?.GetSyntax()
@@ -36,7 +36,7 @@ namespace Semmle.Extraction.CSharp.Entities.Statements
protected override void PopulateStatement(TextWriter trapFile)
{
trapFile.stmt_location(this, cx.CreateLocation(ReportingLocation));
trapFile.stmt_location(this, Context.CreateLocation(ReportingLocation));
}
}
}

View File

@@ -14,18 +14,18 @@ namespace Semmle.Extraction.CSharp.Entities
protected CachedSymbol(Context cx, T init)
: base(cx, init) { }
public virtual Type ContainingType => symbol.ContainingType != null ? Type.Create(Context, symbol.ContainingType) : null;
public virtual Type ContainingType => Symbol.ContainingType != null ? Type.Create(Context, Symbol.ContainingType) : null;
public void PopulateModifiers(TextWriter trapFile)
{
Modifier.ExtractModifiers(Context, trapFile, this, symbol);
Modifier.ExtractModifiers(Context, trapFile, this, Symbol);
}
protected void PopulateAttributes()
{
// Only extract attributes for source declarations
if (ReferenceEquals(symbol, symbol.OriginalDefinition))
Attribute.ExtractAttributes(Context, symbol, this);
if (ReferenceEquals(Symbol, Symbol.OriginalDefinition))
Attribute.ExtractAttributes(Context, Symbol, this);
}
protected void PopulateNullability(TextWriter trapFile, AnnotatedTypeSymbol type)
@@ -55,7 +55,7 @@ namespace Semmle.Extraction.CSharp.Entities
protected void ExtractCompilerGenerated(TextWriter trapFile)
{
if (symbol.IsImplicitlyDeclared)
if (Symbol.IsImplicitlyDeclared)
trapFile.compiler_generated(this);
}
@@ -63,12 +63,12 @@ namespace Semmle.Extraction.CSharp.Entities
/// The location which is stored in the database and is used when highlighing source code.
/// It's generally short, e.g. a method name.
/// </summary>
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.Locations.FirstOrDefault();
public override Microsoft.CodeAnalysis.Location ReportingLocation => Symbol.Locations.FirstOrDefault();
/// <summary>
/// The full text span of the entity, e.g. for binding comments.
/// </summary>
public virtual Microsoft.CodeAnalysis.Location FullLocation => symbol.Locations.FirstOrDefault();
public virtual Microsoft.CodeAnalysis.Location FullLocation => Symbol.Locations.FirstOrDefault();
public virtual IEnumerable<Extraction.Entities.Location> Locations
{
@@ -91,11 +91,11 @@ namespace Semmle.Extraction.CSharp.Entities
/// </summary>
protected void BindComments()
{
if (!symbol.IsImplicitlyDeclared && IsSourceDeclaration && symbol.FromSource())
if (!Symbol.IsImplicitlyDeclared && IsSourceDeclaration && Symbol.FromSource())
Context.BindComments(this, FullLocation);
}
protected virtual T BodyDeclaringSymbol => symbol;
protected virtual T BodyDeclaringSymbol => Symbol;
public BlockSyntax Block
{
@@ -120,9 +120,9 @@ namespace Semmle.Extraction.CSharp.Entities
}
}
public virtual bool IsSourceDeclaration => symbol.IsSourceDeclaration();
public virtual bool IsSourceDeclaration => Symbol.IsSourceDeclaration();
public override bool NeedsPopulation => Context.Defines(symbol);
public override bool NeedsPopulation => Context.Defines(Symbol);
public Extraction.Entities.Location Location => Context.CreateLocation(ReportingLocation);
@@ -143,15 +143,15 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
var handleProp = GetPropertyInfo(symbol, "Handle");
object handleObj = symbol;
var handleProp = GetPropertyInfo(Symbol, "Handle");
object handleObj = Symbol;
if (handleProp is null)
{
var underlyingSymbolProp = GetPropertyInfo(symbol, "UnderlyingSymbol");
var underlyingSymbolProp = GetPropertyInfo(Symbol, "UnderlyingSymbol");
if (underlyingSymbolProp is object)
{
if (underlyingSymbolProp.GetValue(symbol) is object underlying)
if (underlyingSymbolProp.GetValue(Symbol) is object underlying)
{
handleProp = GetPropertyInfo(underlying, "Handle");
handleObj = underlying;

View File

@@ -48,8 +48,8 @@ namespace Semmle.Extraction.CSharp.Entities
{
case ArrayType at:
return GetArrayElementType(at.ElementType);
case NamedType nt when nt.symbol.IsBoundSpan() ||
nt.symbol.IsBoundReadOnlySpan():
case NamedType nt when nt.Symbol.IsBoundSpan() ||
nt.Symbol.IsBoundReadOnlySpan():
return nt.TypeArguments.Single();
case PointerType pt:
return GetArrayElementType(pt.PointedAtType);
@@ -71,7 +71,7 @@ namespace Semmle.Extraction.CSharp.Entities
var nts = (NullableTypeSyntax)syntax;
if (type is NamedType nt)
{
if (!nt.symbol.IsReferenceType)
if (!nt.Symbol.IsReferenceType)
{
Emit(trapFile, loc ?? syntax.GetLocation(), parent, type);
Create(Context, nts.ElementType, this, nt.TypeArguments[0]);

View File

@@ -9,12 +9,12 @@ namespace Semmle.Extraction.CSharp.Entities
private ArrayType(Context cx, IArrayTypeSymbol init)
: base(cx, init)
{
elementLazy = new Lazy<Type>(() => Create(cx, symbol.ElementType));
elementLazy = new Lazy<Type>(() => Create(cx, Symbol.ElementType));
}
private readonly Lazy<Type> elementLazy;
public int Rank => symbol.Rank;
public int Rank => Symbol.Rank;
public Type ElementType => elementLazy.Value;
@@ -33,7 +33,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
trapFile.WriteSubId(ElementType);
symbol.BuildArraySuffix(trapFile);
Symbol.BuildArraySuffix(trapFile);
trapFile.Write(";type");
}

View File

@@ -13,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
symbol.BuildTypeId(Context, trapFile, symbol);
Symbol.BuildTypeId(Context, trapFile, Symbol);
trapFile.Write(";functionpointertype");
}
@@ -21,8 +21,8 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
trapFile.function_pointer_calling_conventions(this, (int)symbol.Signature.CallingConvention);
foreach (var (conv, i) in symbol.Signature.UnmanagedCallingConventionTypes.Select((nt, i) => (Create(Context, nt), i)))
trapFile.function_pointer_calling_conventions(this, (int)Symbol.Signature.CallingConvention);
foreach (var (conv, i) in Symbol.Signature.UnmanagedCallingConventionTypes.Select((nt, i) => (Create(Context, nt), i)))
{
trapFile.has_unmanaged_calling_conventions(this, i, conv.TypeRef);
}

View File

@@ -14,7 +14,7 @@ namespace Semmle.Extraction.CSharp.Entities
private NamedType(Context cx, INamedTypeSymbol init, bool constructUnderlyingTupleType)
: base(cx, init)
{
typeArgumentsLazy = new Lazy<Type[]>(() => symbol.TypeArguments.Select(t => Create(cx, t)).ToArray());
typeArgumentsLazy = new Lazy<Type[]>(() => Symbol.TypeArguments.Select(t => Create(cx, t)).ToArray());
this.constructUnderlyingTupleType = constructUnderlyingTupleType;
}
@@ -30,32 +30,32 @@ namespace Semmle.Extraction.CSharp.Entities
public static NamedType CreateNamedTypeFromTupleType(Context cx, INamedTypeSymbol type) =>
UnderlyingTupleTypeFactory.Instance.CreateEntity(cx, (new SymbolEqualityWrapper(type), typeof(TupleType)), type);
public override bool NeedsPopulation => base.NeedsPopulation || symbol.TypeKind == TypeKind.Error;
public override bool NeedsPopulation => base.NeedsPopulation || Symbol.TypeKind == TypeKind.Error;
public override void Populate(TextWriter trapFile)
{
if (symbol.TypeKind == TypeKind.Error)
if (Symbol.TypeKind == TypeKind.Error)
{
Context.Extractor.MissingType(symbol.ToString(), Context.FromSource);
Context.Extractor.MissingType(Symbol.ToString(), Context.FromSource);
return;
}
if (UsesTypeRef)
trapFile.typeref_type((NamedTypeRef)TypeRef, this);
if (symbol.IsGenericType)
if (Symbol.IsGenericType)
{
if (symbol.IsBoundNullable())
if (Symbol.IsBoundNullable())
{
// An instance of Nullable<T>
trapFile.nullable_underlying_type(this, Create(Context, symbol.TypeArguments[0]).TypeRef);
trapFile.nullable_underlying_type(this, Create(Context, Symbol.TypeArguments[0]).TypeRef);
}
else if (symbol.IsReallyUnbound())
else if (Symbol.IsReallyUnbound())
{
for (var i = 0; i < symbol.TypeParameters.Length; ++i)
for (var i = 0; i < Symbol.TypeParameters.Length; ++i)
{
TypeParameter.Create(Context, symbol.TypeParameters[i]);
var param = symbol.TypeParameters[i];
TypeParameter.Create(Context, Symbol.TypeParameters[i]);
var param = Symbol.TypeParameters[i];
var typeParameter = TypeParameter.Create(Context, param);
trapFile.type_parameters(typeParameter, i, this);
}
@@ -63,11 +63,11 @@ namespace Semmle.Extraction.CSharp.Entities
else
{
var unbound = constructUnderlyingTupleType
? CreateNamedTypeFromTupleType(Context, symbol.ConstructedFrom)
: Type.Create(Context, symbol.ConstructedFrom);
? CreateNamedTypeFromTupleType(Context, Symbol.ConstructedFrom)
: Type.Create(Context, Symbol.ConstructedFrom);
trapFile.constructed_generic(this, unbound.TypeRef);
for (var i = 0; i < symbol.TypeArguments.Length; ++i)
for (var i = 0; i < Symbol.TypeArguments.Length; ++i)
{
trapFile.type_arguments(TypeArguments[i].TypeRef, i, this);
}
@@ -76,19 +76,19 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateType(trapFile, constructUnderlyingTupleType);
if (symbol.EnumUnderlyingType != null)
if (Symbol.EnumUnderlyingType != null)
{
trapFile.enum_underlying_type(this, Type.Create(Context, symbol.EnumUnderlyingType).TypeRef);
trapFile.enum_underlying_type(this, Type.Create(Context, Symbol.EnumUnderlyingType).TypeRef);
}
// Class location
if (!symbol.IsGenericType || symbol.IsReallyUnbound())
if (!Symbol.IsGenericType || Symbol.IsReallyUnbound())
{
foreach (var l in Locations)
trapFile.type_location(this, l);
}
if (symbol.IsAnonymousType)
if (Symbol.IsAnonymousType)
{
trapFile.anonymous_types(this);
}
@@ -105,10 +105,10 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
foreach (var l in GetLocations(symbol))
foreach (var l in GetLocations(Symbol))
yield return Context.CreateLocation(l);
if (Context.Extractor.OutputPath != null && symbol.DeclaringSyntaxReferences.Any())
if (Context.Extractor.OutputPath != null && Symbol.DeclaringSyntaxReferences.Any())
yield return Assembly.CreateOutputAssembly(Context);
}
}
@@ -124,9 +124,9 @@ namespace Semmle.Extraction.CSharp.Entities
);
}
public override Microsoft.CodeAnalysis.Location ReportingLocation => GetLocations(symbol).FirstOrDefault();
public override Microsoft.CodeAnalysis.Location ReportingLocation => GetLocations(Symbol).FirstOrDefault();
private bool IsAnonymousType() => symbol.IsAnonymousType || symbol.Name.Contains("__AnonymousType");
private bool IsAnonymousType() => Symbol.IsAnonymousType || Symbol.Name.Contains("__AnonymousType");
public override void WriteId(TextWriter trapFile)
{
@@ -136,7 +136,7 @@ namespace Semmle.Extraction.CSharp.Entities
}
else
{
symbol.BuildTypeId(Context, trapFile, symbol, constructUnderlyingTupleType);
Symbol.BuildTypeId(Context, trapFile, Symbol, constructUnderlyingTupleType);
trapFile.Write(";type");
}
}
@@ -167,9 +167,9 @@ namespace Semmle.Extraction.CSharp.Entities
// Create typerefs for constructed error types in case they are fully defined elsewhere.
// We cannot use `!this.NeedsPopulation` because this would not be stable as it would depend on
// the assembly that was being extracted at the time.
private bool UsesTypeRef => symbol.TypeKind == TypeKind.Error || SymbolEqualityComparer.Default.Equals(symbol.OriginalDefinition, symbol);
private bool UsesTypeRef => Symbol.TypeKind == TypeKind.Error || SymbolEqualityComparer.Default.Equals(Symbol.OriginalDefinition, Symbol);
public override Type TypeRef => UsesTypeRef ? (Type)NamedTypeRef.Create(Context, symbol) : this;
public override Type TypeRef => UsesTypeRef ? (Type)NamedTypeRef.Create(Context, Symbol) : this;
}
internal class NamedTypeRef : Type<INamedTypeSymbol>
@@ -203,7 +203,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
trapFile.typerefs(this, symbol.Name);
trapFile.typerefs(this, Symbol.Name);
}
}
}

View File

@@ -110,10 +110,10 @@ namespace Semmle.Extraction.CSharp.Entities
public override void Populate(TextWriter trapFile)
{
trapFile.nullability(this, symbol.Annotation);
trapFile.nullability(this, Symbol.Annotation);
var i = 0;
foreach (var s in symbol.NullableParameters)
foreach (var s in Symbol.NullableParameters)
{
trapFile.nullability_parent(Create(Context, s), i, this);
i++;
@@ -122,7 +122,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
symbol.WriteId(trapFile);
Symbol.WriteId(trapFile);
}
public static NullabilityEntity Create(Context cx, Nullability init) => NullabilityFactory.Instance.CreateEntity(cx, init, init);

View File

@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CSharp.Entities
private PointerType(Context cx, IPointerTypeSymbol init)
: base(cx, init)
{
PointedAtType = Create(cx, symbol.PointedAtType);
PointedAtType = Create(cx, Symbol.PointedAtType);
}
public override void WriteId(TextWriter trapFile)

View File

@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
private TupleType(Context cx, INamedTypeSymbol init) : base(cx, init)
{
tupleElementsLazy = new Lazy<Field[]>(() => symbol.TupleElements.Select(t => Field.Create(cx, t)).ToArray());
tupleElementsLazy = new Lazy<Field[]>(() => Symbol.TupleElements.Select(t => Field.Create(cx, t)).ToArray());
}
// All tuple types are "local types"
@@ -32,7 +32,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override void WriteId(TextWriter trapFile)
{
symbol.BuildTypeId(Context, trapFile, symbol);
Symbol.BuildTypeId(Context, trapFile, Symbol);
trapFile.Write(";tuple");
}
@@ -41,7 +41,7 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateType(trapFile);
PopulateGenerics();
var underlyingType = NamedType.CreateNamedTypeFromTupleType(Context, symbol.TupleUnderlyingType ?? symbol);
var underlyingType = NamedType.CreateNamedTypeFromTupleType(Context, Symbol.TupleUnderlyingType ?? Symbol);
trapFile.tuple_underlying_type(this, underlyingType);
@@ -52,7 +52,7 @@ namespace Semmle.Extraction.CSharp.Entities
// 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)
foreach (var l in Symbol.Locations)
trapFile.type_location(this, Context.CreateLocation(l));
}

View File

@@ -15,7 +15,7 @@ namespace Semmle.Extraction.CSharp.Entities
public override bool NeedsPopulation =>
base.NeedsPopulation || symbol.TypeKind == TypeKind.Dynamic || symbol.TypeKind == TypeKind.TypeParameter;
base.NeedsPopulation || Symbol.TypeKind == TypeKind.Dynamic || Symbol.TypeKind == TypeKind.TypeParameter;
public static bool ConstructedOrParentIsConstructed(INamedTypeSymbol symbol)
{
@@ -75,24 +75,24 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.Write("types(");
trapFile.WriteColumn(this);
trapFile.Write(',');
trapFile.WriteColumn((int)GetClassType(Context, symbol, constructUnderlyingTupleType));
trapFile.WriteColumn((int)GetClassType(Context, Symbol, constructUnderlyingTupleType));
trapFile.Write(",\"");
symbol.BuildDisplayName(Context, trapFile, constructUnderlyingTupleType);
Symbol.BuildDisplayName(Context, trapFile, constructUnderlyingTupleType);
trapFile.WriteLine("\")");
// Visit base types
var baseTypes = new List<Type>();
if (symbol.GetNonObjectBaseType(Context) is INamedTypeSymbol @base)
if (Symbol.GetNonObjectBaseType(Context) is INamedTypeSymbol @base)
{
var baseKey = Create(Context, @base);
trapFile.extend(this, baseKey.TypeRef);
if (symbol.TypeKind != TypeKind.Struct)
if (Symbol.TypeKind != TypeKind.Struct)
baseTypes.Add(baseKey);
}
if (!(base.symbol is IArrayTypeSymbol))
if (!(base.Symbol is IArrayTypeSymbol))
{
foreach (var t in base.symbol.Interfaces.Select(i => Create(Context, i)))
foreach (var t in base.Symbol.Interfaces.Select(i => Create(Context, i)))
{
trapFile.implement(this, t.TypeRef);
baseTypes.Add(t);
@@ -100,17 +100,17 @@ namespace Semmle.Extraction.CSharp.Entities
}
var containingType = ContainingType;
if (containingType != null && symbol.Kind != SymbolKind.TypeParameter)
if (containingType != null && Symbol.Kind != SymbolKind.TypeParameter)
{
var originalDefinition = symbol.TypeKind == TypeKind.Error ? this : Create(Context, symbol.OriginalDefinition);
var originalDefinition = Symbol.TypeKind == TypeKind.Error ? this : Create(Context, Symbol.OriginalDefinition);
trapFile.nested_types(this, containingType, originalDefinition);
}
else if (symbol.ContainingNamespace != null)
else if (Symbol.ContainingNamespace != null)
{
trapFile.parent_namespace(this, Namespace.Create(Context, symbol.ContainingNamespace));
trapFile.parent_namespace(this, Namespace.Create(Context, Symbol.ContainingNamespace));
}
if (symbol is IArrayTypeSymbol array)
if (Symbol is IArrayTypeSymbol array)
{
// They are in the namespace of the original object
var elementType = array.ElementType;
@@ -119,7 +119,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.parent_namespace(this, Namespace.Create(Context, ns));
}
if (symbol is IPointerTypeSymbol pointer)
if (Symbol is IPointerTypeSymbol pointer)
{
var elementType = pointer.PointedAtType;
var ns = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
@@ -128,26 +128,26 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.parent_namespace(this, Namespace.Create(Context, ns));
}
if (symbol.BaseType != null && symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
if (Symbol.BaseType != null && Symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
{
// This is a delegate.
// The method "Invoke" has the return type.
var invokeMethod = ((INamedTypeSymbol)symbol).DelegateInvokeMethod;
var invokeMethod = ((INamedTypeSymbol)Symbol).DelegateInvokeMethod;
ExtractParametersForDelegateLikeType(trapFile, invokeMethod,
t => trapFile.delegate_return_type(this, t));
}
if (symbol is IFunctionPointerTypeSymbol functionPointer)
if (Symbol is IFunctionPointerTypeSymbol functionPointer)
{
ExtractParametersForDelegateLikeType(trapFile, functionPointer.Signature,
t => trapFile.function_pointer_return_type(this, t));
}
Modifier.ExtractModifiers(Context, trapFile, this, symbol);
Modifier.ExtractModifiers(Context, trapFile, this, Symbol);
if (IsSourceDeclaration && symbol.FromSource())
if (IsSourceDeclaration && Symbol.FromSource())
{
var declSyntaxReferences = symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).ToArray();
var declSyntaxReferences = Symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).ToArray();
var baseLists = declSyntaxReferences.OfType<ClassDeclarationSyntax>().Select(c => c.BaseList);
baseLists = baseLists.Concat(declSyntaxReferences.OfType<InterfaceDeclarationSyntax>().Select(c => c.BaseList));
@@ -157,7 +157,7 @@ namespace Semmle.Extraction.CSharp.Entities
.Where(bl => bl != null)
.SelectMany(bl => bl.Types)
.Zip(
baseTypes.Where(bt => bt.symbol.SpecialType != SpecialType.System_Object),
baseTypes.Where(bt => bt.Symbol.SpecialType != SpecialType.System_Object),
(s, t) => TypeMention.Create(Context, s.Type, this, t))
.Enumerate();
}
@@ -171,7 +171,7 @@ namespace Semmle.Extraction.CSharp.Entities
var originalParam = invokeMethod.OriginalDefinition.Parameters[i];
var originalParamEntity = SymbolEqualityComparer.Default.Equals(param, originalParam)
? null
: DelegateTypeParameter.Create(Context, originalParam, Create(Context, ((INamedTypeSymbol)symbol).OriginalDefinition));
: DelegateTypeParameter.Create(Context, originalParam, Create(Context, ((INamedTypeSymbol)Symbol).OriginalDefinition));
DelegateTypeParameter.Create(Context, param, this, originalParamEntity);
}
@@ -187,12 +187,12 @@ namespace Semmle.Extraction.CSharp.Entities
/// </summary>
public void ExtractRecursive()
{
foreach (var l in symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax().GetLocation()))
foreach (var l in Symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax().GetLocation()))
{
Context.BindComments(this, l);
}
foreach (var member in symbol.GetMembers())
foreach (var member in Symbol.GetMembers())
{
switch (member.Kind)
{
@@ -211,21 +211,21 @@ namespace Semmle.Extraction.CSharp.Entities
/// </summary>
public void PopulateGenerics()
{
if (symbol == null || !NeedsPopulation || !Context.ExtractGenerics(this))
if (Symbol == null || !NeedsPopulation || !Context.ExtractGenerics(this))
return;
var members = new List<ISymbol>();
foreach (var member in symbol.GetMembers())
foreach (var member in Symbol.GetMembers())
members.Add(member);
foreach (var member in symbol.GetTypeMembers())
foreach (var member in Symbol.GetTypeMembers())
members.Add(member);
// Mono extractor puts all BASE interface members as members of the current interface.
if (symbol.TypeKind == TypeKind.Interface)
if (Symbol.TypeKind == TypeKind.Interface)
{
foreach (var baseInterface in symbol.Interfaces)
foreach (var baseInterface in Symbol.Interfaces)
{
foreach (var member in baseInterface.GetMembers())
members.Add(member);
@@ -239,10 +239,10 @@ namespace Semmle.Extraction.CSharp.Entities
Context.CreateEntity(member);
}
if (symbol.BaseType != null)
Create(Context, symbol.BaseType).PopulateGenerics();
if (Symbol.BaseType != null)
Create(Context, Symbol.BaseType).PopulateGenerics();
foreach (var i in symbol.Interfaces)
foreach (var i in Symbol.Interfaces)
{
Create(Context, i).PopulateGenerics();
}
@@ -250,7 +250,7 @@ namespace Semmle.Extraction.CSharp.Entities
public void ExtractRecursive(TextWriter trapFile, IEntity parent)
{
if (symbol.ContainingSymbol.Kind == SymbolKind.Namespace && !symbol.ContainingNamespace.IsGlobalNamespace)
if (Symbol.ContainingSymbol.Kind == SymbolKind.Namespace && !Symbol.ContainingNamespace.IsGlobalNamespace)
{
trapFile.parent_namespace_declaration(this, (NamespaceDeclaration)parent);
}
@@ -315,10 +315,10 @@ namespace Semmle.Extraction.CSharp.Entities
public override bool Equals(object obj)
{
var other = obj as Type;
return other?.GetType() == GetType() && SymbolEqualityComparer.Default.Equals(other.symbol, symbol);
return other?.GetType() == GetType() && SymbolEqualityComparer.Default.Equals(other.Symbol, Symbol);
}
public override int GetHashCode() => SymbolEqualityComparer.Default.GetHashCode(symbol);
public override int GetHashCode() => SymbolEqualityComparer.Default.GetHashCode(Symbol);
}
internal abstract class Type<T> : Type where T : ITypeSymbol
@@ -327,6 +327,6 @@ namespace Semmle.Extraction.CSharp.Entities
: base(cx, init) { }
// todo: change this with .net 5 to be an override
public new T symbol => (T)base.symbol;
public new T Symbol => (T)base.Symbol;
}
}

View File

@@ -24,22 +24,22 @@ namespace Semmle.Extraction.CSharp.Entities
var constraints = new TypeParameterConstraints(Context);
trapFile.type_parameter_constraints(constraints, this);
if (symbol.HasReferenceTypeConstraint)
if (Symbol.HasReferenceTypeConstraint)
trapFile.general_type_parameter_constraints(constraints, 1);
if (symbol.HasValueTypeConstraint)
if (Symbol.HasValueTypeConstraint)
trapFile.general_type_parameter_constraints(constraints, 2);
if (symbol.HasConstructorConstraint)
if (Symbol.HasConstructorConstraint)
trapFile.general_type_parameter_constraints(constraints, 3);
if (symbol.HasUnmanagedTypeConstraint)
if (Symbol.HasUnmanagedTypeConstraint)
trapFile.general_type_parameter_constraints(constraints, 4);
if (symbol.ReferenceTypeConstraintNullableAnnotation == NullableAnnotation.Annotated)
if (Symbol.ReferenceTypeConstraintNullableAnnotation == NullableAnnotation.Annotated)
trapFile.general_type_parameter_constraints(constraints, 5);
foreach (var abase in symbol.GetAnnotatedTypeConstraints())
foreach (var abase in Symbol.GetAnnotatedTypeConstraints())
{
var t = Create(Context, abase.Symbol);
trapFile.specific_type_parameter_constraints(constraints, t.TypeRef);
@@ -47,19 +47,19 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.specific_type_parameter_nullability(constraints, t.TypeRef, NullabilityEntity.Create(Context, Nullability.Create(abase)));
}
trapFile.types(this, Kinds.TypeKind.TYPE_PARAMETER, symbol.Name);
trapFile.types(this, Kinds.TypeKind.TYPE_PARAMETER, Symbol.Name);
var parentNs = Namespace.Create(Context, symbol.TypeParameterKind == TypeParameterKind.Method ? Context.Compilation.GlobalNamespace : symbol.ContainingNamespace);
var parentNs = Namespace.Create(Context, Symbol.TypeParameterKind == TypeParameterKind.Method ? Context.Compilation.GlobalNamespace : Symbol.ContainingNamespace);
trapFile.parent_namespace(this, parentNs);
foreach (var l in symbol.Locations)
foreach (var l in Symbol.Locations)
{
trapFile.type_location(this, Context.CreateLocation(l));
}
if (IsSourceDeclaration)
{
var declSyntaxReferences = symbol.DeclaringSyntaxReferences
var declSyntaxReferences = Symbol.DeclaringSyntaxReferences
.Select(d => d.GetSyntax())
.Select(s => s.Parent)
.Where(p => p != null)
@@ -69,7 +69,7 @@ namespace Semmle.Extraction.CSharp.Entities
clauses = clauses.Concat(declSyntaxReferences.OfType<ClassDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
clauses = clauses.Concat(declSyntaxReferences.OfType<InterfaceDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
clauses = clauses.Concat(declSyntaxReferences.OfType<StructDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
foreach (var clause in clauses.Where(c => c.Name.Identifier.Text == symbol.Name))
foreach (var clause in clauses.Where(c => c.Name.Identifier.Text == Symbol.Name))
{
TypeMention.Create(Context, clause.Name, this, this);
foreach (var constraint in clause.Constraints.OfType<TypeConstraintSyntax>())
@@ -92,13 +92,13 @@ namespace Semmle.Extraction.CSharp.Entities
{
get
{
switch (symbol.Variance)
switch (Symbol.Variance)
{
case VarianceKind.None: return Variance.None;
case VarianceKind.Out: return Variance.Out;
case VarianceKind.In: return Variance.In;
default:
throw new InternalError($"Unexpected VarianceKind {symbol.Variance}");
throw new InternalError($"Unexpected VarianceKind {Symbol.Variance}");
}
}
}
@@ -107,22 +107,22 @@ namespace Semmle.Extraction.CSharp.Entities
{
string kind;
IEntity containingEntity;
switch (symbol.TypeParameterKind)
switch (Symbol.TypeParameterKind)
{
case TypeParameterKind.Method:
kind = "methodtypeparameter";
containingEntity = Method.Create(Context, (IMethodSymbol)symbol.ContainingSymbol);
containingEntity = Method.Create(Context, (IMethodSymbol)Symbol.ContainingSymbol);
break;
case TypeParameterKind.Type:
kind = "typeparameter";
containingEntity = Create(Context, symbol.ContainingType);
containingEntity = Create(Context, Symbol.ContainingType);
break;
default:
throw new InternalError(symbol, $"Unhandled type parameter kind {symbol.TypeParameterKind}");
throw new InternalError(Symbol, $"Unhandled type parameter kind {Symbol.TypeParameterKind}");
}
trapFile.WriteSubId(containingEntity);
trapFile.Write('_');
trapFile.Write(symbol.Ordinal);
trapFile.Write(Symbol.Ordinal);
trapFile.Write(';');
trapFile.Write(kind);
}

View File

@@ -15,10 +15,10 @@ namespace Semmle.Extraction.CSharp.Entities
PopulateMethod(trapFile);
PopulateModifiers(trapFile);
var returnType = Type.Create(Context, symbol.ReturnType);
var returnType = Type.Create(Context, Symbol.ReturnType);
trapFile.operators(this,
symbol.Name,
OperatorSymbol(Context, symbol.Name),
Symbol.Name,
OperatorSymbol(Context, Symbol.Name),
ContainingType,
returnType.TypeRef,
(UserOperator)OriginalDefinition);
@@ -28,7 +28,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (IsSourceDeclaration)
{
var declSyntaxReferences = symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).ToArray();
var declSyntaxReferences = Symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).ToArray();
foreach (var declaration in declSyntaxReferences.OfType<OperatorDeclarationSyntax>())
TypeMention.Create(Context, declaration.ReturnType, this, returnType);
foreach (var declaration in declSyntaxReferences.OfType<ConversionOperatorDeclarationSyntax>())
@@ -38,7 +38,7 @@ namespace Semmle.Extraction.CSharp.Entities
ContainingType.PopulateGenerics();
}
public override bool NeedsPopulation => Context.Defines(symbol) || IsImplicitOperator(out _);
public override bool NeedsPopulation => Context.Defines(Symbol) || IsImplicitOperator(out _);
public override Type ContainingType
{
@@ -57,22 +57,22 @@ namespace Semmle.Extraction.CSharp.Entities
/// <returns></returns>
private bool IsImplicitOperator(out ITypeSymbol containingType)
{
containingType = symbol.ContainingType;
containingType = Symbol.ContainingType;
if (containingType != null)
{
var containingNamedType = containingType as INamedTypeSymbol;
return containingNamedType == null ||
!containingNamedType.GetMembers(symbol.Name).Contains(symbol);
!containingNamedType.GetMembers(Symbol.Name).Contains(Symbol);
}
var pointerType = symbol.Parameters.Select(p => p.Type).OfType<IPointerTypeSymbol>().FirstOrDefault();
var pointerType = Symbol.Parameters.Select(p => p.Type).OfType<IPointerTypeSymbol>().FirstOrDefault();
if (pointerType != null)
{
containingType = pointerType;
return true;
}
Context.ModelError(symbol, "Unexpected implicit operator");
Context.ModelError(Symbol, "Unexpected implicit operator");
return true;
}