Merge 1.072

This commit is contained in:
kai
2012-02-02 03:13:27 +01:00
parent 81082996e1
commit f9201e8352
72 changed files with 7739 additions and 3484 deletions

View File

@@ -1,6 +1,6 @@
// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -68,9 +68,9 @@ Parser::Parser(Module *module, unsigned char *base, unsigned length, int doDocCo
//nextToken(); // start up the scanner
}
Array *Parser::parseModule()
Dsymbols *Parser::parseModule()
{
Array *decldefs;
Dsymbols *decldefs;
// ModuleDeclation leads off
if (token.value == TOKmodule)
@@ -103,14 +103,14 @@ Array *Parser::parseModule()
}
else
{
Array *a = NULL;
Identifiers *a = NULL;
Identifier *id;
id = token.ident;
while (nextToken() == TOKdot)
{
if (!a)
a = new Array();
a = new Identifiers();
a->push(id);
nextToken();
if (token.value != TOKidentifier)
@@ -138,21 +138,21 @@ Lerr:
while (token.value != TOKsemicolon && token.value != TOKeof)
nextToken();
nextToken();
return new Array();
return new Dsymbols();
}
Array *Parser::parseDeclDefs(int once)
Dsymbols *Parser::parseDeclDefs(int once)
{ Dsymbol *s;
Array *decldefs;
Array *a;
Array *aelse;
Dsymbols *decldefs;
Dsymbols *a;
Dsymbols *aelse;
enum PROT prot;
StorageClass stc;
Condition *condition;
unsigned char *comment;
//printf("Parser::parseDeclDefs()\n");
decldefs = new Array();
decldefs = new Dsymbols();
do
{
comment = token.blockComment;
@@ -396,10 +396,10 @@ Array *Parser::parseDeclDefs(int once)
if (token.value == TOKlparen)
{
nextToken();
if (token.value == TOKint32v)
if (token.value == TOKint32v && token.uns64value > 0)
n = (unsigned)token.uns64value;
else
{ error("integer expected, not %s", token.toChars());
{ error("positive integer expected, not %s", token.toChars());
n = 1;
}
nextToken();
@@ -445,7 +445,7 @@ Array *Parser::parseDeclDefs(int once)
nextToken();
if (token.value == TOKidentifier)
s = new DebugSymbol(loc, token.ident);
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
s = new DebugSymbol(loc, (unsigned)token.uns64value);
else
{ error("identifier or integer expected, not %s", token.toChars());
@@ -466,7 +466,7 @@ Array *Parser::parseDeclDefs(int once)
nextToken();
if (token.value == TOKidentifier)
s = new VersionSymbol(loc, token.ident);
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
s = new VersionSymbol(loc, (unsigned)token.uns64value);
else
{ error("identifier or integer expected, not %s", token.toChars());
@@ -528,14 +528,43 @@ void Parser::composeStorageClass(StorageClass stc)
}
#endif
/***********************************************
* Parse storage class, lexer is on '@'
*/
#if DMDV2
StorageClass Parser::parseAttribute()
{
nextToken();
StorageClass stc = 0;
if (token.value != TOKidentifier)
{
error("identifier expected after @, not %s", token.toChars());
}
else if (token.ident == Id::property)
stc = STCproperty;
else if (token.ident == Id::safe)
stc = STCsafe;
else if (token.ident == Id::trusted)
stc = STCtrusted;
else if (token.ident == Id::system)
stc = STCsystem;
else if (token.ident == Id::disable)
stc = STCdisable;
else
error("valid attribute identifiers are @property, @safe, @trusted, @system, @disable not @%s", token.toChars());
return stc;
}
#endif
/********************************************
* Parse declarations after an align, protection, or extern decl.
*/
Array *Parser::parseBlock()
Dsymbols *Parser::parseBlock()
{
Array *a = NULL;
Dsymbol *s;
Dsymbols *a = NULL;
//printf("parseBlock()\n");
switch (token.value)
@@ -692,7 +721,7 @@ Condition *Parser::parseDebugCondition()
if (token.value == TOKidentifier)
id = token.ident;
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
level = (unsigned)token.uns64value;
else
error("identifier or integer expected, not %s", token.toChars());
@@ -721,7 +750,7 @@ Condition *Parser::parseVersionCondition()
nextToken();
if (token.value == TOKidentifier)
id = token.ident;
else if (token.value == TOKint32v)
else if (token.value == TOKint32v || token.value == TOKint64v)
level = (unsigned)token.uns64value;
#if DMDV2
/* Allow:
@@ -754,8 +783,6 @@ Condition *Parser::parseVersionCondition()
Condition *Parser::parseStaticIfCondition()
{ Expression *exp;
Condition *condition;
Array *aif;
Array *aelse;
Loc loc = this->loc;
nextToken();
@@ -1110,7 +1137,7 @@ EnumDeclaration *Parser::parseEnum()
else if (token.value == TOKlcurly)
{
//printf("enum definition\n");
e->members = new Array();
e->members = new Dsymbols();
nextToken();
unsigned char *comment = token.blockComment;
while (token.value != TOKrcurly)
@@ -1237,7 +1264,7 @@ Dsymbol *Parser::parseAggregate()
{
//printf("aggregate definition\n");
nextToken();
Array *decl = parseDeclDefs(0);
Dsymbols *decl = parseDeclDefs(0);
if (token.value != TOKrcurly)
error("} expected following member declarations in aggregate");
nextToken();
@@ -1259,7 +1286,7 @@ Dsymbol *Parser::parseAggregate()
if (tpl)
{ // Wrap a template around the aggregate declaration
Array *decldefs = new Array();
Dsymbols *decldefs = new Dsymbols();
decldefs->push(a);
TemplateDeclaration *tempdecl =
new TemplateDeclaration(loc, id, tpl, constraint, decldefs);
@@ -1338,7 +1365,7 @@ TemplateDeclaration *Parser::parseTemplateDeclaration()
TemplateDeclaration *tempdecl;
Identifier *id;
TemplateParameters *tpl;
Array *decldefs;
Dsymbols *decldefs;
Loc loc = this->loc;
nextToken();
@@ -1535,7 +1562,7 @@ Dsymbol *Parser::parseMixin()
Identifier *id;
Type *tqual;
Objects *tiargs;
Array *idents;
Identifiers *idents;
//printf("parseMixin()\n");
nextToken();
@@ -1566,7 +1593,7 @@ Dsymbol *Parser::parseMixin()
nextToken();
}
idents = new Array();
idents = new Identifiers();
while (1)
{
tiargs = NULL;
@@ -1659,7 +1686,7 @@ Import *Parser::parseImport(Array *decldefs, int isstatic)
{ Import *s;
Identifier *id;
Identifier *aliasid = NULL;
Array *a;
Identifiers *a;
Loc loc;
//printf("Parser::parseImport()\n");
@@ -1684,7 +1711,7 @@ Import *Parser::parseImport(Array *decldefs, int isstatic)
while (token.value == TOKdot)
{
if (!a)
a = new Array();
a = new Identifiers();
a->push(id);
nextToken();
if (token.value != TOKidentifier)
@@ -2143,7 +2170,7 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
* Return array of Declaration *'s.
*/
Array *Parser::parseDeclarations()
Dsymbols *Parser::parseDeclarations()
{
StorageClass storage_class;
StorageClass stc;
@@ -2151,7 +2178,7 @@ Array *Parser::parseDeclarations()
Type *t;
Type *tfirst;
Identifier *ident;
Array *a;
Dsymbols *a;
enum TOK tok = TOKreserved;
unsigned char *comment = token.blockComment;
enum LINK link = linkage;
@@ -2213,7 +2240,7 @@ Array *Parser::parseDeclarations()
break;
}
a = new Array();
a = new Dsymbols();
/* Look for auto initializers:
* storage_class identifier = initializer;
@@ -2300,7 +2327,7 @@ Array *Parser::parseDeclarations()
a->push(v);
else
{
Array *ax = new Array();
Dsymbols *ax = new Dsymbols();
ax->push(v);
Dsymbol *s = new LinkDeclaration(link, ax);
a->push(s);
@@ -2334,14 +2361,14 @@ Array *Parser::parseDeclarations()
}
else
{
Array *ax = new Array();
Dsymbols *ax = new Dsymbols();
ax->push(f);
s = new LinkDeclaration(link, ax);
}
if (tpl) // it's a function template
{
// Wrap a template around the aggregate declaration
Array *decldefs = new Array();
Dsymbols *decldefs = new Dsymbols();
decldefs->push(s);
TemplateDeclaration *tempdecl =
new TemplateDeclaration(loc, s->ident, tpl, NULL, decldefs);
@@ -2365,7 +2392,7 @@ Array *Parser::parseDeclarations()
a->push(v);
else
{
Array *ax = new Array();
Dsymbols *ax = new Dsymbols();
ax->push(v);
Dsymbol *s = new LinkDeclaration(link, ax);
a->push(s);
@@ -2585,7 +2612,7 @@ Initializer *Parser::parseInitializer()
is = new StructInitializer(loc);
nextToken();
comma = 0;
comma = 2;
while (1)
{
switch (token.value)
@@ -2609,6 +2636,8 @@ Initializer *Parser::parseInitializer()
continue;
case TOKcomma:
if (comma == 2)
error("expression expected, not ','");
nextToken();
comma = 2;
continue;
@@ -2622,6 +2651,8 @@ Initializer *Parser::parseInitializer()
break;
default:
if (comma == 1)
error("comma expected separating field initializers");
value = parseInitializer();
is->addInit(NULL, value);
comma = 1;
@@ -2670,7 +2701,7 @@ Initializer *Parser::parseInitializer()
ia = new ArrayInitializer(loc);
nextToken();
comma = 0;
comma = 2;
while (1)
{
switch (token.value)
@@ -2707,6 +2738,8 @@ Initializer *Parser::parseInitializer()
continue;
case TOKcomma:
if (comma == 2)
error("expression expected, not ','");
nextToken();
comma = 2;
continue;
@@ -2909,10 +2942,10 @@ Statement *Parser::parseStatement(int flags)
{
Statements *as = new Statements();
as->reserve(a->dim);
for (int i = 0; i < a->dim; i++)
for (size_t i = 0; i < a->dim; i++)
{
Dsymbol *d = (Dsymbol *)a->data[i];
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
as->push(s);
}
s = new CompoundDeclarationStatement(loc, as);
@@ -2920,7 +2953,7 @@ Statement *Parser::parseStatement(int flags)
else if (a->dim == 1)
{
Dsymbol *d = (Dsymbol *)a->data[0];
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
}
else
assert(0);
@@ -2936,7 +2969,7 @@ Statement *Parser::parseStatement(int flags)
{ Dsymbol *d;
d = parseAggregate();
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
break;
}
@@ -2944,7 +2977,7 @@ Statement *Parser::parseStatement(int flags)
{ Dsymbol *d;
d = parseEnum();
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
break;
}
@@ -2952,16 +2985,21 @@ Statement *Parser::parseStatement(int flags)
{ t = peek(&token);
if (t->value == TOKlparen)
{ // mixin(string)
nextToken();
check(TOKlparen, "mixin");
Expression *e = parseAssignExp();
check(TOKrparen);
check(TOKsemicolon, "mixin (string)");
s = new CompileStatement(loc, e);
check(TOKsemicolon);
if (e->op == TOKmixin)
{
CompileExp *cpe = (CompileExp *)e;
s = new CompileStatement(loc, cpe->e1);
}
else
{
s = new ExpStatement(loc, e);
}
break;
}
Dsymbol *d = parseMixin();
s = new DeclarationStatement(loc, d);
s = new ExpStatement(loc, d);
break;
}
@@ -2998,7 +3036,7 @@ Statement *Parser::parseStatement(int flags)
if (!(flags & PSsemi))
error("use '{ }' for an empty statement, not a ';'");
nextToken();
s = new ExpStatement(loc, NULL);
s = new ExpStatement(loc, (Expression *)NULL);
break;
case TOKdo:
@@ -3316,7 +3354,7 @@ Statement *Parser::parseStatement(int flags)
s = new ScopeStatement(loc, s);
// Keep cases in order by building the case statements backwards
for (int i = cases.dim; i; i--)
for (size_t i = cases.dim; i; i--)
{
exp = (Expression *)cases.data[i - 1];
s = new CaseStatement(loc, exp, s);
@@ -3707,8 +3745,6 @@ int Parser::isBasicType(Token **pt)
{
// This code parallels parseBasicType()
Token *t = *pt;
Token *t2;
int parens;
switch (t->value)
{
@@ -4157,7 +4193,6 @@ int Parser::skipParens(Token *t, Token **pt)
break;
case TOKeof:
case TOKsemicolon:
goto Lfalse;
default:
@@ -4359,7 +4394,6 @@ Expression *Parser::parsePrimaryExp()
case BASIC_TYPES_X(t):
nextToken();
L1:
check(TOKdot, t->toChars());
if (token.value != TOKidentifier)
{ error("found '%s' when expecting identifier following '%s.'", token.toChars(), t->toChars());
@@ -4676,6 +4710,7 @@ Expression *Parser::parsePostExp(Expression *e)
nextToken();
if (token.value == TOKrbracket)
{ // array[]
inBrackets--;
e = new SliceExp(loc, e, NULL, NULL);
nextToken();
}
@@ -5386,7 +5421,7 @@ Expression *Parser::parseNewExp(Expression *thisexp)
else
{
nextToken();
Array *decl = parseDeclDefs(0);
Dsymbols *decl = parseDeclDefs(0);
if (token.value != TOKrcurly)
error("class member expected");
nextToken();
@@ -5472,7 +5507,7 @@ enum PREC precedence[TOKMAX];
void initPrecedence()
{
for (int i = 0; i < TOKMAX; i++)
for (size_t i = 0; i < TOKMAX; i++)
precedence[i] = PREC_zero;
precedence[TOKtype] = PREC_expr;