//sets the override to directly hop to the base when called, while still remaining overridable //only one function per type can be IsBase private void DirectiveIsBase(string val, IBaseFunction func) { val = val.Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); bool value = (val == "true" || val == "True") ? true : false; if (value) { var samelist = FunctionStack.Where(func.Name).ToList(); foreach (var x in samelist) { //check to make sure this is the only IsBase directive of this type if (x.UID != func.UID && x.Directives != null && x.Directives.ContainsKey("IsBase")) { var stripws = x.Directives["IsBase"].Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); if (stripws == "true" || stripws == "True") { Compiler.ExceptionListener.Throw($"The function [{func.Name}] has already been set IsBase by a directive. Please remove an IsBase directive."); } } } if (FunctionStack.Contains(func)) { FunctionStack.First(func.UID).SetBase(samelist[samelist.Count - 1]); } } }
//i guess a quick way to essentially deep clone base functions on demand. //idk how much this will kill performance but i cant think of another way public static IBaseFunction CopyFunctionReference(string funcName) { IBaseFunction temp = null; string definedIn = typeof(Function).Assembly.GetName().Name; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { if ((!assembly.GlobalAssemblyCache) && ((assembly.GetName().Name == definedIn) || assembly.GetReferencedAssemblies().Any(a => a.Name == definedIn))) { foreach (System.Type type in assembly.GetTypes()) { if (type.GetCustomAttributes(typeof(Function), true).Length > 0) { var attt = type.GetCustomAttribute(typeof(Function), true) as Function; if (attt.Name == funcName) { var func = System.Type.GetType(type.ToString()); var inst = Activator.CreateInstance(func) as IBaseFunction; inst.SetProperties(attt.Name, attt.ExpectedArgs, attt.Invoking, attt.Sealed, attt.Obsolete, attt.Alias, attt.IsAnonymous); if (!attt.Depricated) { temp = (inst); } } } } } } return(temp); }
//public TFunction Token { get; private set; } public Line(string val, IBaseFunction reference) { Compiler.ExceptionListener.SetCurrentLine(val); Value = val; _reference = reference; //Token = WalkTree(val); }
public void SetBase(IBaseFunction func) { if (func.Sealed) { Compiler.ExceptionListener.Throw( $"Cannot override function [{func.Name}] because it is sealed."); } Base = func; }
public static void AnalyzeScreen(string success, IBaseFunction successAction, IBaseFunction failureAction, string[] prop, TFunction caller = null) { var tfunc = new TFunction(caller.Function, new List <EDefinition>(), string.Join(",", caller.Function.GetInvokeProperties()), caller.CallingFunction); try { bool finished = false; bool func = false; Thread th = new Thread(() => { AnalyzeScreen ascreen = new AnalyzeScreen(); ascreen.Analyze(success.UnCleanString(), () => { finished = true; func = true; }, () => { finished = true; }, prop ); }); th.Start(); Stopwatch watch = new Stopwatch(); watch.Start(); while (finished == false) { if (TokenParser.Stop) { break; } Thread.Sleep(1000); //sleep for 1 second before checking again //if 30 seconds go by, then break and kill the thread if (watch.Elapsed.TotalMilliseconds >= 45000) { Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler(ExceptionType.SystemException, $"CheckScreen() timed out.")); //smash the thread and move on. we dont care about that data anyway try { th.Abort(); } catch (Exception e) { if (!(e is ThreadAbortException)) { throw; } } break; } } watch.Stop(); if (func) { successAction.TryParse(tfunc); } else { failureAction.TryParse(tfunc); } } catch { Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler("[63]Image check failed to execute. Continuing with failure function")); failureAction.TryParse(tfunc); } }
public override string[] Extend(IBaseFunction input) { List <string> temp = new List <string>(); temp.Add(input.Name); temp.AddRange(base.Extend()); FunctionReference.TryParse(new TFunction(FunctionReference, null, temp.ToArray(), null)); return(Execute(FunctionReference.ReturnBubble.ToString())); }
private void DirectiveOmit(string val, IBaseFunction func) { val = val.Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); bool value = (val == "true" || val == "True") ? true : false; if (value) { if (FunctionStack.Contains(func)) { FunctionStack.Remove(func); } } }
private void DirectiveLayer(string val, IBaseFunction func) { int index = 0; bool tryint = int.TryParse(val, out index); if (!tryint) { Compiler.ExceptionListener.Throw($"The directive [Layer] must have a whole number as its value."); } if (index - 1 > FunctionStack.List.Count) { index = FunctionStack.List.Count - 1; } FunctionStack.MoveTo(func, index); //apply any override to base connections needed since the stack was shuffled var samelist = FunctionStack.Where(func.Name).ToList(); for (var i = 0; i < samelist.Count; i++) { var obj = samelist[i]; if (!obj.Override) { continue; } if (i == samelist.Count - 1) { continue; } IBaseFunction next = null; for (var nexti = i; nexti <= samelist.Count - i; nexti++) { if (samelist.ElementAtOrDefault(nexti) == null) { continue; } else { next = samelist[nexti]; break; } } if (next == null) { Compiler.ExceptionListener.Throw($"Unknown error applying directive [Layer] on function [{func.Name}]"); } obj.SetBase(next); } }
//this constructor is when function is anonomysly named public AnonymousFunction(string value, bool anon, IBaseFunction callerBase) : this() { Base = callerBase; IsAnonymous = true; //get top level anonymous functions before everything else value = value.Substring(1); var anonRegex = new Regex(Compiler.ScopeRegex(@"=>"), RegexOptions.IgnorePatternWhitespace); var anonRegexMatches = anonRegex.Matches(value); foreach (var a in anonRegexMatches) { var func = new AnonymousFunction(a.ToString(), true, _base); FunctionStack.Add(func); value = value.Replace(a.ToString(), $"\"{func.Name}\""); } Value = value; Name = "AnonymousFunction" + Compiler.AnonymousFunctionIndex; ExpectedArgs = value.Split('(')[1].Split(')')[0].Split(','); ParseDirectives(value); //Name = value.Split('.')[1].Split('(')[0]; }
}/// <summary> /// callingFunction is the function that is calling(usually `this`), func is the function being called /// </summary> /// <param name="func"></param> /// <param name="ext"></param> /// <param name="args"></param> /// <param name="callingFunction"></param> public TFunction(IBaseFunction func, List <EDefinition> ext, string[] args, IBaseFunction callingFunction, LoopTracer t = null) { Name = func.Name; Function = func; _value = "[Type.TFunction]"; Extensions = ext; Arguments = args; CallingFunction = callingFunction; if (t != null) { Tracer = t; } else if (callingFunction != null) { Tracer = callingFunction.Tracer; } else { Tracer = null; } }
//seals the function so no more overrides can occur private void DirectiveSealed(string val, IBaseFunction func) { val = val.Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); bool value = (val == "true" || val == "True") ? true : false; if (value) { //FunctionStack.MoveTo(func, 0); var samelist = FunctionStack.Where(func.Name).ToList(); foreach (var x in samelist) { if (x.UID != func.UID && x.Directives != null && x.Directives.ContainsKey("Sealed")) { var stripws = x.Directives["Sealed"].Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); if (stripws == "true" || stripws == "True") { Compiler.ExceptionListener.Throw($"The function [{func.Name}] has already been sealed by a directive. Please remove a Sealed directive."); } } } func.SetSealed(value); } }
internal TryCatchEvent(IBaseFunction tryblock, IBaseFunction catchblock) { TryBlock = tryblock; CatchBlock = catchblock; }
public virtual string[] Extend(IBaseFunction input) { ObsoleteWarning(); Compiler.ExceptionListener.Throw("[51]Unexpected error occured."); return(null); }
private void DirectiveMinVer(string val, IBaseFunction func) { val = val.Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\r", ""); string[] splode = val.Split(','); if (splode[0] == "soft") { var maj = splode.ElementAtOrDefault(1); var min = splode.ElementAtOrDefault(2); var build = splode.ElementAtOrDefault(3); var rev = splode.ElementAtOrDefault(4); if (maj == null) { Compiler.ExceptionListener.Throw("MinVer Directive must express a major version"); } string[] ver = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.'); int majint = -1; int minint = -1; int buildint = -1; int revint = -1; int.TryParse(maj, out majint); if (min != null) { int.TryParse(min, out minint); } if (build != null) { int.TryParse(build, out buildint); } if (rev != null) { int.TryParse(rev, out revint); } if (majint == -1) { Compiler.ExceptionListener.Throw("MinVer Directive must express a major version as a number"); } if (int.Parse(ver[0]) < majint) { Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Major version [{majint}].")); if (FunctionStack.Contains(func)) { FunctionStack.Remove(func); } return; } if (minint != -1 && int.Parse(ver[1]) < minint) { Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Minor version [{minint}].")); if (FunctionStack.Contains(func)) { FunctionStack.Remove(func); } return; } if (buildint != -1 && int.Parse(ver[2]) < buildint) { Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Build version [{buildint}].")); if (FunctionStack.Contains(func)) { FunctionStack.Remove(func); } return; } if (revint != -1 && int.Parse(ver[3]) < revint) { Compiler.ExceptionListener.ThrowSilent(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Revision version [{revint}].")); if (FunctionStack.Contains(func)) { FunctionStack.Remove(func); } return; } } else { var maj = splode.ElementAtOrDefault(0); var min = splode.ElementAtOrDefault(1); var build = splode.ElementAtOrDefault(2); var rev = splode.ElementAtOrDefault(3); if (maj == null) { Compiler.ExceptionListener.Throw("MinVer Directive must express a major version"); } string[] ver = Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.'); int majint = -1; int minint = -1; int buildint = -1; int revint = -1; int.TryParse(maj, out majint); if (min != null) { int.TryParse(min, out minint); } if (build != null) { int.TryParse(build, out buildint); } if (rev != null) { int.TryParse(rev, out revint); } if (majint == -1) { Compiler.ExceptionListener.Throw("MinVer Directive must express a major version as a number"); } if (int.Parse(ver[0]) < majint) { Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Major version [{majint}].")); } if (minint != -1 && int.Parse(ver[1]) < minint) { Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Minor version [{minint}].")); } if (buildint != -1 && int.Parse(ver[2]) < buildint) { Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Build version [{buildint}].")); } if (revint != -1 && int.Parse(ver[3]) < revint) { Compiler.ExceptionListener.Throw(new ExceptionHandler($"Function [{func.Name}] did not pass minimum version directive. Expected Revision version [{revint}].")); } } }