public static void SetField(string name, object value, ScriptRoutineCheckContext context = 0) { if (context == ScriptRoutineCheckContext.Fields) { for (int i = 0; i < Fields.Count; i++) { var field = Fields [i]; if (field.Name == name) { field = CODE_READER.SetFieldValue(field, value); } Fields[i] = field; } for (int i = 0; i < EnvironmentFields.Count; i++) { var field = EnvironmentFields [i]; if (field.Name == name) { field = CODE_READER.SetFieldValue(field, value); } EnvironmentFields[i] = field; } } if (context == ScriptRoutineCheckContext.ScriptFields) { for (int i = 0; i < ScriptFields.Count; i++) { var field = ScriptFields [i]; if (field.Name == name) { field = CODE_READER.SetFieldValue(field, value); } ScriptFields[i] = field; } } if (context == ScriptRoutineCheckContext.StaticFields) { for (int i = 0; i < StaticFields.Count; i++) { var field = StaticFields [i]; if (field.Name == name) { field = CODE_READER.SetFieldValue(field, value); } StaticFields[i] = field; } for (int i = 0; i < EnvironmentFields.Count; i++) { var field = EnvironmentFields [i]; if (field.Name == name) { field = CODE_READER.SetFieldValue(field, value); } EnvironmentFields[i] = field; } } }
public static void UnregisterField(ScriptField field, ScriptRoutineCheckContext context) { if (context == ScriptRoutineCheckContext.Fields) { Fields.Remove(field); } if (context == ScriptRoutineCheckContext.ScriptFields) { ScriptFields.Remove(field); } if (context == ScriptRoutineCheckContext.StaticFields) { StaticFields.Remove(field); } }
public static void RegisterField(ScriptField field, ScriptRoutineCheckContext context = ScriptRoutineCheckContext.Fields) { if (context == ScriptRoutineCheckContext.Fields) { Fields.Add(field); } if (context == ScriptRoutineCheckContext.ScriptFields) { ScriptFields.Add(field); } if (context == ScriptRoutineCheckContext.StaticFields) { StaticFields.Add(field); } }
public static ScriptField GetField(string name, ScriptRoutineCheckContext context = 0) { if (context == ScriptRoutineCheckContext.Fields) { foreach (var field in Fields) { if (field.Name == name) { return(field); } } foreach (var field in EnvironmentFields) { if (field.Name == name) { return(field); } } } if (context == ScriptRoutineCheckContext.ScriptFields) { foreach (var field in ScriptFields) { if (field.Name == name) { return(field); } } } if (context == ScriptRoutineCheckContext.StaticFields) { foreach (var field in StaticFields) { if (field.Name == name) { return(field); } } foreach (var field in EnvironmentFields) { if (field.Name == name) { return(field); } } } return(null); }
/// <summary> /// Checks the language routines. /// </summary> /// <param name="code">Code.</param> /// <param name="routineContext">Context Of This Routine,Script,Compilation or Static.</param> public static void CheckLanguageRoutines(string code, int routineContext = 0) { ScriptRoutineCheckContext context = (ScriptRoutineCheckContext)routineContext; if (code.Contains(CODE_INFO.LineSeparator.ToString())) { code = code.Replace(CODE_INFO.LineSeparator.ToString(), ""); } if (code.Contains("Declare")) { if (code.Contains("var") && routineContext == 1) { ScriptCompiler.Output.AddLog("This var declaration is invalid|2|10"); } //var l = code.Split(' '); var l = StringUtils.CustomSplit(code, ' ', '"'); if (l.Length >= 3) { string nameOf = l[1]; string valueOf = l[2]; ScriptField field = new ScriptField(nameOf); var reads = GetReads(valueOf, null); field = SetFieldValue(field, reads); var possibleField = CODE_EXEC.GetField(nameOf, context); if (possibleField == null) { CODE_EXEC.RegisterField(field, context); } } } if (code.Contains("Set")) { if (code.Contains("=") && routineContext == 1) { ScriptCompiler.Output.AddLog("= in a wrong local|2|10"); } var l = StringUtils.CustomSplit(code, ' ', '"'); if (l.Length >= 4) { string nameOf = l[1]; string valueOf = l[3]; var reads = GetReads(valueOf, null); CODE_EXEC.SetField(nameOf, reads); } } }