Пример #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
        public static bool TryCreateFromDeclaration(string name, string body, out MethodMacro method)
        {
            method = null;

            try
            {
                PreProcessorEngine engine = new PreProcessorEngine(new PreProcessorOptions());
                using (var reader = new StringReader("#define " + name + body))
                {
                    engine.Process(new TextReaderBag(reader));
                    Macro created = null;
                    if (engine.MacroMap.TryGetValue(name, out created) && created.IsMethod)
                    {
                        method = (MethodMacro)created;
                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(false);
        }