コード例 #1
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods
        internal static string[] Parse(string [] filenames, bool sourceDebuggingSupport)
        {
            string[] results = new string[filenames.Length];
            int      i       = 0;

            foreach (string filename in filenames)
            {
                CsPrimeParser parser = new CsPrimeParser(Path.GetFullPath(filename), sourceDebuggingSupport);
                results[i++] = parser.Result;
            }

            return(results);
        }
コード例 #2
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods
        /// <summary>
        /// Parse & compile a C# prime project.
        /// </summary>
        internal static Project Build(
            Parameters parameters
            )
        {
            TempDirectory tempDirectory = new TempDirectory();

            string[] intermediateSource = null;

            if (parameters.EnableCsPrime)
            {
                intermediateSource = CsPrimeParser.Parse(
                    parameters.SourceFiles,
                    /* sourceDebuggingSupport = */ true
                    );
            }

            ArrayList referencedAssemblies = new ArrayList();

            // Add some implicit referenced assemblies.

            referencedAssemblies.Add(Path.Combine(parameters.ClrDir, "System.dll"));
            if (parameters.EnableCsPrime)
            {
                // Needed so that the project can access MS.Internal.Csp.CsPrimeRuntime.
                // (The parser generates references to it.)
                referencedAssemblies.Add(System.Windows.Forms.Application.ExecutablePath);
            }
            referencedAssemblies.AddRange(parameters.ReferencedAssemblies);

            CompilerParameters cp = new CompilerParameters(
                (string[])referencedAssemblies.ToArray(typeof(string))
                );

            cp.GenerateExecutable      = true;
            cp.IncludeDebugInformation = true;


            // GenerateInMemory:
            //   If true:  Neither cordbg nor Rascal can find symbols.
            //   If false: TempDirectory.Dispose throws an exception if it tries to
            //             clear the directory, because the CLR still has the .exe file open.

            if (parameters.DebugModeHack)
            {
                cp.GenerateInMemory = false;
                tempDirectory.SetToLeak();    // Since cleanup seems impossible
            }
            else
            {
                cp.GenerateInMemory = true;
            }

            // In order to generate a .pdb that Rascal can use, OutputAssembly
            // must be set to something (i.e. not the default which creates a
            // temporary file).
            //
            // (Hence the futzing with TempDirectory).

            cp.OutputAssembly = Path.Combine(tempDirectory.PathName, "csp.project.exe");

            if (parameters.MainClass != null)
            {
                cp.MainClass = parameters.MainClass;
            }

            Microsoft.CSharp.CSharpCodeProvider codeCompiler = new Microsoft.CSharp.CSharpCodeProvider();

            CompilerResults results;

            if (parameters.EnableCsPrime)
            {
                results = codeCompiler.CompileAssemblyFromSource(cp, intermediateSource);
            }
            else
            {
                results = codeCompiler.CompileAssemblyFromFile(cp, parameters.SourceFiles);
            }

            if (results.Output.Count > 0)
            {
                Console.WriteLine("Output from compiler:");
                foreach (String s in results.Output)
                {
                    Console.WriteLine(s);
                }
            }

            if (results.Errors.Count > 0)
            {
                Console.WriteLine("Aborting.");
                return(null);
            }

            return(new Project(
                       results.CompiledAssembly,
                       tempDirectory,
                       parameters.BreakBeforeInvoke
                       ));
        }