Type *
getTypeInfoType (Loc loc, Type *type, Scope *sc)
{
- if (!global.params.useTypeInfo)
- {
- /* Even when compiling without RTTI we should still be able to evaluate
- TypeInfo at compile-time, just not at run-time. */
- if (!sc || !(sc->flags & SCOPEctfe))
- {
- static int warned = 0;
-
- if (!warned)
- {
- error_at (make_location_t (loc),
- "%<object.TypeInfo%> cannot be used with %<-fno-rtti%>");
- warned = 1;
- }
- }
- }
-
- if (Type::dtypeinfo == NULL
- || (Type::dtypeinfo->storage_class & STCtemp))
- {
- /* If TypeInfo has not been declared, warn about each location once. */
- static Loc warnloc;
-
- if (!loc.equals (warnloc))
- {
- error_at (make_location_t (loc),
- "%<object.TypeInfo%> could not be found, "
- "but is implicitly used");
- warnloc = loc;
- }
- }
-
gcc_assert (type->ty != Terror);
+ check_typeinfo_type (loc, sc);
create_typeinfo (type, sc ? sc->_module->importedFrom : NULL);
return type->vtinfo->type;
}
extern unsigned base_vtable_offset (ClassDeclaration *, BaseClass *);
extern tree get_typeinfo_decl (TypeInfoDeclaration *);
extern tree get_classinfo_decl (ClassDeclaration *);
+extern void check_typeinfo_type (const Loc &, Scope *);
extern tree build_typeinfo (const Loc &, Type *);
extern void create_typeinfo (Type *, Module *);
extern void create_tinfo_types (Module *);
#include "dmd/identifier.h"
#include "dmd/module.h"
#include "dmd/mtype.h"
+#include "dmd/scope.h"
#include "dmd/template.h"
#include "dmd/target.h"
static void
create_frontend_tinfo_types (void)
{
- /* If there's no Object class defined, then neither can TypeInfo be. */
- if (object_module == NULL || ClassDeclaration::object == NULL)
+ /* If there's no object module, then neither can there be TypeInfo. */
+ if (object_module == NULL)
return;
/* Create all frontend TypeInfo classes declarations. We rely on all
return decl->csym;
}
-/* Returns typeinfo reference for TYPE. */
+/* Performs sanity checks on the `object.TypeInfo' type, raising an error if
+ RTTI is disabled, or the type is missing. */
-tree
-build_typeinfo (const Loc &loc, Type *type)
+void
+check_typeinfo_type (const Loc &loc, Scope *sc)
{
if (!global.params.useTypeInfo)
{
static int warned = 0;
- if (!warned)
+ /* Even when compiling without RTTI we should still be able to evaluate
+ TypeInfo at compile-time, just not at run-time. */
+ if (!warned && (!sc || !(sc->flags & SCOPEctfe)))
{
error_at (make_location_t (loc),
"%<object.TypeInfo%> cannot be used with %<-fno-rtti%>");
}
}
+ if (Type::dtypeinfo == NULL
+ || (Type::dtypeinfo->storage_class & STCtemp))
+ {
+ /* If TypeInfo has not been declared, warn about each location once. */
+ static Loc warnloc;
+
+ if (!warnloc.equals (loc))
+ {
+ error_at (make_location_t (loc),
+ "%<object.TypeInfo%> could not be found, "
+ "but is implicitly used");
+ warnloc = loc;
+ }
+ }
+}
+
+/* Returns typeinfo reference for TYPE. */
+
+tree
+build_typeinfo (const Loc &loc, Type *type)
+{
gcc_assert (type->ty != Terror);
+ check_typeinfo_type (loc, NULL);
create_typeinfo (type, NULL);
return build_address (get_typeinfo_decl (type->vtinfo));
}