コード例 #1
0
ファイル: CodeModel.cs プロジェクト: cmrazek/DkTools
        public static CodeModel CreateFullModelForPreprocessed(CodeSource source, ProbeAppSettings appSettings, FileStore store, PreprocessorModel prepModel)
        {
            var model    = new CodeModel(appSettings, store);
            var codeFile = new CodeFile(model);

            model.Init(source, codeFile, prepModel.FileName, false, prepModel.DefinitionProvider);
            return(model);
        }
コード例 #2
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);
        }