Exemple #1
0
        public IEnumerable <FunctionDefinition> SearchForFunctionDefinitions(string funcName)
        {
            if (_db == null)
            {
                yield break;
            }

            using (var cmd = _db.CreateCommand(@"
				select file_.file_name, func.*, alt_file.file_name as alt_file_name from func
				inner join file_ on file_.rowid = func.file_id
				left outer join alt_file on alt_file.rowid = func.alt_file_id
				where func.app_id = @app_id
				and func.name = @func_name
				"                ))
            {
                cmd.Parameters.AddWithValue("@app_id", _app.Id);
                cmd.Parameters.AddWithValue("@func_name", funcName);
                using (var rdr = cmd.ExecuteReader())
                {
                    var ordFileName = rdr.GetOrdinal("file_name");

                    while (rdr.Read())
                    {
                        yield return(FFFunction.CreateFunctionDefinitionFromSqlReader(rdr, rdr.GetString(ordFileName)));
                    }
                }
            }
        }
Exemple #2
0
        public void UpdateFromModel(CodeModel.CodeModel model, FFDatabase db, FileStore store, DateTime fileModified, FFScanMode scanMode)
        {
            if (scanMode == FFScanMode.Deep)
            {
                _modified = fileModified;
            }
            else
            {
                _modified = Constants.ZeroDate;
            }
            UpdateVisibility();
            InsertOrUpdate(db, store, model);

            // Only extract functions for .f files or class files.
            switch (_context)
            {
            case CodeModel.FileContext.Function:
            case CodeModel.FileContext.ClientClass:
            case CodeModel.FileContext.ServerClass:
            case CodeModel.FileContext.NeutralClass:

                // Get the list of functions defined in the file.
                var modelFuncs = (from f in model.DefinitionProvider.GetGlobalFromFile <CodeModel.Definitions.FunctionDefinition>()
                                  where f.Extern == false
                                  select f).ToArray();

                // Insert/update the functions that exist in the model.
                foreach (var modelFunc in modelFuncs)
                {
                    var func = _functions.FirstOrDefault(f => f.Name == modelFunc.Name);
                    if (func != null)
                    {
                        func.UpdateFromDefinition(modelFunc);
                    }
                    else
                    {
                        func = new FFFunction(_app, this, _class, modelFunc);
                        _functions.Add(func);
                    }

                    func.InsertOrUpdate(db);
                }

                // Purge functions that no longer exist in the model.
                var removeFuncs = (from f in _functions where !modelFuncs.Any(m => m.Name == f.Name) select f).ToArray();
                foreach (var removeFunc in removeFuncs)
                {
                    removeFunc.Remove(db);
                    _functions.Remove(removeFunc);
                }

                break;
            }

            // Get all permanent extracts in the file
            UpdatePermExList(db, model.File.FindDownward <CodeModel.Tokens.Statements.ExtractStatement>().Where(x => x.IsPermanent).ToArray());

            if (scanMode == FFScanMode.Deep)
            {
                // Get all references in the file.
                var refList = new List <Reference>();
                foreach (var token in model.File.FindDownward(t => t.SourceDefinition != null &&
                                                              !string.IsNullOrEmpty(t.SourceDefinition.ExternalRefId) &&
                                                              t.File != null))
                {
                    var localPos = token.File.CodeSource.GetFilePosition(token.Span.Start);

                    var def   = token.SourceDefinition;
                    var refId = def.ExternalRefId;
                    if (!string.IsNullOrEmpty(refId))
                    {
                        refList.Add(new Reference
                        {
                            ExternalRefId = refId,
                            TrueFileName  = string.Equals(localPos.FileName, model.FileName, StringComparison.OrdinalIgnoreCase) ? null : localPos.FileName,
                            Position      = localPos.Position
                        });
                    }
                }

                foreach (var rf in model.PreprocessorReferences)
                {
                    var def   = rf.Definition;
                    var refId = def.ExternalRefId;
                    if (!string.IsNullOrEmpty(refId))
                    {
                        var filePos = rf.FilePosition;
                        if (filePos.PrimaryFile)
                        {
                            refList.Add(new Reference
                            {
                                ExternalRefId = refId,
                                TrueFileName  = filePos.FileName,
                                Position      = filePos.Position
                            });
                        }
                    }
                }

                UpdateRefList(db, refList);
            }
        }