Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Expression parsing implementation for C++. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 14 | #include "clang/Parse/Parser.h" |
Douglas Gregor | bc61bd8 | 2011-01-11 00:33:19 +0000 | [diff] [blame] | 15 | #include "RAIIObjectsForParser.h" |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 16 | #include "clang/Basic/PrettyStackTrace.h" |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Lex/LiteralSupport.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 19 | #include "clang/Sema/DeclSpec.h" |
| 20 | #include "clang/Sema/ParsedTemplate.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Scope.h" |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
| 23 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 26 | static int SelectDigraphErrorMessage(tok::TokenKind Kind) { |
| 27 | switch (Kind) { |
| 28 | case tok::kw_template: return 0; |
| 29 | case tok::kw_const_cast: return 1; |
| 30 | case tok::kw_dynamic_cast: return 2; |
| 31 | case tok::kw_reinterpret_cast: return 3; |
| 32 | case tok::kw_static_cast: return 4; |
| 33 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 34 | llvm_unreachable("Unknown type for digraph error message."); |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | // Are the two tokens adjacent in the same source file? |
Richard Smith | 19a2702 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 39 | bool Parser::areTokensAdjacent(const Token &First, const Token &Second) { |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 40 | SourceManager &SM = PP.getSourceManager(); |
| 41 | SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation()); |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 42 | SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength()); |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 43 | return FirstEnd == SM.getSpellingLoc(Second.getLocation()); |
| 44 | } |
| 45 | |
| 46 | // Suggest fixit for "<::" after a cast. |
| 47 | static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, |
| 48 | Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) { |
| 49 | // Pull '<:' and ':' off token stream. |
| 50 | if (!AtDigraph) |
| 51 | PP.Lex(DigraphToken); |
| 52 | PP.Lex(ColonToken); |
| 53 | |
| 54 | SourceRange Range; |
| 55 | Range.setBegin(DigraphToken.getLocation()); |
| 56 | Range.setEnd(ColonToken.getLocation()); |
| 57 | P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph) |
| 58 | << SelectDigraphErrorMessage(Kind) |
| 59 | << FixItHint::CreateReplacement(Range, "< ::"); |
| 60 | |
| 61 | // Update token information to reflect their change in token type. |
| 62 | ColonToken.setKind(tok::coloncolon); |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 63 | ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1)); |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 64 | ColonToken.setLength(2); |
| 65 | DigraphToken.setKind(tok::less); |
| 66 | DigraphToken.setLength(1); |
| 67 | |
| 68 | // Push new tokens back to token stream. |
| 69 | PP.EnterToken(ColonToken); |
| 70 | if (!AtDigraph) |
| 71 | PP.EnterToken(DigraphToken); |
| 72 | } |
| 73 | |
Richard Trieu | 950be71 | 2011-09-19 19:01:00 +0000 | [diff] [blame] | 74 | // Check for '<::' which should be '< ::' instead of '[:' when following |
| 75 | // a template name. |
| 76 | void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType, |
| 77 | bool EnteringContext, |
| 78 | IdentifierInfo &II, CXXScopeSpec &SS) { |
Richard Trieu | c11030e | 2011-09-20 20:03:50 +0000 | [diff] [blame] | 79 | if (!Next.is(tok::l_square) || Next.getLength() != 2) |
Richard Trieu | 950be71 | 2011-09-19 19:01:00 +0000 | [diff] [blame] | 80 | return; |
| 81 | |
| 82 | Token SecondToken = GetLookAheadToken(2); |
Richard Smith | 19a2702 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 83 | if (!SecondToken.is(tok::colon) || !areTokensAdjacent(Next, SecondToken)) |
Richard Trieu | 950be71 | 2011-09-19 19:01:00 +0000 | [diff] [blame] | 84 | return; |
| 85 | |
| 86 | TemplateTy Template; |
| 87 | UnqualifiedId TemplateName; |
| 88 | TemplateName.setIdentifier(&II, Tok.getLocation()); |
| 89 | bool MemberOfUnknownSpecialization; |
| 90 | if (!Actions.isTemplateName(getCurScope(), SS, /*hasTemplateKeyword=*/false, |
| 91 | TemplateName, ObjectType, EnteringContext, |
| 92 | Template, MemberOfUnknownSpecialization)) |
| 93 | return; |
| 94 | |
| 95 | FixDigraph(*this, PP, Next, SecondToken, tok::kw_template, |
| 96 | /*AtDigraph*/false); |
| 97 | } |
| 98 | |
Richard Trieu | 919b955 | 2012-11-02 01:08:58 +0000 | [diff] [blame] | 99 | /// \brief Emits an error for a left parentheses after a double colon. |
| 100 | /// |
| 101 | /// When a '(' is found after a '::', emit an error. Attempt to fix the token |
Nico Weber | bba91b8 | 2012-11-29 05:29:23 +0000 | [diff] [blame] | 102 | /// stream by removing the '(', and the matching ')' if found. |
Richard Trieu | 919b955 | 2012-11-02 01:08:58 +0000 | [diff] [blame] | 103 | void Parser::CheckForLParenAfterColonColon() { |
| 104 | if (!Tok.is(tok::l_paren)) |
| 105 | return; |
| 106 | |
| 107 | SourceLocation l_parenLoc = ConsumeParen(), r_parenLoc; |
| 108 | Token Tok1 = getCurToken(); |
| 109 | if (!Tok1.is(tok::identifier) && !Tok1.is(tok::star)) |
| 110 | return; |
| 111 | |
| 112 | if (Tok1.is(tok::identifier)) { |
| 113 | Token Tok2 = GetLookAheadToken(1); |
| 114 | if (Tok2.is(tok::r_paren)) { |
| 115 | ConsumeToken(); |
| 116 | PP.EnterToken(Tok1); |
| 117 | r_parenLoc = ConsumeParen(); |
| 118 | } |
| 119 | } else if (Tok1.is(tok::star)) { |
| 120 | Token Tok2 = GetLookAheadToken(1); |
| 121 | if (Tok2.is(tok::identifier)) { |
| 122 | Token Tok3 = GetLookAheadToken(2); |
| 123 | if (Tok3.is(tok::r_paren)) { |
| 124 | ConsumeToken(); |
| 125 | ConsumeToken(); |
| 126 | PP.EnterToken(Tok2); |
| 127 | PP.EnterToken(Tok1); |
| 128 | r_parenLoc = ConsumeParen(); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | Diag(l_parenLoc, diag::err_paren_after_colon_colon) |
| 134 | << FixItHint::CreateRemoval(l_parenLoc) |
| 135 | << FixItHint::CreateRemoval(r_parenLoc); |
| 136 | } |
| 137 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | /// \brief Parse global scope or nested-name-specifier if present. |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 139 | /// |
| 140 | /// Parses a C++ global scope specifier ('::') or nested-name-specifier (which |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | /// may be preceded by '::'). Note that this routine will not parse ::new or |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 142 | /// ::delete; it will just leave them in the token stream. |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 143 | /// |
| 144 | /// '::'[opt] nested-name-specifier |
| 145 | /// '::' |
| 146 | /// |
| 147 | /// nested-name-specifier: |
| 148 | /// type-name '::' |
| 149 | /// namespace-name '::' |
| 150 | /// nested-name-specifier identifier '::' |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 151 | /// nested-name-specifier 'template'[opt] simple-template-id '::' |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 152 | /// |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 153 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 154 | /// \param SS the scope specifier that will be set to the parsed |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 155 | /// nested-name-specifier (or empty) |
| 156 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | /// \param ObjectType if this nested-name-specifier is being parsed following |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 158 | /// the "." or "->" of a member access expression, this parameter provides the |
| 159 | /// type of the object whose members are being accessed. |
| 160 | /// |
| 161 | /// \param EnteringContext whether we will be entering into the context of |
| 162 | /// the nested-name-specifier after parsing it. |
| 163 | /// |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 164 | /// \param MayBePseudoDestructor When non-NULL, points to a flag that |
| 165 | /// indicates whether this nested-name-specifier may be part of a |
| 166 | /// pseudo-destructor name. In this case, the flag will be set false |
| 167 | /// if we don't actually end up parsing a destructor name. Moreorover, |
| 168 | /// if we do end up determining that we are parsing a destructor name, |
| 169 | /// the last component of the nested-name-specifier is not parsed as |
| 170 | /// part of the scope specifier. |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 171 | /// |
| 172 | /// \param IsTypename If \c true, this nested-name-specifier is known to be |
| 173 | /// part of a type name. This is used to improve error recovery. |
| 174 | /// |
| 175 | /// \param LastII When non-NULL, points to an IdentifierInfo* that will be |
| 176 | /// filled in with the leading identifier in the last component of the |
| 177 | /// nested-name-specifier, if any. |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 178 | /// |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 179 | /// \returns true if there was an error parsing a scope specifier |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 180 | bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 181 | ParsedType ObjectType, |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 182 | bool EnteringContext, |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 183 | bool *MayBePseudoDestructor, |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 184 | bool IsTypename, |
| 185 | IdentifierInfo **LastII) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 186 | assert(getLangOpts().CPlusPlus && |
Chris Lattner | 7452c6f | 2009-01-05 01:24:05 +0000 | [diff] [blame] | 187 | "Call sites of this function should be guarded by checking for C++"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 189 | if (Tok.is(tok::annot_cxxscope)) { |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 190 | assert(!LastII && "want last identifier but have already annotated scope"); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 191 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
| 192 | Tok.getAnnotationRange(), |
| 193 | SS); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 194 | ConsumeToken(); |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 195 | return false; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 196 | } |
Chris Lattner | e607e80 | 2009-01-04 21:14:15 +0000 | [diff] [blame] | 197 | |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 198 | if (LastII) |
| 199 | *LastII = 0; |
| 200 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 201 | bool HasScopeSpecifier = false; |
| 202 | |
Chris Lattner | 5b45473 | 2009-01-05 03:55:46 +0000 | [diff] [blame] | 203 | if (Tok.is(tok::coloncolon)) { |
| 204 | // ::new and ::delete aren't nested-name-specifiers. |
| 205 | tok::TokenKind NextKind = NextToken().getKind(); |
| 206 | if (NextKind == tok::kw_new || NextKind == tok::kw_delete) |
| 207 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 208 | |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 209 | // '::' - Global scope qualifier. |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 210 | if (Actions.ActOnCXXGlobalScopeSpecifier(getCurScope(), ConsumeToken(), SS)) |
| 211 | return true; |
Richard Trieu | 919b955 | 2012-11-02 01:08:58 +0000 | [diff] [blame] | 212 | |
| 213 | CheckForLParenAfterColonColon(); |
| 214 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 215 | HasScopeSpecifier = true; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 218 | bool CheckForDestructor = false; |
| 219 | if (MayBePseudoDestructor && *MayBePseudoDestructor) { |
| 220 | CheckForDestructor = true; |
| 221 | *MayBePseudoDestructor = false; |
| 222 | } |
| 223 | |
David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 224 | if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) { |
| 225 | DeclSpec DS(AttrFactory); |
| 226 | SourceLocation DeclLoc = Tok.getLocation(); |
| 227 | SourceLocation EndLoc = ParseDecltypeSpecifier(DS); |
| 228 | if (Tok.isNot(tok::coloncolon)) { |
| 229 | AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc); |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | SourceLocation CCLoc = ConsumeToken(); |
| 234 | if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc)) |
| 235 | SS.SetInvalid(SourceRange(DeclLoc, CCLoc)); |
| 236 | |
| 237 | HasScopeSpecifier = true; |
| 238 | } |
| 239 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 240 | while (true) { |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 241 | if (HasScopeSpecifier) { |
| 242 | // C++ [basic.lookup.classref]p5: |
| 243 | // If the qualified-id has the form |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 244 | // |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 245 | // ::class-name-or-namespace-name::... |
Douglas Gregor | 3b6afbb | 2009-09-09 00:23:06 +0000 | [diff] [blame] | 246 | // |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 247 | // the class-name-or-namespace-name is looked up in global scope as a |
| 248 | // class-name or namespace-name. |
| 249 | // |
| 250 | // To implement this, we clear out the object type as soon as we've |
| 251 | // seen a leading '::' or part of a nested-name-specifier. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 252 | ObjectType = ParsedType(); |
Douglas Gregor | 81b747b | 2009-09-17 21:32:03 +0000 | [diff] [blame] | 253 | |
| 254 | if (Tok.is(tok::code_completion)) { |
| 255 | // Code completion for a nested-name-specifier, where the code |
| 256 | // code completion token follows the '::'. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 257 | Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext); |
Argyrios Kyrtzidis | b6b2b18 | 2011-04-23 01:04:12 +0000 | [diff] [blame] | 258 | // Include code completion token into the range of the scope otherwise |
| 259 | // when we try to annotate the scope tokens the dangling code completion |
| 260 | // token will cause assertion in |
| 261 | // Preprocessor::AnnotatePreviousCachedTokens. |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 262 | SS.setEndLoc(Tok.getLocation()); |
| 263 | cutOffParsing(); |
| 264 | return true; |
Douglas Gregor | 81b747b | 2009-09-17 21:32:03 +0000 | [diff] [blame] | 265 | } |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 266 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 267 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 268 | // nested-name-specifier: |
Chris Lattner | 77cf72a | 2009-06-26 03:47:46 +0000 | [diff] [blame] | 269 | // nested-name-specifier 'template'[opt] simple-template-id '::' |
| 270 | |
| 271 | // Parse the optional 'template' keyword, then make sure we have |
| 272 | // 'identifier <' after it. |
| 273 | if (Tok.is(tok::kw_template)) { |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 274 | // If we don't have a scope specifier or an object type, this isn't a |
Eli Friedman | eab975d | 2009-08-29 04:08:08 +0000 | [diff] [blame] | 275 | // nested-name-specifier, since they aren't allowed to start with |
| 276 | // 'template'. |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 277 | if (!HasScopeSpecifier && !ObjectType) |
Eli Friedman | eab975d | 2009-08-29 04:08:08 +0000 | [diff] [blame] | 278 | break; |
| 279 | |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 280 | TentativeParsingAction TPA(*this); |
Chris Lattner | 77cf72a | 2009-06-26 03:47:46 +0000 | [diff] [blame] | 281 | SourceLocation TemplateKWLoc = ConsumeToken(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 282 | |
| 283 | UnqualifiedId TemplateName; |
| 284 | if (Tok.is(tok::identifier)) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 285 | // Consume the identifier. |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 286 | TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 287 | ConsumeToken(); |
| 288 | } else if (Tok.is(tok::kw_operator)) { |
| 289 | if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 290 | TemplateName)) { |
| 291 | TPA.Commit(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 292 | break; |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 293 | } |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 294 | |
Sean Hunt | e6252d1 | 2009-11-28 08:58:14 +0000 | [diff] [blame] | 295 | if (TemplateName.getKind() != UnqualifiedId::IK_OperatorFunctionId && |
| 296 | TemplateName.getKind() != UnqualifiedId::IK_LiteralOperatorId) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 297 | Diag(TemplateName.getSourceRange().getBegin(), |
| 298 | diag::err_id_after_template_in_nested_name_spec) |
| 299 | << TemplateName.getSourceRange(); |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 300 | TPA.Commit(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | } else { |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 304 | TPA.Revert(); |
Chris Lattner | 77cf72a | 2009-06-26 03:47:46 +0000 | [diff] [blame] | 305 | break; |
| 306 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 307 | |
Douglas Gregor | 7bb87fc | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 308 | // If the next token is not '<', we have a qualified-id that refers |
| 309 | // to a template name, such as T::template apply, but is not a |
| 310 | // template-id. |
| 311 | if (Tok.isNot(tok::less)) { |
| 312 | TPA.Revert(); |
| 313 | break; |
| 314 | } |
| 315 | |
| 316 | // Commit to parsing the template-id. |
| 317 | TPA.Commit(); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 318 | TemplateTy Template; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 319 | if (TemplateNameKind TNK |
| 320 | = Actions.ActOnDependentTemplateName(getCurScope(), |
| 321 | SS, TemplateKWLoc, TemplateName, |
| 322 | ObjectType, EnteringContext, |
| 323 | Template)) { |
| 324 | if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc, |
| 325 | TemplateName, false)) |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 326 | return true; |
| 327 | } else |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 328 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 329 | |
Chris Lattner | 77cf72a | 2009-06-26 03:47:46 +0000 | [diff] [blame] | 330 | continue; |
| 331 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 333 | if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 334 | // We have |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 335 | // |
| 336 | // simple-template-id '::' |
| 337 | // |
| 338 | // So we need to check whether the simple-template-id is of the |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 339 | // right kind (it should name a type or be dependent), and then |
| 340 | // convert it into a type within the nested-name-specifier. |
Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 341 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 342 | if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) { |
| 343 | *MayBePseudoDestructor = true; |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 344 | return false; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 347 | if (LastII) |
| 348 | *LastII = TemplateId->Name; |
| 349 | |
Douglas Gregor | 6cd9d4a | 2011-03-04 21:37:14 +0000 | [diff] [blame] | 350 | // Consume the template-id token. |
| 351 | ConsumeToken(); |
| 352 | |
| 353 | assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!"); |
| 354 | SourceLocation CCLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | |
David Blaikie | 6796fc1 | 2011-11-07 03:30:03 +0000 | [diff] [blame] | 356 | HasScopeSpecifier = true; |
Douglas Gregor | 6cd9d4a | 2011-03-04 21:37:14 +0000 | [diff] [blame] | 357 | |
Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 358 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), |
Douglas Gregor | 6cd9d4a | 2011-03-04 21:37:14 +0000 | [diff] [blame] | 359 | TemplateId->NumArgs); |
| 360 | |
| 361 | if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 362 | SS, |
| 363 | TemplateId->TemplateKWLoc, |
Douglas Gregor | 6cd9d4a | 2011-03-04 21:37:14 +0000 | [diff] [blame] | 364 | TemplateId->Template, |
| 365 | TemplateId->TemplateNameLoc, |
| 366 | TemplateId->LAngleLoc, |
| 367 | TemplateArgsPtr, |
| 368 | TemplateId->RAngleLoc, |
| 369 | CCLoc, |
| 370 | EnteringContext)) { |
| 371 | SourceLocation StartLoc |
| 372 | = SS.getBeginLoc().isValid()? SS.getBeginLoc() |
| 373 | : TemplateId->TemplateNameLoc; |
| 374 | SS.SetInvalid(SourceRange(StartLoc, CCLoc)); |
Chris Lattner | 67b9e83 | 2009-06-26 03:45:46 +0000 | [diff] [blame] | 375 | } |
Argyrios Kyrtzidis | eccce7e | 2011-05-03 18:45:38 +0000 | [diff] [blame] | 376 | |
Douglas Gregor | 6cd9d4a | 2011-03-04 21:37:14 +0000 | [diff] [blame] | 377 | continue; |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 380 | |
| 381 | // The rest of the nested-name-specifier possibilities start with |
| 382 | // tok::identifier. |
| 383 | if (Tok.isNot(tok::identifier)) |
| 384 | break; |
| 385 | |
| 386 | IdentifierInfo &II = *Tok.getIdentifierInfo(); |
| 387 | |
| 388 | // nested-name-specifier: |
| 389 | // type-name '::' |
| 390 | // namespace-name '::' |
| 391 | // nested-name-specifier identifier '::' |
| 392 | Token Next = NextToken(); |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 393 | |
| 394 | // If we get foo:bar, this is almost certainly a typo for foo::bar. Recover |
| 395 | // and emit a fixit hint for it. |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 396 | if (Next.is(tok::colon) && !ColonIsSacred) { |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 397 | if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, II, |
| 398 | Tok.getLocation(), |
| 399 | Next.getLocation(), ObjectType, |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 400 | EnteringContext) && |
| 401 | // If the token after the colon isn't an identifier, it's still an |
| 402 | // error, but they probably meant something else strange so don't |
| 403 | // recover like this. |
| 404 | PP.LookAhead(1).is(tok::identifier)) { |
| 405 | Diag(Next, diag::err_unexected_colon_in_nested_name_spec) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 406 | << FixItHint::CreateReplacement(Next.getLocation(), "::"); |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 407 | |
| 408 | // Recover as if the user wrote '::'. |
| 409 | Next.setKind(tok::coloncolon); |
| 410 | } |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 413 | if (Next.is(tok::coloncolon)) { |
Douglas Gregor | 7754908 | 2010-02-24 21:29:12 +0000 | [diff] [blame] | 414 | if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) && |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 415 | !Actions.isNonTypeNestedNameSpecifier(getCurScope(), SS, Tok.getLocation(), |
Douglas Gregor | 7754908 | 2010-02-24 21:29:12 +0000 | [diff] [blame] | 416 | II, ObjectType)) { |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 417 | *MayBePseudoDestructor = true; |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 418 | return false; |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 421 | if (LastII) |
| 422 | *LastII = &II; |
| 423 | |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 424 | // We have an identifier followed by a '::'. Lookup this name |
| 425 | // as the name in a nested-name-specifier. |
| 426 | SourceLocation IdLoc = ConsumeToken(); |
Chris Lattner | 4664649 | 2009-12-07 01:36:53 +0000 | [diff] [blame] | 427 | assert((Tok.is(tok::coloncolon) || Tok.is(tok::colon)) && |
| 428 | "NextToken() not working properly!"); |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 429 | SourceLocation CCLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | |
Richard Trieu | 919b955 | 2012-11-02 01:08:58 +0000 | [diff] [blame] | 431 | CheckForLParenAfterColonColon(); |
| 432 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 433 | HasScopeSpecifier = true; |
| 434 | if (Actions.ActOnCXXNestedNameSpecifier(getCurScope(), II, IdLoc, CCLoc, |
| 435 | ObjectType, EnteringContext, SS)) |
| 436 | SS.SetInvalid(SourceRange(IdLoc, CCLoc)); |
| 437 | |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 438 | continue; |
| 439 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
Richard Trieu | 950be71 | 2011-09-19 19:01:00 +0000 | [diff] [blame] | 441 | CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS); |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 442 | |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 443 | // nested-name-specifier: |
| 444 | // type-name '<' |
| 445 | if (Next.is(tok::less)) { |
| 446 | TemplateTy Template; |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 447 | UnqualifiedId TemplateName; |
| 448 | TemplateName.setIdentifier(&II, Tok.getLocation()); |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 449 | bool MemberOfUnknownSpecialization; |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 450 | if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS, |
Abramo Bagnara | 7c15353 | 2010-08-06 12:11:11 +0000 | [diff] [blame] | 451 | /*hasTemplateKeyword=*/false, |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 452 | TemplateName, |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 453 | ObjectType, |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 454 | EnteringContext, |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 455 | Template, |
| 456 | MemberOfUnknownSpecialization)) { |
David Blaikie | 6796fc1 | 2011-11-07 03:30:03 +0000 | [diff] [blame] | 457 | // We have found a template name, so annotate this token |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 458 | // with a template-id annotation. We do not permit the |
| 459 | // template-id to be translated into a type annotation, |
| 460 | // because some clients (e.g., the parsing of class template |
| 461 | // specializations) still want to see the original template-id |
| 462 | // token. |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 463 | ConsumeToken(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 464 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
| 465 | TemplateName, false)) |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 466 | return true; |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 467 | continue; |
Douglas Gregor | d5ab9b0 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) && |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 471 | (IsTypename || IsTemplateArgumentList(1))) { |
Douglas Gregor | d5ab9b0 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 472 | // We have something like t::getAs<T>, where getAs is a |
| 473 | // member of an unknown specialization. However, this will only |
| 474 | // parse correctly as a template, so suggest the keyword 'template' |
| 475 | // before 'getAs' and treat this as a dependent template name. |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 476 | unsigned DiagID = diag::err_missing_dependent_template_keyword; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 477 | if (getLangOpts().MicrosoftExt) |
Francois Pichet | cf320c6 | 2011-04-22 08:25:24 +0000 | [diff] [blame] | 478 | DiagID = diag::warn_missing_dependent_template_keyword; |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 479 | |
| 480 | Diag(Tok.getLocation(), DiagID) |
Douglas Gregor | d5ab9b0 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 481 | << II.getName() |
| 482 | << FixItHint::CreateInsertion(Tok.getLocation(), "template "); |
| 483 | |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 484 | if (TemplateNameKind TNK |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 485 | = Actions.ActOnDependentTemplateName(getCurScope(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 486 | SS, SourceLocation(), |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 487 | TemplateName, ObjectType, |
| 488 | EnteringContext, Template)) { |
| 489 | // Consume the identifier. |
| 490 | ConsumeToken(); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 491 | if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), |
| 492 | TemplateName, false)) |
| 493 | return true; |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 494 | } |
| 495 | else |
Douglas Gregor | d5ab9b0 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 496 | return true; |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 497 | |
Douglas Gregor | d5ab9b0 | 2010-05-21 23:43:39 +0000 | [diff] [blame] | 498 | continue; |
Chris Lattner | 5c7f786 | 2009-06-26 03:52:38 +0000 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 502 | // We don't have any tokens that form the beginning of a |
| 503 | // nested-name-specifier, so we're done. |
| 504 | break; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 505 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 506 | |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 507 | // Even if we didn't see any pieces of a nested-name-specifier, we |
| 508 | // still check whether there is a tilde in this position, which |
| 509 | // indicates a potential pseudo-destructor. |
| 510 | if (CheckForDestructor && Tok.is(tok::tilde)) |
| 511 | *MayBePseudoDestructor = true; |
| 512 | |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 513 | return false; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /// ParseCXXIdExpression - Handle id-expression. |
| 517 | /// |
| 518 | /// id-expression: |
| 519 | /// unqualified-id |
| 520 | /// qualified-id |
| 521 | /// |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 522 | /// qualified-id: |
| 523 | /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id |
| 524 | /// '::' identifier |
| 525 | /// '::' operator-function-id |
Douglas Gregor | edce4dd | 2009-06-30 22:34:41 +0000 | [diff] [blame] | 526 | /// '::' template-id |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 527 | /// |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 528 | /// NOTE: The standard specifies that, for qualified-id, the parser does not |
| 529 | /// expect: |
| 530 | /// |
| 531 | /// '::' conversion-function-id |
| 532 | /// '::' '~' class-name |
| 533 | /// |
| 534 | /// This may cause a slight inconsistency on diagnostics: |
| 535 | /// |
| 536 | /// class C {}; |
| 537 | /// namespace A {} |
| 538 | /// void f() { |
| 539 | /// :: A :: ~ C(); // Some Sema error about using destructor with a |
| 540 | /// // namespace. |
| 541 | /// :: ~ C(); // Some Parser error like 'unexpected ~'. |
| 542 | /// } |
| 543 | /// |
| 544 | /// We simplify the parser a bit and make it work like: |
| 545 | /// |
| 546 | /// qualified-id: |
| 547 | /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id |
| 548 | /// '::' unqualified-id |
| 549 | /// |
| 550 | /// That way Sema can handle and report similar errors for namespaces and the |
| 551 | /// global scope. |
| 552 | /// |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 553 | /// The isAddressOfOperand parameter indicates that this id-expression is a |
| 554 | /// direct operand of the address-of operator. This is, besides member contexts, |
| 555 | /// the only place where a qualified-id naming a non-static class member may |
| 556 | /// appear. |
| 557 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 558 | ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 559 | // qualified-id: |
| 560 | // '::'[opt] nested-name-specifier 'template'[opt] unqualified-id |
| 561 | // '::' unqualified-id |
| 562 | // |
| 563 | CXXScopeSpec SS; |
Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 564 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 565 | |
| 566 | SourceLocation TemplateKWLoc; |
Douglas Gregor | 02a24ee | 2009-11-03 16:56:39 +0000 | [diff] [blame] | 567 | UnqualifiedId Name; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 568 | if (ParseUnqualifiedId(SS, |
| 569 | /*EnteringContext=*/false, |
| 570 | /*AllowDestructorName=*/false, |
| 571 | /*AllowConstructorName=*/false, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 572 | /*ObjectType=*/ ParsedType(), |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 573 | TemplateKWLoc, |
Douglas Gregor | 02a24ee | 2009-11-03 16:56:39 +0000 | [diff] [blame] | 574 | Name)) |
| 575 | return ExprError(); |
John McCall | b681b61 | 2009-11-22 02:49:43 +0000 | [diff] [blame] | 576 | |
| 577 | // This is only the direct operand of an & operator if it is not |
| 578 | // followed by a postfix-expression suffix. |
John McCall | 9c72c60 | 2010-08-27 09:08:28 +0000 | [diff] [blame] | 579 | if (isAddressOfOperand && isPostfixExpressionSuffixStart()) |
| 580 | isAddressOfOperand = false; |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 581 | |
| 582 | return Actions.ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Name, |
| 583 | Tok.is(tok::l_paren), isAddressOfOperand); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 586 | /// ParseLambdaExpression - Parse a C++11 lambda expression. |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 587 | /// |
| 588 | /// lambda-expression: |
| 589 | /// lambda-introducer lambda-declarator[opt] compound-statement |
| 590 | /// |
| 591 | /// lambda-introducer: |
| 592 | /// '[' lambda-capture[opt] ']' |
| 593 | /// |
| 594 | /// lambda-capture: |
| 595 | /// capture-default |
| 596 | /// capture-list |
| 597 | /// capture-default ',' capture-list |
| 598 | /// |
| 599 | /// capture-default: |
| 600 | /// '&' |
| 601 | /// '=' |
| 602 | /// |
| 603 | /// capture-list: |
| 604 | /// capture |
| 605 | /// capture-list ',' capture |
| 606 | /// |
| 607 | /// capture: |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 608 | /// simple-capture |
| 609 | /// init-capture [C++1y] |
| 610 | /// |
| 611 | /// simple-capture: |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 612 | /// identifier |
| 613 | /// '&' identifier |
| 614 | /// 'this' |
| 615 | /// |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 616 | /// init-capture: [C++1y] |
| 617 | /// identifier initializer |
| 618 | /// '&' identifier initializer |
| 619 | /// |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 620 | /// lambda-declarator: |
| 621 | /// '(' parameter-declaration-clause ')' attribute-specifier[opt] |
| 622 | /// 'mutable'[opt] exception-specification[opt] |
| 623 | /// trailing-return-type[opt] |
| 624 | /// |
| 625 | ExprResult Parser::ParseLambdaExpression() { |
| 626 | // Parse lambda-introducer. |
| 627 | LambdaIntroducer Intro; |
| 628 | |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 629 | Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro)); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 630 | if (DiagID) { |
| 631 | Diag(Tok, DiagID.getValue()); |
| 632 | SkipUntil(tok::r_square); |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 633 | SkipUntil(tok::l_brace); |
| 634 | SkipUntil(tok::r_brace); |
| 635 | return ExprError(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return ParseLambdaExpressionAfterIntroducer(Intro); |
| 639 | } |
| 640 | |
| 641 | /// TryParseLambdaExpression - Use lookahead and potentially tentative |
| 642 | /// parsing to determine if we are looking at a C++0x lambda expression, and parse |
| 643 | /// it if we are. |
| 644 | /// |
| 645 | /// If we are not looking at a lambda expression, returns ExprError(). |
| 646 | ExprResult Parser::TryParseLambdaExpression() { |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 647 | assert(getLangOpts().CPlusPlus11 |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 648 | && Tok.is(tok::l_square) |
| 649 | && "Not at the start of a possible lambda expression."); |
| 650 | |
| 651 | const Token Next = NextToken(), After = GetLookAheadToken(2); |
| 652 | |
| 653 | // If lookahead indicates this is a lambda... |
| 654 | if (Next.is(tok::r_square) || // [] |
| 655 | Next.is(tok::equal) || // [= |
| 656 | (Next.is(tok::amp) && // [&] or [&, |
| 657 | (After.is(tok::r_square) || |
| 658 | After.is(tok::comma))) || |
| 659 | (Next.is(tok::identifier) && // [identifier] |
| 660 | After.is(tok::r_square))) { |
| 661 | return ParseLambdaExpression(); |
| 662 | } |
| 663 | |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 664 | // If lookahead indicates an ObjC message send... |
| 665 | // [identifier identifier |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 666 | if (Next.is(tok::identifier) && After.is(tok::identifier)) { |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 667 | return ExprEmpty(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 670 | // Here, we're stuck: lambda introducers and Objective-C message sends are |
| 671 | // unambiguous, but it requires arbitrary lookhead. [a,b,c,d,e,f,g] is a |
| 672 | // lambda, and [a,b,c,d,e,f,g h] is a Objective-C message send. Instead of |
| 673 | // writing two routines to parse a lambda introducer, just try to parse |
| 674 | // a lambda introducer first, and fall back if that fails. |
| 675 | // (TryParseLambdaIntroducer never produces any diagnostic output.) |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 676 | LambdaIntroducer Intro; |
| 677 | if (TryParseLambdaIntroducer(Intro)) |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 678 | return ExprEmpty(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 679 | return ParseLambdaExpressionAfterIntroducer(Intro); |
| 680 | } |
| 681 | |
Richard Smith | 440d456 | 2013-05-21 22:21:19 +0000 | [diff] [blame] | 682 | /// \brief Parse a lambda introducer. |
| 683 | /// \param Intro A LambdaIntroducer filled in with information about the |
| 684 | /// contents of the lambda-introducer. |
| 685 | /// \param SkippedInits If non-null, we are disambiguating between an Obj-C |
| 686 | /// message send and a lambda expression. In this mode, we will |
| 687 | /// sometimes skip the initializers for init-captures and not fully |
| 688 | /// populate \p Intro. This flag will be set to \c true if we do so. |
| 689 | /// \return A DiagnosticID if it hit something unexpected. The location for |
| 690 | /// for the diagnostic is that of the current token. |
| 691 | Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, |
| 692 | bool *SkippedInits) { |
David Blaikie | dc84cd5 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 693 | typedef Optional<unsigned> DiagResult; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 694 | |
| 695 | assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['."); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 696 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 697 | T.consumeOpen(); |
| 698 | |
| 699 | Intro.Range.setBegin(T.getOpenLocation()); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 700 | |
| 701 | bool first = true; |
| 702 | |
| 703 | // Parse capture-default. |
| 704 | if (Tok.is(tok::amp) && |
| 705 | (NextToken().is(tok::comma) || NextToken().is(tok::r_square))) { |
| 706 | Intro.Default = LCD_ByRef; |
Douglas Gregor | 3ac109c | 2012-02-10 17:46:20 +0000 | [diff] [blame] | 707 | Intro.DefaultLoc = ConsumeToken(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 708 | first = false; |
| 709 | } else if (Tok.is(tok::equal)) { |
| 710 | Intro.Default = LCD_ByCopy; |
Douglas Gregor | 3ac109c | 2012-02-10 17:46:20 +0000 | [diff] [blame] | 711 | Intro.DefaultLoc = ConsumeToken(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 712 | first = false; |
| 713 | } |
| 714 | |
| 715 | while (Tok.isNot(tok::r_square)) { |
| 716 | if (!first) { |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 717 | if (Tok.isNot(tok::comma)) { |
Douglas Gregor | 437fbc5 | 2012-07-31 00:50:07 +0000 | [diff] [blame] | 718 | // Provide a completion for a lambda introducer here. Except |
| 719 | // in Objective-C, where this is Almost Surely meant to be a message |
| 720 | // send. In that case, fail here and let the ObjC message |
| 721 | // expression parser perform the completion. |
Douglas Gregor | d48ab06 | 2012-07-31 15:27:48 +0000 | [diff] [blame] | 722 | if (Tok.is(tok::code_completion) && |
| 723 | !(getLangOpts().ObjC1 && Intro.Default == LCD_None && |
| 724 | !Intro.Captures.empty())) { |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 725 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
| 726 | /*AfterAmpersand=*/false); |
| 727 | ConsumeCodeCompletionToken(); |
| 728 | break; |
| 729 | } |
| 730 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 731 | return DiagResult(diag::err_expected_comma_or_rsquare); |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 732 | } |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 733 | ConsumeToken(); |
| 734 | } |
| 735 | |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 736 | if (Tok.is(tok::code_completion)) { |
| 737 | // If we're in Objective-C++ and we have a bare '[', then this is more |
| 738 | // likely to be a message receiver. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 739 | if (getLangOpts().ObjC1 && first) |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 740 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
| 741 | else |
| 742 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
| 743 | /*AfterAmpersand=*/false); |
| 744 | ConsumeCodeCompletionToken(); |
| 745 | break; |
| 746 | } |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 747 | |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 748 | first = false; |
| 749 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 750 | // Parse capture. |
| 751 | LambdaCaptureKind Kind = LCK_ByCopy; |
| 752 | SourceLocation Loc; |
| 753 | IdentifierInfo* Id = 0; |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 754 | SourceLocation EllipsisLoc; |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 755 | ExprResult Init; |
Douglas Gregor | a736524 | 2012-02-14 19:27:52 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 757 | if (Tok.is(tok::kw_this)) { |
| 758 | Kind = LCK_This; |
| 759 | Loc = ConsumeToken(); |
| 760 | } else { |
| 761 | if (Tok.is(tok::amp)) { |
| 762 | Kind = LCK_ByRef; |
| 763 | ConsumeToken(); |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 764 | |
| 765 | if (Tok.is(tok::code_completion)) { |
| 766 | Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, |
| 767 | /*AfterAmpersand=*/true); |
| 768 | ConsumeCodeCompletionToken(); |
| 769 | break; |
| 770 | } |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | if (Tok.is(tok::identifier)) { |
| 774 | Id = Tok.getIdentifierInfo(); |
| 775 | Loc = ConsumeToken(); |
| 776 | } else if (Tok.is(tok::kw_this)) { |
| 777 | // FIXME: If we want to suggest a fixit here, will need to return more |
| 778 | // than just DiagnosticID. Perhaps full DiagnosticBuilder that can be |
| 779 | // Clear()ed to prevent emission in case of tentative parsing? |
| 780 | return DiagResult(diag::err_this_captured_by_reference); |
| 781 | } else { |
| 782 | return DiagResult(diag::err_expected_capture); |
| 783 | } |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 784 | |
| 785 | if (Tok.is(tok::l_paren)) { |
| 786 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 787 | Parens.consumeOpen(); |
| 788 | |
| 789 | ExprVector Exprs; |
| 790 | CommaLocsTy Commas; |
Richard Smith | 440d456 | 2013-05-21 22:21:19 +0000 | [diff] [blame] | 791 | if (SkippedInits) { |
| 792 | Parens.skipToEnd(); |
| 793 | *SkippedInits = true; |
| 794 | } else if (ParseExpressionList(Exprs, Commas)) { |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 795 | Parens.skipToEnd(); |
| 796 | Init = ExprError(); |
| 797 | } else { |
| 798 | Parens.consumeClose(); |
| 799 | Init = Actions.ActOnParenListExpr(Parens.getOpenLocation(), |
| 800 | Parens.getCloseLocation(), |
| 801 | Exprs); |
| 802 | } |
| 803 | } else if (Tok.is(tok::l_brace) || Tok.is(tok::equal)) { |
| 804 | if (Tok.is(tok::equal)) |
| 805 | ConsumeToken(); |
| 806 | |
Richard Smith | 440d456 | 2013-05-21 22:21:19 +0000 | [diff] [blame] | 807 | if (!SkippedInits) |
| 808 | Init = ParseInitializer(); |
| 809 | else if (Tok.is(tok::l_brace)) { |
| 810 | BalancedDelimiterTracker Braces(*this, tok::l_brace); |
| 811 | Braces.consumeOpen(); |
| 812 | Braces.skipToEnd(); |
| 813 | *SkippedInits = true; |
| 814 | } else { |
| 815 | // We're disambiguating this: |
| 816 | // |
| 817 | // [..., x = expr |
| 818 | // |
| 819 | // We need to find the end of the following expression in order to |
| 820 | // determine whether this is an Obj-C message send's receiver, or a |
| 821 | // lambda init-capture. |
| 822 | // |
| 823 | // Parse the expression to find where it ends, and annotate it back |
| 824 | // onto the tokens. We would have parsed this expression the same way |
| 825 | // in either case: both the RHS of an init-capture and the RHS of an |
| 826 | // assignment expression are parsed as an initializer-clause, and in |
| 827 | // neither case can anything be added to the scope between the '[' and |
| 828 | // here. |
| 829 | // |
| 830 | // FIXME: This is horrible. Adding a mechanism to skip an expression |
| 831 | // would be much cleaner. |
| 832 | // FIXME: If there is a ',' before the next ']' or ':', we can skip to |
| 833 | // that instead. (And if we see a ':' with no matching '?', we can |
| 834 | // classify this as an Obj-C message send.) |
| 835 | SourceLocation StartLoc = Tok.getLocation(); |
| 836 | InMessageExpressionRAIIObject MaybeInMessageExpression(*this, true); |
| 837 | Init = ParseInitializer(); |
| 838 | |
| 839 | if (Tok.getLocation() != StartLoc) { |
| 840 | // Back out the lexing of the token after the initializer. |
| 841 | PP.RevertCachedTokens(1); |
| 842 | |
| 843 | // Replace the consumed tokens with an appropriate annotation. |
| 844 | Tok.setLocation(StartLoc); |
| 845 | Tok.setKind(tok::annot_primary_expr); |
| 846 | setExprAnnotation(Tok, Init); |
| 847 | Tok.setAnnotationEndLoc(PP.getLastCachedTokenLocation()); |
| 848 | PP.AnnotateCachedTokens(Tok); |
| 849 | |
| 850 | // Consume the annotated initializer. |
| 851 | ConsumeToken(); |
| 852 | } |
| 853 | } |
Richard Smith | 0d8e964 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 854 | } else if (Tok.is(tok::ellipsis)) |
| 855 | EllipsisLoc = ConsumeToken(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 858 | Intro.addCapture(Kind, Loc, Id, EllipsisLoc, Init); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 861 | T.consumeClose(); |
| 862 | Intro.Range.setEnd(T.getCloseLocation()); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 863 | |
| 864 | return DiagResult(); |
| 865 | } |
| 866 | |
Douglas Gregor | 81f3bff | 2012-02-15 15:34:24 +0000 | [diff] [blame] | 867 | /// TryParseLambdaIntroducer - Tentatively parse a lambda introducer. |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 868 | /// |
| 869 | /// Returns true if it hit something unexpected. |
| 870 | bool Parser::TryParseLambdaIntroducer(LambdaIntroducer &Intro) { |
| 871 | TentativeParsingAction PA(*this); |
| 872 | |
Richard Smith | 440d456 | 2013-05-21 22:21:19 +0000 | [diff] [blame] | 873 | bool SkippedInits = false; |
| 874 | Optional<unsigned> DiagID(ParseLambdaIntroducer(Intro, &SkippedInits)); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 875 | |
| 876 | if (DiagID) { |
| 877 | PA.Revert(); |
| 878 | return true; |
| 879 | } |
| 880 | |
Richard Smith | 440d456 | 2013-05-21 22:21:19 +0000 | [diff] [blame] | 881 | if (SkippedInits) { |
| 882 | // Parse it again, but this time parse the init-captures too. |
| 883 | PA.Revert(); |
| 884 | Intro = LambdaIntroducer(); |
| 885 | DiagID = ParseLambdaIntroducer(Intro); |
| 886 | assert(!DiagID && "parsing lambda-introducer failed on reparse"); |
| 887 | return false; |
| 888 | } |
| 889 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 890 | PA.Commit(); |
| 891 | return false; |
| 892 | } |
| 893 | |
| 894 | /// ParseLambdaExpressionAfterIntroducer - Parse the rest of a lambda |
| 895 | /// expression. |
| 896 | ExprResult Parser::ParseLambdaExpressionAfterIntroducer( |
| 897 | LambdaIntroducer &Intro) { |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 898 | SourceLocation LambdaBeginLoc = Intro.Range.getBegin(); |
| 899 | Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda); |
| 900 | |
| 901 | PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc, |
| 902 | "lambda expression parsing"); |
| 903 | |
Richard Smith | 0a664b8 | 2013-05-09 21:36:41 +0000 | [diff] [blame] | 904 | // FIXME: Call into Actions to add any init-capture declarations to the |
| 905 | // scope while parsing the lambda-declarator and compound-statement. |
| 906 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 907 | // Parse lambda-declarator[opt]. |
| 908 | DeclSpec DS(AttrFactory); |
Eli Friedman | f88c400 | 2012-01-04 04:41:38 +0000 | [diff] [blame] | 909 | Declarator D(DS, Declarator::LambdaExprContext); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 910 | |
| 911 | if (Tok.is(tok::l_paren)) { |
| 912 | ParseScope PrototypeScope(this, |
| 913 | Scope::FunctionPrototypeScope | |
Richard Smith | 3a2b7a1 | 2013-01-28 22:42:45 +0000 | [diff] [blame] | 914 | Scope::FunctionDeclarationScope | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 915 | Scope::DeclScope); |
| 916 | |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 917 | SourceLocation DeclEndLoc; |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 918 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 919 | T.consumeOpen(); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 920 | SourceLocation LParenLoc = T.getOpenLocation(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 921 | |
| 922 | // Parse parameter-declaration-clause. |
| 923 | ParsedAttributes Attr(AttrFactory); |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 924 | SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 925 | SourceLocation EllipsisLoc; |
| 926 | |
| 927 | if (Tok.isNot(tok::r_paren)) |
| 928 | ParseParameterDeclarationClause(D, Attr, ParamInfo, EllipsisLoc); |
| 929 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 930 | T.consumeClose(); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 931 | SourceLocation RParenLoc = T.getCloseLocation(); |
| 932 | DeclEndLoc = RParenLoc; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 933 | |
| 934 | // Parse 'mutable'[opt]. |
| 935 | SourceLocation MutableLoc; |
| 936 | if (Tok.is(tok::kw_mutable)) { |
| 937 | MutableLoc = ConsumeToken(); |
| 938 | DeclEndLoc = MutableLoc; |
| 939 | } |
| 940 | |
| 941 | // Parse exception-specification[opt]. |
| 942 | ExceptionSpecificationType ESpecType = EST_None; |
| 943 | SourceRange ESpecRange; |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 944 | SmallVector<ParsedType, 2> DynamicExceptions; |
| 945 | SmallVector<SourceRange, 2> DynamicExceptionRanges; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 946 | ExprResult NoexceptExpr; |
Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 947 | ESpecType = tryParseExceptionSpecification(ESpecRange, |
Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 948 | DynamicExceptions, |
| 949 | DynamicExceptionRanges, |
Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 950 | NoexceptExpr); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 951 | |
| 952 | if (ESpecType != EST_None) |
| 953 | DeclEndLoc = ESpecRange.getEnd(); |
| 954 | |
| 955 | // Parse attribute-specifier[opt]. |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 956 | MaybeParseCXX11Attributes(Attr, &DeclEndLoc); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 957 | |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 958 | SourceLocation FunLocalRangeEnd = DeclEndLoc; |
| 959 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 960 | // Parse trailing-return-type[opt]. |
Richard Smith | 54655be | 2012-06-12 01:51:59 +0000 | [diff] [blame] | 961 | TypeResult TrailingReturnType; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 962 | if (Tok.is(tok::arrow)) { |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 963 | FunLocalRangeEnd = Tok.getLocation(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 964 | SourceRange Range; |
Richard Smith | 54655be | 2012-06-12 01:51:59 +0000 | [diff] [blame] | 965 | TrailingReturnType = ParseTrailingReturnType(Range); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 966 | if (Range.getEnd().isValid()) |
| 967 | DeclEndLoc = Range.getEnd(); |
| 968 | } |
| 969 | |
| 970 | PrototypeScope.Exit(); |
| 971 | |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 972 | SourceLocation NoLoc; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 973 | D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true, |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 974 | /*isAmbiguous=*/false, |
| 975 | LParenLoc, |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 976 | ParamInfo.data(), ParamInfo.size(), |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 977 | EllipsisLoc, RParenLoc, |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 978 | DS.getTypeQualifiers(), |
| 979 | /*RefQualifierIsLValueRef=*/true, |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 980 | /*RefQualifierLoc=*/NoLoc, |
| 981 | /*ConstQualifierLoc=*/NoLoc, |
| 982 | /*VolatileQualifierLoc=*/NoLoc, |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 983 | MutableLoc, |
| 984 | ESpecType, ESpecRange.getBegin(), |
| 985 | DynamicExceptions.data(), |
| 986 | DynamicExceptionRanges.data(), |
| 987 | DynamicExceptions.size(), |
| 988 | NoexceptExpr.isUsable() ? |
| 989 | NoexceptExpr.get() : 0, |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 990 | LParenLoc, FunLocalRangeEnd, D, |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 991 | TrailingReturnType), |
| 992 | Attr, DeclEndLoc); |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 993 | } else if (Tok.is(tok::kw_mutable) || Tok.is(tok::arrow)) { |
| 994 | // It's common to forget that one needs '()' before 'mutable' or the |
| 995 | // result type. Deal with this. |
| 996 | Diag(Tok, diag::err_lambda_missing_parens) |
| 997 | << Tok.is(tok::arrow) |
| 998 | << FixItHint::CreateInsertion(Tok.getLocation(), "() "); |
| 999 | SourceLocation DeclLoc = Tok.getLocation(); |
| 1000 | SourceLocation DeclEndLoc = DeclLoc; |
| 1001 | |
| 1002 | // Parse 'mutable', if it's there. |
| 1003 | SourceLocation MutableLoc; |
| 1004 | if (Tok.is(tok::kw_mutable)) { |
| 1005 | MutableLoc = ConsumeToken(); |
| 1006 | DeclEndLoc = MutableLoc; |
| 1007 | } |
| 1008 | |
| 1009 | // Parse the return type, if there is one. |
Richard Smith | 54655be | 2012-06-12 01:51:59 +0000 | [diff] [blame] | 1010 | TypeResult TrailingReturnType; |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 1011 | if (Tok.is(tok::arrow)) { |
| 1012 | SourceRange Range; |
Richard Smith | 54655be | 2012-06-12 01:51:59 +0000 | [diff] [blame] | 1013 | TrailingReturnType = ParseTrailingReturnType(Range); |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 1014 | if (Range.getEnd().isValid()) |
| 1015 | DeclEndLoc = Range.getEnd(); |
| 1016 | } |
| 1017 | |
| 1018 | ParsedAttributes Attr(AttrFactory); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 1019 | SourceLocation NoLoc; |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 1020 | D.AddTypeInfo(DeclaratorChunk::getFunction(/*hasProto=*/true, |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 1021 | /*isAmbiguous=*/false, |
| 1022 | /*LParenLoc=*/NoLoc, |
| 1023 | /*Params=*/0, |
| 1024 | /*NumParams=*/0, |
| 1025 | /*EllipsisLoc=*/NoLoc, |
| 1026 | /*RParenLoc=*/NoLoc, |
| 1027 | /*TypeQuals=*/0, |
| 1028 | /*RefQualifierIsLValueRef=*/true, |
| 1029 | /*RefQualifierLoc=*/NoLoc, |
| 1030 | /*ConstQualifierLoc=*/NoLoc, |
| 1031 | /*VolatileQualifierLoc=*/NoLoc, |
| 1032 | MutableLoc, |
| 1033 | EST_None, |
| 1034 | /*ESpecLoc=*/NoLoc, |
| 1035 | /*Exceptions=*/0, |
| 1036 | /*ExceptionRanges=*/0, |
| 1037 | /*NumExceptions=*/0, |
| 1038 | /*NoexceptExpr=*/0, |
| 1039 | DeclLoc, DeclEndLoc, D, |
| 1040 | TrailingReturnType), |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 1041 | Attr, DeclEndLoc); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1042 | } |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 1043 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1044 | |
Eli Friedman | 906a7e1 | 2012-01-06 03:05:34 +0000 | [diff] [blame] | 1045 | // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using |
| 1046 | // it. |
Douglas Gregor | fccfb62 | 2012-02-21 22:51:27 +0000 | [diff] [blame] | 1047 | unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope; |
Douglas Gregor | fccfb62 | 2012-02-21 22:51:27 +0000 | [diff] [blame] | 1048 | ParseScope BodyScope(this, ScopeFlags); |
Eli Friedman | 906a7e1 | 2012-01-06 03:05:34 +0000 | [diff] [blame] | 1049 | |
Eli Friedman | ec9ea72 | 2012-01-05 03:35:19 +0000 | [diff] [blame] | 1050 | Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope()); |
| 1051 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1052 | // Parse compound-statement. |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 1053 | if (!Tok.is(tok::l_brace)) { |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1054 | Diag(Tok, diag::err_expected_lambda_body); |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 1055 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
| 1056 | return ExprError(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 1059 | StmtResult Stmt(ParseCompoundStatementBody()); |
| 1060 | BodyScope.Exit(); |
| 1061 | |
Eli Friedman | deeab90 | 2012-01-04 02:46:53 +0000 | [diff] [blame] | 1062 | if (!Stmt.isInvalid()) |
Douglas Gregor | 9e8c92a | 2012-02-20 19:44:39 +0000 | [diff] [blame] | 1063 | return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.take(), getCurScope()); |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 1064 | |
Eli Friedman | deeab90 | 2012-01-04 02:46:53 +0000 | [diff] [blame] | 1065 | Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope()); |
| 1066 | return ExprError(); |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1069 | /// ParseCXXCasts - This handles the various ways to cast expressions to another |
| 1070 | /// type. |
| 1071 | /// |
| 1072 | /// postfix-expression: [C++ 5.2p1] |
| 1073 | /// 'dynamic_cast' '<' type-name '>' '(' expression ')' |
| 1074 | /// 'static_cast' '<' type-name '>' '(' expression ')' |
| 1075 | /// 'reinterpret_cast' '<' type-name '>' '(' expression ')' |
| 1076 | /// 'const_cast' '<' type-name '>' '(' expression ')' |
| 1077 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1078 | ExprResult Parser::ParseCXXCasts() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1079 | tok::TokenKind Kind = Tok.getKind(); |
| 1080 | const char *CastName = 0; // For error messages |
| 1081 | |
| 1082 | switch (Kind) { |
David Blaikie | eb2d1f1 | 2011-09-23 20:26:49 +0000 | [diff] [blame] | 1083 | default: llvm_unreachable("Unknown C++ cast!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1084 | case tok::kw_const_cast: CastName = "const_cast"; break; |
| 1085 | case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break; |
| 1086 | case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break; |
| 1087 | case tok::kw_static_cast: CastName = "static_cast"; break; |
| 1088 | } |
| 1089 | |
| 1090 | SourceLocation OpLoc = ConsumeToken(); |
| 1091 | SourceLocation LAngleBracketLoc = Tok.getLocation(); |
| 1092 | |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 1093 | // Check for "<::" which is parsed as "[:". If found, fix token stream, |
| 1094 | // diagnose error, suggest fix, and recover parsing. |
Richard Smith | 78fe3e0 | 2012-08-20 17:37:52 +0000 | [diff] [blame] | 1095 | if (Tok.is(tok::l_square) && Tok.getLength() == 2) { |
| 1096 | Token Next = NextToken(); |
| 1097 | if (Next.is(tok::colon) && areTokensAdjacent(Tok, Next)) |
| 1098 | FixDigraph(*this, PP, Tok, Next, Kind, /*AtDigraph*/true); |
| 1099 | } |
Richard Smith | ea698b3 | 2011-04-14 21:45:45 +0000 | [diff] [blame] | 1100 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1101 | if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName)) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1102 | return ExprError(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1103 | |
Argyrios Kyrtzidis | 31862ba | 2011-07-01 22:22:50 +0000 | [diff] [blame] | 1104 | // Parse the common declaration-specifiers piece. |
| 1105 | DeclSpec DS(AttrFactory); |
| 1106 | ParseSpecifierQualifierList(DS); |
| 1107 | |
| 1108 | // Parse the abstract-declarator, if present. |
| 1109 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 1110 | ParseDeclarator(DeclaratorInfo); |
| 1111 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1112 | SourceLocation RAngleBracketLoc = Tok.getLocation(); |
| 1113 | |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1114 | if (ExpectAndConsume(tok::greater, diag::err_expected_greater)) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1115 | return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << "<"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1116 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1117 | SourceLocation LParenLoc, RParenLoc; |
| 1118 | BalancedDelimiterTracker T(*this, tok::l_paren); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1119 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1120 | if (T.expectAndConsume(diag::err_expected_lparen_after, CastName)) |
Argyrios Kyrtzidis | 21e7ad2 | 2009-05-22 10:23:16 +0000 | [diff] [blame] | 1121 | return ExprError(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1122 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1123 | ExprResult Result = ParseExpression(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Argyrios Kyrtzidis | 21e7ad2 | 2009-05-22 10:23:16 +0000 | [diff] [blame] | 1125 | // Match the ')'. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1126 | T.consumeClose(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1127 | |
Argyrios Kyrtzidis | 31862ba | 2011-07-01 22:22:50 +0000 | [diff] [blame] | 1128 | if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType()) |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 1129 | Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, |
Argyrios Kyrtzidis | 31862ba | 2011-07-01 22:22:50 +0000 | [diff] [blame] | 1130 | LAngleBracketLoc, DeclaratorInfo, |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 1131 | RAngleBracketLoc, |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1132 | T.getOpenLocation(), Result.take(), |
| 1133 | T.getCloseLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1134 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1135 | return Result; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1138 | /// ParseCXXTypeid - This handles the C++ typeid expression. |
| 1139 | /// |
| 1140 | /// postfix-expression: [C++ 5.2p1] |
| 1141 | /// 'typeid' '(' expression ')' |
| 1142 | /// 'typeid' '(' type-id ')' |
| 1143 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1144 | ExprResult Parser::ParseCXXTypeid() { |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1145 | assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!"); |
| 1146 | |
| 1147 | SourceLocation OpLoc = ConsumeToken(); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1148 | SourceLocation LParenLoc, RParenLoc; |
| 1149 | BalancedDelimiterTracker T(*this, tok::l_paren); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1150 | |
| 1151 | // typeid expressions are always parenthesized. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1152 | if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid")) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1153 | return ExprError(); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1154 | LParenLoc = T.getOpenLocation(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1155 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1156 | ExprResult Result; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1157 | |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 1158 | // C++0x [expr.typeid]p3: |
| 1159 | // When typeid is applied to an expression other than an lvalue of a |
| 1160 | // polymorphic class type [...] The expression is an unevaluated |
| 1161 | // operand (Clause 5). |
| 1162 | // |
| 1163 | // Note that we can't tell whether the expression is an lvalue of a |
| 1164 | // polymorphic class type until after we've parsed the expression; we |
| 1165 | // speculatively assume the subexpression is unevaluated, and fix it up |
| 1166 | // later. |
| 1167 | // |
| 1168 | // We enter the unevaluated context before trying to determine whether we |
| 1169 | // have a type-id, because the tentative parse logic will try to resolve |
| 1170 | // names, and must treat them as unevaluated. |
Eli Friedman | 80bfa3d | 2012-09-26 04:34:21 +0000 | [diff] [blame] | 1171 | EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, |
| 1172 | Sema::ReuseLambdaContextDecl); |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 1173 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1174 | if (isTypeIdInParens()) { |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 1175 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1176 | |
| 1177 | // Match the ')'. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1178 | T.consumeClose(); |
| 1179 | RParenLoc = T.getCloseLocation(); |
Douglas Gregor | 4eb4f0f | 2010-09-08 23:14:30 +0000 | [diff] [blame] | 1180 | if (Ty.isInvalid() || RParenLoc.isInvalid()) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1181 | return ExprError(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1182 | |
| 1183 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1184 | Ty.get().getAsOpaquePtr(), RParenLoc); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1185 | } else { |
| 1186 | Result = ParseExpression(); |
| 1187 | |
| 1188 | // Match the ')'. |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1189 | if (Result.isInvalid()) |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1190 | SkipUntil(tok::r_paren); |
| 1191 | else { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1192 | T.consumeClose(); |
| 1193 | RParenLoc = T.getCloseLocation(); |
Douglas Gregor | 4eb4f0f | 2010-09-08 23:14:30 +0000 | [diff] [blame] | 1194 | if (RParenLoc.isInvalid()) |
| 1195 | return ExprError(); |
Douglas Gregor | fadb53b | 2011-03-12 01:48:56 +0000 | [diff] [blame] | 1196 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1197 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false, |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 1198 | Result.release(), RParenLoc); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1202 | return Result; |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1205 | /// ParseCXXUuidof - This handles the Microsoft C++ __uuidof expression. |
| 1206 | /// |
| 1207 | /// '__uuidof' '(' expression ')' |
| 1208 | /// '__uuidof' '(' type-id ')' |
| 1209 | /// |
| 1210 | ExprResult Parser::ParseCXXUuidof() { |
| 1211 | assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!"); |
| 1212 | |
| 1213 | SourceLocation OpLoc = ConsumeToken(); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1214 | BalancedDelimiterTracker T(*this, tok::l_paren); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1215 | |
| 1216 | // __uuidof expressions are always parenthesized. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1217 | if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof")) |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1218 | return ExprError(); |
| 1219 | |
| 1220 | ExprResult Result; |
| 1221 | |
| 1222 | if (isTypeIdInParens()) { |
| 1223 | TypeResult Ty = ParseTypeName(); |
| 1224 | |
| 1225 | // Match the ')'. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1226 | T.consumeClose(); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1227 | |
| 1228 | if (Ty.isInvalid()) |
| 1229 | return ExprError(); |
| 1230 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1231 | Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), /*isType=*/true, |
| 1232 | Ty.get().getAsOpaquePtr(), |
| 1233 | T.getCloseLocation()); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1234 | } else { |
| 1235 | EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); |
| 1236 | Result = ParseExpression(); |
| 1237 | |
| 1238 | // Match the ')'. |
| 1239 | if (Result.isInvalid()) |
| 1240 | SkipUntil(tok::r_paren); |
| 1241 | else { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1242 | T.consumeClose(); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1243 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1244 | Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), |
| 1245 | /*isType=*/false, |
| 1246 | Result.release(), T.getCloseLocation()); |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1250 | return Result; |
Francois Pichet | 01b7c30 | 2010-09-08 12:20:18 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1253 | /// \brief Parse a C++ pseudo-destructor expression after the base, |
| 1254 | /// . or -> operator, and nested-name-specifier have already been |
| 1255 | /// parsed. |
| 1256 | /// |
| 1257 | /// postfix-expression: [C++ 5.2] |
| 1258 | /// postfix-expression . pseudo-destructor-name |
| 1259 | /// postfix-expression -> pseudo-destructor-name |
| 1260 | /// |
| 1261 | /// pseudo-destructor-name: |
| 1262 | /// ::[opt] nested-name-specifier[opt] type-name :: ~type-name |
| 1263 | /// ::[opt] nested-name-specifier template simple-template-id :: |
| 1264 | /// ~type-name |
| 1265 | /// ::[opt] nested-name-specifier[opt] ~type-name |
| 1266 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1267 | ExprResult |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1268 | Parser::ParseCXXPseudoDestructor(ExprArg Base, SourceLocation OpLoc, |
| 1269 | tok::TokenKind OpKind, |
| 1270 | CXXScopeSpec &SS, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1271 | ParsedType ObjectType) { |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1272 | // We're parsing either a pseudo-destructor-name or a dependent |
| 1273 | // member access that has the same form as a |
| 1274 | // pseudo-destructor-name. We parse both in the same way and let |
| 1275 | // the action model sort them out. |
| 1276 | // |
| 1277 | // Note that the ::[opt] nested-name-specifier[opt] has already |
| 1278 | // been parsed, and if there was a simple-template-id, it has |
| 1279 | // been coalesced into a template-id annotation token. |
| 1280 | UnqualifiedId FirstTypeName; |
| 1281 | SourceLocation CCLoc; |
| 1282 | if (Tok.is(tok::identifier)) { |
| 1283 | FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 1284 | ConsumeToken(); |
| 1285 | assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); |
| 1286 | CCLoc = ConsumeToken(); |
| 1287 | } else if (Tok.is(tok::annot_template_id)) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1288 | // FIXME: retrieve TemplateKWLoc from template-id annotation and |
| 1289 | // store it in the pseudo-dtor node (to be used when instantiating it). |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1290 | FirstTypeName.setTemplateId( |
| 1291 | (TemplateIdAnnotation *)Tok.getAnnotationValue()); |
| 1292 | ConsumeToken(); |
| 1293 | assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail"); |
| 1294 | CCLoc = ConsumeToken(); |
| 1295 | } else { |
| 1296 | FirstTypeName.setIdentifier(0, SourceLocation()); |
| 1297 | } |
| 1298 | |
| 1299 | // Parse the tilde. |
| 1300 | assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail"); |
| 1301 | SourceLocation TildeLoc = ConsumeToken(); |
David Blaikie | 91ec789 | 2011-12-16 16:03:09 +0000 | [diff] [blame] | 1302 | |
| 1303 | if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid() && SS.isEmpty()) { |
| 1304 | DeclSpec DS(AttrFactory); |
Benjamin Kramer | 85c60db | 2011-12-18 12:18:02 +0000 | [diff] [blame] | 1305 | ParseDecltypeSpecifier(DS); |
David Blaikie | 91ec789 | 2011-12-16 16:03:09 +0000 | [diff] [blame] | 1306 | if (DS.getTypeSpecType() == TST_error) |
| 1307 | return ExprError(); |
| 1308 | return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, |
| 1309 | OpKind, TildeLoc, DS, |
| 1310 | Tok.is(tok::l_paren)); |
| 1311 | } |
| 1312 | |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1313 | if (!Tok.is(tok::identifier)) { |
| 1314 | Diag(Tok, diag::err_destructor_tilde_identifier); |
| 1315 | return ExprError(); |
| 1316 | } |
| 1317 | |
| 1318 | // Parse the second type. |
| 1319 | UnqualifiedId SecondTypeName; |
| 1320 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 1321 | SourceLocation NameLoc = ConsumeToken(); |
| 1322 | SecondTypeName.setIdentifier(Name, NameLoc); |
| 1323 | |
| 1324 | // If there is a '<', the second type name is a template-id. Parse |
| 1325 | // it as such. |
| 1326 | if (Tok.is(tok::less) && |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1327 | ParseUnqualifiedIdTemplateId(SS, SourceLocation(), |
| 1328 | Name, NameLoc, |
| 1329 | false, ObjectType, SecondTypeName, |
| 1330 | /*AssumeTemplateName=*/true)) |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1331 | return ExprError(); |
| 1332 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1333 | return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, |
| 1334 | OpLoc, OpKind, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1335 | SS, FirstTypeName, CCLoc, |
| 1336 | TildeLoc, SecondTypeName, |
| 1337 | Tok.is(tok::l_paren)); |
| 1338 | } |
| 1339 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1340 | /// ParseCXXBoolLiteral - This handles the C++ Boolean literals. |
| 1341 | /// |
| 1342 | /// boolean-literal: [C++ 2.13.5] |
| 1343 | /// 'true' |
| 1344 | /// 'false' |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1345 | ExprResult Parser::ParseCXXBoolLiteral() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1346 | tok::TokenKind Kind = Tok.getKind(); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1347 | return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1348 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1349 | |
| 1350 | /// ParseThrowExpression - This handles the C++ throw expression. |
| 1351 | /// |
| 1352 | /// throw-expression: [C++ 15] |
| 1353 | /// 'throw' assignment-expression[opt] |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1354 | ExprResult Parser::ParseThrowExpression() { |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1355 | assert(Tok.is(tok::kw_throw) && "Not throw!"); |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1356 | SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token. |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1357 | |
Chris Lattner | 2a2819a | 2008-04-06 06:02:23 +0000 | [diff] [blame] | 1358 | // If the current token isn't the start of an assignment-expression, |
| 1359 | // then the expression is not present. This handles things like: |
| 1360 | // "C ? throw : (void)42", which is crazy but legal. |
| 1361 | switch (Tok.getKind()) { // FIXME: move this predicate somewhere common. |
| 1362 | case tok::semi: |
| 1363 | case tok::r_paren: |
| 1364 | case tok::r_square: |
| 1365 | case tok::r_brace: |
| 1366 | case tok::colon: |
| 1367 | case tok::comma: |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1368 | return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, 0); |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1369 | |
Chris Lattner | 2a2819a | 2008-04-06 06:02:23 +0000 | [diff] [blame] | 1370 | default: |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1371 | ExprResult Expr(ParseAssignmentExpression()); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1372 | if (Expr.isInvalid()) return Expr; |
Douglas Gregor | bca01b4 | 2011-07-06 22:04:06 +0000 | [diff] [blame] | 1373 | return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.take()); |
Chris Lattner | 2a2819a | 2008-04-06 06:02:23 +0000 | [diff] [blame] | 1374 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 1375 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1376 | |
| 1377 | /// ParseCXXThis - This handles the C++ 'this' pointer. |
| 1378 | /// |
| 1379 | /// C++ 9.3.2: In the body of a non-static member function, the keyword this is |
| 1380 | /// a non-lvalue expression whose value is the address of the object for which |
| 1381 | /// the function is called. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1382 | ExprResult Parser::ParseCXXThis() { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1383 | assert(Tok.is(tok::kw_this) && "Not 'this'!"); |
| 1384 | SourceLocation ThisLoc = ConsumeToken(); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 1385 | return Actions.ActOnCXXThis(ThisLoc); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1386 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1387 | |
| 1388 | /// ParseCXXTypeConstructExpression - Parse construction of a specified type. |
| 1389 | /// Can be interpreted either as function-style casting ("int(x)") |
| 1390 | /// or class type construction ("ClassType(x,y,z)") |
| 1391 | /// or creation of a value-initialized type ("int()"). |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1392 | /// See [C++ 5.2.3]. |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1393 | /// |
| 1394 | /// postfix-expression: [C++ 5.2p1] |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1395 | /// simple-type-specifier '(' expression-list[opt] ')' |
| 1396 | /// [C++0x] simple-type-specifier braced-init-list |
| 1397 | /// typename-specifier '(' expression-list[opt] ')' |
| 1398 | /// [C++0x] typename-specifier braced-init-list |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1399 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1400 | ExprResult |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1401 | Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1402 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1403 | ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1404 | |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1405 | assert((Tok.is(tok::l_paren) || |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1406 | (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))) |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1407 | && "Expected '(' or '{'!"); |
Douglas Gregor | bc61bd8 | 2011-01-11 00:33:19 +0000 | [diff] [blame] | 1408 | |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1409 | if (Tok.is(tok::l_brace)) { |
Sebastian Redl | 6dc00f6 | 2012-02-12 18:41:05 +0000 | [diff] [blame] | 1410 | ExprResult Init = ParseBraceInitializer(); |
| 1411 | if (Init.isInvalid()) |
| 1412 | return Init; |
| 1413 | Expr *InitList = Init.take(); |
| 1414 | return Actions.ActOnCXXTypeConstructExpr(TypeRep, SourceLocation(), |
| 1415 | MultiExprArg(&InitList, 1), |
| 1416 | SourceLocation()); |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1417 | } else { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1418 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1419 | T.consumeOpen(); |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1420 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 1421 | ExprVector Exprs; |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1422 | CommaLocsTy CommaLocs; |
| 1423 | |
| 1424 | if (Tok.isNot(tok::r_paren)) { |
| 1425 | if (ParseExpressionList(Exprs, CommaLocs)) { |
| 1426 | SkipUntil(tok::r_paren); |
| 1427 | return ExprError(); |
| 1428 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1429 | } |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1430 | |
| 1431 | // Match the ')'. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1432 | T.consumeClose(); |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1433 | |
| 1434 | // TypeRep could be null, if it references an invalid typedef. |
| 1435 | if (!TypeRep) |
| 1436 | return ExprError(); |
| 1437 | |
| 1438 | assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& |
| 1439 | "Unexpected number of commas!"); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1440 | return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(), |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1441 | Exprs, |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1442 | T.getCloseLocation()); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1443 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1446 | /// ParseCXXCondition - if/switch/while condition expression. |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1447 | /// |
| 1448 | /// condition: |
| 1449 | /// expression |
| 1450 | /// type-specifier-seq declarator '=' assignment-expression |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1451 | /// [C++11] type-specifier-seq declarator '=' initializer-clause |
| 1452 | /// [C++11] type-specifier-seq declarator braced-init-list |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1453 | /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] |
| 1454 | /// '=' assignment-expression |
| 1455 | /// |
Dmitri Gribenko | 1ddbd89 | 2012-08-24 00:01:24 +0000 | [diff] [blame] | 1456 | /// \param ExprOut if the condition was parsed as an expression, the parsed |
| 1457 | /// expression. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1458 | /// |
Dmitri Gribenko | 1ddbd89 | 2012-08-24 00:01:24 +0000 | [diff] [blame] | 1459 | /// \param DeclOut if the condition was parsed as a declaration, the parsed |
| 1460 | /// declaration. |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1461 | /// |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1462 | /// \param Loc The location of the start of the statement that requires this |
| 1463 | /// condition, e.g., the "for" in a for loop. |
| 1464 | /// |
| 1465 | /// \param ConvertToBoolean Whether the condition expression should be |
| 1466 | /// converted to a boolean value. |
| 1467 | /// |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1468 | /// \returns true if there was a parsing, false otherwise. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1469 | bool Parser::ParseCXXCondition(ExprResult &ExprOut, |
| 1470 | Decl *&DeclOut, |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1471 | SourceLocation Loc, |
| 1472 | bool ConvertToBoolean) { |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 1473 | if (Tok.is(tok::code_completion)) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1474 | Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1475 | cutOffParsing(); |
| 1476 | return true; |
Douglas Gregor | 01dfea0 | 2010-01-10 23:08:15 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1479 | ParsedAttributesWithRange attrs(AttrFactory); |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1480 | MaybeParseCXX11Attributes(attrs); |
Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1481 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1482 | if (!isCXXConditionDeclaration()) { |
Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1483 | ProhibitAttributes(attrs); |
| 1484 | |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1485 | // Parse the expression. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1486 | ExprOut = ParseExpression(); // expression |
| 1487 | DeclOut = 0; |
| 1488 | if (ExprOut.isInvalid()) |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1489 | return true; |
| 1490 | |
| 1491 | // If required, convert to a boolean value. |
| 1492 | if (ConvertToBoolean) |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1493 | ExprOut |
| 1494 | = Actions.ActOnBooleanCondition(getCurScope(), Loc, ExprOut.get()); |
| 1495 | return ExprOut.isInvalid(); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1496 | } |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1497 | |
| 1498 | // type-specifier-seq |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1499 | DeclSpec DS(AttrFactory); |
Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 1500 | DS.takeAttributesFrom(attrs); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1501 | ParseSpecifierQualifierList(DS); |
| 1502 | |
| 1503 | // declarator |
| 1504 | Declarator DeclaratorInfo(DS, Declarator::ConditionContext); |
| 1505 | ParseDeclarator(DeclaratorInfo); |
| 1506 | |
| 1507 | // simple-asm-expr[opt] |
| 1508 | if (Tok.is(tok::kw_asm)) { |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1509 | SourceLocation Loc; |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1510 | ExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1511 | if (AsmLabel.isInvalid()) { |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1512 | SkipUntil(tok::semi); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1513 | return true; |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1514 | } |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 1515 | DeclaratorInfo.setAsmLabel(AsmLabel.release()); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1516 | DeclaratorInfo.SetRangeEnd(Loc); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | // If attributes are present, parse them. |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1520 | MaybeParseGNUAttributes(DeclaratorInfo); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1522 | // Type-check the declaration itself. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1523 | DeclResult Dcl = Actions.ActOnCXXConditionDeclaration(getCurScope(), |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1524 | DeclaratorInfo); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1525 | DeclOut = Dcl.get(); |
| 1526 | ExprOut = ExprError(); |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 1527 | |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1528 | // '=' assignment-expression |
Richard Trieu | d6c7c67 | 2012-01-18 22:54:52 +0000 | [diff] [blame] | 1529 | // If a '==' or '+=' is found, suggest a fixit to '='. |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1530 | bool CopyInitialization = isTokenEqualOrEqualTypo(); |
| 1531 | if (CopyInitialization) |
Jeffrey Yasskin | dec0984 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1532 | ConsumeToken(); |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1533 | |
| 1534 | ExprResult InitExpr = ExprError(); |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1535 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1536 | Diag(Tok.getLocation(), |
| 1537 | diag::warn_cxx98_compat_generalized_initializer_lists); |
| 1538 | InitExpr = ParseBraceInitializer(); |
| 1539 | } else if (CopyInitialization) { |
| 1540 | InitExpr = ParseAssignmentExpression(); |
| 1541 | } else if (Tok.is(tok::l_paren)) { |
| 1542 | // This was probably an attempt to initialize the variable. |
| 1543 | SourceLocation LParen = ConsumeParen(), RParen = LParen; |
| 1544 | if (SkipUntil(tok::r_paren, true, /*DontConsume=*/true)) |
| 1545 | RParen = ConsumeParen(); |
| 1546 | Diag(DeclOut ? DeclOut->getLocation() : LParen, |
| 1547 | diag::err_expected_init_in_condition_lparen) |
| 1548 | << SourceRange(LParen, RParen); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1549 | } else { |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1550 | Diag(DeclOut ? DeclOut->getLocation() : Tok.getLocation(), |
| 1551 | diag::err_expected_init_in_condition); |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1552 | } |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1553 | |
| 1554 | if (!InitExpr.isInvalid()) |
| 1555 | Actions.AddInitializerToDecl(DeclOut, InitExpr.take(), !CopyInitialization, |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1556 | DS.containsPlaceholderType()); |
Richard Smith | dc7a4f5 | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 1557 | else |
| 1558 | Actions.ActOnInitializerError(DeclOut); |
Richard Smith | 0635aa7 | 2012-02-22 06:49:09 +0000 | [diff] [blame] | 1559 | |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1560 | // FIXME: Build a reference to this declaration? Convert it to bool? |
| 1561 | // (This is currently handled by Sema). |
Richard Smith | 483b9f3 | 2011-02-21 20:05:19 +0000 | [diff] [blame] | 1562 | |
| 1563 | Actions.FinalizeDeclaration(DeclOut); |
Douglas Gregor | 586596f | 2010-05-06 17:25:47 +0000 | [diff] [blame] | 1564 | |
Douglas Gregor | 99e9b4d | 2009-11-25 00:27:52 +0000 | [diff] [blame] | 1565 | return false; |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1568 | /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. |
| 1569 | /// This should only be called when the current token is known to be part of |
| 1570 | /// simple-type-specifier. |
| 1571 | /// |
| 1572 | /// simple-type-specifier: |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1573 | /// '::'[opt] nested-name-specifier[opt] type-name |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1574 | /// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO] |
| 1575 | /// char |
| 1576 | /// wchar_t |
| 1577 | /// bool |
| 1578 | /// short |
| 1579 | /// int |
| 1580 | /// long |
| 1581 | /// signed |
| 1582 | /// unsigned |
| 1583 | /// float |
| 1584 | /// double |
| 1585 | /// void |
| 1586 | /// [GNU] typeof-specifier |
| 1587 | /// [C++0x] auto [TODO] |
| 1588 | /// |
| 1589 | /// type-name: |
| 1590 | /// class-name |
| 1591 | /// enum-name |
| 1592 | /// typedef-name |
| 1593 | /// |
| 1594 | void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { |
| 1595 | DS.SetRangeStart(Tok.getLocation()); |
| 1596 | const char *PrevSpec; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1597 | unsigned DiagID; |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1598 | SourceLocation Loc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1599 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1600 | switch (Tok.getKind()) { |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 1601 | case tok::identifier: // foo::bar |
| 1602 | case tok::coloncolon: // ::foo::bar |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1603 | llvm_unreachable("Annotation token should already be formed!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1604 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1605 | llvm_unreachable("Not a simple-type-specifier token!"); |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 1606 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1607 | // type-name |
Chris Lattner | b31757b | 2009-01-06 05:06:21 +0000 | [diff] [blame] | 1608 | case tok::annot_typename: { |
Douglas Gregor | 6952f1e | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 1609 | if (getTypeAnnotation(Tok)) |
| 1610 | DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, |
| 1611 | getTypeAnnotation(Tok)); |
| 1612 | else |
| 1613 | DS.SetTypeSpecError(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1614 | |
| 1615 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
| 1616 | ConsumeToken(); |
| 1617 | |
| 1618 | // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id' |
| 1619 | // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an |
| 1620 | // Objective-C interface. If we don't have Objective-C or a '<', this is |
| 1621 | // just a normal reference to a typedef name. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1622 | if (Tok.is(tok::less) && getLangOpts().ObjC1) |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1623 | ParseObjCProtocolQualifiers(DS); |
| 1624 | |
| 1625 | DS.Finish(Diags, PP); |
| 1626 | return; |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1628 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1629 | // builtin types |
| 1630 | case tok::kw_short: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1631 | DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1632 | break; |
| 1633 | case tok::kw_long: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1634 | DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1635 | break; |
Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 1636 | case tok::kw___int64: |
| 1637 | DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, DiagID); |
| 1638 | break; |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1639 | case tok::kw_signed: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1640 | DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1641 | break; |
| 1642 | case tok::kw_unsigned: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1643 | DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | case tok::kw_void: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1646 | DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1647 | break; |
| 1648 | case tok::kw_char: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1649 | DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1650 | break; |
| 1651 | case tok::kw_int: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1652 | DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1653 | break; |
Richard Smith | 5a5a971 | 2012-04-04 06:24:32 +0000 | [diff] [blame] | 1654 | case tok::kw___int128: |
| 1655 | DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID); |
| 1656 | break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 1657 | case tok::kw_half: |
| 1658 | DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID); |
| 1659 | break; |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1660 | case tok::kw_float: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1661 | DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1662 | break; |
| 1663 | case tok::kw_double: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1664 | DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1665 | break; |
| 1666 | case tok::kw_wchar_t: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1667 | DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1668 | break; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 1669 | case tok::kw_char16_t: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1670 | DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID); |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 1671 | break; |
| 1672 | case tok::kw_char32_t: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1673 | DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID); |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 1674 | break; |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1675 | case tok::kw_bool: |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1676 | DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1677 | break; |
David Blaikie | 5e089fe | 2012-01-24 05:47:35 +0000 | [diff] [blame] | 1678 | case tok::annot_decltype: |
| 1679 | case tok::kw_decltype: |
| 1680 | DS.SetRangeEnd(ParseDecltypeSpecifier(DS)); |
| 1681 | return DS.Finish(Diags, PP); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1683 | // GNU typeof support. |
| 1684 | case tok::kw_typeof: |
| 1685 | ParseTypeofSpecifier(DS); |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 1686 | DS.Finish(Diags, PP); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1687 | return; |
| 1688 | } |
Chris Lattner | b31757b | 2009-01-06 05:06:21 +0000 | [diff] [blame] | 1689 | if (Tok.is(tok::annot_typename)) |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1690 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
| 1691 | else |
| 1692 | DS.SetRangeEnd(Tok.getLocation()); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1693 | ConsumeToken(); |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 1694 | DS.Finish(Diags, PP); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 1695 | } |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1697 | /// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++ |
| 1698 | /// [dcl.name]), which is a non-empty sequence of type-specifiers, |
| 1699 | /// e.g., "const short int". Note that the DeclSpec is *not* finished |
| 1700 | /// by parsing the type-specifier-seq, because these sequences are |
| 1701 | /// typically followed by some form of declarator. Returns true and |
| 1702 | /// emits diagnostics if this is not a type-specifier-seq, false |
| 1703 | /// otherwise. |
| 1704 | /// |
| 1705 | /// type-specifier-seq: [C++ 8.1] |
| 1706 | /// type-specifier type-specifier-seq[opt] |
| 1707 | /// |
| 1708 | bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { |
Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1709 | ParseSpecifierQualifierList(DS, AS_none, DSC_type_specifier); |
Douglas Gregor | 396a9f2 | 2010-02-24 23:13:13 +0000 | [diff] [blame] | 1710 | DS.Finish(Diags, PP); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1711 | return false; |
| 1712 | } |
| 1713 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1714 | /// \brief Finish parsing a C++ unqualified-id that is a template-id of |
| 1715 | /// some form. |
| 1716 | /// |
| 1717 | /// This routine is invoked when a '<' is encountered after an identifier or |
| 1718 | /// operator-function-id is parsed by \c ParseUnqualifiedId() to determine |
| 1719 | /// whether the unqualified-id is actually a template-id. This routine will |
| 1720 | /// then parse the template arguments and form the appropriate template-id to |
| 1721 | /// return to the caller. |
| 1722 | /// |
| 1723 | /// \param SS the nested-name-specifier that precedes this template-id, if |
| 1724 | /// we're actually parsing a qualified-id. |
| 1725 | /// |
| 1726 | /// \param Name for constructor and destructor names, this is the actual |
| 1727 | /// identifier that may be a template-name. |
| 1728 | /// |
| 1729 | /// \param NameLoc the location of the class-name in a constructor or |
| 1730 | /// destructor. |
| 1731 | /// |
| 1732 | /// \param EnteringContext whether we're entering the scope of the |
| 1733 | /// nested-name-specifier. |
| 1734 | /// |
Douglas Gregor | 46df8cc | 2009-11-03 21:24:04 +0000 | [diff] [blame] | 1735 | /// \param ObjectType if this unqualified-id occurs within a member access |
| 1736 | /// expression, the type of the base object whose member is being accessed. |
| 1737 | /// |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1738 | /// \param Id as input, describes the template-name or operator-function-id |
| 1739 | /// that precedes the '<'. If template arguments were parsed successfully, |
| 1740 | /// will be updated with the template-id. |
| 1741 | /// |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1742 | /// \param AssumeTemplateId When true, this routine will assume that the name |
| 1743 | /// refers to a template without performing name lookup to verify. |
| 1744 | /// |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1745 | /// \returns true if a parse error occurred, false otherwise. |
| 1746 | bool Parser::ParseUnqualifiedIdTemplateId(CXXScopeSpec &SS, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1747 | SourceLocation TemplateKWLoc, |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1748 | IdentifierInfo *Name, |
| 1749 | SourceLocation NameLoc, |
| 1750 | bool EnteringContext, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1751 | ParsedType ObjectType, |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1752 | UnqualifiedId &Id, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1753 | bool AssumeTemplateId) { |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 1754 | assert((AssumeTemplateId || Tok.is(tok::less)) && |
| 1755 | "Expected '<' to finish parsing a template-id"); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1756 | |
| 1757 | TemplateTy Template; |
| 1758 | TemplateNameKind TNK = TNK_Non_template; |
| 1759 | switch (Id.getKind()) { |
| 1760 | case UnqualifiedId::IK_Identifier: |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1761 | case UnqualifiedId::IK_OperatorFunctionId: |
Sean Hunt | e6252d1 | 2009-11-28 08:58:14 +0000 | [diff] [blame] | 1762 | case UnqualifiedId::IK_LiteralOperatorId: |
Douglas Gregor | d4dca08 | 2010-02-24 18:44:31 +0000 | [diff] [blame] | 1763 | if (AssumeTemplateId) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1764 | TNK = Actions.ActOnDependentTemplateName(getCurScope(), SS, TemplateKWLoc, |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 1765 | Id, ObjectType, EnteringContext, |
| 1766 | Template); |
| 1767 | if (TNK == TNK_Non_template) |
| 1768 | return true; |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1769 | } else { |
| 1770 | bool MemberOfUnknownSpecialization; |
Abramo Bagnara | 7c15353 | 2010-08-06 12:11:11 +0000 | [diff] [blame] | 1771 | TNK = Actions.isTemplateName(getCurScope(), SS, |
| 1772 | TemplateKWLoc.isValid(), Id, |
| 1773 | ObjectType, EnteringContext, Template, |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1774 | MemberOfUnknownSpecialization); |
| 1775 | |
| 1776 | if (TNK == TNK_Non_template && MemberOfUnknownSpecialization && |
| 1777 | ObjectType && IsTemplateArgumentList()) { |
| 1778 | // We have something like t->getAs<T>(), where getAs is a |
| 1779 | // member of an unknown specialization. However, this will only |
| 1780 | // parse correctly as a template, so suggest the keyword 'template' |
| 1781 | // before 'getAs' and treat this as a dependent template name. |
| 1782 | std::string Name; |
| 1783 | if (Id.getKind() == UnqualifiedId::IK_Identifier) |
| 1784 | Name = Id.Identifier->getName(); |
| 1785 | else { |
| 1786 | Name = "operator "; |
| 1787 | if (Id.getKind() == UnqualifiedId::IK_OperatorFunctionId) |
| 1788 | Name += getOperatorSpelling(Id.OperatorFunctionId.Operator); |
| 1789 | else |
| 1790 | Name += Id.Identifier->getName(); |
| 1791 | } |
| 1792 | Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword) |
| 1793 | << Name |
| 1794 | << FixItHint::CreateInsertion(Id.StartLocation, "template "); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1795 | TNK = Actions.ActOnDependentTemplateName(getCurScope(), |
| 1796 | SS, TemplateKWLoc, Id, |
| 1797 | ObjectType, EnteringContext, |
| 1798 | Template); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 1799 | if (TNK == TNK_Non_template) |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1800 | return true; |
| 1801 | } |
| 1802 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1803 | break; |
| 1804 | |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1805 | case UnqualifiedId::IK_ConstructorName: { |
| 1806 | UnqualifiedId TemplateName; |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1807 | bool MemberOfUnknownSpecialization; |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1808 | TemplateName.setIdentifier(Name, NameLoc); |
Abramo Bagnara | 7c15353 | 2010-08-06 12:11:11 +0000 | [diff] [blame] | 1809 | TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), |
| 1810 | TemplateName, ObjectType, |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1811 | EnteringContext, Template, |
| 1812 | MemberOfUnknownSpecialization); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1813 | break; |
| 1814 | } |
| 1815 | |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1816 | case UnqualifiedId::IK_DestructorName: { |
| 1817 | UnqualifiedId TemplateName; |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1818 | bool MemberOfUnknownSpecialization; |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1819 | TemplateName.setIdentifier(Name, NameLoc); |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1820 | if (ObjectType) { |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1821 | TNK = Actions.ActOnDependentTemplateName(getCurScope(), |
| 1822 | SS, TemplateKWLoc, TemplateName, |
| 1823 | ObjectType, EnteringContext, |
| 1824 | Template); |
Douglas Gregor | d6ab232 | 2010-06-16 23:00:59 +0000 | [diff] [blame] | 1825 | if (TNK == TNK_Non_template) |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1826 | return true; |
| 1827 | } else { |
Abramo Bagnara | 7c15353 | 2010-08-06 12:11:11 +0000 | [diff] [blame] | 1828 | TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(), |
| 1829 | TemplateName, ObjectType, |
Douglas Gregor | 1fd6d44 | 2010-05-21 23:18:07 +0000 | [diff] [blame] | 1830 | EnteringContext, Template, |
| 1831 | MemberOfUnknownSpecialization); |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1832 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1833 | if (TNK == TNK_Non_template && !Id.DestructorName.get()) { |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 1834 | Diag(NameLoc, diag::err_destructor_template_id) |
| 1835 | << Name << SS.getRange(); |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 1836 | return true; |
| 1837 | } |
| 1838 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1839 | break; |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1840 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1841 | |
| 1842 | default: |
| 1843 | return false; |
| 1844 | } |
| 1845 | |
| 1846 | if (TNK == TNK_Non_template) |
| 1847 | return false; |
| 1848 | |
| 1849 | // Parse the enclosed template argument list. |
| 1850 | SourceLocation LAngleLoc, RAngleLoc; |
| 1851 | TemplateArgList TemplateArgs; |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 1852 | if (Tok.is(tok::less) && |
| 1853 | ParseTemplateIdAfterTemplateName(Template, Id.StartLocation, |
Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1854 | SS, true, LAngleLoc, |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1855 | TemplateArgs, |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1856 | RAngleLoc)) |
| 1857 | return true; |
| 1858 | |
| 1859 | if (Id.getKind() == UnqualifiedId::IK_Identifier || |
Sean Hunt | e6252d1 | 2009-11-28 08:58:14 +0000 | [diff] [blame] | 1860 | Id.getKind() == UnqualifiedId::IK_OperatorFunctionId || |
| 1861 | Id.getKind() == UnqualifiedId::IK_LiteralOperatorId) { |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1862 | // Form a parsed representation of the template-id to be stored in the |
| 1863 | // UnqualifiedId. |
| 1864 | TemplateIdAnnotation *TemplateId |
Benjamin Kramer | 13bb701 | 2012-04-14 12:14:03 +0000 | [diff] [blame] | 1865 | = TemplateIdAnnotation::Allocate(TemplateArgs.size(), TemplateIds); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1866 | |
| 1867 | if (Id.getKind() == UnqualifiedId::IK_Identifier) { |
| 1868 | TemplateId->Name = Id.Identifier; |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1869 | TemplateId->Operator = OO_None; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1870 | TemplateId->TemplateNameLoc = Id.StartLocation; |
| 1871 | } else { |
Douglas Gregor | 014e88d | 2009-11-03 23:16:33 +0000 | [diff] [blame] | 1872 | TemplateId->Name = 0; |
| 1873 | TemplateId->Operator = Id.OperatorFunctionId.Operator; |
| 1874 | TemplateId->TemplateNameLoc = Id.StartLocation; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1877 | TemplateId->SS = SS; |
Benjamin Kramer | 2b28bf1 | 2012-02-19 23:37:39 +0000 | [diff] [blame] | 1878 | TemplateId->TemplateKWLoc = TemplateKWLoc; |
John McCall | 2b5289b | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1879 | TemplateId->Template = Template; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1880 | TemplateId->Kind = TNK; |
| 1881 | TemplateId->LAngleLoc = LAngleLoc; |
| 1882 | TemplateId->RAngleLoc = RAngleLoc; |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 1883 | ParsedTemplateArgument *Args = TemplateId->getTemplateArgs(); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1884 | for (unsigned Arg = 0, ArgEnd = TemplateArgs.size(); |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 1885 | Arg != ArgEnd; ++Arg) |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1886 | Args[Arg] = TemplateArgs[Arg]; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1887 | |
| 1888 | Id.setTemplateId(TemplateId); |
| 1889 | return false; |
| 1890 | } |
| 1891 | |
| 1892 | // Bundle the template arguments together. |
Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1893 | ASTTemplateArgsPtr TemplateArgsPtr(TemplateArgs); |
Abramo Bagnara | fad03b7 | 2012-01-27 08:46:19 +0000 | [diff] [blame] | 1894 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1895 | // Constructor and destructor names. |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1896 | TypeResult Type |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1897 | = Actions.ActOnTemplateIdType(SS, TemplateKWLoc, |
| 1898 | Template, NameLoc, |
Abramo Bagnara | fad03b7 | 2012-01-27 08:46:19 +0000 | [diff] [blame] | 1899 | LAngleLoc, TemplateArgsPtr, RAngleLoc, |
| 1900 | /*IsCtorOrDtorName=*/true); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1901 | if (Type.isInvalid()) |
| 1902 | return true; |
| 1903 | |
| 1904 | if (Id.getKind() == UnqualifiedId::IK_ConstructorName) |
| 1905 | Id.setConstructorName(Type.get(), NameLoc, RAngleLoc); |
| 1906 | else |
| 1907 | Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc); |
| 1908 | |
| 1909 | return false; |
| 1910 | } |
| 1911 | |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1912 | /// \brief Parse an operator-function-id or conversion-function-id as part |
| 1913 | /// of a C++ unqualified-id. |
| 1914 | /// |
| 1915 | /// This routine is responsible only for parsing the operator-function-id or |
| 1916 | /// conversion-function-id; it does not handle template arguments in any way. |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1917 | /// |
| 1918 | /// \code |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1919 | /// operator-function-id: [C++ 13.5] |
| 1920 | /// 'operator' operator |
| 1921 | /// |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1922 | /// operator: one of |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1923 | /// new delete new[] delete[] |
| 1924 | /// + - * / % ^ & | ~ |
| 1925 | /// ! = < > += -= *= /= %= |
| 1926 | /// ^= &= |= << >> >>= <<= == != |
| 1927 | /// <= >= && || ++ -- , ->* -> |
| 1928 | /// () [] |
| 1929 | /// |
| 1930 | /// conversion-function-id: [C++ 12.3.2] |
| 1931 | /// operator conversion-type-id |
| 1932 | /// |
| 1933 | /// conversion-type-id: |
| 1934 | /// type-specifier-seq conversion-declarator[opt] |
| 1935 | /// |
| 1936 | /// conversion-declarator: |
| 1937 | /// ptr-operator conversion-declarator[opt] |
| 1938 | /// \endcode |
| 1939 | /// |
Dmitri Gribenko | 1ddbd89 | 2012-08-24 00:01:24 +0000 | [diff] [blame] | 1940 | /// \param SS The nested-name-specifier that preceded this unqualified-id. If |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1941 | /// non-empty, then we are parsing the unqualified-id of a qualified-id. |
| 1942 | /// |
| 1943 | /// \param EnteringContext whether we are entering the scope of the |
| 1944 | /// nested-name-specifier. |
| 1945 | /// |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1946 | /// \param ObjectType if this unqualified-id occurs within a member access |
| 1947 | /// expression, the type of the base object whose member is being accessed. |
| 1948 | /// |
| 1949 | /// \param Result on a successful parse, contains the parsed unqualified-id. |
| 1950 | /// |
| 1951 | /// \returns true if parsing fails, false otherwise. |
| 1952 | bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1953 | ParsedType ObjectType, |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1954 | UnqualifiedId &Result) { |
| 1955 | assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword"); |
| 1956 | |
| 1957 | // Consume the 'operator' keyword. |
| 1958 | SourceLocation KeywordLoc = ConsumeToken(); |
| 1959 | |
| 1960 | // Determine what kind of operator name we have. |
| 1961 | unsigned SymbolIdx = 0; |
| 1962 | SourceLocation SymbolLocations[3]; |
| 1963 | OverloadedOperatorKind Op = OO_None; |
| 1964 | switch (Tok.getKind()) { |
| 1965 | case tok::kw_new: |
| 1966 | case tok::kw_delete: { |
| 1967 | bool isNew = Tok.getKind() == tok::kw_new; |
| 1968 | // Consume the 'new' or 'delete'. |
| 1969 | SymbolLocations[SymbolIdx++] = ConsumeToken(); |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 1970 | // Check for array new/delete. |
| 1971 | if (Tok.is(tok::l_square) && |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1972 | (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square))) { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1973 | // Consume the '[' and ']'. |
| 1974 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 1975 | T.consumeOpen(); |
| 1976 | T.consumeClose(); |
| 1977 | if (T.getCloseLocation().isInvalid()) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1978 | return true; |
| 1979 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1980 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
| 1981 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 1982 | Op = isNew? OO_Array_New : OO_Array_Delete; |
| 1983 | } else { |
| 1984 | Op = isNew? OO_New : OO_Delete; |
| 1985 | } |
| 1986 | break; |
| 1987 | } |
| 1988 | |
| 1989 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 1990 | case tok::Token: \ |
| 1991 | SymbolLocations[SymbolIdx++] = ConsumeToken(); \ |
| 1992 | Op = OO_##Name; \ |
| 1993 | break; |
| 1994 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 1995 | #include "clang/Basic/OperatorKinds.def" |
| 1996 | |
| 1997 | case tok::l_paren: { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1998 | // Consume the '(' and ')'. |
| 1999 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2000 | T.consumeOpen(); |
| 2001 | T.consumeClose(); |
| 2002 | if (T.getCloseLocation().isInvalid()) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2003 | return true; |
| 2004 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2005 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
| 2006 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2007 | Op = OO_Call; |
| 2008 | break; |
| 2009 | } |
| 2010 | |
| 2011 | case tok::l_square: { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2012 | // Consume the '[' and ']'. |
| 2013 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 2014 | T.consumeOpen(); |
| 2015 | T.consumeClose(); |
| 2016 | if (T.getCloseLocation().isInvalid()) |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2017 | return true; |
| 2018 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2019 | SymbolLocations[SymbolIdx++] = T.getOpenLocation(); |
| 2020 | SymbolLocations[SymbolIdx++] = T.getCloseLocation(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2021 | Op = OO_Subscript; |
| 2022 | break; |
| 2023 | } |
| 2024 | |
| 2025 | case tok::code_completion: { |
| 2026 | // Code completion for the operator name. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2027 | Actions.CodeCompleteOperatorName(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2028 | cutOffParsing(); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2029 | // Don't try to parse any further. |
| 2030 | return true; |
| 2031 | } |
| 2032 | |
| 2033 | default: |
| 2034 | break; |
| 2035 | } |
| 2036 | |
| 2037 | if (Op != OO_None) { |
| 2038 | // We have parsed an operator-function-id. |
| 2039 | Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations); |
| 2040 | return false; |
| 2041 | } |
Sean Hunt | 0486d74 | 2009-11-28 04:44:28 +0000 | [diff] [blame] | 2042 | |
| 2043 | // Parse a literal-operator-id. |
| 2044 | // |
Richard Smith | aa9a8ce | 2012-10-20 08:41:10 +0000 | [diff] [blame] | 2045 | // literal-operator-id: C++11 [over.literal] |
| 2046 | // operator string-literal identifier |
| 2047 | // operator user-defined-string-literal |
Sean Hunt | 0486d74 | 2009-11-28 04:44:28 +0000 | [diff] [blame] | 2048 | |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2049 | if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) { |
Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 2050 | Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator); |
Sean Hunt | 0486d74 | 2009-11-28 04:44:28 +0000 | [diff] [blame] | 2051 | |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2052 | SourceLocation DiagLoc; |
| 2053 | unsigned DiagId = 0; |
| 2054 | |
| 2055 | // We're past translation phase 6, so perform string literal concatenation |
| 2056 | // before checking for "". |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2057 | SmallVector<Token, 4> Toks; |
| 2058 | SmallVector<SourceLocation, 4> TokLocs; |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2059 | while (isTokenStringLiteral()) { |
| 2060 | if (!Tok.is(tok::string_literal) && !DiagId) { |
Richard Smith | aa9a8ce | 2012-10-20 08:41:10 +0000 | [diff] [blame] | 2061 | // C++11 [over.literal]p1: |
| 2062 | // The string-literal or user-defined-string-literal in a |
| 2063 | // literal-operator-id shall have no encoding-prefix [...]. |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2064 | DiagLoc = Tok.getLocation(); |
| 2065 | DiagId = diag::err_literal_operator_string_prefix; |
| 2066 | } |
| 2067 | Toks.push_back(Tok); |
| 2068 | TokLocs.push_back(ConsumeStringToken()); |
| 2069 | } |
| 2070 | |
| 2071 | StringLiteralParser Literal(Toks.data(), Toks.size(), PP); |
| 2072 | if (Literal.hadError) |
| 2073 | return true; |
| 2074 | |
| 2075 | // Grab the literal operator's suffix, which will be either the next token |
| 2076 | // or a ud-suffix from the string literal. |
| 2077 | IdentifierInfo *II = 0; |
| 2078 | SourceLocation SuffixLoc; |
| 2079 | if (!Literal.getUDSuffix().empty()) { |
| 2080 | II = &PP.getIdentifierTable().get(Literal.getUDSuffix()); |
| 2081 | SuffixLoc = |
| 2082 | Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()], |
| 2083 | Literal.getUDSuffixOffset(), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2084 | PP.getSourceManager(), getLangOpts()); |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2085 | } else if (Tok.is(tok::identifier)) { |
| 2086 | II = Tok.getIdentifierInfo(); |
| 2087 | SuffixLoc = ConsumeToken(); |
| 2088 | TokLocs.push_back(SuffixLoc); |
| 2089 | } else { |
Sean Hunt | 0486d74 | 2009-11-28 04:44:28 +0000 | [diff] [blame] | 2090 | Diag(Tok.getLocation(), diag::err_expected_ident); |
| 2091 | return true; |
| 2092 | } |
| 2093 | |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2094 | // The string literal must be empty. |
| 2095 | if (!Literal.GetString().empty() || Literal.Pascal) { |
Richard Smith | aa9a8ce | 2012-10-20 08:41:10 +0000 | [diff] [blame] | 2096 | // C++11 [over.literal]p1: |
| 2097 | // The string-literal or user-defined-string-literal in a |
| 2098 | // literal-operator-id shall [...] contain no characters |
| 2099 | // other than the implicit terminating '\0'. |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2100 | DiagLoc = TokLocs.front(); |
| 2101 | DiagId = diag::err_literal_operator_string_not_empty; |
| 2102 | } |
| 2103 | |
| 2104 | if (DiagId) { |
| 2105 | // This isn't a valid literal-operator-id, but we think we know |
| 2106 | // what the user meant. Tell them what they should have written. |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2107 | SmallString<32> Str; |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 2108 | Str += "\"\" "; |
| 2109 | Str += II->getName(); |
| 2110 | Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement( |
| 2111 | SourceRange(TokLocs.front(), TokLocs.back()), Str); |
| 2112 | } |
| 2113 | |
| 2114 | Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 2115 | return false; |
Sean Hunt | 0486d74 | 2009-11-28 04:44:28 +0000 | [diff] [blame] | 2116 | } |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2117 | |
| 2118 | // Parse a conversion-function-id. |
| 2119 | // |
| 2120 | // conversion-function-id: [C++ 12.3.2] |
| 2121 | // operator conversion-type-id |
| 2122 | // |
| 2123 | // conversion-type-id: |
| 2124 | // type-specifier-seq conversion-declarator[opt] |
| 2125 | // |
| 2126 | // conversion-declarator: |
| 2127 | // ptr-operator conversion-declarator[opt] |
| 2128 | |
| 2129 | // Parse the type-specifier-seq. |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2130 | DeclSpec DS(AttrFactory); |
Douglas Gregor | f6e6fc8 | 2009-11-20 22:03:38 +0000 | [diff] [blame] | 2131 | if (ParseCXXTypeSpecifierSeq(DS)) // FIXME: ObjectType? |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2132 | return true; |
| 2133 | |
| 2134 | // Parse the conversion-declarator, which is merely a sequence of |
| 2135 | // ptr-operators. |
Richard Smith | 14f78f4 | 2013-05-04 01:26:46 +0000 | [diff] [blame] | 2136 | Declarator D(DS, Declarator::ConversionIdContext); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2137 | ParseDeclaratorInternal(D, /*DirectDeclParser=*/0); |
| 2138 | |
| 2139 | // Finish up the type. |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2140 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D); |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2141 | if (Ty.isInvalid()) |
| 2142 | return true; |
| 2143 | |
| 2144 | // Note that this is a conversion-function-id. |
| 2145 | Result.setConversionFunctionId(KeywordLoc, Ty.get(), |
| 2146 | D.getSourceRange().getEnd()); |
| 2147 | return false; |
| 2148 | } |
| 2149 | |
| 2150 | /// \brief Parse a C++ unqualified-id (or a C identifier), which describes the |
| 2151 | /// name of an entity. |
| 2152 | /// |
| 2153 | /// \code |
| 2154 | /// unqualified-id: [C++ expr.prim.general] |
| 2155 | /// identifier |
| 2156 | /// operator-function-id |
| 2157 | /// conversion-function-id |
| 2158 | /// [C++0x] literal-operator-id [TODO] |
| 2159 | /// ~ class-name |
| 2160 | /// template-id |
| 2161 | /// |
| 2162 | /// \endcode |
| 2163 | /// |
Dmitri Gribenko | 1ddbd89 | 2012-08-24 00:01:24 +0000 | [diff] [blame] | 2164 | /// \param SS The nested-name-specifier that preceded this unqualified-id. If |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2165 | /// non-empty, then we are parsing the unqualified-id of a qualified-id. |
| 2166 | /// |
| 2167 | /// \param EnteringContext whether we are entering the scope of the |
| 2168 | /// nested-name-specifier. |
| 2169 | /// |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2170 | /// \param AllowDestructorName whether we allow parsing of a destructor name. |
| 2171 | /// |
| 2172 | /// \param AllowConstructorName whether we allow parsing a constructor name. |
| 2173 | /// |
Douglas Gregor | 46df8cc | 2009-11-03 21:24:04 +0000 | [diff] [blame] | 2174 | /// \param ObjectType if this unqualified-id occurs within a member access |
| 2175 | /// expression, the type of the base object whose member is being accessed. |
| 2176 | /// |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2177 | /// \param Result on a successful parse, contains the parsed unqualified-id. |
| 2178 | /// |
| 2179 | /// \returns true if parsing fails, false otherwise. |
| 2180 | bool Parser::ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, |
| 2181 | bool AllowDestructorName, |
| 2182 | bool AllowConstructorName, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2183 | ParsedType ObjectType, |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2184 | SourceLocation& TemplateKWLoc, |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2185 | UnqualifiedId &Result) { |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 2186 | |
| 2187 | // Handle 'A::template B'. This is for template-ids which have not |
| 2188 | // already been annotated by ParseOptionalCXXScopeSpecifier(). |
| 2189 | bool TemplateSpecified = false; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2190 | if (getLangOpts().CPlusPlus && Tok.is(tok::kw_template) && |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 2191 | (ObjectType || SS.isSet())) { |
| 2192 | TemplateSpecified = true; |
| 2193 | TemplateKWLoc = ConsumeToken(); |
| 2194 | } |
| 2195 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2196 | // unqualified-id: |
| 2197 | // identifier |
| 2198 | // template-id (when it hasn't already been annotated) |
| 2199 | if (Tok.is(tok::identifier)) { |
| 2200 | // Consume the identifier. |
| 2201 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 2202 | SourceLocation IdLoc = ConsumeToken(); |
| 2203 | |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2204 | if (!getLangOpts().CPlusPlus) { |
Douglas Gregor | b862b8f | 2010-01-11 23:29:10 +0000 | [diff] [blame] | 2205 | // If we're not in C++, only identifiers matter. Record the |
| 2206 | // identifier and return. |
| 2207 | Result.setIdentifier(Id, IdLoc); |
| 2208 | return false; |
| 2209 | } |
| 2210 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2211 | if (AllowConstructorName && |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2212 | Actions.isCurrentClassName(*Id, getCurScope(), &SS)) { |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2213 | // We have parsed a constructor name. |
Abramo Bagnara | fad03b7 | 2012-01-27 08:46:19 +0000 | [diff] [blame] | 2214 | ParsedType Ty = Actions.getTypeName(*Id, IdLoc, getCurScope(), |
| 2215 | &SS, false, false, |
| 2216 | ParsedType(), |
| 2217 | /*IsCtorOrDtorName=*/true, |
| 2218 | /*NonTrivialTypeSourceInfo=*/true); |
| 2219 | Result.setConstructorName(Ty, IdLoc, IdLoc); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2220 | } else { |
| 2221 | // We have parsed an identifier. |
| 2222 | Result.setIdentifier(Id, IdLoc); |
| 2223 | } |
| 2224 | |
| 2225 | // If the next token is a '<', we may have a template. |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 2226 | if (TemplateSpecified || Tok.is(tok::less)) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2227 | return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, Id, IdLoc, |
| 2228 | EnteringContext, ObjectType, |
| 2229 | Result, TemplateSpecified); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2230 | |
| 2231 | return false; |
| 2232 | } |
| 2233 | |
| 2234 | // unqualified-id: |
| 2235 | // template-id (already parsed and annotated) |
| 2236 | if (Tok.is(tok::annot_template_id)) { |
Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 2237 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 2238 | |
| 2239 | // If the template-name names the current class, then this is a constructor |
| 2240 | if (AllowConstructorName && TemplateId->Name && |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2241 | Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) { |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 2242 | if (SS.isSet()) { |
| 2243 | // C++ [class.qual]p2 specifies that a qualified template-name |
| 2244 | // is taken as the constructor name where a constructor can be |
| 2245 | // declared. Thus, the template arguments are extraneous, so |
| 2246 | // complain about them and remove them entirely. |
| 2247 | Diag(TemplateId->TemplateNameLoc, |
| 2248 | diag::err_out_of_line_constructor_template_id) |
| 2249 | << TemplateId->Name |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 2250 | << FixItHint::CreateRemoval( |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 2251 | SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc)); |
Abramo Bagnara | fad03b7 | 2012-01-27 08:46:19 +0000 | [diff] [blame] | 2252 | ParsedType Ty = Actions.getTypeName(*TemplateId->Name, |
| 2253 | TemplateId->TemplateNameLoc, |
| 2254 | getCurScope(), |
| 2255 | &SS, false, false, |
| 2256 | ParsedType(), |
| 2257 | /*IsCtorOrDtorName=*/true, |
| 2258 | /*NontrivialTypeSourceInfo=*/true); |
| 2259 | Result.setConstructorName(Ty, TemplateId->TemplateNameLoc, |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 2260 | TemplateId->RAngleLoc); |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 2261 | ConsumeToken(); |
| 2262 | return false; |
| 2263 | } |
| 2264 | |
| 2265 | Result.setConstructorTemplateId(TemplateId); |
| 2266 | ConsumeToken(); |
| 2267 | return false; |
| 2268 | } |
| 2269 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2270 | // We have already parsed a template-id; consume the annotation token as |
| 2271 | // our unqualified-id. |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 2272 | Result.setTemplateId(TemplateId); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2273 | TemplateKWLoc = TemplateId->TemplateKWLoc; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2274 | ConsumeToken(); |
| 2275 | return false; |
| 2276 | } |
| 2277 | |
| 2278 | // unqualified-id: |
| 2279 | // operator-function-id |
| 2280 | // conversion-function-id |
| 2281 | if (Tok.is(tok::kw_operator)) { |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2282 | if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result)) |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2283 | return true; |
| 2284 | |
Sean Hunt | e6252d1 | 2009-11-28 08:58:14 +0000 | [diff] [blame] | 2285 | // If we have an operator-function-id or a literal-operator-id and the next |
| 2286 | // token is a '<', we may have a |
Douglas Gregor | ca1bdd7 | 2009-11-04 00:56:37 +0000 | [diff] [blame] | 2287 | // |
| 2288 | // template-id: |
| 2289 | // operator-function-id < template-argument-list[opt] > |
Sean Hunt | e6252d1 | 2009-11-28 08:58:14 +0000 | [diff] [blame] | 2290 | if ((Result.getKind() == UnqualifiedId::IK_OperatorFunctionId || |
| 2291 | Result.getKind() == UnqualifiedId::IK_LiteralOperatorId) && |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 2292 | (TemplateSpecified || Tok.is(tok::less))) |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2293 | return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, |
| 2294 | 0, SourceLocation(), |
| 2295 | EnteringContext, ObjectType, |
| 2296 | Result, TemplateSpecified); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2297 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2298 | return false; |
| 2299 | } |
| 2300 | |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2301 | if (getLangOpts().CPlusPlus && |
Douglas Gregor | b862b8f | 2010-01-11 23:29:10 +0000 | [diff] [blame] | 2302 | (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) { |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2303 | // C++ [expr.unary.op]p10: |
| 2304 | // There is an ambiguity in the unary-expression ~X(), where X is a |
| 2305 | // class-name. The ambiguity is resolved in favor of treating ~ as a |
| 2306 | // unary complement rather than treating ~X as referring to a destructor. |
| 2307 | |
| 2308 | // Parse the '~'. |
| 2309 | SourceLocation TildeLoc = ConsumeToken(); |
David Blaikie | 53a75c0 | 2011-12-08 16:13:53 +0000 | [diff] [blame] | 2310 | |
| 2311 | if (SS.isEmpty() && Tok.is(tok::kw_decltype)) { |
| 2312 | DeclSpec DS(AttrFactory); |
| 2313 | SourceLocation EndLoc = ParseDecltypeSpecifier(DS); |
| 2314 | if (ParsedType Type = Actions.getDestructorType(DS, ObjectType)) { |
| 2315 | Result.setDestructorName(TildeLoc, Type, EndLoc); |
| 2316 | return false; |
| 2317 | } |
| 2318 | return true; |
| 2319 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2320 | |
| 2321 | // Parse the class-name. |
| 2322 | if (Tok.isNot(tok::identifier)) { |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2323 | Diag(Tok, diag::err_destructor_tilde_identifier); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2324 | return true; |
| 2325 | } |
| 2326 | |
| 2327 | // Parse the class-name (or template-name in a simple-template-id). |
| 2328 | IdentifierInfo *ClassName = Tok.getIdentifierInfo(); |
| 2329 | SourceLocation ClassNameLoc = ConsumeToken(); |
| 2330 | |
Douglas Gregor | 0278e12 | 2010-05-05 05:58:24 +0000 | [diff] [blame] | 2331 | if (TemplateSpecified || Tok.is(tok::less)) { |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2332 | Result.setDestructorName(TildeLoc, ParsedType(), ClassNameLoc); |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 2333 | return ParseUnqualifiedIdTemplateId(SS, TemplateKWLoc, |
| 2334 | ClassName, ClassNameLoc, |
| 2335 | EnteringContext, ObjectType, |
| 2336 | Result, TemplateSpecified); |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2339 | // Note that this is a destructor name. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2340 | ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName, |
| 2341 | ClassNameLoc, getCurScope(), |
| 2342 | SS, ObjectType, |
| 2343 | EnteringContext); |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2344 | if (!Ty) |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2345 | return true; |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2347 | Result.setDestructorName(TildeLoc, Ty, ClassNameLoc); |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2348 | return false; |
| 2349 | } |
| 2350 | |
Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 2351 | Diag(Tok, diag::err_expected_unqualified_id) |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2352 | << getLangOpts().CPlusPlus; |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 2353 | return true; |
| 2354 | } |
| 2355 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2356 | /// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate |
| 2357 | /// memory in a typesafe manner and call constructors. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2358 | /// |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 2359 | /// This method is called to parse the new expression after the optional :: has |
| 2360 | /// been already parsed. If the :: was present, "UseGlobal" is true and "Start" |
| 2361 | /// is its location. Otherwise, "Start" is the location of the 'new' token. |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2362 | /// |
| 2363 | /// new-expression: |
| 2364 | /// '::'[opt] 'new' new-placement[opt] new-type-id |
| 2365 | /// new-initializer[opt] |
| 2366 | /// '::'[opt] 'new' new-placement[opt] '(' type-id ')' |
| 2367 | /// new-initializer[opt] |
| 2368 | /// |
| 2369 | /// new-placement: |
| 2370 | /// '(' expression-list ')' |
| 2371 | /// |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2372 | /// new-type-id: |
| 2373 | /// type-specifier-seq new-declarator[opt] |
Douglas Gregor | 893e1cc | 2011-04-15 19:40:02 +0000 | [diff] [blame] | 2374 | /// [GNU] attributes type-specifier-seq new-declarator[opt] |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2375 | /// |
| 2376 | /// new-declarator: |
| 2377 | /// ptr-operator new-declarator[opt] |
| 2378 | /// direct-new-declarator |
| 2379 | /// |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2380 | /// new-initializer: |
| 2381 | /// '(' expression-list[opt] ')' |
Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2382 | /// [C++0x] braced-init-list |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2383 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2384 | ExprResult |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 2385 | Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { |
| 2386 | assert(Tok.is(tok::kw_new) && "expected 'new' token"); |
| 2387 | ConsumeToken(); // Consume 'new' |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2388 | |
| 2389 | // A '(' now can be a new-placement or the '(' wrapping the type-id in the |
| 2390 | // second form of new-expression. It can't be a new-type-id. |
| 2391 | |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2392 | ExprVector PlacementArgs; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2393 | SourceLocation PlacementLParen, PlacementRParen; |
| 2394 | |
Douglas Gregor | 4bd4031 | 2010-07-13 15:54:32 +0000 | [diff] [blame] | 2395 | SourceRange TypeIdParens; |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2396 | DeclSpec DS(AttrFactory); |
Argyrios Kyrtzidis | 0b8c98f | 2011-06-28 03:01:23 +0000 | [diff] [blame] | 2397 | Declarator DeclaratorInfo(DS, Declarator::CXXNewContext); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2398 | if (Tok.is(tok::l_paren)) { |
| 2399 | // If it turns out to be a placement, we change the type location. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2400 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2401 | T.consumeOpen(); |
| 2402 | PlacementLParen = T.getOpenLocation(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2403 | if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) { |
| 2404 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 2405 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2406 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2407 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2408 | T.consumeClose(); |
| 2409 | PlacementRParen = T.getCloseLocation(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2410 | if (PlacementRParen.isInvalid()) { |
| 2411 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 2412 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2413 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2414 | |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2415 | if (PlacementArgs.empty()) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2416 | // Reset the placement locations. There was no placement. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2417 | TypeIdParens = T.getRange(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2418 | PlacementLParen = PlacementRParen = SourceLocation(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2419 | } else { |
| 2420 | // We still need the type. |
| 2421 | if (Tok.is(tok::l_paren)) { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2422 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2423 | T.consumeOpen(); |
Douglas Gregor | 893e1cc | 2011-04-15 19:40:02 +0000 | [diff] [blame] | 2424 | MaybeParseGNUAttributes(DeclaratorInfo); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2425 | ParseSpecifierQualifierList(DS); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2426 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2427 | ParseDeclarator(DeclaratorInfo); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2428 | T.consumeClose(); |
| 2429 | TypeIdParens = T.getRange(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2430 | } else { |
Douglas Gregor | 893e1cc | 2011-04-15 19:40:02 +0000 | [diff] [blame] | 2431 | MaybeParseGNUAttributes(DeclaratorInfo); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2432 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 2433 | DeclaratorInfo.setInvalidType(true); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2434 | else { |
| 2435 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2436 | ParseDeclaratorInternal(DeclaratorInfo, |
| 2437 | &Parser::ParseDirectNewDeclarator); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2438 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2439 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2440 | } |
| 2441 | } else { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2442 | // A new-type-id is a simplified type-id, where essentially the |
| 2443 | // direct-declarator is replaced by a direct-new-declarator. |
Douglas Gregor | 893e1cc | 2011-04-15 19:40:02 +0000 | [diff] [blame] | 2444 | MaybeParseGNUAttributes(DeclaratorInfo); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2445 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 2446 | DeclaratorInfo.setInvalidType(true); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2447 | else { |
| 2448 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2449 | ParseDeclaratorInternal(DeclaratorInfo, |
| 2450 | &Parser::ParseDirectNewDeclarator); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2451 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2452 | } |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 2453 | if (DeclaratorInfo.isInvalidType()) { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2454 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 2455 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2456 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2457 | |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2458 | ExprResult Initializer; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2459 | |
| 2460 | if (Tok.is(tok::l_paren)) { |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2461 | SourceLocation ConstructorLParen, ConstructorRParen; |
Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2462 | ExprVector ConstructorArgs; |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2463 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2464 | T.consumeOpen(); |
| 2465 | ConstructorLParen = T.getOpenLocation(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2466 | if (Tok.isNot(tok::r_paren)) { |
| 2467 | CommaLocsTy CommaLocs; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2468 | if (ParseExpressionList(ConstructorArgs, CommaLocs)) { |
| 2469 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 2470 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2471 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2472 | } |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2473 | T.consumeClose(); |
| 2474 | ConstructorRParen = T.getCloseLocation(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2475 | if (ConstructorRParen.isInvalid()) { |
| 2476 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 2477 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2478 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2479 | Initializer = Actions.ActOnParenListExpr(ConstructorLParen, |
| 2480 | ConstructorRParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2481 | ConstructorArgs); |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2482 | } else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) { |
Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 2483 | Diag(Tok.getLocation(), |
| 2484 | diag::warn_cxx98_compat_generalized_initializer_lists); |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2485 | Initializer = ParseBraceInitializer(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2486 | } |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2487 | if (Initializer.isInvalid()) |
| 2488 | return Initializer; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2489 | |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 2490 | return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2491 | PlacementArgs, PlacementRParen, |
Sebastian Redl | 2aed8b8 | 2012-02-16 12:22:20 +0000 | [diff] [blame] | 2492 | TypeIdParens, DeclaratorInfo, Initializer.take()); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2495 | /// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be |
| 2496 | /// passed to ParseDeclaratorInternal. |
| 2497 | /// |
| 2498 | /// direct-new-declarator: |
| 2499 | /// '[' expression ']' |
| 2500 | /// direct-new-declarator '[' constant-expression ']' |
| 2501 | /// |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 2502 | void Parser::ParseDirectNewDeclarator(Declarator &D) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2503 | // Parse the array dimensions. |
| 2504 | bool first = true; |
| 2505 | while (Tok.is(tok::l_square)) { |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2506 | // An array-size expression can't start with a lambda. |
| 2507 | if (CheckProhibitedCXX11Attribute()) |
| 2508 | continue; |
| 2509 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2510 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 2511 | T.consumeOpen(); |
| 2512 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2513 | ExprResult Size(first ? ParseExpression() |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 2514 | : ParseConstantExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2515 | if (Size.isInvalid()) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2516 | // Recover |
| 2517 | SkipUntil(tok::r_square); |
| 2518 | return; |
| 2519 | } |
| 2520 | first = false; |
| 2521 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2522 | T.consumeClose(); |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2523 | |
Bill Wendling | ad017fa | 2012-12-20 19:22:21 +0000 | [diff] [blame] | 2524 | // Attributes here appertain to the array type. C++11 [expr.new]p5. |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2525 | ParsedAttributes Attrs(AttrFactory); |
Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2526 | MaybeParseCXX11Attributes(Attrs); |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2527 | |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2528 | D.AddTypeInfo(DeclaratorChunk::getArray(0, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2529 | /*static=*/false, /*star=*/false, |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2530 | Size.release(), |
| 2531 | T.getOpenLocation(), |
| 2532 | T.getCloseLocation()), |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2533 | Attrs, T.getCloseLocation()); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2535 | if (T.getCloseLocation().isInvalid()) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2536 | return; |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | /// ParseExpressionListOrTypeId - Parse either an expression-list or a type-id. |
| 2541 | /// This ambiguity appears in the syntax of the C++ new operator. |
| 2542 | /// |
| 2543 | /// new-expression: |
| 2544 | /// '::'[opt] 'new' new-placement[opt] '(' type-id ')' |
| 2545 | /// new-initializer[opt] |
| 2546 | /// |
| 2547 | /// new-placement: |
| 2548 | /// '(' expression-list ')' |
| 2549 | /// |
John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 2550 | bool Parser::ParseExpressionListOrTypeId( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2551 | SmallVectorImpl<Expr*> &PlacementArgs, |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 2552 | Declarator &D) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2553 | // The '(' was already consumed. |
| 2554 | if (isTypeIdInParens()) { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2555 | ParseSpecifierQualifierList(D.getMutableDeclSpec()); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2556 | D.SetSourceRange(D.getDeclSpec().getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 2557 | ParseDeclarator(D); |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 2558 | return D.isInvalidType(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | // It's not a type, it has to be an expression list. |
| 2562 | // Discard the comma locations - ActOnCXXNew has enough parameters. |
| 2563 | CommaLocsTy CommaLocs; |
| 2564 | return ParseExpressionList(PlacementArgs, CommaLocs); |
| 2565 | } |
| 2566 | |
| 2567 | /// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used |
| 2568 | /// to free memory allocated by new. |
| 2569 | /// |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 2570 | /// This method is called to parse the 'delete' expression after the optional |
| 2571 | /// '::' has been already parsed. If the '::' was present, "UseGlobal" is true |
| 2572 | /// and "Start" is its location. Otherwise, "Start" is the location of the |
| 2573 | /// 'delete' token. |
| 2574 | /// |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2575 | /// delete-expression: |
| 2576 | /// '::'[opt] 'delete' cast-expression |
| 2577 | /// '::'[opt] 'delete' '[' ']' cast-expression |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2578 | ExprResult |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 2579 | Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { |
| 2580 | assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword"); |
| 2581 | ConsumeToken(); // Consume 'delete' |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2582 | |
| 2583 | // Array delete? |
| 2584 | bool ArrayDelete = false; |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 2585 | if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) { |
Richard Smith | 950435c | 2012-08-09 19:01:51 +0000 | [diff] [blame] | 2586 | // C++11 [expr.delete]p1: |
| 2587 | // Whenever the delete keyword is followed by empty square brackets, it |
| 2588 | // shall be interpreted as [array delete]. |
| 2589 | // [Footnote: A lambda expression with a lambda-introducer that consists |
| 2590 | // of empty square brackets can follow the delete keyword if |
| 2591 | // the lambda expression is enclosed in parentheses.] |
| 2592 | // FIXME: Produce a better diagnostic if the '[]' is unambiguously a |
| 2593 | // lambda-introducer. |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2594 | ArrayDelete = true; |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2595 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 2596 | |
| 2597 | T.consumeOpen(); |
| 2598 | T.consumeClose(); |
| 2599 | if (T.getCloseLocation().isInvalid()) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 2600 | return ExprError(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2601 | } |
| 2602 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2603 | ExprResult Operand(ParseCastExpression(false)); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2604 | if (Operand.isInvalid()) |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2605 | return Operand; |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2606 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2607 | return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.take()); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 2608 | } |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2609 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2611 | switch(kind) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2612 | default: llvm_unreachable("Not a known unary type trait."); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2613 | case tok::kw___has_nothrow_assign: return UTT_HasNothrowAssign; |
Joao Matos | 9ef9875 | 2013-03-27 01:34:16 +0000 | [diff] [blame] | 2614 | case tok::kw___has_nothrow_move_assign: return UTT_HasNothrowMoveAssign; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2615 | case tok::kw___has_nothrow_constructor: return UTT_HasNothrowConstructor; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2616 | case tok::kw___has_nothrow_copy: return UTT_HasNothrowCopy; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2617 | case tok::kw___has_trivial_assign: return UTT_HasTrivialAssign; |
Joao Matos | 9ef9875 | 2013-03-27 01:34:16 +0000 | [diff] [blame] | 2618 | case tok::kw___has_trivial_move_assign: return UTT_HasTrivialMoveAssign; |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 2619 | case tok::kw___has_trivial_constructor: |
| 2620 | return UTT_HasTrivialDefaultConstructor; |
Joao Matos | 9ef9875 | 2013-03-27 01:34:16 +0000 | [diff] [blame] | 2621 | case tok::kw___has_trivial_move_constructor: |
| 2622 | return UTT_HasTrivialMoveConstructor; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2623 | case tok::kw___has_trivial_copy: return UTT_HasTrivialCopy; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2624 | case tok::kw___has_trivial_destructor: return UTT_HasTrivialDestructor; |
| 2625 | case tok::kw___has_virtual_destructor: return UTT_HasVirtualDestructor; |
| 2626 | case tok::kw___is_abstract: return UTT_IsAbstract; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2627 | case tok::kw___is_arithmetic: return UTT_IsArithmetic; |
| 2628 | case tok::kw___is_array: return UTT_IsArray; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2629 | case tok::kw___is_class: return UTT_IsClass; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2630 | case tok::kw___is_complete_type: return UTT_IsCompleteType; |
| 2631 | case tok::kw___is_compound: return UTT_IsCompound; |
| 2632 | case tok::kw___is_const: return UTT_IsConst; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2633 | case tok::kw___is_empty: return UTT_IsEmpty; |
| 2634 | case tok::kw___is_enum: return UTT_IsEnum; |
Douglas Gregor | 5e9392b | 2011-12-03 18:14:24 +0000 | [diff] [blame] | 2635 | case tok::kw___is_final: return UTT_IsFinal; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2636 | case tok::kw___is_floating_point: return UTT_IsFloatingPoint; |
| 2637 | case tok::kw___is_function: return UTT_IsFunction; |
| 2638 | case tok::kw___is_fundamental: return UTT_IsFundamental; |
| 2639 | case tok::kw___is_integral: return UTT_IsIntegral; |
John McCall | ea30e2f | 2012-09-25 07:32:49 +0000 | [diff] [blame] | 2640 | case tok::kw___is_interface_class: return UTT_IsInterfaceClass; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2641 | case tok::kw___is_lvalue_reference: return UTT_IsLvalueReference; |
| 2642 | case tok::kw___is_member_function_pointer: return UTT_IsMemberFunctionPointer; |
| 2643 | case tok::kw___is_member_object_pointer: return UTT_IsMemberObjectPointer; |
| 2644 | case tok::kw___is_member_pointer: return UTT_IsMemberPointer; |
| 2645 | case tok::kw___is_object: return UTT_IsObject; |
Chandler Carruth | 4e61ddd | 2011-04-23 10:47:20 +0000 | [diff] [blame] | 2646 | case tok::kw___is_literal: return UTT_IsLiteral; |
Chandler Carruth | 3840281 | 2011-04-24 02:49:28 +0000 | [diff] [blame] | 2647 | case tok::kw___is_literal_type: return UTT_IsLiteral; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2648 | case tok::kw___is_pod: return UTT_IsPOD; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2649 | case tok::kw___is_pointer: return UTT_IsPointer; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2650 | case tok::kw___is_polymorphic: return UTT_IsPolymorphic; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2651 | case tok::kw___is_reference: return UTT_IsReference; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2652 | case tok::kw___is_rvalue_reference: return UTT_IsRvalueReference; |
| 2653 | case tok::kw___is_scalar: return UTT_IsScalar; |
| 2654 | case tok::kw___is_signed: return UTT_IsSigned; |
| 2655 | case tok::kw___is_standard_layout: return UTT_IsStandardLayout; |
| 2656 | case tok::kw___is_trivial: return UTT_IsTrivial; |
Sean Hunt | feb375d | 2011-05-13 00:31:07 +0000 | [diff] [blame] | 2657 | case tok::kw___is_trivially_copyable: return UTT_IsTriviallyCopyable; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2658 | case tok::kw___is_union: return UTT_IsUnion; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2659 | case tok::kw___is_unsigned: return UTT_IsUnsigned; |
| 2660 | case tok::kw___is_void: return UTT_IsVoid; |
| 2661 | case tok::kw___is_volatile: return UTT_IsVolatile; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2662 | } |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | static BinaryTypeTrait BinaryTypeTraitFromTokKind(tok::TokenKind kind) { |
| 2666 | switch(kind) { |
Francois Pichet | 38c2b73 | 2010-12-07 00:55:57 +0000 | [diff] [blame] | 2667 | default: llvm_unreachable("Not a known binary type trait"); |
Francois Pichet | f187237 | 2010-12-08 22:35:30 +0000 | [diff] [blame] | 2668 | case tok::kw___is_base_of: return BTT_IsBaseOf; |
John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 2669 | case tok::kw___is_convertible: return BTT_IsConvertible; |
| 2670 | case tok::kw___is_same: return BTT_IsSame; |
Francois Pichet | f187237 | 2010-12-08 22:35:30 +0000 | [diff] [blame] | 2671 | case tok::kw___builtin_types_compatible_p: return BTT_TypeCompatible; |
Douglas Gregor | 9f36113 | 2011-01-27 20:28:01 +0000 | [diff] [blame] | 2672 | case tok::kw___is_convertible_to: return BTT_IsConvertibleTo; |
Douglas Gregor | 25d0a0f | 2012-02-23 07:33:15 +0000 | [diff] [blame] | 2673 | case tok::kw___is_trivially_assignable: return BTT_IsTriviallyAssignable; |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2674 | } |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2677 | static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind) { |
| 2678 | switch (kind) { |
| 2679 | default: llvm_unreachable("Not a known type trait"); |
| 2680 | case tok::kw___is_trivially_constructible: |
| 2681 | return TT_IsTriviallyConstructible; |
| 2682 | } |
| 2683 | } |
| 2684 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2685 | static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) { |
| 2686 | switch(kind) { |
| 2687 | default: llvm_unreachable("Not a known binary type trait"); |
| 2688 | case tok::kw___array_rank: return ATT_ArrayRank; |
| 2689 | case tok::kw___array_extent: return ATT_ArrayExtent; |
| 2690 | } |
| 2691 | } |
| 2692 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2693 | static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) { |
| 2694 | switch(kind) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2695 | default: llvm_unreachable("Not a known unary expression trait."); |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2696 | case tok::kw___is_lvalue_expr: return ET_IsLValueExpr; |
| 2697 | case tok::kw___is_rvalue_expr: return ET_IsRValueExpr; |
| 2698 | } |
| 2699 | } |
| 2700 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2701 | /// ParseUnaryTypeTrait - Parse the built-in unary type-trait |
| 2702 | /// pseudo-functions that allow implementation of the TR1/C++0x type traits |
| 2703 | /// templates. |
| 2704 | /// |
| 2705 | /// primary-expression: |
| 2706 | /// [GNU] unary-type-trait '(' type-id ')' |
| 2707 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2708 | ExprResult Parser::ParseUnaryTypeTrait() { |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2709 | UnaryTypeTrait UTT = UnaryTypeTraitFromTokKind(Tok.getKind()); |
| 2710 | SourceLocation Loc = ConsumeToken(); |
| 2711 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2712 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2713 | if (T.expectAndConsume(diag::err_expected_lparen)) |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2714 | return ExprError(); |
| 2715 | |
| 2716 | // FIXME: Error reporting absolutely sucks! If the this fails to parse a type |
| 2717 | // there will be cryptic errors about mismatched parentheses and missing |
| 2718 | // specifiers. |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2719 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2720 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2721 | T.consumeClose(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2722 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2723 | if (Ty.isInvalid()) |
| 2724 | return ExprError(); |
| 2725 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2726 | return Actions.ActOnUnaryTypeTrait(UTT, Loc, Ty.get(), T.getCloseLocation()); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 2727 | } |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2728 | |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2729 | /// ParseBinaryTypeTrait - Parse the built-in binary type-trait |
| 2730 | /// pseudo-functions that allow implementation of the TR1/C++0x type traits |
| 2731 | /// templates. |
| 2732 | /// |
| 2733 | /// primary-expression: |
| 2734 | /// [GNU] binary-type-trait '(' type-id ',' type-id ')' |
| 2735 | /// |
| 2736 | ExprResult Parser::ParseBinaryTypeTrait() { |
| 2737 | BinaryTypeTrait BTT = BinaryTypeTraitFromTokKind(Tok.getKind()); |
| 2738 | SourceLocation Loc = ConsumeToken(); |
| 2739 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2740 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2741 | if (T.expectAndConsume(diag::err_expected_lparen)) |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2742 | return ExprError(); |
| 2743 | |
| 2744 | TypeResult LhsTy = ParseTypeName(); |
| 2745 | if (LhsTy.isInvalid()) { |
| 2746 | SkipUntil(tok::r_paren); |
| 2747 | return ExprError(); |
| 2748 | } |
| 2749 | |
| 2750 | if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) { |
| 2751 | SkipUntil(tok::r_paren); |
| 2752 | return ExprError(); |
| 2753 | } |
| 2754 | |
| 2755 | TypeResult RhsTy = ParseTypeName(); |
| 2756 | if (RhsTy.isInvalid()) { |
| 2757 | SkipUntil(tok::r_paren); |
| 2758 | return ExprError(); |
| 2759 | } |
| 2760 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2761 | T.consumeClose(); |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2762 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2763 | return Actions.ActOnBinaryTypeTrait(BTT, Loc, LhsTy.get(), RhsTy.get(), |
| 2764 | T.getCloseLocation()); |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2767 | /// \brief Parse the built-in type-trait pseudo-functions that allow |
| 2768 | /// implementation of the TR1/C++11 type traits templates. |
| 2769 | /// |
| 2770 | /// primary-expression: |
| 2771 | /// type-trait '(' type-id-seq ')' |
| 2772 | /// |
| 2773 | /// type-id-seq: |
| 2774 | /// type-id ...[opt] type-id-seq[opt] |
| 2775 | /// |
| 2776 | ExprResult Parser::ParseTypeTrait() { |
| 2777 | TypeTrait Kind = TypeTraitFromTokKind(Tok.getKind()); |
| 2778 | SourceLocation Loc = ConsumeToken(); |
| 2779 | |
| 2780 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 2781 | if (Parens.expectAndConsume(diag::err_expected_lparen)) |
| 2782 | return ExprError(); |
| 2783 | |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2784 | SmallVector<ParsedType, 2> Args; |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 2785 | do { |
| 2786 | // Parse the next type. |
| 2787 | TypeResult Ty = ParseTypeName(); |
| 2788 | if (Ty.isInvalid()) { |
| 2789 | Parens.skipToEnd(); |
| 2790 | return ExprError(); |
| 2791 | } |
| 2792 | |
| 2793 | // Parse the ellipsis, if present. |
| 2794 | if (Tok.is(tok::ellipsis)) { |
| 2795 | Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken()); |
| 2796 | if (Ty.isInvalid()) { |
| 2797 | Parens.skipToEnd(); |
| 2798 | return ExprError(); |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | // Add this type to the list of arguments. |
| 2803 | Args.push_back(Ty.get()); |
| 2804 | |
| 2805 | if (Tok.is(tok::comma)) { |
| 2806 | ConsumeToken(); |
| 2807 | continue; |
| 2808 | } |
| 2809 | |
| 2810 | break; |
| 2811 | } while (true); |
| 2812 | |
| 2813 | if (Parens.consumeClose()) |
| 2814 | return ExprError(); |
| 2815 | |
| 2816 | return Actions.ActOnTypeTrait(Kind, Loc, Args, Parens.getCloseLocation()); |
| 2817 | } |
| 2818 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2819 | /// ParseArrayTypeTrait - Parse the built-in array type-trait |
| 2820 | /// pseudo-functions. |
| 2821 | /// |
| 2822 | /// primary-expression: |
| 2823 | /// [Embarcadero] '__array_rank' '(' type-id ')' |
| 2824 | /// [Embarcadero] '__array_extent' '(' type-id ',' expression ')' |
| 2825 | /// |
| 2826 | ExprResult Parser::ParseArrayTypeTrait() { |
| 2827 | ArrayTypeTrait ATT = ArrayTypeTraitFromTokKind(Tok.getKind()); |
| 2828 | SourceLocation Loc = ConsumeToken(); |
| 2829 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2830 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2831 | if (T.expectAndConsume(diag::err_expected_lparen)) |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2832 | return ExprError(); |
| 2833 | |
| 2834 | TypeResult Ty = ParseTypeName(); |
| 2835 | if (Ty.isInvalid()) { |
| 2836 | SkipUntil(tok::comma); |
| 2837 | SkipUntil(tok::r_paren); |
| 2838 | return ExprError(); |
| 2839 | } |
| 2840 | |
| 2841 | switch (ATT) { |
| 2842 | case ATT_ArrayRank: { |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2843 | T.consumeClose(); |
| 2844 | return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), NULL, |
| 2845 | T.getCloseLocation()); |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2846 | } |
| 2847 | case ATT_ArrayExtent: { |
| 2848 | if (ExpectAndConsume(tok::comma, diag::err_expected_comma)) { |
| 2849 | SkipUntil(tok::r_paren); |
| 2850 | return ExprError(); |
| 2851 | } |
| 2852 | |
| 2853 | ExprResult DimExpr = ParseExpression(); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2854 | T.consumeClose(); |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2855 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2856 | return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(), |
| 2857 | T.getCloseLocation()); |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2858 | } |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2859 | } |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 2860 | llvm_unreachable("Invalid ArrayTypeTrait!"); |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2863 | /// ParseExpressionTrait - Parse built-in expression-trait |
| 2864 | /// pseudo-functions like __is_lvalue_expr( xxx ). |
| 2865 | /// |
| 2866 | /// primary-expression: |
| 2867 | /// [Embarcadero] expression-trait '(' expression ')' |
| 2868 | /// |
| 2869 | ExprResult Parser::ParseExpressionTrait() { |
| 2870 | ExpressionTrait ET = ExpressionTraitFromTokKind(Tok.getKind()); |
| 2871 | SourceLocation Loc = ConsumeToken(); |
| 2872 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2873 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2874 | if (T.expectAndConsume(diag::err_expected_lparen)) |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2875 | return ExprError(); |
| 2876 | |
| 2877 | ExprResult Expr = ParseExpression(); |
| 2878 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2879 | T.consumeClose(); |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2880 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2881 | return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(), |
| 2882 | T.getCloseLocation()); |
John Wiegley | 5526220 | 2011-04-25 06:54:41 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2886 | /// ParseCXXAmbiguousParenExpression - We have parsed the left paren of a |
| 2887 | /// parenthesized ambiguous type-id. This uses tentative parsing to disambiguate |
| 2888 | /// based on the context past the parens. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2889 | ExprResult |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2890 | Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2891 | ParsedType &CastTy, |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2892 | BalancedDelimiterTracker &Tracker) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2893 | assert(getLangOpts().CPlusPlus && "Should only be called for C++!"); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2894 | assert(ExprType == CastExpr && "Compound literals are not ambiguous!"); |
| 2895 | assert(isTypeIdInParens() && "Not a type-id!"); |
| 2896 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2897 | ExprResult Result(true); |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2898 | CastTy = ParsedType(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2899 | |
| 2900 | // We need to disambiguate a very ugly part of the C++ syntax: |
| 2901 | // |
| 2902 | // (T())x; - type-id |
| 2903 | // (T())*x; - type-id |
| 2904 | // (T())/x; - expression |
| 2905 | // (T()); - expression |
| 2906 | // |
| 2907 | // The bad news is that we cannot use the specialized tentative parser, since |
| 2908 | // it can only verify that the thing inside the parens can be parsed as |
| 2909 | // type-id, it is not useful for determining the context past the parens. |
| 2910 | // |
| 2911 | // The good news is that the parser can disambiguate this part without |
Argyrios Kyrtzidis | a558a89 | 2009-05-22 15:12:46 +0000 | [diff] [blame] | 2912 | // making any unnecessary Action calls. |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2913 | // |
| 2914 | // It uses a scheme similar to parsing inline methods. The parenthesized |
| 2915 | // tokens are cached, the context that follows is determined (possibly by |
| 2916 | // parsing a cast-expression), and then we re-introduce the cached tokens |
| 2917 | // into the token stream and parse them appropriately. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2918 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2919 | ParenParseOption ParseAs; |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2920 | CachedTokens Toks; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2921 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2922 | // Store the tokens of the parentheses. We will parse them after we determine |
| 2923 | // the context that follows them. |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 2924 | if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) { |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2925 | // We didn't find the ')' we expected. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2926 | Tracker.consumeClose(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2927 | return ExprError(); |
| 2928 | } |
| 2929 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2930 | if (Tok.is(tok::l_brace)) { |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2931 | ParseAs = CompoundLiteral; |
| 2932 | } else { |
| 2933 | bool NotCastExpr; |
Eli Friedman | b53f08a | 2009-05-25 19:41:42 +0000 | [diff] [blame] | 2934 | // FIXME: Special-case ++ and --: "(S())++;" is not a cast-expression |
| 2935 | if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) { |
| 2936 | NotCastExpr = true; |
| 2937 | } else { |
| 2938 | // Try parsing the cast-expression that may follow. |
| 2939 | // If it is not a cast-expression, NotCastExpr will be true and no token |
| 2940 | // will be consumed. |
| 2941 | Result = ParseCastExpression(false/*isUnaryExpression*/, |
| 2942 | false/*isAddressofOperand*/, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2943 | NotCastExpr, |
Argyrios Kyrtzidis | 0a85183 | 2011-07-01 22:22:59 +0000 | [diff] [blame] | 2944 | // type-id has priority. |
Kaelyn Uhrain | cd78e61 | 2012-01-25 20:49:08 +0000 | [diff] [blame] | 2945 | IsTypeCast); |
Eli Friedman | b53f08a | 2009-05-25 19:41:42 +0000 | [diff] [blame] | 2946 | } |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2947 | |
| 2948 | // If we parsed a cast-expression, it's really a type-id, otherwise it's |
| 2949 | // an expression. |
| 2950 | ParseAs = NotCastExpr ? SimpleExpr : CastExpr; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2953 | // The current token should go after the cached tokens. |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2954 | Toks.push_back(Tok); |
| 2955 | // Re-enter the stored parenthesized tokens into the token stream, so we may |
| 2956 | // parse them now. |
| 2957 | PP.EnterTokenStream(Toks.data(), Toks.size(), |
| 2958 | true/*DisableMacroExpansion*/, false/*OwnsTokens*/); |
| 2959 | // Drop the current token and bring the first cached one. It's the same token |
| 2960 | // as when we entered this function. |
| 2961 | ConsumeAnyToken(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2962 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2963 | if (ParseAs >= CompoundLiteral) { |
Argyrios Kyrtzidis | 0a85183 | 2011-07-01 22:22:59 +0000 | [diff] [blame] | 2964 | // Parse the type declarator. |
| 2965 | DeclSpec DS(AttrFactory); |
| 2966 | ParseSpecifierQualifierList(DS); |
| 2967 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 2968 | ParseDeclarator(DeclaratorInfo); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2969 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2970 | // Match the ')'. |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2971 | Tracker.consumeClose(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2972 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2973 | if (ParseAs == CompoundLiteral) { |
| 2974 | ExprType = CompoundLiteral; |
Argyrios Kyrtzidis | 0a85183 | 2011-07-01 22:22:59 +0000 | [diff] [blame] | 2975 | TypeResult Ty = ParseTypeName(); |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2976 | return ParseCompoundLiteralExpression(Ty.get(), |
| 2977 | Tracker.getOpenLocation(), |
| 2978 | Tracker.getCloseLocation()); |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2979 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2980 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2981 | // We parsed '(' type-id ')' and the thing after it wasn't a '{'. |
| 2982 | assert(ParseAs == CastExpr); |
| 2983 | |
Argyrios Kyrtzidis | 0a85183 | 2011-07-01 22:22:59 +0000 | [diff] [blame] | 2984 | if (DeclaratorInfo.isInvalidType()) |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2985 | return ExprError(); |
| 2986 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2987 | // Result is what ParseCastExpression returned earlier. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2988 | if (!Result.isInvalid()) |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2989 | Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(), |
| 2990 | DeclaratorInfo, CastTy, |
| 2991 | Tracker.getCloseLocation(), Result.take()); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2992 | return Result; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2993 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2994 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2995 | // Not a compound literal, and not followed by a cast-expression. |
| 2996 | assert(ParseAs == SimpleExpr); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2997 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 2998 | ExprType = SimpleExpr; |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 2999 | Result = ParseExpression(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 3000 | if (!Result.isInvalid() && Tok.is(tok::r_paren)) |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 3001 | Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(), |
| 3002 | Tok.getLocation(), Result.take()); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 3003 | |
| 3004 | // Match the ')'. |
| 3005 | if (Result.isInvalid()) { |
| 3006 | SkipUntil(tok::r_paren); |
| 3007 | return ExprError(); |
| 3008 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3009 | |
Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 3010 | Tracker.consumeClose(); |
Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 3011 | return Result; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 3012 | } |