示例#1
0
        public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
        {
            definingProject = null;
            projEntry       = null;

            // need to handle cases where the name is a function call. I think the only time this would happen is if name ends with ')'
            if (name.EndsWith(")"))
            {
                // try to get the function from the class
                int firstParen = name.IndexOf('(');
                if (firstParen > 0)
                {
                    name = name.Substring(0, firstParen);
                }
            }
            //else
            //{
            if (!string.IsNullOrWhiteSpace(TableName))
            {
                // TODO: get the specified column from the database provider
                return(null);
            }
            else
            {
                MemberType memType = Analysis.MemberType.All;
                // TODO: there's probably a better way to do this
                return(GetAnalysisMembers(ast, memType, out definingProject, out projEntry, function).Where(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault());
            }
            //}
        }
示例#2
0
        private IAnalysisResult GetResolvedType(Genero4glAst ast, out string errMsg)
        {
            errMsg = null;
            IAnalysisResult result = null;
            // if it's not a base type, look up the type
            IGeneroProject dummyProj;
            IProjectEntry  dummyProjEntry;
            bool           isDeferred;
            var            res = Genero4glAst.GetValueByIndex(_typeNameString, StartIndex, ast as Genero4glAst, out dummyProj, out dummyProjEntry, out isDeferred, FunctionProviderSearchMode.NoSearch, false, true, false, false);

            if (res == null)
            {
                errMsg = string.Format("Type {0} not found.", _typeNameString);
            }
            else
            {
                if (res is GeneroPackageClass ||
                    res is TypeDefinitionNode)
                {
                    result = res;
                }
                else
                {
                    errMsg = string.Format("Invalid type {0} found.", _typeNameString);
                }
            }
            return(result);
        }
示例#3
0
 public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
 {
     if (_childRegisters != null)
     {
         return(_childRegisters.Values.Select(x => new MemberResult(x.Name, x, GeneroMemberType.Variable, ast)));
     }
     return(null);
 }
示例#4
0
 public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
 {
     if (Children.Count == 1 &&
         Children[Children.Keys[0]] is TypeReference)
     {
         return((Children[Children.Keys[0]] as TypeReference).GetMembers(ast, memberType, function));
     }
     return(null);
 }
示例#5
0
        public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
        {
            definingProject = null;
            projEntry       = null;
            IFunctionResult funcRes = null;

            _memberFunctions.TryGetValue(name, out funcRes);
            return(funcRes);
        }
示例#6
0
 public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
 {
     if (_returns != null && _returns.Count == 1)
     {
         var typeRef = new TypeReference(_returns[0]);
         return(typeRef.GetMembers(ast, memberType, function));
     }
     return(new MemberResult[0]);
 }
示例#7
0
 public bool HasChildFunctions(Genero4glAst ast)
 {
     if (Children.Count == 1 &&
         Children[Children.Keys[0]] is TypeReference)
     {
         return((Children[Children.Keys[0]] as TypeReference).HasChildFunctions(ast));
     }
     return(false);
 }
示例#8
0
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
 {
     definingProject = null;
     projEntry       = null;
     if (_returns != null && _returns.Count == 1)
     {
         var typeRef = new TypeReference(_returns[0]);
         return(typeRef.GetMember(name, ast, out definingProject, out projEntry, function));
     }
     return(null);
 }
示例#9
0
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
 {
     definingProject = null;
     projEntry       = null;
     if (Children.Count == 1 &&
         Children[Children.Keys[0]] is TypeReference)
     {
         return((Children[Children.Keys[0]] as TypeReference).GetMember(name, ast, out definingProject, out projEntry, function));
     }
     return(null);
 }
示例#10
0
 internal IEnumerable <IAnalysisResult> GetAnalysisResults(Genero4glAst ast)
 {
     if (MemberDictionary.Count == 0 && MimicTableName != null && ast._databaseProvider != null)
     {
         // get the table's columns
         return(ast._databaseProvider.GetColumns(MimicTableName.Name));
     }
     else
     {
         return(MemberDictionary.Values);
     }
 }
示例#11
0
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
 {
     definingProject = null;
     projEntry       = null;
     if (MemberDictionary.Count == 0 && MimicTableName != null)
     {
         return(null);
     }
     else
     {
         VariableDef varDef = null;
         MemberDictionary.TryGetValue(name, out varDef);
         return(varDef);
     }
 }
示例#12
0
        public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
        {
            definingProject = null;
            projEntry       = null;
            ProgramRegister progReg = null;

            if (_childRegisters != null)
            {
                _childRegisters.TryGetValue(name, out progReg);
            }
            else
            {
            }
            return(progReg);
        }
示例#13
0
        internal IEnumerable <MemberResult> GetArrayMembers(Genero4glAst ast, MemberType memberType, bool function)
        {
            List <MemberResult> members = new List <MemberResult>();

            if (Children.Count == 1)
            {
                // we have an array type or a record type definition
                var node = Children[Children.Keys[0]];
                if (node is ArrayTypeReference)
                {
                    return((node as ArrayTypeReference).GetMembersInternal(ast, memberType, function));
                }
            }
            return(members);
        }
示例#14
0
        public bool HasChildFunctions(Genero4glAst ast)
        {
            if (Children.Count == 1)
            {
                var node = Children[Children.Keys[0]];
                if (node is ArrayTypeReference)
                {
                    return(true);
                }
                else if (node is RecordDefinitionNode)
                {
                    return((node as RecordDefinitionNode).HasChildFunctions(ast));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(_typeNameString))
                {
                    if (_typeNameString.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                    else
                    {
                        // try to determine if the _typeNameString is a user defined type
                        IAnalysisResult udt = ast.TryGetUserDefinedType(_typeNameString, LocationIndex);
                        if (udt != null)
                        {
                            return(udt.HasChildFunctions(ast));
                        }

                        // check for package class
                        IGeneroProject dummyProj;
                        IProjectEntry  projEntry;
                        bool           dummyDef;
                        udt = ast.GetValueByIndex(_typeNameString, LocationIndex, ast._functionProvider, ast._databaseProvider, ast._programFileProvider, false, out dummyDef, out dummyProj, out projEntry);
                        if (udt != null)
                        {
                            return(udt.HasChildFunctions(ast));
                        }
                    }
                }
            }
            return(false);
        }
示例#15
0
        internal IEnumerable <IAnalysisResult> GetAnalysisResults(Genero4glAst ast, MemberType memberType, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
        {
            definingProject = null;
            projEntry       = null;
            List <IAnalysisResult> results = new List <IAnalysisResult>();

            if (Children.Count == 1)
            {
                // get the table's columns
                var node = Children[Children.Keys[0]];
                if (node is TypeReference)
                {
                    results.AddRange((node as TypeReference).GetAnalysisMembers(ast, memberType, out definingProject, out projEntry, function));
                }
            }
            results.AddRange(Genero4glAst.ArrayFunctions.Values);
            return(results);
        }
示例#16
0
 public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
 {
     if (MemberDictionary.Count == 0 && MimicTableName != null)
     {
         // get the table's columns
         if (ast._databaseProvider != null)
         {
             return(ast._databaseProvider.GetColumns(MimicTableName.Name).Select(x => new MemberResult(x.Name, x, GeneroMemberType.DbColumn, ast)));
         }
     }
     else
     {
         List <MemberResult> dot = new List <MemberResult> {
             new MemberResult("*", GeneroMemberType.Variable, ast)
         };
         return(dot.Union(MemberDictionary.Values.Select(x => new MemberResult(x.Name, x, GeneroMemberType.Variable, ast))));
     }
     return(new MemberResult[0]);
 }
示例#17
0
 public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc, Dictionary <string, List <int> > deferredFunctionSearches, FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false)
 {
     if (Children.Count > 0)
     {
         base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition);
     }
     else if (!string.IsNullOrWhiteSpace(DatabaseName) ||
              !string.IsNullOrWhiteSpace(TableName) ||
              !string.IsNullOrWhiteSpace(ColumnName))
     {
         // TODO: do deferred checking of these
     }
     else if (_typeNameString != null && !_isConstrainedType)
     {
         // see if the _typeNameString is a base type
         var tok = Tokens.GetToken(_typeNameString);
         if (tok == null || !Genero4glAst.BuiltinTypes.Contains(tok.Kind))
         {
             // if it's not a base type, look up the type
             IGeneroProject dummyProj;
             IProjectEntry  dummyProjEntry;
             bool           isDeferred;
             var            res = Genero4glAst.GetValueByIndex(_typeNameString, StartIndex, ast as Genero4glAst, out dummyProj, out dummyProjEntry, out isDeferred, FunctionProviderSearchMode.NoSearch, false, true, false, false);
             if (res == null)
             {
                 errorFunc(string.Format("Type {0} not found.", _typeNameString), StartIndex, EndIndex);
             }
             else
             {
                 if (res is GeneroPackageClass ||
                     res is TypeDefinitionNode)
                 {
                     ResolvedType = res;
                 }
                 else
                 {
                     errorFunc(string.Format("Invalid type {0} found.", _typeNameString), StartIndex, EndIndex);
                 }
             }
         }
     }
 }
示例#18
0
        internal IEnumerable <MemberResult> GetMembersInternal(Genero4glAst ast, MemberType memberType, bool arrayFunctions = false)
        {
            List <MemberResult> results = new List <MemberResult>();

            if (!arrayFunctions)
            {
                if (Children.Count == 1)
                {
                    var node = Children[Children.Keys[0]];
                    if (node is TypeReference)
                    {
                        results.AddRange((node as TypeReference).GetMembers(ast, memberType, arrayFunctions));
                    }
                }
            }
            else
            {
                results.AddRange(Genero4glAst.ArrayFunctions.Values.Select(x => new MemberResult(x.Name, x, GeneroMemberType.Method, ast)));
            }
            return(results);
        }
        public override IEnumerable <MemberResult> GetContextMembers(int index, IReverseTokenizer revTokenizer, IFunctionInformationProvider functionProvider,
                                                                     IDatabaseInformationProvider databaseProvider, IProgramFileProvider programFileProvider,
                                                                     bool isMemberAccess,
                                                                     out bool includePublicFunctions, out bool includeDatabaseTables, string contextStr,
                                                                     GetMemberOptions options = GetMemberOptions.IntersectMultipleResults)
        {
            _instance               = this;
            _functionProvider       = functionProvider;
            _databaseProvider       = databaseProvider;
            _programFileProvider    = programFileProvider;
            _includePublicFunctions = includePublicFunctions = false;    // this is a flag that the context determination logic sets if public functions should eventually be included in the set
            _includeDatabaseTables  = includeDatabaseTables = false;
            _contextString          = contextStr;

            List <MemberResult> members = new List <MemberResult>();

            // First see if we have a member completion
            if (TryMemberAccess(index, revTokenizer, out members))
            {
                _includePublicFunctions = false;
                _includeDatabaseTables  = false;
                return(members);
            }

            if (!DetermineContext(index, revTokenizer, members) && members.Count == 0)
            {
                // TODO: do we want to put in the statement keywords?
                members.AddRange(GetStatementStartKeywords(index));
            }

            includePublicFunctions  = _includePublicFunctions;
            includeDatabaseTables   = _includeDatabaseTables;
            _includePublicFunctions = false;    // reset the flag
            _includeDatabaseTables  = false;
            _contextString          = null;
            return(members);
        }
示例#20
0
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
 {
     definingProject = null;
     projEntry       = null;
     return(null);
 }
示例#21
0
 public bool HasChildFunctions(Genero4glAst ast)
 {
     return(Type.HasChildFunctions(ast));
 }
示例#22
0
 public bool HasChildFunctions(Genero4glAst ast)
 {
     return(MemberDictionary.Values.Any(x => x.Type.HasChildFunctions(ast)));
 }
示例#23
0
        public static IAnalysisResult GetValueByIndex(string exprText, int index, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projectEntry, out bool isDeferredFunction,
                                                      FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch, bool isFunctionCallOrDefinition = false,
                                                      bool getTypes = true, bool getVariables = true, bool getConstants = true)
        {
            isDeferredFunction = false;
            definingProject    = null;
            projectEntry       = null;
            //_functionProvider = functionProvider;
            //_databaseProvider = databaseProvider;
            //_programFileProvider = programFileProvider;

            AstNode containingNode = null;

            if (ast != null)
            {
                containingNode = GetContainingNode(ast.Body, index);
                ast.Body.SetNamespace(null);
            }

            IAnalysisResult res = null;
            int             tmpIndex = 0;
            int             bracketDepth = 0;
            bool            doSearch = false;
            bool            resetStartIndex = false;
            int             startIndex = 0, endIndex = 0;
            bool            noEndIndexSet = false;

            if (exprText == null)
            {
                return(null);
            }

            while (tmpIndex < exprText.Length)
            {
                if (resetStartIndex)
                {
                    startIndex      = tmpIndex;
                    resetStartIndex = false;
                    if (startIndex + 1 > exprText.Length)
                    {
                        break;
                    }
                }

                doSearch = false;
                switch (exprText[tmpIndex])
                {
                case '.':
                {
                    if (bracketDepth == 0)
                    {
                        endIndex = tmpIndex - 1;
                        if (endIndex >= startIndex)
                        {
                            // we have our 'piece'
                            doSearch = true;
                        }
                        if (exprText[startIndex] == '.')
                        {
                            startIndex++;
                        }
                    }
                    tmpIndex++;
                }
                break;

                case '[':
                    if (noEndIndexSet)
                    {
                        noEndIndexSet = false;
                    }
                    else
                    {
                        if (bracketDepth == 0)
                        {
                            endIndex = tmpIndex - 1;
                        }
                    }
                    bracketDepth++;
                    tmpIndex++;
                    break;

                case ']':
                {
                    bracketDepth--;
                    if (bracketDepth == 0)
                    {
                        if (exprText.Length <= tmpIndex + 1 ||
                            exprText[tmpIndex + 1] != '[')
                        {
                            // we have our first 'piece'
                            doSearch = true;
                        }
                        else
                        {
                            noEndIndexSet = true;
                        }
                    }
                    tmpIndex++;
                }
                break;

                default:
                {
                    if (bracketDepth == 0 && (tmpIndex + 1 == exprText.Length))
                    {
                        endIndex = tmpIndex;
                        doSearch = true;
                    }
                    tmpIndex++;
                }
                break;
                }

                if (!doSearch)
                {
                    continue;
                }

                // we can do our search
                var dotPiece = exprText.Substring(startIndex, (endIndex - startIndex) + 1);
                if (dotPiece.Contains('('))
                {
                    // remove the params piece
                    int remIndex = dotPiece.IndexOf('(');
                    dotPiece = dotPiece.Substring(0, remIndex);
                }

                bool lookForFunctions = isFunctionCallOrDefinition && (endIndex + 1 == exprText.Length);

                resetStartIndex = true;

                if (res != null)
                {
                    if (ast != null)
                    {
                        var gmi = new GetMemberInput
                        {
                            Name       = dotPiece,
                            AST        = ast,
                            IsFunction = lookForFunctions
                        };
                        IAnalysisResult tempRes = res.GetMember(gmi);
                        if (gmi.DefiningProject != null && definingProject != gmi.DefiningProject)
                        {
                            definingProject = gmi.DefiningProject;
                        }
                        if (gmi.ProjectEntry != null && projectEntry != gmi.ProjectEntry)
                        {
                            projectEntry = gmi.ProjectEntry;
                        }
                        res = tempRes;
                        if (tempRes == null)
                        {
                            res = null;
                            break;
                        }
                    }
                    else
                    {
                        res = null;
                        break;
                    }
                }
                else
                {
                    IFunctionResult funcRes;
                    if (!lookForFunctions)
                    {
                        if (SystemVariables.TryGetValue(dotPiece, out res) ||
                            SystemConstants.TryGetValue(dotPiece, out res) ||
                            SystemMacros.TryGetValue(dotPiece, out res))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (SystemFunctions.TryGetValue(dotPiece, out funcRes))
                        {
                            res = funcRes;
                            continue;
                        }

                        if (ast != null && ast._functionProvider != null && ast._functionProvider.Name.Equals(dotPiece, StringComparison.OrdinalIgnoreCase))
                        {
                            res = ast._functionProvider;
                            continue;
                        }
                    }

                    if (containingNode != null && containingNode is IFunctionResult)
                    {
                        IFunctionResult func = containingNode as IFunctionResult;
                        if ((getVariables && func.Variables.TryGetValue(dotPiece, out res)))
                        {
                            continue;
                        }
                        if (!lookForFunctions)
                        {
                            // Check for local vars, types, and constants
                            if ((getTypes && func.Types.TryGetValue(dotPiece, out res)) ||
                                (getConstants && func.Constants.TryGetValue(dotPiece, out res)))
                            {
                                continue;
                            }

                            List <Tuple <IAnalysisResult, IndexSpan> > limitedScopeVars;
                            if ((getVariables && func.LimitedScopeVariables.TryGetValue(dotPiece, out limitedScopeVars)))
                            {
                                foreach (var item in limitedScopeVars)
                                {
                                    if (item.Item2.IsInSpan(index))
                                    {
                                        res = item.Item1;

                                        break;
                                    }
                                }
                                if (res != null)
                                {
                                    continue;
                                }
                            }
                        }
                    }

                    if (ast != null && ast.Body is IModuleResult)
                    {
                        IModuleResult mod = ast.Body as IModuleResult;
                        if (!lookForFunctions)
                        {
                            // check for module vars, types, and constants (and globals defined in this module)
                            if ((getVariables && (mod.Variables.TryGetValue(dotPiece, out res) || mod.GlobalVariables.TryGetValue(dotPiece, out res))) ||
                                (getTypes && (mod.Types.TryGetValue(dotPiece, out res) || mod.GlobalTypes.TryGetValue(dotPiece, out res))) ||
                                (getConstants && (mod.Constants.TryGetValue(dotPiece, out res) || mod.GlobalConstants.TryGetValue(dotPiece, out res))))
                            {
                                continue;
                            }

                            // check for cursors in this module
                            if (mod.Cursors.TryGetValue(dotPiece, out res))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            // check for module functions
                            if (mod.Functions.TryGetValue(dotPiece, out funcRes))
                            {
                                // check for any function info collected at the project entry level, and update the function's documentation with that.
                                if (ast._projEntry != null && ast._projEntry is IGeneroProjectEntry)
                                {
                                    var commentInfo = (ast._projEntry as IGeneroProjectEntry).GetFunctionInfo(funcRes.Name);
                                    if (commentInfo != null)
                                    {
                                        funcRes.SetCommentDocumentation(commentInfo);
                                    }
                                }
                                res = funcRes;
                                continue;
                            }
                        }
                    }

                    // TODO: this could probably be done more efficiently by having each GeneroAst load globals and functions into
                    // dictionaries stored on the IGeneroProject, instead of in each project entry.
                    // However, this does required more upkeep when changes occur. Will look into it...
                    if (ast != null && ast.ProjectEntry != null && ast.ProjectEntry is IGeneroProjectEntry)
                    {
                        IGeneroProjectEntry genProj = ast.ProjectEntry as IGeneroProjectEntry;
                        if (genProj.ParentProject != null &&
                            !genProj.FilePath.ToLower().EndsWith(".inc"))
                        {
                            bool found = false;
                            foreach (var projEntry in genProj.ParentProject.ProjectEntries.Where(x => x.Value != genProj))
                            {
                                if (projEntry.Value.Analysis != null &&
                                    projEntry.Value.Analysis.Body != null)
                                {
                                    projEntry.Value.Analysis.Body.SetNamespace(null);
                                    IModuleResult modRes = projEntry.Value.Analysis.Body as IModuleResult;
                                    if (modRes != null)
                                    {
                                        if (!lookForFunctions)
                                        {
                                            // check global vars, types, and constants
                                            // TODO: need option to enable/disable legacy linking
                                            if ((getVariables && (modRes.Variables.TryGetValue(dotPiece, out res) || modRes.GlobalVariables.TryGetValue(dotPiece, out res))) ||
                                                (getTypes && (modRes.Types.TryGetValue(dotPiece, out res) || modRes.GlobalTypes.TryGetValue(dotPiece, out res))) ||
                                                (getConstants && (modRes.Constants.TryGetValue(dotPiece, out res) || modRes.GlobalConstants.TryGetValue(dotPiece, out res))))
                                            {
                                                found = true;
                                                break;
                                            }

                                            // check for cursors in this module
                                            if (modRes.Cursors.TryGetValue(dotPiece, out res))
                                            {
                                                found = true;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            // check project functions
                                            if (modRes.Functions.TryGetValue(dotPiece, out funcRes))
                                            {
                                                if (funcRes.AccessModifier == AccessModifier.Public)
                                                {
                                                    res   = funcRes;
                                                    found = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (found)
                            {
                                continue;
                            }
                        }
                    }

                    // check for classes
                    GeneroPackage package;
                    if (Packages.TryGetValue(dotPiece, out package))
                    {
                        res = package;
                        continue;
                    }

                    /* TODO:
                     * Need to check for:
                     * 1) Temp tables
                     */

                    // Nothing found yet...
                    // If our containing node is at the function or globals level, we need to go deeper
                    if (containingNode != null &&
                        (containingNode is GlobalsNode ||
                         containingNode is FunctionBlockNode ||
                         containingNode is ReportBlockNode))
                    {
                        containingNode = GetContainingNode(containingNode, index);
                    }
                    // check for record field
                    if (containingNode != null &&
                        (containingNode is DefineNode ||
                         containingNode is TypeDefNode))
                    {
                        containingNode = GetContainingNode(containingNode, index);

                        if (containingNode != null &&
                            (containingNode is VariableDefinitionNode ||
                             containingNode is TypeDefinitionNode) &&
                            containingNode.Children.Count == 1 &&
                            containingNode.Children[containingNode.Children.Keys[0]] is TypeReference)
                        {
                            var typeRef = containingNode.Children[containingNode.Children.Keys[0]] as TypeReference;
                            while (typeRef != null &&
                                   typeRef.Children.Count == 1)
                            {
                                if (typeRef.Children[typeRef.Children.Keys[0]] is RecordDefinitionNode)
                                {
                                    var         recNode = typeRef.Children[typeRef.Children.Keys[0]] as RecordDefinitionNode;
                                    VariableDef recField;
                                    if (recNode.MemberDictionary.TryGetValue(exprText, out recField))
                                    {
                                        res = recField;
                                        break;
                                    }
                                    else
                                    {
                                        recField = recNode.MemberDictionary.Where(x => x.Value.LocationIndex < index)
                                                   .OrderByDescending(x => x.Value.LocationIndex)
                                                   .Select(x => x.Value)
                                                   .FirstOrDefault();
                                        if (recField != null)
                                        {
                                            typeRef = recField.Type;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                                else if (typeRef.Children[typeRef.Children.Keys[0]] is TypeReference)
                                {
                                    typeRef = typeRef.Children[typeRef.Children.Keys[0]] as TypeReference;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }

                    // try an imported module
                    if (ast != null && ast.Body is IModuleResult &&
                        ast.ProjectEntry != null && ast.ProjectEntry != null)
                    {
                        if ((ast.Body as IModuleResult).FglImports.Contains(dotPiece))
                        {
                            // need to get the ast for the other project entry
                            var refProjKVP = (ast.ProjectEntry as IGeneroProjectEntry).ParentProject.ReferencedProjects.Values.FirstOrDefault(
                                x =>
                            {
                                var fn = Path.GetFileNameWithoutExtension(x.Directory);
                                return(fn?.Equals(dotPiece, StringComparison.OrdinalIgnoreCase) ?? false);
                            });
                            if (refProjKVP is IAnalysisResult)
                            {
                                definingProject = refProjKVP;
                                res             = refProjKVP as IAnalysisResult;
                                continue;
                            }

                            IAnalysisResult sysImportMod;
                            // check the system imports
                            if (SystemImportModules.TryGetValue(dotPiece, out sysImportMod))
                            {
                                res = sysImportMod;
                                continue;
                            }
                        }
                    }

                    if (!lookForFunctions)
                    {
                        // try include files
                        var foundInclude = false;
                        if (ast?.ProjectEntry != null)
                        {
                            foreach (var includeFile in ast.ProjectEntry.GetIncludedFiles())
                            {
                                if (includeFile.Analysis?.Body is IModuleResult)
                                {
                                    var mod = includeFile.Analysis.Body as IModuleResult;
                                    if ((getTypes && (mod.Types.TryGetValue(dotPiece, out res) || mod.GlobalTypes.TryGetValue(dotPiece, out res))) ||
                                        (getConstants && (mod.Constants.TryGetValue(dotPiece, out res) || mod.GlobalConstants.TryGetValue(dotPiece, out res))))
                                    {
                                        foundInclude = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (foundInclude)
                        {
                            continue;
                        }

                        if (ast?._databaseProvider != null)
                        {
                            res = ast._databaseProvider.GetTable(dotPiece);
                            if (res != null)
                            {
                                continue;
                            }
                        }
                    }

                    // Only do a public function search if the dotPiece is the whole text we're searching for
                    // I.e. no namespaces
                    if (lookForFunctions && dotPiece == exprText)
                    {
                        if (searchInFunctionProvider == FunctionProviderSearchMode.Search)
                        {
                            if (res == null && ast?._functionProvider != null)
                            {
                                // check for the function name in the function provider
                                var funcs = ast._functionProvider.GetFunction(dotPiece);
                                if (funcs != null)
                                {
                                    res = funcs.FirstOrDefault();
                                    if (res != null)
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                        else if (searchInFunctionProvider == FunctionProviderSearchMode.Deferred)
                        {
                            isDeferredFunction = true;
                        }
                    }

                    if (res == null)
                    {
                        break;
                    }
                }
            }

            return(res);
        }
示例#24
0
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projEntry, bool function)
 {
     return(Type.GetMember(name, ast, out definingProject, out projEntry, function));
 }
示例#25
0
 public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
 {
     return(this.Children.Values.Cast <CreatedTableColumn>().Select(x => new MemberResult(x.ColumnName.Name, x, GeneroMemberType.DbColumn, SyntaxTree)));
 }
示例#26
0
 public IAnalysisResult GetMember(string name, Genero4glAst ast, out IGeneroProject definingProject, out IProjectEntry projectEntry, bool function)
 {
     definingProject = null;
     projectEntry    = null;
     return(this.Children.Values.Cast <CreatedTableColumn>().FirstOrDefault(x => x.ColumnName.Name.Equals(name, StringComparison.OrdinalIgnoreCase)));
 }
示例#27
0
 public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
 {
     return(null);
 }
示例#28
0
 public bool HasChildFunctions(Genero4glAst ast)
 {
     return(_memberFunctions.Count > 0);
 }
示例#29
0
 public bool HasChildFunctions(Genero4glAst ast)
 {
     return(false);
 }
示例#30
0
        public IEnumerable <MemberResult> GetMembers(Genero4glAst ast, MemberType memberType, bool function)
        {
            bool dummyDef;
            List <MemberResult> members = new List <MemberResult>();

            if (Children.Count == 1)
            {
                // we have an array type or a record type definition
                var node = Children[Children.Keys[0]];
                if (node is ArrayTypeReference)
                {
                    return((node as ArrayTypeReference).GetMembersInternal(ast, memberType, function));
                }
                else if (node is RecordDefinitionNode)
                {
                    return((node as RecordDefinitionNode).GetMembers(ast, memberType, function));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(TableName))
                {
                    // TODO: return the table's columns
                }
                else if (_typeNameString.Equals("string", StringComparison.OrdinalIgnoreCase))
                {
                    return(Genero4glAst.StringFunctions.Values.Select(x => new MemberResult(x.Name, x, GeneroMemberType.Method, ast)));
                }
                else if (_typeNameString.Equals("text", StringComparison.OrdinalIgnoreCase))
                {
                    return(Genero4glAst.TextFunctions.Values.Select(x => new MemberResult(x.Name, x, GeneroMemberType.Method, ast)));
                }
                else if (_typeNameString.Equals("byte", StringComparison.OrdinalIgnoreCase))
                {
                    return(Genero4glAst.ByteFunctions.Values.Select(x => new MemberResult(x.Name, x, GeneroMemberType.Method, ast)));
                }
                else
                {
                    // try to determine if the _typeNameString is a user defined type (or package class), in which case we need to call its GetMembers function
                    IAnalysisResult udt = ast.TryGetUserDefinedType(_typeNameString, LocationIndex);
                    if (udt != null)
                    {
                        return(udt.GetMembers(ast, memberType, function));
                    }

                    foreach (var includedFile in ast.ProjectEntry.GetIncludedFiles())
                    {
                        if (includedFile.Analysis != null)
                        {
                            IGeneroProject dummyProj;
                            IProjectEntry  dummyProjEntry;
                            var            res = includedFile.Analysis.GetValueByIndex(_typeNameString, 1, null, null, null, false, out dummyDef, out dummyProj, out dummyProjEntry);
                            if (res != null)
                            {
                                return(res.GetMembers(ast, memberType, function));
                            }
                        }
                    }

                    if (ast.ProjectEntry.ParentProject.ReferencedProjects.Count > 0)
                    {
                        foreach (var refProj in ast.ProjectEntry.ParentProject.ReferencedProjects.Values)
                        {
                            if (refProj is GeneroProject)
                            {
                                IProjectEntry dummyProj;
                                udt = (refProj as GeneroProject).GetMemberOfType(_typeNameString, ast, false, true, false, false, out dummyProj);
                                if (udt != null)
                                {
                                    return(udt.GetMembers(ast, memberType, function));
                                }
                            }
                        }
                    }

                    // check for package class
                    IGeneroProject dummyProject;
                    IProjectEntry  projEntry;
                    udt = ast.GetValueByIndex(_typeNameString, LocationIndex, ast._functionProvider, ast._databaseProvider, ast._programFileProvider, false, out dummyDef, out dummyProject, out projEntry);
                    if (udt != null)
                    {
                        return(udt.GetMembers(ast, memberType, function));
                    }
                }
            }
            return(members);
        }