private Function CreateSymbolForFunction(TokenExpression functionDeclarationToken, string className, bool createSymbol) { var dataTypeToken = functionDeclarationToken.GetFirstSubexpression(TokenType.DataType); Variable dataType; if (dataTypeToken != null) { dataType = GetDataType(dataTypeToken); } else { dataType = new Variable("", DataType.Void, -1, 0); } var functionNameToken = functionDeclarationToken.GetFirstSubexpression(TokenType.FunctionName); string functionName = GetFunctionName(functionNameToken, className); var function = Functions.Get(functionName, createSymbol); function.SetVariableType(dataType); if (function.Parameters != null && function.Parameters.Count > 0) { function.Parameters.Clear(); } var poundSignToken = functionDeclarationToken.GetFirstSubexpression(TokenType.Pound); if (poundSignToken != null) { function.IsLabel = 1; } //add parameters var functionParameterListToken = functionDeclarationToken.GetFirstSubexpression(TokenType.FunctionParameterList); if (functionParameterListToken != null) { var parameters = GetVariablesInFunctionParameters(functionParameterListToken); if (function.Parameters.Count < parameters.Length) { function.Parameters.Clear(); foreach (var parameter in parameters) { int index = function.Parameters.Count; parameter.Root = ainFile; parameter.Parent = function; parameter.Index = index; function.Parameters.Add(parameter); } function.ParameterCount = function.Parameters.Count; } } return(function); }
private HllFunction CreateSymbolForLibraryFunction(TokenExpression functionDeclarationToken, string libraryName, string libraryAlias) { var dataTypeToken = functionDeclarationToken.GetFirstSubexpression(TokenType.DataType); Variable dataType; if (dataTypeToken != null) { dataType = GetDataType(dataTypeToken); } else { dataType = new Variable("", DataType.Void, -1, 0); } var functionNameToken = functionDeclarationToken.GetFirstSubexpression(TokenType.FunctionName); string functionName = GetFunctionName(functionNameToken); var library = Libraries.Get(libraryName); library.Root = ainFile; library.LibraryName = libraryName; string fullName = libraryAlias + "." + functionName; var libraryFunction = Symbols.GetOrNull(fullName) as HllFunction; if (libraryFunction == null) { libraryFunction = new HllFunction(); libraryFunction.SetVariableType(dataType); libraryFunction.Name = functionName; libraryFunction.ParentLibrary = library; libraryFunction.Root = ainFile; libraryFunction.Index = library.Functions.Count; library.Functions.Add(libraryFunction); Symbols[fullName] = libraryFunction; } //add parameters var functionParameterListToken = functionDeclarationToken.GetFirstSubexpression(TokenType.FunctionParameterList); if (functionParameterListToken != null) { var parameters = GetVariablesInFunctionParameters(functionParameterListToken); if (libraryFunction.Parameters.Count < parameters.Length) { libraryFunction.Parameters.Clear(); foreach (var parameter in parameters) { int index = libraryFunction.Parameters.Count; if (parameter.DataType != DataType.Void) { var newParameter = new HllFunctionParameter(); newParameter.Parent = libraryFunction; newParameter.Root = ainFile; newParameter.Name = parameter.Name; newParameter.Index = index; newParameter.SetVariableType(parameter); libraryFunction.Parameters.Add(newParameter); } else { } } libraryFunction.ParameterCount = libraryFunction.Parameters.Count; } } return(libraryFunction); }