Beispiel #1
0
        private static string ConstructorDestructorMatcher(Match m)
        {
            string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
            string front  = m.Groups[0].ToString().StartsWith("~") ? "dtor" : "ctor";

            return(String.Concat(front, extras));
        }
Beispiel #2
0
        public string GetFormatted(bool useHTML)
        {
            string begin = useHTML ? "<b>" : "";
            string end   = useHTML ? "</b>" : "";
            string str   = StringConvertUtils.AssemblyTypeNameForSignature(EntryType) + " " + begin + Name + end;

            if (EntryType == AssemblyType.Method || EntryType == AssemblyType.Constructor)
            {
                if (GenericParamList.Count > 0)
                {
                    str += begin + "<";
                    str += string.Join(", ", GenericParamList.ToArray());
                    str += ">" + end;
                }

                str += begin + " (" + end;
                string[] paramList = ParamList.Select(p => (useHTML ? p.FormattedHTML() : p.Formatted())).ToArray();
                str += string.Join(begin + ", " + end, paramList);
                str += begin + ")" + end;
            }
            if (ReturnType != null)
            {
                str += begin + " : " + end + ReturnType;
            }
            return(str);
        }
Beispiel #3
0
        private static void ProcessNestedTypes(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (var nested in asmDataItem.cecilType.NestedTypes)
            {
                if (!nested.IsNestedPublic)
                {
                    continue;
                }
                if (nested.IsClass)
                {
                    var nestedClassAsm = new AssemblyDataItem(AssemblyType.Class, nested, asmDataItem);

                    var memberName = nested.ToString().SimplifyTypesAndArrays();
                    memberName = StringConvertUtils.LowerCaseNeedsUnderscore(memberName);

                    nestedClassAsm.UniqueName = memberName;
                    AddAssemblyDataItem(a, nestedClassAsm);
                    BuildAsmChildOfClass(nestedClassAsm, a);
                }
                else
                {
                    int k = 0;
                }
            }
        }
Beispiel #4
0
        private string GetMemberName(MemberReference memberReference)
        {
            var    methodDefinition = memberReference as MethodDefinition;
            string memberName       = "";

            if (methodDefinition != null)
            {
                if (methodDefinition.IsConstructor)
                {
                    memberName = "ctor";
                }
                else if (methodDefinition.Name.StartsWith("op_Implicit"))
                {
                    memberName = "implop_" + methodDefinition.ReturnType.ToString().SimplifyTypes() + "(" +
                                 methodDefinition.Parameters[0].ParameterType.ToString().SimplifyTypes() + ")";
                }
                else if (methodDefinition.Name.StartsWith("op_"))
                {
                    memberName = StringConvertUtils.ConvertOperatorFromAssembly(memberReference.Name);
                }
                else
                {
                    memberName = StringConvertUtils.LowerCaseNeedsUnderscore(memberReference.Name);
                }
            }
            else
            {
                var memName = memberReference.Name;
                memberName = memName == "Item" ? "this" : StringConvertUtils.LowerCaseNeedsUnderscore(memName);
            }

            return(GetTypeName(memberReference.DeclaringType) + "." + memberName);
        }
Beispiel #5
0
        private void PopulateMethods(TypeDefinition cecilType, MemberItem parentItem)
        {
            foreach (var method in cecilType.Methods)
            {
                if (!m_ScanForPrivateMembers && !method.IsPublic)
                {
                    continue;
                }

                if (method.IsGetter || method.IsSetter)
                {
                    continue;
                }

                AssemblyType asmType = AssemblyType.Method;

                var methodName = method.Name;
                if (method.IsConstructor)
                {
                    methodName = "constructor";
                    asmType    = AssemblyType.Constructor;
                }
                else if (methodName.StartsWith("op_Implicit"))
                {
                    methodName = method.ReturnType.ToString().SimplifyTypes();
                    asmType    = AssemblyType.ImplOperator;
                }
                else if (methodName.StartsWith("op_"))
                {
                    methodName = StringConvertUtils.ConvertOperatorFromAssembly(methodName).Substring(3);                     // Skip the op_ part
                    asmType    = AssemblyType.Operator;
                }

                string modifier = "";
                if (method.IsStatic)
                {
                    modifier = "static";
                }

                var asmEntry = new AsmEntry(methodName, asmType, modifier);
                foreach (var param in method.Parameters)
                {
                    string paramType      = param.ParameterType.ToString().SimplifyTypes();
                    bool   paramAttribute = IsParams(param);
                    string paramModifiers = paramAttribute? "params": "";
                    var    paramElement   = new ParamElement(param.Name, paramType, paramModifiers);
                    asmEntry.ParamList.Add(paramElement);
                }
                foreach (GenericParameter param in method.GenericParameters)
                {
                    string paramType = param.GetElementType().ToString().SimplifyTypes();
                    asmEntry.GenericParamList.Add(paramType);
                }
                asmEntry.ReturnType = method.ReturnType.ToString().SimplifyTypes();

                var signatureName = MemberNameGenerator.SignatureNameFromMethodDefinition(method);
                HandleMemberAndSignature(GetMemberName(method), signatureName, asmEntry, parentItem);
            }
        }
Beispiel #6
0
        internal static string GetSignatureFromPureSignature(string sig)
        {
            sig = StringConvertUtils.StripCommonModifiers(sig);

            RegexMatcher matcher;
            var          found = TryMatchSignature(sig, out matcher);

            if (found)
            {
                return(matcher.GetFullMatch(sig));
            }
            return("");
        }
Beispiel #7
0
        internal static void InitRegexList(out RegexMatcher[] regexList)
        {
            regexList = new[]
            {
                new RegexMatcher(ImplOperatorMarker,
                                 m =>
                {
                    string ret    = m.Groups[1].ToString();
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                    return(String.Concat("implop_", ret, extras));
                }, "IMPLICIT OPERATOR"),

                new RegexMatcher(IndexerMarker,
                                 m =>
                {
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                    return(String.Concat("this", extras));
                }, "INDEXER",
                                 m => "this"),
                new RegexMatcher(MethodMarker,
                                 m =>
                {
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[5].ToString());
                    if (m.Groups[4].ToString() != "")
                    {
                        extras = StringConvertUtils.ConvertArgsToString(m.Groups[4].ToString(), '<', '>') + extras;
                    }
                    return(String.Concat(m.Groups[2].ToString(), extras));
                }, "METHOD",
                                 m => m.Groups[2].ToString()),
                new RegexMatcher(OperatorMarker,
                                 m =>
                {
                    string name   = StringConvertUtils.ConvertOperator(m.Groups[2].ToString());
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                    return(String.Concat(name, extras));
                }, "OPERATOR",
                                 m => "op_" + StringConvertUtils.ConvertOperator(m.Groups[2].ToString())),
                new RegexMatcher(FieldAssignmentMarker, DefaultMatcher, "FIELD ASSIGNMENT"),
                new RegexMatcher(FieldMarker, DefaultMatcher, "FIELD"),

                new RegexMatcher(ConstMarker, DefaultMatcher, "CONST"),
                new RegexMatcher(ConstructorMarker, ConstructorDestructorMatcher, "CONSTRUCTOR", ConstructorDestructorMatcherSimplified),

                new RegexMatcher(DestructorMarker, ConstructorDestructorMatcher, "DESTRUCTOR", ConstructorDestructorMatcherSimplified),
                new RegexMatcher(EnumEntryAssignmentMarker,
                                 m => m.Groups[1].ToString(), "ENUM_ENTRY"),
                new RegexMatcher(EnumEntryNoAssignment,
                                 m => m.Groups[1].ToString(), "ENUM_ENTRY_NOASS"),
            };
        }
Beispiel #8
0
        private static string GetMemberOrSignatureID(string codeContent, TypeKind t, bool simplifiedSignature)
        {
            switch (t)
            {
            case TypeKind.Class:
                string c1 = codeContent;
                if (c1.Contains(":"))
                {
                    c1 = c1.Remove(c1.IndexOf(':')).Trim();
                }
                c1 = StringConvertUtils.StripCommonModifiers(c1);
                return(c1);

            case TypeKind.Enum:
                var memberName = codeContent.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries)[0];
                memberName = memberName.TrimEnd(new[] { '=' });

                memberName = StringConvertUtils.LowerCaseNeedsUnderscore(memberName);
                return(memberName);

            case TypeKind.AutoProp:
                var memberName1 = codeContent.Split(' ')[1];
                memberName1 = StringConvertUtils.LowerCaseNeedsUnderscore(memberName1);
                return(memberName1);

            case TypeKind.Struct:
                string s = codeContent;
                s = s.Replace("internal ", "");
                return(s.Trim());

            case TypeKind.PureSignature:
                string sig          = codeContent;
                var    indexOfBrace = sig.IndexOf("{", StringComparison.Ordinal);
                if (indexOfBrace >= 0)                         // remove any body
                {
                    sig = sig.Remove(indexOfBrace).Trim();
                }

                if (simplifiedSignature)
                {
                    return(GetMemberNameFromPureSignature(sig));
                }
                else
                {
                    return(GetSignatureFromPureSignature(sig));
                }

            default:
                return("Error");
            }
        }
Beispiel #9
0
        //covered by unit tests

        internal static string GetMemberNameFromPureSignature(string sig)
        {
            sig = StringConvertUtils.StripCommonModifiers(sig);
            sig = Regex.Replace(sig, "<.*>", "");

            RegexMatcher matcher;
            var          found = TryMatchSignature(sig, out matcher);

            if (found)
            {
                string exp = matcher.GetSimplifiedMatch(sig);
                return((exp == "this") ? exp : StringConvertUtils.LowerCaseNeedsUnderscore(exp));
            }
            return("");
        }
Beispiel #10
0
        internal static void BuildAsmChildOfEnum(AssemblyDataItem asmDataItem, ICollection <AssemblyDataItem> a)
        {
            foreach (FieldDefinition field in asmDataItem.cecilType.Fields)
            {
                if (field.Name == "value__")
                {
                    continue;
                }
                var enumAsm = new AssemblyDataItem(AssemblyType.EnumValue, field.DeclaringType, asmDataItem);

                var parentName = field.DeclaringType.ToString().SimplifyTypesAndArrays();
                var memberName = StringConvertUtils.LowerCaseNeedsUnderscore(field.Name);
                enumAsm.UniqueName = string.Format("{0}.{1}", parentName, memberName);
                AddAssemblyDataItem(a, enumAsm);
            }
        }
Beispiel #11
0
        private static string MemberNameFromMethodDefinition(MethodDefinition methodInfo, bool simplified)
        {
            if (methodInfo.Name.Contains("Slider"))
            {
                int k = 0;
            }
            var sb = new StringBuilder();

            if (methodInfo.Name.Contains("ctor"))
            {
                sb.Append("ctor");
            }
            else if (methodInfo.Name.Contains("op_Implicit"))
            {
                sb.Append("implop_");
                var retString = methodInfo.ReturnType.ToString();
                sb.Append(retString.SimplifyTypesAndArrays());
            }
            else if (methodInfo.Name.Contains("op_"))
            {
                sb.Append(StringConvertUtils.ConvertOperatorFromAssembly(methodInfo.Name));
                sb.Replace("op_", "");
            }

            else
            {
                sb.Append(methodInfo.Name);
            }

            if (methodInfo.HasGenericParameters)
            {
                foreach (var generic in methodInfo.GenericParameters)
                {
                    sb.AppendFormat("_{0}_", generic.Name);
                }
            }
            if (!simplified)
            {
                foreach (var param in methodInfo.Parameters)
                {
                    var paramString = param.ParameterType.ToString();
                    sb.Append("_");
                    sb.Append(paramString.SimplifyTypesAndArrays());
                }
            }
            return(sb.ToString());
        }
        //covered by unit tests
        internal static string GetMemberNameFromPureSignature(string sig, bool simplified = false)
        {
            sig = StringConvertUtils.StripCommonModifiers(sig);

            sig = HandleGenerics(sig);

            RegexMatcher matcher;
            var          found = TryMatchSignature(sig, out matcher);

            if (found)
            {
                string exp = simplified ? matcher.GetSimplifiedMatch(sig) : matcher.GetFullMatch(sig);

                return(StringConvertUtils.LowerCaseNeedsUnderscore(exp));
            }
            return("");
        }
Beispiel #13
0
 private static void AppendName(string methodInfoName, StringBuilder sb)
 {
     if (methodInfoName.Equals(".ctor"))
     {
         sb.Append("ctor");
     }
     else if (methodInfoName.Contains("op_Implicit"))
     {
         Assert.Fail("We are handling this as a special case");
         //sb.Append("implop_");
         //sb.Append(retString.SimplifyTypesAndArrays());
     }
     else if (methodInfoName.Contains("op_"))
     {
         sb.Append(StringConvertUtils.ConvertOperatorFromAssembly(methodInfoName));
         sb.Replace("op_", "");
     }
     else
     {
         sb.Append(methodInfoName);
     }
 }
Beispiel #14
0
 private static string MemberNameFromPropertyDefinition(PropertyDefinition propDefinition)
 {
     return(StringConvertUtils.LowerCaseNeedsUnderscore(propDefinition.Name));
 }
Beispiel #15
0
 private static string MemberNameFromFieldDefinition(FieldDefinition fieldDefinition)
 {
     return(StringConvertUtils.LowerCaseNeedsUnderscore(fieldDefinition.Name));
 }
Beispiel #16
0
        internal static void InitRegexList(out RegexMatcher[] regexList)
        {
            regexList = new[]
            {
                new RegexMatcher(ImplOperatorMarker,
                                 m =>
                {
                    string ret    = m.Groups[1].ToString();
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                    return(String.Concat("implop_", ret, extras));
                }, "IMPLICIT OPERATOR"),

                new RegexMatcher(ImplOperatorFromAssembly,
                                 m =>
                {
                    string ret    = m.Groups[1].ToString();
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                    return(String.Concat("implop_", ret, extras));
                }, "IMPLICIT OPERATOR"),
                new RegexMatcher(OperatorFromAssembly,
                                 m =>
                {
                    string name   = StringConvertUtils.ConvertOperatorFromAssembly(m.Groups[2].ToString());
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                    return(String.Concat(name, extras));
                }, "OPERATOR"),
                new RegexMatcher(IndexerMarker,
                                 m =>
                {
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                    return(String.Concat("this", extras));
                }, "INDEXER"),
                new RegexMatcher(MethodMarker,
                                 m =>
                {
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                    return(String.Concat(m.Groups[2].ToString(), extras));
                }, "METHOD",
                                 m => m.Groups[2].ToString()),
                new RegexMatcher(OperatorMarker,
                                 m =>
                {
                    string name   = StringConvertUtils.ConvertOperator(m.Groups[2].ToString());
                    string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                    return(String.Concat(name, extras));
                }, "OPERATOR"),
                new RegexMatcher(FieldAssignmentMarker, DefaultMatcher, "FIELD ASSIGNMENT"),
                new RegexMatcher(FieldMarker, DefaultMatcher, "FIELD"),

                new RegexMatcher(ConstMarker, DefaultMatcher, "CONST"),
                new RegexMatcher(ConstructorMarker, ConstructorDestructorMatcher,
                                 "CONSTRUCTOR",
                                 m => "ctor"),

                new RegexMatcher(DestructorMarker, ConstructorDestructorMatcher, "DESTRUCTOR"),
                new RegexMatcher(ConstructorFromAssemblyMarker,
                                 m =>
                {
                    var sb = new StringBuilder(m.Groups[0].ToString());
                    sb.Replace("Void .ctor(", "");
                    sb.Replace(")", "");

                    string args = StringConvertUtils.ConvertArgsToString(sb.ToString());
                    return(String.Concat("ctor", args));
                },
                                 "CONSTRUCTOR_ASSEMBLY"),
                new RegexMatcher(EnumEntryAssignmentMarker,
                                 m => m.Groups[1].ToString(), "ENUM_ENTRY"),
                new RegexMatcher(EnumEntryNoAssignment,
                                 m => m.Groups[1].ToString(), "ENUM_ENTRY_NOASS"),
            };
        }