示例#1
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);
        }
示例#2
0
        internal IEnumerable <IAnalysisResult> GetAnalysisMembers(MemberType memberType, GetMemberInput input)
        {
            bool dummyDef;
            List <IAnalysisResult> members = new List <IAnalysisResult>();

            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).GetAnalysisResults(memberType, input));
                }
                else if (node is RecordDefinitionNode)
                {
                    return((node as RecordDefinitionNode).GetAnalysisResults(input.AST));
                }
                else if (node is DictionaryDefinitionNode)
                {
                    return((node as DictionaryDefinitionNode).GetAnalysisResults(memberType, input));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(TableName))
                {
                    // TODO: return the table's columns
                    int i = 0;
                }
                else if (_typeNameString != null && _typeNameString.Equals("string", StringComparison.OrdinalIgnoreCase))
                {
                    return(Genero4glAst.StringFunctions.Values.Where(x => input.AST.LanguageVersion >= x.MinimumLanguageVersion && input.AST.LanguageVersion <= x.MaximumLanguageVersion));
                }
                else if (_typeNameString != null && _typeNameString.Equals("text", StringComparison.OrdinalIgnoreCase))
                {
                    return(Genero4glAst.TextFunctions.Values.Where(x => input.AST.LanguageVersion >= x.MinimumLanguageVersion && input.AST.LanguageVersion <= x.MaximumLanguageVersion));
                }
                else if (_typeNameString != null && _typeNameString.Equals("byte", StringComparison.OrdinalIgnoreCase))
                {
                    return(Genero4glAst.ByteFunctions.Values.Where(x => input.AST.LanguageVersion >= x.MinimumLanguageVersion && input.AST.LanguageVersion <= x.MaximumLanguageVersion));
                }
                else
                {
                    if (ResolvedType != null &&
                        ResolvedType is TypeDefinitionNode &&
                        (ResolvedType as TypeDefinitionNode).TypeRef != null)
                    {
                        return((ResolvedType as TypeDefinitionNode).TypeRef.GetAnalysisMembers(memberType, input));
                    }

                    var gmi = new GetMultipleMembersInput
                    {
                        AST                 = input.AST,
                        MemberType          = memberType,
                        GetArrayTypeMembers = input.IsFunction
                    };

                    // try to determine if the _typeNameString is a user defined type, in which case we need to call its GetMembers function
                    IAnalysisResult udt = (input.AST as Genero4glAst).TryGetUserDefinedType(_typeNameString, LocationIndex);
                    if (udt != null)
                    {
                        return(udt.GetMembers(gmi).Select(x => x.Var).Where(y => y != null));
                    }

                    IGeneroProject definingProject;
                    IProjectEntry  projectEntry;
                    if (input.AST.ProjectEntry != null)
                    {
                        foreach (var includedFile in input.AST.ProjectEntry.GetIncludedFiles())
                        {
                            if (includedFile.Analysis != null)
                            {
                                var res = includedFile.Analysis.GetValueByIndex(_typeNameString, 1, null, null, null, false, out dummyDef, out definingProject, out projectEntry);
                                if (res != null)
                                {
                                    input.DefiningProject = definingProject;
                                    input.ProjectEntry    = projectEntry;
                                    return(res.GetMembers(gmi).Select(x => x.Var).Where(y => y != null));
                                }
                            }
                        }

                        // try to get the _typeNameString from types available in imported modules
                        if (input.AST.ProjectEntry.ParentProject.ReferencedProjects.Count > 0)
                        {
                            foreach (var refProj in input.AST.ProjectEntry.ParentProject.ReferencedProjects.Values)
                            {
                                if (refProj is GeneroProject)
                                {
                                    IProjectEntry dummyProj;
                                    udt = (refProj as GeneroProject).GetMemberOfType(_typeNameString, input.AST, false, true, false, false, out dummyProj);
                                    if (udt != null)
                                    {
                                        input.DefiningProject = refProj;
                                        input.ProjectEntry    = dummyProj;
                                        return(udt.GetMembers(gmi).Select(x => x.Var).Where(y => y != null));
                                    }
                                }
                            }
                        }
                    }


                    // check for package class
                    udt = input.AST.GetValueByIndex(_typeNameString, LocationIndex, input.AST._functionProvider, input.AST._databaseProvider, input.AST._programFileProvider, false, out dummyDef, out definingProject, out projectEntry);
                    if (udt != null)
                    {
                        input.DefiningProject = definingProject;
                        input.ProjectEntry    = projectEntry;
                        return(udt.GetMembers(gmi).Select(x => x.Var).Where(y => y != null));
                    }
                }
            }
            return(members);
        }