コード例 #1
0
ファイル: PreprocessorModel.cs プロジェクト: cmrazek/DkTools
        public PreprocessorModel(CodeSource source, DefinitionProvider defProv, string fileName, bool visible, IEnumerable <Preprocessor.IncludeDependency> includeDependencies)
        {
#if DEBUG
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (defProv == null)
            {
                throw new ArgumentNullException("defProv");
            }
#endif
            _source   = source;
            _code     = new CodeParser(source.Text);
            _defProv  = defProv;
            _fileName = fileName;
            FunctionFileScanning.FFUtil.FileNameIsClass(_fileName, out _className);
            _fileContext = FileContextUtil.GetFileContextFromFileName(fileName);
            _visible     = visible;

            if (includeDependencies != null)
            {
                _includeDependencies = includeDependencies.ToArray();
            }
            else
            {
                _includeDependencies = new Preprocessor.IncludeDependency[0];
            }

            Parse();
        }
コード例 #2
0
ファイル: CodeModel.cs プロジェクト: cmrazek/DkTools
        private void Init(CodeSource source, CodeFile file, string fileName, bool visible, DefinitionProvider defProvider)
        {
#if DEBUG
            if (defProvider == null)
            {
                throw new ArgumentNullException("defProvider");
            }
#endif
            this.RefreshTime = DateTime.Now;

            _fileName = fileName;
            if (!string.IsNullOrEmpty(_fileName))
            {
                _fileTitle = Path.GetFileNameWithoutExtension(_fileName);
            }

            _fileContext = FileContextUtil.GetFileContextFromFileName(_fileName);

            if (FunctionFileScanning.FFUtil.FileNameIsFunction(fileName))
            {
                _modelType = ModelType.Function;
            }
            else if (FunctionFileScanning.FFUtil.FileNameIsClass(fileName, out _className))
            {
                _modelType = DkTools.CodeModel.ModelType.Class;
            }
            else
            {
                _modelType = DkTools.CodeModel.ModelType.Other;
            }

            _defProvider = defProvider;
            _file        = new CodeFile(this);

            _file.Parse(source, _fileName, new string[0], visible);

            this.RefreshTime = DateTime.Now;
        }
コード例 #3
0
ファイル: FileStore.cs プロジェクト: cmrazek/DkTools
        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);
        }
コード例 #4
0
ファイル: FileStore.cs プロジェクト: cmrazek/DkTools
        public CodeModel CreatePreprocessedModel(ProbeAppSettings appSettings, CodeSource source, string fileName,
                                                 bool visible, string reason, IEnumerable <Preprocessor.IncludeDependency> includeDependencies)
        {
#if DEBUG
            Log.Debug("Creating preprocessed model. Reason: {0}", reason);
            var startTime = DateTime.Now;
#endif

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

            var defProvider = new DefinitionProvider(appSettings, fileName);

            var fileContext = FileContextUtil.GetFileContextFromFileName(fileName);
            var prep        = new Preprocessor(appSettings, this);
            if (includeDependencies != null)
            {
                prep.AddIncludeDependencies(includeDependencies);
            }
            prep.Preprocess(reader, prepSource, fileName, new string[0], fileContext, stdlibDefines: _stdLibDefines);
            prep.AddDefinitionsToProvider(defProvider);

            if (fileContext == FileContext.Include && !string.IsNullOrEmpty(fileName))
            {
                var includeParentDefs = GetIncludeParentDefinitions(appSettings, fileName);
                defProvider.AddGlobalFromFile(includeParentDefs);
            }

#if DEBUG
            var midTime1 = DateTime.Now;
#endif

            var prepModel = new PreprocessorModel(prepSource, defProvider, fileName, visible, prep.IncludeDependencies)
            {
                Preprocessor = prep
            };

#if DEBUG
            var midTime2 = DateTime.Now;
#endif

            CodeModel modelToReturn;
            if (visible)
            {
                modelToReturn = CodeModel.CreateVisibleModelForPreprocessed(source, appSettings, this, prepModel);
                modelToReturn.PreprocessorModel = prepModel;
                modelToReturn.DisabledSections  = prepSource.GenerateDisabledSections().ToArray();
            }
            else
            {
                modelToReturn = CodeModel.CreateFullModelForPreprocessed(prepSource, appSettings, this, prepModel);
                modelToReturn.PreprocessorModel = prepModel;
            }

            modelToReturn.PreprocessorReferences = prep.References;

#if DEBUG
            var endTime     = DateTime.Now;
            var elapsedTime = endTime.Subtract(startTime).TotalMilliseconds;
            var prepTime    = midTime1.Subtract(startTime).TotalMilliseconds;
            var modelTime   = midTime2.Subtract(midTime1).TotalMilliseconds;
            var visTime     = endTime.Subtract(midTime2).TotalMilliseconds;
            Log.Debug("Created model in {0} msecs ({1} preprocessor, {2} model, {3} visible)", elapsedTime, prepTime, modelTime, visTime);
#endif

            return(modelToReturn);
        }