Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 1 | //===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C++ Declaration portions of the Parser interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Anders Carlsson | 0c6139d | 2009-06-27 00:27:47 +0000 | [diff] [blame] | 14 | #include "clang/Basic/OperatorKinds.h" |
Douglas Gregor | 1b7f898 | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 16 | #include "clang/Parse/ParseDiagnostic.h" |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 17 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 18 | #include "clang/Parse/Scope.h" |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 19 | #include "clang/Parse/Template.h" |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 20 | #include "ExtensionRAIIObject.h" |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | /// ParseNamespace - We know that the current token is a namespace keyword. This |
| 24 | /// may either be a top level namespace or a block-level namespace alias. |
| 25 | /// |
| 26 | /// namespace-definition: [C++ 7.3: basic.namespace] |
| 27 | /// named-namespace-definition |
| 28 | /// unnamed-namespace-definition |
| 29 | /// |
| 30 | /// unnamed-namespace-definition: |
| 31 | /// 'namespace' attributes[opt] '{' namespace-body '}' |
| 32 | /// |
| 33 | /// named-namespace-definition: |
| 34 | /// original-namespace-definition |
| 35 | /// extension-namespace-definition |
| 36 | /// |
| 37 | /// original-namespace-definition: |
| 38 | /// 'namespace' identifier attributes[opt] '{' namespace-body '}' |
| 39 | /// |
| 40 | /// extension-namespace-definition: |
| 41 | /// 'namespace' original-namespace-name '{' namespace-body '}' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | /// |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 43 | /// namespace-alias-definition: [C++ 7.3.2: namespace.alias] |
| 44 | /// 'namespace' identifier '=' qualified-namespace-specifier ';' |
| 45 | /// |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 46 | Parser::DeclPtrTy Parser::ParseNamespace(unsigned Context, |
| 47 | SourceLocation &DeclEnd) { |
Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 48 | assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 49 | SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 50 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 51 | if (Tok.is(tok::code_completion)) { |
| 52 | Actions.CodeCompleteNamespaceDecl(CurScope); |
| 53 | ConsumeToken(); |
| 54 | } |
| 55 | |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 56 | SourceLocation IdentLoc; |
| 57 | IdentifierInfo *Ident = 0; |
Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 58 | |
| 59 | Token attrTok; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 61 | if (Tok.is(tok::identifier)) { |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 62 | Ident = Tok.getIdentifierInfo(); |
| 63 | IdentLoc = ConsumeToken(); // eat the identifier. |
| 64 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 66 | // Read label attributes, if present. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 67 | Action::AttrTy *AttrList = 0; |
Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 68 | if (Tok.is(tok::kw___attribute)) { |
| 69 | attrTok = Tok; |
| 70 | |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 71 | // FIXME: save these somewhere. |
| 72 | AttrList = ParseAttributes(); |
Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 73 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 74 | |
Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 75 | if (Tok.is(tok::equal)) { |
| 76 | if (AttrList) |
| 77 | Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); |
| 78 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 79 | return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); |
Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 80 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 82 | if (Tok.isNot(tok::l_brace)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 83 | Diag(Tok, Ident ? diag::err_expected_lbrace : |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 84 | diag::err_expected_ident_lbrace); |
| 85 | return DeclPtrTy(); |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 86 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 88 | SourceLocation LBrace = ConsumeBrace(); |
| 89 | |
| 90 | // Enter a scope for the namespace. |
| 91 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 92 | |
| 93 | DeclPtrTy NamespcDecl = |
| 94 | Actions.ActOnStartNamespaceDef(CurScope, IdentLoc, Ident, LBrace); |
| 95 | |
| 96 | PrettyStackTraceActionsDecl CrashInfo(NamespcDecl, NamespaceLoc, Actions, |
| 97 | PP.getSourceManager(), |
| 98 | "parsing namespace"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 100 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) |
| 101 | ParseExternalDeclaration(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 103 | // Leave the namespace scope. |
| 104 | NamespaceScope.Exit(); |
| 105 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 106 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace); |
| 107 | Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 108 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 109 | DeclEnd = RBraceLoc; |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 110 | return NamespcDecl; |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 111 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 112 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 113 | /// ParseNamespaceAlias - Parse the part after the '=' in a namespace |
| 114 | /// alias definition. |
| 115 | /// |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 116 | Parser::DeclPtrTy Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | SourceLocation AliasLoc, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 118 | IdentifierInfo *Alias, |
| 119 | SourceLocation &DeclEnd) { |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 120 | assert(Tok.is(tok::equal) && "Not equal token"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 122 | ConsumeToken(); // eat the '='. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 124 | if (Tok.is(tok::code_completion)) { |
| 125 | Actions.CodeCompleteNamespaceAliasDecl(CurScope); |
| 126 | ConsumeToken(); |
| 127 | } |
| 128 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 129 | CXXScopeSpec SS; |
| 130 | // Parse (optional) nested-name-specifier. |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 131 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 132 | |
| 133 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
| 134 | Diag(Tok, diag::err_expected_namespace_name); |
| 135 | // Skip to end of the definition and eat the ';'. |
| 136 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 137 | return DeclPtrTy(); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // Parse identifier. |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 141 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 142 | SourceLocation IdentLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 144 | // Eat the ';'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 145 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 146 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name, |
| 147 | "", tok::semi); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
| 149 | return Actions.ActOnNamespaceAliasDef(CurScope, NamespaceLoc, AliasLoc, Alias, |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 150 | SS, IdentLoc, Ident); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 153 | /// ParseLinkage - We know that the current token is a string_literal |
| 154 | /// and just before that, that extern was seen. |
| 155 | /// |
| 156 | /// linkage-specification: [C++ 7.5p2: dcl.link] |
| 157 | /// 'extern' string-literal '{' declaration-seq[opt] '}' |
| 158 | /// 'extern' string-literal declaration |
| 159 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 160 | Parser::DeclPtrTy Parser::ParseLinkage(unsigned Context) { |
Douglas Gregor | c19923d | 2008-11-21 16:10:08 +0000 | [diff] [blame] | 161 | assert(Tok.is(tok::string_literal) && "Not a string literal!"); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 162 | llvm::SmallVector<char, 8> LangBuffer; |
| 163 | // LangBuffer is guaranteed to be big enough. |
| 164 | LangBuffer.resize(Tok.getLength()); |
| 165 | const char *LangBufPtr = &LangBuffer[0]; |
| 166 | unsigned StrSize = PP.getSpelling(Tok, LangBufPtr); |
| 167 | |
| 168 | SourceLocation Loc = ConsumeStringToken(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 169 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 170 | ParseScope LinkageScope(this, Scope::DeclScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | DeclPtrTy LinkageSpec |
| 172 | = Actions.ActOnStartLinkageSpecification(CurScope, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 173 | /*FIXME: */SourceLocation(), |
| 174 | Loc, LangBufPtr, StrSize, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | Tok.is(tok::l_brace)? Tok.getLocation() |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 176 | : SourceLocation()); |
| 177 | |
| 178 | if (Tok.isNot(tok::l_brace)) { |
| 179 | ParseDeclarationOrFunctionDefinition(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 181 | SourceLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | } |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 183 | |
| 184 | SourceLocation LBrace = ConsumeBrace(); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 185 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 186 | ParseExternalDeclaration(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 189 | SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace); |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 190 | return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec, RBrace); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 191 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 192 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 193 | /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or |
| 194 | /// using-directive. Assumes that current token is 'using'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 195 | Parser::DeclPtrTy Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, |
| 196 | SourceLocation &DeclEnd) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 197 | assert(Tok.is(tok::kw_using) && "Not using token"); |
| 198 | |
| 199 | // Eat 'using'. |
| 200 | SourceLocation UsingLoc = ConsumeToken(); |
| 201 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 202 | if (Tok.is(tok::code_completion)) { |
| 203 | Actions.CodeCompleteUsing(CurScope); |
| 204 | ConsumeToken(); |
| 205 | } |
| 206 | |
Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 207 | if (Tok.is(tok::kw_namespace)) |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 208 | // Next token after 'using' is 'namespace' so it must be using-directive |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 209 | return ParseUsingDirective(Context, UsingLoc, DeclEnd); |
Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 210 | |
| 211 | // Otherwise, it must be using-declaration. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 212 | return ParseUsingDeclaration(Context, UsingLoc, DeclEnd); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /// ParseUsingDirective - Parse C++ using-directive, assumes |
| 216 | /// that current token is 'namespace' and 'using' was already parsed. |
| 217 | /// |
| 218 | /// using-directive: [C++ 7.3.p4: namespace.udir] |
| 219 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 220 | /// namespace-name ; |
| 221 | /// [GNU] using-directive: |
| 222 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 223 | /// namespace-name attributes[opt] ; |
| 224 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 225 | Parser::DeclPtrTy Parser::ParseUsingDirective(unsigned Context, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 226 | SourceLocation UsingLoc, |
| 227 | SourceLocation &DeclEnd) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 228 | assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); |
| 229 | |
| 230 | // Eat 'namespace'. |
| 231 | SourceLocation NamespcLoc = ConsumeToken(); |
| 232 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 233 | if (Tok.is(tok::code_completion)) { |
| 234 | Actions.CodeCompleteUsingDirective(CurScope); |
| 235 | ConsumeToken(); |
| 236 | } |
| 237 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 238 | CXXScopeSpec SS; |
| 239 | // Parse (optional) nested-name-specifier. |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 240 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 241 | |
| 242 | AttributeList *AttrList = 0; |
| 243 | IdentifierInfo *NamespcName = 0; |
| 244 | SourceLocation IdentLoc = SourceLocation(); |
| 245 | |
| 246 | // Parse namespace-name. |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 247 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 248 | Diag(Tok, diag::err_expected_namespace_name); |
| 249 | // If there was invalid namespace name, skip to end of decl, and eat ';'. |
| 250 | SkipUntil(tok::semi); |
| 251 | // FIXME: Are there cases, when we would like to call ActOnUsingDirective? |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 252 | return DeclPtrTy(); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 253 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 254 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 255 | // Parse identifier. |
| 256 | NamespcName = Tok.getIdentifierInfo(); |
| 257 | IdentLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 258 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 259 | // Parse (optional) attributes (most likely GNU strong-using extension). |
| 260 | if (Tok.is(tok::kw___attribute)) |
| 261 | AttrList = ParseAttributes(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 263 | // Eat ';'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 264 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 265 | ExpectAndConsume(tok::semi, |
| 266 | AttrList ? diag::err_expected_semi_after_attribute_list : |
| 267 | diag::err_expected_semi_after_namespace_name, "", tok::semi); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 268 | |
| 269 | return Actions.ActOnUsingDirective(CurScope, UsingLoc, NamespcLoc, SS, |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 270 | IdentLoc, NamespcName, AttrList); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /// ParseUsingDeclaration - Parse C++ using-declaration. Assumes that |
| 274 | /// 'using' was already seen. |
| 275 | /// |
| 276 | /// using-declaration: [C++ 7.3.p3: namespace.udecl] |
| 277 | /// 'using' 'typename'[opt] ::[opt] nested-name-specifier |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 278 | /// unqualified-id |
| 279 | /// 'using' :: unqualified-id |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 280 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 281 | Parser::DeclPtrTy Parser::ParseUsingDeclaration(unsigned Context, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 282 | SourceLocation UsingLoc, |
Anders Carlsson | 595adc1 | 2009-08-29 19:54:19 +0000 | [diff] [blame] | 283 | SourceLocation &DeclEnd, |
| 284 | AccessSpecifier AS) { |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 285 | CXXScopeSpec SS; |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 286 | SourceLocation TypenameLoc; |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 287 | bool IsTypeName; |
| 288 | |
| 289 | // Ignore optional 'typename'. |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 290 | // FIXME: This is wrong; we should parse this as a typename-specifier. |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 291 | if (Tok.is(tok::kw_typename)) { |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 292 | TypenameLoc = Tok.getLocation(); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 293 | ConsumeToken(); |
| 294 | IsTypeName = true; |
| 295 | } |
| 296 | else |
| 297 | IsTypeName = false; |
| 298 | |
| 299 | // Parse nested-name-specifier. |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 300 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 301 | |
| 302 | AttributeList *AttrList = 0; |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 303 | |
| 304 | // Check nested-name specifier. |
| 305 | if (SS.isInvalid()) { |
| 306 | SkipUntil(tok::semi); |
| 307 | return DeclPtrTy(); |
| 308 | } |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 309 | |
| 310 | // Parse the unqualified-id. We allow parsing of both constructor and |
| 311 | // destructor names and allow the action module to diagnose any semantic |
| 312 | // errors. |
| 313 | UnqualifiedId Name; |
| 314 | if (ParseUnqualifiedId(SS, |
| 315 | /*EnteringContext=*/false, |
| 316 | /*AllowDestructorName=*/true, |
| 317 | /*AllowConstructorName=*/true, |
| 318 | /*ObjectType=*/0, |
| 319 | Name)) { |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 320 | SkipUntil(tok::semi); |
| 321 | return DeclPtrTy(); |
| 322 | } |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 324 | // Parse (optional) attributes (most likely GNU strong-using extension). |
| 325 | if (Tok.is(tok::kw___attribute)) |
| 326 | AttrList = ParseAttributes(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 328 | // Eat ';'. |
| 329 | DeclEnd = Tok.getLocation(); |
| 330 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 331 | AttrList ? "attributes list" : "using declaration", |
| 332 | tok::semi); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 333 | |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 334 | return Actions.ActOnUsingDeclaration(CurScope, AS, UsingLoc, SS, Name, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 335 | AttrList, IsTypeName, TypenameLoc); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 338 | /// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion. |
| 339 | /// |
| 340 | /// static_assert-declaration: |
| 341 | /// static_assert ( constant-expression , string-literal ) ; |
| 342 | /// |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 343 | Parser::DeclPtrTy Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 344 | assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration"); |
| 345 | SourceLocation StaticAssertLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 347 | if (Tok.isNot(tok::l_paren)) { |
| 348 | Diag(Tok, diag::err_expected_lparen); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 349 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 350 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 352 | SourceLocation LParenLoc = ConsumeParen(); |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 353 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 354 | OwningExprResult AssertExpr(ParseConstantExpression()); |
| 355 | if (AssertExpr.isInvalid()) { |
| 356 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 357 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 360 | if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 361 | return DeclPtrTy(); |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 362 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 363 | if (Tok.isNot(tok::string_literal)) { |
| 364 | Diag(Tok, diag::err_expected_string_literal); |
| 365 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 366 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 367 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 369 | OwningExprResult AssertMessage(ParseStringLiteralExpression()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | if (AssertMessage.isInvalid()) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 371 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 372 | |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 373 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 375 | DeclEnd = Tok.getLocation(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 376 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert); |
| 377 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, move(AssertExpr), |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 379 | move(AssertMessage)); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 382 | /// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. |
| 383 | /// |
| 384 | /// 'decltype' ( expression ) |
| 385 | /// |
| 386 | void Parser::ParseDecltypeSpecifier(DeclSpec &DS) { |
| 387 | assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier"); |
| 388 | |
| 389 | SourceLocation StartLoc = ConsumeToken(); |
| 390 | SourceLocation LParenLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | |
| 392 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 393 | "decltype")) { |
| 394 | SkipUntil(tok::r_paren); |
| 395 | return; |
| 396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 398 | // Parse the expression |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 400 | // C++0x [dcl.type.simple]p4: |
| 401 | // The operand of the decltype specifier is an unevaluated operand. |
| 402 | EnterExpressionEvaluationContext Unevaluated(Actions, |
| 403 | Action::Unevaluated); |
| 404 | OwningExprResult Result = ParseExpression(); |
| 405 | if (Result.isInvalid()) { |
| 406 | SkipUntil(tok::r_paren); |
| 407 | return; |
| 408 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 409 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 410 | // Match the ')' |
| 411 | SourceLocation RParenLoc; |
| 412 | if (Tok.is(tok::r_paren)) |
| 413 | RParenLoc = ConsumeParen(); |
| 414 | else |
| 415 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 417 | if (RParenLoc.isInvalid()) |
| 418 | return; |
| 419 | |
| 420 | const char *PrevSpec = 0; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 421 | unsigned DiagID; |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 422 | // Check for duplicate type specifiers (e.g. "int decltype(a)"). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 424 | DiagID, Result.release())) |
| 425 | Diag(StartLoc, DiagID) << PrevSpec; |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 428 | /// ParseClassName - Parse a C++ class-name, which names a class. Note |
| 429 | /// that we only check that the result names a type; semantic analysis |
| 430 | /// will need to verify that the type names a class. The result is |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 431 | /// either a type or NULL, depending on whether a type name was |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 432 | /// found. |
| 433 | /// |
| 434 | /// class-name: [C++ 9.1] |
| 435 | /// identifier |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 436 | /// simple-template-id |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | /// |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 438 | Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, |
Fariborz Jahanian | d33c868 | 2009-07-20 17:43:15 +0000 | [diff] [blame] | 439 | const CXXScopeSpec *SS, |
| 440 | bool DestrExpected) { |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 441 | // Check whether we have a template-id that names a type. |
| 442 | if (Tok.is(tok::annot_template_id)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 443 | TemplateIdAnnotation *TemplateId |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 444 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 445 | if (TemplateId->Kind == TNK_Type_template) { |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 446 | AnnotateTemplateIdTokenAsType(SS); |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 447 | |
| 448 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 449 | TypeTy *Type = Tok.getAnnotationValue(); |
| 450 | EndLocation = Tok.getAnnotationEndLoc(); |
| 451 | ConsumeToken(); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 452 | |
| 453 | if (Type) |
| 454 | return Type; |
| 455 | return true; |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | // Fall through to produce an error below. |
| 459 | } |
| 460 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 461 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 462 | Diag(Tok, diag::err_expected_class_name); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 463 | return true; |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | // We have an identifier; check whether it is actually a type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 467 | TypeTy *Type = Actions.getTypeName(*Tok.getIdentifierInfo(), |
Douglas Gregor | 42c39f3 | 2009-08-26 18:27:52 +0000 | [diff] [blame] | 468 | Tok.getLocation(), CurScope, SS, |
| 469 | true); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 470 | if (!Type) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 471 | Diag(Tok, DestrExpected ? diag::err_destructor_class_name |
Fariborz Jahanian | d33c868 | 2009-07-20 17:43:15 +0000 | [diff] [blame] | 472 | : diag::err_expected_class_name); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 473 | return true; |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // Consume the identifier. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 477 | EndLocation = ConsumeToken(); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 478 | return Type; |
| 479 | } |
| 480 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 481 | /// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or |
| 482 | /// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which |
| 483 | /// until we reach the start of a definition or see a token that |
| 484 | /// cannot start a definition. |
| 485 | /// |
| 486 | /// class-specifier: [C++ class] |
| 487 | /// class-head '{' member-specification[opt] '}' |
| 488 | /// class-head '{' member-specification[opt] '}' attributes[opt] |
| 489 | /// class-head: |
| 490 | /// class-key identifier[opt] base-clause[opt] |
| 491 | /// class-key nested-name-specifier identifier base-clause[opt] |
| 492 | /// class-key nested-name-specifier[opt] simple-template-id |
| 493 | /// base-clause[opt] |
| 494 | /// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | /// [GNU] class-key attributes[opt] nested-name-specifier |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 496 | /// identifier base-clause[opt] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | /// [GNU] class-key attributes[opt] nested-name-specifier[opt] |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 498 | /// simple-template-id base-clause[opt] |
| 499 | /// class-key: |
| 500 | /// 'class' |
| 501 | /// 'struct' |
| 502 | /// 'union' |
| 503 | /// |
| 504 | /// elaborated-type-specifier: [C++ dcl.type.elab] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 505 | /// class-key ::[opt] nested-name-specifier[opt] identifier |
| 506 | /// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] |
| 507 | /// simple-template-id |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 508 | /// |
| 509 | /// Note that the C++ class-specifier and elaborated-type-specifier, |
| 510 | /// together, subsume the C99 struct-or-union-specifier: |
| 511 | /// |
| 512 | /// struct-or-union-specifier: [C99 6.7.2.1] |
| 513 | /// struct-or-union identifier[opt] '{' struct-contents '}' |
| 514 | /// struct-or-union identifier |
| 515 | /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents |
| 516 | /// '}' attributes[opt] |
| 517 | /// [GNU] struct-or-union attributes[opt] identifier |
| 518 | /// struct-or-union: |
| 519 | /// 'struct' |
| 520 | /// 'union' |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 521 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, |
| 522 | SourceLocation StartLoc, DeclSpec &DS, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 523 | const ParsedTemplateInfo &TemplateInfo, |
Douglas Gregor | 06c0fec | 2009-03-25 22:00:53 +0000 | [diff] [blame] | 524 | AccessSpecifier AS) { |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 525 | DeclSpec::TST TagType; |
| 526 | if (TagTokKind == tok::kw_struct) |
| 527 | TagType = DeclSpec::TST_struct; |
| 528 | else if (TagTokKind == tok::kw_class) |
| 529 | TagType = DeclSpec::TST_class; |
| 530 | else { |
| 531 | assert(TagTokKind == tok::kw_union && "Not a class specifier"); |
| 532 | TagType = DeclSpec::TST_union; |
| 533 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 534 | |
Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 535 | if (Tok.is(tok::code_completion)) { |
| 536 | // Code completion for a struct, class, or union name. |
| 537 | Actions.CodeCompleteTag(CurScope, TagType); |
| 538 | ConsumeToken(); |
| 539 | } |
| 540 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 541 | AttributeList *Attr = 0; |
| 542 | // If attributes exist after tag, parse them. |
| 543 | if (Tok.is(tok::kw___attribute)) |
| 544 | Attr = ParseAttributes(); |
| 545 | |
Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 546 | // If declspecs exist after tag, parse them. |
Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 547 | if (Tok.is(tok::kw___declspec)) |
| 548 | Attr = ParseMicrosoftDeclSpec(Attr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 550 | if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_pod)) { |
| 551 | // GNU libstdc++ 4.2 uses __is_pod as the name of a struct template, but |
| 552 | // __is_pod is a keyword in GCC >= 4.3. Therefore, when we see the |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | // token sequence "struct __is_pod", make __is_pod into a normal |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 554 | // identifier rather than a keyword, to allow libstdc++ 4.2 to work |
| 555 | // properly. |
| 556 | Tok.getIdentifierInfo()->setTokenID(tok::identifier); |
| 557 | Tok.setKind(tok::identifier); |
| 558 | } |
| 559 | |
| 560 | if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_empty)) { |
| 561 | // GNU libstdc++ 4.2 uses __is_empty as the name of a struct template, but |
| 562 | // __is_empty is a keyword in GCC >= 4.3. Therefore, when we see the |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 563 | // token sequence "struct __is_empty", make __is_empty into a normal |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 564 | // identifier rather than a keyword, to allow libstdc++ 4.2 to work |
| 565 | // properly. |
| 566 | Tok.getIdentifierInfo()->setTokenID(tok::identifier); |
| 567 | Tok.setKind(tok::identifier); |
| 568 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 570 | // Parse the (optional) nested-name-specifier. |
| 571 | CXXScopeSpec SS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 572 | if (getLang().CPlusPlus && |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 573 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true)) |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 574 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 575 | Diag(Tok, diag::err_expected_ident); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 576 | |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 577 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 578 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 579 | // Parse the (optional) class name or simple-template-id. |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 580 | IdentifierInfo *Name = 0; |
| 581 | SourceLocation NameLoc; |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 582 | TemplateIdAnnotation *TemplateId = 0; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 583 | if (Tok.is(tok::identifier)) { |
| 584 | Name = Tok.getIdentifierInfo(); |
| 585 | NameLoc = ConsumeToken(); |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 586 | |
| 587 | if (Tok.is(tok::less)) { |
| 588 | // The name was supposed to refer to a template, but didn't. |
| 589 | // Eat the template argument list and try to continue parsing this as |
| 590 | // a class (or template thereof). |
| 591 | TemplateArgList TemplateArgs; |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 592 | SourceLocation LAngleLoc, RAngleLoc; |
| 593 | if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, &SS, |
| 594 | true, LAngleLoc, |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 595 | TemplateArgs, RAngleLoc)) { |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 596 | // We couldn't parse the template argument list at all, so don't |
| 597 | // try to give any location information for the list. |
| 598 | LAngleLoc = RAngleLoc = SourceLocation(); |
| 599 | } |
| 600 | |
| 601 | Diag(NameLoc, diag::err_explicit_spec_non_template) |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 602 | << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 603 | << (TagType == DeclSpec::TST_class? 0 |
| 604 | : TagType == DeclSpec::TST_struct? 1 |
| 605 | : 2) |
| 606 | << Name |
| 607 | << SourceRange(LAngleLoc, RAngleLoc); |
| 608 | |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 609 | // Strip off the last template parameter list if it was empty, since |
| 610 | // we've removed its template argument list. |
| 611 | if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { |
| 612 | if (TemplateParams && TemplateParams->size() > 1) { |
| 613 | TemplateParams->pop_back(); |
| 614 | } else { |
| 615 | TemplateParams = 0; |
| 616 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
| 617 | = ParsedTemplateInfo::NonTemplate; |
| 618 | } |
| 619 | } else if (TemplateInfo.Kind |
| 620 | == ParsedTemplateInfo::ExplicitInstantiation) { |
| 621 | // Pretend this is just a forward declaration. |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 622 | TemplateParams = 0; |
| 623 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
| 624 | = ParsedTemplateInfo::NonTemplate; |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 625 | const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc |
| 626 | = SourceLocation(); |
| 627 | const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc |
| 628 | = SourceLocation(); |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 629 | } |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 630 | |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 631 | |
| 632 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 633 | } else if (Tok.is(tok::annot_template_id)) { |
| 634 | TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
| 635 | NameLoc = ConsumeToken(); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 637 | if (TemplateId->Kind != TNK_Type_template) { |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 638 | // The template-name in the simple-template-id refers to |
| 639 | // something other than a class template. Give an appropriate |
| 640 | // error message and skip to the ';'. |
| 641 | SourceRange Range(NameLoc); |
| 642 | if (SS.isNotEmpty()) |
| 643 | Range.setBegin(SS.getBeginLoc()); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 644 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 645 | Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) |
| 646 | << Name << static_cast<int>(TemplateId->Kind) << Range; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 647 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 648 | DS.SetTypeSpecError(); |
| 649 | SkipUntil(tok::semi, false, true); |
| 650 | TemplateId->Destroy(); |
| 651 | return; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 652 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 653 | } |
| 654 | |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 655 | // There are four options here. If we have 'struct foo;', then this |
| 656 | // is either a forward declaration or a friend declaration, which |
| 657 | // have to be treated differently. If we have 'struct foo {...' or |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 658 | // 'struct foo :...' then this is a definition. Otherwise we have |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 659 | // something like 'struct foo xyz', a reference. |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 660 | Action::TagUseKind TUK; |
Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 661 | if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon))) { |
| 662 | if (DS.isFriendSpecified()) { |
| 663 | // C++ [class.friend]p2: |
| 664 | // A class shall not be defined in a friend declaration. |
| 665 | Diag(Tok.getLocation(), diag::err_friend_decl_defines_class) |
| 666 | << SourceRange(DS.getFriendSpecLoc()); |
| 667 | |
| 668 | // Skip everything up to the semicolon, so that this looks like a proper |
| 669 | // friend class (or template thereof) declaration. |
| 670 | SkipUntil(tok::semi, true, true); |
| 671 | TUK = Action::TUK_Friend; |
| 672 | } else { |
| 673 | // Okay, this is a class definition. |
| 674 | TUK = Action::TUK_Definition; |
| 675 | } |
| 676 | } else if (Tok.is(tok::semi)) |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 677 | TUK = DS.isFriendSpecified() ? Action::TUK_Friend : Action::TUK_Declaration; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 678 | else |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 679 | TUK = Action::TUK_Reference; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 680 | |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 681 | if (!Name && !TemplateId && TUK != Action::TUK_Definition) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 682 | // We have a declaration or reference to an anonymous class. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 683 | Diag(StartLoc, diag::err_anon_type_definition) |
| 684 | << DeclSpec::getSpecifierName(TagType); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 685 | |
| 686 | // Skip the rest of this declarator, up until the comma or semicolon. |
| 687 | SkipUntil(tok::comma, true); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 688 | |
| 689 | if (TemplateId) |
| 690 | TemplateId->Destroy(); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 691 | return; |
| 692 | } |
| 693 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 694 | // Create the tag portion of the class or class template. |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 695 | Action::DeclResult TagOrTempResult = true; // invalid |
| 696 | Action::TypeResult TypeResult = true; // invalid |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 697 | |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 698 | // FIXME: When TUK == TUK_Reference and we have a template-id, we need |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 699 | // to turn that template-id into a type. |
| 700 | |
Douglas Gregor | 402abb5 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 701 | bool Owned = false; |
John McCall | f1bbbb4 | 2009-09-04 01:14:41 +0000 | [diff] [blame] | 702 | if (TemplateId) { |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 703 | // Explicit specialization, class template partial specialization, |
| 704 | // or explicit instantiation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | ASTTemplateArgsPtr TemplateArgsPtr(Actions, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 706 | TemplateId->getTemplateArgs(), |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 707 | TemplateId->NumArgs); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 708 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 709 | TUK == Action::TUK_Declaration) { |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 710 | // This is an explicit instantiation of a class template. |
| 711 | TagOrTempResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | = Actions.ActOnExplicitInstantiation(CurScope, |
Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 713 | TemplateInfo.ExternLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | TemplateInfo.TemplateLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 715 | TagType, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | StartLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 717 | SS, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | TemplateTy::make(TemplateId->Template), |
| 719 | TemplateId->TemplateNameLoc, |
| 720 | TemplateId->LAngleLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 721 | TemplateArgsPtr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | TemplateId->RAngleLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 723 | Attr); |
Douglas Gregor | fc9cd61 | 2009-09-26 20:57:03 +0000 | [diff] [blame] | 724 | } else if (TUK == Action::TUK_Reference) { |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 725 | TypeResult |
John McCall | 6b2becf | 2009-09-08 17:47:29 +0000 | [diff] [blame] | 726 | = Actions.ActOnTemplateIdType(TemplateTy::make(TemplateId->Template), |
| 727 | TemplateId->TemplateNameLoc, |
| 728 | TemplateId->LAngleLoc, |
| 729 | TemplateArgsPtr, |
John McCall | 6b2becf | 2009-09-08 17:47:29 +0000 | [diff] [blame] | 730 | TemplateId->RAngleLoc); |
| 731 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 732 | TypeResult = Actions.ActOnTagTemplateIdType(TypeResult, TUK, |
| 733 | TagType, StartLoc); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 734 | } else { |
| 735 | // This is an explicit specialization or a class template |
| 736 | // partial specialization. |
| 737 | TemplateParameterLists FakedParamLists; |
| 738 | |
| 739 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 740 | // This looks like an explicit instantiation, because we have |
| 741 | // something like |
| 742 | // |
| 743 | // template class Foo<X> |
| 744 | // |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 745 | // but it actually has a definition. Most likely, this was |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 746 | // meant to be an explicit specialization, but the user forgot |
| 747 | // the '<>' after 'template'. |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 748 | assert(TUK == Action::TUK_Definition && "Expected a definition here"); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 749 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | SourceLocation LAngleLoc |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 751 | = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | Diag(TemplateId->TemplateNameLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 753 | diag::err_explicit_instantiation_with_definition) |
| 754 | << SourceRange(TemplateInfo.TemplateLoc) |
| 755 | << CodeModificationHint::CreateInsertion(LAngleLoc, "<>"); |
| 756 | |
| 757 | // Create a fake template parameter list that contains only |
| 758 | // "template<>", so that we treat this construct as a class |
| 759 | // template specialization. |
| 760 | FakedParamLists.push_back( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | Actions.ActOnTemplateParameterList(0, SourceLocation(), |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 762 | TemplateInfo.TemplateLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 763 | LAngleLoc, |
| 764 | 0, 0, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 765 | LAngleLoc)); |
| 766 | TemplateParams = &FakedParamLists; |
| 767 | } |
| 768 | |
| 769 | // Build the class template specialization. |
| 770 | TagOrTempResult |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 771 | = Actions.ActOnClassTemplateSpecialization(CurScope, TagType, TUK, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 772 | StartLoc, SS, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | TemplateTy::make(TemplateId->Template), |
| 774 | TemplateId->TemplateNameLoc, |
| 775 | TemplateId->LAngleLoc, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 776 | TemplateArgsPtr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | TemplateId->RAngleLoc, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 778 | Attr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | Action::MultiTemplateParamsArg(Actions, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 780 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 781 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 782 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 783 | TemplateId->Destroy(); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 784 | } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 785 | TUK == Action::TUK_Declaration) { |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 786 | // Explicit instantiation of a member of a class template |
| 787 | // specialization, e.g., |
| 788 | // |
| 789 | // template struct Outer<int>::Inner; |
| 790 | // |
| 791 | TagOrTempResult |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 792 | = Actions.ActOnExplicitInstantiation(CurScope, |
Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 793 | TemplateInfo.ExternLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | TemplateInfo.TemplateLoc, |
| 795 | TagType, StartLoc, SS, Name, |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 796 | NameLoc, Attr); |
| 797 | } else { |
| 798 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 799 | TUK == Action::TUK_Definition) { |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 800 | // FIXME: Diagnose this particular error. |
| 801 | } |
| 802 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 803 | bool IsDependent = false; |
| 804 | |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 805 | // Declaration or definition of a class type |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | TagOrTempResult = Actions.ActOnTag(CurScope, TagType, TUK, StartLoc, SS, |
Douglas Gregor | 7cdbc58 | 2009-07-22 23:48:44 +0000 | [diff] [blame] | 807 | Name, NameLoc, Attr, AS, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 808 | Action::MultiTemplateParamsArg(Actions, |
Douglas Gregor | 7cdbc58 | 2009-07-22 23:48:44 +0000 | [diff] [blame] | 809 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 810 | TemplateParams? TemplateParams->size() : 0), |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 811 | Owned, IsDependent); |
| 812 | |
| 813 | // If ActOnTag said the type was dependent, try again with the |
| 814 | // less common call. |
| 815 | if (IsDependent) |
| 816 | TypeResult = Actions.ActOnDependentTag(CurScope, TagType, TUK, |
| 817 | SS, Name, StartLoc, NameLoc); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 818 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 819 | |
| 820 | // Parse the optional base clause (C++ only). |
Chris Lattner | 22bd905 | 2009-02-16 22:07:16 +0000 | [diff] [blame] | 821 | if (getLang().CPlusPlus && Tok.is(tok::colon)) |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 822 | ParseBaseClause(TagOrTempResult.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 823 | |
| 824 | // If there is a body, parse it and inform the actions module. |
| 825 | if (Tok.is(tok::l_brace)) |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 826 | if (getLang().CPlusPlus) |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 827 | ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get()); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 828 | else |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 829 | ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 830 | else if (TUK == Action::TUK_Definition) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 831 | // FIXME: Complain that we have a base-specifier list but no |
| 832 | // definition. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 833 | Diag(Tok, diag::err_expected_lbrace); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 834 | } |
| 835 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 836 | void *Result; |
| 837 | if (!TypeResult.isInvalid()) { |
| 838 | TagType = DeclSpec::TST_typename; |
| 839 | Result = TypeResult.get(); |
| 840 | Owned = false; |
| 841 | } else if (!TagOrTempResult.isInvalid()) { |
| 842 | Result = TagOrTempResult.get().getAs<void>(); |
| 843 | } else { |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 844 | DS.SetTypeSpecError(); |
Anders Carlsson | 66e9977 | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 845 | return; |
| 846 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 847 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 848 | const char *PrevSpec = 0; |
| 849 | unsigned DiagID; |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 850 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 851 | if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, DiagID, |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 852 | Result, Owned)) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 853 | Diag(StartLoc, DiagID) << PrevSpec; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 857 | /// |
| 858 | /// base-clause : [C++ class.derived] |
| 859 | /// ':' base-specifier-list |
| 860 | /// base-specifier-list: |
| 861 | /// base-specifier '...'[opt] |
| 862 | /// base-specifier-list ',' base-specifier '...'[opt] |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 863 | void Parser::ParseBaseClause(DeclPtrTy ClassDecl) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 864 | assert(Tok.is(tok::colon) && "Not a base clause"); |
| 865 | ConsumeToken(); |
| 866 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 867 | // Build up an array of parsed base specifiers. |
| 868 | llvm::SmallVector<BaseTy *, 8> BaseInfo; |
| 869 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 870 | while (true) { |
| 871 | // Parse a base-specifier. |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 872 | BaseResult Result = ParseBaseSpecifier(ClassDecl); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 873 | if (Result.isInvalid()) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 874 | // Skip the rest of this base specifier, up until the comma or |
| 875 | // opening brace. |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 876 | SkipUntil(tok::comma, tok::l_brace, true, true); |
| 877 | } else { |
| 878 | // Add this to our array of base specifiers. |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 879 | BaseInfo.push_back(Result.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // If the next token is a comma, consume it and keep reading |
| 883 | // base-specifiers. |
| 884 | if (Tok.isNot(tok::comma)) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 885 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 886 | // Consume the comma. |
| 887 | ConsumeToken(); |
| 888 | } |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 889 | |
| 890 | // Attach the base specifiers |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 891 | Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is |
| 895 | /// one entry in the base class list of a class specifier, for example: |
| 896 | /// class foo : public bar, virtual private baz { |
| 897 | /// 'public bar' and 'virtual private baz' are each base-specifiers. |
| 898 | /// |
| 899 | /// base-specifier: [C++ class.derived] |
| 900 | /// ::[opt] nested-name-specifier[opt] class-name |
| 901 | /// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt] |
| 902 | /// class-name |
| 903 | /// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] |
| 904 | /// class-name |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 905 | Parser::BaseResult Parser::ParseBaseSpecifier(DeclPtrTy ClassDecl) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 906 | bool IsVirtual = false; |
| 907 | SourceLocation StartLoc = Tok.getLocation(); |
| 908 | |
| 909 | // Parse the 'virtual' keyword. |
| 910 | if (Tok.is(tok::kw_virtual)) { |
| 911 | ConsumeToken(); |
| 912 | IsVirtual = true; |
| 913 | } |
| 914 | |
| 915 | // Parse an (optional) access specifier. |
| 916 | AccessSpecifier Access = getAccessSpecifierIfPresent(); |
| 917 | if (Access) |
| 918 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 920 | // Parse the 'virtual' keyword (again!), in case it came after the |
| 921 | // access specifier. |
| 922 | if (Tok.is(tok::kw_virtual)) { |
| 923 | SourceLocation VirtualLoc = ConsumeToken(); |
| 924 | if (IsVirtual) { |
| 925 | // Complain about duplicate 'virtual' |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 926 | Diag(VirtualLoc, diag::err_dup_virtual) |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 927 | << CodeModificationHint::CreateRemoval(SourceRange(VirtualLoc)); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | IsVirtual = true; |
| 931 | } |
| 932 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 933 | // Parse optional '::' and optional nested-name-specifier. |
| 934 | CXXScopeSpec SS; |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 935 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 937 | // The location of the base class itself. |
| 938 | SourceLocation BaseLoc = Tok.getLocation(); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 939 | |
| 940 | // Parse the class-name. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 941 | SourceLocation EndLocation; |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 942 | TypeResult BaseType = ParseClassName(EndLocation, &SS); |
| 943 | if (BaseType.isInvalid()) |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 944 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 945 | |
| 946 | // Find the complete source range for the base-specifier. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 947 | SourceRange Range(StartLoc, EndLocation); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 948 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 949 | // Notify semantic analysis that we have parsed a complete |
| 950 | // base-specifier. |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 951 | return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access, |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 952 | BaseType.get(), BaseLoc); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | /// getAccessSpecifierIfPresent - Determine whether the next token is |
| 956 | /// a C++ access-specifier. |
| 957 | /// |
| 958 | /// access-specifier: [C++ class.derived] |
| 959 | /// 'private' |
| 960 | /// 'protected' |
| 961 | /// 'public' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 962 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 963 | switch (Tok.getKind()) { |
| 964 | default: return AS_none; |
| 965 | case tok::kw_private: return AS_private; |
| 966 | case tok::kw_protected: return AS_protected; |
| 967 | case tok::kw_public: return AS_public; |
| 968 | } |
| 969 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 970 | |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 971 | void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, |
| 972 | DeclPtrTy ThisDecl) { |
| 973 | // We just declared a member function. If this member function |
| 974 | // has any default arguments, we'll need to parse them later. |
| 975 | LateParsedMethodDeclaration *LateMethod = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 976 | DeclaratorChunk::FunctionTypeInfo &FTI |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 977 | = DeclaratorInfo.getTypeObject(0).Fun; |
| 978 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { |
| 979 | if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { |
| 980 | if (!LateMethod) { |
| 981 | // Push this method onto the stack of late-parsed method |
| 982 | // declarations. |
| 983 | getCurrentClass().MethodDecls.push_back( |
| 984 | LateParsedMethodDeclaration(ThisDecl)); |
| 985 | LateMethod = &getCurrentClass().MethodDecls.back(); |
Douglas Gregor | d83d040 | 2009-08-22 00:34:47 +0000 | [diff] [blame] | 986 | LateMethod->TemplateScope = CurScope->isTemplateParamScope(); |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 987 | |
| 988 | // Add all of the parameters prior to this one (they don't |
| 989 | // have default arguments). |
| 990 | LateMethod->DefaultArgs.reserve(FTI.NumArgs); |
| 991 | for (unsigned I = 0; I < ParamIdx; ++I) |
| 992 | LateMethod->DefaultArgs.push_back( |
| 993 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param)); |
| 994 | } |
| 995 | |
| 996 | // Add this parameter to the list of parameters (it or may |
| 997 | // not have a default argument). |
| 998 | LateMethod->DefaultArgs.push_back( |
| 999 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, |
| 1000 | FTI.ArgInfo[ParamIdx].DefaultArgTokens)); |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1005 | /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. |
| 1006 | /// |
| 1007 | /// member-declaration: |
| 1008 | /// decl-specifier-seq[opt] member-declarator-list[opt] ';' |
| 1009 | /// function-definition ';'[opt] |
| 1010 | /// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] |
| 1011 | /// using-declaration [TODO] |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1012 | /// [C++0x] static_assert-declaration |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1013 | /// template-declaration |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1014 | /// [GNU] '__extension__' member-declaration |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1015 | /// |
| 1016 | /// member-declarator-list: |
| 1017 | /// member-declarator |
| 1018 | /// member-declarator-list ',' member-declarator |
| 1019 | /// |
| 1020 | /// member-declarator: |
| 1021 | /// declarator pure-specifier[opt] |
| 1022 | /// declarator constant-initializer[opt] |
| 1023 | /// identifier[opt] ':' constant-expression |
| 1024 | /// |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1025 | /// pure-specifier: |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1026 | /// '= 0' |
| 1027 | /// |
| 1028 | /// constant-initializer: |
| 1029 | /// '=' constant-expression |
| 1030 | /// |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1031 | void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, |
| 1032 | const ParsedTemplateInfo &TemplateInfo) { |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1033 | // static_assert-declaration |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1034 | if (Tok.is(tok::kw_static_assert)) { |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1035 | // FIXME: Check for templates |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1036 | SourceLocation DeclEnd; |
| 1037 | ParseStaticAssertDeclaration(DeclEnd); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1038 | return; |
| 1039 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1041 | if (Tok.is(tok::kw_template)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1042 | assert(!TemplateInfo.TemplateParams && |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1043 | "Nested template improperly parsed?"); |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1044 | SourceLocation DeclEnd; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1045 | ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1046 | AS); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1047 | return; |
| 1048 | } |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1049 | |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1050 | // Handle: member-declaration ::= '__extension__' member-declaration |
| 1051 | if (Tok.is(tok::kw___extension__)) { |
| 1052 | // __extension__ silences extension warnings in the subexpression. |
| 1053 | ExtensionRAIIObject O(Diags); // Use RAII to do this. |
| 1054 | ConsumeToken(); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1055 | return ParseCXXClassMemberDeclaration(AS, TemplateInfo); |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1056 | } |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1057 | |
| 1058 | if (Tok.is(tok::kw_using)) { |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1059 | // FIXME: Check for template aliases |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1061 | // Eat 'using'. |
| 1062 | SourceLocation UsingLoc = ConsumeToken(); |
| 1063 | |
| 1064 | if (Tok.is(tok::kw_namespace)) { |
| 1065 | Diag(UsingLoc, diag::err_using_namespace_in_class); |
| 1066 | SkipUntil(tok::semi, true, true); |
| 1067 | } |
| 1068 | else { |
| 1069 | SourceLocation DeclEnd; |
| 1070 | // Otherwise, it must be using-declaration. |
Anders Carlsson | 595adc1 | 2009-08-29 19:54:19 +0000 | [diff] [blame] | 1071 | ParseUsingDeclaration(Declarator::MemberContext, UsingLoc, DeclEnd, AS); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1072 | } |
| 1073 | return; |
| 1074 | } |
| 1075 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1076 | SourceLocation DSStart = Tok.getLocation(); |
| 1077 | // decl-specifier-seq: |
| 1078 | // Parse the common declaration-specifiers piece. |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1079 | ParsingDeclSpec DS(*this); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1080 | ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1081 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 1082 | Action::MultiTemplateParamsArg TemplateParams(Actions, |
| 1083 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, |
| 1084 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); |
| 1085 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1086 | if (Tok.is(tok::semi)) { |
| 1087 | ConsumeToken(); |
Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1088 | Actions.ParsedFreeStandingDeclSpec(CurScope, DS); |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1089 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1090 | } |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1091 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1092 | ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1093 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1094 | if (Tok.isNot(tok::colon)) { |
| 1095 | // Parse the first declarator. |
| 1096 | ParseDeclarator(DeclaratorInfo); |
| 1097 | // Error parsing the declarator? |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 1098 | if (!DeclaratorInfo.hasName()) { |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1099 | // If so, skip until the semi-colon or a }. |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1100 | SkipUntil(tok::r_brace, true); |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1101 | if (Tok.is(tok::semi)) |
| 1102 | ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1103 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1106 | // function-definition: |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1107 | if (Tok.is(tok::l_brace) |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 1108 | || (DeclaratorInfo.isFunctionDeclarator() && |
| 1109 | (Tok.is(tok::colon) || Tok.is(tok::kw_try)))) { |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1110 | if (!DeclaratorInfo.isFunctionDeclarator()) { |
| 1111 | Diag(Tok, diag::err_func_def_no_params); |
| 1112 | ConsumeBrace(); |
| 1113 | SkipUntil(tok::r_brace, true); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1114 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1115 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1116 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1117 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 1118 | Diag(Tok, diag::err_function_declared_typedef); |
| 1119 | // This recovery skips the entire function body. It would be nice |
| 1120 | // to simply call ParseCXXInlineMethodDef() below, however Sema |
| 1121 | // assumes the declarator represents a function, not a typedef. |
| 1122 | ConsumeBrace(); |
| 1123 | SkipUntil(tok::r_brace, true); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1124 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1127 | ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1128 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1129 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | // member-declarator-list: |
| 1133 | // member-declarator |
| 1134 | // member-declarator-list ',' member-declarator |
| 1135 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1136 | llvm::SmallVector<DeclPtrTy, 8> DeclsInGroup; |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1137 | OwningExprResult BitfieldSize(Actions); |
| 1138 | OwningExprResult Init(Actions); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1139 | bool Deleted = false; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1140 | |
| 1141 | while (1) { |
| 1142 | |
| 1143 | // member-declarator: |
| 1144 | // declarator pure-specifier[opt] |
| 1145 | // declarator constant-initializer[opt] |
| 1146 | // identifier[opt] ':' constant-expression |
| 1147 | |
| 1148 | if (Tok.is(tok::colon)) { |
| 1149 | ConsumeToken(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1150 | BitfieldSize = ParseConstantExpression(); |
| 1151 | if (BitfieldSize.isInvalid()) |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1152 | SkipUntil(tok::comma, true, true); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1153 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1154 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1155 | // pure-specifier: |
| 1156 | // '= 0' |
| 1157 | // |
| 1158 | // constant-initializer: |
| 1159 | // '=' constant-expression |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1160 | // |
| 1161 | // defaulted/deleted function-definition: |
| 1162 | // '=' 'default' [TODO] |
| 1163 | // '=' 'delete' |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1164 | |
| 1165 | if (Tok.is(tok::equal)) { |
| 1166 | ConsumeToken(); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1167 | if (getLang().CPlusPlus0x && Tok.is(tok::kw_delete)) { |
| 1168 | ConsumeToken(); |
| 1169 | Deleted = true; |
| 1170 | } else { |
| 1171 | Init = ParseInitializer(); |
| 1172 | if (Init.isInvalid()) |
| 1173 | SkipUntil(tok::comma, true, true); |
| 1174 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | // If attributes exist after the declarator, parse them. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1178 | if (Tok.is(tok::kw___attribute)) { |
| 1179 | SourceLocation Loc; |
| 1180 | AttributeList *AttrList = ParseAttributes(&Loc); |
| 1181 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 1182 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1183 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1184 | // NOTE: If Sema is the Action module and declarator is an instance field, |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1185 | // this call will *not* return the created decl; It will return null. |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1186 | // See Sema::ActOnCXXMemberDeclarator for details. |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1187 | |
| 1188 | DeclPtrTy ThisDecl; |
| 1189 | if (DS.isFriendSpecified()) { |
John McCall | bbbcdd9 | 2009-09-11 21:02:39 +0000 | [diff] [blame] | 1190 | // TODO: handle initializers, bitfields, 'delete' |
| 1191 | ThisDecl = Actions.ActOnFriendFunctionDecl(CurScope, DeclaratorInfo, |
| 1192 | /*IsDefinition*/ false, |
| 1193 | move(TemplateParams)); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1194 | } else { |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1195 | ThisDecl = Actions.ActOnCXXMemberDeclarator(CurScope, AS, |
| 1196 | DeclaratorInfo, |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1197 | move(TemplateParams), |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1198 | BitfieldSize.release(), |
| 1199 | Init.release(), |
| 1200 | Deleted); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1201 | } |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1202 | if (ThisDecl) |
| 1203 | DeclsInGroup.push_back(ThisDecl); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1204 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1205 | if (DeclaratorInfo.isFunctionDeclarator() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1207 | != DeclSpec::SCS_typedef) { |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1208 | HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1211 | DeclaratorInfo.complete(ThisDecl); |
| 1212 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1213 | // If we don't have a comma, it is either the end of the list (a ';') |
| 1214 | // or an error, bail out. |
| 1215 | if (Tok.isNot(tok::comma)) |
| 1216 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1218 | // Consume the comma. |
| 1219 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1220 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1221 | // Parse the next declarator. |
| 1222 | DeclaratorInfo.clear(); |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1223 | BitfieldSize = 0; |
| 1224 | Init = 0; |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1225 | Deleted = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1227 | // Attributes are only allowed on the second declarator. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1228 | if (Tok.is(tok::kw___attribute)) { |
| 1229 | SourceLocation Loc; |
| 1230 | AttributeList *AttrList = ParseAttributes(&Loc); |
| 1231 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 1232 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1233 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1234 | if (Tok.isNot(tok::colon)) |
| 1235 | ParseDeclarator(DeclaratorInfo); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (Tok.is(tok::semi)) { |
| 1239 | ConsumeToken(); |
Eli Friedman | c1dc653 | 2009-05-29 01:49:24 +0000 | [diff] [blame] | 1240 | Actions.FinalizeDeclaratorGroup(CurScope, DS, DeclsInGroup.data(), |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1241 | DeclsInGroup.size()); |
| 1242 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 1246 | // Skip to end of block or statement |
| 1247 | SkipUntil(tok::r_brace, true, true); |
| 1248 | if (Tok.is(tok::semi)) |
| 1249 | ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1250 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /// ParseCXXMemberSpecification - Parse the class definition. |
| 1254 | /// |
| 1255 | /// member-specification: |
| 1256 | /// member-declaration member-specification[opt] |
| 1257 | /// access-specifier ':' member-specification[opt] |
| 1258 | /// |
| 1259 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1260 | unsigned TagType, DeclPtrTy TagDecl) { |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1261 | assert((TagType == DeclSpec::TST_struct || |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1262 | TagType == DeclSpec::TST_union || |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1263 | TagType == DeclSpec::TST_class) && "Invalid TagType!"); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1264 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 1265 | PrettyStackTraceActionsDecl CrashInfo(TagDecl, RecordLoc, Actions, |
| 1266 | PP.getSourceManager(), |
| 1267 | "parsing struct/union/class body"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1268 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1269 | SourceLocation LBraceLoc = ConsumeBrace(); |
| 1270 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1271 | // Determine whether this is a top-level (non-nested) class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1272 | bool TopLevelClass = ClassStack.empty() || |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1273 | CurScope->isInCXXInlineMethodScope(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1274 | |
| 1275 | // Enter a scope for the class. |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 1276 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1277 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1278 | // Note that we are parsing a new (potentially-nested) class definition. |
| 1279 | ParsingClassDefinition ParsingDef(*this, TagDecl, TopLevelClass); |
| 1280 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1281 | if (TagDecl) |
| 1282 | Actions.ActOnTagStartDefinition(CurScope, TagDecl); |
| 1283 | else { |
| 1284 | SkipUntil(tok::r_brace, false, false); |
| 1285 | return; |
| 1286 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1287 | |
| 1288 | // C++ 11p3: Members of a class defined with the keyword class are private |
| 1289 | // by default. Members of a class defined with the keywords struct or union |
| 1290 | // are public by default. |
| 1291 | AccessSpecifier CurAS; |
| 1292 | if (TagType == DeclSpec::TST_class) |
| 1293 | CurAS = AS_private; |
| 1294 | else |
| 1295 | CurAS = AS_public; |
| 1296 | |
| 1297 | // While we still have something to read, read the member-declarations. |
| 1298 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
| 1299 | // Each iteration of this loop reads one member-declaration. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1300 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1301 | // Check for extraneous top-level semicolon. |
| 1302 | if (Tok.is(tok::semi)) { |
Chris Lattner | c2253f5 | 2009-11-06 06:40:12 +0000 | [diff] [blame] | 1303 | Diag(Tok, diag::ext_extra_struct_semi) |
| 1304 | << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation())); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1305 | ConsumeToken(); |
| 1306 | continue; |
| 1307 | } |
| 1308 | |
| 1309 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 1310 | if (AS != AS_none) { |
| 1311 | // Current token is a C++ access specifier. |
| 1312 | CurAS = AS; |
| 1313 | ConsumeToken(); |
| 1314 | ExpectAndConsume(tok::colon, diag::err_expected_colon); |
| 1315 | continue; |
| 1316 | } |
| 1317 | |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1318 | // FIXME: Make sure we don't have a template here. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1319 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1320 | // Parse all the comma separated declarators. |
| 1321 | ParseCXXClassMemberDeclaration(CurAS); |
| 1322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1324 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1325 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1326 | AttributeList *AttrList = 0; |
| 1327 | // If attributes exist after class contents, parse them. |
| 1328 | if (Tok.is(tok::kw___attribute)) |
| 1329 | AttrList = ParseAttributes(); // FIXME: where should I put them? |
| 1330 | |
| 1331 | Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl, |
| 1332 | LBraceLoc, RBraceLoc); |
| 1333 | |
| 1334 | // C++ 9.2p2: Within the class member-specification, the class is regarded as |
| 1335 | // complete within function bodies, default arguments, |
| 1336 | // exception-specifications, and constructor ctor-initializers (including |
| 1337 | // such things in nested classes). |
| 1338 | // |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1339 | // FIXME: Only function bodies and constructor ctor-initializers are |
| 1340 | // parsed correctly, fix the rest. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1341 | if (TopLevelClass) { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1342 | // We are not inside a nested class. This class and its nested classes |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1343 | // are complete and we can parse the delayed portions of method |
| 1344 | // declarations and the lexed inline method definitions. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1345 | ParseLexedMethodDeclarations(getCurrentClass()); |
| 1346 | ParseLexedMethodDefs(getCurrentClass()); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | // Leave the class scope. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1350 | ParsingDef.Pop(); |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1351 | ClassScope.Exit(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1352 | |
Argyrios Kyrtzidis | 07a5b28 | 2009-07-14 03:17:52 +0000 | [diff] [blame] | 1353 | Actions.ActOnTagFinishDefinition(CurScope, TagDecl, RBraceLoc); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1354 | } |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1355 | |
| 1356 | /// ParseConstructorInitializer - Parse a C++ constructor initializer, |
| 1357 | /// which explicitly initializes the members or base classes of a |
| 1358 | /// class (C++ [class.base.init]). For example, the three initializers |
| 1359 | /// after the ':' in the Derived constructor below: |
| 1360 | /// |
| 1361 | /// @code |
| 1362 | /// class Base { }; |
| 1363 | /// class Derived : Base { |
| 1364 | /// int x; |
| 1365 | /// float f; |
| 1366 | /// public: |
| 1367 | /// Derived(float f) : Base(), x(17), f(f) { } |
| 1368 | /// }; |
| 1369 | /// @endcode |
| 1370 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | /// [C++] ctor-initializer: |
| 1372 | /// ':' mem-initializer-list |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1373 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | /// [C++] mem-initializer-list: |
| 1375 | /// mem-initializer |
| 1376 | /// mem-initializer , mem-initializer-list |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1377 | void Parser::ParseConstructorInitializer(DeclPtrTy ConstructorDecl) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1378 | assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); |
| 1379 | |
| 1380 | SourceLocation ColonLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1382 | llvm::SmallVector<MemInitTy*, 4> MemInitializers; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1383 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1384 | do { |
| 1385 | MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1386 | if (!MemInit.isInvalid()) |
| 1387 | MemInitializers.push_back(MemInit.get()); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1388 | |
| 1389 | if (Tok.is(tok::comma)) |
| 1390 | ConsumeToken(); |
| 1391 | else if (Tok.is(tok::l_brace)) |
| 1392 | break; |
| 1393 | else { |
| 1394 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 1395 | Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1396 | SkipUntil(tok::l_brace, true, true); |
| 1397 | break; |
| 1398 | } |
| 1399 | } while (true); |
| 1400 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1402 | MemInitializers.data(), MemInitializers.size()); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /// ParseMemInitializer - Parse a C++ member initializer, which is |
| 1406 | /// part of a constructor initializer that explicitly initializes one |
| 1407 | /// member or base class (C++ [class.base.init]). See |
| 1408 | /// ParseConstructorInitializer for an example. |
| 1409 | /// |
| 1410 | /// [C++] mem-initializer: |
| 1411 | /// mem-initializer-id '(' expression-list[opt] ')' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | /// |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1413 | /// [C++] mem-initializer-id: |
| 1414 | /// '::'[opt] nested-name-specifier[opt] class-name |
| 1415 | /// identifier |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1416 | Parser::MemInitResult Parser::ParseMemInitializer(DeclPtrTy ConstructorDecl) { |
Fariborz Jahanian | bcfad54 | 2009-06-30 23:26:25 +0000 | [diff] [blame] | 1417 | // parse '::'[opt] nested-name-specifier[opt] |
| 1418 | CXXScopeSpec SS; |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 1419 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1420 | TypeTy *TemplateTypeTy = 0; |
| 1421 | if (Tok.is(tok::annot_template_id)) { |
| 1422 | TemplateIdAnnotation *TemplateId |
| 1423 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
| 1424 | if (TemplateId->Kind == TNK_Type_template) { |
| 1425 | AnnotateTemplateIdTokenAsType(&SS); |
| 1426 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 1427 | TemplateTypeTy = Tok.getAnnotationValue(); |
| 1428 | } |
| 1429 | // FIXME. May need to check for TNK_Dependent_template as well. |
| 1430 | } |
| 1431 | if (!TemplateTypeTy && Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1432 | Diag(Tok, diag::err_expected_member_or_base_name); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1433 | return true; |
| 1434 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1435 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1436 | // Get the identifier. This may be a member name or a class name, |
| 1437 | // but we'll let the semantic analysis determine which it is. |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1438 | IdentifierInfo *II = Tok.is(tok::identifier) ? Tok.getIdentifierInfo() : 0; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1439 | SourceLocation IdLoc = ConsumeToken(); |
| 1440 | |
| 1441 | // Parse the '('. |
| 1442 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1443 | Diag(Tok, diag::err_expected_lparen); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1444 | return true; |
| 1445 | } |
| 1446 | SourceLocation LParenLoc = ConsumeParen(); |
| 1447 | |
| 1448 | // Parse the optional expression-list. |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1449 | ExprVector ArgExprs(Actions); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1450 | CommaLocsTy CommaLocs; |
| 1451 | if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { |
| 1452 | SkipUntil(tok::r_paren); |
| 1453 | return true; |
| 1454 | } |
| 1455 | |
| 1456 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 1457 | |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1458 | return Actions.ActOnMemInitializer(ConstructorDecl, CurScope, SS, II, |
| 1459 | TemplateTypeTy, IdLoc, |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1460 | LParenLoc, ArgExprs.take(), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1461 | ArgExprs.size(), CommaLocs.data(), |
| 1462 | RParenLoc); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1463 | } |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1464 | |
| 1465 | /// ParseExceptionSpecification - Parse a C++ exception-specification |
| 1466 | /// (C++ [except.spec]). |
| 1467 | /// |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1468 | /// exception-specification: |
| 1469 | /// 'throw' '(' type-id-list [opt] ')' |
| 1470 | /// [MS] 'throw' '(' '...' ')' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1471 | /// |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1472 | /// type-id-list: |
| 1473 | /// type-id |
| 1474 | /// type-id-list ',' type-id |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1475 | /// |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1476 | bool Parser::ParseExceptionSpecification(SourceLocation &EndLoc, |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1477 | llvm::SmallVector<TypeTy*, 2> |
| 1478 | &Exceptions, |
| 1479 | llvm::SmallVector<SourceRange, 2> |
| 1480 | &Ranges, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1481 | bool &hasAnyExceptionSpec) { |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1482 | assert(Tok.is(tok::kw_throw) && "expected throw"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1483 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1484 | SourceLocation ThrowLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1485 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1486 | if (!Tok.is(tok::l_paren)) { |
| 1487 | return Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 1488 | } |
| 1489 | SourceLocation LParenLoc = ConsumeParen(); |
| 1490 | |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1491 | // Parse throw(...), a Microsoft extension that means "this function |
| 1492 | // can throw anything". |
| 1493 | if (Tok.is(tok::ellipsis)) { |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1494 | hasAnyExceptionSpec = true; |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1495 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 1496 | if (!getLang().Microsoft) |
| 1497 | Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1498 | EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1499 | return false; |
| 1500 | } |
| 1501 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1502 | // Parse the sequence of type-ids. |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1503 | SourceRange Range; |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1504 | while (Tok.isNot(tok::r_paren)) { |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1505 | TypeResult Res(ParseTypeName(&Range)); |
| 1506 | if (!Res.isInvalid()) { |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1507 | Exceptions.push_back(Res.get()); |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1508 | Ranges.push_back(Range); |
| 1509 | } |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1510 | if (Tok.is(tok::comma)) |
| 1511 | ConsumeToken(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1512 | else |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1513 | break; |
| 1514 | } |
| 1515 | |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1516 | EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1517 | return false; |
| 1518 | } |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1519 | |
| 1520 | /// \brief We have just started parsing the definition of a new class, |
| 1521 | /// so push that class onto our stack of classes that is currently |
| 1522 | /// being parsed. |
| 1523 | void Parser::PushParsingClass(DeclPtrTy ClassDecl, bool TopLevelClass) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | assert((TopLevelClass || !ClassStack.empty()) && |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1525 | "Nested class without outer class"); |
| 1526 | ClassStack.push(new ParsingClass(ClassDecl, TopLevelClass)); |
| 1527 | } |
| 1528 | |
| 1529 | /// \brief Deallocate the given parsed class and all of its nested |
| 1530 | /// classes. |
| 1531 | void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { |
| 1532 | for (unsigned I = 0, N = Class->NestedClasses.size(); I != N; ++I) |
| 1533 | DeallocateParsedClasses(Class->NestedClasses[I]); |
| 1534 | delete Class; |
| 1535 | } |
| 1536 | |
| 1537 | /// \brief Pop the top class of the stack of classes that are |
| 1538 | /// currently being parsed. |
| 1539 | /// |
| 1540 | /// This routine should be called when we have finished parsing the |
| 1541 | /// definition of a class, but have not yet popped the Scope |
| 1542 | /// associated with the class's definition. |
| 1543 | /// |
| 1544 | /// \returns true if the class we've popped is a top-level class, |
| 1545 | /// false otherwise. |
| 1546 | void Parser::PopParsingClass() { |
| 1547 | assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1549 | ParsingClass *Victim = ClassStack.top(); |
| 1550 | ClassStack.pop(); |
| 1551 | if (Victim->TopLevelClass) { |
| 1552 | // Deallocate all of the nested classes of this class, |
| 1553 | // recursively: we don't need to keep any of this information. |
| 1554 | DeallocateParsedClasses(Victim); |
| 1555 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1556 | } |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1557 | assert(!ClassStack.empty() && "Missing top-level class?"); |
| 1558 | |
| 1559 | if (Victim->MethodDecls.empty() && Victim->MethodDefs.empty() && |
| 1560 | Victim->NestedClasses.empty()) { |
| 1561 | // The victim is a nested class, but we will not need to perform |
| 1562 | // any processing after the definition of this class since it has |
| 1563 | // no members whose handling was delayed. Therefore, we can just |
| 1564 | // remove this nested class. |
| 1565 | delete Victim; |
| 1566 | return; |
| 1567 | } |
| 1568 | |
| 1569 | // This nested class has some members that will need to be processed |
| 1570 | // after the top-level class is completely defined. Therefore, add |
| 1571 | // it to the list of nested classes within its parent. |
| 1572 | assert(CurScope->isClassScope() && "Nested class outside of class scope?"); |
| 1573 | ClassStack.top()->NestedClasses.push_back(Victim); |
| 1574 | Victim->TemplateScope = CurScope->getParent()->isTemplateParamScope(); |
| 1575 | } |