[cfe-commits] r60904 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp lib/Parse/ParseObjc.cpp lib/Parse/ParseStmt.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Thu Dec 11 14:33:43 PST 2008
Author: cornedbee
Date: Thu Dec 11 16:33:27 2008
New Revision: 60904
URL: http://llvm.org/viewvc/llvm-project?rev=60904&view=rev
Log:
Convert some more expression parsers to use smart pointers.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=60904&r1=60903&r2=60904&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Dec 11 16:33:27 2008
@@ -486,13 +486,14 @@
// Expr that doesn't include commas.
OwningExprResult ParseAssignmentExpression();
- ExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
+ OwningExprResult ParseExpressionWithLeadingAt(SourceLocation AtLoc);
- ExprResult ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec);
+ OwningExprResult ParseRHSOfBinaryExpression(OwningExprResult LHS,
+ unsigned MinPrec);
OwningExprResult ParseCastExpression(bool isUnaryExpression);
OwningExprResult ParsePostfixExpressionSuffix(OwningExprResult LHS);
- ExprResult ParseSizeofAlignofExpression();
- ExprResult ParseBuiltinPrimaryExpression();
+ OwningExprResult ParseSizeofAlignofExpression();
+ OwningExprResult ParseBuiltinPrimaryExpression();
static const unsigned ExprListSize = 12;
typedef llvm::SmallVector<ExprTy*, ExprListSize> ExprListTy;
@@ -500,7 +501,7 @@
/// ParseExpressionList - Used for C/C++ (argument-)expression-list.
bool ParseExpressionList(ExprListTy &Exprs, CommaLocsTy &CommaLocs);
-
+
/// ParenParseOption - Control what ParseParenExpression will parse.
enum ParenParseOption {
SimpleExpr, // Only parse '(' expression ')'
@@ -508,14 +509,15 @@
CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
CastExpr // Also allow '(' type-name ')' <anything>
};
- ExprResult ParseParenExpression(ParenParseOption &ExprType, TypeTy *&CastTy,
- SourceLocation &RParenLoc);
-
- ExprResult ParseSimpleParenExpression() { // Parse SimpleExpr only.
+ OwningExprResult ParseParenExpression(ParenParseOption &ExprType,
+ TypeTy *&CastTy,
+ SourceLocation &RParenLoc);
+
+ OwningExprResult ParseSimpleParenExpression() { // Parse SimpleExpr only.
SourceLocation RParenLoc;
return ParseSimpleParenExpression(RParenLoc);
}
- ExprResult ParseSimpleParenExpression(SourceLocation &RParenLoc) {
+ OwningExprResult ParseSimpleParenExpression(SourceLocation &RParenLoc) {
ParenParseOption Op = SimpleExpr;
TypeTy *CastTy;
return ParseParenExpression(Op, CastTy, RParenLoc);
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=60904&r1=60903&r2=60904&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Dec 11 16:33:27 2008
@@ -176,7 +176,7 @@
OwningExprResult LHS(ParseCastExpression(false));
if (LHS.isInvalid()) return move(LHS);
- return Owned(ParseRHSOfBinaryExpression(LHS.result(), prec::Comma));
+ return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
}
/// This routine is called when the '@' is seen and consumed.
@@ -184,11 +184,12 @@
/// routine is necessary to disambiguate @try-statement from,
/// for example, @encode-expression.
///
-Parser::ExprResult Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
+Parser::OwningExprResult
+Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
OwningExprResult LHS(Actions, ParseObjCAtExpression(AtLoc));
- if (LHS.isInvalid()) return LHS.result();
+ if (LHS.isInvalid()) return move(LHS);
- return ParseRHSOfBinaryExpression(LHS.result(), prec::Comma);
+ return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
}
/// ParseAssignmentExpression - Parse an expr that doesn't include commas.
@@ -200,7 +201,7 @@
OwningExprResult LHS(ParseCastExpression(false));
if (LHS.isInvalid()) return move(LHS);
- return Owned(ParseRHSOfBinaryExpression(LHS.result(), prec::Assignment));
+ return ParseRHSOfBinaryExpression(move(LHS), prec::Assignment);
}
/// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression
@@ -211,7 +212,7 @@
///
/// Since this handles full assignment-expression's, it handles postfix
/// expressions and other binary operators for these expressions as well.
-Parser::ExprResult
+Parser::ExprResult
Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
@@ -222,7 +223,7 @@
if (R.isInvalid()) return R.result();
R = ParsePostfixExpressionSuffix(move(R));
if (R.isInvalid()) return R.result();
- return ParseRHSOfBinaryExpression(R.result(), 2);
+ return ParseRHSOfBinaryExpression(move(R), prec::Assignment).result();
}
@@ -230,23 +231,22 @@
OwningExprResult LHS(ParseCastExpression(false));
if (LHS.isInvalid()) return move(LHS);
- return Owned(ParseRHSOfBinaryExpression(LHS.result(), prec::Conditional));
+ return ParseRHSOfBinaryExpression(move(LHS), prec::Conditional);
}
/// ParseRHSOfBinaryExpression - Parse a binary expression that starts with
/// LHS and has a precedence of at least MinPrec.
-Parser::ExprResult
-Parser::ParseRHSOfBinaryExpression(ExprResult LHSArg, unsigned MinPrec) {
+Parser::OwningExprResult
+Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, unsigned MinPrec) {
unsigned NextTokPrec = getBinOpPrecedence(Tok.getKind());
SourceLocation ColonLoc;
- OwningExprResult LHS(Actions, LHSArg);
while (1) {
// If this token has a lower precedence than we are allowed to parse (e.g.
// because we are called recursively, or because the token is not a binop),
// then we are done!
if (NextTokPrec < MinPrec)
- return LHS.result();
+ return move(LHS);
// Consume the operator, saving the operator token for error reporting.
Token OpToken = Tok;
@@ -262,7 +262,7 @@
// 'logical-OR-expression' as we might expect.
TernaryMiddle = ParseExpression();
if (TernaryMiddle.isInvalid())
- return TernaryMiddle.result();
+ return move(TernaryMiddle);
} else {
// Special case handling of "X ? Y : Z" where Y is empty:
// logical-OR-expression '?' ':' conditional-expression [GNU]
@@ -273,17 +273,17 @@
if (Tok.isNot(tok::colon)) {
Diag(Tok, diag::err_expected_colon);
Diag(OpToken, diag::note_matching) << "?";
- return ExprResult(true);
+ return ExprError();
}
-
+
// Eat the colon.
ColonLoc = ConsumeToken();
}
-
+
// Parse another leaf here for the RHS of the operator.
OwningExprResult RHS(ParseCastExpression(false));
if (RHS.isInvalid())
- return RHS.result();
+ return move(RHS);
// Remember the precedence of this operator and get the precedence of the
// operator immediately to the right of the RHS.
@@ -303,9 +303,9 @@
// is okay, to bind exactly as tightly. For example, compile A=B=C=D as
// A=(B=(C=D)), where each paren is a level of recursion here.
// The function takes ownership of the RHS.
- RHS = ParseRHSOfBinaryExpression(RHS.result(), ThisPrec + !isRightAssoc);
+ RHS = ParseRHSOfBinaryExpression(move(RHS), ThisPrec + !isRightAssoc);
if (RHS.isInvalid())
- return RHS.result();
+ return move(RHS);
NextTokPrec = getBinOpPrecedence(Tok.getKind());
}
@@ -520,7 +520,7 @@
case tok::kw___builtin_choose_expr:
case tok::kw___builtin_overload:
case tok::kw___builtin_types_compatible_p:
- return Owned(ParseBuiltinPrimaryExpression());
+ return ParseBuiltinPrimaryExpression();
case tok::kw___null:
return Owned(Actions.ActOnGNUNullExpr(ConsumeToken()));
break;
@@ -563,7 +563,7 @@
case tok::kw___alignof: // unary-expression: '__alignof' unary-expression
// unary-expression: '__alignof' '(' type-name ')'
// unary-expression: 'alignof' '(' type-id ')'
- return Owned(ParseSizeofAlignofExpression());
+ return ParseSizeofAlignofExpression();
case tok::ampamp: { // unary-expression: '&&' identifier
SourceLocation AmpAmpLoc = ConsumeToken();
if (Tok.isNot(tok::identifier))
@@ -772,7 +772,7 @@
/// [GNU] '__alignof' unary-expression
/// [GNU] '__alignof' '(' type-name ')'
/// [C++0x] 'alignof' '(' type-id ')'
-Parser::ExprResult Parser::ParseSizeofAlignofExpression() {
+Parser::OwningExprResult Parser::ParseSizeofAlignofExpression() {
assert((Tok.is(tok::kw_sizeof) || Tok.is(tok::kw___alignof)
|| Tok.is(tok::kw_alignof)) &&
"Not a sizeof/alignof expression!");
@@ -792,28 +792,28 @@
TypeTy *CastTy;
SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
Operand = ParseParenExpression(ExprType, CastTy, RParenLoc);
-
+
// If ParseParenExpression parsed a '(typename)' sequence only, the this is
// sizeof/alignof a type. Otherwise, it is sizeof/alignof an expression.
if (ExprType == CastExpr)
- return Actions.ActOnSizeOfAlignOfExpr(OpTok.getLocation(),
+ return Owned(Actions.ActOnSizeOfAlignOfExpr(OpTok.getLocation(),
OpTok.is(tok::kw_sizeof),
/*isType=*/true, CastTy,
- SourceRange(LParenLoc, RParenLoc));
-
+ SourceRange(LParenLoc, RParenLoc)));
+
// If this is a parenthesized expression, it is the start of a
// unary-expression, but doesn't include any postfix pieces. Parse these
// now if present.
Operand = ParsePostfixExpressionSuffix(move(Operand));
}
-
+
// If we get here, the operand to the sizeof/alignof was an expresion.
if (!Operand.isInvalid())
Operand = Actions.ActOnSizeOfAlignOfExpr(OpTok.getLocation(),
OpTok.is(tok::kw_sizeof),
/*isType=*/false,
Operand.release(), SourceRange());
- return Operand.result();
+ return move(Operand);
}
/// ParseBuiltinPrimaryExpression
@@ -831,7 +831,7 @@
/// [GNU] offsetof-member-designator '.' identifier
/// [GNU] offsetof-member-designator '[' expression ']'
///
-Parser::ExprResult Parser::ParseBuiltinPrimaryExpression() {
+Parser::OwningExprResult Parser::ParseBuiltinPrimaryExpression() {
OwningExprResult Res(Actions);
const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
@@ -839,11 +839,10 @@
SourceLocation StartLoc = ConsumeToken(); // Eat the builtin identifier.
// All of these start with an open paren.
- if (Tok.isNot(tok::l_paren)) {
- Diag(Tok, diag::err_expected_lparen_after_id) << BuiltinII;
- return ExprResult(true);
- }
-
+ if (Tok.isNot(tok::l_paren))
+ return ExprError(Diag(Tok, diag::err_expected_lparen_after_id)
+ << BuiltinII);
+
SourceLocation LParenLoc = ConsumeParen();
// TODO: Build AST.
@@ -853,17 +852,17 @@
OwningExprResult Expr(ParseAssignmentExpression());
if (Expr.isInvalid()) {
SkipUntil(tok::r_paren);
- return ExprResult(true);
+ return ExprError();
}
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
- return ExprResult(true);
+ return ExprError();
TypeTy *Ty = ParseTypeName();
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected_rparen);
- return ExprResult(true);
+ return ExprError();
}
Res = Actions.ActOnVAArg(StartLoc, Expr.release(), Ty, ConsumeParen());
break;
@@ -873,18 +872,18 @@
TypeTy *Ty = ParseTypeName();
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
- return ExprResult(true);
-
+ return ExprError();
+
// We must have at least one identifier here.
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident);
SkipUntil(tok::r_paren);
- return true;
+ return ExprError();
}
-
+
// Keep track of the various subcomponents we see.
llvm::SmallVector<Action::OffsetOfComponent, 4> Comps;
-
+
Comps.push_back(Action::OffsetOfComponent());
Comps.back().isBrackets = false;
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
@@ -897,15 +896,15 @@
Comps.push_back(Action::OffsetOfComponent());
Comps.back().isBrackets = false;
Comps.back().LocStart = ConsumeToken();
-
+
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident);
SkipUntil(tok::r_paren);
- return true;
+ return ExprError();
}
Comps.back().U.IdentInfo = Tok.getIdentifierInfo();
Comps.back().LocEnd = ConsumeToken();
-
+
} else if (Tok.is(tok::l_square)) {
// offsetof-member-designator: offsetof-member-design '[' expression ']'
Comps.push_back(Action::OffsetOfComponent());
@@ -914,7 +913,7 @@
Res = ParseExpression();
if (Res.isInvalid()) {
SkipUntil(tok::r_paren);
- return Res.result();
+ return move(Res);
}
Comps.back().U.E = Res.release();
@@ -926,7 +925,7 @@
break;
} else {
// Error occurred.
- return ExprResult(true);
+ return ExprError();
}
}
break;
@@ -935,27 +934,27 @@
OwningExprResult Cond(ParseAssignmentExpression());
if (Cond.isInvalid()) {
SkipUntil(tok::r_paren);
- return Cond.result();
+ return move(Cond);
}
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
- return ExprResult(true);
-
+ return ExprError();
+
OwningExprResult Expr1(ParseAssignmentExpression());
if (Expr1.isInvalid()) {
SkipUntil(tok::r_paren);
- return Expr1.result();
+ return move(Expr1);
}
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
- return ExprResult(true);
-
+ return ExprError();
+
OwningExprResult Expr2(ParseAssignmentExpression());
if (Expr2.isInvalid()) {
SkipUntil(tok::r_paren);
- return Expr2.result();
+ return move(Expr2);
}
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected_rparen);
- return ExprResult(true);
+ return ExprError();
}
Res = Actions.ActOnChooseExpr(StartLoc, Cond.release(), Expr1.release(),
Expr2.release(), ConsumeParen());
@@ -972,7 +971,7 @@
OwningExprResult ArgExpr(ParseAssignmentExpression());
if (ArgExpr.isInvalid()) {
SkipUntil(tok::r_paren);
- return ExprResult(true);
+ return ExprError();
} else
ArgExprs.push_back(ArgExpr.release());
@@ -982,28 +981,28 @@
CommaLocs.push_back(ConsumeToken());
}
}
-
+
// Attempt to consume the r-paren
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected_rparen);
SkipUntil(tok::r_paren);
- return ExprResult(true);
+ return ExprError();
}
- Res = Actions.ActOnOverloadExpr(ArgExprs.take(), ArgExprs.size(),
+ Res = Actions.ActOnOverloadExpr(ArgExprs.take(), ArgExprs.size(),
&CommaLocs[0], StartLoc, ConsumeParen());
break;
}
case tok::kw___builtin_types_compatible_p:
TypeTy *Ty1 = ParseTypeName();
-
+
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
- return ExprResult(true);
-
+ return ExprError();
+
TypeTy *Ty2 = ParseTypeName();
-
+
if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_expected_rparen);
- return ExprResult(true);
+ return ExprError();
}
Res = Actions.ActOnTypesCompatibleExpr(StartLoc, Ty1, Ty2, ConsumeParen());
break;
@@ -1011,7 +1010,7 @@
// These can be followed by postfix-expr pieces because they are
// primary-expressions.
- return ParsePostfixExpressionSuffix(move(Res)).result();
+ return ParsePostfixExpressionSuffix(move(Res));
}
/// ParseParenExpression - This parses the unit that starts with a '(' token,
@@ -1027,14 +1026,14 @@
/// cast-expression: [C99 6.5.4]
/// '(' type-name ')' cast-expression
///
-Parser::ExprResult Parser::ParseParenExpression(ParenParseOption &ExprType,
- TypeTy *&CastTy,
- SourceLocation &RParenLoc) {
+Parser::OwningExprResult
+Parser::ParseParenExpression(ParenParseOption &ExprType,
+ TypeTy *&CastTy, SourceLocation &RParenLoc) {
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
SourceLocation OpenLoc = ConsumeParen();
OwningExprResult Result(Actions, true);
CastTy = 0;
-
+
if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
Diag(Tok, diag::ext_gnu_statement_expr);
OwningStmtResult Stmt(ParseCompoundStatement(true));
@@ -1054,26 +1053,26 @@
RParenLoc = ConsumeParen();
else
MatchRHSPunctuation(tok::r_paren, OpenLoc);
-
+
if (Tok.is(tok::l_brace)) {
if (!getLang().C99) // Compound literals don't exist in C90.
Diag(OpenLoc, diag::ext_c99_compound_literal);
Result = ParseInitializer();
ExprType = CompoundLiteral;
if (!Result.isInvalid())
- return Actions.ActOnCompoundLiteral(OpenLoc, Ty, RParenLoc,
- Result.release());
+ return Owned(Actions.ActOnCompoundLiteral(OpenLoc, Ty, RParenLoc,
+ Result.release()));
} else if (ExprType == CastExpr) {
// Note that this doesn't parse the subsequence cast-expression, it just
// returns the parsed type to the callee.
ExprType = CastExpr;
CastTy = Ty;
- return ExprResult(false);
+ return OwningExprResult(Actions);
} else {
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
- return ExprResult(true);
+ return ExprError();
}
- return Result.result();
+ return move(Result);
} else {
Result = ParseExpression();
ExprType = SimpleExpr;
@@ -1081,7 +1080,7 @@
Result = Actions.ActOnParenExpr(
OpenLoc, Tok.getLocation(), Result.release());
}
-
+
// Match the ')'.
if (Result.isInvalid())
SkipUntil(tok::r_paren);
@@ -1091,8 +1090,8 @@
else
MatchRHSPunctuation(tok::r_paren, OpenLoc);
}
-
- return Result.result();
+
+ return move(Result);
}
/// ParseStringLiteralExpression - This handles the various token types that
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=60904&r1=60903&r2=60904&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Thu Dec 11 16:33:27 2008
@@ -221,7 +221,7 @@
if (Tok.isNot(tok::l_paren))
return Diag(Tok, diag::err_expected_lparen_after) << CastName;
- OwningExprResult Result(Actions, ParseSimpleParenExpression(RParenLoc));
+ OwningExprResult Result(ParseSimpleParenExpression(RParenLoc));
if (!Result.isInvalid())
Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=60904&r1=60903&r2=60904&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Thu Dec 11 16:33:27 2008
@@ -1380,7 +1380,7 @@
return ParseObjCThrowStmt(AtLoc);
else if (Tok.isObjCAtKeyword(tok::objc_synchronized))
return ParseObjCSynchronizedStmt(AtLoc);
- OwningExprResult Res(Actions, ParseExpressionWithLeadingAt(AtLoc));
+ OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
if (Res.isInvalid()) {
// If the expression is invalid, skip ahead to the next semicolon. Not
// doing this opens us up to the possibility of infinite loops if
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=60904&r1=60903&r2=60904&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Thu Dec 11 16:33:27 2008
@@ -749,7 +749,7 @@
}
// Parse the condition.
- OwningExprResult Cond(Actions, ParseSimpleParenExpression());
+ OwningExprResult Cond(ParseSimpleParenExpression());
DoScope.Exit();
if (Cond.isInvalid() || Body.isInvalid())
@@ -1192,7 +1192,7 @@
}
// Read the parenthesized expression.
- OwningExprResult Res(Actions, ParseSimpleParenExpression());
+ OwningExprResult Res(ParseSimpleParenExpression());
if (Res.isInvalid()) {
SkipUntil(tok::r_paren);
return true;
More information about the cfe-commits
mailing list