Skip to content

Commit

Permalink
dmd 0.101
Browse files Browse the repository at this point in the history
  • Loading branch information
braddr committed Jul 2, 2009
1 parent 6346f36 commit 8b88849
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 72 deletions.
6 changes: 4 additions & 2 deletions src/cast.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ Expression *StringExp::castTo(Type *t)
error(p); error(p);
else else
buffer.writeUTF16(c); buffer.writeUTF16(c);
newlen++;
} }
newlen = buffer.offset / 2;
buffer.writeUTF16(0); buffer.writeUTF16(0);
goto L1; goto L1;


Expand All @@ -438,8 +438,8 @@ Expression *StringExp::castTo(Type *t)
error(p); error(p);
else else
buffer.writeUTF8(c); buffer.writeUTF8(c);
newlen++;
} }
newlen = buffer.offset;
buffer.writeUTF8(0); buffer.writeUTF8(0);
goto L1; goto L1;


Expand All @@ -465,6 +465,7 @@ Expression *StringExp::castTo(Type *t)
buffer.writeUTF8(c); buffer.writeUTF8(c);
newlen++; newlen++;
} }
newlen = buffer.offset;
buffer.writeUTF8(0); buffer.writeUTF8(0);
goto L1; goto L1;


Expand All @@ -478,6 +479,7 @@ Expression *StringExp::castTo(Type *t)
buffer.writeUTF16(c); buffer.writeUTF16(c);
newlen++; newlen++;
} }
newlen = buffer.offset / 2;
buffer.writeUTF16(0); buffer.writeUTF16(0);
goto L1; goto L1;


Expand Down
69 changes: 38 additions & 31 deletions src/debcond.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,8 +15,27 @@
#include "expression.h" #include "expression.h"
#include "debcond.h" #include "debcond.h"


Condition::Condition(unsigned level, Identifier *ident) int findCondition(Array *ids, Identifier *ident)
{ {
if (ids)
{
for (int i = 0; i < ids->dim; i++)
{
char *id = (char *)ids->data[i];

if (strcmp(id, ident->toChars()) == 0)
return TRUE;
}
}

return FALSE;
}

/* ============================================================ */

Condition::Condition(Module *mod, unsigned level, Identifier *ident)
{
this->mod = mod;
this->level = level; this->level = level;
this->ident = ident; this->ident = ident;
} }
Expand Down Expand Up @@ -48,21 +67,21 @@ void Condition::toCBuffer(OutBuffer *buf)


/* ============================================================ */ /* ============================================================ */


void DebugCondition::setLevel(unsigned level) void DebugCondition::setGlobalLevel(unsigned level)
{ {
global.params.debuglevel = level; global.params.debuglevel = level;
} }


void DebugCondition::addIdent(char *ident) void DebugCondition::addGlobalIdent(char *ident)
{ {
if (!global.params.debugids) if (!global.params.debugids)
global.params.debugids = new Array(); global.params.debugids = new Array();
global.params.debugids->push(ident); global.params.debugids->push(ident);
} }




DebugCondition::DebugCondition(unsigned level, Identifier *ident) DebugCondition::DebugCondition(Module *mod, unsigned level, Identifier *ident)
: Condition(level, ident) : Condition(mod, level, ident)
{ {
} }


Expand All @@ -71,61 +90,49 @@ int DebugCondition::include()
//printf("DebugCondition::include() level = %d, debuglevel = %d\n", level, global.params.debuglevel); //printf("DebugCondition::include() level = %d, debuglevel = %d\n", level, global.params.debuglevel);
if (ident) if (ident)
{ {
if (global.params.debugids) if (findCondition(mod->debugids, ident))
{ return TRUE;
for (int i = 0; i < global.params.debugids->dim; i++)
{
char *id = (char *)global.params.debugids->data[i];


if (strcmp(id, ident->toChars()) == 0) if (findCondition(global.params.debugids, ident))
return TRUE; return TRUE;
}
}
} }
else if (level <= global.params.debuglevel) else if (level <= global.params.debuglevel || level <= mod->debuglevel)
return TRUE; return TRUE;
return FALSE; return FALSE;
} }


/* ============================================================ */ /* ============================================================ */


void VersionCondition::setLevel(unsigned level) void VersionCondition::setGlobalLevel(unsigned level)
{ {
global.params.versionlevel = level; global.params.versionlevel = level;
} }


void VersionCondition::addIdent(char *ident) void VersionCondition::addGlobalIdent(char *ident)
{ {
if (!global.params.versionids) if (!global.params.versionids)
global.params.versionids = new Array(); global.params.versionids = new Array();
global.params.versionids->push(ident); global.params.versionids->push(ident);
} }




VersionCondition::VersionCondition(unsigned level, Identifier *ident) VersionCondition::VersionCondition(Module *mod, unsigned level, Identifier *ident)
: Condition(level, ident) : Condition(mod, level, ident)
{ {
this->level = level;
this->ident = ident;
} }


int VersionCondition::include() int VersionCondition::include()
{ {
//printf("VersionCondition::include() level = %d, versionlevel = %d\n", level, global.params.versionlevel); //printf("VersionCondition::include() level = %d, versionlevel = %d\n", level, global.params.versionlevel);
if (ident) if (ident)
{ {
if (global.params.versionids) if (findCondition(mod->versionids, ident))
{ return TRUE;
for (int i = 0; i < global.params.versionids->dim; i++)
{
char *id = (char *)global.params.versionids->data[i];


if (strcmp(id, ident->toChars()) == 0) if (findCondition(global.params.versionids, ident))
return TRUE; return TRUE;
}
}
} }
else if (level <= global.params.versionlevel) else if (level <= global.params.versionlevel || level <= mod->versionlevel)
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
Expand Down
16 changes: 9 additions & 7 deletions src/debcond.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
struct Expression; struct Expression;
struct Identifier; struct Identifier;
struct OutBuffer; struct OutBuffer;
struct Module;


struct Condition struct Condition
{ {
unsigned level; unsigned level;
Identifier *ident; Identifier *ident;
Module *mod;


Condition(unsigned level, Identifier *ident); Condition(Module *mod, unsigned level, Identifier *ident);


virtual int include(); virtual int include();
int isBool(int result); int isBool(int result);
Expand All @@ -29,20 +31,20 @@ struct Condition


struct DebugCondition : Condition struct DebugCondition : Condition
{ {
static void setLevel(unsigned level); static void setGlobalLevel(unsigned level);
static void addIdent(char *ident); static void addGlobalIdent(char *ident);


DebugCondition(unsigned level, Identifier *ident); DebugCondition(Module *mod, unsigned level, Identifier *ident);


int include(); int include();
}; };


struct VersionCondition : Condition struct VersionCondition : Condition
{ {
static void setLevel(unsigned level); static void setGlobalLevel(unsigned level);
static void addIdent(char *ident); static void addGlobalIdent(char *ident);


VersionCondition(unsigned level, Identifier *ident); VersionCondition(Module *mod, unsigned level, Identifier *ident);


int include(); int include();
}; };
Expand Down
3 changes: 2 additions & 1 deletion src/expression.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2766,7 +2766,8 @@ if (arguments && arguments->dim)
// See if we need to adjust the 'this' pointer // See if we need to adjust the 'this' pointer
AggregateDeclaration *ad = f->isThis(); AggregateDeclaration *ad = f->isThis();
ClassDeclaration *cd = dve->e1->type->isClassHandle(); ClassDeclaration *cd = dve->e1->type->isClassHandle();
if (ad && cd && ad->isClassDeclaration() && ad != cd) if (ad && cd && ad->isClassDeclaration() && ad != cd &&
dve->e1->op != TOKsuper)
{ {
dve->e1 = new CastExp(loc, dve->e1, ad->type); dve->e1 = new CastExp(loc, dve->e1, ad->type);
dve->e1 = dve->e1->semantic(sc); dve->e1 = dve->e1->semantic(sc);
Expand Down
1 change: 1 addition & 0 deletions src/func.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ FuncLiteralDeclaration::FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type,
enum TOK tok, ForeachStatement *fes) enum TOK tok, ForeachStatement *fes)
: FuncDeclaration(loc, endloc, NULL, STCundefined, type) : FuncDeclaration(loc, endloc, NULL, STCundefined, type)
{ {
this->ident = Identifier::generateId("__funclit");
this->tok = tok; this->tok = tok;
this->fes = fes; this->fes = fes;
} }
Expand Down
15 changes: 14 additions & 1 deletion src/identifier.c
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@


// Copyright (c) 1999-2002 by Digital Mars // Copyright (c) 1999-2004 by Digital Mars
// All Rights Reserved // All Rights Reserved
// written by Walter Bright // written by Walter Bright
// www.digitalmars.com // www.digitalmars.com
Expand Down Expand Up @@ -50,3 +50,16 @@ int Identifier::dyncast()
{ {
return DYNCAST_IDENTIFIER; return DYNCAST_IDENTIFIER;
} }

Identifier *Identifier::generateId(char *prefix)
{ OutBuffer buf;
char *id;
static unsigned i;

buf.writestring(prefix);
buf.printf("%u", ++i);

id = buf.toChars();
buf.data = NULL;
return new Identifier(id, TOKidentifier);
}
4 changes: 3 additions & 1 deletion src/identifier.h
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@


// Copyright (c) 1999-2002 by Digital Mars // Copyright (c) 1999-2004 by Digital Mars
// All Rights Reserved // All Rights Reserved
// written by Walter Bright // written by Walter Bright
// www.digitalmars.com // www.digitalmars.com
Expand Down Expand Up @@ -28,6 +28,8 @@ struct Identifier : Object
void print(); void print();
char *toChars(); char *toChars();
int dyncast(); int dyncast();

static Identifier *generateId(char *prefix);
}; };


#endif /* DMD_IDENTIFIER_H */ #endif /* DMD_IDENTIFIER_H */
2 changes: 2 additions & 0 deletions src/lexer.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Lexer::Lexer(Module *mod, unsigned char *base, unsigned length)
this->base = base; this->base = base;
this->end = base + length; this->end = base + length;
p = base; p = base;
this->mod = mod;
//initKeywords(); //initKeywords();
} }


Expand Down Expand Up @@ -2088,4 +2089,5 @@ void Lexer::initKeywords()
Token::tochars[TOKdotvar] = "dotvar"; Token::tochars[TOKdotvar] = "dotvar";
Token::tochars[TOKsymoff] = "symoff"; Token::tochars[TOKsymoff] = "symoff";
Token::tochars[TOKtypedot] = "typedot"; Token::tochars[TOKtypedot] = "typedot";
Token::tochars[TOKarraylength] = "arraylength";
} }
1 change: 1 addition & 0 deletions src/lexer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ struct Lexer
unsigned char *end; // past end of buffer unsigned char *end; // past end of buffer
unsigned char *p; // current character unsigned char *p; // current character
Token token; Token token;
Module *mod;


Lexer(Module *mod, unsigned char *base, unsigned length); Lexer(Module *mod, unsigned char *base, unsigned length);


Expand Down
24 changes: 12 additions & 12 deletions src/mars.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Global::Global()


copyright = "Copyright (c) 1999-2004 by Digital Mars"; copyright = "Copyright (c) 1999-2004 by Digital Mars";
written = "written by Walter Bright"; written = "written by Walter Bright";
version = "v0.100"; version = "v0.101";
global.structalign = 8; global.structalign = 8;


memset(&params, 0, sizeof(Param)); memset(&params, 0, sizeof(Param));
Expand Down Expand Up @@ -181,18 +181,18 @@ int main(int argc, char *argv[])
global.params.objfiles = new Array(); global.params.objfiles = new Array();


// Predefine version identifiers // Predefine version identifiers
VersionCondition::addIdent("DigitalMars"); VersionCondition::addGlobalIdent("DigitalMars");
#if _WIN32 #if _WIN32
VersionCondition::addIdent("Windows"); VersionCondition::addGlobalIdent("Windows");
VersionCondition::addIdent("Win32"); VersionCondition::addGlobalIdent("Win32");
#endif #endif
#if linux #if linux
VersionCondition::addIdent("linux"); VersionCondition::addGlobalIdent("linux");
global.params.isLinux = 1; global.params.isLinux = 1;
#endif /* linux */ #endif /* linux */
VersionCondition::addIdent("X86"); VersionCondition::addGlobalIdent("X86");
VersionCondition::addIdent("LittleEndian"); VersionCondition::addGlobalIdent("LittleEndian");
VersionCondition::addIdent("D_InlineAsm"); VersionCondition::addGlobalIdent("D_InlineAsm");


#if _WIN32 #if _WIN32
inifile(argv[0], "sc.ini"); inifile(argv[0], "sc.ini");
Expand Down Expand Up @@ -275,9 +275,9 @@ int main(int argc, char *argv[])
if (p[6] == '=') if (p[6] == '=')
{ {
if (isdigit(p[7])) if (isdigit(p[7]))
DebugCondition::setLevel(atoi(p + 7)); DebugCondition::setGlobalLevel(atoi(p + 7));
else if (isalpha(p[7])) else if (isalpha(p[7]))
DebugCondition::addIdent(p + 7); DebugCondition::addGlobalIdent(p + 7);
else else
goto Lerror; goto Lerror;
} }
Expand All @@ -292,9 +292,9 @@ int main(int argc, char *argv[])
if (p[8] == '=') if (p[8] == '=')
{ {
if (isdigit(p[9])) if (isdigit(p[9]))
VersionCondition::setLevel(atoi(p + 9)); VersionCondition::setGlobalLevel(atoi(p + 9));
else if (isalpha(p[9])) else if (isalpha(p[9]))
VersionCondition::addIdent(p + 9); VersionCondition::addGlobalIdent(p + 9);
else else
goto Lerror; goto Lerror;
} }
Expand Down
5 changes: 5 additions & 0 deletions src/module.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Module::Module(char *filename, Identifier *ident)
sfilename = NULL; sfilename = NULL;
importedFrom = this; importedFrom = this;


debuglevel = 0;
debugids = NULL;
versionlevel = 0;
versionids = NULL;

srcfilename = FileName::defaultExt(filename, global.mars_ext); srcfilename = FileName::defaultExt(filename, global.mars_ext);
if (!srcfilename->equalsExt(global.mars_ext)) if (!srcfilename->equalsExt(global.mars_ext))
{ {
Expand Down
12 changes: 10 additions & 2 deletions src/module.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct Module : Package


static ClassDeclaration *moduleinfo; static ClassDeclaration *moduleinfo;



const char *arg; // original argument name const char *arg; // original argument name
ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
File *srcfile; // input source file File *srcfile; // input source file
Expand All @@ -53,15 +54,22 @@ struct Module : Package
int isHtml; // if it is an HTML file int isHtml; // if it is an HTML file
int needmoduleinfo; int needmoduleinfo;
int insearch; int insearch;
int semanticdone; // has semantic() been done? int semanticdone; // has semantic() been done?
Module *importedFrom; // module from command line we're imported from, Module *importedFrom; // module from command line we're imported from,
// i.e. a module that will be taken all the // i.e. a module that will be taken all the
// way to an object file // way to an object file


Array *decldefs; // top level declarations for this Module Array *decldefs; // top level declarations for this Module


ModuleInfoDeclaration *vmoduleinfo; ModuleInfoDeclaration *vmoduleinfo;


unsigned debuglevel; // debug level
Array *debugids; // debug identifiers

unsigned versionlevel; // version level
Array *versionids; // version identifiers


Module(char *arg, Identifier *ident); Module(char *arg, Identifier *ident);
~Module(); ~Module();


Expand Down
Loading

0 comments on commit 8b88849

Please sign in to comment.