Mercurial > projects > dil
changeset 260:b83180748ae6
- Added method parseAlignAttribute().
- Fix in parseStatement(): the align attribute can only be followed by a struct declaration.
author | aziz |
---|---|
date | Fri, 03 Aug 2007 08:44:03 +0000 |
parents | 8118da6fee44 |
children | 966756c5d5d3 |
files | trunk/src/Parser.d |
diffstat | 1 files changed, 34 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Parser.d Fri Aug 03 08:04:03 2007 +0000 +++ b/trunk/src/Parser.d Fri Aug 03 08:44:03 2007 +0000 @@ -619,6 +619,26 @@ return parse()[0]; } + Token* parseAlignAttribute() + { + assert(token.type == T.Align); + nT(); // Skip align keyword. + Token* tok; + if (token.type == T.LParen) + { + nT(); + if (token.type == T.Int32) + { + tok = token; + nT(); + } + else + expected(T.Int32); + require(T.RParen); + } + return tok; + } + Declaration parseAttributeSpecifier() { Declaration decl; @@ -626,20 +646,10 @@ switch (token.type) { case T.Align: - nT(); int size = -1; - if (token.type == T.LParen) - { - nT(); - if (token.type == T.Int32) - { - size = token.int_; - nT(); - } - else - expected(T.Int32); - require(T.RParen); - } + auto intTok = parseAlignAttribute(); + if (intTok) + size = intTok.int_; decl = new AlignDeclaration(size, parseDeclarationsBlock()); break; case T.Pragma: @@ -1468,14 +1478,22 @@ Statement parseStatement() { // writefln("°parseStatement:(%d)token='%s'°", lx.loc, token.srcText); - Statement s; Declaration d; switch (token.type) { case T.Align: - // TODO: don't call parseAttributeSpecifier(). - d = parseAttributeSpecifier(); + int size = -1; + auto intTok = parseAlignAttribute(); + if (intTok) + size = intTok.int_; + // Restrict align attribute to structs in parsing phase. + Declaration structDecl; + if (token.type == T.Struct) + structDecl = parseAggregateDeclaration(); + else + expected(T.Struct); + d = new AlignDeclaration(size, structDecl ? [structDecl] : null); goto case_DeclarationStatement; /+ Not applicable for statements. // T.Private,