Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assembly kind #35

Open
wants to merge 4 commits into
base: metadata-provider
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CCIProvider/AssemblyTraverser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ public AssemblyTraverser(Host host, Cci.IMetadataHost cciHost, Cci.PdbReader pdb
this.TraverseIntoMethodBodies = false;
this.typeExtractor = new TypeExtractor(host);
}

private AssemblyKind AssemblyKindFrom(Cci.IAssembly cciAssembly)
{
switch (cciAssembly.Kind)
{
case Cci.ModuleKind.ConsoleApplication:
case Cci.ModuleKind.WindowsApplication: return AssemblyKind.Exe;
case Cci.ModuleKind.DynamicallyLinkedLibrary: return AssemblyKind.Dll;
default: throw new Exception($"Assembly kind {cciAssembly.Kind} not supported");
}
}

public override void TraverseChildren(Cci.IAssembly cciAssembly)
{
var ourAssembly = new Assembly(cciAssembly.Name.Value);
var ourAssembly = new Assembly(cciAssembly.Name.Value, AssemblyKindFrom(cciAssembly));

foreach (var cciReference in cciAssembly.AssemblyReferences)
{
Expand Down
10 changes: 9 additions & 1 deletion MetadataProvider/AssemblyExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,19 @@ public FieldDefinition GetDefinedField(SRM.FieldDefinitionHandle handle)
return result;
}


private AssemblyKind AssemblyKindFrom(SRPE.PEHeaders headers)
{
if (headers.IsDll) return AssemblyKind.Dll;
if (headers.IsExe || headers.IsConsoleApplication) return AssemblyKind.Exe;
else throw new Exception("Assembly kind not supported");
}

public Assembly Extract()
{
var assemblydef = metadata.GetAssemblyDefinition();
var name = metadata.GetString(assemblydef.Name);
assembly = new Assembly(name);
assembly = new Assembly(name, AssemblyKindFrom(reader.PEHeaders));

foreach (var handle in metadata.AssemblyReferences)
{
Expand Down
15 changes: 12 additions & 3 deletions Model/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,24 @@ public override bool Equals(object obj)
}
}

public enum AssemblyKind
{
Exe,
Dll
}

public class Assembly : IAssemblyReference
{
public string Name { get; private set; }
public AssemblyKind Kind { get; private set; }
public IList<IAssemblyReference> References { get; private set; }
public Namespace RootNamespace { get; set; }

public Assembly(string name)
public Assembly(string name, AssemblyKind kind)
{
this.Name = name;
this.References = new List<IAssemblyReference>();
this.Kind = kind;
}

public bool MatchReference(IAssemblyReference reference)
Expand All @@ -69,15 +77,16 @@ public override string ToString()

public override int GetHashCode()
{
return this.Name.GetHashCode();
return this.Name.GetHashCode() ^ this.Kind.GetHashCode();
}

public override bool Equals(object obj)
{
var other = obj as Assembly;

var result = other != null &&
this.Name == other.Name;
this.Name == other.Name &&
this.Kind == other.Kind;

return result;
}
Expand Down