public DefinedEnumMember(DeltinScript translateInfo, DefinedEnum type, string name, int id, Location definedAt) { Enum = type; Name = name; DefinedAt = definedAt; ID = id; _translateInfo = translateInfo; translateInfo.AddSymbolLink(this, definedAt); }
public DefinedEnumMember(ParseInfo parseInfo, DefinedEnum type, string name, LanguageServer.Location definedAt, ExpressionOrWorkshopValue value) { Enum = type; Name = name; DefinedAt = definedAt; _translateInfo = parseInfo.TranslateInfo; ValueExpression = value; _translateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, definedAt, true); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.EnumValue, DefinedAt.range)); }
public DefinedEnumMember(ParseInfo parseInfo, DefinedEnum type, string name, LanguageServer.Location definedAt, ExpressionOrWorkshopValue value) { Enum = type; Name = name; DefinedAt = definedAt; _deltinScript = parseInfo.TranslateInfo; ValueExpression = value; parseInfo.Script.Elements.AddDeclarationCall(this, new(definedAt.range, true)); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.EnumValue, DefinedAt.range)); }
public DefinedEnumMember(ParseInfo parseInfo, DefinedEnum type, string name, int id, Location definedAt) { Enum = type; Name = name; DefinedAt = definedAt; ID = id; _translateInfo = parseInfo.TranslateInfo; _translateInfo.AddSymbolLink(this, definedAt, true); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.EnumValue, DefinedAt.range)); }
void Translate() { // Get the reserved variables and IDs foreach (ScriptFile script in ScriptFiles) { if (script.Context.reserved_global()?.reserved_list() != null) { foreach (var name in script.Context.reserved_global().reserved_list().PART()) { VarCollection.Reserve(name.GetText(), true); } foreach (var id in script.Context.reserved_global().reserved_list().NUMBER()) { VarCollection.Reserve(int.Parse(id.GetText()), true, null, null); } } if (script.Context.reserved_player()?.reserved_list() != null) { foreach (var name in script.Context.reserved_player().reserved_list().PART()) { VarCollection.Reserve(name.GetText(), false); } foreach (var id in script.Context.reserved_player().reserved_list().NUMBER()) { VarCollection.Reserve(int.Parse(id.GetText()), false, null, null); } } } // Get the enums foreach (ScriptFile script in ScriptFiles) { foreach (var enumContext in script.Context.enum_define()) { var newEnum = new DefinedEnum(new ParseInfo(script, this), enumContext); types.Add(newEnum); definedTypes.Add(newEnum); } } // Get the types foreach (ScriptFile script in ScriptFiles) { foreach (var typeContext in script.Context.type_define()) { var newType = new DefinedType(new ParseInfo(script, this), GlobalScope, typeContext); types.Add(newType); definedTypes.Add(newType); } } // Get the methods and macros foreach (ScriptFile script in ScriptFiles) { // Get the methods. foreach (var methodContext in script.Context.define_method()) { var newMethod = new DefinedMethod(new ParseInfo(script, this), RulesetScope, RulesetScope, methodContext, null); } // Get the macros. foreach (var macroContext in script.Context.define_macro()) { GetMacro(new ParseInfo(script, this), RulesetScope, RulesetScope, macroContext); } } // Get the defined variables. foreach (ScriptFile script in ScriptFiles) { foreach (var varContext in script.Context.define()) { Var newVar = new RuleLevelVariable(RulesetScope, new DefineContextHandler(new ParseInfo(script, this), varContext)); rulesetVariables.Add(newVar); // Add the variable to the player variables scope if it is a player variable. if (newVar.VariableType == VariableType.Player) { PlayerVariableScope.CopyVariable(newVar); } } } foreach (var applyType in types) { if (applyType is ClassType classType) { classType.ResolveElements(); } } foreach (var apply in applyBlocks) { apply.SetupParameters(); } foreach (var apply in applyBlocks) { apply.SetupBlock(); } foreach (var apply in applyBlocks) { apply.CallInfo?.CheckRecursion(); } // Get the rules foreach (ScriptFile script in ScriptFiles) { foreach (var ruleContext in script.Context.ow_rule()) { rules.Add(new RuleAction(new ParseInfo(script, this), RulesetScope, ruleContext)); } } }
void Translate() { List <IApplyBlock> applyMethods = new List <IApplyBlock>(); // Get the reserved variables and IDs foreach (ScriptFile script in ScriptFiles) { if (script.Context.reserved_global()?.reserved_list() != null) { foreach (var name in script.Context.reserved_global().reserved_list().PART()) { VarCollection.Reserve(name.GetText(), true); } foreach (var id in script.Context.reserved_global().reserved_list().NUMBER()) { VarCollection.Reserve(int.Parse(id.GetText()), true, null, null); } } if (script.Context.reserved_player()?.reserved_list() != null) { foreach (var name in script.Context.reserved_player().reserved_list().PART()) { VarCollection.Reserve(name.GetText(), false); } foreach (var id in script.Context.reserved_player().reserved_list().NUMBER()) { VarCollection.Reserve(int.Parse(id.GetText()), false, null, null); } } } // Get the enums foreach (ScriptFile script in ScriptFiles) { foreach (var enumContext in script.Context.enum_define()) { var newEnum = new DefinedEnum(new ParseInfo(script, this), enumContext); types.Add(newEnum); definedTypes.Add(newEnum); } } // Get the types foreach (ScriptFile script in ScriptFiles) { foreach (var typeContext in script.Context.type_define()) { var newType = new DefinedType(new ParseInfo(script, this), GlobalScope, typeContext, applyMethods); types.Add(newType); definedTypes.Add(newType); } } // Get the methods and macros foreach (ScriptFile script in ScriptFiles) { // Get the methods. foreach (var methodContext in script.Context.define_method()) { var newMethod = new DefinedMethod(new ParseInfo(script, this), RulesetScope, methodContext); applyMethods.Add(newMethod); //RulesetScope.AddMethod(newMethod, script.Diagnostics, DocRange.GetRange(methodContext.name)); } // Get the macros. foreach (var macroContext in script.Context.define_macro()) { GetMacro(new ParseInfo(script, this), RulesetScope, macroContext, applyMethods); } } // Get the defined variables. foreach (ScriptFile script in ScriptFiles) { foreach (var varContext in script.Context.define()) { var newVar = Var.CreateVarFromContext(VariableDefineType.RuleLevel, new ParseInfo(script, this), varContext); newVar.Finalize(RulesetScope); rulesetVariables.Add(newVar); // Add the variable to the player variables scope if it is a player variable. if (newVar.VariableType == VariableType.Player) { PlayerVariableScope.AddVariable(newVar, null, null); } } } foreach (var apply in applyMethods) { apply.SetupBlock(); } foreach (var apply in applyMethods) { apply.CallInfo.CheckRecursion(); } // Get the rules foreach (ScriptFile script in ScriptFiles) { foreach (var ruleContext in script.Context.ow_rule()) { rules.Add(new RuleAction(new ParseInfo(script, this), RulesetScope, ruleContext)); } } }
void Translate() { // Get the reserved variables and IDs // foreach (ScriptFile script in Importer.ScriptFiles) // { // if (script.Context.reserved_global()?.reserved_list() != null) // { // foreach (var name in script.Context.reserved_global().reserved_list().PART()) VarCollection.Reserve(name.GetText(), true); // foreach (var id in script.Context.reserved_global().reserved_list().NUMBER()) VarCollection.Reserve(int.Parse(id.GetText()), true, null, null); // } // if (script.Context.reserved_player()?.reserved_list() != null) // { // foreach (var name in script.Context.reserved_player().reserved_list().PART()) VarCollection.Reserve(name.GetText(), false); // foreach (var id in script.Context.reserved_player().reserved_list().NUMBER()) VarCollection.Reserve(int.Parse(id.GetText()), false, null, null); // } // } // Get the enums foreach (ScriptFile script in Importer.ScriptFiles) { foreach (var enumContext in script.Context.Enums) { var newEnum = new DefinedEnum(new ParseInfo(script, this), enumContext); Types.AllTypes.Add(newEnum); Types.DefinedTypes.Add(newEnum); Types.CalledTypes.Add(newEnum); } } // Get the types foreach (ScriptFile script in Importer.ScriptFiles) { foreach (var typeContext in script.Context.Classes) { var newType = new DefinedType(new ParseInfo(script, this), GlobalScope, typeContext); Types.AllTypes.Add(newType); Types.DefinedTypes.Add(newType); Types.CalledTypes.Add(newType); } } // Get the declarations foreach (ScriptFile script in Importer.ScriptFiles) { ParseInfo parseInfo = new ParseInfo(script, this); // Get the functions. foreach (var declaration in script.Context.Declarations) { // Function if (declaration is FunctionContext function) { new DefinedMethod(parseInfo, RulesetScope, RulesetScope, function, null); } // Macro function else if (declaration is MacroFunctionContext macroFunction) { parseInfo.GetMacro(RulesetScope, RulesetScope, macroFunction); } // Macro var else if (declaration is MacroVarDeclaration macroVar) { parseInfo.GetMacro(RulesetScope, RulesetScope, macroVar); } // Variables else if (declaration is VariableDeclaration variable) { Var newVar = new RuleLevelVariable(RulesetScope, new DefineContextHandler(new ParseInfo(script, this), variable)); rulesetVariables.Add(newVar); // Add the variable to the player variables scope if it is a player variable. if (newVar.VariableType == VariableType.Player) { PlayerVariableScope.CopyVariable(newVar); } } } } foreach (var applyType in Types.AllTypes) { if (applyType is ClassType classType) { classType.ResolveElements(); } } foreach (var apply in _applyBlocks) { apply.SetupParameters(); } foreach (var apply in _applyBlocks) { apply.SetupBlock(); } foreach (var callInfo in _recursionCheck) { callInfo.CheckRecursion(); } // Get hooks foreach (ScriptFile script in Importer.ScriptFiles) { foreach (var hookContext in script.Context.Hooks) { HookVar.GetHook(new ParseInfo(script, this), RulesetScope, hookContext); } } // Get the rules foreach (ScriptFile script in Importer.ScriptFiles) { foreach (var ruleContext in script.Context.Rules) { rules.Add(new RuleAction(new ParseInfo(script, this), RulesetScope, ruleContext)); } } }