/// <summary> /// Returns function declaration line from source code. /// </summary> /// <param name="node">The node.</param> /// <param name="document">The document.</param> /// <returns></returns> public static TextPoint GetFunctionDeclarationFromSource( FunctionDeclaration node, TextDocument document) { TextPoint endPoint = null; string name = node.Name; var functionLineText = GetCodeLineText(document, node.Location.sLin); if (!string.IsNullOrEmpty(functionLineText)) { int startIndex = functionLineText.ToLower().IndexOf("function", StringComparison.CurrentCultureIgnoreCase); if (startIndex > -1) { int nameIndex = functionLineText.IndexOf(name); endPoint = new LuaTextPoint(document, nameIndex + name.Length + 2, node.Location.sLin); } } return endPoint; }
/// <summary> /// Adds a function to the top-level element. /// </summary> /// <param name="objectName">Name of the object.</param> /// <param name="returnType">Type of the return.</param> /// <param name="function">The function.</param> /// <returns></returns> public CodeFunction AddFunction(string objectName, LuaDeclaredType returnType, FunctionDeclaration function) { CodeFunction codeFunction = RootElement.AddFunction(objectName, vsCMFunction.vsCMFunctionFunction, returnType, Missing.Value, vsCMAccess.vsCMAccessPublic, function); return codeFunction; }
/// <summary> /// Recurse and translate Function AST node. /// </summary> /// <param name="node">AST node instance.</param> /// <param name="parentElement">Parent of LuaCodeFunction element.</param> private void RecurseFunctionNode(Function node, CodeElement parentElement) { var functionNode = new FunctionDeclaration(node.Location) { Body = node.Body, Name = node.Name, Next = node.Next, ParameterList = node.ParameterList, IsLocal = true }; RecurseFunctionDeclarationNode(parentElement, functionNode); }
/// <summary> /// Recurse and translate FunctionDeclaration AST node. /// </summary> /// <param name="node">AST node instance.</param> /// <param name="parentElement">Parent of element.</param> private void RecurseFunctionDeclarationNode(CodeElement parentElement, FunctionDeclaration node) { AddElementToParent(parentElement, RecurseFunctionDeclaration(parentElement, node)); }
/// <summary> /// Recurse and translate FunctionDeclaration AST node. /// </summary> /// <param name="node">AST node instance.</param> private void RecurseFunctionDeclarationNode(FunctionDeclaration node) { rootElement.AddFunction(RecurseFunctionDeclaration(rootElement, node)); }
/// <summary> /// Recurse and translate FunctionDeclaration AST node. /// </summary> /// <param name="node">AST node instance.</param> /// <param name="parentElement">Parent of function.</param> private LuaCodeFunction RecurseFunctionDeclaration(CodeElement parentElement, FunctionDeclaration node) { LuaCodeFunction function = LuaCodeElementFactory.CreateLuaCodeFunction( dte, parentElement, node.Name, LuaType.Unknown, node.IsLocal, node); if (node.Body != null && node.Body.StatementList != null) { foreach (var statement in node.Body.StatementList) { RecurseStatement(function, statement); } } if (node.ParameterList != null) { foreach (Identifier param in node.ParameterList.IdentifierList) { function.AddParameter(param.Name, param, -1); } } return function; }