Ejemplo n.º 1
0
            public CodeSource GetSource(ProbeAppSettings appSettings)
            {
                if (_source == null)
                {
                    try
                    {
                        var merger = new FileMerger();
                        merger.MergeFile(appSettings, _fullPathName, null, false, false);
                        _source = merger.MergedContent;

                        var fileInfo = new FileInfo(_fullPathName);
                        _lastModifiedDate = fileInfo.LastWriteTime;
                        _lastCheck        = DateTime.Now;

                        foreach (var mergeFileName in merger.FileNames)
                        {
                            var content = merger.GetFileContent(mergeFileName);
                            if (content == null)
                            {
                                throw new InvalidOperationException("Merger content is null.");
                            }
                            _preMergeContent[mergeFileName.ToLower()] = content;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "Exception when attempting to read content of include file '{0}'.", _fullPathName);
                        _source = null;
                    }
                }
                return(_source);
            }
Ejemplo n.º 2
0
        public CodeModel CreatePreprocessedModel(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot, bool visible, string reason)
        {
            CodeSource source;
            IEnumerable <Preprocessor.IncludeDependency> includeDependencies = null;

            if (visible)
            {
                source = new CodeSource();
                source.Append(snapshot.GetText(), fileName, 0, snapshot.Length, true, true, false);
                source.Flush();
            }
            else
            {
                var merger = new FileMerger();
                merger.MergeFile(appSettings, fileName, snapshot.GetText(), false, true);
                source = merger.MergedContent;

                includeDependencies = (from f in merger.FileNames
                                       select new Preprocessor.IncludeDependency(f, false, true, merger.GetFileContent(f))).ToArray();
            }

            var model = CreatePreprocessedModel(appSettings, source, fileName, visible, reason, includeDependencies);

            model.Snapshot = snapshot;
            return(model);
        }
Ejemplo n.º 3
0
            private static CodeModel.CodeSource GetCodeSourceForActiveView(out string fileName)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                var view = Shell.ActiveView;

                if (view != null)
                {
                    fileName = VsTextUtil.TryGetDocumentFileName(view.TextBuffer);
                    var content = view.TextBuffer.CurrentSnapshot.GetText();

                    try
                    {
                        var merger = new CodeModel.FileMerger();
                        merger.MergeFile(ProbeEnvironment.CurrentAppSettings, fileName, content, true, true);
                        return(merger.MergedContent);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteEx(ex);

                        var codeSource = new CodeModel.CodeSource();
                        codeSource.Append(content, new CodeModel.CodeAttributes(fileName, 0, content.Length, true, true, false));
                        codeSource.Flush();

                        return(codeSource);
                    }
                }

                fileName = null;
                return(null);
            }
Ejemplo n.º 4
0
        public Definition[] GetIncludeParentDefinitions(ProbeAppSettings appSettings, string includePathName)
        {
            Definition[] cachedDefs;
            if (_includeParentDefs.TryGetValue(includePathName.ToLower(), out cachedDefs))
            {
                return(cachedDefs);
            }

            Log.Debug("Getting include file parent definitions: {0}", includePathName);

            IEnumerable <string> parentFileNames;

            using (var searcher = ProbeToolsPackage.Instance.FunctionFileScanner.CurrentApp.CreateSearcher())
            {
                parentFileNames = searcher.GetIncludeParentFiles(includePathName, 3);                   // TODO: make limit configurable
            }

            Definition[] commonDefines = null;

            if (!parentFileNames.Any())
            {
                Log.Debug("This file is not included by any other file.");
                commonDefines = new Definition[0];
                _includeParentDefs[includePathName.ToLower()] = commonDefines;
                return(commonDefines);
            }

            foreach (var parentPathName in parentFileNames)
            {
                Log.Debug("Preprocessing include parent: {0}", parentPathName);

                var merger = new FileMerger();
                merger.MergeFile(appSettings, parentPathName, null, false, true);
                var source = merger.MergedContent;

                var reader     = new CodeSource.CodeSourcePreprocessorReader(source);
                var prepSource = new CodeSource();

                var fileContext = FileContextUtil.GetFileContextFromFileName(parentPathName);
                var prep        = new Preprocessor(appSettings, this);
                var prepResult  = prep.Preprocess(reader, prepSource, parentPathName, new string[0], fileContext, includePathName);
                if (!prepResult.IncludeFileReached)
                {
                    Log.Warning("Include file not reached when preprocessing parent.\r\nInclude File: {0}\r\nParent File: {1}",
                                includePathName, parentPathName);
                    continue;
                }

                var defs = prep.ActiveDefineDefinitions;
                if (!defs.Any())
                {
                    // No defines will be common
                    Log.Debug("No definitions found in include parent file: {0}", parentPathName);
                    commonDefines = new Definition[0];
                    break;
                }

                if (commonDefines == null)
                {
                    commonDefines = defs.ToArray();
                    Log.Debug("{1} definition(s) found in include parent file: {0}", parentPathName, commonDefines.Length);
                }
                else
                {
                    // Create array of defines common to all
                    commonDefines = (from c in commonDefines where defs.Any(d => d.Name == c.Name) select c).ToArray();
                    Log.Debug("{1} definition(s) found in include parent file: {0}", parentPathName, commonDefines.Length);
                    if (commonDefines.Length == 0)
                    {
                        break;
                    }
                }
            }

            if (commonDefines == null)
            {
                commonDefines = new Definition[0];
            }
            Log.Debug("Using {0} definition(s) from include parent files.", commonDefines.Length);
            _includeParentDefs[includePathName.ToLower()] = commonDefines;
            return(commonDefines);
        }