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 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 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); }
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 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); }
public LuatFunction(LuatValue returnValue, string[] arguments) : base(null) { m_type = new LuatTypeFunction(arguments); ReturnValue = returnValue; }
/// <summary> /// Gets the formatted text to display in quick info for the specified function call /// </summary> private string GetQuickInfoForFunctionCall(LuatValue func, int parameterIndex) { var functionType = func.Type as LuatTypeFunction; var sb = new StringBuilder(); sb.Append("<img src=\"resource:PublicMethod\" align=\"absbottom\"/> "); sb.Append("<span style=\"color: blue;\">function</span> "); // sb.Append(String.Format("<span style=\"color: teal;\">{0}</span>", IntelliPrompt.EscapeMarkupText(functionDeclaration.Name.Text))); sb.Append("("); string[] parameters = functionType == null ? new string[0] : functionType.Arguments; for (int index = 0; index < parameters.Length; index++) { if (index > 0) sb.Append(", "); if (parameterIndex == index) sb.Append("<b>"); sb.Append(IntelliPrompt.EscapeMarkupText(parameters[index])); if (parameterIndex == index) sb.Append("</b>"); } sb.Append(")<br/>"); sb.Append(FormatText(func.Description)); return sb.ToString(); }
public AutoCompleteItem(string name, LuatValue value) { Name = name; Description = value.Description; Icon = value.Type.Icon; }
public LuatVariable CreateReflectedVariable(string strTypeName, LuatValue parent) { foreach (ReflectedTypeResolver resolver in m_reflectedTypeResolvers) { LuatVariable variable; if (resolver(strTypeName, parent, out variable)) { return variable; } } return new LuatVariable(parent, new LuatTypeReflected(strTypeName), LuatVariableFlags.FixedType); }
public override LuatValue Resolve(LuatScript script) { LuatValue value = base.Resolve(script); if (null != value) { return(value); } LuatValue funcValue = Owner.Resolve(script); if (null == funcValue) { return(null); } if (null != Name) { // funcValue isn't actually the function, but the owner. funcValue = funcValue.Index(Name.Text); if (null == funcValue) { return(null); } } // Infer return type for value LuatFunction function = funcValue as LuatFunction; if (null == function) { LuatVariable variable = funcValue as LuatVariable; if (null != variable) { foreach (LuatValue.IReference reference in variable.AssignmentsRecursive) { function = reference.Value as LuatFunction; if (null != function) { break; } } } } if (null == function) { return(null); } if (function.ExpectsSelf != this.PassesSelf) { string warning = string.Format("Function expects to be called using '{0}' not '{1}'", function.ExpectsSelf ? ':' : '.', this.PassesSelf ? ':' : '.'); AddWarning(script, WarningType.WrongFunctionCall, warning); } this.m_resolvedFunctions.Add(script, function); this.ResolvedValues[script] = function.ReturnValue; return(function); }
public LuatVariable(LuatValue parent, LuatType type, LuatVariableFlags flags) : base(parent) { m_flags = flags; m_type = type; }
public LuatVariable(LuatValue parent, LuatVariableFlags flags) : base(parent) { m_flags = flags; }
public LuatVariable(LuatValue parent) : base(parent) { }
private static string GetReferenceText(LuatValue.IReference reference, ILuaIntellisenseProject project) { string fileContents; { var uri = new Uri(reference.Path); var document = project[uri]; var useOpenDocument = (document != null) && (!string.IsNullOrEmpty(document.Contents)); try { fileContents = useOpenDocument ? document.Contents : System.IO.File.ReadAllText(uri.LocalPath); } catch (Exception ex) { fileContents = string.Empty; ex.ToString(); } fileContents = fileContents.Replace("\r\n", "\n"); } if (string.IsNullOrEmpty(fileContents)) return reference.DisplayText; int lineStart, lineEnd; for (lineStart = reference.TextRange.StartOffset; lineStart > 0; --lineStart) { if (fileContents[lineStart] == '\n') { ++lineStart; break; } } for (lineEnd = reference.TextRange.StartOffset; lineEnd < fileContents.Length; ++lineEnd) { if (fileContents[lineEnd] == '\n') { break; } } return fileContents.Substring(lineStart, lineEnd - lineStart); }