protected override void BaseScopes(string scopeName) { Scope global = parseInfo.TranslateInfo.GlobalScope; staticScope = global.Child(scopeName); operationalScope = global.Child(scopeName); serveObjectScope = new Scope(scopeName); }
protected override void BaseScopes(string scopeName) { Scope classContainer = _parseInfo.TranslateInfo.GlobalScope.Child(); classContainer.CatchConflict = true; staticScope = classContainer.Child(scopeName); operationalScope = classContainer.Child(scopeName); serveObjectScope = new Scope(scopeName); }
public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext) { RawContinue = false; Scope varScope = scope.Child(); ForeachVar = new ForeachVariable(varScope, new ForeachContextHandler(parseInfo, foreachContext)); // Get the array that will be iterated on. Syntax error if it is missing. if (foreachContext.expr() != null) { Array = parseInfo.GetExpression(scope, foreachContext.expr()); } else { parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN())); } // Get the foreach block. Syntax error if it is missing. if (foreachContext.block() != null) { Block = new BlockAction(parseInfo.SetLoop(this), varScope, foreachContext.block()); // Get the path info. Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false); } else { parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN())); } }
public void GetMeta() { _staticScope = _scope.Child(true); _objectScope = _staticScope.Child(true); // Add type args to scopes. foreach (var type in GenericTypes) { _staticScope.AddType(new GenericCodeTypeInitializer(type)); _objectScope.AddType(new GenericCodeTypeInitializer(type)); } var declarationParseInfo = _parseInfo.SetContextualModifierGroup(_contextualVariableModifiers); // Get declarations. foreach (var declaration in _context.Declarations) { var element = ((IDefinedTypeInitializer)this).ApplyDeclaration(declaration, declarationParseInfo); if (element is IMethodProvider method) { Methods.Add(method); } } }
public ForAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForContext forContext) { Scope varScope = scope.Child(); if (forContext.define() != null) { DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, forContext.define())); } else if (forContext.initialVarset != null) { InitialVarSet = new SetVariableAction(parseInfo, varScope, forContext.initialVarset); } if (forContext.expr() != null) { Condition = DeltinScript.GetExpression(parseInfo, varScope, forContext.expr()); } if (forContext.endingVarset != null) { SetVariableAction = new SetVariableAction(parseInfo, varScope, forContext.endingVarset); } // Get the block. if (forContext.block() != null) { Block = new BlockAction(parseInfo.SetLoop(this), varScope, forContext.block()); // Get the path info. Path = new PathInfo(Block, DocRange.GetRange(forContext.FOR()), false); } else { parseInfo.Script.Diagnostics.Error("Expected a block.", DocRange.GetRange(forContext.RIGHT_PAREN())); } }
public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext) { Scope varScope = scope.Child(); ForeachVar = new Var(foreachContext.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(foreachContext.name)), parseInfo); ForeachVar.VariableType = VariableType.ElementReference; ForeachVar.CodeType = CodeType.GetCodeTypeFromContext(parseInfo, foreachContext.code_type()); ForeachVar.Finalize(varScope); // Get the array that will be iterated on. Syntax error if it is missing. if (foreachContext.expr() != null) { Array = DeltinScript.GetExpression(parseInfo, scope, foreachContext.expr()); } else { parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN())); } // Get the foreach block. Syntax error if it is missing. if (foreachContext.block() != null) { Block = new BlockAction(parseInfo, varScope, foreachContext.block()); // Get the path info. Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false); } else { parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN())); } }
public DefinedFunction(ParseInfo parseInfo, Scope scope, string name, Location definedAt) { Name = name; DefinedAt = definedAt; this.parseInfo = parseInfo; methodScope = scope.Child(); CallInfo = new CallInfo(this, parseInfo.Script); parseInfo.TranslateInfo.AddSymbolLink(this, definedAt); }
public void SetupBlock() { if (_expressionToParse != null) { Expression = _parseInfo.SetCallInfo(CallInfo).GetExpression(_scope.Child(), _expressionToParse); } foreach (var listener in listeners) { listener.Applied(); } }
public BlockAction(ParseInfo parseInfo, Scope scope, Block blockContext) { BlockScope = scope.Child(); Statements = new IStatement[blockContext.Statements.Count]; for (int i = 0; i < Statements.Length; i++) { Statements[i] = parseInfo.GetStatement(BlockScope, blockContext.Statements[i]); } parseInfo.Script.AddCompletionRange(new CompletionRange(BlockScope, blockContext.Range, CompletionRangeKind.Catch)); }
public BlockAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.S_blockContext blockContext) { BlockScope = scope.Child(); if (blockContext.statement() == null) { Statements = new IStatement[0]; } else { Statements = new IStatement[blockContext.statement().Length]; for (int i = 0; i < Statements.Length; i++) { Statements[i] = parseInfo.GetStatement(BlockScope, blockContext.statement(i)); } } parseInfo.Script.AddCompletionRange(new CompletionRange(BlockScope, DocRange.GetRange(blockContext.BLOCK_START(), blockContext.BLOCK_END()), CompletionRangeKind.Catch)); }
public DefinedConstructor(ParseInfo parseInfo, Scope scope, CodeType type, DeltinScriptParser.ConstructorContext context) : base( type, new LanguageServer.Location(parseInfo.Script.Uri, DocRange.GetRange(context.name)), context.accessor().GetAccessLevel()) { this.parseInfo = parseInfo; this.context = context; CallInfo = new CallInfo(this, parseInfo.Script); ConstructorScope = scope.Child(); if (Type is DefinedType) { ((DefinedType)Type).AddLink(DefinedAt); } parseInfo.TranslateInfo.ApplyBlock(this); parseInfo.TranslateInfo.AddSymbolLink(this, DefinedAt, true); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Constructor, DefinedAt.range)); }
public DefinedConstructor(ParseInfo parseInfo, Scope scope, CodeType type, ConstructorContext context) : base( type, new LanguageServer.Location(parseInfo.Script.Uri, context.LocationToken.Range), context.Attributes.GetAccessLevel()) { this.parseInfo = parseInfo; this.context = context; _recursiveCallHandler = new RecursiveCallHandler(this, "constructor"); CallInfo = new CallInfo(_recursiveCallHandler, parseInfo.Script); SubroutineName = context.SubroutineName?.Text.RemoveQuotes(); ConstructorScope = scope.Child(); if (Type is DefinedType) { ((DefinedType)Type).AddLink(DefinedAt); } parseInfo.TranslateInfo.ApplyBlock(this); parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, DefinedAt, true); parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Constructor, DefinedAt.range)); }
public DeltinScript(TranslateSettings translateSettings) { FileGetter = translateSettings.FileGetter; Diagnostics = translateSettings.Diagnostics; Language = translateSettings.OutputLanguage; OptimizeOutput = translateSettings.OptimizeOutput; Types = new ScriptTypes(this); Types.GetDefaults(); GlobalScope = new Scope("global scope"); RulesetScope = GlobalScope.Child(); RulesetScope.PrivateCatch = true; Types.AddTypesToScope(GlobalScope); Importer = new Importer(this, FileGetter, translateSettings.Root.Uri); Importer.CollectScriptFiles(this, translateSettings.Root); Translate(); if (!Diagnostics.ContainsErrors()) { try { ToWorkshop(translateSettings.AdditionalRules); } catch (Exception ex) { WorkshopCode = "An exception was thrown while translating to workshop.\r\n" + ex.ToString(); } } foreach (IComponent component in Components) { if (component is IDisposable disposable) { disposable.Dispose(); } } }
public ForAction(ParseInfo parseInfo, Scope scope, For forContext) { Scope varScope = scope.Child(); IsAutoFor = forContext.Iterator is ExpressionStatement; // Get the initializer. if (!IsAutoFor) { // Normal for loop initializer. if (forContext.Initializer != null) { // Declaration for initializer. if (forContext.Initializer is VariableDeclaration declaration) { DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, declaration)); } // Variable assignment for initializer else if (forContext.Initializer is Assignment assignment) { Initializer = new SetVariableAction(parseInfo, varScope, assignment); } // TODO: Throw error on incorrect initializer type. } } else { // Auto-for initializer. // Missing initializer. if (forContext.Initializer == null) { // Error if there is no initializer. if (forContext.InitializerSemicolon) { parseInfo.Script.Diagnostics.Error("Auto-for loops require an initializer.", forContext.InitializerSemicolon.Range); } } // Declaration else if (forContext.Initializer is VariableDeclaration declaration) { DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, declaration)); } // Assignment else if (forContext.Initializer is Assignment assignment) { // Get the variable being set. VariableResolve = new VariableResolve(new VariableResolveOptions() { // The for cannot be indexed and should be on the rule-level. CanBeIndexed = false, FullVariable = true }, parseInfo.GetExpression(varScope, assignment.VariableExpression), assignment.VariableExpression.Range, parseInfo.Script.Diagnostics); InitialResolveValue = parseInfo.GetExpression(scope, assignment.Value); } // Variable else if (forContext.Initializer is ExpressionStatement exprStatement && exprStatement.Expression is Identifier identifier) { // The variable is defined but no start value was given. In this case, just start at 0. // Get the variable. VariableResolve = new VariableResolve(new VariableResolveOptions() { // The for cannot be indexed and should be on the rule-level. CanBeIndexed = false, FullVariable = true }, parseInfo.GetExpression(varScope, identifier), identifier.Range, parseInfo.Script.Diagnostics); }
protected void SetupScope(Scope chosenScope) { methodScope = chosenScope.Child(); containingScope = chosenScope; }
public void SetupBlock() { if (_expressionToParse != null) { Expression = _parseInfo.SetCallInfo(CallInfo).SetExpectingLambda(CodeType).GetExpression(_scope.Child(), _expressionToParse); } _wasApplied = true; foreach (var listener in listeners) { listener.Applied(); } }
protected void SetupScope(Scope chosenScope) { methodScope = chosenScope.Child(); methodScope.CatchConflict = true; containingScope = chosenScope; }