Fewer TODO comments

This commit is contained in:
Hackerpilot 2013-06-27 22:08:46 -07:00
parent ad8b4fdeaa
commit 859ddd3d20
2 changed files with 129 additions and 100 deletions

View File

@ -58,7 +58,6 @@ abstract class ASTVisitor
/** */ void visit(AssertExpression assertExpression) { assertExpression.accept(this); } /** */ void visit(AssertExpression assertExpression) { assertExpression.accept(this); }
/** */ void visit(AssertStatement assertStatement) { assertStatement.accept(this); } /** */ void visit(AssertStatement assertStatement) { assertStatement.accept(this); }
/** */ void visit(AssignExpression assignExpression) { assignExpression.accept(this); } /** */ void visit(AssignExpression assignExpression) { assignExpression.accept(this); }
/** */ void visit(AssignStatement assignStatement) { assignStatement.accept(this); }
/** */ void visit(AssocArrayLiteral assocArrayLiteral) { assocArrayLiteral.accept(this); } /** */ void visit(AssocArrayLiteral assocArrayLiteral) { assocArrayLiteral.accept(this); }
/** */ void visit(AtAttribute atAttribute) { atAttribute.accept(this); } /** */ void visit(AtAttribute atAttribute) { atAttribute.accept(this); }
/** */ void visit(Attribute attribute) { attribute.accept(this); } /** */ void visit(Attribute attribute) { attribute.accept(this); }
@ -542,18 +541,6 @@ public:
/** */ TokenType operator; /** */ TokenType operator;
} }
///
class AssignStatement : ASTNode
{
public:
mixin(DEFAULT_ACCEPT);
/** */ PreIncDecExpression preIncDecExpression;
/** */ PostIncDecExpression postIncDecExpression;
/** */ UnaryExpression[] unaryExpressions;
/** */ AssignExpression[] assignExpressions;
/** */ TokenType[] assignOperators;
}
/// ///
class AssocArrayLiteral : ASTNode class AssocArrayLiteral : ASTNode
{ {
@ -1482,7 +1469,6 @@ public:
mixin(DEFAULT_ACCEPT); mixin(DEFAULT_ACCEPT);
/** */ LabeledStatement labeledStatement; /** */ LabeledStatement labeledStatement;
/** */ BlockStatement blockStatement; /** */ BlockStatement blockStatement;
/** */ AssignStatement assignStatement;
/** */ IfStatement ifStatement; /** */ IfStatement ifStatement;
/** */ WhileStatement whileStatement; /** */ WhileStatement whileStatement;
/** */ DoStatement doStatement; /** */ DoStatement doStatement;

View File

@ -375,7 +375,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmAndExp parseAsmAndExp() AsmAndExp parseAsmAndExp()
{ {
auto node = new AsmAndExp; auto node = new AsmAndExp;
// TODO // TODO asm
return node; return node;
} }
@ -390,7 +390,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmBrExp parseAsmBrExp() AsmBrExp parseAsmBrExp()
{ {
auto node = new AsmBrExp; auto node = new AsmBrExp;
// TODO // TODO asm
return node; return node;
} }
@ -404,7 +404,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmEqualExp parseAsmEqualExp() AsmEqualExp parseAsmEqualExp()
{ {
auto node = new AsmEqualExp; auto node = new AsmEqualExp;
// TODO // TODO asm
return node; return node;
} }
@ -418,7 +418,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmExp parseAsmExp() AsmExp parseAsmExp()
{ {
auto node = new AsmExp; auto node = new AsmExp;
// TODO // TODO asm
return node; return node;
} }
@ -437,7 +437,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmInstruction parseAsmInstruction() AsmInstruction parseAsmInstruction()
{ {
auto node = new AsmInstruction; auto node = new AsmInstruction;
// TODO // TODO asm
return node; return node;
} }
@ -451,7 +451,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmLogAndExp parseAsmLogAndExp() AsmLogAndExp parseAsmLogAndExp()
{ {
auto node = new AsmLogAndExp; auto node = new AsmLogAndExp;
// TODO // TODO asm
return node; return node;
} }
@ -465,7 +465,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmLogOrExp parseAsmLogOrExp() AsmLogOrExp parseAsmLogOrExp()
{ {
auto node = new AsmLogOrExp; auto node = new AsmLogOrExp;
// TODO // TODO asm
return node; return node;
} }
@ -479,7 +479,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmMulExp parseAsmMulExp() AsmMulExp parseAsmMulExp()
{ {
auto node = new AsmMulExp; auto node = new AsmMulExp;
// TODO // TODO asm
return node; return node;
} }
@ -493,7 +493,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmOrExp parseAsmOrExp() AsmOrExp parseAsmOrExp()
{ {
auto node = new AsmOrExp; auto node = new AsmOrExp;
// TODO // TODO asm
return node; return node;
} }
@ -511,7 +511,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmPrimaryExp parseAsmPrimaryExp() AsmPrimaryExp parseAsmPrimaryExp()
{ {
auto node = new AsmPrimaryExp; auto node = new AsmPrimaryExp;
// TODO // TODO asm
return node; return node;
} }
@ -525,7 +525,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmRelExp parseAsmRelExp() AsmRelExp parseAsmRelExp()
{ {
auto node = new AsmRelExp; auto node = new AsmRelExp;
// TODO // TODO asm
return node; return node;
} }
@ -539,7 +539,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmShiftExp parseAsmShiftExp() AsmShiftExp parseAsmShiftExp()
{ {
auto node = new AsmShiftExp; auto node = new AsmShiftExp;
// TODO // TODO asm
return node; return node;
} }
@ -553,7 +553,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmStatement parseAsmStatement() AsmStatement parseAsmStatement()
{ {
auto node = new AsmStatement; auto node = new AsmStatement;
// TODO // TODO asm
return node; return node;
} }
@ -573,7 +573,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmTypePrefix parseAsmTypePrefix() AsmTypePrefix parseAsmTypePrefix()
{ {
auto node = new AsmTypePrefix; auto node = new AsmTypePrefix;
// TODO // TODO asm
return node; return node;
} }
@ -593,7 +593,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmUnaExp parseAsmUnaExp() AsmUnaExp parseAsmUnaExp()
{ {
auto node = new AsmUnaExp; auto node = new AsmUnaExp;
// TODO // TODO asm
return node; return node;
} }
@ -607,7 +607,7 @@ alias core.sys.posix.stdio.fileno fileno;
AsmXorExp parseAsmXorExp() AsmXorExp parseAsmXorExp()
{ {
auto node = new AsmXorExp; auto node = new AsmXorExp;
// TODO // TODO asm
return node; return node;
} }
@ -674,21 +674,6 @@ alias core.sys.posix.stdio.fileno fileno;
return node; return node;
} }
/**
* Parses an AssignStatement
*
* $(GRAMMAR $(RULEDEF assignStatement):
* $(RULE unaryExpression) $(RULE assignOperator) $(RULE assignExpression) ($(LITERAL ',') $(RULE unaryExpression) $(RULE assignOperator) $(RULE assignExpression))* $(LITERAL ';')
* ;)
*/
AssignStatement parseAssignStatement()
{
auto node = new AssignStatement;
// TODO
if (expect(TokenType.semicolon) is null) return null;
return node;
}
/** /**
* Parses an AssocArrayLiteral * Parses an AssocArrayLiteral
* *
@ -855,7 +840,22 @@ alias core.sys.posix.stdio.fileno fileno;
AutoDeclaration parseAutoDeclaration() AutoDeclaration parseAutoDeclaration()
{ {
auto node = new AutoDeclaration; auto node = new AutoDeclaration;
// TODO node.storageClass = parseStorageClass();
if (node.storageClass is null) return null;
do
{
auto ident = expect(TokenType.identifier);
if (ident is null) return null;
node.identifiers ~= *ident;
if (expect(TokenType.assign) is null) return null;
auto init = parseInitializer();
if (init is null) return null;
node.initializers ~= init;
if (currentIs(TokenType.comma))
advance();
else
break;
} while (true);
return node; return node;
} }
@ -1260,8 +1260,8 @@ incorrect;
auto node = new ClassDeclaration; auto node = new ClassDeclaration;
expect(TokenType.class_); expect(TokenType.class_);
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.name = *ident; node.name = *ident;
if (currentIs(TokenType.lParen)) if (currentIs(TokenType.lParen))
{ {
node.templateParameters = parseTemplateParameters(); node.templateParameters = parseTemplateParameters();
@ -1726,10 +1726,10 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
break; break;
case auto_: case auto_:
if (startsWith(auto_, ref_, identifier, lParen) if (startsWith(auto_, ref_, identifier, lParen)
|| startsWith(auto_, identifier, lParen)) || startsWith(auto_, identifier, lParen))
node.functionDeclaration = parseFunctionDeclaration(); node.functionDeclaration = parseFunctionDeclaration();
else else
node.variableDeclaration = parseVariableDeclaration(); node.variableDeclaration = parseVariableDeclaration();
break; break;
case ref_: case ref_:
if (startsWith(ref_, auto_, identifier, lParen) if (startsWith(ref_, auto_, identifier, lParen)
@ -1786,7 +1786,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
DeclarationsAndStatements parseDeclarationsAndStatements() DeclarationsAndStatements parseDeclarationsAndStatements()
{ {
auto node = new DeclarationsAndStatements; auto node = new DeclarationsAndStatements;
while (!currentIsOneOf(TokenType.rBrace) && moreTokens()) while (!currentIsOneOf(TokenType.rBrace) && moreTokens())
{ {
auto dos = new DeclarationOrStatement; auto dos = new DeclarationOrStatement;
// "Any ambiguities in the grammar between Statements and // "Any ambiguities in the grammar between Statements and
@ -1874,7 +1874,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
{ {
auto node = new DeleteExpression; auto node = new DeleteExpression;
if (expect(TokenType.delete_) is null) return null; if (expect(TokenType.delete_) is null) return null;
node.unaryExpression = parseUnaryExpression(); node.unaryExpression = parseUnaryExpression();
return node; return node;
} }
@ -2014,7 +2014,7 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
EnumMember parseEnumMember() EnumMember parseEnumMember()
{ {
auto node = new EnumMember; auto node = new EnumMember;
// TODO // TODO: ambiguity between type and identifier
return node; return node;
} }
@ -2103,13 +2103,17 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
*/ */
ForStatement parseForStatement() ForStatement parseForStatement()
{ {
// forStatement:
// 'for' '(' declarationOrStatement expression? ';' expression? ')' statementNoCaseNoDefault
// ;
auto node = new ForStatement; auto node = new ForStatement;
expect(TokenType.for_); if (expect(TokenType.for_) is null) return null;
expect(TokenType.lParen); if (expect(TokenType.lParen) is null) return null;
// TODO // TODO
assert (0); assert (0);
expect(TokenType.rParen); if (expect(TokenType.rParen) is null) return null;
node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault(); node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault();
if (node.statementNoCaseNoDefault is null) return null;
return node; return node;
} }
@ -2130,25 +2134,25 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
else else
if (expect(TokenType.foreach_reverse_) is null) return null; if (expect(TokenType.foreach_reverse_) is null) return null;
if (expect(TokenType.lParen) is null) return null; if (expect(TokenType.lParen) is null) return null;
auto feType = parseForeachTypeList(); auto feType = parseForeachTypeList();
bool canBeRange = feType.items.length == 0; bool canBeRange = feType.items.length == 0;
expect(TokenType.semicolon); expect(TokenType.semicolon);
node.low = parseExpression(); node.low = parseExpression();
if (node.low is null) return null; if (node.low is null) return null;
if (currentIs(TokenType.slice)) if (currentIs(TokenType.slice))
{ {
if (!canBeRange) if (!canBeRange)
{ {
error(`Cannot have more than one foreach varible for a foreach range statement`); error(`Cannot have more than one foreach varible for a foreach range statement`);
return null; return null;
} }
advance(); advance();
node.high = parseExpression(); node.high = parseExpression();
if (node.high is null) return null; if (node.high is null) return null;
} }
if (expect(TokenType.rParen) is null) return null; if (expect(TokenType.rParen) is null) return null;
node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault(); node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault();
if (node.statementNoCaseNoDefault is null) return null; if (node.statementNoCaseNoDefault is null) return null;
return node; return node;
} }
@ -2417,7 +2421,31 @@ body {} // six
FunctionLiteralExpression parseFunctionLiteralExpression() FunctionLiteralExpression parseFunctionLiteralExpression()
{ {
auto node = new FunctionLiteralExpression; auto node = new FunctionLiteralExpression;
// TODO if (currentIsOneOf(TokenType.function_, TokenType.delegate_))
{
node.functionOrDelegate = advance().type;
if (!currentIsOneOf(TokenType.lParen, TokenType.in_, TokenType.body_,
TokenType.out_, TokenType.rBrace))
{
node.type = parseType();
if (node.type is null) return null;
}
}
if (currentIs(TokenType.lParen))
{
node.parameters = parseParameters();
if (node.parameters is null) return null;
do
{
auto attr = parseFunctionAttribute(false);
if (attr is null)
break;
else
node.functionAttributes ~= attr;
} while (true);
}
node.functionBody = parseFunctionBody();
if (node.functionBody is null) return null;
return node; return node;
} }
@ -2501,8 +2529,8 @@ body {} // six
auto node = new IdentifierList; auto node = new IdentifierList;
do do
{ {
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.identifiers ~= *ident; node.identifiers ~= *ident;
if (currentIs(TokenType.comma)) if (currentIs(TokenType.comma))
{ {
@ -2618,8 +2646,8 @@ body {} // six
{ {
advance(); advance();
node.hasRight = true; node.hasRight = true;
auto id = expect(TokenType.identifier); auto id = expect(TokenType.identifier);
if (id is null) return null; if (id is null) return null;
node.right = *id; node.right = *id;
} }
return node; return node;
@ -3030,8 +3058,8 @@ invariant() foo();
LabeledStatement parseLabeledStatement() LabeledStatement parseLabeledStatement()
{ {
auto node = new LabeledStatement; auto node = new LabeledStatement;
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.identifier = *ident; node.identifier = *ident;
expect(TokenType.colon); expect(TokenType.colon);
node.statement = parseStatement(); node.statement = parseStatement();
@ -3104,8 +3132,8 @@ invariant() foo();
auto node = new LinkageAttribute; auto node = new LinkageAttribute;
expect(TokenType.extern_); expect(TokenType.extern_);
expect(TokenType.lParen); expect(TokenType.lParen);
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.identifier = *ident; node.identifier = *ident;
if (currentIs(TokenType.increment)) if (currentIs(TokenType.increment))
{ {
@ -3319,7 +3347,6 @@ invariant() foo();
* $(GRAMMAR $(RULEDEF statementNoCaseNoDefault): * $(GRAMMAR $(RULEDEF statementNoCaseNoDefault):
* $(RULE labeledStatement) * $(RULE labeledStatement)
* | $(RULE blockStatement) * | $(RULE blockStatement)
* | $(RULE assignStatement)
* | $(RULE ifStatement) * | $(RULE ifStatement)
* | $(RULE whileStatement) * | $(RULE whileStatement)
* | $(RULE doStatement) * | $(RULE doStatement)
@ -3369,7 +3396,7 @@ invariant() foo();
case foreach_: case foreach_:
case foreach_reverse_: case foreach_reverse_:
node.foreachStatement = parseForeachStatement(); node.foreachStatement = parseForeachStatement();
break; break;
case switch_: case switch_:
node.switchStatement = parseSwitchStatement(); node.switchStatement = parseSwitchStatement();
break; break;
@ -3508,8 +3535,8 @@ invariant() foo();
if (currentIs(TokenType.lParen)) if (currentIs(TokenType.lParen))
{ {
advance(); advance();
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.parameter = *ident; node.parameter = *ident;
expect(TokenType.rParen); expect(TokenType.rParen);
} }
@ -3907,14 +3934,14 @@ q{(int a, ...)
Register parseRegister() Register parseRegister()
{ {
auto node = new Register; auto node = new Register;
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.identifier = *ident; node.identifier = *ident;
if (currentIs(TokenType.lParen)) if (currentIs(TokenType.lParen))
{ {
advance(); advance();
auto intLit = expect(TokenType.intLiteral); auto intLit = expect(TokenType.intLiteral);
if (intLit is null) return null; if (intLit is null) return null;
node.intLiteral = *intLit; node.intLiteral = *intLit;
expect(TokenType.rParen); expect(TokenType.rParen);
} }
@ -3983,8 +4010,8 @@ q{(int a, ...)
auto node = new ScopeGuardStatement; auto node = new ScopeGuardStatement;
expect(TokenType.scope_); expect(TokenType.scope_);
expect(TokenType.lParen); expect(TokenType.lParen);
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.identifier = *ident; node.identifier = *ident;
expect(TokenType.rParen); expect(TokenType.rParen);
node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault(); node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault();
@ -4258,8 +4285,8 @@ q{(int a, ...)
{ {
auto node = new StructDeclaration; auto node = new StructDeclaration;
expect(TokenType.struct_); expect(TokenType.struct_);
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.name = *ident; node.name = *ident;
if (currentIs(TokenType.lParen)) if (currentIs(TokenType.lParen))
{ {
@ -4483,8 +4510,8 @@ q{(int a, ...)
version(verbose) writeln("parseTemplateDeclaration"); version(verbose) writeln("parseTemplateDeclaration");
auto node = new TemplateDeclaration; auto node = new TemplateDeclaration;
expect(TokenType.template_); expect(TokenType.template_);
auto ident = expect(TokenType.identifier); auto ident = expect(TokenType.identifier);
if (ident is null) return null; if (ident is null) return null;
node.identifier = *ident; node.identifier = *ident;
node.templateParameters = parseTemplateParameters(); node.templateParameters = parseTemplateParameters();
if (currentIs(TokenType.if_)) if (currentIs(TokenType.if_))
@ -4801,7 +4828,7 @@ q{(int a, ...)
TraitsArgument parseTraitsArgument() TraitsArgument parseTraitsArgument()
{ {
auto node = new TraitsArgument; auto node = new TraitsArgument;
// TODO if ()
return node; return node;
} }
@ -4886,7 +4913,7 @@ q{(int a, ...)
node.typeSuffixes ~= suffix; node.typeSuffixes ~= suffix;
else else
return null; return null;
break; break;
default: default:
break loop; break loop;
} }
@ -5100,7 +5127,16 @@ q{(int a, ...)
auto node = new TypeidExpression; auto node = new TypeidExpression;
expect(TokenType.typeid_); expect(TokenType.typeid_);
expect(TokenType.lParen); expect(TokenType.lParen);
// TODO if (isExpression())
{
node.expression = parseExpression();
if (node.expression is null) return null;
}
else
{
node.type = parseType();
if (node.type is null) return null;
}
expect(TokenType.rParen); expect(TokenType.rParen);
return node; return node;
} }
@ -5481,6 +5517,13 @@ private:
return parseStatement() !is null; return parseStatement() !is null;
} }
bool isExpression()
{
auto b = setBookmark();
scope (exit) goToBookmark(b);
return parseExpression() !is null;
}
bool currentIsMemberFunctionAttribute() const bool currentIsMemberFunctionAttribute() const
{ {
switch (current.type) switch (current.type)