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

Correctly model in/ref/out keywords. #24

Open
wants to merge 1 commit 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
9 changes: 5 additions & 4 deletions CCIProvider/TypeExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ private void ExtractParameters(IList<MethodParameter> dest, IEnumerable<Cci.IPar

private MethodParameterKind GetMethodParameterKind(Cci.IParameterTypeInformation parameterref)
{
var result = MethodParameterKind.In;
var result = MethodParameterKind.Normal;

if (parameterref.IsByReference) result = MethodParameterKind.Ref;

Expand All @@ -981,10 +981,11 @@ private MethodParameterKind GetMethodParameterKind(Cci.IParameterTypeInformation

private MethodParameterKind GetMethodParameterKind(Cci.IParameterDefinition parameterdef)
{
var result = MethodParameterKind.In;
var result = MethodParameterKind.Normal;

if (parameterdef.IsOut) result = MethodParameterKind.Out;
if (parameterdef.IsByReference) result = MethodParameterKind.Ref;
if (parameterdef.IsIn) result = MethodParameterKind.In;
else if (parameterdef.IsOut) result = MethodParameterKind.Out;
else if (parameterdef.IsByReference) result = MethodParameterKind.Ref;

return result;
}
Expand Down
7 changes: 6 additions & 1 deletion MetadataProvider/AssemblyExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,18 @@ private void ExtractParameter(SRM.MethodSignature<IType> signature, SRM.Paramete

private static MethodParameterKind GetParameterKind(SR.ParameterAttributes attributes, IType type)
{
var result = MethodParameterKind.In;
var result = MethodParameterKind.Normal;
var isOut = attributes.HasFlag(SR.ParameterAttributes.Out);
var isIn = attributes.HasFlag(SR.ParameterAttributes.In);

if (isOut)
{
result = MethodParameterKind.Out;
}
else if (isIn)
{
result = MethodParameterKind.In;
}
else if (type.IsPointer())
{
result = MethodParameterKind.Ref;
Expand Down
6 changes: 4 additions & 2 deletions Model/ThreeAddressCode/Instructions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ public override ISet<IVariable> ModifiedVariables
// We don't care here if the objects referenced by arguments could be modified.
foreach (var parameterInfo in this.Method.Parameters)
{
if (parameterInfo.Kind == MethodParameterKind.Ref)
if (parameterInfo.Kind == MethodParameterKind.Ref ||
parameterInfo.Kind == MethodParameterKind.Out)
{
var argument = this.Arguments[argumentIndex++];
result.Add(argument);
Expand Down Expand Up @@ -1017,7 +1018,8 @@ public override ISet<IVariable> ModifiedVariables
// We don't care here if the objects referenced by arguments could be modified.
foreach (var parameterInfo in this.Function.Parameters)
{
if (parameterInfo.Kind == MethodParameterKind.Ref)
if (parameterInfo.Kind == MethodParameterKind.Ref ||
parameterInfo.Kind == MethodParameterKind.Out)
{
var argument = this.Arguments[argumentIndex++];
result.Add(argument);
Expand Down
17 changes: 10 additions & 7 deletions Model/Types/TypeDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ public override string ToString()

public enum MethodParameterKind
{
In,
Out,
Ref
Normal, // none
In, // in keyword
Out, // out keyword
Ref // ref keyword
}

public interface IMethodParameterReference
Expand All @@ -183,7 +184,7 @@ public MethodParameterReference(ushort index, IType type)
{
this.Index = index;
this.Type = type;
this.Kind = MethodParameterKind.In;
this.Kind = MethodParameterKind.Normal;
}

public override string ToString()
Expand All @@ -192,7 +193,8 @@ public override string ToString()

switch (this.Kind)
{
case MethodParameterKind.In: kind = string.Empty; break;
case MethodParameterKind.Normal: kind = String.Empty; break;
case MethodParameterKind.In: kind = "in "; break;
case MethodParameterKind.Out: kind = "out "; break;
case MethodParameterKind.Ref: kind = "ref "; break;

Expand Down Expand Up @@ -233,7 +235,7 @@ public MethodParameter(ushort index, string name, IType type)
this.Index = index;
this.Name = name;
this.Type = type;
this.Kind = MethodParameterKind.In;
this.Kind = MethodParameterKind.Normal;
this.Attributes = new HashSet<CustomAttribute>();
}

Expand Down Expand Up @@ -265,7 +267,8 @@ public override string ToString()

switch (this.Kind)
{
case MethodParameterKind.In: kind = string.Empty; break;
case MethodParameterKind.Normal: kind = string.Empty; break;
case MethodParameterKind.In: kind = "in "; break;
case MethodParameterKind.Out: kind = "out "; break;
case MethodParameterKind.Ref: kind = "ref "; break;

Expand Down