diff options
| author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-11-11 11:37:55 +0000 |
|---|---|---|
| committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2008-11-11 11:37:55 +0000 |
| commit | c470476420249d85e6a82275e90d3a8f62312fa1 (patch) | |
| tree | a8f9b143310c392c35c5883bd8358da872b63403 /clang/lib/Parse/ParseExprCXX.cpp | |
| parent | 8cb2e28e43b99df65c904d87ada93c99660e4fa4 (diff) | |
| download | bcm5719-llvm-c470476420249d85e6a82275e90d3a8f62312fa1.tar.gz bcm5719-llvm-c470476420249d85e6a82275e90d3a8f62312fa1.zip | |
Implement C++ 'typeid' parsing and sema.
llvm-svn: 59042
Diffstat (limited to 'clang/lib/Parse/ParseExprCXX.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseExprCXX.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index a1fd565822d..692e35df93d 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -216,6 +216,54 @@ Parser::ExprResult Parser::ParseCXXCasts() { return Result; } +/// ParseCXXTypeid - This handles the C++ typeid expression. +/// +/// postfix-expression: [C++ 5.2p1] +/// 'typeid' '(' expression ')' +/// 'typeid' '(' type-id ')' +/// +Parser::ExprResult Parser::ParseCXXTypeid() { + assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!"); + + SourceLocation OpLoc = ConsumeToken(); + SourceLocation LParenLoc = Tok.getLocation(); + SourceLocation RParenLoc; + + // typeid expressions are always parenthesized. + if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, + "typeid")) + return ExprResult(true); + + Parser::ExprResult Result; + + if (isTypeIdInParens()) { + TypeTy *Ty = ParseTypeName(); + + // Match the ')'. + MatchRHSPunctuation(tok::r_paren, LParenLoc); + + if (!Ty) + return ExprResult(true); + + Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true, + Ty, RParenLoc); + } else { + Result = ParseExpression(); + + // Match the ')'. + if (Result.isInvalid) + SkipUntil(tok::r_paren); + else { + MatchRHSPunctuation(tok::r_paren, LParenLoc); + + Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false, + Result.Val, RParenLoc); + } + } + + return Result; +} + /// ParseCXXBoolLiteral - This handles the C++ Boolean literals. /// /// boolean-literal: [C++ 2.13.5] |

