Skip to content

Commit

Permalink
Merge branch 'dataflow/expression' of https://github.com/mateoatr/linker
Browse files Browse the repository at this point in the history
 into dataflow/expression
  • Loading branch information
Mateo Torres Ruiz committed Apr 2, 2020
2 parents 7b6b245 + 5536901 commit f257ef9
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3919,6 +3919,58 @@ void MarkFieldsFromReflectionCall (ref ReflectionPatternContext reflectionContex
if (!foundMatch)
reflectionContext.RecordUnrecognizedPattern ($"Reflection call '{reflectionContext.MethodCalled.FullName}' inside '{reflectionContext.MethodCalling.FullName}' could not resolve field `{name}` on type `{declaringType.FullName}`.");
}

void MarkPropertiesFromReflectionCall (ref ReflectionPatternContext reflectionContext, TypeDefinition declaringType, string name, bool staticOnly = false)
{
bool foundMatch = false;
foreach (var property in declaringType.Properties) {
if (property.Name != name)
continue;

bool markedAny = false;

// It is not easy to reliably detect in the IL code whether the getter or setter (or both) are used.
// Be conservative and mark everything for the property.
var getter = property.GetMethod;
if (getter != null && (!staticOnly || staticOnly && getter.IsStatic)) {
reflectionContext.RecordRecognizedPattern (getter, () => _markStep.MarkIndirectlyCalledMethod (getter));
markedAny = true;
}

var setter = property.SetMethod;
if (setter != null && (!staticOnly || staticOnly && setter.IsStatic)) {
reflectionContext.RecordRecognizedPattern (setter, () => _markStep.MarkIndirectlyCalledMethod (setter));
markedAny = true;
}

if (markedAny) {
foundMatch = true;
reflectionContext.RecordRecognizedPattern (property, () => _markStep.MarkProperty (property));
}
}

if (!foundMatch)
reflectionContext.RecordUnrecognizedPattern ($"Reflection call '{reflectionContext.MethodCalled.FullName}' inside '{reflectionContext.MethodCalling.FullName}' could not resolve property `{name}` on type `{declaringType.FullName}`.");
}

void MarkFieldsFromReflectionCall (ref ReflectionPatternContext reflectionContext, TypeDefinition declaringType, string name, bool staticOnly = false)
{
bool foundMatch = false;
foreach (var field in declaringType.Fields) {
if (field.Name != name)
continue;

if (staticOnly && !field.IsStatic)
continue;

foundMatch = true;
reflectionContext.RecordRecognizedPattern (field, () => _markStep.MarkField (field));
break;
}

if (!foundMatch)
reflectionContext.RecordUnrecognizedPattern ($"Reflection call '{reflectionContext.MethodCalled.FullName}' inside '{reflectionContext.MethodCalling.FullName}' could not resolve field `{name}` on type `{declaringType.FullName}`.");
}
}
}

Expand Down

0 comments on commit f257ef9

Please sign in to comment.