-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #200, moved FluentIL to main repo
- Loading branch information
Showing
28 changed files
with
1,908 additions
and
319 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/AspectInjector.Rules/AspectInjector.Rules.csproj
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\external\FluentIL\src\FluentIL.Common\FluentIL.Common.csproj" /> | ||
<ProjectReference Include="..\FluentIL.Common\FluentIL.Common.csproj" /> | ||
<ProjectReference Include="..\AspectInjector.Broker\AspectInjector.Broker.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace FluentIL.Common | ||
{ | ||
public enum RuleSeverity | ||
{ | ||
Hidden, | ||
Info, | ||
Warning, | ||
Error | ||
} | ||
|
||
public class Rule | ||
{ | ||
|
||
public Rule(string id, string title, string message, RuleSeverity severity, string description, string helpLinkUri) | ||
{ | ||
Id = id; | ||
Title = title; | ||
Message = message; | ||
Severity = severity; | ||
Description = description; | ||
HelpLinkUri = helpLinkUri; | ||
} | ||
|
||
public string Id { get; } | ||
public string Title { get; } | ||
public string Message { get; } | ||
public RuleSeverity Severity { get; } | ||
public string Description { get; } | ||
public string HelpLinkUri { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using FluentIL.Extensions; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
using System; | ||
|
||
namespace FluentIL | ||
{ | ||
public static class Arrays | ||
{ | ||
public static Cut CreateArray(this in Cut cut, TypeReference elementType, params PointCut[] elements) | ||
{ | ||
var pc = cut | ||
.Write(OpCodes.Ldc_I4, elements.Length) | ||
.Write(OpCodes.Newarr, elementType); | ||
|
||
for (var i = 0; i < elements.Length; i++) | ||
{ | ||
pc = pc.Write(OpCodes.Dup); | ||
pc = SetByIndex(pc, elementType, i, elements[i]); | ||
} | ||
|
||
return pc; | ||
} | ||
|
||
public static Cut GetByIndex(this in Cut pc, TypeReference elementType, int index) | ||
{ | ||
return pc | ||
.Write(OpCodes.Ldc_I4, index) | ||
.Write(GetLoadOpcode(elementType)); | ||
} | ||
|
||
public static Cut SetByIndex(this in Cut pc, TypeReference elementType, int index, PointCut value) | ||
{ | ||
return pc | ||
.Write(OpCodes.Ldc_I4, index) | ||
.Here(value) | ||
.Write(GetStoreOpcode(elementType)); | ||
} | ||
|
||
private static OpCode GetLoadOpcode(TypeReference elementType) | ||
{ | ||
switch (elementType.MetadataType) | ||
{ | ||
case MetadataType.Class: return OpCodes.Ldelem_Ref; | ||
case MetadataType.Object: return OpCodes.Ldelem_Ref; | ||
case MetadataType.Double: return OpCodes.Ldelem_R8; | ||
case MetadataType.Single: return OpCodes.Ldelem_R4; | ||
case MetadataType.Int64: return OpCodes.Ldelem_I8; | ||
case MetadataType.UInt64: return OpCodes.Ldelem_I8; | ||
case MetadataType.Int32: return OpCodes.Ldelem_I4; | ||
case MetadataType.UInt32: return OpCodes.Ldelem_U4; | ||
case MetadataType.Int16: return OpCodes.Ldelem_I2; | ||
case MetadataType.UInt16: return OpCodes.Ldelem_U2; | ||
case MetadataType.Byte: return OpCodes.Ldelem_U1; | ||
case MetadataType.SByte: return OpCodes.Ldelem_I1; | ||
case MetadataType.Boolean: return OpCodes.Ldelem_I1; | ||
case MetadataType.String: return OpCodes.Ldelem_Ref; | ||
} | ||
|
||
throw new NotSupportedException($"No instruction for {elementType.MetadataType}"); | ||
} | ||
|
||
|
||
private static OpCode GetStoreOpcode(TypeReference elementType) | ||
{ | ||
if(elementType.IsValueType && !elementType.IsPrimitive) | ||
{ | ||
var r = elementType.Resolve(); | ||
if (r.IsEnum) | ||
elementType = r.GetEnumType(); | ||
} | ||
|
||
switch (elementType.MetadataType) | ||
{ | ||
case MetadataType.Class: return OpCodes.Stelem_Ref; | ||
case MetadataType.Object: return OpCodes.Stelem_Ref; | ||
case MetadataType.Double: return OpCodes.Stelem_R8; | ||
case MetadataType.Single: return OpCodes.Stelem_R4; | ||
case MetadataType.Int64: return OpCodes.Stelem_I8; | ||
case MetadataType.UInt64: return OpCodes.Stelem_I8; | ||
case MetadataType.Int32: return OpCodes.Stelem_I4; | ||
case MetadataType.UInt32: return OpCodes.Stelem_I4; | ||
case MetadataType.Int16: return OpCodes.Stelem_I2; | ||
case MetadataType.UInt16: return OpCodes.Stelem_I2; | ||
case MetadataType.Byte: return OpCodes.Stelem_I1; | ||
case MetadataType.SByte: return OpCodes.Stelem_I1; | ||
case MetadataType.Boolean: return OpCodes.Stelem_I1; | ||
case MetadataType.String: return OpCodes.Stelem_Ref; | ||
} | ||
|
||
throw new NotSupportedException($"No instruction for {elementType.MetadataType}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using FluentIL.Extensions; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
using System; | ||
|
||
namespace FluentIL | ||
{ | ||
public static class Statements | ||
{ | ||
public static Cut Return(this in Cut cut) | ||
{ | ||
return cut.Write(OpCodes.Ret); | ||
} | ||
|
||
public static Cut Call(this in Cut cut, MethodReference method, PointCut args = null) | ||
{ | ||
var cur_cut = cut; | ||
|
||
if (!method.IsCallCompatible()) | ||
throw new ArgumentException($"Uninitialized generic call reference: {method}"); | ||
|
||
if (args != null) cur_cut = cur_cut.Here(args); | ||
|
||
var methodDef = method.Resolve(); | ||
|
||
var code = OpCodes.Call; | ||
if (methodDef.IsConstructor) code = OpCodes.Newobj; | ||
else if (methodDef.IsVirtual) code = OpCodes.Callvirt; | ||
|
||
return cur_cut.Write(code, method); | ||
} | ||
|
||
public static Cut IfEqual(this in Cut pc, PointCut left, PointCut right, PointCut pos = null, PointCut neg = null) | ||
{ | ||
if (pos != null && neg != null) | ||
return Compare(pc, left, right, OpCodes.Ceq, pos, neg); | ||
|
||
if (pos != null) | ||
return Compare(pc, left, right, OpCodes.Ceq, OpCodes.Brfalse, pos); | ||
|
||
if (neg != null) | ||
return Compare(pc, left, right, OpCodes.Ceq, OpCodes.Brtrue, neg); | ||
|
||
return pc; | ||
} | ||
|
||
private static Cut Compare(in Cut cut, PointCut left, PointCut right, OpCode cmp, PointCut pos, PointCut neg) | ||
{ | ||
var pc = cut | ||
.Here(left) | ||
.Here(right) | ||
.Write(cmp); | ||
|
||
var pe = pc.Here(pos); | ||
var ne = pe.Here(neg); | ||
|
||
var exit = ne.Write(OpCodes.Nop); | ||
|
||
pc.Write(OpCodes.Brfalse, pe.Next()); | ||
pe.Write(OpCodes.Br, exit); | ||
|
||
return exit; | ||
} | ||
|
||
private static Cut Compare(in Cut cut, PointCut left, PointCut right, OpCode cmp, OpCode brexit, PointCut action) | ||
{ | ||
var pc = cut | ||
.Here(left) | ||
.Here(right) | ||
.Write(cmp); | ||
|
||
var exit = pc.Write(OpCodes.Nop); | ||
|
||
pc.Write(brexit, exit).Here(action); | ||
|
||
return exit; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using FluentIL.Extensions; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
using System; | ||
|
||
namespace FluentIL | ||
{ | ||
public static class TypeMembers | ||
{ | ||
public static Cut ThisOrStatic(this in Cut cut) => | ||
cut.Method.HasThis ? cut.This() : cut; | ||
|
||
public static Cut ThisOrNull(this in Cut cut) => | ||
cut.Method.HasThis ? cut.This() : cut.Null(); | ||
|
||
public static Cut This(this in Cut cut) | ||
{ | ||
if (cut.Method.HasThis) return cut.Write(OpCodes.Ldarg_0); | ||
else throw new InvalidOperationException("Attempt to load 'this' on static method."); | ||
} | ||
|
||
public static Cut Load(this in Cut cut, VariableDefinition variable) => cut | ||
.Write(OpCodes.Ldloc, variable); | ||
|
||
public static Cut Load(this in Cut cut, ParameterReference par) => cut | ||
.Write(OpCodes.Ldarg, par.Resolve()); | ||
|
||
public static Cut Load(this in Cut cut, FieldReference field) | ||
{ | ||
if(!field.IsCallCompatible()) | ||
throw new ArgumentException($"Uninitialized generic call reference: {field}"); | ||
|
||
var fieldDef = field.Resolve(); | ||
|
||
return cut.Write(fieldDef.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, field); | ||
} | ||
|
||
public static Cut LoadRef(this in Cut cut, VariableDefinition variable) => cut | ||
.Write(OpCodes.Ldloca, variable); | ||
|
||
public static Cut LoadRef(this in Cut cut, ParameterReference par) => cut | ||
.Write(OpCodes.Ldarga, par.Resolve()); | ||
|
||
public static Cut LoadRef(this in Cut cut, FieldReference field) | ||
{ | ||
if (!field.IsCallCompatible()) | ||
throw new ArgumentException($"Uninitialized generic call reference: {field}"); | ||
|
||
var fieldDef = field.Resolve(); | ||
|
||
return cut.Write(fieldDef.IsStatic ? OpCodes.Ldsflda : OpCodes.Ldflda, field); | ||
} | ||
|
||
public static Cut Store(this in Cut cut, FieldReference field, PointCut value = null) | ||
{ | ||
if (!field.IsCallCompatible()) | ||
throw new ArgumentException($"Uninitialized generic call reference: {field}"); | ||
|
||
var fieldDef = field.Resolve(); | ||
|
||
return cut | ||
.Here(value) | ||
.Write(fieldDef.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, field); | ||
} | ||
|
||
public static Cut Store(this in Cut cut, VariableDefinition variable, PointCut value = null) => cut | ||
.Here(value) | ||
.Write(OpCodes.Stloc, variable); | ||
|
||
public static Cut Store(this in Cut cut, ParameterReference par, PointCut value = null) | ||
{ | ||
if (par.ParameterType.IsByReference) | ||
{ | ||
return cut | ||
.Load(par) | ||
.Here(value); | ||
} | ||
else | ||
{ | ||
return cut | ||
.Here(value) | ||
.Write(OpCodes.Starg, par.Resolve()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.