internal static bool PostValidateArguments(LolCompilerArguments arguments)
        {
            // Are there any files?
            if (arguments.sources.Length == 0)
            {
                Console.Error.WriteLine("lolc error: No source files specified");
                return false; 
            }

            // Do they exist?
            foreach (string file in arguments.sources)
            {
                if (!File.Exists(file))
                {
                    Console.Error.WriteLine("lolc error: Source file '{0}' does not exist.", file);
                    return false; 
                }
            }

            // Is the target platform valid? 
            if (!String.IsNullOrEmpty(arguments.platform) && !IsPlatformValid(arguments.platform))
            {
                Console.Error.WriteLine("lolc error: Platform '{0}' is not valid", arguments.platform);
                return false; 
            }

            // Is the target assembly type valid?
            if (!String.IsNullOrEmpty(arguments.target) && !IsTargetValid(arguments.target))
            {
                Console.Error.WriteLine("lolc error: Target '{0}' is not valid", arguments.platform);
                return false; 
            }

            return true; 
        }
        internal static bool PostValidateArguments(LolCompilerArguments arguments)
        {
            // Are there any files?
            if (arguments.sources.Length == 0)
            {
                Console.Error.WriteLine("lolc error: No source files specified");
                return(false);
            }

            // Do they exist?
            foreach (string file in arguments.sources)
            {
                if (!File.Exists(file))
                {
                    Console.Error.WriteLine("lolc error: Source file '{0}' does not exist.", file);
                    return(false);
                }
            }

            // Is the target platform valid?
            if (!String.IsNullOrEmpty(arguments.platform) && !IsPlatformValid(arguments.platform))
            {
                Console.Error.WriteLine("lolc error: Platform '{0}' is not valid", arguments.platform);
                return(false);
            }

            // Is the target assembly type valid?
            if (!String.IsNullOrEmpty(arguments.target) && !IsTargetValid(arguments.target))
            {
                Console.Error.WriteLine("lolc error: Target '{0}' is not valid", arguments.platform);
                return(false);
            }

            return(true);
        }
Exemple #3
0
        static int Main(string[] args)
        {
            LolCompilerArguments arguments = new LolCompilerArguments();

            if (!CommandLine.Parser.ParseArgumentsWithUsage(args, arguments))
            {
                return(2);
            }

            // Ensure some goodness in the arguments
            if (!LolCompilerArguments.PostValidateArguments(arguments))
            {
                // Errors are output by PostValidateArguments to STDERR
                return(3);
            }

            // Warn the user if there is more than one source file, as they will be ignored (for now)
            // TODO: Should be removed eventually
            if (arguments.sources.Length > 1)
            {
                Console.Error.WriteLine("lolc warning: More than one source file specifed. Only '{0}' will be compiled.", arguments.sources[0]);
            }

            // Good to go
            string outfileFile           = String.IsNullOrEmpty(arguments.output) ? Path.ChangeExtension(arguments.sources[0], ".exe") : arguments.output;
            LOLCodeCodeProvider compiler = new LOLCodeCodeProvider();
            CompilerParameters  cparam   = new CompilerParameters();

            cparam.GenerateExecutable      = true;
            cparam.GenerateInMemory        = false;
            cparam.OutputAssembly          = outfileFile;
            cparam.MainClass               = "Program";
            cparam.IncludeDebugInformation = arguments.debug;
            cparam.ReferencedAssemblies.AddRange(arguments.references);
            CompilerResults results = compiler.CompileAssemblyFromFile(cparam, arguments.sources[0]);

            for (int i = 0; i < results.Errors.Count; i++)
            {
                Console.Error.WriteLine(results.Errors[i].ToString());
            }

            if (results.Errors.HasErrors)
            {
                Console.Out.WriteLine("Failed to compile.");
                return(1);
            }
            else
            {
                Console.Out.WriteLine("Successfully compiled.");
                return(0);
            }
        }
Exemple #4
0
        static int Main(string[] args)
        {
            LolCompilerArguments arguments = new LolCompilerArguments();

            if (!CommandLine.Parser.ParseArgumentsWithUsage(args, arguments))
            {
                return 2; 
            }

            // Ensure some goodness in the arguments
            if (!LolCompilerArguments.PostValidateArguments(arguments))
            {
                // Errors are output by PostValidateArguments to STDERR
                return 3;
            }

            // Warn the user if there is more than one source file, as they will be ignored (for now) 
            // TODO: Should be removed eventually
            if (arguments.sources.Length > 1)
            {
                Console.Error.WriteLine("lolc warning: More than one source file specifed. Only '{0}' will be compiled.", arguments.sources[0]);
            }

            // Good to go
            string outfileFile = String.IsNullOrEmpty(arguments.output) ? Path.ChangeExtension(arguments.sources[0], ".exe") : arguments.output;
            LOLCodeCodeProvider compiler = new LOLCodeCodeProvider();
            CompilerParameters cparam = new CompilerParameters();
            cparam.GenerateExecutable = true;
            cparam.GenerateInMemory = false;
            cparam.OutputAssembly = outfileFile;
            cparam.MainClass = "Program";
            cparam.IncludeDebugInformation = arguments.debug;
            cparam.ReferencedAssemblies.AddRange(arguments.references); 
            CompilerResults results = compiler.CompileAssemblyFromFile(cparam, arguments.sources[0]);

            for (int i = 0; i < results.Errors.Count; i++)
                Console.Error.WriteLine(results.Errors[i].ToString());

            if (results.Errors.HasErrors)
            {
                Console.Out.WriteLine("Failed to compile.");
                return 1;
            }
            else
            {
                Console.Out.WriteLine("Successfully compiled.");
                return 0;
            }
        }