Skip to content

Commit 0b5641e

Browse files
committed
Merge pull request #1925 from ibuclaw/moduleinfo_struct
Add check that 'struct ModuleInfo' exists in object.d
2 parents 211f09d + bb502a0 commit 0b5641e

File tree

7 files changed

+19
-4
lines changed

7 files changed

+19
-4
lines changed

src/class.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,13 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
218218
classinfo = this;
219219
}
220220

221+
#if !MODULEINFO_IS_STRUCT
221222
if (id == Id::ModuleInfo)
222223
{ if (Module::moduleinfo)
223224
Module::moduleinfo->error("%s", msg);
224225
Module::moduleinfo = this;
225226
}
227+
#endif
226228
}
227229

228230
com = 0;

src/declaration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ int overloadApply(FuncDeclaration *fstart,
108108
int (*fp)(void *, FuncDeclaration *),
109109
void *param);
110110

111+
void ObjectNotFound(Identifier *id);
112+
111113
enum Semantic
112114
{
113115
SemanticStart, // semantic has not been run

src/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "d-dmd-gcc.h"
2828
#endif
2929

30-
ClassDeclaration *Module::moduleinfo;
30+
AggregateDeclaration *Module::moduleinfo;
3131

3232
Module *Module::rootModule;
3333
DsymbolTable *Module::modules;

src/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct Module : Package
5454
static unsigned dprogress; // progress resolving the deferred list
5555
static void init();
5656

57-
static ClassDeclaration *moduleinfo;
57+
static AggregateDeclaration *moduleinfo;
5858

5959

6060
const char *arg; // original argument name

src/mtype.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
#include "hdrgen.h"
4848

4949
FuncDeclaration *hasThis(Scope *sc);
50-
void ObjectNotFound(Identifier *id);
51-
5250

5351
#define LOGDOTEXP 0 // log ::dotExp()
5452
#define LOGDEFAULTINIT 0 // log ::defaultInit()

src/struct.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,14 @@ StructDeclaration::StructDeclaration(Loc loc, Identifier *id)
427427

428428
// For forward references
429429
type = new TypeStruct(this);
430+
431+
#if MODULEINFO_IS_STRUCT
432+
if (id == Id::ModuleInfo)
433+
{ if (Module::moduleinfo)
434+
Module::moduleinfo->error("only object.d can define this reserved struct name");
435+
Module::moduleinfo = this;
436+
}
437+
#endif
430438
}
431439

432440
Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s)

src/toobj.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ void Module::genmoduleinfo()
4949
{
5050
//printf("Module::genmoduleinfo() %s\n", toChars());
5151

52+
if (! Module::moduleinfo)
53+
{
54+
ObjectNotFound(Id::ModuleInfo);
55+
}
56+
5257
Symbol *msym = toSymbol();
5358
#if DMDV2
5459
unsigned sizeof_ModuleInfo = 16 * Target::ptrsize;

0 commit comments

Comments
 (0)