Example #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;
        }
        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;
        }
Example #3
0
    private static BasicSymbolStorage Generate(TextWriter writer)
    {
        NativeCodeAnalyzer analyzer = NativeCodeAnalyzerFactory.Create(OsVersion.WindowsVista);

        analyzer.IncludePathList.AddRange(NativeCodeAnalyzerFactory.GetCommonSdkPaths());

        // Run the preprocessor
        analyzer.Trace = true;
        string        winPath = Path.Combine(PInvoke.Parser.NativeCodeAnalyzerFactory.GetPlatformSdkIncludePath(), "windows.h");
        TextReaderBag tr      = analyzer.RunPreProcessor(winPath);

        File.WriteAllText("d:\\temp\\windows.out.h", tr.TextReader.ReadToEnd());
        analyzer.Trace = false;

        NativeCodeAnalyzerResult result = analyzer.Analyze(winPath);
        ErrorProvider            ep     = result.ErrorProvider;

        if (ep.Errors.Count > 0)
        {
            Debug.Fail("Encountered an error during the parse");
        }
        NativeSymbolBag bag = NativeSymbolBag.CreateFrom(result, CreateInitialBasicSymbolStorage(), ep);

        // Resolve with the full dll list
        using (ProcedureFinder finder = new ProcedureFinder(FullDllList))
        {
            bag.TryResolveSymbolsAndValues(finder, ep);
        }

        foreach (string msg in ep.AllMessages)
        {
            writer.WriteLine("' " + msg);
        }

        // GenerateCode(writer, bag)

        // Now write out the file
        var ns = new BasicSymbolStorage();

        bag.SaveToNativeStorage(ns);
        VerifyGeneratedStorage(ns);

        // TODO: need to write to file again otherwise it's just in memory.

        // Copy the file to the various applications
        File.Copy("windows.xml", "..\\..\\..\\ConsoleTool\\bin\\Debug\\windows.xml", true);
        File.Copy("windows.xml", "..\\..\\Data\\windows.xml", true);

        string fullInstallTarget = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), Path.Combine(PInvoke.Constants.ProductName, "Data\\windows.xml"));

        if (File.Exists(fullInstallTarget))
        {
            File.Copy("windows.xml", fullInstallTarget, true);
        }

        return(ns);
    }