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; }
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); }
public static BTLParser.Node[][] GetBTLRoots(BTSource[] texts) { BTLParser.Node[][] rootSets = null; BTLCache btlCache = Fetch(texts); rootSets = btlCache.rootSets; return(rootSets); }
public static BTLTokenizer.Token[][] GetBTLTokens(BTSource[] texts) { BTLTokenizer.Token[][] tokenSets = null; BTLCache btlCache = Fetch(texts); tokenSets = btlCache.tokenSets; return(tokenSets); }
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()); }
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); }
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); }
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); }