Remove crash-prone *expect calls
This commit is contained in:
parent
62734e58df
commit
7a4e588793
|
@ -74,8 +74,6 @@ version (unittest) import std.stdio;
|
||||||
version(development) import std.stdio;
|
version(development) import std.stdio;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
// TODO: any place that says *expect(...) needs to be fixed
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Params:
|
* Params:
|
||||||
* tokens = the tokens parsed by std.d.lexer
|
* tokens = the tokens parsed by std.d.lexer
|
||||||
|
@ -1261,7 +1259,9 @@ incorrect;
|
||||||
{
|
{
|
||||||
auto node = new ClassDeclaration;
|
auto node = new ClassDeclaration;
|
||||||
expect(TokenType.class_);
|
expect(TokenType.class_);
|
||||||
node.name = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.name = *ident;
|
||||||
if (currentIs(TokenType.lParen))
|
if (currentIs(TokenType.lParen))
|
||||||
{
|
{
|
||||||
node.templateParameters = parseTemplateParameters();
|
node.templateParameters = parseTemplateParameters();
|
||||||
|
@ -2499,9 +2499,11 @@ body {} // six
|
||||||
IdentifierList parseIdentifierList()
|
IdentifierList parseIdentifierList()
|
||||||
{
|
{
|
||||||
auto node = new IdentifierList;
|
auto node = new IdentifierList;
|
||||||
while (true)
|
do
|
||||||
{
|
{
|
||||||
node.identifiers ~= *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.identifiers ~= *ident;
|
||||||
if (currentIs(TokenType.comma))
|
if (currentIs(TokenType.comma))
|
||||||
{
|
{
|
||||||
advance();
|
advance();
|
||||||
|
@ -2509,7 +2511,7 @@ body {} // six
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
} while (true);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2616,7 +2618,9 @@ body {} // six
|
||||||
{
|
{
|
||||||
advance();
|
advance();
|
||||||
node.hasRight = true;
|
node.hasRight = true;
|
||||||
node.right = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.right = *ident;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -3026,7 +3030,9 @@ invariant() foo();
|
||||||
LabeledStatement parseLabeledStatement()
|
LabeledStatement parseLabeledStatement()
|
||||||
{
|
{
|
||||||
auto node = new LabeledStatement;
|
auto node = new LabeledStatement;
|
||||||
node.identifier = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.identifier = *ident;
|
||||||
expect(TokenType.colon);
|
expect(TokenType.colon);
|
||||||
node.statement = parseStatement();
|
node.statement = parseStatement();
|
||||||
return node;
|
return node;
|
||||||
|
@ -3098,7 +3104,9 @@ invariant() foo();
|
||||||
auto node = new LinkageAttribute;
|
auto node = new LinkageAttribute;
|
||||||
expect(TokenType.extern_);
|
expect(TokenType.extern_);
|
||||||
expect(TokenType.lParen);
|
expect(TokenType.lParen);
|
||||||
node.identifier = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.identifier = *ident;
|
||||||
if (currentIs(TokenType.increment))
|
if (currentIs(TokenType.increment))
|
||||||
{
|
{
|
||||||
advance();
|
advance();
|
||||||
|
@ -3243,7 +3251,7 @@ invariant() foo();
|
||||||
node.allocatorArguments = parseArguments();
|
node.allocatorArguments = parseArguments();
|
||||||
expect(TokenType.class_);
|
expect(TokenType.class_);
|
||||||
if (!currentIs(TokenType.lBrace))
|
if (!currentIs(TokenType.lBrace))
|
||||||
node.baseClassList = parseBaseClassList;
|
node.baseClassList = parseBaseClassList();
|
||||||
node.classBody = parseClassBody();
|
node.classBody = parseClassBody();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -3500,7 +3508,9 @@ invariant() foo();
|
||||||
if (currentIs(TokenType.lParen))
|
if (currentIs(TokenType.lParen))
|
||||||
{
|
{
|
||||||
advance();
|
advance();
|
||||||
node.parameter = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.parameter = *ident;
|
||||||
expect(TokenType.rParen);
|
expect(TokenType.rParen);
|
||||||
}
|
}
|
||||||
node.blockStatement = parseBlockStatement();
|
node.blockStatement = parseBlockStatement();
|
||||||
|
@ -3897,11 +3907,15 @@ q{(int a, ...)
|
||||||
Register parseRegister()
|
Register parseRegister()
|
||||||
{
|
{
|
||||||
auto node = new Register;
|
auto node = new Register;
|
||||||
node.identifier = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.identifier = *ident;
|
||||||
if (currentIs(TokenType.lParen))
|
if (currentIs(TokenType.lParen))
|
||||||
{
|
{
|
||||||
advance();
|
advance();
|
||||||
node.intLiteral = *expect(TokenType.intLiteral);
|
auto intLit = expect(TokenType.intLiteral);
|
||||||
|
if (intLit is null) return null;
|
||||||
|
node.intLiteral = *intLit;
|
||||||
expect(TokenType.rParen);
|
expect(TokenType.rParen);
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
@ -3969,7 +3983,9 @@ q{(int a, ...)
|
||||||
auto node = new ScopeGuardStatement;
|
auto node = new ScopeGuardStatement;
|
||||||
expect(TokenType.scope_);
|
expect(TokenType.scope_);
|
||||||
expect(TokenType.lParen);
|
expect(TokenType.lParen);
|
||||||
node.identifier = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.identifier = *ident;
|
||||||
expect(TokenType.rParen);
|
expect(TokenType.rParen);
|
||||||
node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault();
|
node.statementNoCaseNoDefault = parseStatementNoCaseNoDefault();
|
||||||
return node;
|
return node;
|
||||||
|
@ -4242,7 +4258,9 @@ q{(int a, ...)
|
||||||
{
|
{
|
||||||
auto node = new StructDeclaration;
|
auto node = new StructDeclaration;
|
||||||
expect(TokenType.struct_);
|
expect(TokenType.struct_);
|
||||||
node.name = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.name = *ident;
|
||||||
if (currentIs(TokenType.lParen))
|
if (currentIs(TokenType.lParen))
|
||||||
{
|
{
|
||||||
node.templateParameters = parseTemplateParameters();
|
node.templateParameters = parseTemplateParameters();
|
||||||
|
@ -4465,7 +4483,9 @@ 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_);
|
||||||
node.identifier = *expect(TokenType.identifier);
|
auto ident = expect(TokenType.identifier);
|
||||||
|
if (ident is null) return null;
|
||||||
|
node.identifier = *ident;
|
||||||
node.templateParameters = parseTemplateParameters();
|
node.templateParameters = parseTemplateParameters();
|
||||||
if (currentIs(TokenType.if_))
|
if (currentIs(TokenType.if_))
|
||||||
node.constraint = parseConstraint();
|
node.constraint = parseConstraint();
|
||||||
|
@ -4866,6 +4886,7 @@ q{(int a, ...)
|
||||||
node.typeSuffixes ~= suffix;
|
node.typeSuffixes ~= suffix;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
|
@ -5153,7 +5174,7 @@ q{(int a, ...)
|
||||||
node.deleteExpression = parseDeleteExpression();
|
node.deleteExpression = parseDeleteExpression();
|
||||||
return node;
|
return node;
|
||||||
case cast_:
|
case cast_:
|
||||||
node.castExpression = parseCastExpression;
|
node.castExpression = parseCastExpression();
|
||||||
return node;
|
return node;
|
||||||
case assert_:
|
case assert_:
|
||||||
node.assertExpression = parseAssertExpression();
|
node.assertExpression = parseAssertExpression();
|
||||||
|
@ -5236,12 +5257,12 @@ q{doStuff(5)}c;
|
||||||
node.templateParameters = parseTemplateParameters();
|
node.templateParameters = parseTemplateParameters();
|
||||||
if (currentIs(TokenType.if_))
|
if (currentIs(TokenType.if_))
|
||||||
node.constraint = parseConstraint();
|
node.constraint = parseConstraint();
|
||||||
node.structBody = parseStructBody;
|
node.structBody = parseStructBody();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (currentIs(TokenType.semicolon))
|
if (currentIs(TokenType.semicolon))
|
||||||
advance;
|
advance();
|
||||||
else
|
else
|
||||||
node.structBody = parseStructBody();
|
node.structBody = parseStructBody();
|
||||||
}
|
}
|
||||||
|
@ -5729,8 +5750,8 @@ private:
|
||||||
size_t index;
|
size_t index;
|
||||||
string fileName;
|
string fileName;
|
||||||
void function(string, int, int, string) errorFunction;
|
void function(string, int, int, string) errorFunction;
|
||||||
immutable string BASIC_TYPE_CASE_RANGE = q{case bool_: .. case wchar_:};
|
static immutable string BASIC_TYPE_CASE_RANGE = q{case bool_: .. case wchar_:};
|
||||||
immutable string LITERAL_CASE_RANGE = q{case doubleLiteral: .. case wstringLiteral:};
|
static immutable string LITERAL_CASE_RANGE = q{case doubleLiteral: .. case wstringLiteral:};
|
||||||
immutable string SPECIAL_CASE_RANGE = q{case specialDate: .. case specialPrettyFunction:};
|
static immutable string SPECIAL_CASE_RANGE = q{case specialDate: .. case specialPrettyFunction:};
|
||||||
int suppressMessages;
|
int suppressMessages;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue