예제 #1
0
        private static void OnDoBackgroundCompile(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            string result = null;

            try
            {
                Data               data     = (Data)e.Argument;
                string             code     = data.Text;
                NativeCodeAnalyzer analyzer = NativeCodeAnalyzerFactory.CreateForMiniParse(OsVersion.WindowsVista, data.InitialMacroList);
                using (var reader = new StringReader(code))
                {
                    NativeCodeAnalyzerResult parseResult = analyzer.Analyze(reader);
                    ErrorProvider            ep          = parseResult.ErrorProvider;
                    if (ep.Warnings.Count == 0 && ep.Errors.Count == 0)
                    {
                        result = "None ...";
                    }
                    else
                    {
                        result = ep.CreateDisplayString();
                    }
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            e.Result = result;
        }
예제 #2
0
        /// <summary>
        /// Convert the block of native code into a CodeDom hierarchy
        /// </summary>
        /// <param name="code"></param>
        /// <param name="ep"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public CodeTypeDeclarationCollection ConvertNativeCodeToCodeDom(string code, ErrorProvider ep)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }

            if (ep == null)
            {
                throw new ArgumentNullException("ep");
            }

            var analyzer = NativeCodeAnalyzerFactory.CreateForMiniParse(OsVersion.WindowsVista, _storage.GetAllMacros());

            // TODO: probably should delete this
            analyzer.IncludePathList.Add("c:\\program files (x86)\\windows kits\\8.1\\include\\shared");
            NativeSymbolBag bag = default(NativeSymbolBag);

            using (System.IO.StringReader reader = new StringReader(code))
            {
                NativeCodeAnalyzerResult result = analyzer.Analyze(reader);

                ep.Append(result.ErrorProvider);
                bag = NativeSymbolBag.CreateFrom(result, Storage);
            }

            return(ConvertBagToCodeDom(bag, ep));
        }
        private static void OnDoBackgroundWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            ResponseData result = new ResponseData();

            try
            {
                RequestData        req      = (RequestData)e.Argument;
                string             code     = req.Text;
                NativeCodeAnalyzer analyzer = NativeCodeAnalyzerFactory.CreateForMiniParse(OsVersion.WindowsVista, req.InitialMacroList);

                // TODO: shouldn't include this
                analyzer.IncludePathList.Add("c:\\program files (x86)\\windows kits\\8.1\\include\\shared");
                using (var reader = new StringReader(code))
                {
                    NativeCodeAnalyzerResult parseResult = analyzer.Analyze(reader);
                    ErrorProvider            ep          = parseResult.ErrorProvider;
                    if (ep.Warnings.Count == 0 && ep.Errors.Count == 0)
                    {
                        result.ParseOutput = "None ...";
                    }
                    else
                    {
                        result.ParseOutput = ep.CreateDisplayString();
                    }
                }
            }
            catch (Exception ex)
            {
                result.ParseOutput = ex.Message;
            }

            e.Result = result;
        }