Пример #1
0
        private HashSet <string> GetFIRSTForBranch(List <SubRulePart> branch)
        {
            HashSet <string> res = new HashSet <string>();

            if (branch.Count == 0)
            {
                res.Add(StringConstants.EmptyProduction);
            }
            foreach (SubRulePart srp in branch)
            {
                if (srp is SubRuleAction)
                {
                    continue;
                }
                HashSet <string> HS;
                if (srp is SubRuleComplexPart)
                {
                    HS = GetFIRSTforComplexSubRulePart(srp as SubRuleComplexPart);
                }
                else
                {
                    HS = GetFIRST(srp.Name);
                }
                res.UnionWith(HS);
                if (!HS.Contains(StringConstants.EmptyProduction))
                {
                    break;
                }
            }
            return(res);
        }
Пример #2
0
    private static void CheckError_Invocation(string allInvokeWithLocationOutputPath)
    {
        if (typesImpByJs == null)
        {
            typesImpByJs      = new Dictionary <string, List <string> >();
            typesImpByJs["T"] = new List <string> {
                "T"
            };
            typesImpByJs["System.Action"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Action$1"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Action$2"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Action$3"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Action$4"] = new List <string> {
                ""                                                  /* 调用 action */
            };
            typesImpByJs["System.Func$1"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Func$2"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Func$3"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Func$4"] = new List <string> {
                ""                                                /* 调用 action */
            };
            typesImpByJs["System.Exception"] = new List <string> {
                "ctor$$String"
            };
            typesImpByJs["System.NotImplementedException"] = new List <string> {
                "ctor"
            };
            typesImpByJs["System.Array"] = new List <string>
            {
                "length",
                "CopyTo",
                "Static_Convertall",
                "Static_Sort$1$$T$Array"
            };
            typesImpByJs["System.Collections.Generic.List$1"] = new List <string>
            {
                "ctor",
                "ctor$$IEnumerable$1",
                "ctor$$Int32",
                "RemoveRange",
                "Clear",
                "get_Item$$Int32",
                "set_Item$$Int32",
                "get_Count",
                "GetEnumerator",
                "ToArray",
                "AddRange",
                "Add",
                "Remove",
                "Contains",
                "SetItems",
                "IndexOf",
                "Exists",
                "IndexOf$$T",
                "Insert",
                "RemoveAt",
                "RemoveAll",
                //"TryRemove",
                "CopyTo",
                //"get_IsReadOnly",
                "Reverse",
                "Sort",
                "Sort$$Comparison$1",
                "ForEach",
                "Find",
                "FindIndex$$Predicate$1",
                "FindIndex$$Int32$$Predicate$1",
                "FindIndex$$Int32$$Int32$$Predicate$1",
                "FindLastIndex$$Predicate$1",
                "FindLastIndex$$Int32$$Predicate$1",
                "FindLastIndex$$Int32$$Int32$$Predicate$1",
                "FindAll",
                "GetRange",
                "InsertRange"
            };
            typesImpByJs["System.Collections.Generic.Dictionary$2"] = new List <string>
            {
                "ctor",
                "ctor$$Int32",
                "Add",
                "Remove",
                "get_Item$$TKey",
                "set_Item$$TKey",
                "ContainsKey",
                "GetEnumerator",
                "Clear",
                "TryGetValue",
                "get_Count",
                "get_Keys",
                "get_Values"
            };
            typesImpByJs["System.Collections.Generic.KeyValuePair$2"] = new List <string>
            {
                "get_Key",
                "get_Value",
                "ctor$$TKey$$TValue"
            };
            typesImpByJs["System.Collections.Generic.Dictionary.ValueCollection$2"] = new List <string> {
                "CopyTo"
            };
            // 特殊!
            typesImpByJs["System.Collections.Generic.Dictionary.KeyCollection$2"] = new List <string> {
                "CopyTo"
            };                                                                                                     // 特殊!
            typesImpByJs["System.Linq.Enumerable"] = new List <string> {
                "Static_ToArray$1"
            };
            typesImpByJs["System.Collections.Generic.HashSet$1"] = new List <string>
            {
                "ctor",
                "Add",
                "get_Count",
                "Clear",
                "Contains",
                "Remove"
            };
            typesImpByJs["System.Collections.Generic.Queue$1"] = new List <string>
            {
                "ctor",
                "ctor$$Int32",
                "Clear",
                "get_Count",
                "Enqueue",
                "Dequeue",
                "Peek",
                "Contains",
                "ToArray"
            };
            typesImpByJs["System.String"] = new List <string>
            {
                // native
                "toString",
                "length",
                "replace",
                "split",
                "indexOf",
                "substr",
                "charAt",
                /// static
                "Static_Empty",
                "Static_Format$$String$$Object",
                "Static_Format$$String$$Object$$Object",
                "Static_Format$$String$$Object$$Object$$Object",
                "Static_IsNullOrEmpty",
                "Static_Equals$$String$$String$$StringComparison",
                "Static_Join$$String$$String$Array",
                // instance
                "ctor$$Char$Array",
                "ctor$$Char$Array$$Int32$$Int32",
                "Insert",
                "Substring$$Int32",
                "Substring$$Int32$$Int32",
                "Substring",
                "ToLower",
                "toLowerCase",
                "ToUpper",
                "toUpperCase",
                "getItem",
                "IndexOf$$String",
                "IndexOf$$Char",
                "LastIndexOf",
                "LastIndexOf$$Char",
                "LastIndexOf$$String",
                "Remove$$Int32",
                "Remove$$Int32$$Int32",
                "StartsWith$$String",
                "EndsWith$$String",
                "Contains",
                "get_Length",
                "Split$$Char$Array",
                "trim",
                "Trim",
                "ltrim",
                "rtrim",
                "Static_Format$$String$$Object$Array",
                "Replace$$String$$String",
                "Replace$$Char$$Char",
                "PadLeft$$Int32$$Char",
                "PadRight$$Int32$$Char",
                "ToCharArray"
            };
            typesImpByJs["System.Char"] = new List <string> {
                "toString", "Static_IsNumber$$Char"
            };
            typesImpByJs["System.Int32"] = new List <string>
            {
                "toString",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Int32",
                "ToString$$String",
                "CompareTo$$Int32"
            };
            typesImpByJs["System.UInt64"] = new List <string>
            {
                "toString",
                "Static_Parse$$String",
                "Static_TryParse$$String$$UInt64"
            };
            typesImpByJs["System.Int64"] = new List <string>
            {
                "toString",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Int64",
                "ToString$$String",
                "CompareTo$$Int64"
            };
            typesImpByJs["System.Boolean"] = new List <string>
            {
                "toString",
                "CompareTo$$Boolean"
            };
            typesImpByJs["System.Double"] = new List <string>
            {
                "toString",
                "ToString$$String",
                "CompareTo$$Double",
                "Static_tryParse",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Double"
            };
            typesImpByJs["System.Single"] = new List <string>
            {
                "toString",
                "ToString$$String",
                "CompareTo$$Single",
                "Static_tryParse",
                "Static_Parse$$String",
                "Static_TryParse$$String$$Single"
            };
            //			typesImpByJs["System.Int32"] = new List<string> { "toString", "Static_Parse$$String",  };
            typesImpByJs["System.Enum"] = new List <string> {
                "toString"
            };
            typesImpByJs["System.MulticastDelegate"] = new List <string>();
        }


        string allExportedMembersFile = GetAllExportedMembersFile();

        var allInvoked  = LoadAllInvoked(allInvokeWithLocationOutputPath);
        var allExported = LoadAllExported(allExportedMembersFile);

        foreach (var KV in typesImpByJs)
        {
            HashSet <string> HS = null;
            if (!allExported.TryGetValue(KV.Key, out HS))
            {
                HS = new HashSet <string>();
                allExported.Add(KV.Key, HS);
            }
            if (KV.Value == null)
            {
                continue;
            }

            foreach (string m in KV.Value)
            {
                if (!HS.Contains(m))
                {
                    HS.Add(m);
                }
            }
        }

        var sbError = new StringBuilder();

        int errCount = 0;

        foreach (var KV in allInvoked)
        {
            string           typeName = KV.Key;
            HashSet <string> hsExported;
            var DInvoked = KV.Value;

            // 类有导出吗?
            if (!allExported.TryGetValue(typeName, out hsExported))
            {
                errCount++;
                sbError.AppendFormat("[{0}] not exported.", typeName);
                sbError.AppendLine();
                foreach (var KV2 in DInvoked)
                {
                    string methodName = KV2.Key;
                    sbError.AppendFormat("      {0}", methodName);
                    sbError.AppendLine();

                    foreach (var loc in KV2.Value)
                    {
                        sbError.AppendFormat("        {0} {1}", loc.FileName, loc.Line);
                        sbError.AppendLine();
                    }
                }
            }
            else
            {
                foreach (var KV2 in DInvoked)
                {
                    string methodName = KV2.Key;
                    // 函数可用/有导出吗
                    if (hsExported == null || !hsExported.Contains(methodName))
                    {
                        errCount++;
                        sbError.AppendFormat("[{0}].{1} not valid.", typeName, methodName);
                        sbError.AppendLine();

                        foreach (var loc in KV2.Value)
                        {
                            sbError.AppendFormat("        {0} {1}", loc.FileName, loc.Line);
                            sbError.AppendLine();
                        }
                    }
                }
            }
        }

        string fullpath = GetTempFileNameFullPath("CompilerCheckErrorResult.txt");

        File.Delete(fullpath);

        if (errCount > 0)
        {
            File.WriteAllText(fullpath, sbError.ToString());

            string relPath = fullpath.Replace("\\", "/").Substring(fullpath.IndexOf("Assets/"));
            var    context = AssetDatabase.LoadAssetAtPath <Object>(relPath);
            Debug.LogError("Check invocation error result: (" + errCount + " errors) (点击此条可定位文件)", context);
            Debug.LogError(sbError);
        }
        else
        {
            Debug.Log("Check invocation error result: 0 error");
        }
    }