示例#1
0
        public CodeAnalyzer(OutputPane pane, DkTools.CodeModel.CodeModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            _pane      = pane;
            _codeModel = model;
        }
示例#2
0
文件: Scope.cs 项目: cmrazek/DkTools
        public Scope(CodeModel model)
        {
#if DEBUG
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
#endif
            _file           = model.File;
            _hint           = default(ScopeHint);
            _depth          = 0;
            _visible        = false;
            _defProvider    = model.DefinitionProvider;
            _className      = null;
            _code           = null;
            _breakOwner     = null;
            _continueOwner  = null;
            _returnDataType = null;
        }
示例#3
0
        public CodeModel RegenerateModel(ProbeAppSettings appSettings, string fileName, VsText.ITextSnapshot snapshot, string reason)
        {
#if DEBUG
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }
#endif

            _model = CreatePreprocessedModel(appSettings, fileName, snapshot, reason);

            var ev = ModelUpdated;
            if (ev != null)
            {
                ev(this, new ModelUpdatedEventArgs(_model));
            }

            return(_model);
        }
示例#4
0
        private static void CreateStdLibModel(ProbeAppSettings appSettings)
        {
            var tempStore   = new FileStore();
            var includeFile = tempStore.GetIncludeFile(appSettings, null, "stdlib.i", false, new string[0]);

            if (includeFile != null)
            {
                _stdLibModel = tempStore.CreatePreprocessedModel(appSettings, includeFile.GetSource(appSettings),
                                                                 includeFile.FullPathName, false, "stdlib.i model", null);
            }
            else
            {
                var blankSource = new CodeSource();
                blankSource.Flush();

                _stdLibModel = tempStore.CreatePreprocessedModel(appSettings, blankSource, "stdlib.i", false,
                                                                 "stdlib.i model (blank)", null);
            }

            _stdLibDefines = _stdLibModel.PreprocessorModel.Preprocessor.Defines.ToArray();
        }
示例#5
0
 public ModelUpdatedEventArgs(CodeModel model)
 {
     Model = model;
 }
示例#6
0
 private void FileStore_AllModelRebuildRequired(object sender, EventArgs e)
 {
     _model = null;
 }
示例#7
0
        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);
        }