Пример #1
0
        /// <summary>
        /// Run the PreProcessor on the stream
        /// </summary>
        /// <param name="result"></param>
        /// <param name="readerBag"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private TextReaderBag RunPreProcessorImpl(NativeCodeAnalyzerResult result, TextReaderBag readerBag)
        {
            ThrowIfNull(result);
            ThrowIfNull(readerBag);

            // Create the options
            PreProcessorOptions opts = new PreProcessorOptions();

            opts.FollowIncludes = this.FollowIncludes;
            opts.IncludePathList.AddRange(this.IncludePathList);
            opts.InitialMacroList.AddRange(_initialMacroList);
            opts.Trace = this.Trace;

            PreProcessorEngine preprocessor = new PreProcessorEngine(opts);

            // Process the file
            string ret = preprocessor.Process(readerBag);

            // Process the results
            result.ErrorProvider.Append(preprocessor.ErrorProvider);
            foreach (KeyValuePair <string, Macro> pair in preprocessor.MacroMap)
            {
                if (_includeInitialMacroInResult || pair.Value.IsFromParse)
                {
                    result.MacroMap.Add(pair.Key, pair.Value);
                }
            }

            return(new TextReaderBag(new StringReader(ret)));
        }
Пример #2
0
        /// <summary>
        /// Process the given stream and return the result of removing the
        /// preprocessor definitions
        /// </summary>
        /// <param name="readerBag"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public string Process(TextReaderBag readerBag)
        {
            ThrowIfTrue(_processing, "Recursive parsing not supported in this manner.");

            StringBuilder builder = new StringBuilder();

            try
            {
                // Setup the macro map
                _macroMap.Clear();
                foreach (Macro m in _options.InitialMacroList)
                {
                    _macroMap[m.Name] = m;
                }

                _outputStream = new StringWriter(builder);
                using (_outputStream)
                {
                    _processing = true;
                    ProcessCore(readerBag);

                    if (_options.Trace)
                    {
                        TraceMacroMap();
                    }
                }
            }
            finally
            {
                _processing   = false;
                _outputStream = null;
            }

            return(builder.ToString());
        }
Пример #3
0
 public Scanner(TextReaderBag bag, ScannerOptions options)
 {
     ThrowIfNull(bag);
     ThrowIfNull(options);
     _readerBag = bag;
     _buffer    = new ScannerBuffer(bag.TextReader);
     _options   = options;
 }
Пример #4
0
        /// <summary>
        /// Run the actual parser on the stream
        /// </summary>
        /// <param name="result"></param>
        /// <param name="readerBag"></param>
        /// <remarks></remarks>
        private void RunParser(NativeCodeAnalyzerResult result, TextReaderBag readerBag)
        {
            ThrowIfNull(readerBag);

            // Perform the parse
            ParseEngine parser      = new ParseEngine();
            ParseResult parseResult = parser.Parse(readerBag);

            // add in the basic results
            result.ErrorProvider.Append(parseResult.ErrorProvider);
            result.Symbols.AddRange(parseResult.NativeDefinedTypes.Select(x => new NativeGlobalSymbol(x)));
            result.Symbols.AddRange(parseResult.NativeTypeDefs.Select(x => new NativeGlobalSymbol(x)));
            result.Symbols.AddRange(parseResult.NativeProcedures.Select(x => new NativeGlobalSymbol(x)));
            result.Symbols.AddRange(parseResult.NativeEnumValues.Select(x => new NativeGlobalSymbol(x)));
        }
Пример #5
0
        private NativeCodeAnalyzerResult AnalyzeImpl(TextReaderBag readerbag)
        {
            ThrowIfNull(readerbag);

            NativeCodeAnalyzerResult result = new NativeCodeAnalyzerResult();

            // Run the procprocessor and get the resulting Textreader
            TextReaderBag readerBag2 = this.RunPreProcessorImpl(result, readerbag);

            using (readerBag2.TextReader)
            {
                // Run the parser
                this.RunParser(result, readerBag2);
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Called to process a particular stream of text.  Can be called recursively
        /// </summary>
        /// <param name="readerBag"></param>
        /// <remarks></remarks>
        private void ProcessCore(TextReaderBag readerBag)
        {
            ThrowIfFalse(_processing);
            Scanner oldScanner = _scanner;

            try
            {
                // Create the scanner
                _scanner = new Scanner(readerBag, CreateScannerOptions());
                _scanner.ErrorProvider = this.ErrorProvider;

                ProcessLoop();
            }
            finally
            {
                _scanner = oldScanner;
            }
        }