示例#1
0
文件: VsLol.cs 项目: turkmvc/lol
        protected override void Initialize()
        {
            // Trace the beginning of this method and call the base implementation.
            Trace.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                          "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            Logger.Initialize(GetService(typeof(SVsOutputWindow)) as IVsOutputWindow);

            /* Register the "Generate Compilers" context menu */
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                CommandID id = new CommandID(GuidsList.guidVsLolCmdSet,
                                             VsLolIDList.cmdidGenerateCompilers);
                OleMenuCommand command = new MenuGenerateCompilers(new ServiceProvider((IOleServiceProvider)this.GetService(typeof(IOleServiceProvider))), id);
                mcs.AddCommand(command);
            }

            /* Register the LolFx language service */
            IServiceContainer    serviceContainer = this as IServiceContainer;
            LolFxLanguageService lolfxserv        = new LolFxLanguageService();

            lolfxserv.SetSite(this);
            serviceContainer.AddService(typeof(LolFxLanguageService),
                                        lolfxserv, true);
        }
示例#2
0
        private static void ClickCallback(object sender, EventArgs args)
        {
            MenuGenerateCompilers cmd = sender as MenuGenerateCompilers;

            if (cmd == null)
            {
                return;
            }

            Logger.Clear();
            Logger.Info("------ Build started: Generating Compilers ------\n");

            int scanner_count = 0, parser_count = 0, error_count = 0;

            foreach (Project project in cmd.projects)
            {
                Logger.Info("Project " + project.Name + "\n");

                string project_path = Path.GetDirectoryName(project.FullName);

                /* FIXME: find this using the solution globals! */
                string external_path = project_path;
                for (int i = 0; i < 10; ++i)
                {
                    external_path += "\\..";
                    if (Directory.Exists(external_path + "\\external"))
                    {
                        break;
                    }
                }

                /* FIXME: do not hardcode shit! */
                string flex_path  = external_path + "\\external\\flex-2.5.35";
                string bison_path = external_path + "\\external\\bison-2.4.2";

                /* Workaround for an MSYS bug. If these directories don't
                 * exist, fork() will fail. Yeah, wtf. */
                try
                {
                    Directory.CreateDirectory(flex_path + "\\etc");
                    Directory.CreateDirectory(bison_path + "\\etc");
                }
                catch (Exception e) { }

                // Run flex on all the .l files
                foreach (ProjectItem item in ParseProjectItems(project))
                {
                    string filename = item.get_FileNames(0);

                    if (filename.StartsWith(project_path + "\\"))
                    {
                        filename = filename.Substring(project_path.Length + 1);
                        filename = filename.Replace("\\", "/");
                    }

                    if (item.Name.EndsWith("-scanner.l"))
                    {
                        Logger.Info("flex.exe " + filename + "\n");

                        string basename = Path.GetFileName(filename.Substring(0, filename.LastIndexOf("-scanner.l")));
                        if (!cmd.Run(project_path,
                                     flex_path + "\\bin\\flex.exe",
                                     "-v -o "
                                     + "generated/" + basename + "-scanner.cpp "
                                     + filename,
                                     ""))
                        {
                            ++error_count;
                        }

                        ++scanner_count;
                    }

                    if (item.Name.EndsWith("-parser.y"))
                    {
                        Logger.Info("bison.exe " + filename + "\n");

                        string basename = Path.GetFileName(filename.Substring(0, filename.LastIndexOf("-parser.y")));
                        if (!cmd.Run(project_path,
                                     bison_path + "\\bin\\bison.exe",
                                     "-v -o "
                                     + "generated/" + basename + "-parser.cpp "
                                     + "--defines=generated/" + basename + "-parser.h "
                                     + "-d "
                                     + "-b "
                                     + "generated/" + basename + " "
                                     + filename,
                                     "BISON_PKGDATADIR=" + bison_path + "\\share\\bison"))
                        {
                            ++error_count;
                        }

                        ++parser_count;
                    }
                }
            }

            Logger.Info(string.Format("========== Done: {0} scanner(s), {1} parser(s), {2} error(s) ==========\n",
                                      scanner_count, parser_count, error_count));
        }