Пример #1
0
        public override Type LookupTypeReflection(string name, Location loc)
        {
            Type found_type = base.LookupTypeReflection(name, loc);

            if (modules != null)
            {
                foreach (Module module in modules)
                {
                    Type t = module.GetType(name);
                    if (t == null)
                    {
                        continue;
                    }

                    if (found_type == null)
                    {
                        found_type = t;
                        continue;
                    }

                    Report.SymbolRelatedToPreviousError(found_type);
                    if (loc.IsNull)
                    {
                        DeclSpace ds = TypeManager.LookupDeclSpace(t);
                        Report.Warning(1685, 1, ds.Location, "The type `{0}' conflicts with the predefined type `{1}' and will be ignored",
                                       ds.GetSignatureForError(), TypeManager.CSharpName(found_type));
                        return(found_type);
                    }
                    Report.SymbolRelatedToPreviousError(t);
                    Report.Warning(436, 2, loc, "The type `{0}' conflicts with the imported type `{1}'. Ignoring the imported type definition",
                                   TypeManager.CSharpName(t), TypeManager.CSharpName(found_type));
                    return(t);
                }
            }

            return(found_type);
        }
Пример #2
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);
        }