Example #1
0
        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();
        }
Example #2
0
 public void AddDefinitionsToProvider(DefinitionProvider defProv)
 {
     foreach (var define in _defines.Values)
     {
         defProv.AddGlobalFromFile(define.Definition);
     }
 }
Example #3
0
        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;
        }
Example #4
0
        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;
        }
Example #5
0
        public Scope(CodeFile file, int depth, ScopeHint hint, bool visible, DefinitionProvider defProvider)
        {
#if DEBUG
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (defProvider == null)
            {
                throw new InvalidOperationException("Model has no definition provider.");
            }
#endif
            _file           = file;
            _depth          = depth;
            _hint           = hint;
            _visible        = visible;
            _defProvider    = defProvider;
            _className      = null;
            _code           = file.CodeParser;
            _breakOwner     = null;
            _continueOwner  = null;
            _returnDataType = null;
        }
Example #6
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);
        }