Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 1 | //===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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 | a523517 | 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 | |
Anders Carlsson | 74d7f0d | 2009-06-27 00:27:47 +0000 | [diff] [blame] | 14 | #include "clang/Basic/OperatorKinds.h" |
Douglas Gregor | 423984d | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
Chris Lattner | 60f3622 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 16 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/DeclSpec.h" |
| 18 | #include "clang/Sema/Scope.h" |
| 19 | #include "clang/Sema/ParsedTemplate.h" |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 20 | #include "clang/Sema/PrettyDeclStackTrace.h" |
Chris Lattner | 8a9a97a | 2009-12-10 00:21:05 +0000 | [diff] [blame] | 21 | #include "RAIIObjectsForParser.h" |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
| 24 | /// ParseNamespace - We know that the current token is a namespace keyword. This |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 25 | /// may either be a top level namespace or a block-level namespace alias. If |
| 26 | /// there was an inline keyword, it has already been parsed. |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 27 | /// |
| 28 | /// namespace-definition: [C++ 7.3: basic.namespace] |
| 29 | /// named-namespace-definition |
| 30 | /// unnamed-namespace-definition |
| 31 | /// |
| 32 | /// unnamed-namespace-definition: |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 33 | /// 'inline'[opt] 'namespace' attributes[opt] '{' namespace-body '}' |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 34 | /// |
| 35 | /// named-namespace-definition: |
| 36 | /// original-namespace-definition |
| 37 | /// extension-namespace-definition |
| 38 | /// |
| 39 | /// original-namespace-definition: |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 40 | /// 'inline'[opt] 'namespace' identifier attributes[opt] |
| 41 | /// '{' namespace-body '}' |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 42 | /// |
| 43 | /// extension-namespace-definition: |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 44 | /// 'inline'[opt] 'namespace' original-namespace-name |
| 45 | /// '{' namespace-body '}' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 46 | /// |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 47 | /// namespace-alias-definition: [C++ 7.3.2: namespace.alias] |
| 48 | /// 'namespace' identifier '=' qualified-namespace-specifier ';' |
| 49 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 50 | Decl *Parser::ParseNamespace(unsigned Context, |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 51 | SourceLocation &DeclEnd, |
| 52 | SourceLocation InlineLoc) { |
Chris Lattner | 76c7228 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 53 | assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 54 | SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 56 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 57 | Actions.CodeCompleteNamespaceDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 58 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 59 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 60 | |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 61 | SourceLocation IdentLoc; |
| 62 | IdentifierInfo *Ident = 0; |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 63 | |
| 64 | Token attrTok; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | |
Chris Lattner | 76c7228 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 66 | if (Tok.is(tok::identifier)) { |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 67 | Ident = Tok.getIdentifierInfo(); |
| 68 | IdentLoc = ConsumeToken(); // eat the identifier. |
| 69 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 70 | |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 71 | // Read label attributes, if present. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 72 | ParsedAttributes attrs(AttrFactory); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 73 | if (Tok.is(tok::kw___attribute)) { |
| 74 | attrTok = Tok; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 75 | ParseGNUAttributes(attrs); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 76 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 78 | if (Tok.is(tok::equal)) { |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 79 | if (!attrs.empty()) |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 80 | Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); |
Sebastian Redl | 6766794 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 81 | if (InlineLoc.isValid()) |
| 82 | Diag(InlineLoc, diag::err_inline_namespace_alias) |
| 83 | << FixItHint::CreateRemoval(InlineLoc); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 85 | return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); |
Douglas Gregor | 6b6bba4 | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 86 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 88 | if (Tok.isNot(tok::l_brace)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | Diag(Tok, Ident ? diag::err_expected_lbrace : |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 90 | diag::err_expected_ident_lbrace); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 91 | return 0; |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 92 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 94 | SourceLocation LBrace = ConsumeBrace(); |
| 95 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 96 | if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || |
| 97 | getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() || |
| 98 | getCurScope()->getFnParent()) { |
Douglas Gregor | 05cfc29 | 2010-05-14 05:08:22 +0000 | [diff] [blame] | 99 | Diag(LBrace, diag::err_namespace_nonnamespace_scope); |
| 100 | SkipUntil(tok::r_brace, false); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 101 | return 0; |
Douglas Gregor | 05cfc29 | 2010-05-14 05:08:22 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Sebastian Redl | 5a5f2c7 | 2010-08-31 00:36:45 +0000 | [diff] [blame] | 104 | // If we're still good, complain about inline namespaces in non-C++0x now. |
| 105 | if (!getLang().CPlusPlus0x && InlineLoc.isValid()) |
| 106 | Diag(InlineLoc, diag::ext_inline_namespace); |
| 107 | |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 108 | // Enter a scope for the namespace. |
| 109 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 110 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 111 | Decl *NamespcDecl = |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 112 | Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc, |
| 113 | IdentLoc, Ident, LBrace, attrs.getList()); |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 114 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 115 | PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc, |
| 116 | "parsing namespace"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 118 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 119 | ParsedAttributesWithRange attrs(AttrFactory); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 120 | MaybeParseCXX0XAttributes(attrs); |
| 121 | MaybeParseMicrosoftAttributes(attrs); |
| 122 | ParseExternalDeclaration(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 123 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 125 | // Leave the namespace scope. |
| 126 | NamespaceScope.Exit(); |
| 127 | |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 128 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace); |
| 129 | Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 130 | |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 131 | DeclEnd = RBraceLoc; |
Chris Lattner | 4de55aa | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 132 | return NamespcDecl; |
Chris Lattner | a523517 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 133 | } |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 134 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 135 | /// ParseNamespaceAlias - Parse the part after the '=' in a namespace |
| 136 | /// alias definition. |
| 137 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 138 | Decl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 139 | SourceLocation AliasLoc, |
| 140 | IdentifierInfo *Alias, |
| 141 | SourceLocation &DeclEnd) { |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 142 | assert(Tok.is(tok::equal) && "Not equal token"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 144 | ConsumeToken(); // eat the '='. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 146 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 147 | Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 148 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 149 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 150 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 151 | CXXScopeSpec SS; |
| 152 | // Parse (optional) nested-name-specifier. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 153 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 154 | |
| 155 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
| 156 | Diag(Tok, diag::err_expected_namespace_name); |
| 157 | // Skip to end of the definition and eat the ';'. |
| 158 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 159 | return 0; |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | // Parse identifier. |
Anders Carlsson | 47952ae | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 163 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 164 | SourceLocation IdentLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 165 | |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 166 | // Eat the ';'. |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 167 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 34a9566 | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 168 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name, |
| 169 | "", tok::semi); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 171 | return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias, |
Anders Carlsson | 47952ae | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 172 | SS, IdentLoc, Ident); |
Anders Carlsson | 1894f0d4 | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 175 | /// ParseLinkage - We know that the current token is a string_literal |
| 176 | /// and just before that, that extern was seen. |
| 177 | /// |
| 178 | /// linkage-specification: [C++ 7.5p2: dcl.link] |
| 179 | /// 'extern' string-literal '{' declaration-seq[opt] '}' |
| 180 | /// 'extern' string-literal declaration |
| 181 | /// |
Chris Lattner | 8ea6442 | 2010-11-09 20:15:55 +0000 | [diff] [blame] | 182 | Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { |
Douglas Gregor | 15799fd | 2008-11-21 16:10:08 +0000 | [diff] [blame] | 183 | assert(Tok.is(tok::string_literal) && "Not a string literal!"); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 184 | llvm::SmallString<8> LangBuffer; |
Douglas Gregor | dc970f0 | 2010-03-16 22:30:13 +0000 | [diff] [blame] | 185 | bool Invalid = false; |
| 186 | llvm::StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid); |
| 187 | if (Invalid) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 188 | return 0; |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 189 | |
| 190 | SourceLocation Loc = ConsumeStringToken(); |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 191 | |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 192 | ParseScope LinkageScope(this, Scope::DeclScope); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 193 | Decl *LinkageSpec |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 194 | = Actions.ActOnStartLinkageSpecification(getCurScope(), |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 195 | DS.getSourceRange().getBegin(), |
Benjamin Kramer | bebee84 | 2010-05-03 13:08:54 +0000 | [diff] [blame] | 196 | Loc, Lang, |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 197 | Tok.is(tok::l_brace) ? Tok.getLocation() |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 198 | : SourceLocation()); |
| 199 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 200 | ParsedAttributesWithRange attrs(AttrFactory); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 201 | MaybeParseCXX0XAttributes(attrs); |
| 202 | MaybeParseMicrosoftAttributes(attrs); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 203 | |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 204 | if (Tok.isNot(tok::l_brace)) { |
Abramo Bagnara | 4d42399 | 2011-05-01 16:25:54 +0000 | [diff] [blame] | 205 | // Reset the source range in DS, as the leading "extern" |
| 206 | // does not really belong to the inner declaration ... |
| 207 | DS.SetRangeStart(SourceLocation()); |
| 208 | DS.SetRangeEnd(SourceLocation()); |
| 209 | // ... but anyway remember that such an "extern" was seen. |
Abramo Bagnara | ed5b689 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 210 | DS.setExternInLinkageSpec(true); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 211 | ParseExternalDeclaration(attrs, &DS); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 212 | return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, |
Douglas Gregor | 07665a6 | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 213 | SourceLocation()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 214 | } |
Douglas Gregor | 29ff7d0 | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 215 | |
Douglas Gregor | b65a913 | 2010-02-07 08:38:28 +0000 | [diff] [blame] | 216 | DS.abort(); |
| 217 | |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 218 | ProhibitAttributes(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 219 | |
Douglas Gregor | 29ff7d0 | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 220 | SourceLocation LBrace = ConsumeBrace(); |
Douglas Gregor | 29ff7d0 | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 221 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 222 | ParsedAttributesWithRange attrs(AttrFactory); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 223 | MaybeParseCXX0XAttributes(attrs); |
| 224 | MaybeParseMicrosoftAttributes(attrs); |
| 225 | ParseExternalDeclaration(attrs); |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Douglas Gregor | 29ff7d0 | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 228 | SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace); |
Chris Lattner | 8ea6442 | 2010-11-09 20:15:55 +0000 | [diff] [blame] | 229 | return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, |
| 230 | RBrace); |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 231 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 233 | /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or |
| 234 | /// using-directive. Assumes that current token is 'using'. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 235 | Decl *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 236 | const ParsedTemplateInfo &TemplateInfo, |
| 237 | SourceLocation &DeclEnd, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 238 | ParsedAttributesWithRange &attrs) { |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 239 | assert(Tok.is(tok::kw_using) && "Not using token"); |
| 240 | |
| 241 | // Eat 'using'. |
| 242 | SourceLocation UsingLoc = ConsumeToken(); |
| 243 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 244 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 245 | Actions.CodeCompleteUsing(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 246 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 247 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 248 | |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 249 | // 'using namespace' means this is a using-directive. |
| 250 | if (Tok.is(tok::kw_namespace)) { |
| 251 | // Template parameters are always an error here. |
| 252 | if (TemplateInfo.Kind) { |
| 253 | SourceRange R = TemplateInfo.getSourceRange(); |
| 254 | Diag(UsingLoc, diag::err_templated_using_directive) |
| 255 | << R << FixItHint::CreateRemoval(R); |
| 256 | } |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 257 | |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 258 | return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs); |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 261 | // Otherwise, it must be a using-declaration or an alias-declaration. |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 262 | |
| 263 | // Using declarations can't have attributes. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 264 | ProhibitAttributes(attrs); |
Chris Lattner | 9b01ca1 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 265 | |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 266 | return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /// ParseUsingDirective - Parse C++ using-directive, assumes |
| 270 | /// that current token is 'namespace' and 'using' was already parsed. |
| 271 | /// |
| 272 | /// using-directive: [C++ 7.3.p4: namespace.udir] |
| 273 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 274 | /// namespace-name ; |
| 275 | /// [GNU] using-directive: |
| 276 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 277 | /// namespace-name attributes[opt] ; |
| 278 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 279 | Decl *Parser::ParseUsingDirective(unsigned Context, |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 280 | SourceLocation UsingLoc, |
| 281 | SourceLocation &DeclEnd, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 282 | ParsedAttributes &attrs) { |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 283 | assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); |
| 284 | |
| 285 | // Eat 'namespace'. |
| 286 | SourceLocation NamespcLoc = ConsumeToken(); |
| 287 | |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 288 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 289 | Actions.CodeCompleteUsingDirective(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 290 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 7e90c6d | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 291 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 292 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 293 | CXXScopeSpec SS; |
| 294 | // Parse (optional) nested-name-specifier. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 295 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 296 | |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 297 | IdentifierInfo *NamespcName = 0; |
| 298 | SourceLocation IdentLoc = SourceLocation(); |
| 299 | |
| 300 | // Parse namespace-name. |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 301 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 302 | Diag(Tok, diag::err_expected_namespace_name); |
| 303 | // If there was invalid namespace name, skip to end of decl, and eat ';'. |
| 304 | SkipUntil(tok::semi); |
| 305 | // FIXME: Are there cases, when we would like to call ActOnUsingDirective? |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 306 | return 0; |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 307 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 309 | // Parse identifier. |
| 310 | NamespcName = Tok.getIdentifierInfo(); |
| 311 | IdentLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 313 | // Parse (optional) attributes (most likely GNU strong-using extension). |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 314 | bool GNUAttr = false; |
| 315 | if (Tok.is(tok::kw___attribute)) { |
| 316 | GNUAttr = true; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 317 | ParseGNUAttributes(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 318 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Chris Lattner | ce1da2c | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 320 | // Eat ';'. |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 321 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 34a9566 | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 322 | ExpectAndConsume(tok::semi, |
Douglas Gregor | 45d6bdf | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 323 | GNUAttr ? diag::err_expected_semi_after_attribute_list |
| 324 | : diag::err_expected_semi_after_namespace_name, |
| 325 | "", tok::semi); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 326 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 327 | return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 328 | IdentLoc, NamespcName, attrs.getList()); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 331 | /// ParseUsingDeclaration - Parse C++ using-declaration or alias-declaration. |
| 332 | /// Assumes that 'using' was already seen. |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 333 | /// |
| 334 | /// using-declaration: [C++ 7.3.p3: namespace.udecl] |
| 335 | /// 'using' 'typename'[opt] ::[opt] nested-name-specifier |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 336 | /// unqualified-id |
| 337 | /// 'using' :: unqualified-id |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 338 | /// |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 339 | /// alias-declaration: C++0x [decl.typedef]p2 |
| 340 | /// 'using' identifier = type-id ; |
| 341 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 342 | Decl *Parser::ParseUsingDeclaration(unsigned Context, |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 343 | const ParsedTemplateInfo &TemplateInfo, |
| 344 | SourceLocation UsingLoc, |
| 345 | SourceLocation &DeclEnd, |
| 346 | AccessSpecifier AS) { |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 347 | CXXScopeSpec SS; |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 348 | SourceLocation TypenameLoc; |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 349 | bool IsTypeName; |
| 350 | |
| 351 | // Ignore optional 'typename'. |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 352 | // FIXME: This is wrong; we should parse this as a typename-specifier. |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 353 | if (Tok.is(tok::kw_typename)) { |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 354 | TypenameLoc = Tok.getLocation(); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 355 | ConsumeToken(); |
| 356 | IsTypeName = true; |
| 357 | } |
| 358 | else |
| 359 | IsTypeName = false; |
| 360 | |
| 361 | // Parse nested-name-specifier. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 362 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 363 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 364 | // Check nested-name specifier. |
| 365 | if (SS.isInvalid()) { |
| 366 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 367 | return 0; |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 368 | } |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 369 | |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 370 | // Parse the unqualified-id. We allow parsing of both constructor and |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 371 | // destructor names and allow the action module to diagnose any semantic |
| 372 | // errors. |
| 373 | UnqualifiedId Name; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 374 | if (ParseUnqualifiedId(SS, |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 375 | /*EnteringContext=*/false, |
| 376 | /*AllowDestructorName=*/true, |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 377 | /*AllowConstructorName=*/true, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 378 | ParsedType(), |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 379 | Name)) { |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 380 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 381 | return 0; |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 382 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 383 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 384 | ParsedAttributes attrs(AttrFactory); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 385 | |
| 386 | // Maybe this is an alias-declaration. |
| 387 | bool IsAliasDecl = Tok.is(tok::equal); |
| 388 | TypeResult TypeAlias; |
| 389 | if (IsAliasDecl) { |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 390 | // TODO: Attribute support. C++0x attributes may appear before the equals. |
| 391 | // Where can GNU attributes appear? |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 392 | ConsumeToken(); |
| 393 | |
| 394 | if (!getLang().CPlusPlus0x) |
| 395 | Diag(Tok.getLocation(), diag::ext_alias_declaration); |
| 396 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 397 | // Type alias templates cannot be specialized. |
| 398 | int SpecKind = -1; |
Richard Smith | 1403402 | 2011-05-05 22:36:10 +0000 | [diff] [blame] | 399 | if (TemplateInfo.Kind == ParsedTemplateInfo::Template && |
| 400 | Name.getKind() == UnqualifiedId::IK_TemplateId) |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 401 | SpecKind = 0; |
| 402 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) |
| 403 | SpecKind = 1; |
| 404 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
| 405 | SpecKind = 2; |
| 406 | if (SpecKind != -1) { |
| 407 | SourceRange Range; |
| 408 | if (SpecKind == 0) |
| 409 | Range = SourceRange(Name.TemplateId->LAngleLoc, |
| 410 | Name.TemplateId->RAngleLoc); |
| 411 | else |
| 412 | Range = TemplateInfo.getSourceRange(); |
| 413 | Diag(Range.getBegin(), diag::err_alias_declaration_specialization) |
| 414 | << SpecKind << Range; |
| 415 | SkipUntil(tok::semi); |
| 416 | return 0; |
| 417 | } |
| 418 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 419 | // Name must be an identifier. |
| 420 | if (Name.getKind() != UnqualifiedId::IK_Identifier) { |
| 421 | Diag(Name.StartLocation, diag::err_alias_declaration_not_identifier); |
| 422 | // No removal fixit: can't recover from this. |
| 423 | SkipUntil(tok::semi); |
| 424 | return 0; |
| 425 | } else if (IsTypeName) |
| 426 | Diag(TypenameLoc, diag::err_alias_declaration_not_identifier) |
| 427 | << FixItHint::CreateRemoval(SourceRange(TypenameLoc, |
| 428 | SS.isNotEmpty() ? SS.getEndLoc() : TypenameLoc)); |
| 429 | else if (SS.isNotEmpty()) |
| 430 | Diag(SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) |
| 431 | << FixItHint::CreateRemoval(SS.getRange()); |
| 432 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 433 | TypeAlias = ParseTypeName(0, TemplateInfo.Kind ? |
| 434 | Declarator::AliasTemplateContext : |
| 435 | Declarator::AliasDeclContext); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 436 | } else |
| 437 | // Parse (optional) attributes (most likely GNU strong-using extension). |
| 438 | MaybeParseGNUAttributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 439 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 440 | // Eat ';'. |
| 441 | DeclEnd = Tok.getLocation(); |
| 442 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 443 | !attrs.empty() ? "attributes list" : |
| 444 | IsAliasDecl ? "alias declaration" : "using declaration", |
Douglas Gregor | 220f427 | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 445 | tok::semi); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 446 | |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 447 | // Diagnose an attempt to declare a templated using-declaration. |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 448 | // In C++0x, alias-declarations can be templates: |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 449 | // template <...> using id = type; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 450 | if (TemplateInfo.Kind && !IsAliasDecl) { |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 451 | SourceRange R = TemplateInfo.getSourceRange(); |
| 452 | Diag(UsingLoc, diag::err_templated_using_declaration) |
| 453 | << R << FixItHint::CreateRemoval(R); |
| 454 | |
| 455 | // Unfortunately, we have to bail out instead of recovering by |
| 456 | // ignoring the parameters, just in case the nested name specifier |
| 457 | // depends on the parameters. |
| 458 | return 0; |
| 459 | } |
| 460 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 461 | if (IsAliasDecl) { |
| 462 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 463 | MultiTemplateParamsArg TemplateParamsArg(Actions, |
| 464 | TemplateParams ? TemplateParams->data() : 0, |
| 465 | TemplateParams ? TemplateParams->size() : 0); |
| 466 | return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, |
| 467 | UsingLoc, Name, TypeAlias); |
| 468 | } |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 469 | |
Ted Kremenek | 5eec2b0 | 2010-11-10 05:59:39 +0000 | [diff] [blame] | 470 | return Actions.ActOnUsingDeclaration(getCurScope(), AS, true, UsingLoc, SS, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 471 | Name, attrs.getList(), |
| 472 | IsTypeName, TypenameLoc); |
Douglas Gregor | d7c4d98 | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 475 | /// ParseStaticAssertDeclaration - Parse C++0x or C1X static_assert-declaration. |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 476 | /// |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 477 | /// [C++0x] static_assert-declaration: |
| 478 | /// static_assert ( constant-expression , string-literal ) ; |
| 479 | /// |
| 480 | /// [C1X] static_assert-declaration: |
| 481 | /// _Static_assert ( constant-expression , string-literal ) ; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 482 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 483 | Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 484 | assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) && |
| 485 | "Not a static_assert declaration"); |
| 486 | |
| 487 | if (Tok.is(tok::kw__Static_assert) && !getLang().C1X) |
| 488 | Diag(Tok, diag::ext_c1x_static_assert); |
| 489 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 490 | SourceLocation StaticAssertLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 492 | if (Tok.isNot(tok::l_paren)) { |
| 493 | Diag(Tok, diag::err_expected_lparen); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 494 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 495 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 497 | SourceLocation LParenLoc = ConsumeParen(); |
Douglas Gregor | c9c02ed | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 498 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 499 | ExprResult AssertExpr(ParseConstantExpression()); |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 500 | if (AssertExpr.isInvalid()) { |
| 501 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 502 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 503 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Anders Carlsson | b4cf3ad | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 505 | if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 506 | return 0; |
Anders Carlsson | b4cf3ad | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 507 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 508 | if (Tok.isNot(tok::string_literal)) { |
| 509 | Diag(Tok, diag::err_expected_string_literal); |
| 510 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 511 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 512 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 513 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 514 | ExprResult AssertMessage(ParseStringLiteralExpression()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | if (AssertMessage.isInvalid()) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 516 | return 0; |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 517 | |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 518 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 520 | DeclEnd = Tok.getLocation(); |
Douglas Gregor | 45d6bdf | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 521 | ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert); |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 522 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 523 | return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, |
| 524 | AssertExpr.take(), |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 525 | AssertMessage.take(), |
| 526 | RParenLoc); |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 529 | /// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. |
| 530 | /// |
| 531 | /// 'decltype' ( expression ) |
| 532 | /// |
| 533 | void Parser::ParseDecltypeSpecifier(DeclSpec &DS) { |
| 534 | assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier"); |
| 535 | |
| 536 | SourceLocation StartLoc = ConsumeToken(); |
| 537 | SourceLocation LParenLoc = Tok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | |
| 539 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 540 | "decltype")) { |
| 541 | SkipUntil(tok::r_paren); |
| 542 | return; |
| 543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 545 | // Parse the expression |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 547 | // C++0x [dcl.type.simple]p4: |
| 548 | // The operand of the decltype specifier is an unevaluated operand. |
| 549 | EnterExpressionEvaluationContext Unevaluated(Actions, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 550 | Sema::Unevaluated); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 551 | ExprResult Result = ParseExpression(); |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 552 | if (Result.isInvalid()) { |
| 553 | SkipUntil(tok::r_paren); |
| 554 | return; |
| 555 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 556 | |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 557 | // Match the ')' |
| 558 | SourceLocation RParenLoc; |
| 559 | if (Tok.is(tok::r_paren)) |
| 560 | RParenLoc = ConsumeParen(); |
| 561 | else |
| 562 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 564 | if (RParenLoc.isInvalid()) |
| 565 | return; |
| 566 | |
| 567 | const char *PrevSpec = 0; |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 568 | unsigned DiagID; |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 569 | // Check for duplicate type specifiers (e.g. "int decltype(a)"). |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 571 | DiagID, Result.release())) |
| 572 | Diag(StartLoc, DiagID) << PrevSpec; |
Anders Carlsson | 74948d0 | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 575 | void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { |
| 576 | assert(Tok.is(tok::kw___underlying_type) && |
| 577 | "Not an underlying type specifier"); |
| 578 | |
| 579 | SourceLocation StartLoc = ConsumeToken(); |
| 580 | SourceLocation LParenLoc = Tok.getLocation(); |
| 581 | |
| 582 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
| 583 | "__underlying_type")) { |
| 584 | SkipUntil(tok::r_paren); |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | TypeResult Result = ParseTypeName(); |
| 589 | if (Result.isInvalid()) { |
| 590 | SkipUntil(tok::r_paren); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | // Match the ')' |
| 595 | SourceLocation RParenLoc; |
| 596 | if (Tok.is(tok::r_paren)) |
| 597 | RParenLoc = ConsumeParen(); |
| 598 | else |
| 599 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 600 | |
| 601 | if (RParenLoc.isInvalid()) |
| 602 | return; |
| 603 | |
| 604 | const char *PrevSpec = 0; |
| 605 | unsigned DiagID; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 606 | if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec, |
Alexis Hunt | 4a25707 | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 607 | DiagID, Result.release())) |
| 608 | Diag(StartLoc, DiagID) << PrevSpec; |
| 609 | } |
| 610 | |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 611 | /// ParseClassName - Parse a C++ class-name, which names a class. Note |
| 612 | /// that we only check that the result names a type; semantic analysis |
| 613 | /// will need to verify that the type names a class. The result is |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 614 | /// either a type or NULL, depending on whether a type name was |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 615 | /// found. |
| 616 | /// |
| 617 | /// class-name: [C++ 9.1] |
| 618 | /// identifier |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 619 | /// simple-template-id |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | /// |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 621 | Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 622 | CXXScopeSpec &SS) { |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 623 | // Check whether we have a template-id that names a type. |
| 624 | if (Tok.is(tok::annot_template_id)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | TemplateIdAnnotation *TemplateId |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 626 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
Douglas Gregor | 46c5961 | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 627 | if (TemplateId->Kind == TNK_Type_template || |
| 628 | TemplateId->Kind == TNK_Dependent_template_name) { |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 629 | AnnotateTemplateIdTokenAsType(); |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 630 | |
| 631 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 632 | ParsedType Type = getTypeAnnotation(Tok); |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 633 | EndLocation = Tok.getAnnotationEndLoc(); |
| 634 | ConsumeToken(); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 635 | |
| 636 | if (Type) |
| 637 | return Type; |
| 638 | return true; |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | // Fall through to produce an error below. |
| 642 | } |
| 643 | |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 644 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 645 | Diag(Tok, diag::err_expected_class_name); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 646 | return true; |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 649 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 650 | SourceLocation IdLoc = ConsumeToken(); |
| 651 | |
| 652 | if (Tok.is(tok::less)) { |
| 653 | // It looks the user intended to write a template-id here, but the |
| 654 | // template-name was wrong. Try to fix that. |
| 655 | TemplateNameKind TNK = TNK_Type_template; |
| 656 | TemplateTy Template; |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 657 | if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 658 | &SS, Template, TNK)) { |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 659 | Diag(IdLoc, diag::err_unknown_template_name) |
| 660 | << Id; |
| 661 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 662 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 663 | if (!Template) |
| 664 | return true; |
| 665 | |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 666 | // Form the template name |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 667 | UnqualifiedId TemplateName; |
| 668 | TemplateName.setIdentifier(Id, IdLoc); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 670 | // Parse the full template-id, then turn it into a type. |
| 671 | if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, |
| 672 | SourceLocation(), true)) |
| 673 | return true; |
| 674 | if (TNK == TNK_Dependent_template_name) |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 675 | AnnotateTemplateIdTokenAsType(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 676 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 677 | // If we didn't end up with a typename token, there's nothing more we |
| 678 | // can do. |
| 679 | if (Tok.isNot(tok::annot_typename)) |
| 680 | return true; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 682 | // Retrieve the type from the annotation token, consume that token, and |
| 683 | // return. |
| 684 | EndLocation = Tok.getAnnotationEndLoc(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 685 | ParsedType Type = getTypeAnnotation(Tok); |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 686 | ConsumeToken(); |
| 687 | return Type; |
| 688 | } |
| 689 | |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 690 | // We have an identifier; check whether it is actually a type. |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 691 | ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, true, |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 692 | false, ParsedType(), |
| 693 | /*NonTrivialTypeSourceInfo=*/true); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 694 | if (!Type) { |
Douglas Gregor | fe17d25 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 695 | Diag(IdLoc, diag::err_expected_class_name); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 696 | return true; |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | // Consume the identifier. |
Douglas Gregor | 18473f3 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 700 | EndLocation = IdLoc; |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 701 | |
| 702 | // Fake up a Declarator to use with ActOnTypeName. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 703 | DeclSpec DS(AttrFactory); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 704 | DS.SetRangeStart(IdLoc); |
| 705 | DS.SetRangeEnd(EndLocation); |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 706 | DS.getTypeSpecScope() = SS; |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 707 | |
| 708 | const char *PrevSpec = 0; |
| 709 | unsigned DiagID; |
| 710 | DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type); |
| 711 | |
| 712 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 713 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 716 | /// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or |
| 717 | /// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which |
| 718 | /// until we reach the start of a definition or see a token that |
Sebastian Redl | 2b37272 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 719 | /// cannot start a definition. If SuppressDeclarations is true, we do know. |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 720 | /// |
| 721 | /// class-specifier: [C++ class] |
| 722 | /// class-head '{' member-specification[opt] '}' |
| 723 | /// class-head '{' member-specification[opt] '}' attributes[opt] |
| 724 | /// class-head: |
| 725 | /// class-key identifier[opt] base-clause[opt] |
| 726 | /// class-key nested-name-specifier identifier base-clause[opt] |
| 727 | /// class-key nested-name-specifier[opt] simple-template-id |
| 728 | /// base-clause[opt] |
| 729 | /// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | /// [GNU] class-key attributes[opt] nested-name-specifier |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 731 | /// identifier base-clause[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | /// [GNU] class-key attributes[opt] nested-name-specifier[opt] |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 733 | /// simple-template-id base-clause[opt] |
| 734 | /// class-key: |
| 735 | /// 'class' |
| 736 | /// 'struct' |
| 737 | /// 'union' |
| 738 | /// |
| 739 | /// elaborated-type-specifier: [C++ dcl.type.elab] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 740 | /// class-key ::[opt] nested-name-specifier[opt] identifier |
| 741 | /// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] |
| 742 | /// simple-template-id |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 743 | /// |
| 744 | /// Note that the C++ class-specifier and elaborated-type-specifier, |
| 745 | /// together, subsume the C99 struct-or-union-specifier: |
| 746 | /// |
| 747 | /// struct-or-union-specifier: [C99 6.7.2.1] |
| 748 | /// struct-or-union identifier[opt] '{' struct-contents '}' |
| 749 | /// struct-or-union identifier |
| 750 | /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents |
| 751 | /// '}' attributes[opt] |
| 752 | /// [GNU] struct-or-union attributes[opt] identifier |
| 753 | /// struct-or-union: |
| 754 | /// 'struct' |
| 755 | /// 'union' |
Chris Lattner | ffaa0e6 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 756 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, |
| 757 | SourceLocation StartLoc, DeclSpec &DS, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 758 | const ParsedTemplateInfo &TemplateInfo, |
Sebastian Redl | 2b37272 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 759 | AccessSpecifier AS, bool SuppressDeclarations){ |
Chris Lattner | ffaa0e6 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 760 | DeclSpec::TST TagType; |
| 761 | if (TagTokKind == tok::kw_struct) |
| 762 | TagType = DeclSpec::TST_struct; |
| 763 | else if (TagTokKind == tok::kw_class) |
| 764 | TagType = DeclSpec::TST_class; |
| 765 | else { |
| 766 | assert(TagTokKind == tok::kw_union && "Not a class specifier"); |
| 767 | TagType = DeclSpec::TST_union; |
| 768 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 769 | |
Douglas Gregor | f45b0cf | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 770 | if (Tok.is(tok::code_completion)) { |
| 771 | // Code completion for a struct, class, or union name. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 772 | Actions.CodeCompleteTag(getCurScope(), TagType); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 773 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f45b0cf | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 774 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 775 | |
Chandler Carruth | 2d69ec7 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 776 | // C++03 [temp.explicit] 14.7.2/8: |
| 777 | // The usual access checking rules do not apply to names used to specify |
| 778 | // explicit instantiations. |
| 779 | // |
| 780 | // As an extension we do not perform access checking on the names used to |
| 781 | // specify explicit specializations either. This is important to allow |
| 782 | // specializing traits classes for private types. |
| 783 | bool SuppressingAccessChecks = false; |
| 784 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || |
| 785 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) { |
| 786 | Actions.ActOnStartSuppressingAccessChecks(); |
| 787 | SuppressingAccessChecks = true; |
| 788 | } |
| 789 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 790 | ParsedAttributes attrs(AttrFactory); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 791 | // If attributes exist after tag, parse them. |
| 792 | if (Tok.is(tok::kw___attribute)) |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 793 | ParseGNUAttributes(attrs); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 794 | |
Steve Naroff | 3a9b7e0 | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 795 | // If declspecs exist after tag, parse them. |
John McCall | 0f8ccc4 | 2010-08-05 17:13:11 +0000 | [diff] [blame] | 796 | while (Tok.is(tok::kw___declspec)) |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 797 | ParseMicrosoftDeclSpec(attrs); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 798 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 799 | // If C++0x attributes exist here, parse them. |
| 800 | // FIXME: Are we consistent with the ordering of parsing of different |
| 801 | // styles of attributes? |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 802 | MaybeParseCXX0XAttributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
John Wiegley | 65497cc | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 804 | if (TagType == DeclSpec::TST_struct && |
Douglas Gregor | f1fce5d | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 805 | !Tok.is(tok::identifier) && |
| 806 | Tok.getIdentifierInfo() && |
| 807 | (Tok.is(tok::kw___is_arithmetic) || |
| 808 | Tok.is(tok::kw___is_convertible) || |
John Wiegley | 65497cc | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 809 | Tok.is(tok::kw___is_empty) || |
Douglas Gregor | f1fce5d | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 810 | Tok.is(tok::kw___is_floating_point) || |
| 811 | Tok.is(tok::kw___is_function) || |
John Wiegley | 65497cc | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 812 | Tok.is(tok::kw___is_fundamental) || |
Douglas Gregor | f1fce5d | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 813 | Tok.is(tok::kw___is_integral) || |
| 814 | Tok.is(tok::kw___is_member_function_pointer) || |
| 815 | Tok.is(tok::kw___is_member_pointer) || |
| 816 | Tok.is(tok::kw___is_pod) || |
| 817 | Tok.is(tok::kw___is_pointer) || |
| 818 | Tok.is(tok::kw___is_same) || |
Douglas Gregor | 63180b1 | 2011-04-29 01:38:03 +0000 | [diff] [blame] | 819 | Tok.is(tok::kw___is_scalar) || |
Douglas Gregor | f1fce5d | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 820 | Tok.is(tok::kw___is_signed) || |
| 821 | Tok.is(tok::kw___is_unsigned) || |
| 822 | Tok.is(tok::kw___is_void))) { |
| 823 | // GNU libstdc++ 4.2 and libc++ uaw certain intrinsic names as the |
| 824 | // name of struct templates, but some are keywords in GCC >= 4.3 |
| 825 | // and Clang. Therefore, when we see the token sequence "struct |
| 826 | // X", make X into a normal identifier rather than a keyword, to |
| 827 | // allow libstdc++ 4.2 and libc++ to work properly. |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 828 | Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); |
Douglas Gregor | 119b0c7 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 829 | Tok.setKind(tok::identifier); |
| 830 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | |
Argyrios Kyrtzidis | 32a0379 | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 832 | // Parse the (optional) nested-name-specifier. |
John McCall | 9dab4e6 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 833 | CXXScopeSpec &SS = DS.getTypeSpecScope(); |
Chris Lattner | d5c1c9d | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 834 | if (getLang().CPlusPlus) { |
| 835 | // "FOO : BAR" is not a potential typo for "FOO::BAR". |
| 836 | ColonProtectionRAIIObject X(*this); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 837 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 838 | if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), true)) |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 839 | DS.SetTypeSpecError(); |
John McCall | 1f476a1 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 840 | if (SS.isSet()) |
Chris Lattner | d5c1c9d | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 841 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) |
| 842 | Diag(Tok, diag::err_expected_ident); |
| 843 | } |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 844 | |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 845 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 846 | |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 847 | // Parse the (optional) class name or simple-template-id. |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 848 | IdentifierInfo *Name = 0; |
| 849 | SourceLocation NameLoc; |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 850 | TemplateIdAnnotation *TemplateId = 0; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 851 | if (Tok.is(tok::identifier)) { |
| 852 | Name = Tok.getIdentifierInfo(); |
| 853 | NameLoc = ConsumeToken(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 854 | |
Douglas Gregor | d5a479c | 2010-05-30 22:30:21 +0000 | [diff] [blame] | 855 | if (Tok.is(tok::less) && getLang().CPlusPlus) { |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 856 | // The name was supposed to refer to a template, but didn't. |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 857 | // Eat the template argument list and try to continue parsing this as |
| 858 | // a class (or template thereof). |
| 859 | TemplateArgList TemplateArgs; |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 860 | SourceLocation LAngleLoc, RAngleLoc; |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 861 | if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, SS, |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 862 | true, LAngleLoc, |
Douglas Gregor | b53edfb | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 863 | TemplateArgs, RAngleLoc)) { |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 864 | // We couldn't parse the template argument list at all, so don't |
| 865 | // try to give any location information for the list. |
| 866 | LAngleLoc = RAngleLoc = SourceLocation(); |
| 867 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 868 | |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 869 | Diag(NameLoc, diag::err_explicit_spec_non_template) |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 870 | << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 871 | << (TagType == DeclSpec::TST_class? 0 |
| 872 | : TagType == DeclSpec::TST_struct? 1 |
| 873 | : 2) |
| 874 | << Name |
| 875 | << SourceRange(LAngleLoc, RAngleLoc); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 876 | |
| 877 | // Strip off the last template parameter list if it was empty, since |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 878 | // we've removed its template argument list. |
| 879 | if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { |
| 880 | if (TemplateParams && TemplateParams->size() > 1) { |
| 881 | TemplateParams->pop_back(); |
| 882 | } else { |
| 883 | TemplateParams = 0; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 884 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 885 | = ParsedTemplateInfo::NonTemplate; |
| 886 | } |
| 887 | } else if (TemplateInfo.Kind |
| 888 | == ParsedTemplateInfo::ExplicitInstantiation) { |
| 889 | // Pretend this is just a forward declaration. |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 890 | TemplateParams = 0; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 891 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 892 | = ParsedTemplateInfo::NonTemplate; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 893 | const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc |
Douglas Gregor | 1d0015f | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 894 | = SourceLocation(); |
| 895 | const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc |
| 896 | = SourceLocation(); |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 897 | } |
Douglas Gregor | 916462b | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 898 | } |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 899 | } else if (Tok.is(tok::annot_template_id)) { |
| 900 | TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
| 901 | NameLoc = ConsumeToken(); |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 902 | |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 903 | if (TemplateId->Kind != TNK_Type_template && |
| 904 | TemplateId->Kind != TNK_Dependent_template_name) { |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 905 | // The template-name in the simple-template-id refers to |
| 906 | // something other than a class template. Give an appropriate |
| 907 | // error message and skip to the ';'. |
| 908 | SourceRange Range(NameLoc); |
| 909 | if (SS.isNotEmpty()) |
| 910 | Range.setBegin(SS.getBeginLoc()); |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 911 | |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 912 | Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) |
| 913 | << Name << static_cast<int>(TemplateId->Kind) << Range; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 915 | DS.SetTypeSpecError(); |
| 916 | SkipUntil(tok::semi, false, true); |
| 917 | TemplateId->Destroy(); |
Chandler Carruth | 2d69ec7 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 918 | if (SuppressingAccessChecks) |
| 919 | Actions.ActOnStopSuppressingAccessChecks(); |
| 920 | |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 921 | return; |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 922 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Chandler Carruth | 2d69ec7 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 925 | // As soon as we're finished parsing the class's template-id, turn access |
| 926 | // checking back on. |
| 927 | if (SuppressingAccessChecks) |
| 928 | Actions.ActOnStopSuppressingAccessChecks(); |
| 929 | |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 930 | // There are four options here. If we have 'struct foo;', then this |
| 931 | // is either a forward declaration or a friend declaration, which |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 932 | // have to be treated differently. If we have 'struct foo {...', |
Anders Carlsson | 65c76d3 | 2011-03-25 14:55:14 +0000 | [diff] [blame] | 933 | // 'struct foo :...' or 'struct foo final[opt]' then this is a |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 934 | // definition. Otherwise we have something like 'struct foo xyz', a reference. |
Sebastian Redl | 2b37272 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 935 | // However, in some contexts, things look like declarations but are just |
| 936 | // references, e.g. |
| 937 | // new struct s; |
| 938 | // or |
| 939 | // &T::operator struct s; |
| 940 | // For these, SuppressDeclarations is true. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 941 | Sema::TagUseKind TUK; |
Sebastian Redl | 2b37272 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 942 | if (SuppressDeclarations) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 943 | TUK = Sema::TUK_Reference; |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 944 | else if (Tok.is(tok::l_brace) || |
| 945 | (getLang().CPlusPlus && Tok.is(tok::colon)) || |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 946 | isCXX0XFinalKeyword()) { |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 947 | if (DS.isFriendSpecified()) { |
| 948 | // C++ [class.friend]p2: |
| 949 | // A class shall not be defined in a friend declaration. |
| 950 | Diag(Tok.getLocation(), diag::err_friend_decl_defines_class) |
| 951 | << SourceRange(DS.getFriendSpecLoc()); |
| 952 | |
| 953 | // Skip everything up to the semicolon, so that this looks like a proper |
| 954 | // friend class (or template thereof) declaration. |
| 955 | SkipUntil(tok::semi, true, true); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 956 | TUK = Sema::TUK_Friend; |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 957 | } else { |
| 958 | // Okay, this is a class definition. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 959 | TUK = Sema::TUK_Definition; |
Douglas Gregor | 3dad842 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 960 | } |
| 961 | } else if (Tok.is(tok::semi)) |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 962 | TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 963 | else |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 964 | TUK = Sema::TUK_Reference; |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 965 | |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 966 | if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 967 | TUK != Sema::TUK_Definition)) { |
John McCall | 413021a | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 968 | if (DS.getTypeSpecType() != DeclSpec::TST_error) { |
| 969 | // We have a declaration or reference to an anonymous class. |
| 970 | Diag(StartLoc, diag::err_anon_type_definition) |
| 971 | << DeclSpec::getSpecifierName(TagType); |
| 972 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 973 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 974 | SkipUntil(tok::comma, true); |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 975 | |
| 976 | if (TemplateId) |
| 977 | TemplateId->Destroy(); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 978 | return; |
| 979 | } |
| 980 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 981 | // Create the tag portion of the class or class template. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 982 | DeclResult TagOrTempResult = true; // invalid |
| 983 | TypeResult TypeResult = true; // invalid |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | d6ab874 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 985 | bool Owned = false; |
John McCall | 06f6fe8d | 2009-09-04 01:14:41 +0000 | [diff] [blame] | 986 | if (TemplateId) { |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 987 | // Explicit specialization, class template partial specialization, |
| 988 | // or explicit instantiation. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | ASTTemplateArgsPtr TemplateArgsPtr(Actions, |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 990 | TemplateId->getTemplateArgs(), |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 991 | TemplateId->NumArgs); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 992 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 993 | TUK == Sema::TUK_Declaration) { |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 994 | // This is an explicit instantiation of a class template. |
| 995 | TagOrTempResult |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 996 | = Actions.ActOnExplicitInstantiation(getCurScope(), |
Douglas Gregor | 43e7517 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 997 | TemplateInfo.ExternLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | TemplateInfo.TemplateLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 999 | TagType, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | StartLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1001 | SS, |
John McCall | 3e56fd4 | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1002 | TemplateId->Template, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 | TemplateId->TemplateNameLoc, |
| 1004 | TemplateId->LAngleLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1005 | TemplateArgsPtr, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | TemplateId->RAngleLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1007 | attrs.getList()); |
John McCall | b7c5c27 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 1008 | |
| 1009 | // Friend template-ids are treated as references unless |
| 1010 | // they have template headers, in which case they're ill-formed |
| 1011 | // (FIXME: "template <class T> friend class A<T>::B<int>;"). |
| 1012 | // We diagnose this error in ActOnClassTemplateSpecialization. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1013 | } else if (TUK == Sema::TUK_Reference || |
| 1014 | (TUK == Sema::TUK_Friend && |
John McCall | b7c5c27 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 1015 | TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1016 | TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, |
| 1017 | StartLoc, |
| 1018 | TemplateId->SS, |
| 1019 | TemplateId->Template, |
| 1020 | TemplateId->TemplateNameLoc, |
| 1021 | TemplateId->LAngleLoc, |
| 1022 | TemplateArgsPtr, |
| 1023 | TemplateId->RAngleLoc); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1024 | } else { |
| 1025 | // This is an explicit specialization or a class template |
| 1026 | // partial specialization. |
| 1027 | TemplateParameterLists FakedParamLists; |
| 1028 | |
| 1029 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 1030 | // This looks like an explicit instantiation, because we have |
| 1031 | // something like |
| 1032 | // |
| 1033 | // template class Foo<X> |
| 1034 | // |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1035 | // but it actually has a definition. Most likely, this was |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1036 | // meant to be an explicit specialization, but the user forgot |
| 1037 | // the '<>' after 'template'. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1038 | assert(TUK == Sema::TUK_Definition && "Expected a definition here"); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1039 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | SourceLocation LAngleLoc |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1041 | = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1042 | Diag(TemplateId->TemplateNameLoc, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1043 | diag::err_explicit_instantiation_with_definition) |
| 1044 | << SourceRange(TemplateInfo.TemplateLoc) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1045 | << FixItHint::CreateInsertion(LAngleLoc, "<>"); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1046 | |
| 1047 | // Create a fake template parameter list that contains only |
| 1048 | // "template<>", so that we treat this construct as a class |
| 1049 | // template specialization. |
| 1050 | FakedParamLists.push_back( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1051 | Actions.ActOnTemplateParameterList(0, SourceLocation(), |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1052 | TemplateInfo.TemplateLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | LAngleLoc, |
| 1054 | 0, 0, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1055 | LAngleLoc)); |
| 1056 | TemplateParams = &FakedParamLists; |
| 1057 | } |
| 1058 | |
| 1059 | // Build the class template specialization. |
| 1060 | TagOrTempResult |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1061 | = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK, |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1062 | StartLoc, SS, |
John McCall | 3e56fd4 | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1063 | TemplateId->Template, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | TemplateId->TemplateNameLoc, |
| 1065 | TemplateId->LAngleLoc, |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1066 | TemplateArgsPtr, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | TemplateId->RAngleLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1068 | attrs.getList(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1069 | MultiTemplateParamsArg(Actions, |
Douglas Gregor | 67a6564 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1070 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 1071 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1072 | } |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1073 | TemplateId->Destroy(); |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1074 | } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1075 | TUK == Sema::TUK_Declaration) { |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1076 | // Explicit instantiation of a member of a class template |
| 1077 | // specialization, e.g., |
| 1078 | // |
| 1079 | // template struct Outer<int>::Inner; |
| 1080 | // |
| 1081 | TagOrTempResult |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1082 | = Actions.ActOnExplicitInstantiation(getCurScope(), |
Douglas Gregor | 43e7517 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1083 | TemplateInfo.ExternLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | TemplateInfo.TemplateLoc, |
| 1085 | TagType, StartLoc, SS, Name, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1086 | NameLoc, attrs.getList()); |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1087 | } else if (TUK == Sema::TUK_Friend && |
| 1088 | TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) { |
| 1089 | TagOrTempResult = |
| 1090 | Actions.ActOnTemplatedFriendTag(getCurScope(), DS.getFriendSpecLoc(), |
| 1091 | TagType, StartLoc, SS, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1092 | Name, NameLoc, attrs.getList(), |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1093 | MultiTemplateParamsArg(Actions, |
| 1094 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 1095 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1096 | } else { |
| 1097 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1098 | TUK == Sema::TUK_Definition) { |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1099 | // FIXME: Diagnose this particular error. |
| 1100 | } |
| 1101 | |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1102 | bool IsDependent = false; |
| 1103 | |
John McCall | 32723e9 | 2010-10-19 18:40:57 +0000 | [diff] [blame] | 1104 | // Don't pass down template parameter lists if this is just a tag |
| 1105 | // reference. For example, we don't need the template parameters here: |
| 1106 | // template <class T> class A *makeA(T t); |
| 1107 | MultiTemplateParamsArg TParams; |
| 1108 | if (TUK != Sema::TUK_Reference && TemplateParams) |
| 1109 | TParams = |
| 1110 | MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size()); |
| 1111 | |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1112 | // Declaration or definition of a class type |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1113 | TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1114 | SS, Name, NameLoc, attrs.getList(), AS, |
John McCall | 32723e9 | 2010-10-19 18:40:57 +0000 | [diff] [blame] | 1115 | TParams, Owned, IsDependent, false, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1116 | false, clang::TypeResult()); |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1117 | |
| 1118 | // If ActOnTag said the type was dependent, try again with the |
| 1119 | // less common call. |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1120 | if (IsDependent) { |
| 1121 | assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1122 | TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1123 | SS, Name, StartLoc, NameLoc); |
John McCall | ace48cd | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1124 | } |
Douglas Gregor | 2ec748c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1125 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1126 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1127 | // If there is a body, parse it and inform the actions module. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1128 | if (TUK == Sema::TUK_Definition) { |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1129 | assert(Tok.is(tok::l_brace) || |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1130 | (getLang().CPlusPlus && Tok.is(tok::colon)) || |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1131 | isCXX0XFinalKeyword()); |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1132 | if (getLang().CPlusPlus) |
Douglas Gregor | c08f489 | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 1133 | ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get()); |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1134 | else |
Douglas Gregor | c08f489 | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 1135 | ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1138 | const char *PrevSpec = 0; |
| 1139 | unsigned DiagID; |
| 1140 | bool Result; |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1141 | if (!TypeResult.isInvalid()) { |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 1142 | Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, |
| 1143 | NameLoc.isValid() ? NameLoc : StartLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1144 | PrevSpec, DiagID, TypeResult.get()); |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1145 | } else if (!TagOrTempResult.isInvalid()) { |
Abramo Bagnara | 9875a3c | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 1146 | Result = DS.SetTypeSpecType(TagType, StartLoc, |
| 1147 | NameLoc.isValid() ? NameLoc : StartLoc, |
| 1148 | PrevSpec, DiagID, TagOrTempResult.get(), Owned); |
John McCall | 7f41d98 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1149 | } else { |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1150 | DS.SetTypeSpecError(); |
Anders Carlsson | f83c9fa | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 1151 | return; |
| 1152 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1154 | if (Result) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1155 | Diag(StartLoc, DiagID) << PrevSpec; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1156 | |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1157 | // At this point, we've successfully parsed a class-specifier in 'definition' |
| 1158 | // form (e.g. "struct foo { int x; }". While we could just return here, we're |
| 1159 | // going to look at what comes after it to improve error recovery. If an |
| 1160 | // impossible token occurs next, we assume that the programmer forgot a ; at |
| 1161 | // the end of the declaration and recover that way. |
| 1162 | // |
| 1163 | // This switch enumerates the valid "follow" set for definition. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1164 | if (TUK == Sema::TUK_Definition) { |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1165 | bool ExpectedSemi = true; |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1166 | switch (Tok.getKind()) { |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1167 | default: break; |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1168 | case tok::semi: // struct foo {...} ; |
Chris Lattner | afe6a84 | 2010-02-02 17:32:27 +0000 | [diff] [blame] | 1169 | case tok::star: // struct foo {...} * P; |
| 1170 | case tok::amp: // struct foo {...} & R = ... |
| 1171 | case tok::identifier: // struct foo {...} V ; |
| 1172 | case tok::r_paren: //(struct foo {...} ) {4} |
| 1173 | case tok::annot_cxxscope: // struct foo {...} a:: b; |
| 1174 | case tok::annot_typename: // struct foo {...} a ::b; |
| 1175 | case tok::annot_template_id: // struct foo {...} a<int> ::b; |
Chris Lattner | 5e854b9 | 2010-02-03 20:41:24 +0000 | [diff] [blame] | 1176 | case tok::l_paren: // struct foo {...} ( x); |
Chris Lattner | 35af0ab | 2010-02-03 01:45:03 +0000 | [diff] [blame] | 1177 | case tok::comma: // __builtin_offsetof(struct foo{...} , |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1178 | ExpectedSemi = false; |
| 1179 | break; |
| 1180 | // Type qualifiers |
| 1181 | case tok::kw_const: // struct foo {...} const x; |
| 1182 | case tok::kw_volatile: // struct foo {...} volatile x; |
| 1183 | case tok::kw_restrict: // struct foo {...} restrict x; |
| 1184 | case tok::kw_inline: // struct foo {...} inline foo() {}; |
Chris Lattner | afe6a84 | 2010-02-02 17:32:27 +0000 | [diff] [blame] | 1185 | // Storage-class specifiers |
| 1186 | case tok::kw_static: // struct foo {...} static x; |
| 1187 | case tok::kw_extern: // struct foo {...} extern x; |
| 1188 | case tok::kw_typedef: // struct foo {...} typedef x; |
| 1189 | case tok::kw_register: // struct foo {...} register x; |
| 1190 | case tok::kw_auto: // struct foo {...} auto x; |
Douglas Gregor | c9a99c5 | 2010-05-17 18:19:56 +0000 | [diff] [blame] | 1191 | case tok::kw_mutable: // struct foo {...} mutable x; |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1192 | // As shown above, type qualifiers and storage class specifiers absolutely |
| 1193 | // can occur after class specifiers according to the grammar. However, |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1194 | // almost no one actually writes code like this. If we see one of these, |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1195 | // it is much more likely that someone missed a semi colon and the |
| 1196 | // type/storage class specifier we're seeing is part of the *next* |
| 1197 | // intended declaration, as in: |
| 1198 | // |
| 1199 | // struct foo { ... } |
| 1200 | // typedef int X; |
| 1201 | // |
| 1202 | // We'd really like to emit a missing semicolon error instead of emitting |
| 1203 | // an error on the 'int' saying that you can't have two type specifiers in |
| 1204 | // the same declaration of X. Because of this, we look ahead past this |
| 1205 | // token to see if it's a type specifier. If so, we know the code is |
| 1206 | // otherwise invalid, so we can produce the expected semi error. |
| 1207 | if (!isKnownToBeTypeSpecifier(NextToken())) |
| 1208 | ExpectedSemi = false; |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1209 | break; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1210 | |
| 1211 | case tok::r_brace: // struct bar { struct foo {...} } |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1212 | // Missing ';' at end of struct is accepted as an extension in C mode. |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1213 | if (!getLang().CPlusPlus) |
| 1214 | ExpectedSemi = false; |
| 1215 | break; |
| 1216 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1217 | |
Chris Lattner | fd48afe | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1218 | if (ExpectedSemi) { |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1219 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl, |
| 1220 | TagType == DeclSpec::TST_class ? "class" |
| 1221 | : TagType == DeclSpec::TST_struct? "struct" : "union"); |
| 1222 | // Push this token back into the preprocessor and change our current token |
| 1223 | // to ';' so that the rest of the code recovers as though there were an |
| 1224 | // ';' after the definition. |
| 1225 | PP.EnterToken(Tok); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1226 | Tok.setKind(tok::semi); |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1227 | } |
| 1228 | } |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1232 | /// |
| 1233 | /// base-clause : [C++ class.derived] |
| 1234 | /// ':' base-specifier-list |
| 1235 | /// base-specifier-list: |
| 1236 | /// base-specifier '...'[opt] |
| 1237 | /// base-specifier-list ',' base-specifier '...'[opt] |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1238 | void Parser::ParseBaseClause(Decl *ClassDecl) { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1239 | assert(Tok.is(tok::colon) && "Not a base clause"); |
| 1240 | ConsumeToken(); |
| 1241 | |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1242 | // Build up an array of parsed base specifiers. |
John McCall | 37ad551 | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 1243 | llvm::SmallVector<CXXBaseSpecifier *, 8> BaseInfo; |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1244 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1245 | while (true) { |
| 1246 | // Parse a base-specifier. |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1247 | BaseResult Result = ParseBaseSpecifier(ClassDecl); |
Douglas Gregor | f829825 | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1248 | if (Result.isInvalid()) { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1249 | // Skip the rest of this base specifier, up until the comma or |
| 1250 | // opening brace. |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1251 | SkipUntil(tok::comma, tok::l_brace, true, true); |
| 1252 | } else { |
| 1253 | // Add this to our array of base specifiers. |
Douglas Gregor | f829825 | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1254 | BaseInfo.push_back(Result.get()); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | // If the next token is a comma, consume it and keep reading |
| 1258 | // base-specifiers. |
| 1259 | if (Tok.isNot(tok::comma)) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1261 | // Consume the comma. |
| 1262 | ConsumeToken(); |
| 1263 | } |
Douglas Gregor | 29a9247 | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1264 | |
| 1265 | // Attach the base specifiers |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1266 | Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is |
| 1270 | /// one entry in the base class list of a class specifier, for example: |
| 1271 | /// class foo : public bar, virtual private baz { |
| 1272 | /// 'public bar' and 'virtual private baz' are each base-specifiers. |
| 1273 | /// |
| 1274 | /// base-specifier: [C++ class.derived] |
| 1275 | /// ::[opt] nested-name-specifier[opt] class-name |
| 1276 | /// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt] |
| 1277 | /// class-name |
| 1278 | /// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] |
| 1279 | /// class-name |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1280 | Parser::BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1281 | bool IsVirtual = false; |
| 1282 | SourceLocation StartLoc = Tok.getLocation(); |
| 1283 | |
| 1284 | // Parse the 'virtual' keyword. |
| 1285 | if (Tok.is(tok::kw_virtual)) { |
| 1286 | ConsumeToken(); |
| 1287 | IsVirtual = true; |
| 1288 | } |
| 1289 | |
| 1290 | // Parse an (optional) access specifier. |
| 1291 | AccessSpecifier Access = getAccessSpecifierIfPresent(); |
John McCall | 553c079 | 2010-01-23 00:46:32 +0000 | [diff] [blame] | 1292 | if (Access != AS_none) |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1293 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1295 | // Parse the 'virtual' keyword (again!), in case it came after the |
| 1296 | // access specifier. |
| 1297 | if (Tok.is(tok::kw_virtual)) { |
| 1298 | SourceLocation VirtualLoc = ConsumeToken(); |
| 1299 | if (IsVirtual) { |
| 1300 | // Complain about duplicate 'virtual' |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1301 | Diag(VirtualLoc, diag::err_dup_virtual) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1302 | << FixItHint::CreateRemoval(VirtualLoc); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | IsVirtual = true; |
| 1306 | } |
| 1307 | |
Argyrios Kyrtzidis | 32a0379 | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1308 | // Parse optional '::' and optional nested-name-specifier. |
| 1309 | CXXScopeSpec SS; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1310 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1311 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1312 | // The location of the base class itself. |
| 1313 | SourceLocation BaseLoc = Tok.getLocation(); |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1314 | |
| 1315 | // Parse the class-name. |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1316 | SourceLocation EndLocation; |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1317 | TypeResult BaseType = ParseClassName(EndLocation, SS); |
Douglas Gregor | fe3d7d0 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1318 | if (BaseType.isInvalid()) |
Douglas Gregor | 831c93f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1319 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1321 | // Parse the optional ellipsis (for a pack expansion). The ellipsis is |
| 1322 | // actually part of the base-specifier-list grammar productions, but we |
| 1323 | // parse it here for convenience. |
| 1324 | SourceLocation EllipsisLoc; |
| 1325 | if (Tok.is(tok::ellipsis)) |
| 1326 | EllipsisLoc = ConsumeToken(); |
| 1327 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1328 | // Find the complete source range for the base-specifier. |
Douglas Gregor | d54dfb8 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1329 | SourceRange Range(StartLoc, EndLocation); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1331 | // Notify semantic analysis that we have parsed a complete |
| 1332 | // base-specifier. |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1333 | return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access, |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1334 | BaseType.get(), BaseLoc, EllipsisLoc); |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | /// getAccessSpecifierIfPresent - Determine whether the next token is |
| 1338 | /// a C++ access-specifier. |
| 1339 | /// |
| 1340 | /// access-specifier: [C++ class.derived] |
| 1341 | /// 'private' |
| 1342 | /// 'protected' |
| 1343 | /// 'public' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const { |
Douglas Gregor | 556877c | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1345 | switch (Tok.getKind()) { |
| 1346 | default: return AS_none; |
| 1347 | case tok::kw_private: return AS_private; |
| 1348 | case tok::kw_protected: return AS_protected; |
| 1349 | case tok::kw_public: return AS_public; |
| 1350 | } |
| 1351 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1352 | |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1353 | void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1354 | Decl *ThisDecl) { |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1355 | // We just declared a member function. If this member function |
| 1356 | // has any default arguments, we'll need to parse them later. |
| 1357 | LateParsedMethodDeclaration *LateMethod = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1358 | DeclaratorChunk::FunctionTypeInfo &FTI |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 1359 | = DeclaratorInfo.getFunctionTypeInfo(); |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1360 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { |
| 1361 | if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { |
| 1362 | if (!LateMethod) { |
| 1363 | // Push this method onto the stack of late-parsed method |
| 1364 | // declarations. |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1365 | LateMethod = new LateParsedMethodDeclaration(this, ThisDecl); |
| 1366 | getCurrentClass().LateParsedDeclarations.push_back(LateMethod); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1367 | LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1368 | |
| 1369 | // Add all of the parameters prior to this one (they don't |
| 1370 | // have default arguments). |
| 1371 | LateMethod->DefaultArgs.reserve(FTI.NumArgs); |
| 1372 | for (unsigned I = 0; I < ParamIdx; ++I) |
| 1373 | LateMethod->DefaultArgs.push_back( |
Douglas Gregor | 1d85d29 | 2010-03-02 01:29:43 +0000 | [diff] [blame] | 1374 | LateParsedDefaultArgument(FTI.ArgInfo[I].Param)); |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | // Add this parameter to the list of parameters (it or may |
| 1378 | // not have a default argument). |
| 1379 | LateMethod->DefaultArgs.push_back( |
| 1380 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, |
| 1381 | FTI.ArgInfo[ParamIdx].DefaultArgTokens)); |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1386 | /// isCXX0XVirtSpecifier - Determine whether the next token is a C++0x |
| 1387 | /// virt-specifier. |
| 1388 | /// |
| 1389 | /// virt-specifier: |
| 1390 | /// override |
| 1391 | /// final |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1392 | VirtSpecifiers::Specifier Parser::isCXX0XVirtSpecifier() const { |
Anders Carlsson | 5a72fdb | 2011-01-22 23:01:49 +0000 | [diff] [blame] | 1393 | if (!getLang().CPlusPlus) |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1394 | return VirtSpecifiers::VS_None; |
| 1395 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1396 | if (Tok.is(tok::identifier)) { |
| 1397 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1398 | |
Anders Carlsson | 428803b | 2011-01-20 03:47:08 +0000 | [diff] [blame] | 1399 | // Initialize the contextual keywords. |
| 1400 | if (!Ident_final) { |
| 1401 | Ident_final = &PP.getIdentifierTable().get("final"); |
| 1402 | Ident_override = &PP.getIdentifierTable().get("override"); |
| 1403 | } |
| 1404 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1405 | if (II == Ident_override) |
| 1406 | return VirtSpecifiers::VS_Override; |
| 1407 | |
| 1408 | if (II == Ident_final) |
| 1409 | return VirtSpecifiers::VS_Final; |
| 1410 | } |
| 1411 | |
| 1412 | return VirtSpecifiers::VS_None; |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /// ParseOptionalCXX0XVirtSpecifierSeq - Parse a virt-specifier-seq. |
| 1416 | /// |
| 1417 | /// virt-specifier-seq: |
| 1418 | /// virt-specifier |
| 1419 | /// virt-specifier-seq virt-specifier |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1420 | void Parser::ParseOptionalCXX0XVirtSpecifierSeq(VirtSpecifiers &VS) { |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1421 | while (true) { |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1422 | VirtSpecifiers::Specifier Specifier = isCXX0XVirtSpecifier(); |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1423 | if (Specifier == VirtSpecifiers::VS_None) |
| 1424 | return; |
| 1425 | |
| 1426 | // C++ [class.mem]p8: |
| 1427 | // A virt-specifier-seq shall contain at most one of each virt-specifier. |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1428 | const char *PrevSpec = 0; |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 1429 | if (VS.SetSpecifier(Specifier, Tok.getLocation(), PrevSpec)) |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1430 | Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier) |
| 1431 | << PrevSpec |
| 1432 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 1433 | |
Anders Carlsson | 5a72fdb | 2011-01-22 23:01:49 +0000 | [diff] [blame] | 1434 | if (!getLang().CPlusPlus0x) |
| 1435 | Diag(Tok.getLocation(), diag::ext_override_control_keyword) |
| 1436 | << VirtSpecifiers::getSpecifierName(Specifier); |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1437 | ConsumeToken(); |
| 1438 | } |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1441 | /// isCXX0XFinalKeyword - Determine whether the next token is a C++0x |
| 1442 | /// contextual 'final' keyword. |
| 1443 | bool Parser::isCXX0XFinalKeyword() const { |
Anders Carlsson | 5a72fdb | 2011-01-22 23:01:49 +0000 | [diff] [blame] | 1444 | if (!getLang().CPlusPlus) |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1445 | return false; |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1446 | |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1447 | if (!Tok.is(tok::identifier)) |
| 1448 | return false; |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1449 | |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1450 | // Initialize the contextual keywords. |
| 1451 | if (!Ident_final) { |
| 1452 | Ident_final = &PP.getIdentifierTable().get("final"); |
| 1453 | Ident_override = &PP.getIdentifierTable().get("override"); |
| 1454 | } |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1455 | |
Anders Carlsson | cafbab7 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1456 | return Tok.getIdentifierInfo() == Ident_final; |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1459 | /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. |
| 1460 | /// |
| 1461 | /// member-declaration: |
| 1462 | /// decl-specifier-seq[opt] member-declarator-list[opt] ';' |
| 1463 | /// function-definition ';'[opt] |
| 1464 | /// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] |
| 1465 | /// using-declaration [TODO] |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1466 | /// [C++0x] static_assert-declaration |
Anders Carlsson | dfbbdf6 | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1467 | /// template-declaration |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1468 | /// [GNU] '__extension__' member-declaration |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1469 | /// |
| 1470 | /// member-declarator-list: |
| 1471 | /// member-declarator |
| 1472 | /// member-declarator-list ',' member-declarator |
| 1473 | /// |
| 1474 | /// member-declarator: |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1475 | /// declarator virt-specifier-seq[opt] pure-specifier[opt] |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1476 | /// declarator constant-initializer[opt] |
| 1477 | /// identifier[opt] ':' constant-expression |
| 1478 | /// |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1479 | /// virt-specifier-seq: |
| 1480 | /// virt-specifier |
| 1481 | /// virt-specifier-seq virt-specifier |
| 1482 | /// |
| 1483 | /// virt-specifier: |
| 1484 | /// override |
| 1485 | /// final |
| 1486 | /// new |
| 1487 | /// |
Sebastian Redl | 42e92c4 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1488 | /// pure-specifier: |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1489 | /// '= 0' |
| 1490 | /// |
| 1491 | /// constant-initializer: |
| 1492 | /// '=' constant-expression |
| 1493 | /// |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1494 | void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1495 | const ParsedTemplateInfo &TemplateInfo, |
| 1496 | ParsingDeclRAIIObject *TemplateDiags) { |
Douglas Gregor | 23c8476 | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1497 | if (Tok.is(tok::at)) { |
| 1498 | if (getLang().ObjC1 && NextToken().isObjCAtKeyword(tok::objc_defs)) |
| 1499 | Diag(Tok, diag::err_at_defs_cxx); |
| 1500 | else |
| 1501 | Diag(Tok, diag::err_at_in_class); |
| 1502 | |
| 1503 | ConsumeToken(); |
| 1504 | SkipUntil(tok::r_brace); |
| 1505 | return; |
| 1506 | } |
| 1507 | |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1508 | // Access declarations. |
| 1509 | if (!TemplateInfo.Kind && |
| 1510 | (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) && |
John McCall | 1f476a1 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1511 | !TryAnnotateCXXScopeToken() && |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1512 | Tok.is(tok::annot_cxxscope)) { |
| 1513 | bool isAccessDecl = false; |
| 1514 | if (NextToken().is(tok::identifier)) |
| 1515 | isAccessDecl = GetLookAheadToken(2).is(tok::semi); |
| 1516 | else |
| 1517 | isAccessDecl = NextToken().is(tok::kw_operator); |
| 1518 | |
| 1519 | if (isAccessDecl) { |
| 1520 | // Collect the scope specifier token we annotated earlier. |
| 1521 | CXXScopeSpec SS; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1522 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1523 | |
| 1524 | // Try to parse an unqualified-id. |
| 1525 | UnqualifiedId Name; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1526 | if (ParseUnqualifiedId(SS, false, true, true, ParsedType(), Name)) { |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1527 | SkipUntil(tok::semi); |
| 1528 | return; |
| 1529 | } |
| 1530 | |
| 1531 | // TODO: recover from mistakenly-qualified operator declarations. |
| 1532 | if (ExpectAndConsume(tok::semi, |
| 1533 | diag::err_expected_semi_after, |
| 1534 | "access declaration", |
| 1535 | tok::semi)) |
| 1536 | return; |
| 1537 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1538 | Actions.ActOnUsingDeclaration(getCurScope(), AS, |
John McCall | a009726 | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1539 | false, SourceLocation(), |
| 1540 | SS, Name, |
| 1541 | /* AttrList */ 0, |
| 1542 | /* IsTypeName */ false, |
| 1543 | SourceLocation()); |
| 1544 | return; |
| 1545 | } |
| 1546 | } |
| 1547 | |
Anders Carlsson | f24fcff6 | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1548 | // static_assert-declaration |
Peter Collingbourne | 3d9cbdc | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 1549 | if (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) { |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1550 | // FIXME: Check for templates |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1551 | SourceLocation DeclEnd; |
| 1552 | ParseStaticAssertDeclaration(DeclEnd); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1553 | return; |
| 1554 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1555 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1556 | if (Tok.is(tok::kw_template)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1557 | assert(!TemplateInfo.TemplateParams && |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1558 | "Nested template improperly parsed?"); |
Chris Lattner | 49836b4 | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1559 | SourceLocation DeclEnd; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, |
Douglas Gregor | 1b57ff3 | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1561 | AS); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1562 | return; |
| 1563 | } |
Anders Carlsson | dfbbdf6 | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1564 | |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1565 | // Handle: member-declaration ::= '__extension__' member-declaration |
| 1566 | if (Tok.is(tok::kw___extension__)) { |
| 1567 | // __extension__ silences extension warnings in the subexpression. |
| 1568 | ExtensionRAIIObject O(Diags); // Use RAII to do this. |
| 1569 | ConsumeToken(); |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1570 | return ParseCXXClassMemberDeclaration(AS, TemplateInfo, TemplateDiags); |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1571 | } |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1572 | |
Chris Lattner | cf25141 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1573 | // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it |
| 1574 | // is a bitfield. |
Chris Lattner | 17c3b1f | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 1575 | ColonProtectionRAIIObject X(*this); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1576 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1577 | ParsedAttributesWithRange attrs(AttrFactory); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1578 | // Optional C++0x attribute-specifier |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1579 | MaybeParseCXX0XAttributes(attrs); |
| 1580 | MaybeParseMicrosoftAttributes(attrs); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1581 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1582 | if (Tok.is(tok::kw_using)) { |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1583 | ProhibitAttributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1584 | |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1585 | // Eat 'using'. |
| 1586 | SourceLocation UsingLoc = ConsumeToken(); |
| 1587 | |
| 1588 | if (Tok.is(tok::kw_namespace)) { |
| 1589 | Diag(UsingLoc, diag::err_using_namespace_in_class); |
| 1590 | SkipUntil(tok::semi, true, true); |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 1591 | } else { |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1592 | SourceLocation DeclEnd; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 1593 | // Otherwise, it must be a using-declaration or an alias-declaration. |
John McCall | 9b72f89 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 1594 | ParseUsingDeclaration(Declarator::MemberContext, TemplateInfo, |
| 1595 | UsingLoc, DeclEnd, AS); |
Douglas Gregor | fec5263 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1596 | } |
| 1597 | return; |
| 1598 | } |
| 1599 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1600 | // decl-specifier-seq: |
| 1601 | // Parse the common declaration-specifiers piece. |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1602 | ParsingDeclSpec DS(*this, TemplateDiags); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1603 | DS.takeAttributesFrom(attrs); |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1604 | ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1605 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1606 | MultiTemplateParamsArg TemplateParams(Actions, |
John McCall | 11083da | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 1607 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, |
| 1608 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); |
| 1609 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1610 | if (Tok.is(tok::semi)) { |
| 1611 | ConsumeToken(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1612 | Decl *TheDecl = |
Chandler Carruth | 7c9856d | 2011-05-03 18:35:10 +0000 | [diff] [blame] | 1613 | Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS, TemplateParams); |
John McCall | 796c2a5 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1614 | DS.complete(TheDecl); |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1615 | return; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1616 | } |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1617 | |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1618 | ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 1619 | VirtSpecifiers VS; |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 1620 | ExprResult Init; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1621 | |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1622 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | 17c3b1f | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 1623 | // Don't parse FOO:BAR as if it were a typo for FOO::BAR. |
| 1624 | ColonProtectionRAIIObject X(*this); |
| 1625 | |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1626 | // Parse the first declarator. |
| 1627 | ParseDeclarator(DeclaratorInfo); |
| 1628 | // Error parsing the declarator? |
Douglas Gregor | 92751d4 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 1629 | if (!DeclaratorInfo.hasName()) { |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1630 | // If so, skip until the semi-colon or a }. |
Sebastian Redl | 83f3b85 | 2011-04-24 16:27:48 +0000 | [diff] [blame] | 1631 | SkipUntil(tok::r_brace, true, true); |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1632 | if (Tok.is(tok::semi)) |
| 1633 | ConsumeToken(); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1634 | return; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 1637 | ParseOptionalCXX0XVirtSpecifierSeq(VS); |
| 1638 | |
John Thompson | 5bc5cbe | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 1639 | // If attributes exist after the declarator, but before an '{', parse them. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1640 | MaybeParseGNUAttributes(DeclaratorInfo); |
John Thompson | 5bc5cbe | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 1641 | |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 1642 | // MSVC permits pure specifier on inline functions declared at class scope. |
| 1643 | // Hence check for =0 before checking for function definition. |
| 1644 | if (getLang().Microsoft && Tok.is(tok::equal) && |
| 1645 | DeclaratorInfo.isFunctionDeclarator() && |
| 1646 | NextToken().is(tok::numeric_constant)) { |
| 1647 | ConsumeToken(); |
| 1648 | Init = ParseInitializer(); |
| 1649 | if (Init.isInvalid()) |
| 1650 | SkipUntil(tok::comma, true, true); |
| 1651 | } |
| 1652 | |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1653 | bool IsDefinition = false; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1654 | // function-definition: |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1655 | if (Tok.is(tok::l_brace)) { |
| 1656 | IsDefinition = true; |
| 1657 | } else if (DeclaratorInfo.isFunctionDeclarator()) { |
| 1658 | if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) { |
| 1659 | IsDefinition = true; |
| 1660 | } else if (Tok.is(tok::equal)) { |
| 1661 | const Token &KW = NextToken(); |
| 1662 | if (KW.is(tok::kw_default) || KW.is(tok::kw_delete)) |
| 1663 | IsDefinition = true; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | if (IsDefinition) { |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1668 | if (!DeclaratorInfo.isFunctionDeclarator()) { |
| 1669 | Diag(Tok, diag::err_func_def_no_params); |
| 1670 | ConsumeBrace(); |
| 1671 | SkipUntil(tok::r_brace, true); |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 1672 | |
| 1673 | // Consume the optional ';' |
| 1674 | if (Tok.is(tok::semi)) |
| 1675 | ConsumeToken(); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1676 | return; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1677 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1678 | |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1679 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 1680 | Diag(Tok, diag::err_function_declared_typedef); |
| 1681 | // This recovery skips the entire function body. It would be nice |
| 1682 | // to simply call ParseCXXInlineMethodDef() below, however Sema |
| 1683 | // assumes the declarator represents a function, not a typedef. |
| 1684 | ConsumeBrace(); |
| 1685 | SkipUntil(tok::r_brace, true); |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 1686 | |
| 1687 | // Consume the optional ';' |
| 1688 | if (Tok.is(tok::semi)) |
| 1689 | ConsumeToken(); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1690 | return; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 1693 | ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo, VS, Init); |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1694 | |
| 1695 | // Consume the ';' - it's optional unless we have a delete or default |
| 1696 | if (Tok.is(tok::semi)) { |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 1697 | ConsumeToken(); |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1698 | } |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 1699 | |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1700 | return; |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1701 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | // member-declarator-list: |
| 1705 | // member-declarator |
| 1706 | // member-declarator-list ',' member-declarator |
| 1707 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1708 | llvm::SmallVector<Decl *, 8> DeclsInGroup; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1709 | ExprResult BitfieldSize; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1710 | |
| 1711 | while (1) { |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1712 | // member-declarator: |
| 1713 | // declarator pure-specifier[opt] |
| 1714 | // declarator constant-initializer[opt] |
| 1715 | // identifier[opt] ':' constant-expression |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1716 | if (Tok.is(tok::colon)) { |
| 1717 | ConsumeToken(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1718 | BitfieldSize = ParseConstantExpression(); |
| 1719 | if (BitfieldSize.isInvalid()) |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1720 | SkipUntil(tok::comma, true, true); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1721 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1723 | ParseOptionalCXX0XVirtSpecifierSeq(VS); |
Anders Carlsson | 11fdbbc | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1724 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1725 | // pure-specifier: |
| 1726 | // '= 0' |
| 1727 | // |
| 1728 | // constant-initializer: |
| 1729 | // '=' constant-expression |
Sebastian Redl | 42e92c4 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1730 | // |
| 1731 | // defaulted/deleted function-definition: |
| 1732 | // '=' 'default' [TODO] |
| 1733 | // '=' 'delete' |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1734 | if (Tok.is(tok::equal)) { |
| 1735 | ConsumeToken(); |
Anders Carlsson | 991285e | 2010-09-24 21:25:25 +0000 | [diff] [blame] | 1736 | if (Tok.is(tok::kw_delete)) { |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1737 | if (DeclaratorInfo.isFunctionDeclarator()) |
| 1738 | Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) |
| 1739 | << 1 /* delete */; |
| 1740 | else |
| 1741 | Diag(ConsumeToken(), diag::err_deleted_non_function); |
Alexis Hunt | 5dafebc | 2011-05-06 01:42:00 +0000 | [diff] [blame] | 1742 | } else if (Tok.is(tok::kw_default)) { |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1743 | if (DeclaratorInfo.isFunctionDeclarator()) |
| 1744 | Diag(Tok, diag::err_default_delete_in_multiple_declaration) |
| 1745 | << 1 /* delete */; |
| 1746 | else |
| 1747 | Diag(ConsumeToken(), diag::err_default_special_members); |
Sebastian Redl | 42e92c4 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1748 | } else { |
| 1749 | Init = ParseInitializer(); |
| 1750 | if (Init.isInvalid()) |
| 1751 | SkipUntil(tok::comma, true, true); |
| 1752 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Chris Lattner | f3d3b36 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 1755 | // If a simple-asm-expr is present, parse it. |
| 1756 | if (Tok.is(tok::kw_asm)) { |
| 1757 | SourceLocation Loc; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1758 | ExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
Chris Lattner | f3d3b36 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 1759 | if (AsmLabel.isInvalid()) |
| 1760 | SkipUntil(tok::comma, true, true); |
| 1761 | |
| 1762 | DeclaratorInfo.setAsmLabel(AsmLabel.release()); |
| 1763 | DeclaratorInfo.SetRangeEnd(Loc); |
| 1764 | } |
| 1765 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1766 | // If attributes exist after the declarator, parse them. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1767 | MaybeParseGNUAttributes(DeclaratorInfo); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1768 | |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1769 | // NOTE: If Sema is the Action module and declarator is an instance field, |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1770 | // this call will *not* return the created decl; It will return null. |
Argyrios Kyrtzidis | ed98342 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1771 | // See Sema::ActOnCXXMemberDeclarator for details. |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1772 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1773 | Decl *ThisDecl = 0; |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1774 | if (DS.isFriendSpecified()) { |
John McCall | 2f212b3 | 2009-09-11 21:02:39 +0000 | [diff] [blame] | 1775 | // TODO: handle initializers, bitfields, 'delete' |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1776 | ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, |
John McCall | 2f212b3 | 2009-09-11 21:02:39 +0000 | [diff] [blame] | 1777 | /*IsDefinition*/ false, |
| 1778 | move(TemplateParams)); |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1779 | } else { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1780 | ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1781 | DeclaratorInfo, |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1782 | move(TemplateParams), |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1783 | BitfieldSize.release(), |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1784 | VS, Init.release(), false); |
Douglas Gregor | 3447e76 | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1785 | } |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1786 | if (ThisDecl) |
| 1787 | DeclsInGroup.push_back(ThisDecl); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1788 | |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1789 | if (DeclaratorInfo.isFunctionDeclarator() && |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1790 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1791 | != DeclSpec::SCS_typedef) { |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1792 | HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl); |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1795 | DeclaratorInfo.complete(ThisDecl); |
| 1796 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1797 | // If we don't have a comma, it is either the end of the list (a ';') |
| 1798 | // or an error, bail out. |
| 1799 | if (Tok.isNot(tok::comma)) |
| 1800 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1801 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1802 | // Consume the comma. |
| 1803 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1805 | // Parse the next declarator. |
| 1806 | DeclaratorInfo.clear(); |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 1807 | VS.clear(); |
Sebastian Redl | c13f268 | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1808 | BitfieldSize = 0; |
| 1809 | Init = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1810 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1811 | // Attributes are only allowed on the second declarator. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1812 | MaybeParseGNUAttributes(DeclaratorInfo); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1813 | |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1814 | if (Tok.isNot(tok::colon)) |
| 1815 | ParseDeclarator(DeclaratorInfo); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 1818 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { |
| 1819 | // Skip to end of block or statement. |
| 1820 | SkipUntil(tok::r_brace, true, true); |
| 1821 | // If we stopped at a ';', eat it. |
| 1822 | if (Tok.is(tok::semi)) ConsumeToken(); |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1823 | return; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1826 | Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup.data(), |
Chris Lattner | 916dbf1 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 1827 | DeclsInGroup.size()); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | /// ParseCXXMemberSpecification - Parse the class definition. |
| 1831 | /// |
| 1832 | /// member-specification: |
| 1833 | /// member-declaration member-specification[opt] |
| 1834 | /// access-specifier ':' member-specification[opt] |
| 1835 | /// |
| 1836 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1837 | unsigned TagType, Decl *TagDecl) { |
Sanjiv Gupta | d795924 | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1838 | assert((TagType == DeclSpec::TST_struct || |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1839 | TagType == DeclSpec::TST_union || |
Sanjiv Gupta | d795924 | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1840 | TagType == DeclSpec::TST_class) && "Invalid TagType!"); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1841 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1842 | PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc, |
| 1843 | "parsing struct/union/class body"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1845 | // Determine whether this is a non-nested class. Note that local |
| 1846 | // classes are *not* considered to be nested classes. |
| 1847 | bool NonNestedClass = true; |
| 1848 | if (!ClassStack.empty()) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1849 | for (const Scope *S = getCurScope(); S; S = S->getParent()) { |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1850 | if (S->isClassScope()) { |
| 1851 | // We're inside a class scope, so this is a nested class. |
| 1852 | NonNestedClass = false; |
| 1853 | break; |
| 1854 | } |
| 1855 | |
| 1856 | if ((S->getFlags() & Scope::FnScope)) { |
| 1857 | // If we're in a function or function template declared in the |
| 1858 | // body of a class, then this is a local class rather than a |
| 1859 | // nested class. |
| 1860 | const Scope *Parent = S->getParent(); |
| 1861 | if (Parent->isTemplateParamScope()) |
| 1862 | Parent = Parent->getParent(); |
| 1863 | if (Parent->isClassScope()) |
| 1864 | break; |
| 1865 | } |
| 1866 | } |
| 1867 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1868 | |
| 1869 | // Enter a scope for the class. |
Douglas Gregor | 658b955 | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 1870 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1872 | // Note that we are parsing a new (potentially-nested) class definition. |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1873 | ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1874 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1875 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1876 | Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1877 | |
Anders Carlsson | f9eb63b | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 1878 | SourceLocation FinalLoc; |
| 1879 | |
| 1880 | // Parse the optional 'final' keyword. |
| 1881 | if (getLang().CPlusPlus && Tok.is(tok::identifier)) { |
| 1882 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1883 | |
| 1884 | // Initialize the contextual keywords. |
| 1885 | if (!Ident_final) { |
| 1886 | Ident_final = &PP.getIdentifierTable().get("final"); |
| 1887 | Ident_override = &PP.getIdentifierTable().get("override"); |
| 1888 | } |
| 1889 | |
| 1890 | if (II == Ident_final) |
| 1891 | FinalLoc = ConsumeToken(); |
| 1892 | |
| 1893 | if (!getLang().CPlusPlus0x) |
| 1894 | Diag(FinalLoc, diag::ext_override_control_keyword) << "final"; |
| 1895 | } |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1896 | |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1897 | if (Tok.is(tok::colon)) { |
| 1898 | ParseBaseClause(TagDecl); |
| 1899 | |
| 1900 | if (!Tok.is(tok::l_brace)) { |
| 1901 | Diag(Tok, diag::err_expected_lbrace_after_base_specifiers); |
John McCall | 2ff380a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 1902 | |
| 1903 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1904 | Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); |
John McCall | 2d814c3 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1905 | return; |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | assert(Tok.is(tok::l_brace)); |
| 1910 | |
| 1911 | SourceLocation LBraceLoc = ConsumeBrace(); |
| 1912 | |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1913 | if (TagDecl) |
Anders Carlsson | 30f2944 | 2011-03-25 14:31:08 +0000 | [diff] [blame] | 1914 | Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, FinalLoc, |
Anders Carlsson | fc1eef4 | 2011-01-22 17:51:53 +0000 | [diff] [blame] | 1915 | LBraceLoc); |
John McCall | 1c7e6ec | 2009-12-20 07:58:13 +0000 | [diff] [blame] | 1916 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1917 | // C++ 11p3: Members of a class defined with the keyword class are private |
| 1918 | // by default. Members of a class defined with the keywords struct or union |
| 1919 | // are public by default. |
| 1920 | AccessSpecifier CurAS; |
| 1921 | if (TagType == DeclSpec::TST_class) |
| 1922 | CurAS = AS_private; |
| 1923 | else |
| 1924 | CurAS = AS_public; |
| 1925 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1926 | SourceLocation RBraceLoc; |
| 1927 | if (TagDecl) { |
| 1928 | // While we still have something to read, read the member-declarations. |
| 1929 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
| 1930 | // Each iteration of this loop reads one member-declaration. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1931 | |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame^] | 1932 | if (getLang().Microsoft && (Tok.is(tok::kw___if_exists) || |
| 1933 | Tok.is(tok::kw___if_not_exists))) { |
| 1934 | ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); |
| 1935 | continue; |
| 1936 | } |
| 1937 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1938 | // Check for extraneous top-level semicolon. |
| 1939 | if (Tok.is(tok::semi)) { |
| 1940 | Diag(Tok, diag::ext_extra_struct_semi) |
| 1941 | << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) |
| 1942 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 1943 | ConsumeToken(); |
| 1944 | continue; |
| 1945 | } |
| 1946 | |
| 1947 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 1948 | if (AS != AS_none) { |
| 1949 | // Current token is a C++ access specifier. |
| 1950 | CurAS = AS; |
| 1951 | SourceLocation ASLoc = Tok.getLocation(); |
| 1952 | ConsumeToken(); |
| 1953 | if (Tok.is(tok::colon)) |
| 1954 | Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); |
| 1955 | else |
| 1956 | Diag(Tok, diag::err_expected_colon); |
| 1957 | ConsumeToken(); |
| 1958 | continue; |
| 1959 | } |
| 1960 | |
| 1961 | // FIXME: Make sure we don't have a template here. |
| 1962 | |
| 1963 | // Parse all the comma separated declarators. |
| 1964 | ParseCXXClassMemberDeclaration(CurAS); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1967 | RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
| 1968 | } else { |
| 1969 | SkipUntil(tok::r_brace, false, false); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1970 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1971 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1972 | // If attributes exist after class contents, parse them. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1973 | ParsedAttributes attrs(AttrFactory); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1974 | MaybeParseGNUAttributes(attrs); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1975 | |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1976 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1977 | Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1978 | LBraceLoc, RBraceLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1979 | attrs.getList()); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1980 | |
| 1981 | // C++ 9.2p2: Within the class member-specification, the class is regarded as |
| 1982 | // complete within function bodies, default arguments, |
| 1983 | // exception-specifications, and constructor ctor-initializers (including |
| 1984 | // such things in nested classes). |
| 1985 | // |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1986 | // FIXME: Only function bodies and constructor ctor-initializers are |
| 1987 | // parsed correctly, fix the rest. |
Douglas Gregor | 9377c82 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1988 | if (TagDecl && NonNestedClass) { |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1989 | // We are not inside a nested class. This class and its nested classes |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1990 | // are complete and we can parse the delayed portions of method |
| 1991 | // declarations and the lexed inline method definitions. |
Douglas Gregor | 428119e | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 1992 | SourceLocation SavedPrevTokLocation = PrevTokLocation; |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1993 | ParseLexedMethodDeclarations(getCurrentClass()); |
| 1994 | ParseLexedMethodDefs(getCurrentClass()); |
Douglas Gregor | 428119e | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 1995 | PrevTokLocation = SavedPrevTokLocation; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
John McCall | 08bede4 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1998 | if (TagDecl) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1999 | Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, RBraceLoc); |
John McCall | 2ff380a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 2000 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2001 | // Leave the class scope. |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2002 | ParsingDef.Pop(); |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 2003 | ClassScope.Exit(); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2004 | } |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2005 | |
| 2006 | /// ParseConstructorInitializer - Parse a C++ constructor initializer, |
| 2007 | /// which explicitly initializes the members or base classes of a |
| 2008 | /// class (C++ [class.base.init]). For example, the three initializers |
| 2009 | /// after the ':' in the Derived constructor below: |
| 2010 | /// |
| 2011 | /// @code |
| 2012 | /// class Base { }; |
| 2013 | /// class Derived : Base { |
| 2014 | /// int x; |
| 2015 | /// float f; |
| 2016 | /// public: |
| 2017 | /// Derived(float f) : Base(), x(17), f(f) { } |
| 2018 | /// }; |
| 2019 | /// @endcode |
| 2020 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2021 | /// [C++] ctor-initializer: |
| 2022 | /// ':' mem-initializer-list |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2023 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | /// [C++] mem-initializer-list: |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 2025 | /// mem-initializer ...[opt] |
| 2026 | /// mem-initializer ...[opt] , mem-initializer-list |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2027 | void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2028 | assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); |
| 2029 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2030 | // Poison the SEH identifiers so they are flagged as illegal in constructor initializers |
| 2031 | PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2032 | SourceLocation ColonLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2033 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 2034 | llvm::SmallVector<CXXCtorInitializer*, 4> MemInitializers; |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 2035 | bool AnyErrors = false; |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2036 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2037 | do { |
Douglas Gregor | eaeeca9 | 2010-08-28 00:00:50 +0000 | [diff] [blame] | 2038 | if (Tok.is(tok::code_completion)) { |
| 2039 | Actions.CodeCompleteConstructorInitializer(ConstructorDecl, |
| 2040 | MemInitializers.data(), |
| 2041 | MemInitializers.size()); |
| 2042 | ConsumeCodeCompletionToken(); |
| 2043 | } else { |
| 2044 | MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); |
| 2045 | if (!MemInit.isInvalid()) |
| 2046 | MemInitializers.push_back(MemInit.get()); |
| 2047 | else |
| 2048 | AnyErrors = true; |
| 2049 | } |
| 2050 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2051 | if (Tok.is(tok::comma)) |
| 2052 | ConsumeToken(); |
| 2053 | else if (Tok.is(tok::l_brace)) |
| 2054 | break; |
Douglas Gregor | 3465e26 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 2055 | // If the next token looks like a base or member initializer, assume that |
| 2056 | // we're just missing a comma. |
Douglas Gregor | ce66d02 | 2010-09-07 14:51:08 +0000 | [diff] [blame] | 2057 | else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { |
| 2058 | SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); |
| 2059 | Diag(Loc, diag::err_ctor_init_missing_comma) |
| 2060 | << FixItHint::CreateInsertion(Loc, ", "); |
| 2061 | } else { |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2062 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 2063 | Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2064 | SkipUntil(tok::l_brace, true, true); |
| 2065 | break; |
| 2066 | } |
| 2067 | } while (true); |
| 2068 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 2070 | MemInitializers.data(), MemInitializers.size(), |
| 2071 | AnyErrors); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | /// ParseMemInitializer - Parse a C++ member initializer, which is |
| 2075 | /// part of a constructor initializer that explicitly initializes one |
| 2076 | /// member or base class (C++ [class.base.init]). See |
| 2077 | /// ParseConstructorInitializer for an example. |
| 2078 | /// |
| 2079 | /// [C++] mem-initializer: |
| 2080 | /// mem-initializer-id '(' expression-list[opt] ')' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2081 | /// |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2082 | /// [C++] mem-initializer-id: |
| 2083 | /// '::'[opt] nested-name-specifier[opt] class-name |
| 2084 | /// identifier |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2085 | Parser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { |
Fariborz Jahanian | 302bb66 | 2009-06-30 23:26:25 +0000 | [diff] [blame] | 2086 | // parse '::'[opt] nested-name-specifier[opt] |
| 2087 | CXXScopeSpec SS; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2088 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false); |
| 2089 | ParsedType TemplateTypeTy; |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2090 | if (Tok.is(tok::annot_template_id)) { |
| 2091 | TemplateIdAnnotation *TemplateId |
| 2092 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
Douglas Gregor | 46c5961 | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 2093 | if (TemplateId->Kind == TNK_Type_template || |
| 2094 | TemplateId->Kind == TNK_Dependent_template_name) { |
Douglas Gregor | e7c2065 | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 2095 | AnnotateTemplateIdTokenAsType(); |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2096 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2097 | TemplateTypeTy = getTypeAnnotation(Tok); |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2098 | } |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2099 | } |
| 2100 | if (!TemplateTypeTy && Tok.isNot(tok::identifier)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 2101 | Diag(Tok, diag::err_expected_member_or_base_name); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2102 | return true; |
| 2103 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2104 | |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2105 | // Get the identifier. This may be a member name or a class name, |
| 2106 | // but we'll let the semantic analysis determine which it is. |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2107 | IdentifierInfo *II = Tok.is(tok::identifier) ? Tok.getIdentifierInfo() : 0; |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2108 | SourceLocation IdLoc = ConsumeToken(); |
| 2109 | |
| 2110 | // Parse the '('. |
| 2111 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 2112 | Diag(Tok, diag::err_expected_lparen); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2113 | return true; |
| 2114 | } |
| 2115 | SourceLocation LParenLoc = ConsumeParen(); |
| 2116 | |
| 2117 | // Parse the optional expression-list. |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2118 | ExprVector ArgExprs(Actions); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2119 | CommaLocsTy CommaLocs; |
| 2120 | if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { |
| 2121 | SkipUntil(tok::r_paren); |
| 2122 | return true; |
| 2123 | } |
| 2124 | |
| 2125 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2126 | |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 2127 | SourceLocation EllipsisLoc; |
| 2128 | if (Tok.is(tok::ellipsis)) |
| 2129 | EllipsisLoc = ConsumeToken(); |
| 2130 | |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2131 | return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, |
Fariborz Jahanian | c1fc3ec | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2132 | TemplateTypeTy, IdLoc, |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2133 | LParenLoc, ArgExprs.take(), |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 2134 | ArgExprs.size(), RParenLoc, |
| 2135 | EllipsisLoc); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2136 | } |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2137 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2138 | /// \brief Parse a C++ exception-specification if present (C++0x [except.spec]). |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2139 | /// |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2140 | /// exception-specification: |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2141 | /// dynamic-exception-specification |
| 2142 | /// noexcept-specification |
| 2143 | /// |
| 2144 | /// noexcept-specification: |
| 2145 | /// 'noexcept' |
| 2146 | /// 'noexcept' '(' constant-expression ')' |
| 2147 | ExceptionSpecificationType |
| 2148 | Parser::MaybeParseExceptionSpecification(SourceRange &SpecificationRange, |
| 2149 | llvm::SmallVectorImpl<ParsedType> &DynamicExceptions, |
| 2150 | llvm::SmallVectorImpl<SourceRange> &DynamicExceptionRanges, |
| 2151 | ExprResult &NoexceptExpr) { |
| 2152 | ExceptionSpecificationType Result = EST_None; |
| 2153 | |
| 2154 | // See if there's a dynamic specification. |
| 2155 | if (Tok.is(tok::kw_throw)) { |
| 2156 | Result = ParseDynamicExceptionSpecification(SpecificationRange, |
| 2157 | DynamicExceptions, |
| 2158 | DynamicExceptionRanges); |
| 2159 | assert(DynamicExceptions.size() == DynamicExceptionRanges.size() && |
| 2160 | "Produced different number of exception types and ranges."); |
| 2161 | } |
| 2162 | |
| 2163 | // If there's no noexcept specification, we're done. |
| 2164 | if (Tok.isNot(tok::kw_noexcept)) |
| 2165 | return Result; |
| 2166 | |
| 2167 | // If we already had a dynamic specification, parse the noexcept for, |
| 2168 | // recovery, but emit a diagnostic and don't store the results. |
| 2169 | SourceRange NoexceptRange; |
| 2170 | ExceptionSpecificationType NoexceptType = EST_None; |
| 2171 | |
| 2172 | SourceLocation KeywordLoc = ConsumeToken(); |
| 2173 | if (Tok.is(tok::l_paren)) { |
| 2174 | // There is an argument. |
| 2175 | SourceLocation LParenLoc = ConsumeParen(); |
| 2176 | NoexceptType = EST_ComputedNoexcept; |
| 2177 | NoexceptExpr = ParseConstantExpression(); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2178 | // The argument must be contextually convertible to bool. We use |
| 2179 | // ActOnBooleanCondition for this purpose. |
| 2180 | if (!NoexceptExpr.isInvalid()) |
| 2181 | NoexceptExpr = Actions.ActOnBooleanCondition(getCurScope(), KeywordLoc, |
| 2182 | NoexceptExpr.get()); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2183 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2184 | NoexceptRange = SourceRange(KeywordLoc, RParenLoc); |
| 2185 | } else { |
| 2186 | // There is no argument. |
| 2187 | NoexceptType = EST_BasicNoexcept; |
| 2188 | NoexceptRange = SourceRange(KeywordLoc, KeywordLoc); |
| 2189 | } |
| 2190 | |
| 2191 | if (Result == EST_None) { |
| 2192 | SpecificationRange = NoexceptRange; |
| 2193 | Result = NoexceptType; |
| 2194 | |
| 2195 | // If there's a dynamic specification after a noexcept specification, |
| 2196 | // parse that and ignore the results. |
| 2197 | if (Tok.is(tok::kw_throw)) { |
| 2198 | Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); |
| 2199 | ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions, |
| 2200 | DynamicExceptionRanges); |
| 2201 | } |
| 2202 | } else { |
| 2203 | Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); |
| 2204 | } |
| 2205 | |
| 2206 | return Result; |
| 2207 | } |
| 2208 | |
| 2209 | /// ParseDynamicExceptionSpecification - Parse a C++ |
| 2210 | /// dynamic-exception-specification (C++ [except.spec]). |
| 2211 | /// |
| 2212 | /// dynamic-exception-specification: |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2213 | /// 'throw' '(' type-id-list [opt] ')' |
| 2214 | /// [MS] 'throw' '(' '...' ')' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2215 | /// |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2216 | /// type-id-list: |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2217 | /// type-id ... [opt] |
| 2218 | /// type-id-list ',' type-id ... [opt] |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2219 | /// |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2220 | ExceptionSpecificationType Parser::ParseDynamicExceptionSpecification( |
| 2221 | SourceRange &SpecificationRange, |
| 2222 | llvm::SmallVectorImpl<ParsedType> &Exceptions, |
| 2223 | llvm::SmallVectorImpl<SourceRange> &Ranges) { |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2224 | assert(Tok.is(tok::kw_throw) && "expected throw"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2225 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2226 | SpecificationRange.setBegin(ConsumeToken()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2227 | |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2228 | if (!Tok.is(tok::l_paren)) { |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2229 | Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 2230 | SpecificationRange.setEnd(SpecificationRange.getBegin()); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2231 | return EST_DynamicNone; |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2232 | } |
| 2233 | SourceLocation LParenLoc = ConsumeParen(); |
| 2234 | |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2235 | // Parse throw(...), a Microsoft extension that means "this function |
| 2236 | // can throw anything". |
| 2237 | if (Tok.is(tok::ellipsis)) { |
| 2238 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 2239 | if (!getLang().Microsoft) |
| 2240 | Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2241 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2242 | SpecificationRange.setEnd(RParenLoc); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2243 | return EST_MSAny; |
Douglas Gregor | 356513d | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2246 | // Parse the sequence of type-ids. |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2247 | SourceRange Range; |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2248 | while (Tok.isNot(tok::r_paren)) { |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2249 | TypeResult Res(ParseTypeName(&Range)); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2250 | |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2251 | if (Tok.is(tok::ellipsis)) { |
| 2252 | // C++0x [temp.variadic]p5: |
| 2253 | // - In a dynamic-exception-specification (15.4); the pattern is a |
| 2254 | // type-id. |
| 2255 | SourceLocation Ellipsis = ConsumeToken(); |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2256 | Range.setEnd(Ellipsis); |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2257 | if (!Res.isInvalid()) |
| 2258 | Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis); |
| 2259 | } |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2260 | |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2261 | if (!Res.isInvalid()) { |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 2262 | Exceptions.push_back(Res.get()); |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2263 | Ranges.push_back(Range); |
| 2264 | } |
Douglas Gregor | 830837d | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2265 | |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2266 | if (Tok.is(tok::comma)) |
| 2267 | ConsumeToken(); |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 2268 | else |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2269 | break; |
| 2270 | } |
| 2271 | |
Sebastian Redl | 965b0e3 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2272 | SpecificationRange.setEnd(MatchRHSPunctuation(tok::r_paren, LParenLoc)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2273 | return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic; |
Douglas Gregor | 2afd0be | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2274 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2275 | |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 2276 | /// ParseTrailingReturnType - Parse a trailing return type on a new-style |
| 2277 | /// function declaration. |
| 2278 | TypeResult Parser::ParseTrailingReturnType() { |
| 2279 | assert(Tok.is(tok::arrow) && "expected arrow"); |
| 2280 | |
| 2281 | ConsumeToken(); |
| 2282 | |
| 2283 | // FIXME: Need to suppress declarations when parsing this typename. |
| 2284 | // Otherwise in this function definition: |
| 2285 | // |
| 2286 | // auto f() -> struct X {} |
| 2287 | // |
| 2288 | // struct X is parsed as class definition because of the trailing |
| 2289 | // brace. |
| 2290 | |
| 2291 | SourceRange Range; |
| 2292 | return ParseTypeName(&Range); |
| 2293 | } |
| 2294 | |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2295 | /// \brief We have just started parsing the definition of a new class, |
| 2296 | /// so push that class onto our stack of classes that is currently |
| 2297 | /// being parsed. |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 2298 | Sema::ParsingClassState |
| 2299 | Parser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass) { |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2300 | assert((NonNestedClass || !ClassStack.empty()) && |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2301 | "Nested class without outer class"); |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2302 | ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass)); |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 2303 | return Actions.PushParsingClass(); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /// \brief Deallocate the given parsed class and all of its nested |
| 2307 | /// classes. |
| 2308 | void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 2309 | for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I) |
| 2310 | delete Class->LateParsedDeclarations[I]; |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2311 | delete Class; |
| 2312 | } |
| 2313 | |
| 2314 | /// \brief Pop the top class of the stack of classes that are |
| 2315 | /// currently being parsed. |
| 2316 | /// |
| 2317 | /// This routine should be called when we have finished parsing the |
| 2318 | /// definition of a class, but have not yet popped the Scope |
| 2319 | /// associated with the class's definition. |
| 2320 | /// |
| 2321 | /// \returns true if the class we've popped is a top-level class, |
| 2322 | /// false otherwise. |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 2323 | void Parser::PopParsingClass(Sema::ParsingClassState state) { |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2324 | assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2325 | |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 2326 | Actions.PopParsingClass(state); |
| 2327 | |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2328 | ParsingClass *Victim = ClassStack.top(); |
| 2329 | ClassStack.pop(); |
| 2330 | if (Victim->TopLevelClass) { |
| 2331 | // Deallocate all of the nested classes of this class, |
| 2332 | // recursively: we don't need to keep any of this information. |
| 2333 | DeallocateParsedClasses(Victim); |
| 2334 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2335 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2336 | assert(!ClassStack.empty() && "Missing top-level class?"); |
| 2337 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 2338 | if (Victim->LateParsedDeclarations.empty()) { |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2339 | // The victim is a nested class, but we will not need to perform |
| 2340 | // any processing after the definition of this class since it has |
| 2341 | // no members whose handling was delayed. Therefore, we can just |
| 2342 | // remove this nested class. |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 2343 | DeallocateParsedClasses(Victim); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2344 | return; |
| 2345 | } |
| 2346 | |
| 2347 | // This nested class has some members that will need to be processed |
| 2348 | // after the top-level class is completely defined. Therefore, add |
| 2349 | // it to the list of nested classes within its parent. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2350 | assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 2351 | ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim)); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2352 | Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2353 | } |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2354 | |
| 2355 | /// ParseCXX0XAttributes - Parse a C++0x attribute-specifier. Currently only |
| 2356 | /// parses standard attributes. |
| 2357 | /// |
| 2358 | /// [C++0x] attribute-specifier: |
| 2359 | /// '[' '[' attribute-list ']' ']' |
| 2360 | /// |
| 2361 | /// [C++0x] attribute-list: |
| 2362 | /// attribute[opt] |
| 2363 | /// attribute-list ',' attribute[opt] |
| 2364 | /// |
| 2365 | /// [C++0x] attribute: |
| 2366 | /// attribute-token attribute-argument-clause[opt] |
| 2367 | /// |
| 2368 | /// [C++0x] attribute-token: |
| 2369 | /// identifier |
| 2370 | /// attribute-scoped-token |
| 2371 | /// |
| 2372 | /// [C++0x] attribute-scoped-token: |
| 2373 | /// attribute-namespace '::' identifier |
| 2374 | /// |
| 2375 | /// [C++0x] attribute-namespace: |
| 2376 | /// identifier |
| 2377 | /// |
| 2378 | /// [C++0x] attribute-argument-clause: |
| 2379 | /// '(' balanced-token-seq ')' |
| 2380 | /// |
| 2381 | /// [C++0x] balanced-token-seq: |
| 2382 | /// balanced-token |
| 2383 | /// balanced-token-seq balanced-token |
| 2384 | /// |
| 2385 | /// [C++0x] balanced-token: |
| 2386 | /// '(' balanced-token-seq ')' |
| 2387 | /// '[' balanced-token-seq ']' |
| 2388 | /// '{' balanced-token-seq '}' |
| 2389 | /// any token but '(', ')', '[', ']', '{', or '}' |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2390 | void Parser::ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, |
| 2391 | SourceLocation *endLoc) { |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2392 | assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) |
| 2393 | && "Not a C++0x attribute list"); |
| 2394 | |
| 2395 | SourceLocation StartLoc = Tok.getLocation(), Loc; |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2396 | |
| 2397 | ConsumeBracket(); |
| 2398 | ConsumeBracket(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2399 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2400 | if (Tok.is(tok::comma)) { |
| 2401 | Diag(Tok.getLocation(), diag::err_expected_ident); |
| 2402 | ConsumeToken(); |
| 2403 | } |
| 2404 | |
| 2405 | while (Tok.is(tok::identifier) || Tok.is(tok::comma)) { |
| 2406 | // attribute not present |
| 2407 | if (Tok.is(tok::comma)) { |
| 2408 | ConsumeToken(); |
| 2409 | continue; |
| 2410 | } |
| 2411 | |
| 2412 | IdentifierInfo *ScopeName = 0, *AttrName = Tok.getIdentifierInfo(); |
| 2413 | SourceLocation ScopeLoc, AttrLoc = ConsumeToken(); |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2414 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2415 | // scoped attribute |
| 2416 | if (Tok.is(tok::coloncolon)) { |
| 2417 | ConsumeToken(); |
| 2418 | |
| 2419 | if (!Tok.is(tok::identifier)) { |
| 2420 | Diag(Tok.getLocation(), diag::err_expected_ident); |
| 2421 | SkipUntil(tok::r_square, tok::comma, true, true); |
| 2422 | continue; |
| 2423 | } |
Kovarththanan Rajaratnam | ba2c652 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2424 | |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2425 | ScopeName = AttrName; |
| 2426 | ScopeLoc = AttrLoc; |
| 2427 | |
| 2428 | AttrName = Tok.getIdentifierInfo(); |
| 2429 | AttrLoc = ConsumeToken(); |
| 2430 | } |
| 2431 | |
| 2432 | bool AttrParsed = false; |
| 2433 | // No scoped names are supported; ideally we could put all non-standard |
| 2434 | // attributes into namespaces. |
| 2435 | if (!ScopeName) { |
| 2436 | switch(AttributeList::getKind(AttrName)) |
| 2437 | { |
| 2438 | // No arguments |
Alexis Hunt | 54a0254 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 2439 | case AttributeList::AT_carries_dependency: |
Anders Carlsson | e30621b | 2011-01-23 21:33:18 +0000 | [diff] [blame] | 2440 | case AttributeList::AT_noreturn: { |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2441 | if (Tok.is(tok::l_paren)) { |
| 2442 | Diag(Tok.getLocation(), diag::err_cxx0x_attribute_forbids_arguments) |
| 2443 | << AttrName->getName(); |
| 2444 | break; |
| 2445 | } |
| 2446 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2447 | attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, 0, |
| 2448 | SourceLocation(), 0, 0, false, true); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2449 | AttrParsed = true; |
| 2450 | break; |
| 2451 | } |
| 2452 | |
| 2453 | // One argument; must be a type-id or assignment-expression |
| 2454 | case AttributeList::AT_aligned: { |
| 2455 | if (Tok.isNot(tok::l_paren)) { |
| 2456 | Diag(Tok.getLocation(), diag::err_cxx0x_attribute_requires_arguments) |
| 2457 | << AttrName->getName(); |
| 2458 | break; |
| 2459 | } |
| 2460 | SourceLocation ParamLoc = ConsumeParen(); |
| 2461 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2462 | ExprResult ArgExpr = ParseCXX0XAlignArgument(ParamLoc); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2463 | |
| 2464 | MatchRHSPunctuation(tok::r_paren, ParamLoc); |
| 2465 | |
| 2466 | ExprVector ArgExprs(Actions); |
| 2467 | ArgExprs.push_back(ArgExpr.release()); |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2468 | attrs.addNew(AttrName, AttrLoc, 0, AttrLoc, |
| 2469 | 0, ParamLoc, ArgExprs.take(), 1, |
| 2470 | false, true); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2471 | |
| 2472 | AttrParsed = true; |
| 2473 | break; |
| 2474 | } |
| 2475 | |
| 2476 | // Silence warnings |
| 2477 | default: break; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | // Skip the entire parameter clause, if any |
| 2482 | if (!AttrParsed && Tok.is(tok::l_paren)) { |
| 2483 | ConsumeParen(); |
| 2484 | // SkipUntil maintains the balancedness of tokens. |
| 2485 | SkipUntil(tok::r_paren, false); |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) |
| 2490 | SkipUntil(tok::r_square, false); |
| 2491 | Loc = Tok.getLocation(); |
| 2492 | if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) |
| 2493 | SkipUntil(tok::r_square, false); |
| 2494 | |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2495 | attrs.Range = SourceRange(StartLoc, Loc); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | /// ParseCXX0XAlignArgument - Parse the argument to C++0x's [[align]] |
| 2499 | /// attribute. |
| 2500 | /// |
| 2501 | /// FIXME: Simply returns an alignof() expression if the argument is a |
| 2502 | /// type. Ideally, the type should be propagated directly into Sema. |
| 2503 | /// |
| 2504 | /// [C++0x] 'align' '(' type-id ')' |
| 2505 | /// [C++0x] 'align' '(' assignment-expression ')' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2506 | ExprResult Parser::ParseCXX0XAlignArgument(SourceLocation Start) { |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2507 | if (isTypeIdInParens()) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2508 | EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2509 | SourceLocation TypeLoc = Tok.getLocation(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2510 | ParsedType Ty = ParseTypeName().get(); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2511 | SourceRange TypeRange(Start, Tok.getLocation()); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 2512 | return Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, |
| 2513 | Ty.getAsOpaquePtr(), TypeRange); |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2514 | } else |
| 2515 | return ParseConstantExpression(); |
| 2516 | } |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 2517 | |
| 2518 | /// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr] |
| 2519 | /// |
| 2520 | /// [MS] ms-attribute: |
| 2521 | /// '[' token-seq ']' |
| 2522 | /// |
| 2523 | /// [MS] ms-attribute-seq: |
| 2524 | /// ms-attribute[opt] |
| 2525 | /// ms-attribute ms-attribute-seq |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2526 | void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, |
| 2527 | SourceLocation *endLoc) { |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 2528 | assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); |
| 2529 | |
| 2530 | while (Tok.is(tok::l_square)) { |
| 2531 | ConsumeBracket(); |
| 2532 | SkipUntil(tok::r_square, true, true); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2533 | if (endLoc) *endLoc = Tok.getLocation(); |
Francois Pichet | c2bc5ac | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 2534 | ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); |
| 2535 | } |
| 2536 | } |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame^] | 2537 | |
| 2538 | void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, |
| 2539 | AccessSpecifier& CurAS) { |
| 2540 | bool Result; |
| 2541 | if (ParseMicrosoftIfExistsCondition(Result)) |
| 2542 | return; |
| 2543 | |
| 2544 | if (Tok.isNot(tok::l_brace)) { |
| 2545 | Diag(Tok, diag::err_expected_lbrace); |
| 2546 | return; |
| 2547 | } |
| 2548 | ConsumeBrace(); |
| 2549 | |
| 2550 | // Condition is false skip all inside the {}. |
| 2551 | if (!Result) { |
| 2552 | SkipUntil(tok::r_brace, false); |
| 2553 | return; |
| 2554 | } |
| 2555 | |
| 2556 | // Condition is true, parse the declaration. |
| 2557 | while (Tok.isNot(tok::r_brace)) { |
| 2558 | |
| 2559 | // __if_exists, __if_not_exists can nest. |
| 2560 | if ((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists))) { |
| 2561 | ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); |
| 2562 | continue; |
| 2563 | } |
| 2564 | |
| 2565 | // Check for extraneous top-level semicolon. |
| 2566 | if (Tok.is(tok::semi)) { |
| 2567 | Diag(Tok, diag::ext_extra_struct_semi) |
| 2568 | << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) |
| 2569 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 2570 | ConsumeToken(); |
| 2571 | continue; |
| 2572 | } |
| 2573 | |
| 2574 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 2575 | if (AS != AS_none) { |
| 2576 | // Current token is a C++ access specifier. |
| 2577 | CurAS = AS; |
| 2578 | SourceLocation ASLoc = Tok.getLocation(); |
| 2579 | ConsumeToken(); |
| 2580 | if (Tok.is(tok::colon)) |
| 2581 | Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); |
| 2582 | else |
| 2583 | Diag(Tok, diag::err_expected_colon); |
| 2584 | ConsumeToken(); |
| 2585 | continue; |
| 2586 | } |
| 2587 | |
| 2588 | // Parse all the comma separated declarators. |
| 2589 | ParseCXXClassMemberDeclaration(CurAS); |
| 2590 | } |
| 2591 | |
| 2592 | if (Tok.isNot(tok::r_brace)) { |
| 2593 | Diag(Tok, diag::err_expected_rbrace); |
| 2594 | return; |
| 2595 | } |
| 2596 | ConsumeBrace(); |
| 2597 | } |