Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 1 | //===--- ParseDeclCXX.cpp - C++ Declaration 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. |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ Declaration portions of the Parser interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Douglas Gregor | 1b7f898 | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 14 | #include "clang/Parse/Parser.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 15 | #include "clang/Parse/ParseDiagnostic.h" |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 16 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 17 | #include "clang/Parse/Scope.h" |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 18 | #include "AstGuard.h" |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 19 | #include "ExtensionRAIIObject.h" |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
| 22 | /// ParseNamespace - We know that the current token is a namespace keyword. This |
| 23 | /// may either be a top level namespace or a block-level namespace alias. |
| 24 | /// |
| 25 | /// namespace-definition: [C++ 7.3: basic.namespace] |
| 26 | /// named-namespace-definition |
| 27 | /// unnamed-namespace-definition |
| 28 | /// |
| 29 | /// unnamed-namespace-definition: |
| 30 | /// 'namespace' attributes[opt] '{' namespace-body '}' |
| 31 | /// |
| 32 | /// named-namespace-definition: |
| 33 | /// original-namespace-definition |
| 34 | /// extension-namespace-definition |
| 35 | /// |
| 36 | /// original-namespace-definition: |
| 37 | /// 'namespace' identifier attributes[opt] '{' namespace-body '}' |
| 38 | /// |
| 39 | /// extension-namespace-definition: |
| 40 | /// 'namespace' original-namespace-name '{' namespace-body '}' |
| 41 | /// |
| 42 | /// namespace-alias-definition: [C++ 7.3.2: namespace.alias] |
| 43 | /// 'namespace' identifier '=' qualified-namespace-specifier ';' |
| 44 | /// |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 45 | Parser::DeclPtrTy Parser::ParseNamespace(unsigned Context, |
| 46 | SourceLocation &DeclEnd) { |
Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 47 | assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 48 | SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. |
| 49 | |
| 50 | SourceLocation IdentLoc; |
| 51 | IdentifierInfo *Ident = 0; |
| 52 | |
Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 53 | if (Tok.is(tok::identifier)) { |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 54 | Ident = Tok.getIdentifierInfo(); |
| 55 | IdentLoc = ConsumeToken(); // eat the identifier. |
| 56 | } |
| 57 | |
| 58 | // Read label attributes, if present. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 59 | Action::AttrTy *AttrList = 0; |
Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 60 | if (Tok.is(tok::kw___attribute)) |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 61 | // FIXME: save these somewhere. |
| 62 | AttrList = ParseAttributes(); |
| 63 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 64 | if (Tok.is(tok::equal)) |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 65 | // FIXME: Verify no attributes were present. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 66 | return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 67 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 68 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 69 | Diag(Tok, Ident ? diag::err_expected_lbrace : |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 70 | diag::err_expected_ident_lbrace); |
| 71 | return DeclPtrTy(); |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 74 | SourceLocation LBrace = ConsumeBrace(); |
| 75 | |
| 76 | // Enter a scope for the namespace. |
| 77 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 78 | |
| 79 | DeclPtrTy NamespcDecl = |
| 80 | Actions.ActOnStartNamespaceDef(CurScope, IdentLoc, Ident, LBrace); |
| 81 | |
| 82 | PrettyStackTraceActionsDecl CrashInfo(NamespcDecl, NamespaceLoc, Actions, |
| 83 | PP.getSourceManager(), |
| 84 | "parsing namespace"); |
| 85 | |
| 86 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) |
| 87 | ParseExternalDeclaration(); |
| 88 | |
| 89 | // Leave the namespace scope. |
| 90 | NamespaceScope.Exit(); |
| 91 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 92 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace); |
| 93 | Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 94 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 95 | DeclEnd = RBraceLoc; |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 96 | return NamespcDecl; |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 97 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 98 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 99 | /// ParseNamespaceAlias - Parse the part after the '=' in a namespace |
| 100 | /// alias definition. |
| 101 | /// |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 102 | Parser::DeclPtrTy Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, |
| 103 | SourceLocation AliasLoc, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 104 | IdentifierInfo *Alias, |
| 105 | SourceLocation &DeclEnd) { |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 106 | assert(Tok.is(tok::equal) && "Not equal token"); |
| 107 | |
| 108 | ConsumeToken(); // eat the '='. |
| 109 | |
| 110 | CXXScopeSpec SS; |
| 111 | // Parse (optional) nested-name-specifier. |
| 112 | ParseOptionalCXXScopeSpecifier(SS); |
| 113 | |
| 114 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
| 115 | Diag(Tok, diag::err_expected_namespace_name); |
| 116 | // Skip to end of the definition and eat the ';'. |
| 117 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 118 | return DeclPtrTy(); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // Parse identifier. |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 122 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 123 | SourceLocation IdentLoc = ConsumeToken(); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 124 | |
| 125 | // Eat the ';'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 126 | DeclEnd = Tok.getLocation(); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 127 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
| 128 | "namespace name", tok::semi); |
| 129 | |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 130 | return Actions.ActOnNamespaceAliasDef(CurScope, NamespaceLoc, AliasLoc, Alias, |
| 131 | SS, IdentLoc, Ident); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 134 | /// ParseLinkage - We know that the current token is a string_literal |
| 135 | /// and just before that, that extern was seen. |
| 136 | /// |
| 137 | /// linkage-specification: [C++ 7.5p2: dcl.link] |
| 138 | /// 'extern' string-literal '{' declaration-seq[opt] '}' |
| 139 | /// 'extern' string-literal declaration |
| 140 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 141 | Parser::DeclPtrTy Parser::ParseLinkage(unsigned Context) { |
Douglas Gregor | c19923d | 2008-11-21 16:10:08 +0000 | [diff] [blame] | 142 | assert(Tok.is(tok::string_literal) && "Not a string literal!"); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 143 | llvm::SmallVector<char, 8> LangBuffer; |
| 144 | // LangBuffer is guaranteed to be big enough. |
| 145 | LangBuffer.resize(Tok.getLength()); |
| 146 | const char *LangBufPtr = &LangBuffer[0]; |
| 147 | unsigned StrSize = PP.getSpelling(Tok, LangBufPtr); |
| 148 | |
| 149 | SourceLocation Loc = ConsumeStringToken(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 150 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 151 | ParseScope LinkageScope(this, Scope::DeclScope); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 152 | DeclPtrTy LinkageSpec |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 153 | = Actions.ActOnStartLinkageSpecification(CurScope, |
| 154 | /*FIXME: */SourceLocation(), |
| 155 | Loc, LangBufPtr, StrSize, |
| 156 | Tok.is(tok::l_brace)? Tok.getLocation() |
| 157 | : SourceLocation()); |
| 158 | |
| 159 | if (Tok.isNot(tok::l_brace)) { |
| 160 | ParseDeclarationOrFunctionDefinition(); |
| 161 | return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec, |
| 162 | SourceLocation()); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | SourceLocation LBrace = ConsumeBrace(); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 166 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 167 | ParseExternalDeclaration(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 170 | SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 171 | return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec, RBrace); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 172 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 173 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 174 | /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or |
| 175 | /// using-directive. Assumes that current token is 'using'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 176 | Parser::DeclPtrTy Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, |
| 177 | SourceLocation &DeclEnd) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 178 | assert(Tok.is(tok::kw_using) && "Not using token"); |
| 179 | |
| 180 | // Eat 'using'. |
| 181 | SourceLocation UsingLoc = ConsumeToken(); |
| 182 | |
Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 183 | if (Tok.is(tok::kw_namespace)) |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 184 | // Next token after 'using' is 'namespace' so it must be using-directive |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 185 | return ParseUsingDirective(Context, UsingLoc, DeclEnd); |
Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 186 | |
| 187 | // Otherwise, it must be using-declaration. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 188 | return ParseUsingDeclaration(Context, UsingLoc, DeclEnd); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /// ParseUsingDirective - Parse C++ using-directive, assumes |
| 192 | /// that current token is 'namespace' and 'using' was already parsed. |
| 193 | /// |
| 194 | /// using-directive: [C++ 7.3.p4: namespace.udir] |
| 195 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 196 | /// namespace-name ; |
| 197 | /// [GNU] using-directive: |
| 198 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 199 | /// namespace-name attributes[opt] ; |
| 200 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 201 | Parser::DeclPtrTy Parser::ParseUsingDirective(unsigned Context, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 202 | SourceLocation UsingLoc, |
| 203 | SourceLocation &DeclEnd) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 204 | assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); |
| 205 | |
| 206 | // Eat 'namespace'. |
| 207 | SourceLocation NamespcLoc = ConsumeToken(); |
| 208 | |
| 209 | CXXScopeSpec SS; |
| 210 | // Parse (optional) nested-name-specifier. |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 211 | ParseOptionalCXXScopeSpecifier(SS); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 212 | |
| 213 | AttributeList *AttrList = 0; |
| 214 | IdentifierInfo *NamespcName = 0; |
| 215 | SourceLocation IdentLoc = SourceLocation(); |
| 216 | |
| 217 | // Parse namespace-name. |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 218 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 219 | Diag(Tok, diag::err_expected_namespace_name); |
| 220 | // If there was invalid namespace name, skip to end of decl, and eat ';'. |
| 221 | SkipUntil(tok::semi); |
| 222 | // FIXME: Are there cases, when we would like to call ActOnUsingDirective? |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 223 | return DeclPtrTy(); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 224 | } |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 225 | |
| 226 | // Parse identifier. |
| 227 | NamespcName = Tok.getIdentifierInfo(); |
| 228 | IdentLoc = ConsumeToken(); |
| 229 | |
| 230 | // Parse (optional) attributes (most likely GNU strong-using extension). |
| 231 | if (Tok.is(tok::kw___attribute)) |
| 232 | AttrList = ParseAttributes(); |
| 233 | |
| 234 | // Eat ';'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 235 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 236 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
| 237 | AttrList ? "attributes list" : "namespace name", tok::semi); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 238 | |
| 239 | return Actions.ActOnUsingDirective(CurScope, UsingLoc, NamespcLoc, SS, |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 240 | IdentLoc, NamespcName, AttrList); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /// ParseUsingDeclaration - Parse C++ using-declaration. Assumes that |
| 244 | /// 'using' was already seen. |
| 245 | /// |
| 246 | /// using-declaration: [C++ 7.3.p3: namespace.udecl] |
| 247 | /// 'using' 'typename'[opt] ::[opt] nested-name-specifier |
| 248 | /// unqualified-id [TODO] |
| 249 | /// 'using' :: unqualified-id [TODO] |
| 250 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 251 | Parser::DeclPtrTy Parser::ParseUsingDeclaration(unsigned Context, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 252 | SourceLocation UsingLoc, |
| 253 | SourceLocation &DeclEnd) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 254 | assert(false && "Not implemented"); |
| 255 | // FIXME: Implement parsing. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 256 | return DeclPtrTy(); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 259 | /// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion. |
| 260 | /// |
| 261 | /// static_assert-declaration: |
| 262 | /// static_assert ( constant-expression , string-literal ) ; |
| 263 | /// |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 264 | Parser::DeclPtrTy Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 265 | assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration"); |
| 266 | SourceLocation StaticAssertLoc = ConsumeToken(); |
| 267 | |
| 268 | if (Tok.isNot(tok::l_paren)) { |
| 269 | Diag(Tok, diag::err_expected_lparen); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 270 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | SourceLocation LParenLoc = ConsumeParen(); |
| 274 | |
| 275 | OwningExprResult AssertExpr(ParseConstantExpression()); |
| 276 | if (AssertExpr.isInvalid()) { |
| 277 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 278 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 281 | if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 282 | return DeclPtrTy(); |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 283 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 284 | if (Tok.isNot(tok::string_literal)) { |
| 285 | Diag(Tok, diag::err_expected_string_literal); |
| 286 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 287 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | OwningExprResult AssertMessage(ParseStringLiteralExpression()); |
| 291 | if (AssertMessage.isInvalid()) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 292 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 293 | |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 294 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 295 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 296 | DeclEnd = Tok.getLocation(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 297 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert); |
| 298 | |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 299 | return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, move(AssertExpr), |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 300 | move(AssertMessage)); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 303 | /// ParseClassName - Parse a C++ class-name, which names a class. Note |
| 304 | /// that we only check that the result names a type; semantic analysis |
| 305 | /// will need to verify that the type names a class. The result is |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 306 | /// either a type or NULL, depending on whether a type name was |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 307 | /// found. |
| 308 | /// |
| 309 | /// class-name: [C++ 9.1] |
| 310 | /// identifier |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 311 | /// simple-template-id |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 312 | /// |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 313 | Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, |
| 314 | const CXXScopeSpec *SS) { |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 315 | // Check whether we have a template-id that names a type. |
| 316 | if (Tok.is(tok::annot_template_id)) { |
| 317 | TemplateIdAnnotation *TemplateId |
| 318 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 319 | if (TemplateId->Kind == TNK_Type_template) { |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 320 | AnnotateTemplateIdTokenAsType(SS); |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 321 | |
| 322 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 323 | TypeTy *Type = Tok.getAnnotationValue(); |
| 324 | EndLocation = Tok.getAnnotationEndLoc(); |
| 325 | ConsumeToken(); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 326 | |
| 327 | if (Type) |
| 328 | return Type; |
| 329 | return true; |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Fall through to produce an error below. |
| 333 | } |
| 334 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 335 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 336 | Diag(Tok, diag::err_expected_class_name); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 337 | return true; |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // We have an identifier; check whether it is actually a type. |
Douglas Gregor | b696ea3 | 2009-02-04 17:00:24 +0000 | [diff] [blame] | 341 | TypeTy *Type = Actions.getTypeName(*Tok.getIdentifierInfo(), |
| 342 | Tok.getLocation(), CurScope, SS); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 343 | if (!Type) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 344 | Diag(Tok, diag::err_expected_class_name); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 345 | return true; |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | // Consume the identifier. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 349 | EndLocation = ConsumeToken(); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 350 | return Type; |
| 351 | } |
| 352 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 353 | /// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or |
| 354 | /// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which |
| 355 | /// until we reach the start of a definition or see a token that |
| 356 | /// cannot start a definition. |
| 357 | /// |
| 358 | /// class-specifier: [C++ class] |
| 359 | /// class-head '{' member-specification[opt] '}' |
| 360 | /// class-head '{' member-specification[opt] '}' attributes[opt] |
| 361 | /// class-head: |
| 362 | /// class-key identifier[opt] base-clause[opt] |
| 363 | /// class-key nested-name-specifier identifier base-clause[opt] |
| 364 | /// class-key nested-name-specifier[opt] simple-template-id |
| 365 | /// base-clause[opt] |
| 366 | /// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] |
| 367 | /// [GNU] class-key attributes[opt] nested-name-specifier |
| 368 | /// identifier base-clause[opt] |
| 369 | /// [GNU] class-key attributes[opt] nested-name-specifier[opt] |
| 370 | /// simple-template-id base-clause[opt] |
| 371 | /// class-key: |
| 372 | /// 'class' |
| 373 | /// 'struct' |
| 374 | /// 'union' |
| 375 | /// |
| 376 | /// elaborated-type-specifier: [C++ dcl.type.elab] |
| 377 | /// class-key ::[opt] nested-name-specifier[opt] identifier |
| 378 | /// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] |
| 379 | /// simple-template-id |
| 380 | /// |
| 381 | /// Note that the C++ class-specifier and elaborated-type-specifier, |
| 382 | /// together, subsume the C99 struct-or-union-specifier: |
| 383 | /// |
| 384 | /// struct-or-union-specifier: [C99 6.7.2.1] |
| 385 | /// struct-or-union identifier[opt] '{' struct-contents '}' |
| 386 | /// struct-or-union identifier |
| 387 | /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents |
| 388 | /// '}' attributes[opt] |
| 389 | /// [GNU] struct-or-union attributes[opt] identifier |
| 390 | /// struct-or-union: |
| 391 | /// 'struct' |
| 392 | /// 'union' |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 393 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, |
| 394 | SourceLocation StartLoc, DeclSpec &DS, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 395 | const ParsedTemplateInfo &TemplateInfo, |
Douglas Gregor | 06c0fec | 2009-03-25 22:00:53 +0000 | [diff] [blame] | 396 | AccessSpecifier AS) { |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 397 | DeclSpec::TST TagType; |
| 398 | if (TagTokKind == tok::kw_struct) |
| 399 | TagType = DeclSpec::TST_struct; |
| 400 | else if (TagTokKind == tok::kw_class) |
| 401 | TagType = DeclSpec::TST_class; |
| 402 | else { |
| 403 | assert(TagTokKind == tok::kw_union && "Not a class specifier"); |
| 404 | TagType = DeclSpec::TST_union; |
| 405 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 406 | |
| 407 | AttributeList *Attr = 0; |
| 408 | // If attributes exist after tag, parse them. |
| 409 | if (Tok.is(tok::kw___attribute)) |
| 410 | Attr = ParseAttributes(); |
| 411 | |
Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 412 | // If declspecs exist after tag, parse them. |
| 413 | if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft) |
| 414 | FuzzyParseMicrosoftDeclSpec(); |
| 415 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 416 | // Parse the (optional) nested-name-specifier. |
| 417 | CXXScopeSpec SS; |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 418 | if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS)) |
| 419 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 420 | Diag(Tok, diag::err_expected_ident); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 421 | |
| 422 | // Parse the (optional) class name or simple-template-id. |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 423 | IdentifierInfo *Name = 0; |
| 424 | SourceLocation NameLoc; |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 425 | TemplateIdAnnotation *TemplateId = 0; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 426 | if (Tok.is(tok::identifier)) { |
| 427 | Name = Tok.getIdentifierInfo(); |
| 428 | NameLoc = ConsumeToken(); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 429 | } else if (Tok.is(tok::annot_template_id)) { |
| 430 | TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
| 431 | NameLoc = ConsumeToken(); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 432 | |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 433 | if (TemplateId->Kind != TNK_Type_template) { |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 434 | // The template-name in the simple-template-id refers to |
| 435 | // something other than a class template. Give an appropriate |
| 436 | // error message and skip to the ';'. |
| 437 | SourceRange Range(NameLoc); |
| 438 | if (SS.isNotEmpty()) |
| 439 | Range.setBegin(SS.getBeginLoc()); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 440 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 441 | Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) |
| 442 | << Name << static_cast<int>(TemplateId->Kind) << Range; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 443 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 444 | DS.SetTypeSpecError(); |
| 445 | SkipUntil(tok::semi, false, true); |
| 446 | TemplateId->Destroy(); |
| 447 | return; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 448 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // There are three options here. If we have 'struct foo;', then |
| 452 | // this is a forward declaration. If we have 'struct foo {...' or |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 453 | // 'struct foo :...' then this is a definition. Otherwise we have |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 454 | // something like 'struct foo xyz', a reference. |
| 455 | Action::TagKind TK; |
| 456 | if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon))) |
| 457 | TK = Action::TK_Definition; |
Anders Carlsson | 5dc2af1 | 2009-05-11 22:25:03 +0000 | [diff] [blame] | 458 | else if (Tok.is(tok::semi) && !DS.isFriendSpecified()) |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 459 | TK = Action::TK_Declaration; |
| 460 | else |
| 461 | TK = Action::TK_Reference; |
| 462 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 463 | if (!Name && !TemplateId && TK != Action::TK_Definition) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 464 | // We have a declaration or reference to an anonymous class. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 465 | Diag(StartLoc, diag::err_anon_type_definition) |
| 466 | << DeclSpec::getSpecifierName(TagType); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 467 | |
| 468 | // Skip the rest of this declarator, up until the comma or semicolon. |
| 469 | SkipUntil(tok::comma, true); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 470 | |
| 471 | if (TemplateId) |
| 472 | TemplateId->Destroy(); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 476 | // Create the tag portion of the class or class template. |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 477 | Action::DeclResult TagOrTempResult; |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 478 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 479 | |
| 480 | // FIXME: When TK == TK_Reference and we have a template-id, we need |
| 481 | // to turn that template-id into a type. |
| 482 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 483 | if (TemplateId && TK != Action::TK_Reference) { |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 484 | // Explicit specialization, class template partial specialization, |
| 485 | // or explicit instantiation. |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 486 | ASTTemplateArgsPtr TemplateArgsPtr(Actions, |
| 487 | TemplateId->getTemplateArgs(), |
| 488 | TemplateId->getTemplateArgIsType(), |
| 489 | TemplateId->NumArgs); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 490 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
| 491 | TK == Action::TK_Declaration) { |
| 492 | // This is an explicit instantiation of a class template. |
| 493 | TagOrTempResult |
| 494 | = Actions.ActOnExplicitInstantiation(CurScope, |
| 495 | TemplateInfo.TemplateLoc, |
| 496 | TagType, |
| 497 | StartLoc, |
| 498 | SS, |
| 499 | TemplateTy::make(TemplateId->Template), |
| 500 | TemplateId->TemplateNameLoc, |
| 501 | TemplateId->LAngleLoc, |
| 502 | TemplateArgsPtr, |
| 503 | TemplateId->getTemplateArgLocations(), |
| 504 | TemplateId->RAngleLoc, |
| 505 | Attr); |
| 506 | } else { |
| 507 | // This is an explicit specialization or a class template |
| 508 | // partial specialization. |
| 509 | TemplateParameterLists FakedParamLists; |
| 510 | |
| 511 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 512 | // This looks like an explicit instantiation, because we have |
| 513 | // something like |
| 514 | // |
| 515 | // template class Foo<X> |
| 516 | // |
| 517 | // but it is actually a declaration. Most likely, this was |
| 518 | // meant to be an explicit specialization, but the user forgot |
| 519 | // the '<>' after 'template'. |
| 520 | assert(TK == Action::TK_Definition && "Can only get a definition here"); |
| 521 | |
| 522 | SourceLocation LAngleLoc |
| 523 | = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
| 524 | Diag(TemplateId->TemplateNameLoc, |
| 525 | diag::err_explicit_instantiation_with_definition) |
| 526 | << SourceRange(TemplateInfo.TemplateLoc) |
| 527 | << CodeModificationHint::CreateInsertion(LAngleLoc, "<>"); |
| 528 | |
| 529 | // Create a fake template parameter list that contains only |
| 530 | // "template<>", so that we treat this construct as a class |
| 531 | // template specialization. |
| 532 | FakedParamLists.push_back( |
| 533 | Actions.ActOnTemplateParameterList(0, SourceLocation(), |
| 534 | TemplateInfo.TemplateLoc, |
| 535 | LAngleLoc, |
| 536 | 0, 0, |
| 537 | LAngleLoc)); |
| 538 | TemplateParams = &FakedParamLists; |
| 539 | } |
| 540 | |
| 541 | // Build the class template specialization. |
| 542 | TagOrTempResult |
| 543 | = Actions.ActOnClassTemplateSpecialization(CurScope, TagType, TK, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 544 | StartLoc, SS, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 545 | TemplateTy::make(TemplateId->Template), |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 546 | TemplateId->TemplateNameLoc, |
| 547 | TemplateId->LAngleLoc, |
| 548 | TemplateArgsPtr, |
| 549 | TemplateId->getTemplateArgLocations(), |
| 550 | TemplateId->RAngleLoc, |
| 551 | Attr, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 552 | Action::MultiTemplateParamsArg(Actions, |
| 553 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 554 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 555 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 556 | TemplateId->Destroy(); |
| 557 | } else if (TemplateParams && TK != Action::TK_Reference) |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 558 | TagOrTempResult = Actions.ActOnClassTemplate(CurScope, TagType, TK, |
| 559 | StartLoc, SS, Name, NameLoc, |
| 560 | Attr, |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 561 | Action::MultiTemplateParamsArg(Actions, |
| 562 | &(*TemplateParams)[0], |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 563 | TemplateParams->size()), |
| 564 | AS); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 565 | else |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 566 | TagOrTempResult = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, SS, Name, |
Douglas Gregor | 06c0fec | 2009-03-25 22:00:53 +0000 | [diff] [blame] | 567 | NameLoc, Attr, AS); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 568 | |
| 569 | // Parse the optional base clause (C++ only). |
Chris Lattner | 22bd905 | 2009-02-16 22:07:16 +0000 | [diff] [blame] | 570 | if (getLang().CPlusPlus && Tok.is(tok::colon)) |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 571 | ParseBaseClause(TagOrTempResult.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 572 | |
| 573 | // If there is a body, parse it and inform the actions module. |
| 574 | if (Tok.is(tok::l_brace)) |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 575 | if (getLang().CPlusPlus) |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 576 | ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get()); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 577 | else |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 578 | ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 579 | else if (TK == Action::TK_Definition) { |
| 580 | // FIXME: Complain that we have a base-specifier list but no |
| 581 | // definition. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 582 | Diag(Tok, diag::err_expected_lbrace); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | const char *PrevSpec = 0; |
Anders Carlsson | 66e9977 | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 586 | if (TagOrTempResult.isInvalid()) { |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 587 | DS.SetTypeSpecError(); |
Anders Carlsson | 66e9977 | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 588 | return; |
| 589 | } |
| 590 | |
Anders Carlsson | 66e9977 | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 591 | if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, |
| 592 | TagOrTempResult.get().getAs<void>())) |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 593 | Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; |
Anders Carlsson | d4f551b | 2009-05-11 22:42:30 +0000 | [diff] [blame] | 594 | |
| 595 | if (DS.isFriendSpecified()) |
| 596 | Actions.ActOnFriendDecl(CurScope, DS.getFriendSpecLoc(), |
| 597 | TagOrTempResult.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. |
| 601 | /// |
| 602 | /// base-clause : [C++ class.derived] |
| 603 | /// ':' base-specifier-list |
| 604 | /// base-specifier-list: |
| 605 | /// base-specifier '...'[opt] |
| 606 | /// base-specifier-list ',' base-specifier '...'[opt] |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 607 | void Parser::ParseBaseClause(DeclPtrTy ClassDecl) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 608 | assert(Tok.is(tok::colon) && "Not a base clause"); |
| 609 | ConsumeToken(); |
| 610 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 611 | // Build up an array of parsed base specifiers. |
| 612 | llvm::SmallVector<BaseTy *, 8> BaseInfo; |
| 613 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 614 | while (true) { |
| 615 | // Parse a base-specifier. |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 616 | BaseResult Result = ParseBaseSpecifier(ClassDecl); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 617 | if (Result.isInvalid()) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 618 | // Skip the rest of this base specifier, up until the comma or |
| 619 | // opening brace. |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 620 | SkipUntil(tok::comma, tok::l_brace, true, true); |
| 621 | } else { |
| 622 | // Add this to our array of base specifiers. |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 623 | BaseInfo.push_back(Result.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | // If the next token is a comma, consume it and keep reading |
| 627 | // base-specifiers. |
| 628 | if (Tok.isNot(tok::comma)) break; |
| 629 | |
| 630 | // Consume the comma. |
| 631 | ConsumeToken(); |
| 632 | } |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 633 | |
| 634 | // Attach the base specifiers |
| 635 | Actions.ActOnBaseSpecifiers(ClassDecl, &BaseInfo[0], BaseInfo.size()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is |
| 639 | /// one entry in the base class list of a class specifier, for example: |
| 640 | /// class foo : public bar, virtual private baz { |
| 641 | /// 'public bar' and 'virtual private baz' are each base-specifiers. |
| 642 | /// |
| 643 | /// base-specifier: [C++ class.derived] |
| 644 | /// ::[opt] nested-name-specifier[opt] class-name |
| 645 | /// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt] |
| 646 | /// class-name |
| 647 | /// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] |
| 648 | /// class-name |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 649 | Parser::BaseResult Parser::ParseBaseSpecifier(DeclPtrTy ClassDecl) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 650 | bool IsVirtual = false; |
| 651 | SourceLocation StartLoc = Tok.getLocation(); |
| 652 | |
| 653 | // Parse the 'virtual' keyword. |
| 654 | if (Tok.is(tok::kw_virtual)) { |
| 655 | ConsumeToken(); |
| 656 | IsVirtual = true; |
| 657 | } |
| 658 | |
| 659 | // Parse an (optional) access specifier. |
| 660 | AccessSpecifier Access = getAccessSpecifierIfPresent(); |
| 661 | if (Access) |
| 662 | ConsumeToken(); |
| 663 | |
| 664 | // Parse the 'virtual' keyword (again!), in case it came after the |
| 665 | // access specifier. |
| 666 | if (Tok.is(tok::kw_virtual)) { |
| 667 | SourceLocation VirtualLoc = ConsumeToken(); |
| 668 | if (IsVirtual) { |
| 669 | // Complain about duplicate 'virtual' |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 670 | Diag(VirtualLoc, diag::err_dup_virtual) |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 671 | << CodeModificationHint::CreateRemoval(SourceRange(VirtualLoc)); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | IsVirtual = true; |
| 675 | } |
| 676 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 677 | // Parse optional '::' and optional nested-name-specifier. |
| 678 | CXXScopeSpec SS; |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 679 | ParseOptionalCXXScopeSpecifier(SS); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 680 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 681 | // The location of the base class itself. |
| 682 | SourceLocation BaseLoc = Tok.getLocation(); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 683 | |
| 684 | // Parse the class-name. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 685 | SourceLocation EndLocation; |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 686 | TypeResult BaseType = ParseClassName(EndLocation, &SS); |
| 687 | if (BaseType.isInvalid()) |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 688 | return true; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 689 | |
| 690 | // Find the complete source range for the base-specifier. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 691 | SourceRange Range(StartLoc, EndLocation); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 692 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 693 | // Notify semantic analysis that we have parsed a complete |
| 694 | // base-specifier. |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 695 | return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access, |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 696 | BaseType.get(), BaseLoc); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /// getAccessSpecifierIfPresent - Determine whether the next token is |
| 700 | /// a C++ access-specifier. |
| 701 | /// |
| 702 | /// access-specifier: [C++ class.derived] |
| 703 | /// 'private' |
| 704 | /// 'protected' |
| 705 | /// 'public' |
Douglas Gregor | 1b7f898 | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 706 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 707 | { |
| 708 | switch (Tok.getKind()) { |
| 709 | default: return AS_none; |
| 710 | case tok::kw_private: return AS_private; |
| 711 | case tok::kw_protected: return AS_protected; |
| 712 | case tok::kw_public: return AS_public; |
| 713 | } |
| 714 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 715 | |
| 716 | /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. |
| 717 | /// |
| 718 | /// member-declaration: |
| 719 | /// decl-specifier-seq[opt] member-declarator-list[opt] ';' |
| 720 | /// function-definition ';'[opt] |
| 721 | /// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] |
| 722 | /// using-declaration [TODO] |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 723 | /// [C++0x] static_assert-declaration |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 724 | /// template-declaration |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 725 | /// [GNU] '__extension__' member-declaration |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 726 | /// |
| 727 | /// member-declarator-list: |
| 728 | /// member-declarator |
| 729 | /// member-declarator-list ',' member-declarator |
| 730 | /// |
| 731 | /// member-declarator: |
| 732 | /// declarator pure-specifier[opt] |
| 733 | /// declarator constant-initializer[opt] |
| 734 | /// identifier[opt] ':' constant-expression |
| 735 | /// |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 736 | /// pure-specifier: |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 737 | /// '= 0' |
| 738 | /// |
| 739 | /// constant-initializer: |
| 740 | /// '=' constant-expression |
| 741 | /// |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 742 | void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 743 | // static_assert-declaration |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 744 | if (Tok.is(tok::kw_static_assert)) { |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 745 | SourceLocation DeclEnd; |
| 746 | ParseStaticAssertDeclaration(DeclEnd); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 747 | return; |
| 748 | } |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 749 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 750 | if (Tok.is(tok::kw_template)) { |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 751 | SourceLocation DeclEnd; |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 752 | ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, |
| 753 | AS); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 754 | return; |
| 755 | } |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 756 | |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 757 | // Handle: member-declaration ::= '__extension__' member-declaration |
| 758 | if (Tok.is(tok::kw___extension__)) { |
| 759 | // __extension__ silences extension warnings in the subexpression. |
| 760 | ExtensionRAIIObject O(Diags); // Use RAII to do this. |
| 761 | ConsumeToken(); |
| 762 | return ParseCXXClassMemberDeclaration(AS); |
| 763 | } |
| 764 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 765 | SourceLocation DSStart = Tok.getLocation(); |
| 766 | // decl-specifier-seq: |
| 767 | // Parse the common declaration-specifiers piece. |
| 768 | DeclSpec DS; |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame^] | 769 | ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 770 | |
| 771 | if (Tok.is(tok::semi)) { |
| 772 | ConsumeToken(); |
| 773 | // C++ 9.2p7: The member-declarator-list can be omitted only after a |
| 774 | // class-specifier or an enum-specifier or in a friend declaration. |
| 775 | // FIXME: Friend declarations. |
| 776 | switch (DS.getTypeSpecType()) { |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 777 | case DeclSpec::TST_struct: |
| 778 | case DeclSpec::TST_union: |
| 779 | case DeclSpec::TST_class: |
| 780 | case DeclSpec::TST_enum: |
| 781 | Actions.ParsedFreeStandingDeclSpec(CurScope, DS); |
| 782 | return; |
| 783 | default: |
| 784 | Diag(DSStart, diag::err_no_declarators); |
| 785 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 786 | } |
| 787 | } |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 788 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 789 | Declarator DeclaratorInfo(DS, Declarator::MemberContext); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 790 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 791 | if (Tok.isNot(tok::colon)) { |
| 792 | // Parse the first declarator. |
| 793 | ParseDeclarator(DeclaratorInfo); |
| 794 | // Error parsing the declarator? |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 795 | if (!DeclaratorInfo.hasName()) { |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 796 | // If so, skip until the semi-colon or a }. |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 797 | SkipUntil(tok::r_brace, true); |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 798 | if (Tok.is(tok::semi)) |
| 799 | ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 800 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 803 | // function-definition: |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 804 | if (Tok.is(tok::l_brace) |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 805 | || (DeclaratorInfo.isFunctionDeclarator() && |
| 806 | (Tok.is(tok::colon) || Tok.is(tok::kw_try)))) { |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 807 | if (!DeclaratorInfo.isFunctionDeclarator()) { |
| 808 | Diag(Tok, diag::err_func_def_no_params); |
| 809 | ConsumeBrace(); |
| 810 | SkipUntil(tok::r_brace, true); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 811 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 812 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 813 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 814 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 815 | Diag(Tok, diag::err_function_declared_typedef); |
| 816 | // This recovery skips the entire function body. It would be nice |
| 817 | // to simply call ParseCXXInlineMethodDef() below, however Sema |
| 818 | // assumes the declarator represents a function, not a typedef. |
| 819 | ConsumeBrace(); |
| 820 | SkipUntil(tok::r_brace, true); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 821 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 824 | ParseCXXInlineMethodDef(AS, DeclaratorInfo); |
| 825 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 826 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | // member-declarator-list: |
| 830 | // member-declarator |
| 831 | // member-declarator-list ',' member-declarator |
| 832 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 833 | llvm::SmallVector<DeclPtrTy, 8> DeclsInGroup; |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 834 | OwningExprResult BitfieldSize(Actions); |
| 835 | OwningExprResult Init(Actions); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 836 | bool Deleted = false; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 837 | |
| 838 | while (1) { |
| 839 | |
| 840 | // member-declarator: |
| 841 | // declarator pure-specifier[opt] |
| 842 | // declarator constant-initializer[opt] |
| 843 | // identifier[opt] ':' constant-expression |
| 844 | |
| 845 | if (Tok.is(tok::colon)) { |
| 846 | ConsumeToken(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 847 | BitfieldSize = ParseConstantExpression(); |
| 848 | if (BitfieldSize.isInvalid()) |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 849 | SkipUntil(tok::comma, true, true); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | // pure-specifier: |
| 853 | // '= 0' |
| 854 | // |
| 855 | // constant-initializer: |
| 856 | // '=' constant-expression |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 857 | // |
| 858 | // defaulted/deleted function-definition: |
| 859 | // '=' 'default' [TODO] |
| 860 | // '=' 'delete' |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 861 | |
| 862 | if (Tok.is(tok::equal)) { |
| 863 | ConsumeToken(); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 864 | if (getLang().CPlusPlus0x && Tok.is(tok::kw_delete)) { |
| 865 | ConsumeToken(); |
| 866 | Deleted = true; |
| 867 | } else { |
| 868 | Init = ParseInitializer(); |
| 869 | if (Init.isInvalid()) |
| 870 | SkipUntil(tok::comma, true, true); |
| 871 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | // If attributes exist after the declarator, parse them. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 875 | if (Tok.is(tok::kw___attribute)) { |
| 876 | SourceLocation Loc; |
| 877 | AttributeList *AttrList = ParseAttributes(&Loc); |
| 878 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 879 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 880 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 881 | // NOTE: If Sema is the Action module and declarator is an instance field, |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 882 | // this call will *not* return the created decl; It will return null. |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 883 | // See Sema::ActOnCXXMemberDeclarator for details. |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 884 | DeclPtrTy ThisDecl = Actions.ActOnCXXMemberDeclarator(CurScope, AS, |
| 885 | DeclaratorInfo, |
| 886 | BitfieldSize.release(), |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 887 | Init.release(), |
| 888 | Deleted); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 889 | if (ThisDecl) |
| 890 | DeclsInGroup.push_back(ThisDecl); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 891 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 892 | if (DeclaratorInfo.isFunctionDeclarator() && |
| 893 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() |
| 894 | != DeclSpec::SCS_typedef) { |
| 895 | // We just declared a member function. If this member function |
| 896 | // has any default arguments, we'll need to parse them later. |
| 897 | LateParsedMethodDeclaration *LateMethod = 0; |
| 898 | DeclaratorChunk::FunctionTypeInfo &FTI |
| 899 | = DeclaratorInfo.getTypeObject(0).Fun; |
| 900 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { |
| 901 | if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { |
| 902 | if (!LateMethod) { |
| 903 | // Push this method onto the stack of late-parsed method |
| 904 | // declarations. |
| 905 | getCurTopClassStack().MethodDecls.push_back( |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 906 | LateParsedMethodDeclaration(ThisDecl)); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 907 | LateMethod = &getCurTopClassStack().MethodDecls.back(); |
| 908 | |
| 909 | // Add all of the parameters prior to this one (they don't |
| 910 | // have default arguments). |
| 911 | LateMethod->DefaultArgs.reserve(FTI.NumArgs); |
| 912 | for (unsigned I = 0; I < ParamIdx; ++I) |
| 913 | LateMethod->DefaultArgs.push_back( |
| 914 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param)); |
| 915 | } |
| 916 | |
| 917 | // Add this parameter to the list of parameters (it or may |
| 918 | // not have a default argument). |
| 919 | LateMethod->DefaultArgs.push_back( |
| 920 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, |
| 921 | FTI.ArgInfo[ParamIdx].DefaultArgTokens)); |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 926 | // If we don't have a comma, it is either the end of the list (a ';') |
| 927 | // or an error, bail out. |
| 928 | if (Tok.isNot(tok::comma)) |
| 929 | break; |
| 930 | |
| 931 | // Consume the comma. |
| 932 | ConsumeToken(); |
| 933 | |
| 934 | // Parse the next declarator. |
| 935 | DeclaratorInfo.clear(); |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 936 | BitfieldSize = 0; |
| 937 | Init = 0; |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 938 | Deleted = false; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 939 | |
| 940 | // Attributes are only allowed on the second declarator. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 941 | if (Tok.is(tok::kw___attribute)) { |
| 942 | SourceLocation Loc; |
| 943 | AttributeList *AttrList = ParseAttributes(&Loc); |
| 944 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 945 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 946 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 947 | if (Tok.isNot(tok::colon)) |
| 948 | ParseDeclarator(DeclaratorInfo); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | if (Tok.is(tok::semi)) { |
| 952 | ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 953 | Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0], |
| 954 | DeclsInGroup.size()); |
| 955 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 959 | // Skip to end of block or statement |
| 960 | SkipUntil(tok::r_brace, true, true); |
| 961 | if (Tok.is(tok::semi)) |
| 962 | ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 963 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | /// ParseCXXMemberSpecification - Parse the class definition. |
| 967 | /// |
| 968 | /// member-specification: |
| 969 | /// member-declaration member-specification[opt] |
| 970 | /// access-specifier ':' member-specification[opt] |
| 971 | /// |
| 972 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 973 | unsigned TagType, DeclPtrTy TagDecl) { |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 974 | assert((TagType == DeclSpec::TST_struct || |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 975 | TagType == DeclSpec::TST_union || |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 976 | TagType == DeclSpec::TST_class) && "Invalid TagType!"); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 977 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 978 | PrettyStackTraceActionsDecl CrashInfo(TagDecl, RecordLoc, Actions, |
| 979 | PP.getSourceManager(), |
| 980 | "parsing struct/union/class body"); |
Chris Lattner | 27b7f10 | 2009-03-05 02:25:03 +0000 | [diff] [blame] | 981 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 982 | SourceLocation LBraceLoc = ConsumeBrace(); |
| 983 | |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 984 | if (!CurScope->isClassScope() && // Not about to define a nested class. |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 985 | CurScope->isInCXXInlineMethodScope()) { |
| 986 | // We will define a local class of an inline method. |
| 987 | // Push a new LexedMethodsForTopClass for its inline methods. |
| 988 | PushTopClassStack(); |
| 989 | } |
| 990 | |
| 991 | // Enter a scope for the class. |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 992 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 993 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 994 | if (TagDecl) |
| 995 | Actions.ActOnTagStartDefinition(CurScope, TagDecl); |
| 996 | else { |
| 997 | SkipUntil(tok::r_brace, false, false); |
| 998 | return; |
| 999 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1000 | |
| 1001 | // C++ 11p3: Members of a class defined with the keyword class are private |
| 1002 | // by default. Members of a class defined with the keywords struct or union |
| 1003 | // are public by default. |
| 1004 | AccessSpecifier CurAS; |
| 1005 | if (TagType == DeclSpec::TST_class) |
| 1006 | CurAS = AS_private; |
| 1007 | else |
| 1008 | CurAS = AS_public; |
| 1009 | |
| 1010 | // While we still have something to read, read the member-declarations. |
| 1011 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
| 1012 | // Each iteration of this loop reads one member-declaration. |
| 1013 | |
| 1014 | // Check for extraneous top-level semicolon. |
| 1015 | if (Tok.is(tok::semi)) { |
| 1016 | Diag(Tok, diag::ext_extra_struct_semi); |
| 1017 | ConsumeToken(); |
| 1018 | continue; |
| 1019 | } |
| 1020 | |
| 1021 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 1022 | if (AS != AS_none) { |
| 1023 | // Current token is a C++ access specifier. |
| 1024 | CurAS = AS; |
| 1025 | ConsumeToken(); |
| 1026 | ExpectAndConsume(tok::colon, diag::err_expected_colon); |
| 1027 | continue; |
| 1028 | } |
| 1029 | |
| 1030 | // Parse all the comma separated declarators. |
| 1031 | ParseCXXClassMemberDeclaration(CurAS); |
| 1032 | } |
| 1033 | |
| 1034 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
| 1035 | |
| 1036 | AttributeList *AttrList = 0; |
| 1037 | // If attributes exist after class contents, parse them. |
| 1038 | if (Tok.is(tok::kw___attribute)) |
| 1039 | AttrList = ParseAttributes(); // FIXME: where should I put them? |
| 1040 | |
| 1041 | Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl, |
| 1042 | LBraceLoc, RBraceLoc); |
| 1043 | |
| 1044 | // C++ 9.2p2: Within the class member-specification, the class is regarded as |
| 1045 | // complete within function bodies, default arguments, |
| 1046 | // exception-specifications, and constructor ctor-initializers (including |
| 1047 | // such things in nested classes). |
| 1048 | // |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1049 | // FIXME: Only function bodies and constructor ctor-initializers are |
| 1050 | // parsed correctly, fix the rest. |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 1051 | if (!CurScope->getParent()->isClassScope()) { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1052 | // We are not inside a nested class. This class and its nested classes |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1053 | // are complete and we can parse the delayed portions of method |
| 1054 | // declarations and the lexed inline method definitions. |
| 1055 | ParseLexedMethodDeclarations(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1056 | ParseLexedMethodDefs(); |
| 1057 | |
| 1058 | // For a local class of inline method, pop the LexedMethodsForTopClass that |
| 1059 | // was previously pushed. |
| 1060 | |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1061 | assert((CurScope->isInCXXInlineMethodScope() || |
| 1062 | TopClassStacks.size() == 1) && |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1063 | "MethodLexers not getting popped properly!"); |
| 1064 | if (CurScope->isInCXXInlineMethodScope()) |
| 1065 | PopTopClassStack(); |
| 1066 | } |
| 1067 | |
| 1068 | // Leave the class scope. |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1069 | ClassScope.Exit(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1070 | |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 1071 | Actions.ActOnTagFinishDefinition(CurScope, TagDecl); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1072 | } |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1073 | |
| 1074 | /// ParseConstructorInitializer - Parse a C++ constructor initializer, |
| 1075 | /// which explicitly initializes the members or base classes of a |
| 1076 | /// class (C++ [class.base.init]). For example, the three initializers |
| 1077 | /// after the ':' in the Derived constructor below: |
| 1078 | /// |
| 1079 | /// @code |
| 1080 | /// class Base { }; |
| 1081 | /// class Derived : Base { |
| 1082 | /// int x; |
| 1083 | /// float f; |
| 1084 | /// public: |
| 1085 | /// Derived(float f) : Base(), x(17), f(f) { } |
| 1086 | /// }; |
| 1087 | /// @endcode |
| 1088 | /// |
| 1089 | /// [C++] ctor-initializer: |
| 1090 | /// ':' mem-initializer-list |
| 1091 | /// |
| 1092 | /// [C++] mem-initializer-list: |
| 1093 | /// mem-initializer |
| 1094 | /// mem-initializer , mem-initializer-list |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1095 | void Parser::ParseConstructorInitializer(DeclPtrTy ConstructorDecl) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1096 | assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); |
| 1097 | |
| 1098 | SourceLocation ColonLoc = ConsumeToken(); |
| 1099 | |
| 1100 | llvm::SmallVector<MemInitTy*, 4> MemInitializers; |
| 1101 | |
| 1102 | do { |
| 1103 | MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1104 | if (!MemInit.isInvalid()) |
| 1105 | MemInitializers.push_back(MemInit.get()); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1106 | |
| 1107 | if (Tok.is(tok::comma)) |
| 1108 | ConsumeToken(); |
| 1109 | else if (Tok.is(tok::l_brace)) |
| 1110 | break; |
| 1111 | else { |
| 1112 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 1113 | Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1114 | SkipUntil(tok::l_brace, true, true); |
| 1115 | break; |
| 1116 | } |
| 1117 | } while (true); |
| 1118 | |
| 1119 | Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, |
| 1120 | &MemInitializers[0], MemInitializers.size()); |
| 1121 | } |
| 1122 | |
| 1123 | /// ParseMemInitializer - Parse a C++ member initializer, which is |
| 1124 | /// part of a constructor initializer that explicitly initializes one |
| 1125 | /// member or base class (C++ [class.base.init]). See |
| 1126 | /// ParseConstructorInitializer for an example. |
| 1127 | /// |
| 1128 | /// [C++] mem-initializer: |
| 1129 | /// mem-initializer-id '(' expression-list[opt] ')' |
| 1130 | /// |
| 1131 | /// [C++] mem-initializer-id: |
| 1132 | /// '::'[opt] nested-name-specifier[opt] class-name |
| 1133 | /// identifier |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1134 | Parser::MemInitResult Parser::ParseMemInitializer(DeclPtrTy ConstructorDecl) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1135 | // FIXME: parse '::'[opt] nested-name-specifier[opt] |
| 1136 | |
| 1137 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1138 | Diag(Tok, diag::err_expected_member_or_base_name); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1139 | return true; |
| 1140 | } |
| 1141 | |
| 1142 | // Get the identifier. This may be a member name or a class name, |
| 1143 | // but we'll let the semantic analysis determine which it is. |
| 1144 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1145 | SourceLocation IdLoc = ConsumeToken(); |
| 1146 | |
| 1147 | // Parse the '('. |
| 1148 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1149 | Diag(Tok, diag::err_expected_lparen); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1150 | return true; |
| 1151 | } |
| 1152 | SourceLocation LParenLoc = ConsumeParen(); |
| 1153 | |
| 1154 | // Parse the optional expression-list. |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1155 | ExprVector ArgExprs(Actions); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1156 | CommaLocsTy CommaLocs; |
| 1157 | if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { |
| 1158 | SkipUntil(tok::r_paren); |
| 1159 | return true; |
| 1160 | } |
| 1161 | |
| 1162 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 1163 | |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1164 | return Actions.ActOnMemInitializer(ConstructorDecl, CurScope, II, IdLoc, |
| 1165 | LParenLoc, ArgExprs.take(), |
| 1166 | ArgExprs.size(), &CommaLocs[0], RParenLoc); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1167 | } |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1168 | |
| 1169 | /// ParseExceptionSpecification - Parse a C++ exception-specification |
| 1170 | /// (C++ [except.spec]). |
| 1171 | /// |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1172 | /// exception-specification: |
| 1173 | /// 'throw' '(' type-id-list [opt] ')' |
| 1174 | /// [MS] 'throw' '(' '...' ')' |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1175 | /// |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1176 | /// type-id-list: |
| 1177 | /// type-id |
| 1178 | /// type-id-list ',' type-id |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1179 | /// |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1180 | bool Parser::ParseExceptionSpecification(SourceLocation &EndLoc, |
| 1181 | std::vector<TypeTy*> &Exceptions, |
| 1182 | bool &hasAnyExceptionSpec) { |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1183 | assert(Tok.is(tok::kw_throw) && "expected throw"); |
| 1184 | |
| 1185 | SourceLocation ThrowLoc = ConsumeToken(); |
| 1186 | |
| 1187 | if (!Tok.is(tok::l_paren)) { |
| 1188 | return Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 1189 | } |
| 1190 | SourceLocation LParenLoc = ConsumeParen(); |
| 1191 | |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1192 | // Parse throw(...), a Microsoft extension that means "this function |
| 1193 | // can throw anything". |
| 1194 | if (Tok.is(tok::ellipsis)) { |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1195 | hasAnyExceptionSpec = true; |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1196 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 1197 | if (!getLang().Microsoft) |
| 1198 | Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1199 | EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1200 | return false; |
| 1201 | } |
| 1202 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1203 | // Parse the sequence of type-ids. |
| 1204 | while (Tok.isNot(tok::r_paren)) { |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1205 | TypeResult Res(ParseTypeName()); |
| 1206 | if (!Res.isInvalid()) |
| 1207 | Exceptions.push_back(Res.get()); |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1208 | if (Tok.is(tok::comma)) |
| 1209 | ConsumeToken(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1210 | else |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1211 | break; |
| 1212 | } |
| 1213 | |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1214 | EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1215 | return false; |
| 1216 | } |