mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 05:18:38 +00:00
string.IndexOf(char) works now
This commit is contained in:
parent
8e5e6a027a
commit
a3734ff054
2 changed files with 39 additions and 4 deletions
|
|
@ -107,6 +107,27 @@ namespace Indy.IL2CPU.IL {
|
|||
return sb.ToString().TrimEnd(',') + ")";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full name of a method, without the defining type included
|
||||
/// </summary>
|
||||
/// <param name="aSelf"></param>
|
||||
/// <returns></returns>
|
||||
private static string GetStrippedMethodDefinitionFullName(MethodReference aSelf) {
|
||||
StringBuilder sb = new StringBuilder(aSelf.ReturnType.ReturnType.FullName + " " + aSelf.Name);
|
||||
sb.Append("(");
|
||||
if (aSelf.HasThis) {
|
||||
sb.Append(aSelf.DeclaringType.FullName);
|
||||
sb.Append(",");
|
||||
}
|
||||
if (aSelf.Parameters.Count > 0) {
|
||||
foreach (ParameterDefinition xParam in aSelf.Parameters) {
|
||||
sb.Append(xParam.ParameterType.FullName);
|
||||
sb.Append(",");
|
||||
}
|
||||
}
|
||||
return sb.ToString().TrimEnd(',') + ")";
|
||||
}
|
||||
|
||||
private void InitializePlugMethodsList(Assembler.Assembler aAssembler, IEnumerable<AssemblyDefinition> aPlugs, Func<TypeReference, TypeDefinition> aTypeResolver, Func<string, AssemblyDefinition> aAssemblyResolver) {
|
||||
if (mPlugMethods != null) {
|
||||
throw new Exception("PlugMethods list already initialized!");
|
||||
|
|
@ -145,7 +166,6 @@ namespace Indy.IL2CPU.IL {
|
|||
CustomAttribute xPlugMethodAttrib = (from item in xMethod.CustomAttributes.Cast<CustomAttribute>()
|
||||
where item.Constructor.DeclaringType.FullName == typeof(PlugMethodAttribute).FullName
|
||||
select item).FirstOrDefault();
|
||||
//System.Diagnostics.Debugger.Break();
|
||||
string xSignature = String.Empty;
|
||||
if (xPlugMethodAttrib != null) {
|
||||
if (!xPlugMethodAttrib.Resolved) {
|
||||
|
|
@ -172,15 +192,15 @@ namespace Indy.IL2CPU.IL {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
string xStrippedSignature = GetMethodDefinitionFullName(xMethod).Replace(xType.FullName, "");
|
||||
string xStrippedSignature = GetStrippedMethodDefinitionFullName(xMethod);
|
||||
foreach (MethodDefinition xOrigMethodDef in xReplaceTypeDef.Methods) {
|
||||
string xOrigStrippedSignature = GetMethodDefinitionFullName(xOrigMethodDef).Replace(xReplaceTypeDef.FullName, "");
|
||||
string xOrigStrippedSignature = GetStrippedMethodDefinitionFullName(xOrigMethodDef);
|
||||
if (xOrigStrippedSignature == xStrippedSignature) {
|
||||
mPlugMethods.Add(Label.GenerateLabelName(xOrigMethodDef), xMethod);
|
||||
}
|
||||
}
|
||||
foreach (MethodDefinition xOrigMethodDef in xReplaceTypeDef.Constructors) {
|
||||
string xOrigStrippedSignature = GetMethodDefinitionFullName(xOrigMethodDef).Replace(xReplaceTypeDef.FullName, "");
|
||||
string xOrigStrippedSignature = GetStrippedMethodDefinitionFullName(xOrigMethodDef);
|
||||
if (xOrigStrippedSignature == xStrippedSignature) {
|
||||
mPlugMethods.Add(Label.GenerateLabelName(xOrigMethodDef), xMethod);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,20 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Indy.IL2CPU.Plugs;
|
||||
|
||||
namespace Indy.IL2CPU.CustomImplementation.System {
|
||||
[Plug(Target = typeof(String))]
|
||||
public static class StringImpl {
|
||||
[MethodAlias(Name = "System.String System.String.FastAllocateString(System.Int32)")]
|
||||
[PlugMethod(Enabled = false)]
|
||||
public static String FastAllocateString(int aLength) {
|
||||
Char[] xItems = new Char[aLength];
|
||||
return new String(xItems);
|
||||
}
|
||||
|
||||
[MethodAlias(Name = "System.Void System.String..ctor(System.Char[],System.Int32,System.Int32)")]
|
||||
[PlugMethod(Enabled = false)]
|
||||
public static void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")]ref Char[] aStorage, Char[] aChars, int aStartIndex, int aLength) {
|
||||
Char[] newChars = new Char[aLength];
|
||||
Array.Copy(aChars, aStartIndex, newChars, 0, aLength);
|
||||
|
|
@ -20,10 +24,21 @@ namespace Indy.IL2CPU.CustomImplementation.System {
|
|||
}
|
||||
|
||||
[MethodAlias(Name = "System.Void System.String..ctor(System.Char[])")]
|
||||
[PlugMethod(Enabled = false)]
|
||||
public static void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")] ref Char[] aStorage, Char[] aChars) {
|
||||
aStorage = aChars;
|
||||
}
|
||||
|
||||
public static int IndexOf(string aThis, char c) {
|
||||
for (int i = 0; i < aThis.Length; i++) {
|
||||
if (aThis[i] == c) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
[PlugMethod(Enabled = false)]
|
||||
public static uint GetStorage(string aString) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue