C#: Fix public property naming

This commit is contained in:
Tamas Vajk
2020-10-05 11:01:33 +02:00
parent a4fec39c11
commit 7075c6f8ca
14 changed files with 180 additions and 180 deletions

View File

@@ -17,30 +17,30 @@ namespace Semmle.Extraction.CIL
private readonly FileStream stream;
private Entities.Assembly? assemblyNull;
public Extraction.Context cx { get; }
public MetadataReader mdReader { get; }
public PEReader peReader { get; }
public string assemblyPath { get; }
public Entities.Assembly assembly
public Extraction.Context Cx { get; }
public MetadataReader MdReader { get; }
public PEReader PeReader { get; }
public string AssemblyPath { get; }
public Entities.Assembly Assembly
{
get { return assemblyNull!; }
set { assemblyNull = value; }
}
public PDB.IPdb? pdb { get; }
public PDB.IPdb? Pdb { get; }
public Context(Extraction.Context cx, string assemblyPath, bool extractPdbs)
{
this.cx = cx;
this.assemblyPath = assemblyPath;
this.Cx = cx;
this.AssemblyPath = assemblyPath;
stream = File.OpenRead(assemblyPath);
peReader = new PEReader(stream, PEStreamOptions.PrefetchEntireImage);
mdReader = peReader.GetMetadataReader();
PeReader = new PEReader(stream, PEStreamOptions.PrefetchEntireImage);
MdReader = PeReader.GetMetadataReader();
TypeSignatureDecoder = new Entities.TypeSignatureDecoder(this);
globalNamespace = new Lazy<Entities.Namespace>(() => Populate(new Entities.Namespace(this, "", null)));
systemNamespace = new Lazy<Entities.Namespace>(() => Populate(new Entities.Namespace(this, "System")));
genericHandleFactory = new CachedFunction<GenericContext, Handle, IExtractedEntity>(CreateGenericHandle);
namespaceFactory = new CachedFunction<StringHandle, Entities.Namespace>(n => CreateNamespace(mdReader.GetString(n)));
namespaceFactory = new CachedFunction<StringHandle, Entities.Namespace>(n => CreateNamespace(MdReader.GetString(n)));
namespaceDefinitionFactory = new CachedFunction<NamespaceDefinitionHandle, Entities.Namespace>(CreateNamespace);
sourceFiles = new CachedFunction<PDB.ISourceFile, Entities.PdbSourceFile>(path => new Entities.PdbSourceFile(this, path));
folders = new CachedFunction<PathTransformer.ITransformedPath, Entities.Folder>(path => new Entities.Folder(this, path));
@@ -50,8 +50,8 @@ namespace Semmle.Extraction.CIL
if (extractPdbs)
{
pdb = PDB.PdbReader.Create(assemblyPath, peReader);
if (pdb != null)
Pdb = PDB.PdbReader.Create(assemblyPath, PeReader);
if (Pdb != null)
{
cx.Extractor.Logger.Log(Util.Logging.Severity.Info, string.Format("Found PDB information for {0}", assemblyPath));
}
@@ -60,9 +60,9 @@ namespace Semmle.Extraction.CIL
public void Dispose()
{
if (pdb != null)
pdb.Dispose();
peReader.Dispose();
if (Pdb != null)
Pdb.Dispose();
PeReader.Dispose();
stream.Dispose();
}
@@ -80,7 +80,7 @@ namespace Semmle.Extraction.CIL
public void WriteAssemblyPrefix(TextWriter trapFile)
{
var def = mdReader.GetAssemblyDefinition();
var def = MdReader.GetAssemblyDefinition();
trapFile.Write(GetString(def.Name));
trapFile.Write('_');
trapFile.Write(def.Version.ToString());
@@ -113,7 +113,7 @@ namespace Semmle.Extraction.CIL
/// <returns>The debugging information, or null if the information could not be located.</returns>
public PDB.IMethod? GetMethodDebugInformation(MethodDefinitionHandle handle)
{
return pdb?.GetMethod(handle.ToDebugInformationHandle());
return Pdb?.GetMethod(handle.ToDebugInformationHandle());
}
}
@@ -123,11 +123,11 @@ namespace Semmle.Extraction.CIL
/// </summary>
public abstract class GenericContext
{
public Context cx { get; }
public Context Cx { get; }
protected GenericContext(Context cx)
{
this.cx = cx;
this.Cx = cx;
}
/// <summary>

View File

@@ -27,27 +27,27 @@ namespace Semmle.Extraction.CIL.Entities
public Assembly(Context cx) : base(cx)
{
cx.assembly = this;
var def = cx.mdReader.GetAssemblyDefinition();
cx.Assembly = this;
var def = cx.MdReader.GetAssemblyDefinition();
assemblyName = new AssemblyName
{
Name = cx.mdReader.GetString(def.Name),
Name = cx.MdReader.GetString(def.Name),
Version = def.Version,
CultureInfo = new CultureInfo(cx.mdReader.GetString(def.Culture))
CultureInfo = new CultureInfo(cx.MdReader.GetString(def.Culture))
};
if (!def.PublicKey.IsNil)
assemblyName.SetPublicKey(cx.mdReader.GetBlobBytes(def.PublicKey));
assemblyName.SetPublicKey(cx.MdReader.GetBlobBytes(def.PublicKey));
file = new File(cx, cx.assemblyPath);
file = new File(cx, cx.AssemblyPath);
}
public override void WriteId(TextWriter trapFile)
{
trapFile.Write(FullName);
trapFile.Write("#file:///");
trapFile.Write(cx.assemblyPath.Replace("\\", "/"));
trapFile.Write(Cx.AssemblyPath.Replace("\\", "/"));
}
public override bool Equals(object? obj)
@@ -68,24 +68,24 @@ namespace Semmle.Extraction.CIL.Entities
yield return file;
yield return Tuples.assemblies(this, file, FullName, assemblyName.Name ?? string.Empty, assemblyName.Version?.ToString() ?? string.Empty);
if (cx.pdb != null)
if (Cx.Pdb != null)
{
foreach (var f in cx.pdb.SourceFiles)
foreach (var f in Cx.Pdb.SourceFiles)
{
yield return cx.CreateSourceFile(f);
yield return Cx.CreateSourceFile(f);
}
}
foreach (var handle in cx.mdReader.TypeDefinitions)
foreach (var handle in Cx.MdReader.TypeDefinitions)
{
IExtractionProduct? product = null;
try
{
product = cx.Create(handle);
product = Cx.Create(handle);
}
catch (InternalError e)
{
cx.cx.ExtractionError("Error processing type definition", e.Message, GeneratedLocation.Create(cx.cx), e.StackTrace);
Cx.Cx.ExtractionError("Error processing type definition", e.Message, GeneratedLocation.Create(Cx.Cx), e.StackTrace);
}
// Limitation of C#: Cannot yield return inside a try-catch.
@@ -93,16 +93,16 @@ namespace Semmle.Extraction.CIL.Entities
yield return product;
}
foreach (var handle in cx.mdReader.MethodDefinitions)
foreach (var handle in Cx.MdReader.MethodDefinitions)
{
IExtractionProduct? product = null;
try
{
product = cx.Create(handle);
product = Cx.Create(handle);
}
catch (InternalError e)
{
cx.cx.ExtractionError("Error processing bytecode", e.Message, GeneratedLocation.Create(cx.cx), e.StackTrace);
Cx.Cx.ExtractionError("Error processing bytecode", e.Message, GeneratedLocation.Create(Cx.Cx), e.StackTrace);
}
if (product != null)
@@ -115,7 +115,7 @@ namespace Semmle.Extraction.CIL.Entities
{
using var cilContext = new Context(cx, assemblyPath, extractPdbs);
cilContext.Populate(new Assembly(cilContext));
cilContext.cx.PopulateAll();
cilContext.Cx.PopulateAll();
}
/// <summary>

View File

@@ -22,7 +22,7 @@ namespace Semmle.Extraction.CIL.Entities
public Attribute(Context cx, IEntity @object, CustomAttributeHandle handle) : base(cx)
{
attrib = cx.mdReader.GetCustomAttribute(handle);
attrib = cx.MdReader.GetCustomAttribute(handle);
this.handle = handle;
this.@object = @object;
}
@@ -38,7 +38,7 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
var constructor = (Method)cx.Create(attrib.Constructor);
var constructor = (Method)Cx.Create(attrib.Constructor);
yield return constructor;
yield return Tuples.cil_attribute(this, @object, constructor);
@@ -47,7 +47,7 @@ namespace Semmle.Extraction.CIL.Entities
try
{
decoded = attrib.DecodeValue(new CustomAttributeDecoder(cx));
decoded = attrib.DecodeValue(new CustomAttributeDecoder(Cx));
}
catch (NotImplementedException)
{

View File

@@ -24,14 +24,14 @@ namespace Semmle.Extraction.CIL.Entities
{
this.handle = handle;
this.parent = parent;
ed = cx.mdReader.GetEventDefinition(handle);
ed = cx.MdReader.GetEventDefinition(handle);
}
public override void WriteId(TextWriter trapFile)
{
parent.WriteId(trapFile);
trapFile.Write('.');
trapFile.Write(cx.ShortName(ed.Name));
trapFile.Write(Cx.ShortName(ed.Name));
}
public override string IdSuffix => ";cil-event";
@@ -47,34 +47,34 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
var signature = (Type)cx.CreateGeneric(parent, ed.Type);
var signature = (Type)Cx.CreateGeneric(parent, ed.Type);
yield return signature;
yield return Tuples.cil_event(this, parent, cx.ShortName(ed.Name), signature);
yield return Tuples.cil_event(this, parent, Cx.ShortName(ed.Name), signature);
var accessors = ed.GetAccessors();
if (!accessors.Adder.IsNil)
{
var adder = (Method)cx.CreateGeneric(parent, accessors.Adder);
var adder = (Method)Cx.CreateGeneric(parent, accessors.Adder);
yield return adder;
yield return Tuples.cil_adder(this, adder);
}
if (!accessors.Remover.IsNil)
{
var remover = (Method)cx.CreateGeneric(parent, accessors.Remover);
var remover = (Method)Cx.CreateGeneric(parent, accessors.Remover);
yield return remover;
yield return Tuples.cil_remover(this, remover);
}
if (!accessors.Raiser.IsNil)
{
var raiser = (Method)cx.CreateGeneric(parent, accessors.Raiser);
var raiser = (Method)Cx.CreateGeneric(parent, accessors.Raiser);
yield return raiser;
yield return Tuples.cil_raiser(this, raiser);
}
foreach (var c in Attribute.Populate(cx, this, ed.GetCustomAttributes()))
foreach (var c in Attribute.Populate(Cx, this, ed.GetCustomAttributes()))
yield return c;
}
}

View File

@@ -17,7 +17,7 @@ namespace Semmle.Extraction.CIL.Entities
private readonly System.Reflection.Metadata.ExceptionRegion r;
private readonly Dictionary<int, IInstruction> jump_table;
public ExceptionRegion(GenericContext gc, MethodImplementation method, int index, System.Reflection.Metadata.ExceptionRegion r, Dictionary<int, IInstruction> jump_table) : base(gc.cx)
public ExceptionRegion(GenericContext gc, MethodImplementation method, int index, System.Reflection.Metadata.ExceptionRegion r, Dictionary<int, IInstruction> jump_table) : base(gc.Cx)
{
this.gc = gc;
this.method = method;
@@ -50,7 +50,7 @@ namespace Semmle.Extraction.CIL.Entities
if (!r.CatchType.IsNil)
{
var catchType = (Type)cx.CreateGeneric(gc, r.CatchType);
var catchType = (Type)Cx.CreateGeneric(gc, r.CatchType);
yield return catchType;
yield return Tuples.cil_handler_type(this, catchType);
}

View File

@@ -81,10 +81,10 @@ namespace Semmle.Extraction.CIL.Entities
private readonly Handle handle;
private readonly FieldDefinition fd;
public DefinitionField(GenericContext gc, FieldDefinitionHandle handle) : base(gc.cx)
public DefinitionField(GenericContext gc, FieldDefinitionHandle handle) : base(gc.Cx)
{
this.handle = handle;
fd = cx.mdReader.GetFieldDefinition(handle);
fd = Cx.MdReader.GetFieldDefinition(handle);
}
public override bool Equals(object? obj)
@@ -98,7 +98,7 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
yield return Tuples.metadata_handle(this, cx.assembly, MetadataTokens.GetToken(handle));
yield return Tuples.metadata_handle(this, Cx.Assembly, MetadataTokens.GetToken(handle));
foreach (var c in base.Contents)
yield return c;
@@ -118,16 +118,16 @@ namespace Semmle.Extraction.CIL.Entities
if (fd.Attributes.HasFlag(FieldAttributes.Assembly))
yield return Tuples.cil_internal(this);
foreach (var c in Attribute.Populate(cx, this, fd.GetCustomAttributes()))
foreach (var c in Attribute.Populate(Cx, this, fd.GetCustomAttributes()))
yield return c;
}
}
public override string Name => cx.GetString(fd.Name);
public override string Name => Cx.GetString(fd.Name);
public override Type DeclaringType => (Type)cx.Create(fd.GetDeclaringType());
public override Type DeclaringType => (Type)Cx.Create(fd.GetDeclaringType());
public override Type Type => fd.DecodeSignature(cx.TypeSignatureDecoder, DeclaringType);
public override Type Type => fd.DecodeSignature(Cx.TypeSignatureDecoder, DeclaringType);
public override IEnumerable<Type> TypeParameters => throw new NotImplementedException();
@@ -141,12 +141,12 @@ namespace Semmle.Extraction.CIL.Entities
private readonly GenericContext gc;
private readonly Type declType;
public MemberReferenceField(GenericContext gc, MemberReferenceHandle handle) : base(gc.cx)
public MemberReferenceField(GenericContext gc, MemberReferenceHandle handle) : base(gc.Cx)
{
this.handle = handle;
this.gc = gc;
mr = cx.mdReader.GetMemberReference(handle);
declType = (Type)cx.CreateGeneric(gc, mr.Parent);
mr = Cx.MdReader.GetMemberReference(handle);
declType = (Type)Cx.CreateGeneric(gc, mr.Parent);
}
public override bool Equals(object? obj)
@@ -159,11 +159,11 @@ namespace Semmle.Extraction.CIL.Entities
return handle.GetHashCode();
}
public override string Name => cx.GetString(mr.Name);
public override string Name => Cx.GetString(mr.Name);
public override Type DeclaringType => declType;
public override Type Type => mr.DecodeFieldSignature(cx.TypeSignatureDecoder, this);
public override Type Type => mr.DecodeFieldSignature(Cx.TypeSignatureDecoder, this);
public override IEnumerable<Type> TypeParameters => gc.TypeParameters.Concat(declType.TypeParameters);

View File

@@ -19,7 +19,7 @@ namespace Semmle.Extraction.CIL.Entities
public File(Context cx, string path) : base(cx)
{
this.OriginalPath = path;
TransformedPath = cx.cx.Extractor.PathTransformer.Transform(OriginalPath);
TransformedPath = cx.Cx.Extractor.PathTransformer.Transform(OriginalPath);
}
public override void WriteId(TextWriter trapFile)
@@ -40,7 +40,7 @@ namespace Semmle.Extraction.CIL.Entities
{
if (TransformedPath.ParentDirectory is PathTransformer.ITransformedPath dir)
{
var parent = cx.CreateFolder(dir);
var parent = Cx.CreateFolder(dir);
yield return parent;
yield return Tuples.containerparent(parent, this);
}
@@ -70,9 +70,9 @@ namespace Semmle.Extraction.CIL.Entities
var text = file.Contents;
if (text == null)
cx.cx.Extractor.Logger.Log(Util.Logging.Severity.Warning, string.Format("PDB source file {0} could not be found", OriginalPath));
Cx.Cx.Extractor.Logger.Log(Util.Logging.Severity.Warning, string.Format("PDB source file {0} could not be found", OriginalPath));
else
cx.cx.TrapWriter.Archive(TransformedPath, text);
Cx.Cx.TrapWriter.Archive(TransformedPath, text);
yield return Tuples.file_extraction_mode(this, 2);
}

View File

@@ -29,7 +29,7 @@ namespace Semmle.Extraction.CIL.Entities
{
if (transformedPath.ParentDirectory is PathTransformer.ITransformedPath parent)
{
var parentFolder = cx.CreateFolder(parent);
var parentFolder = Cx.CreateFolder(parent);
yield return parentFolder;
yield return Tuples.containerparent(parentFolder, this);
}

View File

@@ -374,7 +374,7 @@ namespace Semmle.Extraction.CIL.Entities
switch (PayloadType)
{
case Payload.String:
yield return Tuples.cil_value(this, cx.mdReader.GetUserString(MetadataTokens.UserStringHandle(payloadValue)));
yield return Tuples.cil_value(this, Cx.MdReader.GetUserString(MetadataTokens.UserStringHandle(payloadValue)));
break;
case Payload.Float32:
yield return Tuples.cil_value(this, BitConverter.ToSingle(data, offset).ToString());
@@ -405,7 +405,7 @@ namespace Semmle.Extraction.CIL.Entities
case Payload.ValueType:
// A generic EntityHandle.
var handle = MetadataTokens.EntityHandle(payloadValue);
var target = cx.CreateGeneric(Method, handle);
var target = Cx.CreateGeneric(Method, handle);
yield return target;
if (target != null)
{
@@ -494,7 +494,7 @@ namespace Semmle.Extraction.CIL.Entities
// TODO: Find a solution to this.
// For now, just log the error
cx.cx.ExtractionError("A CIL instruction jumps outside the current method", "", Extraction.Entities.GeneratedLocation.Create(cx.cx), "", Util.Logging.Severity.Warning);
Cx.Cx.ExtractionError("A CIL instruction jumps outside the current method", "", Extraction.Entities.GeneratedLocation.Create(Cx.Cx), "", Util.Logging.Severity.Warning);
}
}
}

View File

@@ -26,7 +26,7 @@ namespace Semmle.Extraction.CIL.Entities
protected GenericContext gc;
protected MethodSignature<ITypeSignature> signature;
protected Method(GenericContext gc) : base(gc.cx)
protected Method(GenericContext gc) : base(gc.Cx)
{
this.gc = gc;
}
@@ -92,11 +92,11 @@ namespace Semmle.Extraction.CIL.Entities
if (!IsStatic)
{
yield return cx.Populate(new Parameter(cx, this, i++, DeclaringType));
yield return Cx.Populate(new Parameter(Cx, this, i++, DeclaringType));
}
foreach (var p in parameterTypes)
yield return cx.Populate(new Parameter(cx, this, i++, p));
yield return Cx.Populate(new Parameter(Cx, this, i++, p));
}
}
@@ -115,7 +115,7 @@ namespace Semmle.Extraction.CIL.Entities
{
private readonly Method m;
public MethodImplementation(Method m) : base(m.cx)
public MethodImplementation(Method m) : base(m.Cx)
{
this.m = m;
}
@@ -124,7 +124,7 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
yield return Tuples.cil_method_implementation(this, m, cx.assembly);
yield return Tuples.cil_method_implementation(this, m, Cx.Assembly);
}
}
}
@@ -149,16 +149,16 @@ namespace Semmle.Extraction.CIL.Entities
public DefinitionMethod(GenericContext gc, MethodDefinitionHandle handle) : base(gc)
{
md = cx.mdReader.GetMethodDefinition(handle);
md = Cx.MdReader.GetMethodDefinition(handle);
this.gc = gc;
this.handle = handle;
name = cx.GetString(md.Name);
name = Cx.GetString(md.Name);
declaringType = (Type)cx.CreateGeneric(this, md.GetDeclaringType());
declaringType = (Type)Cx.CreateGeneric(this, md.GetDeclaringType());
signature = md.DecodeSignature(new SignatureDecoder(), this);
methodDebugInformation = cx.GetMethodDebugInformation(handle);
methodDebugInformation = Cx.GetMethodDebugInformation(handle);
}
public override bool Equals(object? obj)
@@ -172,7 +172,7 @@ namespace Semmle.Extraction.CIL.Entities
public override Type DeclaringType => declaringType;
public override string Name => cx.ShortName(md.Name);
public override string Name => Cx.ShortName(md.Name);
public override string NameLabel => name;
@@ -191,14 +191,14 @@ namespace Semmle.Extraction.CIL.Entities
// depend on other type parameters (as a constraint).
genericParams = new MethodTypeParameter[md.GetGenericParameters().Count];
for (var i = 0; i < genericParams.Length; ++i)
genericParams[i] = cx.Populate(new MethodTypeParameter(this, this, i));
genericParams[i] = Cx.Populate(new MethodTypeParameter(this, this, i));
for (var i = 0; i < genericParams.Length; ++i)
genericParams[i].PopulateHandle(md.GetGenericParameters()[i]);
foreach (var p in genericParams)
yield return p;
}
var typeSignature = md.DecodeSignature(cx.TypeSignatureDecoder, this);
var typeSignature = md.DecodeSignature(Cx.TypeSignatureDecoder, this);
Parameters = MakeParameters(typeSignature.ParameterTypes).ToArray();
@@ -208,38 +208,38 @@ namespace Semmle.Extraction.CIL.Entities
foreach (var c in PopulateFlags)
yield return c;
foreach (var p in md.GetParameters().Select(h => cx.mdReader.GetParameter(h)).Where(p => p.SequenceNumber > 0))
foreach (var p in md.GetParameters().Select(h => Cx.MdReader.GetParameter(h)).Where(p => p.SequenceNumber > 0))
{
var pe = Parameters[IsStatic ? p.SequenceNumber - 1 : p.SequenceNumber];
if (p.Attributes.HasFlag(ParameterAttributes.Out))
yield return Tuples.cil_parameter_out(pe);
if (p.Attributes.HasFlag(ParameterAttributes.In))
yield return Tuples.cil_parameter_in(pe);
Attribute.Populate(cx, pe, p.GetCustomAttributes());
Attribute.Populate(Cx, pe, p.GetCustomAttributes());
}
yield return Tuples.metadata_handle(this, cx.assembly, MetadataTokens.GetToken(handle));
yield return Tuples.metadata_handle(this, Cx.Assembly, MetadataTokens.GetToken(handle));
yield return Tuples.cil_method(this, Name, declaringType, typeSignature.ReturnType);
yield return Tuples.cil_method_source_declaration(this, this);
yield return Tuples.cil_method_location(this, cx.assembly);
yield return Tuples.cil_method_location(this, Cx.Assembly);
if (HasBytecode)
{
Implementation = new MethodImplementation(this);
yield return Implementation;
var body = cx.peReader.GetMethodBody(md.RelativeVirtualAddress);
var body = Cx.PeReader.GetMethodBody(md.RelativeVirtualAddress);
if (!body.LocalSignature.IsNil)
{
var locals = cx.mdReader.GetStandaloneSignature(body.LocalSignature);
var localVariableTypes = locals.DecodeLocalSignature(cx.TypeSignatureDecoder, this);
var locals = Cx.MdReader.GetStandaloneSignature(body.LocalSignature);
var localVariableTypes = locals.DecodeLocalSignature(Cx.TypeSignatureDecoder, this);
this.locals = new LocalVariable[localVariableTypes.Length];
for (var l = 0; l < this.locals.Length; ++l)
{
this.locals[l] = cx.Populate(new LocalVariable(cx, Implementation, l, localVariableTypes[l]));
this.locals[l] = Cx.Populate(new LocalVariable(Cx, Implementation, l, localVariableTypes[l]));
yield return this.locals[l];
}
}
@@ -259,7 +259,7 @@ namespace Semmle.Extraction.CIL.Entities
if (methodDebugInformation != null)
{
var sourceLocation = cx.CreateSourceLocation(methodDebugInformation.Location);
var sourceLocation = Cx.CreateSourceLocation(methodDebugInformation.Location);
yield return sourceLocation;
yield return Tuples.cil_method_location(this, sourceLocation);
}
@@ -298,7 +298,7 @@ namespace Semmle.Extraction.CIL.Entities
yield return Tuples.cil_newslot(this);
// Populate attributes
Attribute.Populate(cx, this, md.GetCustomAttributes());
Attribute.Populate(Cx, this, md.GetCustomAttributes());
}
}
@@ -317,7 +317,7 @@ namespace Semmle.Extraction.CIL.Entities
nextSequencePoint = methodDebugInformation.SequencePoints.GetEnumerator();
if (nextSequencePoint.MoveNext())
{
instructionLocation = cx.CreateSourceLocation(nextSequencePoint.Current.Location);
instructionLocation = Cx.CreateSourceLocation(nextSequencePoint.Current.Location);
yield return instructionLocation;
}
else
@@ -329,12 +329,12 @@ namespace Semmle.Extraction.CIL.Entities
var child = 0;
for (var offset = 0; offset < ilbytes.Length;)
{
var instruction = new Instruction(cx, this, ilbytes, offset, child++);
var instruction = new Instruction(Cx, this, ilbytes, offset, child++);
yield return instruction;
if (nextSequencePoint != null && offset >= nextSequencePoint.Current.Offset)
{
instructionLocation = cx.CreateSourceLocation(nextSequencePoint.Current.Location);
instructionLocation = Cx.CreateSourceLocation(nextSequencePoint.Current.Location);
yield return instructionLocation;
if (!nextSequencePoint.MoveNext())
nextSequencePoint = null;
@@ -364,7 +364,7 @@ namespace Semmle.Extraction.CIL.Entities
{
if (md.ImplAttributes == MethodImplAttributes.IL && md.RelativeVirtualAddress != 0)
{
var body = cx.peReader.GetMethodBody(md.RelativeVirtualAddress);
var body = Cx.PeReader.GetMethodBody(md.RelativeVirtualAddress);
var ilbytes = body.GetILBytes();
@@ -374,7 +374,7 @@ namespace Semmle.Extraction.CIL.Entities
Instruction decoded;
try
{
decoded = new Instruction(cx, this, ilbytes, offset, child++);
decoded = new Instruction(Cx, this, ilbytes, offset, child++);
offset += decoded.Width;
}
catch // lgtm[cs/catch-of-all-exceptions]
@@ -403,11 +403,11 @@ namespace Semmle.Extraction.CIL.Entities
{
this.handle = handle;
this.gc = gc;
mr = cx.mdReader.GetMemberReference(handle);
mr = Cx.MdReader.GetMemberReference(handle);
signature = mr.DecodeMethodSignature(new SignatureDecoder(), gc);
parent = (GenericContext)cx.CreateGeneric(gc, mr.Parent);
parent = (GenericContext)Cx.CreateGeneric(gc, mr.Parent);
var declType = parent is Method parentMethod
? parentMethod.DeclaringType
@@ -417,7 +417,7 @@ namespace Semmle.Extraction.CIL.Entities
throw new InternalError("Parent context of method is not a type");
declaringType = declType;
nameLabel = cx.GetString(mr.Name);
nameLabel = Cx.GetString(mr.Name);
var typeSourceDeclaration = declaringType.SourceDeclaration;
sourceDeclaration = typeSourceDeclaration == declaringType ? (Method)this : typeSourceDeclaration.LookupMethod(mr.Name, mr.Signature);
@@ -443,7 +443,7 @@ namespace Semmle.Extraction.CIL.Entities
public override Type DeclaringType => declaringType;
public override string Name => cx.ShortName(mr.Name);
public override string Name => Cx.ShortName(mr.Name);
public override IEnumerable<Type> TypeParameters => parent.TypeParameters.Concat(gc.TypeParameters);
@@ -453,12 +453,12 @@ namespace Semmle.Extraction.CIL.Entities
{
genericParams = new MethodTypeParameter[signature.GenericParameterCount];
for (var p = 0; p < genericParams.Length; ++p)
genericParams[p] = cx.Populate(new MethodTypeParameter(this, this, p));
genericParams[p] = Cx.Populate(new MethodTypeParameter(this, this, p));
foreach (var p in genericParams)
yield return p;
var typeSignature = mr.DecodeMethodSignature(cx.TypeSignatureDecoder, this);
var typeSignature = mr.DecodeMethodSignature(Cx.TypeSignatureDecoder, this);
Parameters = MakeParameters(typeSignature.ParameterTypes).ToArray();
foreach (var p in Parameters) yield return p;
@@ -486,9 +486,9 @@ namespace Semmle.Extraction.CIL.Entities
public MethodSpecificationMethod(GenericContext gc, MethodSpecificationHandle handle) : base(gc)
{
this.handle = handle;
ms = cx.mdReader.GetMethodSpecification(handle);
typeParams = ms.DecodeSignature(cx.TypeSignatureDecoder, gc);
unboundMethod = (Method)cx.CreateGeneric(gc, ms.Method);
ms = Cx.MdReader.GetMethodSpecification(handle);
typeParams = ms.DecodeSignature(Cx.TypeSignatureDecoder, gc);
unboundMethod = (Method)Cx.CreateGeneric(gc, ms.Method);
}
public override void WriteId(TextWriter trapFile)
@@ -531,12 +531,12 @@ namespace Semmle.Extraction.CIL.Entities
switch (ms.Method.Kind)
{
case HandleKind.MemberReference:
var mr = cx.mdReader.GetMemberReference((MemberReferenceHandle)ms.Method);
constructedTypeSignature = mr.DecodeMethodSignature(cx.TypeSignatureDecoder, this);
var mr = Cx.MdReader.GetMemberReference((MemberReferenceHandle)ms.Method);
constructedTypeSignature = mr.DecodeMethodSignature(Cx.TypeSignatureDecoder, this);
break;
case HandleKind.MethodDefinition:
var md = cx.mdReader.GetMethodDefinition((MethodDefinitionHandle)ms.Method);
constructedTypeSignature = md.DecodeSignature(cx.TypeSignatureDecoder, this);
var md = Cx.MdReader.GetMethodDefinition((MethodDefinitionHandle)ms.Method);
constructedTypeSignature = md.DecodeSignature(Cx.TypeSignatureDecoder, this);
break;
default:
throw new InternalError($"Unexpected constructed method handle kind {ms.Method.Kind}");

View File

@@ -23,11 +23,11 @@ namespace Semmle.Extraction.CIL.Entities
public override string IdSuffix => ";cil-property";
private readonly GenericContext gc;
public Property(GenericContext gc, Type type, PropertyDefinitionHandle handle) : base(gc.cx)
public Property(GenericContext gc, Type type, PropertyDefinitionHandle handle) : base(gc.Cx)
{
this.gc = gc;
this.handle = handle;
pd = cx.mdReader.GetPropertyDefinition(handle);
pd = Cx.MdReader.GetPropertyDefinition(handle);
this.type = type;
}
@@ -35,7 +35,7 @@ namespace Semmle.Extraction.CIL.Entities
{
trapFile.WriteSubId(type);
trapFile.Write('.');
trapFile.Write(cx.GetString(pd.Name));
trapFile.Write(Cx.GetString(pd.Name));
trapFile.Write("(");
var index = 0;
var signature = pd.DecodeSignature(new SignatureDecoder(), gc);
@@ -58,27 +58,27 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
yield return Tuples.metadata_handle(this, cx.assembly, MetadataTokens.GetToken(handle));
var sig = pd.DecodeSignature(cx.TypeSignatureDecoder, type);
yield return Tuples.metadata_handle(this, Cx.Assembly, MetadataTokens.GetToken(handle));
var sig = pd.DecodeSignature(Cx.TypeSignatureDecoder, type);
yield return Tuples.cil_property(this, type, cx.ShortName(pd.Name), sig.ReturnType);
yield return Tuples.cil_property(this, type, Cx.ShortName(pd.Name), sig.ReturnType);
var accessors = pd.GetAccessors();
if (!accessors.Getter.IsNil)
{
var getter = (Method)cx.CreateGeneric(type, accessors.Getter);
var getter = (Method)Cx.CreateGeneric(type, accessors.Getter);
yield return getter;
yield return Tuples.cil_getter(this, getter);
}
if (!accessors.Setter.IsNil)
{
var setter = (Method)cx.CreateGeneric(type, accessors.Setter);
var setter = (Method)Cx.CreateGeneric(type, accessors.Setter);
yield return setter;
yield return Tuples.cil_setter(this, setter);
}
foreach (var c in Attribute.Populate(cx, this, pd.GetCustomAttributes()))
foreach (var c in Attribute.Populate(Cx, this, pd.GetCustomAttributes()))
yield return c;
}
}

View File

@@ -237,7 +237,7 @@ namespace Semmle.Extraction.CIL.Entities
{
if (TryGetPrimitiveTypeCode(out var code))
{
t = cx.Create(code);
t = Cx.Create(code);
return true;
}
@@ -247,7 +247,7 @@ namespace Semmle.Extraction.CIL.Entities
private bool TryGetPrimitiveTypeCode(out PrimitiveTypeCode code)
{
if (ContainingType == null && Namespace?.Name == cx.SystemNamespace.Name)
if (ContainingType == null && Namespace?.Name == Cx.SystemNamespace.Name)
{
switch (Name)
{
@@ -315,7 +315,7 @@ namespace Semmle.Extraction.CIL.Entities
protected bool IsPrimitiveType => TryGetPrimitiveTypeCode(out _);
public static Type DecodeType(GenericContext gc, TypeSpecificationHandle handle) =>
gc.cx.mdReader.GetTypeSpecification(handle).DecodeSignature(gc.cx.TypeSignatureDecoder, gc);
gc.Cx.MdReader.GetTypeSpecification(handle).DecodeSignature(gc.Cx.TypeSignatureDecoder, gc);
}
/// <summary>
@@ -328,7 +328,7 @@ namespace Semmle.Extraction.CIL.Entities
public TypeDefinitionType(Context cx, TypeDefinitionHandle handle) : base(cx)
{
td = cx.mdReader.GetTypeDefinition(handle);
td = cx.MdReader.GetTypeDefinition(handle);
this.handle = handle;
declType =
@@ -354,7 +354,7 @@ namespace Semmle.Extraction.CIL.Entities
return;
}
var name = cx.GetString(td.Name);
var name = Cx.GetString(td.Name);
if (ContainingType != null)
{
@@ -380,13 +380,13 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
var name = cx.GetString(td.Name);
var name = Cx.GetString(td.Name);
var tick = name.IndexOf('`');
return tick == -1 ? name : name.Substring(0, tick);
}
}
public override Namespace Namespace => cx.Create(td.NamespaceDefinition);
public override Namespace Namespace => Cx.Create(td.NamespaceDefinition);
private readonly Type? declType;
@@ -398,7 +398,7 @@ namespace Semmle.Extraction.CIL.Entities
{
var containingType = td.GetDeclaringType();
var parentTypeParameters = containingType.IsNil ? 0 :
cx.mdReader.GetTypeDefinition(containingType).GetGenericParameters().Count;
Cx.MdReader.GetTypeDefinition(containingType).GetGenericParameters().Count;
return td.GetGenericParameters().Count - parentTypeParameters;
}
@@ -408,14 +408,14 @@ namespace Semmle.Extraction.CIL.Entities
public override Type Construct(IEnumerable<Type> typeArguments)
{
return cx.Populate(new ConstructedType(cx, this, typeArguments));
return Cx.Populate(new ConstructedType(Cx, this, typeArguments));
}
public override void WriteAssemblyPrefix(TextWriter trapFile)
{
var ct = ContainingType;
if (ct is null)
cx.WriteAssemblyPrefix(trapFile);
Cx.WriteAssemblyPrefix(trapFile);
else if (IsPrimitiveType)
trapFile.Write("builtin:");
else
@@ -433,7 +433,7 @@ namespace Semmle.Extraction.CIL.Entities
// Two-phase population because type parameters can be mutually dependent
for (var i = 0; i < newTypeParams.Length; ++i)
newTypeParams[i] = cx.Populate(new TypeTypeParameter(this, this, i));
newTypeParams[i] = Cx.Populate(new TypeTypeParameter(this, this, i));
for (var i = 0; i < newTypeParams.Length; ++i)
newTypeParams[i].PopulateHandle(genericParams[i + toSkip]);
return newTypeParams;
@@ -462,7 +462,7 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
yield return Tuples.metadata_handle(this, cx.assembly, handle.GetHashCode());
yield return Tuples.metadata_handle(this, Cx.Assembly, handle.GetHashCode());
foreach (var c in base.Contents) yield return c;
@@ -471,7 +471,7 @@ namespace Semmle.Extraction.CIL.Entities
foreach (var f in td.GetFields())
{
// Populate field if needed
yield return cx.CreateGeneric(this, f);
yield return Cx.CreateGeneric(this, f);
}
foreach (var prop in td.GetProperties())
@@ -481,16 +481,16 @@ namespace Semmle.Extraction.CIL.Entities
foreach (var @event in td.GetEvents())
{
yield return new Event(cx, this, @event);
yield return new Event(Cx, this, @event);
}
foreach (var a in Attribute.Populate(cx, this, td.GetCustomAttributes()))
foreach (var a in Attribute.Populate(Cx, this, td.GetCustomAttributes()))
yield return a;
foreach (var impl in td.GetMethodImplementations().Select(i => cx.mdReader.GetMethodImplementation(i)))
foreach (var impl in td.GetMethodImplementations().Select(i => Cx.MdReader.GetMethodImplementation(i)))
{
var m = (Method)cx.CreateGeneric(this, impl.MethodBody);
var decl = (Method)cx.CreateGeneric(this, impl.MethodDeclaration);
var m = (Method)Cx.CreateGeneric(this, impl.MethodBody);
var decl = (Method)Cx.CreateGeneric(this, impl.MethodDeclaration);
yield return m;
yield return decl;
@@ -518,20 +518,20 @@ namespace Semmle.Extraction.CIL.Entities
if (!td.BaseType.IsNil)
{
var @base = (Type)cx.CreateGeneric(this, td.BaseType);
var @base = (Type)Cx.CreateGeneric(this, td.BaseType);
yield return @base;
yield return Tuples.cil_base_class(this, @base);
}
foreach (var @interface in td.GetInterfaceImplementations().Select(i => cx.mdReader.GetInterfaceImplementation(i)))
foreach (var @interface in td.GetInterfaceImplementations().Select(i => Cx.MdReader.GetInterfaceImplementation(i)))
{
var t = (Type)cx.CreateGeneric(this, @interface.Interface);
var t = (Type)Cx.CreateGeneric(this, @interface.Interface);
yield return t;
yield return Tuples.cil_base_interface(this, t);
}
// Only type definitions have locations.
yield return Tuples.cil_type_location(this, cx.assembly);
yield return Tuples.cil_type_location(this, Cx.Assembly);
}
}
@@ -539,11 +539,11 @@ namespace Semmle.Extraction.CIL.Entities
{
foreach (var h in td.GetMethods())
{
var md = cx.mdReader.GetMethodDefinition(h);
var md = Cx.MdReader.GetMethodDefinition(h);
if (md.Name == name && md.Signature == signature)
{
return (Method)cx.Create(h);
return (Method)Cx.Create(h);
}
}
@@ -564,7 +564,7 @@ namespace Semmle.Extraction.CIL.Entities
{
this.typeParams = new Lazy<TypeTypeParameter[]>(MakeTypeParameters);
this.handle = handle;
this.tr = cx.mdReader.GetTypeReference(handle);
this.tr = cx.MdReader.GetTypeReference(handle);
}
public override bool Equals(object? obj)
@@ -603,20 +603,20 @@ namespace Semmle.Extraction.CIL.Entities
{
get
{
var name = cx.GetString(tr.Name);
var name = Cx.GetString(tr.Name);
var tick = name.IndexOf('`');
return tick == -1 ? name : name.Substring(0, tick);
}
}
public override Namespace Namespace => cx.CreateNamespace(tr.Namespace);
public override Namespace Namespace => Cx.CreateNamespace(tr.Namespace);
public override int ThisTypeParameters
{
get
{
// Parse the name
var name = cx.GetString(tr.Name);
var name = Cx.GetString(tr.Name);
var tick = name.IndexOf('`');
return tick == -1 ? 0 : int.Parse(name.Substring(tick + 1));
}
@@ -636,7 +636,7 @@ namespace Semmle.Extraction.CIL.Entities
get
{
if (tr.ResolutionScope.Kind == HandleKind.TypeReference)
return (Type)cx.Create((TypeReferenceHandle)tr.ResolutionScope);
return (Type)Cx.Create((TypeReferenceHandle)tr.ResolutionScope);
return null;
}
}
@@ -651,14 +651,14 @@ namespace Semmle.Extraction.CIL.Entities
ContainingType!.WriteAssemblyPrefix(trapFile);
break;
case HandleKind.AssemblyReference:
var assemblyDef = cx.mdReader.GetAssemblyReference((AssemblyReferenceHandle)tr.ResolutionScope);
trapFile.Write(cx.GetString(assemblyDef.Name));
var assemblyDef = Cx.MdReader.GetAssemblyReference((AssemblyReferenceHandle)tr.ResolutionScope);
trapFile.Write(Cx.GetString(assemblyDef.Name));
trapFile.Write('_');
trapFile.Write(assemblyDef.Version.ToString());
trapFile.Write("::");
break;
default:
cx.WriteAssemblyPrefix(trapFile);
Cx.WriteAssemblyPrefix(trapFile);
break;
}
}
@@ -694,7 +694,7 @@ namespace Semmle.Extraction.CIL.Entities
}
trapFile.Write('.');
trapFile.Write(cx.GetString(tr.Name));
trapFile.Write(Cx.GetString(tr.Name));
}
public override Type Construct(IEnumerable<Type> typeArguments)
@@ -702,7 +702,7 @@ namespace Semmle.Extraction.CIL.Entities
if (TotalTypeParametersCheck != typeArguments.Count())
throw new InternalError("Mismatched type arguments");
return cx.Populate(new ConstructedType(cx, this, typeArguments));
return Cx.Populate(new ConstructedType(Cx, this, typeArguments));
}
}
@@ -869,7 +869,7 @@ namespace Semmle.Extraction.CIL.Entities
public override string Name => typeCode.Id();
public override Namespace Namespace => cx.SystemNamespace;
public override Namespace Namespace => Cx.SystemNamespace;
public override Type? ContainingType => null;
@@ -925,7 +925,7 @@ namespace Semmle.Extraction.CIL.Entities
public override string Name => elementType.Name + "[]";
public override Namespace Namespace => cx.SystemNamespace;
public override Namespace Namespace => Cx.SystemNamespace;
public override Type? ContainingType => null;
@@ -933,9 +933,9 @@ namespace Semmle.Extraction.CIL.Entities
public override CilTypeKind Kind => CilTypeKind.Array;
public override Type Construct(IEnumerable<Type> typeArguments) => cx.Populate(new ArrayType(cx, elementType.Construct(typeArguments)));
public override Type Construct(IEnumerable<Type> typeArguments) => Cx.Populate(new ArrayType(Cx, elementType.Construct(typeArguments)));
public override Type SourceDeclaration => cx.Populate(new ArrayType(cx, elementType.SourceDeclaration));
public override Type SourceDeclaration => Cx.Populate(new ArrayType(Cx, elementType.SourceDeclaration));
public override IEnumerable<IExtractionProduct> Contents
{
@@ -965,7 +965,7 @@ namespace Semmle.Extraction.CIL.Entities
{
protected readonly GenericContext gc;
protected TypeParameter(GenericContext gc) : base(gc.cx)
protected TypeParameter(GenericContext gc) : base(gc.Cx)
{
this.gc = gc;
}
@@ -986,7 +986,7 @@ namespace Semmle.Extraction.CIL.Entities
{
if (!parameterHandle.IsNil)
{
var tp = cx.mdReader.GetGenericParameter(parameterHandle);
var tp = Cx.MdReader.GetGenericParameter(parameterHandle);
if (tp.Attributes.HasFlag(GenericParameterAttributes.Contravariant))
yield return Tuples.cil_typeparam_contravariant(this);
@@ -999,9 +999,9 @@ namespace Semmle.Extraction.CIL.Entities
if (tp.Attributes.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint))
yield return Tuples.cil_typeparam_struct(this);
foreach (var constraint in tp.GetConstraints().Select(h => cx.mdReader.GetGenericParameterConstraint(h)))
foreach (var constraint in tp.GetConstraints().Select(h => Cx.MdReader.GetGenericParameterConstraint(h)))
{
var t = (Type)cx.CreateGeneric(this.gc, constraint.Type);
var t = (Type)Cx.CreateGeneric(this.gc, constraint.Type);
yield return t;
yield return Tuples.cil_typeparam_constraint(this, t);
}
@@ -1176,7 +1176,7 @@ namespace Semmle.Extraction.CIL.Entities
public override string Name => "!error";
public override Namespace Namespace => cx.GlobalNamespace;
public override Namespace Namespace => Cx.GlobalNamespace;
public override Type? ContainingType => null;
@@ -1454,7 +1454,7 @@ namespace Semmle.Extraction.CIL.Entities
public void WriteId(TextWriter trapFile, GenericContext gc)
{
var type = (Type)gc.cx.Create(handle);
var type = (Type)gc.Cx.Create(handle);
type.WriteId(trapFile);
}
}
@@ -1475,7 +1475,7 @@ namespace Semmle.Extraction.CIL.Entities
public void WriteId(TextWriter trapFile, GenericContext gc)
{
var type = (Type)gc.cx.Create(handle);
var type = (Type)gc.Cx.Create(handle);
type.WriteId(trapFile);
}
}

View File

@@ -63,12 +63,12 @@ namespace Semmle.Extraction.CIL
cx2.Extract(this);
}
public Context cx { get; }
public Context Cx { get; }
protected UnlabelledEntity(Context cx)
{
this.cx = cx;
cx.cx.AddFreshLabel(this);
this.Cx = cx;
cx.Cx.AddFreshLabel(this);
}
TrapStackBehaviour IEntity.TrapStackBehaviour => TrapStackBehaviour.NoLabel;
@@ -101,11 +101,11 @@ namespace Semmle.Extraction.CIL
cx2.Populate(this);
}
public Context cx { get; }
public Context Cx { get; }
protected LabelledEntity(Context cx)
{
this.cx = cx;
this.Cx = cx;
}
public override string ToString()
@@ -132,7 +132,7 @@ namespace Semmle.Extraction.CIL
public void Extract(Context cx)
{
cx.cx.Emit(tuple);
cx.Cx.Emit(tuple);
}
public override string ToString() => tuple.ToString();

View File

@@ -27,10 +27,10 @@ namespace Semmle.Extraction.CIL
}
else
{
e.Label = cx.GetNewLabel();
cx.DefineLabel(e, cx.TrapWriter.Writer, cx.Extractor);
e.Label = Cx.GetNewLabel();
Cx.DefineLabel(e, Cx.TrapWriter.Writer, Cx.Extractor);
ids.Add(e, e.Label);
cx.PopulateLater(() =>
Cx.PopulateLater(() =>
{
foreach (var c in e.Contents)
c.Extract(this);
@@ -42,7 +42,7 @@ namespace Semmle.Extraction.CIL
if (debugLabels.TryGetValue(id, out var previousEntity))
{
cx.Extractor.Message(new Message("Duplicate trap ID", id, null, severity: Util.Logging.Severity.Warning));
Cx.Extractor.Message(new Message("Duplicate trap ID", id, null, severity: Util.Logging.Severity.Warning));
}
else
{
@@ -74,9 +74,9 @@ namespace Semmle.Extraction.CIL
{
e = new PrimitiveType(this, code)
{
Label = cx.GetNewLabel()
Label = Cx.GetNewLabel()
};
cx.DefineLabel(e, cx.TrapWriter.Writer, cx.Extractor);
Cx.DefineLabel(e, Cx.TrapWriter.Writer, Cx.Extractor);
primitiveTypes[(int)code] = e;
}
@@ -138,7 +138,7 @@ namespace Semmle.Extraction.CIL
private IExtractedEntity Create(GenericContext gc, MemberReferenceHandle handle)
{
var mr = mdReader.GetMemberReference(handle);
var mr = MdReader.GetMemberReference(handle);
switch (mr.GetKind())
{
case MemberReferenceKind.Method:
@@ -155,7 +155,7 @@ namespace Semmle.Extraction.CIL
/// </summary>
/// <param name="h">The string handle.</param>
/// <returns>The string.</returns>
public string GetString(StringHandle h) => mdReader.GetString(h);
public string GetString(StringHandle h) => MdReader.GetString(h);
#region Namespaces
@@ -195,7 +195,7 @@ namespace Semmle.Extraction.CIL
{
if (handle.IsNil)
return GlobalNamespace;
var nd = mdReader.GetNamespaceDefinition(handle);
var nd = MdReader.GetNamespaceDefinition(handle);
return Populate(new Namespace(this, GetString(nd.Name), Create(nd.Parent)));
}
#endregion
@@ -237,7 +237,7 @@ namespace Semmle.Extraction.CIL
/// <returns>The short name.</returns>
public string ShortName(StringHandle handle)
{
var str = mdReader.GetString(handle);
var str = MdReader.GetString(handle);
if (str.EndsWith(".ctor"))
return ".ctor";
if (str.EndsWith(".cctor"))