//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]); } } }
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); } }
//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); } }
private void StartParse() { //start function is an inherit for easier override implementation down the line new Directives(); var startScope = FunctionStack.First("Start"); var awakeScope = FunctionStack.First("Awake"); HaltFunction = FunctionStack.First("Halt"); GuaranteedHaltFunction = FunctionStack.First("GuaranteedHalt"); if (awakeScope != null) { var awakecollection = FunctionStack.Where("Awake"); foreach (var x in awakecollection) { x.TryParse(null); } } if (startScope == null) { Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.SystemException, $"Your script is missing a 'Start' function.")); } var startCollection = FunctionStack.Where("Start"); if (startCollection.Count() != 2) { Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.SystemException, $"There must only be one `Start` function. Please remove {startCollection.Count() - 2} `Start` functions")); } //remove the start override from the stack var startIndex = FunctionStack.IndexOf(startScope); FunctionStack.RemoveAt(startIndex); startScope.TryParse(null); }