Example #1
0
        public void Parse(FrontendCompiler frontend)
        {
            if (this.TextView != null)
            {
                using (TextSnapshotToTextReader reader = new TextSnapshotToTextReader(this.TextView.TextBuffer.CurrentSnapshot))
                {
                    frontend.Parse(reader, this.Path);
                }
            }
            else
            {
                frontend.Parse(this.Path);
            }

            this.NeedsCompilation = false;
        }
Example #2
0
        /// <summary>
        /// Compiles the added files into a target output appropriate for the output path extension.
        /// </summary>
        /// <param name="type">Package type to generate.</param>
        /// <param name="architecture">Package architecture to generate.</param>
        /// <param name="languages">Package languages to generate.</param>
        /// <param name="outputPath">Path to generate output. Output path file extension determines the output type.</param>
        public void Compile(PackageType type, PackageArchitecture architecture, CultureInfo[] languages, string outputPath)
        {
            FrontendCompiler frontend = new FrontendCompiler(architecture, this.referenceAssemblies);

            frontend.Messages += this.Messages;

            foreach (KeyValuePair <string, string> define in this.PreprocessorDefines)
            {
                frontend.Substitutions.Add(define.Key, define.Value);
            }

            foreach (Swix root in this.roots)
            {
                frontend.AddRoot(root);
            }

            foreach (string path in this.sourceFiles)
            {
                frontend.Parse(path);
            }

            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Resolve();
            if (frontend.EncounteredError)
            {
                return;
            }

            frontend.Harvest();
            if (frontend.EncounteredError)
            {
                return;
            }

            Intermediate[] intermediates = frontend.GetIntermediates();

            CompilerFileManager fileManager = this.FileManager ?? new CompilerFileManager();

            fileManager.Architecture = architecture;
            fileManager.Language     = languages.Length == 0 ? null : languages[0];
            fileManager.OutputPath   = outputPath;
            foreach (string searchPath in this.SearchPaths)
            {
                fileManager.SearchPaths.Add(searchPath);
            }

            using (BackendCompiler backend = BackendCompiler.Create(type, outputPath))
            {
                backend.Messages    += this.Messages;
                backend.Architecture = architecture;
                backend.FileManager  = fileManager;
                backend.Languages    = languages;

                backend.Generate(intermediates, outputPath);
            }
        }