public LuatVariable AddLocal(LuatScript script, Identifier Name, string type) { string name = Name.Text; LuatVariable variable = Locals[script].Index(name, false) as LuatVariable; if (null == variable) { LuatTable localTable = Locals[script]; if (null != type) { variable = Database.Instance.CreateReflectedVariable(type, localTable); } if (null == variable) { variable = new LuatVariable(localTable); } localTable.AddChild(name, variable); } else { Name.AddWarning(script, WarningType.DuplicateLocal, "Warning: Local '" + name + "' already defined"); } return(variable); }
public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null != value) { return(value); } int index = 1; foreach (Identifier identifier in this.Parameters) { LuatVariable local = this.Block.AddLocal(script, identifier, null); local.Description = string.Format("parameter {0}", index++); } List <string> args = new List <string>(); foreach (Identifier param in this.Parameters) { args.Add(param.Text); } LuatValue returnValue = this.Block.ReturnValues[script]; LuatFunction function = new LuatFunction(returnValue, args.ToArray()); function.Description = this.Description; function.ExpectsSelf = this.ExpectsSelf; value = function; this.ResolvedValues[script] = value; return(value); }
public override IEnumerable <AutoCompleteItem> GetAutoCompleteList(LuatScript script, int offset) { Dictionary <string, LuatValue> scopedValues = new Dictionary <string, LuatValue>(); GetScopedValues(script, ref scopedValues); foreach (KeyValuePair <string, LuatValue> v in scopedValues) { yield return(new AutoCompleteItem(v.Key, v.Value)); } yield return(new AutoCompleteItem("function", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("local", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("end", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("for", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("if", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("do", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("while", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("repeat", null, LuaIntellisenseIconType.Keyword)); yield return(new AutoCompleteItem("return", null, LuaIntellisenseIconType.Keyword)); }
public override bool Install(LuatScript script) { if (false == base.Install(script)) { return(false); } if (null == this.Body) { return(false); } if (null == this.Start) { return(false); } LuatVariable iterator = Body.AddLocal(script, Iterator.Name, null); LuatValue.IReference reference = new Parser.AST.Expression.Reference(script, this.Start); iterator.AddAssignment(reference); AddUninstallAction(script, delegate() { iterator.RemoveAssignment(reference); }); return(base.Install(script)); }
public T this[LuatScript script] { get { return(Add(script)); } }
public override void Invalidate(LuatScript script) { if (Database.Instance.AddUnresolvedStatement(script, this)) { Uninstall(script); } }
public void Invalidate(LuatScript script) { if (m_entries.ContainsKey(script)) { m_entries[script].RemoveReference(new Parser.AST.Expression.Reference(script, m_owner)); m_entries.Remove(script); } }
public virtual void GetScopedValues(LuatScript script, ref Dictionary <string, LuatValue> scopedValues) { LuatAstNodeBase parent = this.ParentNode as LuatAstNodeBase; if (null != parent) { parent.GetScopedValues(script, ref scopedValues); } }
public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null != value) { return(value); } LuatTable table = new LuatTable(null); int fieldIndex = 1; foreach (Field field in Fields) { string key; if (null == field.Key) { key = (fieldIndex++).ToString(); } else if (field.Key is StringExpression) { key = (field.Key as StringExpression).String; } else if (field.Key is NumberExpression) { key = (field.Key as NumberExpression).Number.ToString(); } else if (field.Key is Identifier) { key = (field.Key as Identifier).Text; } else { continue; } if (null != table.Index(key, false)) { field.AddWarning(script, WarningType.DuplicateTableKey, string.Format("Table already contains key '{0}'", key)); continue; } LuatVariable entry = table.AddChild(key, new LuatVariable(table)); entry.Description = Description; if (null != field.Value) { entry.AddAssignment(new Parser.AST.Expression.Reference(script, field.Value, this.DisplayText)); } } this.ResolvedValues[script] = table; return(table); }
public virtual bool Uninstall(LuatScript script) { foreach (UninstallAction uninstallAction in m_uninstallScriptActions[script]) { uninstallAction(); } m_uninstallScriptActions.Remove(script); return(true); }
public T Add(LuatScript script) { T value; if (false == m_entries.TryGetValue(script, out value)) { value = m_valueConstructor(); m_entries.Add(script, value); } return(value); }
public override void GetScopedValues(LuatScript script, ref Dictionary <string, LuatValue> scopedValues) { foreach (var v in script.Table.Children) { if (scopedValues.ContainsKey(v.Key)) { continue; } scopedValues.Add(v.Key, v.Value); } }
public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null == value) { value = new LuatLiteral(Type); value.Description = this.Description; this.ResolvedValues[script] = value; } return(value); }
private static LuatScript CreateLuatScript(ILuaIntellisenseDocument document) { var table = new LuatTable(null) { Description = Helpers.Decorate(document.Name, DecorationType.Code) }; var luatScript = LuatScript.Create(); luatScript.Table = table; luatScript.Path = document.Uri.LocalPath; luatScript.Reference = document; luatScript.Name = document.Name; return(luatScript); }
public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null != value) { return(value); } string name = Name.Text; BlockStatement block = this.FindAncestor(typeof(BlockStatement)) as BlockStatement; if (IsLocal) { value = block.AddLocal(script, Name, Type); } else { // Start by searching locals of the ancestor blocks while (block != null) { value = block.Locals[script].Index(name); if (null != value) { ResolvedValues[script] = value; return(value); } block = block.FindAncestor(typeof(BlockStatement)) as BlockStatement; } // Now try globals value = script.Table.Index(name, IsLHSOfAssignment); } if (null != value) { this.ResolvedValues[script] = value; } return(value); }
public override bool Install(LuatScript script) { if (false == base.Install(script)) { return(false); } if (null == this.Body) { return(false); } foreach (Identifier iterator in this.Iterators) { Body.AddLocal(script, iterator, null); } return(base.Install(script)); }
public override bool Install(LuatScript script) { if (false == base.Install(script)) { return(false); } BlockStatement block; Function func = this.FindAncestor <Function>(); if (null != func) { block = func.Block; } else { block = this.FindAncestor <BlockStatement>(); } if (null == block) { throw new Exception("ReturnStatement requires a BlockStatement as ancestor"); } List <LuatValue> values = new List <LuatValue>(); foreach (Expression expression in Values) { // TODO: not correct for multiple return values LuatVariable returnValue = block.ReturnValues[script]; LuatValue.IReference reference = new Parser.AST.Expression.Reference(script, expression, "return " + expression.DisplayText); returnValue.AddAssignment(reference); AddUninstallAction(script, delegate() { returnValue.RemoveAssignment(reference); }); } if (IsMultiline) { AddWarning(script, WarningType.MultilineReturn, string.Format("Returning value from next line")); } return(true); }
public override void Invalidate(LuatScript script) { if (null == this.ResolvedValues[script]) { return; } // Add this expression to the needs-resolving list Database.Instance.AddUnresolvedExpression(script, this); // Drop the value this.ResolvedValues.Invalidate(script); // Propagate invalidation up the syntax tree LuatAstNodeBase parent = this.ParentNode as LuatAstNodeBase; if (null != parent) { parent.Invalidate(script); } }
public override IEnumerable <AutoCompleteItem> GetAutoCompleteList(LuatScript script, int offset) { if (offset > this.LHS.EndOffset) { LuatValue value = LHS.ResolvedValues[script]; if (null != value) { foreach (KeyValuePair <string, LuatValue> child in value.Children) { yield return(new AutoCompleteItem(child.Key, child.Value)); } } } else { foreach (AutoCompleteItem item in base.GetAutoCompleteList(script, offset)) { yield return(item); } } }
public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null != value) { return(value); } LuatValue lhsValue = LHS.Resolve(script); if (null == lhsValue) { return(null); } if (null == RHS) { return(null); } string index; if (false == GetString(RHS, out index)) { return(null); } value = lhsValue.Index(index, IsLHSOfAssignment); if (null == value) { return(null); } this.ResolvedValues[script] = value; return(value); }
// Indexer public LuatValue this[LuatScript script] { get { LuatValue value; m_entries.TryGetValue(script, out value); return(value); } set { if (null == value) { throw new Exception("Do not assign null to Value. Instead call Invalidate()"); } if (m_entries.ContainsKey(script)) { throw new Exception("Value can only be assigned once after creation or invalidation"); } this.m_entries.Add(script, value); value.AddReference(new Parser.AST.Expression.Reference(script, m_owner, m_owner.DisplayText)); } }
public bool Contains(LuatScript script) { return(m_entries.ContainsKey(script)); }
public UnresolvedExpression(LuatScript script, Expression expression) { Script = script; Expression = expression; }
/// <summary> /// Remove the LuatScript from the database /// </summary> /// <param name="script"></param> private void Drop(LuatScript script) { // Invalidate all nodes foreach (LuatAstNodeBase node in Helpers.Traversal<IAstNode>(script.CU, n => n.ChildNodes)) { node.Invalidate(script); } script.UnresolvedExpressions.Clear(); script.UnresolvedStatements.Clear(); }
public virtual bool Install(LuatScript script) { return(true); }
public virtual void Invalidate(LuatScript script) { CU.ClearWarnings(script); }
public override void Invalidate(LuatScript script) { this.Locals.Remove(script); base.Invalidate(script); }
protected void AddUninstallAction(LuatScript script, UninstallAction action) { m_uninstallScriptActions[script].Add(action); }
/// <summary> /// Resolves the expression. Since the type of the LHS of a binary expression /// must match the type of the RHS, resolve the RHS and return that type. /// </summary> /// <param name="script"></param> /// <returns></returns> public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null != value) { return value; } if (null != RightExpression) { value = RightExpression.Resolve(script); if (null != value) { this.ResolvedValues[script] = value; } } return value; }
public void Remove(LuatScript script) { m_entries.Remove(script); }
/// <summary> /// Adds an expression to the unresolved list /// </summary> /// <param name="script"></param> /// <param name="expression"></param> /// <returns></returns> public bool AddUnresolvedExpression(LuatScript script, Expression expression) { LinkedListNode<Expression> node = expression.ListNode[script]; if (node.List == script.UnresolvedExpressions) { return false; } if (null != node.List) { if (node.List != script.ResolvedExpressions) { throw new Exception("Expression is part of an unknown list"); } node.List.Remove(node); } script.UnresolvedExpressions.AddFirst(node); return true; }
public void AddWarning(LuatScript script, WarningType type, string message) { LuatWarning warning = new LuatWarning(script, type, this.TextRange, message); CU.AddWarning(warning); }
/// <summary> /// Adds a statement to the unresolved list /// </summary> /// <param name="script"></param> /// <param name="statement"></param> /// <returns></returns> public bool AddUnresolvedStatement(LuatScript script, Statement statement) { LinkedListNode<Statement> node = statement.ListNode[script]; if (node.List == script.UnresolvedStatements) { return false; } if (null != node.List) { if (node.List != script.ResolvedStatements) { throw new Exception("Statement is part of an unknown list"); } node.List.Remove(node); } script.UnresolvedStatements.AddFirst(node); return true; }
public virtual IEnumerable <AutoCompleteItem> GetAutoCompleteList(LuatScript script, int offset) { LuatAstNodeBase parent = this.ParentNode as LuatAstNodeBase; return((null != parent) ? parent.GetAutoCompleteList(script, offset) : new AutoCompleteItem[0]); }
public override IEnumerable <AutoCompleteItem> GetAutoCompleteList(LuatScript script, int offset) { return(new AutoCompleteItem[0]); }