Formalize unary prefix '&' to mean "make ref"

This makes reserved operator parsing more robust and easier to understand.

Swift SVN r3884
This commit is contained in:
Dave Zarzycki
2013-01-27 21:20:06 +00:00
parent 93a81f1cd8
commit 5fe85d7020
7 changed files with 68 additions and 62 deletions

View File

@@ -80,20 +80,18 @@ NullablePtr<Expr> Parser::parseExprUnary(Diag<> Message) {
Tok.setKind(tok::oper_prefix);
}
if (Tok.is(tok::make_ref)) {
SourceLoc Loc = consumeToken(tok::make_ref);
if (Expr *SubExpr = parseExprUnary(Message).getPtrOrNull())
return new (Context) AddressOfExpr(Loc, SubExpr, Type());
return 0;
}
// If the next token is not an operator, just parse this as expr-postfix.
if (Tok.isNot(tok::oper_prefix))
return parseExprPostfix(Message);
// '&' is a very special case.
if (Tok.getText() == "&") {
SourceLoc loc = Tok.getLoc();
consumeToken(tok::oper_prefix);
if (Expr *SubExpr = parseExprUnary(Message).getPtrOrNull())
return new (Context) AddressOfExpr(loc, SubExpr, Type());
return 0;
}
// Parse the operator.
Expr *Operator = parseExprOperator();