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