Exemple #1
0
        void SetEntryPoint()
        {
            if (!Compiler.Settings.NeedsEntryPoint)
            {
                if (Compiler.Settings.MainClass != null)
                {
                    Report.Error(2017, "Cannot specify -main if building a module or library");
                }

                return;
            }

            PEFileKinds file_kind;

            switch (Compiler.Settings.Target)
            {
            case Target.Library:
            case Target.Module:
                file_kind = PEFileKinds.Dll;
                break;

            case Target.WinExe:
                file_kind = PEFileKinds.WindowApplication;
                break;

            default:
                file_kind = PEFileKinds.ConsoleApplication;
                break;
            }

            if (entry_point == null)
            {
                if (Compiler.Settings.MainClass != null)
                {
                    // TODO: Should use MemberCache
                    DeclSpace main_cont = module.GetDefinition(Compiler.Settings.MainClass) as DeclSpace;
                    if (main_cont == null)
                    {
                        Report.Error(1555, "Could not find `{0}' specified for Main method", Compiler.Settings.MainClass);
                        return;
                    }

                    if (!(main_cont is ClassOrStruct))
                    {
                        Report.Error(1556, "`{0}' specified for Main method must be a valid class or struct", Compiler.Settings.MainClass);
                        return;
                    }

                    Report.Error(1558, main_cont.Location, "`{0}' does not have a suitable static Main method", main_cont.GetSignatureForError());
                    return;
                }

                if (Report.Errors == 0)
                {
                    string pname = file_name == null ? name : Path.GetFileName(file_name);

                    Report.Error(5001, "Program `{0}' does not contain a static `Main' method suitable for an entry point",
                                 pname);
                }

                return;
            }

            Builder.SetEntryPoint(entry_point.MethodBuilder, file_kind);
        }