Example #1
0
        static void Cache(BTSource[] sources)
        {
            BTLCache btlCache = new BTLCache();

            int n = sources.Length;

            string[] strSources = new string[n];
            string[] filepaths  = new string[n];
            btlCache.hashes     = new byte[n][];
            btlCache.exceptions = new PandaScriptException[n];

            for (int i = 0; i < n; i++)
            {
                if (sources[i] != null)
                {
                    strSources[i]          = sources[i].source;
                    filepaths[i]           = sources[i].url;
                    btlCache.hashes[i]     = GetHash(strSources[i]);
                    btlCache.exceptions[i] = null;
                }
                else
                {
                    strSources[i]          = null;
                    filepaths[i]           = null;
                    btlCache.hashes[i]     = null;
                    btlCache.exceptions[i] = null;
                }
            }

            btlCache.tokenSets = Tokenize(strSources, filepaths, ref btlCache.exceptions);
            btlCache.rootSets  = ParseTokens(btlCache.tokenSets, filepaths, ref btlCache.exceptions);

            cache[GetKey(sources)] = btlCache;
        }
Example #2
0
        static BTLCache Fetch(BTSource[] texts)
        {
            BTLCache btlCache = null;

            bool   updateCache = true;
            string key         = GetKey(texts);

            if (cache.ContainsKey(key))
            {
                btlCache = cache[key];
                var newHashes = GetHashes(texts);
                if (AreSameHashes(newHashes, btlCache.hashes))
                {
                    updateCache = false;
                }
            }

            if (updateCache)
            {
                Cache(texts);
                btlCache = cache[GetKey(texts)];
            }

            return(btlCache);
        }
Example #3
0
        public static BTLParser.Node[][] GetBTLRoots(BTSource[] texts)
        {
            BTLParser.Node[][] rootSets = null;
            BTLCache           btlCache = Fetch(texts);

            rootSets = btlCache.rootSets;
            return(rootSets);
        }
Example #4
0
        public static BTLTokenizer.Token[][] GetBTLTokens(BTSource[] texts)
        {
            BTLTokenizer.Token[][] tokenSets = null;
            BTLCache btlCache = Fetch(texts);

            tokenSets = btlCache.tokenSets;
            return(tokenSets);
        }
Example #5
0
        public static System.Exception[] GetCompilationExceptions(BTSource[] texts)
        {
            var      exceptions = new List <System.Exception>();
            BTLCache btlCache   = Fetch(texts);

            for (int i = 0; i < texts.Length; i++)
            {
                if (btlCache.exceptions[i] != null)
                {
                    exceptions.Add(btlCache.exceptions[i]);
                }
            }
            return(exceptions.ToArray());
        }
Example #6
0
        public static bool HasCompilationErrors(BTSource[] texts)
        {
            bool     hasErrors = false;
            BTLCache btlCache  = Fetch(texts);

            for (int i = 0; i < texts.Length; i++)
            {
                if (btlCache.exceptions[i] != null)
                {
                    hasErrors = true;
                }
            }
            return(hasErrors);
        }
Example #7
0
        public static BTLParser.Node[] GetBTLRoots(BTSource[] texts, BTSource text)
        {
            BTLParser.Node[] roots    = null;
            BTLCache         btlCache = Fetch(texts);

            for (int i = 0; i < texts.Length; i++)
            {
                if (texts[i] == text)
                {
                    roots = btlCache.rootSets[i];
                }
            }
            return(roots);
        }
Example #8
0
        public static BTLTokenizer.Token[] GetBTLTokens(BTSource[] texts, BTSource text)
        {
            BTLTokenizer.Token[] tokens   = null;
            BTLCache             btlCache = Fetch(texts);

            for (int i = 0; i < texts.Length; i++)
            {
                if (texts[i] == text && i < btlCache.tokenSets.Length)
                {
                    tokens = btlCache.tokenSets[i];
                }
            }
            return(tokens);
        }