public void GetDeclarations(LuaBlockNode block, LuaModel model) { for (int i = 0; i < VariableList.Count; ++i) { LuaNode variable = VariableList[i]; Declaration namespaces, sibling = null; bool isDeclarationAssign = false; if (i < ExpressionList.Count) isDeclarationAssign = DeclarationHelper.TryGetExpressionDeclaration(ExpressionList[i], block, model, out sibling); DeclarationType type = GetDeclarationType(variable, block, out namespaces); if (type == DeclarationType.Global && variable is LuaIdentifierNode) { Declaration declaration = new Declaration(variable.AsString, String.Empty, model.FilePath, new ScopeSpan(variable.Span.EndPosition, variable.EndLine, int.MaxValue, int.MaxValue)); if (isDeclarationAssign) sibling.AddSibling(declaration); block.Globals.Add(declaration); } else if (type == DeclarationType.Global && variable is LuaTableAccessNode) { string[] names = variable.AsString.Split('.'); Declaration declaration = new Declaration(names[names.Length - 1], String.Empty, model.FilePath, new ScopeSpan(variable.Span.EndPosition, variable.EndLine, int.MaxValue, int.MaxValue), namespaces); if (isDeclarationAssign) sibling.AddSibling(declaration); block.Globals.Add(declaration); } else if (type == DeclarationType.Local) { string[] names = variable.AsString.Split('.'); Declaration declaration = new Declaration(names[names.Length - 1], String.Empty, model.FilePath, new ScopeSpan(variable.Span.EndPosition, variable.EndLine, block.Span.EndPosition, block.EndLine), namespaces); if (isDeclarationAssign) sibling.AddSibling(declaration); block.Locals.Add(declaration); } } }
public void GetDeclarations(LuaBlockNode block, LuaModel model) { for (int i = 0; i < VariableList.Count && i < ExpressionList.Count; ++i) { LuaNode variable = VariableList[i]; Declaration declaration = new Declaration(variable.AsString, String.Empty, model.FilePath, new ScopeSpan(variable.Span.EndPosition, variable.EndLine, block.Span.EndPosition, block.EndLine)); //block.Locals.Add(declaration); if (i < ExpressionList.Count) { if (ExpressionList[i] is LuaTableNode) { declaration.Type = LuaDeclarationType.Table; AddDeclarationsForTableField(block, model, declaration, ExpressionList[i]); } else if (ExpressionList[i] is LuaIdentifierNode || ExpressionList[i] is LuaTableAccessNode) { Declaration sibling = null; if (DeclarationHelper.TryGetExpressionDeclaration(ExpressionList[i], block, model, out sibling)) { declaration.Type = sibling.Type; sibling.AddSibling(declaration); } } } // add declaration as the end in case of circling sibling which lead to stackoverflow block.Locals.Add(declaration); } }