Ejemplo n.º 1
0
        // For better GDB, ELF, DWARF and exported EntryPoints, we want avoid ReturnType and (Arguments) spaces within SymbolName for better usability.
        public static string GetSignature(string name, MosaMethodSignature sig, bool shortSig, bool includeReturnType = true, bool stripSpaces = false)
        {
            var result = new StringBuilder();

            if (shortSig)
            {
                result.Append(name);
                result.Append("(");
                for (int i = 0; i < sig.Parameters.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append(",");
                        if (!stripSpaces)
                        {
                            result.Append(" ");
                        }
                    }
                    result.Append(sig.Parameters[i].ParameterType.ShortName);
                }
                result.Append(")");

                if (includeReturnType)
                {
                    result.Append(" : ");
                    result.Append(sig.ReturnType.ShortName);
                }

                return(result.ToString());
            }
            else
            {
                if (includeReturnType)
                {
                    result.Append(sig.ReturnType.FullName);
                    result.Append(" ");
                }

                result.Append(name);
                result.Append("(");
                for (int i = 0; i < sig.Parameters.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append(",");
                        if (!stripSpaces)
                        {
                            result.Append(" ");
                        }
                    }
                    result.Append(sig.Parameters[i].ParameterType.FullName);
                }
                result.Append(")");
                return(result.ToString());
            }
        }
Ejemplo n.º 2
0
        public static int GetHashCode(MosaMethodSignature method)
        {
            int result = GetHashCode(method.ReturnType);

            foreach (var param in method.Parameters)
            {
                result += result * 7 + GetHashCode(param.ParameterType);
            }
            return(result);
        }
Ejemplo n.º 3
0
 public MosaMethod FindMethodBySignature(string name, MosaMethodSignature sig)
 {
     foreach (var method in Methods)
     {
         if (method.Name == name && method.Signature.Equals(sig))
         {
             return(method);
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
        public static MosaType ToFnPtr(this TypeSystem typeSystem, MosaMethodSignature signature)
        {
            MosaType result = typeSystem.Controller.CreateType();

            using (var ptrType = typeSystem.Controller.MutateType(result))
            {
                ptrType.Module    = typeSystem.LinkerModule;
                ptrType.Namespace = "";
                ptrType.Name      = "";

                ptrType.TypeCode       = MosaTypeCode.FunctionPointer;
                ptrType.FunctionPtrSig = signature;

                return(result);
            }
        }
Ejemplo n.º 5
0
        public static string GetSignature(string name, MosaMethodSignature sig, bool shortSig)
        {
            StringBuilder result = new StringBuilder();

            if (shortSig)
            {
                result.Append(name);
                result.Append("(");
                for (int i = 0; i < sig.Parameters.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append(", ");
                    }
                    result.Append(sig.Parameters[i].ParameterType.Name);
                }
                result.Append(") : ");
                result.Append(sig.ReturnType.Name);
                return(result.ToString());
            }
            else
            {
                result.Append(sig.ReturnType.FullName);
                result.Append(" ");
                result.Append(name);
                result.Append("(");
                for (int i = 0; i < sig.Parameters.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append(", ");
                    }
                    result.Append(sig.Parameters[i].ParameterType.FullName);
                }
                result.Append(")");
                return(result.ToString());
            }
        }
Ejemplo n.º 6
0
 bool IEqualityComparer <MosaMethodSignature> .Equals(MosaMethodSignature x, MosaMethodSignature y)
 {
     return(Equals(x, y));
 }
Ejemplo n.º 7
0
 public static bool Equals(MosaMethodSignature x, MosaMethodSignature y)
 {
     return(Equals(x.ReturnType, y.ReturnType) &&
            x.Parameters.SequenceEquals(y.Parameters));
 }
Ejemplo n.º 8
0
 int IEqualityComparer <MosaMethodSignature> .GetHashCode(MosaMethodSignature method)
 {
     return(GetHashCode(method));
 }