Skip to content

Commit

Permalink
[Refactoring] Unify parsing code for linkage, uda, and template param…
Browse files Browse the repository at this point in the history
…eters
  • Loading branch information
9rnsr committed Sep 20, 2014
1 parent c83986a commit bd99c47
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions src/parse.c
Expand Up @@ -3445,14 +3445,10 @@ Dsymbols *Parser::parseDeclarations(bool autodecl, PrefixAttributes *pAttrs, con
error("user defined attributes not allowed for %s declarations", Token::toChars(tok));

t = parseType();
Dsymbol *s = new AliasDeclaration(loc, ident, t);
((Declaration *)s)->storage_class = storage_class;
if (link != linkage)
{
Dsymbols *a2 = new Dsymbols();
a2->push(s);
s = new LinkDeclaration(link, a2);
}
Declaration *v = new AliasDeclaration(loc, ident, t);
v->storage_class = storage_class;

Dsymbol *s = v;
if (tpl)
{
Dsymbols *a2 = new Dsymbols();
Expand All @@ -3461,6 +3457,12 @@ Dsymbols *Parser::parseDeclarations(bool autodecl, PrefixAttributes *pAttrs, con
new TemplateDeclaration(loc, ident, tpl, NULL, a2);
s = tempdecl;
}
if (link != linkage)
{
Dsymbols *a2 = new Dsymbols();
a2->push(s);
s = new LinkDeclaration(link, a2);
}
a->push(s);
switch (token.value)
{
Expand Down Expand Up @@ -3641,15 +3643,15 @@ Dsymbols *Parser::parseDeclarations(bool autodecl, PrefixAttributes *pAttrs, con
v = new AliasDeclaration(loc, ident, t);
}
v->storage_class = storage_class;
if (link == linkage)
a->push(v);
else
Dsymbol *s = v;

if (link != linkage)
{
Dsymbols *ax = new Dsymbols();
ax->push(v);
Dsymbol *s = new LinkDeclaration(link, ax);
a->push(s);
s = new LinkDeclaration(link, ax);
}
a->push(s);
switch (token.value)
{
case TOKsemicolon:
Expand Down Expand Up @@ -3786,8 +3788,8 @@ Dsymbols *Parser::parseDeclarations(bool autodecl, PrefixAttributes *pAttrs, con
ax->push(s);
s = new UserAttributeDeclaration(udas, ax);
}
addComment(s, comment);
a->push(s);
addComment(s, comment);
}
else if (ident)
{
Expand All @@ -3810,7 +3812,6 @@ Dsymbols *Parser::parseDeclarations(bool autodecl, PrefixAttributes *pAttrs, con
new TemplateDeclaration(loc, ident, tpl, NULL, a2, 0);
s = tempdecl;
}

if (link != linkage)
{
Dsymbols *ax = new Dsymbols();
Expand Down Expand Up @@ -3884,28 +3885,30 @@ Dsymbols *Parser::parseAutoDeclarations(StorageClass storageClass, const utf8_t
new TemplateDeclaration(loc, ident, tpl, NULL, a2, 0);
s = tempdecl;
}

a->push(s);
if (token.value == TOKsemicolon)
{
nextToken();
addComment(v, comment);
}
else if (token.value == TOKcomma)
switch (token.value)
{
nextToken();
if (token.value == TOKidentifier &&
skipParensIf(peek(&token), &tk) &&
tk->value == TOKassign)
{
case TOKsemicolon:
nextToken();
addComment(v, comment);
break;

case TOKcomma:
nextToken();
if (!(token.value == TOKidentifier &&
skipParensIf(peek(&token), &tk) &&
tk->value == TOKassign))
{
error("Identifier expected following comma");
break;
}
addComment(v, comment);
continue;
}
else
error("Identifier expected following comma");

default:
error("semicolon expected following auto declaration, not '%s'", token.toChars());
break;
}
else
error("semicolon expected following auto declaration, not '%s'", token.toChars());
break;
}
return a;
Expand Down

0 comments on commit bd99c47

Please sign in to comment.