/// <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))); }
/// <summary> /// Run the preprocessor on the specefied file and return a Stream to the resulting /// data /// </summary> /// <param name="filePath"></param> /// <returns></returns> /// <remarks></remarks> public TextReaderBag RunPreProcessor(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } NativeCodeAnalyzerResult result = new NativeCodeAnalyzerResult(); using (StreamReader fileStream = new StreamReader(filePath)) { return(RunPreProcessorImpl(result, new TextReaderBag(filePath, fileStream))); } }
/// <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))); }
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); }
public static NativeSymbolBag CreateFrom(Parser.NativeCodeAnalyzerResult result, INativeSymbolStorage storage) { return(CreateFrom(result, storage, new ErrorProvider())); }