Пример #1
0
        public override string GetExpressionType(GeneroAst ast)
        {
            // need to determine the return type for the function call
            IGeneroProject dummyProj;
            IProjectEntry  dummyProjEntry;
            bool           dummy;
            var            result = ast.GetValueByIndex(Function.Name,
                                                        Function.IndexSpan.Start,
                                                        ast._functionProvider,
                                                        ast._databaseProvider,
                                                        ast._programFileProvider,
                                                        true,
                                                        out dummy,
                                                        out dummyProj,
                                                        out dummyProjEntry,
                                                        FunctionProviderSearchMode.Search);

            if (result != null)
            {
                return(result.Typename);
            }
            return(null);
        }
Пример #2
0
        public override void CheckForErrors(GeneroAst ast, Action <string, int, int> errorFunc,
                                            Dictionary <string, List <int> > deferredFunctionSearches,
                                            FunctionProviderSearchMode searchInFunctionProvider = FunctionProviderSearchMode.NoSearch,
                                            bool isFunctionCallOrDefinition = false)
        {
            // Check to see if the _firstPiece exists
            IGeneroProject proj;
            IProjectEntry  projEntry;
            string         searchStr = _firstPiece;

            if (searchInFunctionProvider != FunctionProviderSearchMode.NoSearch ||
                isFunctionCallOrDefinition)
            {
                StringBuilder sb = new StringBuilder(searchStr);
                foreach (var child in Children.Values)
                {
                    if (child is ArrayIndexFglNameExpressionPiece)
                    {
                        sb.Append(child.ToString());
                    }
                    else if (child is MemberAccessNameExpressionPiece)
                    {
                        if ((child as MemberAccessNameExpressionPiece).Text != ".*")
                        {
                            sb.Append(child.ToString());
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                searchStr = sb.ToString();
            }

            bool isDeferred;
            // TODO: need to defer database lookups too
            var res = ast.GetValueByIndex(searchStr,
                                          StartIndex,
                                          ast._functionProvider,
                                          ast._databaseProvider,
                                          ast._programFileProvider,
                                          isFunctionCallOrDefinition,
                                          out isDeferred,
                                          out proj,
                                          out projEntry,
                                          searchInFunctionProvider);

            if (res == null)
            {
                if (isDeferred)
                {
                    if (deferredFunctionSearches.ContainsKey(searchStr))
                    {
                        deferredFunctionSearches[searchStr].Add(StartIndex);
                    }
                    else
                    {
                        deferredFunctionSearches.Add(searchStr, new List <int> {
                            StartIndex
                        });
                    }
                }
                else
                {
                    errorFunc(string.Format("No definition found for {0}", searchStr), StartIndex, StartIndex + searchStr.Length);
                }
            }
            else
            {
                if (Name.EndsWith(".*") && res is VariableDef && (res as VariableDef).ResolvedType == null)
                {
                    // need to make sure that the res has a resolved type
                    (res as VariableDef).Type.CheckForErrors(ast, errorFunc, deferredFunctionSearches);
                    (res as VariableDef).ResolvedType = (res as VariableDef).Type.ResolvedType;
                }
                // TODO: need to check array element type
                ResolvedResult = res;
            }

            base.CheckForErrors(ast, errorFunc, deferredFunctionSearches, searchInFunctionProvider, isFunctionCallOrDefinition);
        }