Skip to content

Commit

Permalink
Merge pull request #1925 from ibuclaw/moduleinfo_struct
Browse files Browse the repository at this point in the history
Add check that 'struct ModuleInfo' exists in object.d
  • Loading branch information
MartinNowak committed Apr 24, 2013
2 parents 211f09d + bb502a0 commit 0b5641e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
classinfo = this;
}

#if !MODULEINFO_IS_STRUCT
if (id == Id::ModuleInfo)
{ if (Module::moduleinfo)
Module::moduleinfo->error("%s", msg);
Module::moduleinfo = this;
}
#endif
}

com = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ int overloadApply(FuncDeclaration *fstart,
int (*fp)(void *, FuncDeclaration *),
void *param);

void ObjectNotFound(Identifier *id);

enum Semantic
{
SemanticStart, // semantic has not been run
Expand Down
2 changes: 1 addition & 1 deletion src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "d-dmd-gcc.h"
#endif

ClassDeclaration *Module::moduleinfo;
AggregateDeclaration *Module::moduleinfo;

Module *Module::rootModule;
DsymbolTable *Module::modules;
Expand Down
2 changes: 1 addition & 1 deletion src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct Module : Package
static unsigned dprogress; // progress resolving the deferred list
static void init();

static ClassDeclaration *moduleinfo;
static AggregateDeclaration *moduleinfo;


const char *arg; // original argument name
Expand Down
2 changes: 0 additions & 2 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
#include "hdrgen.h"

FuncDeclaration *hasThis(Scope *sc);
void ObjectNotFound(Identifier *id);


#define LOGDOTEXP 0 // log ::dotExp()
#define LOGDEFAULTINIT 0 // log ::defaultInit()
Expand Down
8 changes: 8 additions & 0 deletions src/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ StructDeclaration::StructDeclaration(Loc loc, Identifier *id)

// For forward references
type = new TypeStruct(this);

#if MODULEINFO_IS_STRUCT
if (id == Id::ModuleInfo)
{ if (Module::moduleinfo)
Module::moduleinfo->error("only object.d can define this reserved struct name");
Module::moduleinfo = this;
}
#endif
}

Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s)
Expand Down
5 changes: 5 additions & 0 deletions src/toobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ void Module::genmoduleinfo()
{
//printf("Module::genmoduleinfo() %s\n", toChars());

if (! Module::moduleinfo)
{
ObjectNotFound(Id::ModuleInfo);
}

Symbol *msym = toSymbol();
#if DMDV2
unsigned sizeof_ModuleInfo = 16 * Target::ptrsize;
Expand Down

0 comments on commit 0b5641e

Please sign in to comment.