From e266af47f447909fc0cf1d8a7a406af964f180da Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Fri, 24 Jul 2009 16:05:07 +0000 Subject: [PATCH] Change scanning. includes static constructors now. scans for static fields now, and includes more types now (method return types, and method parameter types). also, removed the mTypes list. wasn't used for anything --- source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs | 34 +++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs index dc9cd1144..608762b75 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs @@ -20,7 +20,7 @@ namespace Cosmos.IL2CPU { private HashSet mMethodsSet = new HashSet(); private List mMethods = new List(); private HashSet mTypesSet = new HashSet(); - private List mTypes = new List(); + private HashSet mFieldsSet = new HashSet(); protected ILReader mReader; public ILScanner(Type aAssemblerBaseOp) { @@ -70,14 +70,36 @@ namespace Cosmos.IL2CPU { mMethodsSet.Add(aMethod); mMethods.Add(aMethod); QueueType(aMethod.DeclaringType); + var xMethodInfo = aMethod as MethodInfo; + if (xMethodInfo != null) + { + QueueType(xMethodInfo.ReturnType); + } + foreach (var xParam in aMethod.GetParameters()) + { + QueueType(xParam.ParameterType); + } } } + public void QueueStaticField(FieldInfo aFieldInfo) + { + if (!mFieldsSet.Contains(aFieldInfo)) + { + if (!aFieldInfo.IsStatic) + { + throw new Exception("Cannot queue instance fields!"); + } + mFieldsSet.Add(aFieldInfo); + QueueType(aFieldInfo.DeclaringType); + QueueType(aFieldInfo.FieldType); + } + } + public void QueueType(Type aType) { if (aType != null) { if (!mTypesSet.Contains(aType)) { mTypesSet.Add(aType); - mTypes.Add(aType); QueueType(aType.BaseType); foreach (var xMethod in aType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { if (xMethod.DeclaringType == aType) { @@ -86,6 +108,14 @@ namespace Cosmos.IL2CPU { } } } + // queue static constructor + foreach (var xCctor in aType.GetConstructors(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) + { + if (xCctor.DeclaringType == aType) + { + QueueMethod(xCctor); + } + } } } }