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 | d167ca0 | 2009-12-10 00:21:05 +0000 | [diff] [blame] | 20 | #include "RAIIObjectsForParser.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)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 52 | Actions.CodeCompleteNamespaceDecl(getCurScope()); |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 53 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 54 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 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. |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 67 | llvm::OwningPtr<AttributeList> AttrList; |
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. |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 72 | AttrList.reset(ParseGNUAttributes()); |
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 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 90 | if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || |
| 91 | getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() || |
| 92 | getCurScope()->getFnParent()) { |
Douglas Gregor | 95f1b15 | 2010-05-14 05:08:22 +0000 | [diff] [blame] | 93 | Diag(LBrace, diag::err_namespace_nonnamespace_scope); |
| 94 | SkipUntil(tok::r_brace, false); |
| 95 | return DeclPtrTy(); |
| 96 | } |
| 97 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 98 | // Enter a scope for the namespace. |
| 99 | ParseScope NamespaceScope(this, Scope::DeclScope); |
| 100 | |
| 101 | DeclPtrTy NamespcDecl = |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 102 | Actions.ActOnStartNamespaceDef(getCurScope(), IdentLoc, Ident, LBrace, |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 103 | AttrList.get()); |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 104 | |
| 105 | PrettyStackTraceActionsDecl CrashInfo(NamespcDecl, NamespaceLoc, Actions, |
| 106 | PP.getSourceManager(), |
| 107 | "parsing namespace"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 109 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
| 110 | CXX0XAttributeList Attr; |
| 111 | if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) |
| 112 | Attr = ParseCXX0XAttributes(); |
| 113 | ParseExternalDeclaration(Attr); |
| 114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 116 | // Leave the namespace scope. |
| 117 | NamespaceScope.Exit(); |
| 118 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 119 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace); |
| 120 | Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc); |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 122 | DeclEnd = RBraceLoc; |
Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 123 | return NamespcDecl; |
Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 124 | } |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 125 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 126 | /// ParseNamespaceAlias - Parse the part after the '=' in a namespace |
| 127 | /// alias definition. |
| 128 | /// |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 129 | Parser::DeclPtrTy Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 130 | SourceLocation AliasLoc, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 131 | IdentifierInfo *Alias, |
| 132 | SourceLocation &DeclEnd) { |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 133 | assert(Tok.is(tok::equal) && "Not equal token"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 134 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 135 | ConsumeToken(); // eat the '='. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 136 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 137 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 138 | Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 139 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 140 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 141 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 142 | CXXScopeSpec SS; |
| 143 | // Parse (optional) nested-name-specifier. |
Chris Lattner | be1ea44 | 2009-12-07 01:38:03 +0000 | [diff] [blame] | 144 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 145 | |
| 146 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
| 147 | Diag(Tok, diag::err_expected_namespace_name); |
| 148 | // Skip to end of the definition and eat the ';'. |
| 149 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 150 | return DeclPtrTy(); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // Parse identifier. |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 154 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 155 | SourceLocation IdentLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 157 | // Eat the ';'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 158 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 159 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name, |
| 160 | "", tok::semi); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 162 | return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias, |
Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 163 | SS, IdentLoc, Ident); |
Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 166 | /// ParseLinkage - We know that the current token is a string_literal |
| 167 | /// and just before that, that extern was seen. |
| 168 | /// |
| 169 | /// linkage-specification: [C++ 7.5p2: dcl.link] |
| 170 | /// 'extern' string-literal '{' declaration-seq[opt] '}' |
| 171 | /// 'extern' string-literal declaration |
| 172 | /// |
Fariborz Jahanian | 3acd9aa | 2009-12-09 21:39:38 +0000 | [diff] [blame] | 173 | Parser::DeclPtrTy Parser::ParseLinkage(ParsingDeclSpec &DS, |
| 174 | unsigned Context) { |
Douglas Gregor | c19923d | 2008-11-21 16:10:08 +0000 | [diff] [blame] | 175 | assert(Tok.is(tok::string_literal) && "Not a string literal!"); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 176 | llvm::SmallString<8> LangBuffer; |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 177 | // LangBuffer is guaranteed to be big enough. |
Douglas Gregor | 453091c | 2010-03-16 22:30:13 +0000 | [diff] [blame] | 178 | bool Invalid = false; |
| 179 | llvm::StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid); |
| 180 | if (Invalid) |
| 181 | return DeclPtrTy(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 182 | |
| 183 | SourceLocation Loc = ConsumeStringToken(); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 185 | ParseScope LinkageScope(this, Scope::DeclScope); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | DeclPtrTy LinkageSpec |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 187 | = Actions.ActOnStartLinkageSpecification(getCurScope(), |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 188 | /*FIXME: */SourceLocation(), |
Benjamin Kramer | d566381 | 2010-05-03 13:08:54 +0000 | [diff] [blame] | 189 | Loc, Lang, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 190 | Tok.is(tok::l_brace)? Tok.getLocation() |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 191 | : SourceLocation()); |
| 192 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 193 | CXX0XAttributeList Attr; |
| 194 | if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { |
| 195 | Attr = ParseCXX0XAttributes(); |
| 196 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 197 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 198 | if (Tok.isNot(tok::l_brace)) { |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 199 | DS.setExternInLinkageSpec(true); |
Fariborz Jahanian | 3acd9aa | 2009-12-09 21:39:38 +0000 | [diff] [blame] | 200 | ParseDeclarationOrFunctionDefinition(DS, Attr.AttrList); |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 201 | return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 202 | SourceLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 203 | } |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 204 | |
Douglas Gregor | 63a0113 | 2010-02-07 08:38:28 +0000 | [diff] [blame] | 205 | DS.abort(); |
| 206 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 207 | if (Attr.HasAttr) |
| 208 | Diag(Attr.Range.getBegin(), diag::err_attributes_not_allowed) |
| 209 | << Attr.Range; |
| 210 | |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 211 | SourceLocation LBrace = ConsumeBrace(); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 212 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 213 | CXX0XAttributeList Attr; |
| 214 | if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) |
| 215 | Attr = ParseCXX0XAttributes(); |
| 216 | ParseExternalDeclaration(Attr); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 219 | SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace); |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 220 | return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, RBrace); |
Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 221 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 222 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 223 | /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or |
| 224 | /// using-directive. Assumes that current token is 'using'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 225 | Parser::DeclPtrTy Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 226 | SourceLocation &DeclEnd, |
| 227 | CXX0XAttributeList Attr) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 228 | assert(Tok.is(tok::kw_using) && "Not using token"); |
| 229 | |
| 230 | // Eat 'using'. |
| 231 | SourceLocation UsingLoc = ConsumeToken(); |
| 232 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 233 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 234 | Actions.CodeCompleteUsing(getCurScope()); |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 235 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 236 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 237 | |
Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 238 | if (Tok.is(tok::kw_namespace)) |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 239 | // Next token after 'using' is 'namespace' so it must be using-directive |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 240 | return ParseUsingDirective(Context, UsingLoc, DeclEnd, Attr.AttrList); |
| 241 | |
| 242 | if (Attr.HasAttr) |
| 243 | Diag(Attr.Range.getBegin(), diag::err_attributes_not_allowed) |
| 244 | << Attr.Range; |
Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 245 | |
| 246 | // Otherwise, it must be using-declaration. |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 247 | // Ignore illegal attributes (the caller should already have issued an error. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 248 | return ParseUsingDeclaration(Context, UsingLoc, DeclEnd); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /// ParseUsingDirective - Parse C++ using-directive, assumes |
| 252 | /// that current token is 'namespace' and 'using' was already parsed. |
| 253 | /// |
| 254 | /// using-directive: [C++ 7.3.p4: namespace.udir] |
| 255 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 256 | /// namespace-name ; |
| 257 | /// [GNU] using-directive: |
| 258 | /// 'using' 'namespace' ::[opt] nested-name-specifier[opt] |
| 259 | /// namespace-name attributes[opt] ; |
| 260 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 261 | Parser::DeclPtrTy Parser::ParseUsingDirective(unsigned Context, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 262 | SourceLocation UsingLoc, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 263 | SourceLocation &DeclEnd, |
| 264 | AttributeList *Attr) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 265 | assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); |
| 266 | |
| 267 | // Eat 'namespace'. |
| 268 | SourceLocation NamespcLoc = ConsumeToken(); |
| 269 | |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 270 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 271 | Actions.CodeCompleteUsingDirective(getCurScope()); |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 272 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 273 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 274 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 275 | CXXScopeSpec SS; |
| 276 | // Parse (optional) nested-name-specifier. |
Chris Lattner | be1ea44 | 2009-12-07 01:38:03 +0000 | [diff] [blame] | 277 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 278 | |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 279 | IdentifierInfo *NamespcName = 0; |
| 280 | SourceLocation IdentLoc = SourceLocation(); |
| 281 | |
| 282 | // Parse namespace-name. |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 283 | if (SS.isInvalid() || Tok.isNot(tok::identifier)) { |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 284 | Diag(Tok, diag::err_expected_namespace_name); |
| 285 | // If there was invalid namespace name, skip to end of decl, and eat ';'. |
| 286 | SkipUntil(tok::semi); |
| 287 | // FIXME: Are there cases, when we would like to call ActOnUsingDirective? |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 288 | return DeclPtrTy(); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 291 | // Parse identifier. |
| 292 | NamespcName = Tok.getIdentifierInfo(); |
| 293 | IdentLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 294 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 295 | // Parse (optional) attributes (most likely GNU strong-using extension). |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 296 | bool GNUAttr = false; |
| 297 | if (Tok.is(tok::kw___attribute)) { |
| 298 | GNUAttr = true; |
| 299 | Attr = addAttributeLists(Attr, ParseGNUAttributes()); |
| 300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 302 | // Eat ';'. |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 303 | DeclEnd = Tok.getLocation(); |
Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 304 | ExpectAndConsume(tok::semi, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 305 | GNUAttr ? diag::err_expected_semi_after_attribute_list : |
Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 306 | diag::err_expected_semi_after_namespace_name, "", tok::semi); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 307 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 308 | return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 309 | IdentLoc, NamespcName, Attr); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /// ParseUsingDeclaration - Parse C++ using-declaration. Assumes that |
| 313 | /// 'using' was already seen. |
| 314 | /// |
| 315 | /// using-declaration: [C++ 7.3.p3: namespace.udecl] |
| 316 | /// 'using' 'typename'[opt] ::[opt] nested-name-specifier |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 317 | /// unqualified-id |
| 318 | /// 'using' :: unqualified-id |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 319 | /// |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 320 | Parser::DeclPtrTy Parser::ParseUsingDeclaration(unsigned Context, |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 321 | SourceLocation UsingLoc, |
Anders Carlsson | 595adc1 | 2009-08-29 19:54:19 +0000 | [diff] [blame] | 322 | SourceLocation &DeclEnd, |
| 323 | AccessSpecifier AS) { |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 324 | CXXScopeSpec SS; |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 325 | SourceLocation TypenameLoc; |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 326 | bool IsTypeName; |
| 327 | |
| 328 | // Ignore optional 'typename'. |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 329 | // FIXME: This is wrong; we should parse this as a typename-specifier. |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 330 | if (Tok.is(tok::kw_typename)) { |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 331 | TypenameLoc = Tok.getLocation(); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 332 | ConsumeToken(); |
| 333 | IsTypeName = true; |
| 334 | } |
| 335 | else |
| 336 | IsTypeName = false; |
| 337 | |
| 338 | // Parse nested-name-specifier. |
Chris Lattner | be1ea44 | 2009-12-07 01:38:03 +0000 | [diff] [blame] | 339 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 340 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 341 | // Check nested-name specifier. |
| 342 | if (SS.isInvalid()) { |
| 343 | SkipUntil(tok::semi); |
| 344 | return DeclPtrTy(); |
| 345 | } |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 346 | |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 347 | // Parse the unqualified-id. We allow parsing of both constructor and |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 348 | // destructor names and allow the action module to diagnose any semantic |
| 349 | // errors. |
| 350 | UnqualifiedId Name; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 351 | if (ParseUnqualifiedId(SS, |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 352 | /*EnteringContext=*/false, |
| 353 | /*AllowDestructorName=*/true, |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 354 | /*AllowConstructorName=*/true, |
| 355 | /*ObjectType=*/0, |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 356 | Name)) { |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 357 | SkipUntil(tok::semi); |
| 358 | return DeclPtrTy(); |
| 359 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 360 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 361 | // Parse (optional) attributes (most likely GNU strong-using extension). |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 362 | llvm::OwningPtr<AttributeList> AttrList; |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 363 | if (Tok.is(tok::kw___attribute)) |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 364 | AttrList.reset(ParseGNUAttributes()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 366 | // Eat ';'. |
| 367 | DeclEnd = Tok.getLocation(); |
| 368 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 369 | AttrList ? "attributes list" : "using declaration", |
Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 370 | tok::semi); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 371 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 372 | return Actions.ActOnUsingDeclaration(getCurScope(), AS, true, UsingLoc, SS, Name, |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 373 | AttrList.get(), IsTypeName, TypenameLoc); |
Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 376 | /// ParseStaticAssertDeclaration - Parse C++0x static_assert-declaratoion. |
| 377 | /// |
| 378 | /// static_assert-declaration: |
| 379 | /// static_assert ( constant-expression , string-literal ) ; |
| 380 | /// |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 381 | Parser::DeclPtrTy Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 382 | assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration"); |
| 383 | SourceLocation StaticAssertLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 385 | if (Tok.isNot(tok::l_paren)) { |
| 386 | Diag(Tok, diag::err_expected_lparen); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 387 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 388 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 390 | SourceLocation LParenLoc = ConsumeParen(); |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 391 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 392 | OwningExprResult AssertExpr(ParseConstantExpression()); |
| 393 | if (AssertExpr.isInvalid()) { |
| 394 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 395 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 396 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 397 | |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 398 | if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 399 | return DeclPtrTy(); |
Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 400 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 401 | if (Tok.isNot(tok::string_literal)) { |
| 402 | Diag(Tok, diag::err_expected_string_literal); |
| 403 | SkipUntil(tok::semi); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 404 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 405 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 407 | OwningExprResult AssertMessage(ParseStringLiteralExpression()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | if (AssertMessage.isInvalid()) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 409 | return DeclPtrTy(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 410 | |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 411 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 413 | DeclEnd = Tok.getLocation(); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 414 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert); |
| 415 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, move(AssertExpr), |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 417 | move(AssertMessage)); |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 420 | /// ParseDecltypeSpecifier - Parse a C++0x decltype specifier. |
| 421 | /// |
| 422 | /// 'decltype' ( expression ) |
| 423 | /// |
| 424 | void Parser::ParseDecltypeSpecifier(DeclSpec &DS) { |
| 425 | assert(Tok.is(tok::kw_decltype) && "Not a decltype specifier"); |
| 426 | |
| 427 | SourceLocation StartLoc = ConsumeToken(); |
| 428 | SourceLocation LParenLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | |
| 430 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 431 | "decltype")) { |
| 432 | SkipUntil(tok::r_paren); |
| 433 | return; |
| 434 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 436 | // Parse the expression |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 438 | // C++0x [dcl.type.simple]p4: |
| 439 | // The operand of the decltype specifier is an unevaluated operand. |
| 440 | EnterExpressionEvaluationContext Unevaluated(Actions, |
| 441 | Action::Unevaluated); |
| 442 | OwningExprResult Result = ParseExpression(); |
| 443 | if (Result.isInvalid()) { |
| 444 | SkipUntil(tok::r_paren); |
| 445 | return; |
| 446 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 448 | // Match the ')' |
| 449 | SourceLocation RParenLoc; |
| 450 | if (Tok.is(tok::r_paren)) |
| 451 | RParenLoc = ConsumeParen(); |
| 452 | else |
| 453 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 455 | if (RParenLoc.isInvalid()) |
| 456 | return; |
| 457 | |
| 458 | const char *PrevSpec = 0; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 459 | unsigned DiagID; |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 460 | // Check for duplicate type specifiers (e.g. "int decltype(a)"). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | if (DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 462 | DiagID, Result.release())) |
| 463 | Diag(StartLoc, DiagID) << PrevSpec; |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 466 | /// ParseClassName - Parse a C++ class-name, which names a class. Note |
| 467 | /// that we only check that the result names a type; semantic analysis |
| 468 | /// 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] | 469 | /// either a type or NULL, depending on whether a type name was |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 470 | /// found. |
| 471 | /// |
| 472 | /// class-name: [C++ 9.1] |
| 473 | /// identifier |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 474 | /// simple-template-id |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | /// |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 476 | Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation, |
Jeffrey Yasskin | 9ab1454 | 2010-04-08 16:38:48 +0000 | [diff] [blame] | 477 | CXXScopeSpec *SS) { |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 478 | // Check whether we have a template-id that names a type. |
| 479 | if (Tok.is(tok::annot_template_id)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | TemplateIdAnnotation *TemplateId |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 481 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
Douglas Gregor | d9b600c | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 482 | if (TemplateId->Kind == TNK_Type_template || |
| 483 | TemplateId->Kind == TNK_Dependent_template_name) { |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 484 | AnnotateTemplateIdTokenAsType(SS); |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 485 | |
| 486 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 487 | TypeTy *Type = Tok.getAnnotationValue(); |
| 488 | EndLocation = Tok.getAnnotationEndLoc(); |
| 489 | ConsumeToken(); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 490 | |
| 491 | if (Type) |
| 492 | return Type; |
| 493 | return true; |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | // Fall through to produce an error below. |
| 497 | } |
| 498 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 499 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 500 | Diag(Tok, diag::err_expected_class_name); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 501 | return true; |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 504 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 505 | SourceLocation IdLoc = ConsumeToken(); |
| 506 | |
| 507 | if (Tok.is(tok::less)) { |
| 508 | // It looks the user intended to write a template-id here, but the |
| 509 | // template-name was wrong. Try to fix that. |
| 510 | TemplateNameKind TNK = TNK_Type_template; |
| 511 | TemplateTy Template; |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 512 | if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 513 | SS, Template, TNK)) { |
| 514 | Diag(IdLoc, diag::err_unknown_template_name) |
| 515 | << Id; |
| 516 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 517 | |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 518 | if (!Template) |
| 519 | return true; |
| 520 | |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 521 | // Form the template name |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 522 | UnqualifiedId TemplateName; |
| 523 | TemplateName.setIdentifier(Id, IdLoc); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 524 | |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 525 | // Parse the full template-id, then turn it into a type. |
| 526 | if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateName, |
| 527 | SourceLocation(), true)) |
| 528 | return true; |
| 529 | if (TNK == TNK_Dependent_template_name) |
| 530 | AnnotateTemplateIdTokenAsType(SS); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 531 | |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 532 | // If we didn't end up with a typename token, there's nothing more we |
| 533 | // can do. |
| 534 | if (Tok.isNot(tok::annot_typename)) |
| 535 | return true; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 536 | |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 537 | // Retrieve the type from the annotation token, consume that token, and |
| 538 | // return. |
| 539 | EndLocation = Tok.getAnnotationEndLoc(); |
| 540 | TypeTy *Type = Tok.getAnnotationValue(); |
| 541 | ConsumeToken(); |
| 542 | return Type; |
| 543 | } |
| 544 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 545 | // We have an identifier; check whether it is actually a type. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 546 | TypeTy *Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), SS, true); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 547 | if (!Type) { |
Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 548 | Diag(IdLoc, diag::err_expected_class_name); |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 549 | return true; |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | // Consume the identifier. |
Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 553 | EndLocation = IdLoc; |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 554 | |
| 555 | // Fake up a Declarator to use with ActOnTypeName. |
| 556 | DeclSpec DS; |
| 557 | DS.SetRangeStart(IdLoc); |
| 558 | DS.SetRangeEnd(EndLocation); |
| 559 | DS.getTypeSpecScope() = *SS; |
| 560 | |
| 561 | const char *PrevSpec = 0; |
| 562 | unsigned DiagID; |
| 563 | DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type); |
| 564 | |
| 565 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 566 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 569 | /// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or |
| 570 | /// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which |
| 571 | /// until we reach the start of a definition or see a token that |
Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 572 | /// cannot start a definition. If SuppressDeclarations is true, we do know. |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 573 | /// |
| 574 | /// class-specifier: [C++ class] |
| 575 | /// class-head '{' member-specification[opt] '}' |
| 576 | /// class-head '{' member-specification[opt] '}' attributes[opt] |
| 577 | /// class-head: |
| 578 | /// class-key identifier[opt] base-clause[opt] |
| 579 | /// class-key nested-name-specifier identifier base-clause[opt] |
| 580 | /// class-key nested-name-specifier[opt] simple-template-id |
| 581 | /// base-clause[opt] |
| 582 | /// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 583 | /// [GNU] class-key attributes[opt] nested-name-specifier |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 584 | /// identifier base-clause[opt] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | /// [GNU] class-key attributes[opt] nested-name-specifier[opt] |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 586 | /// simple-template-id base-clause[opt] |
| 587 | /// class-key: |
| 588 | /// 'class' |
| 589 | /// 'struct' |
| 590 | /// 'union' |
| 591 | /// |
| 592 | /// elaborated-type-specifier: [C++ dcl.type.elab] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | /// class-key ::[opt] nested-name-specifier[opt] identifier |
| 594 | /// class-key ::[opt] nested-name-specifier[opt] 'template'[opt] |
| 595 | /// simple-template-id |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 596 | /// |
| 597 | /// Note that the C++ class-specifier and elaborated-type-specifier, |
| 598 | /// together, subsume the C99 struct-or-union-specifier: |
| 599 | /// |
| 600 | /// struct-or-union-specifier: [C99 6.7.2.1] |
| 601 | /// struct-or-union identifier[opt] '{' struct-contents '}' |
| 602 | /// struct-or-union identifier |
| 603 | /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents |
| 604 | /// '}' attributes[opt] |
| 605 | /// [GNU] struct-or-union attributes[opt] identifier |
| 606 | /// struct-or-union: |
| 607 | /// 'struct' |
| 608 | /// 'union' |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 609 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, |
| 610 | SourceLocation StartLoc, DeclSpec &DS, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 611 | const ParsedTemplateInfo &TemplateInfo, |
Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 612 | AccessSpecifier AS, bool SuppressDeclarations){ |
Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 613 | DeclSpec::TST TagType; |
| 614 | if (TagTokKind == tok::kw_struct) |
| 615 | TagType = DeclSpec::TST_struct; |
| 616 | else if (TagTokKind == tok::kw_class) |
| 617 | TagType = DeclSpec::TST_class; |
| 618 | else { |
| 619 | assert(TagTokKind == tok::kw_union && "Not a class specifier"); |
| 620 | TagType = DeclSpec::TST_union; |
| 621 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 622 | |
Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 623 | if (Tok.is(tok::code_completion)) { |
| 624 | // Code completion for a struct, class, or union name. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 625 | Actions.CodeCompleteTag(getCurScope(), TagType); |
Douglas Gregor | dc84534 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 626 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 627 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 628 | |
Chandler Carruth | 926c4b4 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 629 | // C++03 [temp.explicit] 14.7.2/8: |
| 630 | // The usual access checking rules do not apply to names used to specify |
| 631 | // explicit instantiations. |
| 632 | // |
| 633 | // As an extension we do not perform access checking on the names used to |
| 634 | // specify explicit specializations either. This is important to allow |
| 635 | // specializing traits classes for private types. |
| 636 | bool SuppressingAccessChecks = false; |
| 637 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || |
| 638 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) { |
| 639 | Actions.ActOnStartSuppressingAccessChecks(); |
| 640 | SuppressingAccessChecks = true; |
| 641 | } |
| 642 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 643 | AttributeList *AttrList = 0; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 644 | // If attributes exist after tag, parse them. |
| 645 | if (Tok.is(tok::kw___attribute)) |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 646 | AttrList = ParseGNUAttributes(); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 647 | |
Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 648 | // If declspecs exist after tag, parse them. |
John McCall | b1d397c | 2010-08-05 17:13:11 +0000 | [diff] [blame] | 649 | while (Tok.is(tok::kw___declspec)) |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 650 | AttrList = ParseMicrosoftDeclSpec(AttrList); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 651 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 652 | // If C++0x attributes exist here, parse them. |
| 653 | // FIXME: Are we consistent with the ordering of parsing of different |
| 654 | // styles of attributes? |
| 655 | if (isCXX0XAttributeSpecifier()) |
| 656 | AttrList = addAttributeLists(AttrList, ParseCXX0XAttributes().AttrList); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 658 | if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_pod)) { |
| 659 | // GNU libstdc++ 4.2 uses __is_pod as the name of a struct template, but |
| 660 | // __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] | 661 | // token sequence "struct __is_pod", make __is_pod into a normal |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 662 | // identifier rather than a keyword, to allow libstdc++ 4.2 to work |
| 663 | // properly. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame^] | 664 | Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 665 | Tok.setKind(tok::identifier); |
| 666 | } |
| 667 | |
| 668 | if (TagType == DeclSpec::TST_struct && Tok.is(tok::kw___is_empty)) { |
| 669 | // GNU libstdc++ 4.2 uses __is_empty as the name of a struct template, but |
| 670 | // __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] | 671 | // token sequence "struct __is_empty", make __is_empty into a normal |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 672 | // identifier rather than a keyword, to allow libstdc++ 4.2 to work |
| 673 | // properly. |
Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame^] | 674 | Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); |
Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 675 | Tok.setKind(tok::identifier); |
| 676 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 678 | // Parse the (optional) nested-name-specifier. |
John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 679 | CXXScopeSpec &SS = DS.getTypeSpecScope(); |
Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 680 | if (getLang().CPlusPlus) { |
| 681 | // "FOO : BAR" is not a potential typo for "FOO::BAR". |
| 682 | ColonProtectionRAIIObject X(*this); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 683 | |
John McCall | 207014e | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 684 | if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true)) |
| 685 | DS.SetTypeSpecError(); |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 686 | if (SS.isSet()) |
Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 687 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) |
| 688 | Diag(Tok, diag::err_expected_ident); |
| 689 | } |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 690 | |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 691 | TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; |
| 692 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 693 | // Parse the (optional) class name or simple-template-id. |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 694 | IdentifierInfo *Name = 0; |
| 695 | SourceLocation NameLoc; |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 696 | TemplateIdAnnotation *TemplateId = 0; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 697 | if (Tok.is(tok::identifier)) { |
| 698 | Name = Tok.getIdentifierInfo(); |
| 699 | NameLoc = ConsumeToken(); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 700 | |
Douglas Gregor | 5ee3734 | 2010-05-30 22:30:21 +0000 | [diff] [blame] | 701 | if (Tok.is(tok::less) && getLang().CPlusPlus) { |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 702 | // The name was supposed to refer to a template, but didn't. |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 703 | // Eat the template argument list and try to continue parsing this as |
| 704 | // a class (or template thereof). |
| 705 | TemplateArgList TemplateArgs; |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 706 | SourceLocation LAngleLoc, RAngleLoc; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 707 | if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, &SS, |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 708 | true, LAngleLoc, |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 709 | TemplateArgs, RAngleLoc)) { |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 710 | // We couldn't parse the template argument list at all, so don't |
| 711 | // try to give any location information for the list. |
| 712 | LAngleLoc = RAngleLoc = SourceLocation(); |
| 713 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 714 | |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 715 | Diag(NameLoc, diag::err_explicit_spec_non_template) |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 716 | << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 717 | << (TagType == DeclSpec::TST_class? 0 |
| 718 | : TagType == DeclSpec::TST_struct? 1 |
| 719 | : 2) |
| 720 | << Name |
| 721 | << SourceRange(LAngleLoc, RAngleLoc); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 722 | |
| 723 | // Strip off the last template parameter list if it was empty, since |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 724 | // we've removed its template argument list. |
| 725 | if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { |
| 726 | if (TemplateParams && TemplateParams->size() > 1) { |
| 727 | TemplateParams->pop_back(); |
| 728 | } else { |
| 729 | TemplateParams = 0; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 730 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 731 | = ParsedTemplateInfo::NonTemplate; |
| 732 | } |
| 733 | } else if (TemplateInfo.Kind |
| 734 | == ParsedTemplateInfo::ExplicitInstantiation) { |
| 735 | // Pretend this is just a forward declaration. |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 736 | TemplateParams = 0; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 737 | const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 738 | = ParsedTemplateInfo::NonTemplate; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 739 | const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc |
Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 740 | = SourceLocation(); |
| 741 | const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc |
| 742 | = SourceLocation(); |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 743 | } |
Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 744 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 745 | } else if (Tok.is(tok::annot_template_id)) { |
| 746 | TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
| 747 | NameLoc = ConsumeToken(); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 748 | |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 749 | if (TemplateId->Kind != TNK_Type_template) { |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 750 | // The template-name in the simple-template-id refers to |
| 751 | // something other than a class template. Give an appropriate |
| 752 | // error message and skip to the ';'. |
| 753 | SourceRange Range(NameLoc); |
| 754 | if (SS.isNotEmpty()) |
| 755 | Range.setBegin(SS.getBeginLoc()); |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 757 | Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) |
| 758 | << Name << static_cast<int>(TemplateId->Kind) << Range; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 759 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 760 | DS.SetTypeSpecError(); |
| 761 | SkipUntil(tok::semi, false, true); |
| 762 | TemplateId->Destroy(); |
Chandler Carruth | 926c4b4 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 763 | if (SuppressingAccessChecks) |
| 764 | Actions.ActOnStopSuppressingAccessChecks(); |
| 765 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 766 | return; |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 767 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Chandler Carruth | 926c4b4 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 770 | // As soon as we're finished parsing the class's template-id, turn access |
| 771 | // checking back on. |
| 772 | if (SuppressingAccessChecks) |
| 773 | Actions.ActOnStopSuppressingAccessChecks(); |
| 774 | |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 775 | // There are four options here. If we have 'struct foo;', then this |
| 776 | // is either a forward declaration or a friend declaration, which |
| 777 | // have to be treated differently. If we have 'struct foo {...' or |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 778 | // 'struct foo :...' then this is a definition. Otherwise we have |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 779 | // something like 'struct foo xyz', a reference. |
Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 780 | // However, in some contexts, things look like declarations but are just |
| 781 | // references, e.g. |
| 782 | // new struct s; |
| 783 | // or |
| 784 | // &T::operator struct s; |
| 785 | // For these, SuppressDeclarations is true. |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 786 | Action::TagUseKind TUK; |
Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 787 | if (SuppressDeclarations) |
| 788 | TUK = Action::TUK_Reference; |
| 789 | else if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon))){ |
Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 790 | if (DS.isFriendSpecified()) { |
| 791 | // C++ [class.friend]p2: |
| 792 | // A class shall not be defined in a friend declaration. |
| 793 | Diag(Tok.getLocation(), diag::err_friend_decl_defines_class) |
| 794 | << SourceRange(DS.getFriendSpecLoc()); |
| 795 | |
| 796 | // Skip everything up to the semicolon, so that this looks like a proper |
| 797 | // friend class (or template thereof) declaration. |
| 798 | SkipUntil(tok::semi, true, true); |
| 799 | TUK = Action::TUK_Friend; |
| 800 | } else { |
| 801 | // Okay, this is a class definition. |
| 802 | TUK = Action::TUK_Definition; |
| 803 | } |
| 804 | } else if (Tok.is(tok::semi)) |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 805 | TUK = DS.isFriendSpecified() ? Action::TUK_Friend : Action::TUK_Declaration; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 806 | else |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 807 | TUK = Action::TUK_Reference; |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 808 | |
John McCall | 207014e | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 809 | if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || |
| 810 | TUK != Action::TUK_Definition)) { |
| 811 | if (DS.getTypeSpecType() != DeclSpec::TST_error) { |
| 812 | // We have a declaration or reference to an anonymous class. |
| 813 | Diag(StartLoc, diag::err_anon_type_definition) |
| 814 | << DeclSpec::getSpecifierName(TagType); |
| 815 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 816 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 817 | SkipUntil(tok::comma, true); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 818 | |
| 819 | if (TemplateId) |
| 820 | TemplateId->Destroy(); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 824 | // Create the tag portion of the class or class template. |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 825 | Action::DeclResult TagOrTempResult = true; // invalid |
| 826 | Action::TypeResult TypeResult = true; // invalid |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 827 | |
Douglas Gregor | 402abb5 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 828 | bool Owned = false; |
John McCall | f1bbbb4 | 2009-09-04 01:14:41 +0000 | [diff] [blame] | 829 | if (TemplateId) { |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 830 | // Explicit specialization, class template partial specialization, |
| 831 | // or explicit instantiation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | ASTTemplateArgsPtr TemplateArgsPtr(Actions, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 833 | TemplateId->getTemplateArgs(), |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 834 | TemplateId->NumArgs); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 835 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 836 | TUK == Action::TUK_Declaration) { |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 837 | // This is an explicit instantiation of a class template. |
| 838 | TagOrTempResult |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 839 | = Actions.ActOnExplicitInstantiation(getCurScope(), |
Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 840 | TemplateInfo.ExternLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | TemplateInfo.TemplateLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 842 | TagType, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | StartLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 844 | SS, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | TemplateTy::make(TemplateId->Template), |
| 846 | TemplateId->TemplateNameLoc, |
| 847 | TemplateId->LAngleLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 848 | TemplateArgsPtr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 849 | TemplateId->RAngleLoc, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 850 | AttrList); |
John McCall | 74256f5 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 851 | |
| 852 | // Friend template-ids are treated as references unless |
| 853 | // they have template headers, in which case they're ill-formed |
| 854 | // (FIXME: "template <class T> friend class A<T>::B<int>;"). |
| 855 | // We diagnose this error in ActOnClassTemplateSpecialization. |
| 856 | } else if (TUK == Action::TUK_Reference || |
| 857 | (TUK == Action::TUK_Friend && |
| 858 | TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 859 | TypeResult |
John McCall | 6b2becf | 2009-09-08 17:47:29 +0000 | [diff] [blame] | 860 | = Actions.ActOnTemplateIdType(TemplateTy::make(TemplateId->Template), |
| 861 | TemplateId->TemplateNameLoc, |
| 862 | TemplateId->LAngleLoc, |
| 863 | TemplateArgsPtr, |
John McCall | 6b2becf | 2009-09-08 17:47:29 +0000 | [diff] [blame] | 864 | TemplateId->RAngleLoc); |
| 865 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 866 | TypeResult = Actions.ActOnTagTemplateIdType(TypeResult, TUK, |
| 867 | TagType, StartLoc); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 868 | } else { |
| 869 | // This is an explicit specialization or a class template |
| 870 | // partial specialization. |
| 871 | TemplateParameterLists FakedParamLists; |
| 872 | |
| 873 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 874 | // This looks like an explicit instantiation, because we have |
| 875 | // something like |
| 876 | // |
| 877 | // template class Foo<X> |
| 878 | // |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 879 | // but it actually has a definition. Most likely, this was |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 880 | // meant to be an explicit specialization, but the user forgot |
| 881 | // the '<>' after 'template'. |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 882 | assert(TUK == Action::TUK_Definition && "Expected a definition here"); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 883 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | SourceLocation LAngleLoc |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 885 | = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 886 | Diag(TemplateId->TemplateNameLoc, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 887 | diag::err_explicit_instantiation_with_definition) |
| 888 | << SourceRange(TemplateInfo.TemplateLoc) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 889 | << FixItHint::CreateInsertion(LAngleLoc, "<>"); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 890 | |
| 891 | // Create a fake template parameter list that contains only |
| 892 | // "template<>", so that we treat this construct as a class |
| 893 | // template specialization. |
| 894 | FakedParamLists.push_back( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | Actions.ActOnTemplateParameterList(0, SourceLocation(), |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 896 | TemplateInfo.TemplateLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | LAngleLoc, |
| 898 | 0, 0, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 899 | LAngleLoc)); |
| 900 | TemplateParams = &FakedParamLists; |
| 901 | } |
| 902 | |
| 903 | // Build the class template specialization. |
| 904 | TagOrTempResult |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 905 | = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 906 | StartLoc, SS, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 907 | TemplateTy::make(TemplateId->Template), |
| 908 | TemplateId->TemplateNameLoc, |
| 909 | TemplateId->LAngleLoc, |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 910 | TemplateArgsPtr, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | TemplateId->RAngleLoc, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 912 | AttrList, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | Action::MultiTemplateParamsArg(Actions, |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 914 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 915 | TemplateParams? TemplateParams->size() : 0)); |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 916 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 917 | TemplateId->Destroy(); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 918 | } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 919 | TUK == Action::TUK_Declaration) { |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 920 | // Explicit instantiation of a member of a class template |
| 921 | // specialization, e.g., |
| 922 | // |
| 923 | // template struct Outer<int>::Inner; |
| 924 | // |
| 925 | TagOrTempResult |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 926 | = Actions.ActOnExplicitInstantiation(getCurScope(), |
Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 927 | TemplateInfo.ExternLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | TemplateInfo.TemplateLoc, |
| 929 | TagType, StartLoc, SS, Name, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 930 | NameLoc, AttrList); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 931 | } else { |
| 932 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && |
John McCall | 0f434ec | 2009-07-31 02:45:11 +0000 | [diff] [blame] | 933 | TUK == Action::TUK_Definition) { |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 934 | // FIXME: Diagnose this particular error. |
| 935 | } |
| 936 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 937 | bool IsDependent = false; |
| 938 | |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 939 | // Declaration or definition of a class type |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 940 | TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc, SS, |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 941 | Name, NameLoc, AttrList, AS, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 942 | Action::MultiTemplateParamsArg(Actions, |
Douglas Gregor | 7cdbc58 | 2009-07-22 23:48:44 +0000 | [diff] [blame] | 943 | TemplateParams? &(*TemplateParams)[0] : 0, |
| 944 | TemplateParams? TemplateParams->size() : 0), |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 945 | Owned, IsDependent); |
| 946 | |
| 947 | // If ActOnTag said the type was dependent, try again with the |
| 948 | // less common call. |
| 949 | if (IsDependent) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 950 | TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 951 | SS, Name, StartLoc, NameLoc); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 952 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 953 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 954 | // If there is a body, parse it and inform the actions module. |
John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 955 | if (TUK == Action::TUK_Definition) { |
| 956 | assert(Tok.is(tok::l_brace) || |
| 957 | (getLang().CPlusPlus && Tok.is(tok::colon))); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 958 | if (getLang().CPlusPlus) |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 959 | ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get()); |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 960 | else |
Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 961 | ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 962 | } |
| 963 | |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 964 | void *Result; |
| 965 | if (!TypeResult.isInvalid()) { |
| 966 | TagType = DeclSpec::TST_typename; |
| 967 | Result = TypeResult.get(); |
| 968 | Owned = false; |
| 969 | } else if (!TagOrTempResult.isInvalid()) { |
| 970 | Result = TagOrTempResult.get().getAs<void>(); |
| 971 | } else { |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 972 | DS.SetTypeSpecError(); |
Anders Carlsson | 66e9977 | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 973 | return; |
| 974 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 976 | const char *PrevSpec = 0; |
| 977 | unsigned DiagID; |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | b988f9c | 2010-01-25 16:33:23 +0000 | [diff] [blame] | 979 | // FIXME: The DeclSpec should keep the locations of both the keyword and the |
| 980 | // name (if there is one). |
| 981 | SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | b988f9c | 2010-01-25 16:33:23 +0000 | [diff] [blame] | 983 | if (DS.SetTypeSpecType(TagType, TSTLoc, PrevSpec, DiagID, |
John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 984 | Result, Owned)) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 985 | Diag(StartLoc, DiagID) << PrevSpec; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 986 | |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 987 | // At this point, we've successfully parsed a class-specifier in 'definition' |
| 988 | // form (e.g. "struct foo { int x; }". While we could just return here, we're |
| 989 | // going to look at what comes after it to improve error recovery. If an |
| 990 | // impossible token occurs next, we assume that the programmer forgot a ; at |
| 991 | // the end of the declaration and recover that way. |
| 992 | // |
| 993 | // This switch enumerates the valid "follow" set for definition. |
| 994 | if (TUK == Action::TUK_Definition) { |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 995 | bool ExpectedSemi = true; |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 996 | switch (Tok.getKind()) { |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 997 | default: break; |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 998 | case tok::semi: // struct foo {...} ; |
Chris Lattner | 99c9520 | 2010-02-02 17:32:27 +0000 | [diff] [blame] | 999 | case tok::star: // struct foo {...} * P; |
| 1000 | case tok::amp: // struct foo {...} & R = ... |
| 1001 | case tok::identifier: // struct foo {...} V ; |
| 1002 | case tok::r_paren: //(struct foo {...} ) {4} |
| 1003 | case tok::annot_cxxscope: // struct foo {...} a:: b; |
| 1004 | case tok::annot_typename: // struct foo {...} a ::b; |
| 1005 | case tok::annot_template_id: // struct foo {...} a<int> ::b; |
Chris Lattner | c2e1c1a | 2010-02-03 20:41:24 +0000 | [diff] [blame] | 1006 | case tok::l_paren: // struct foo {...} ( x); |
Chris Lattner | 16acfee | 2010-02-03 01:45:03 +0000 | [diff] [blame] | 1007 | case tok::comma: // __builtin_offsetof(struct foo{...} , |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1008 | ExpectedSemi = false; |
| 1009 | break; |
| 1010 | // Type qualifiers |
| 1011 | case tok::kw_const: // struct foo {...} const x; |
| 1012 | case tok::kw_volatile: // struct foo {...} volatile x; |
| 1013 | case tok::kw_restrict: // struct foo {...} restrict x; |
| 1014 | case tok::kw_inline: // struct foo {...} inline foo() {}; |
Chris Lattner | 99c9520 | 2010-02-02 17:32:27 +0000 | [diff] [blame] | 1015 | // Storage-class specifiers |
| 1016 | case tok::kw_static: // struct foo {...} static x; |
| 1017 | case tok::kw_extern: // struct foo {...} extern x; |
| 1018 | case tok::kw_typedef: // struct foo {...} typedef x; |
| 1019 | case tok::kw_register: // struct foo {...} register x; |
| 1020 | case tok::kw_auto: // struct foo {...} auto x; |
Douglas Gregor | 33f9924 | 2010-05-17 18:19:56 +0000 | [diff] [blame] | 1021 | case tok::kw_mutable: // struct foo {...} mutable x; |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1022 | // As shown above, type qualifiers and storage class specifiers absolutely |
| 1023 | // can occur after class specifiers according to the grammar. However, |
| 1024 | // almost noone actually writes code like this. If we see one of these, |
| 1025 | // it is much more likely that someone missed a semi colon and the |
| 1026 | // type/storage class specifier we're seeing is part of the *next* |
| 1027 | // intended declaration, as in: |
| 1028 | // |
| 1029 | // struct foo { ... } |
| 1030 | // typedef int X; |
| 1031 | // |
| 1032 | // We'd really like to emit a missing semicolon error instead of emitting |
| 1033 | // an error on the 'int' saying that you can't have two type specifiers in |
| 1034 | // the same declaration of X. Because of this, we look ahead past this |
| 1035 | // token to see if it's a type specifier. If so, we know the code is |
| 1036 | // otherwise invalid, so we can produce the expected semi error. |
| 1037 | if (!isKnownToBeTypeSpecifier(NextToken())) |
| 1038 | ExpectedSemi = false; |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1039 | break; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1040 | |
| 1041 | case tok::r_brace: // struct bar { struct foo {...} } |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1042 | // Missing ';' at end of struct is accepted as an extension in C mode. |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1043 | if (!getLang().CPlusPlus) |
| 1044 | ExpectedSemi = false; |
| 1045 | break; |
| 1046 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1047 | |
Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 1048 | if (ExpectedSemi) { |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1049 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl, |
| 1050 | TagType == DeclSpec::TST_class ? "class" |
| 1051 | : TagType == DeclSpec::TST_struct? "struct" : "union"); |
| 1052 | // Push this token back into the preprocessor and change our current token |
| 1053 | // to ';' so that the rest of the code recovers as though there were an |
| 1054 | // ';' after the definition. |
| 1055 | PP.EnterToken(Tok); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1056 | Tok.setKind(tok::semi); |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1057 | } |
| 1058 | } |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1062 | /// |
| 1063 | /// base-clause : [C++ class.derived] |
| 1064 | /// ':' base-specifier-list |
| 1065 | /// base-specifier-list: |
| 1066 | /// base-specifier '...'[opt] |
| 1067 | /// base-specifier-list ',' base-specifier '...'[opt] |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1068 | void Parser::ParseBaseClause(DeclPtrTy ClassDecl) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1069 | assert(Tok.is(tok::colon) && "Not a base clause"); |
| 1070 | ConsumeToken(); |
| 1071 | |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1072 | // Build up an array of parsed base specifiers. |
| 1073 | llvm::SmallVector<BaseTy *, 8> BaseInfo; |
| 1074 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1075 | while (true) { |
| 1076 | // Parse a base-specifier. |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1077 | BaseResult Result = ParseBaseSpecifier(ClassDecl); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1078 | if (Result.isInvalid()) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1079 | // Skip the rest of this base specifier, up until the comma or |
| 1080 | // opening brace. |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1081 | SkipUntil(tok::comma, tok::l_brace, true, true); |
| 1082 | } else { |
| 1083 | // Add this to our array of base specifiers. |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1084 | BaseInfo.push_back(Result.get()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | // If the next token is a comma, consume it and keep reading |
| 1088 | // base-specifiers. |
| 1089 | if (Tok.isNot(tok::comma)) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1090 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1091 | // Consume the comma. |
| 1092 | ConsumeToken(); |
| 1093 | } |
Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1094 | |
| 1095 | // Attach the base specifiers |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1096 | Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is |
| 1100 | /// one entry in the base class list of a class specifier, for example: |
| 1101 | /// class foo : public bar, virtual private baz { |
| 1102 | /// 'public bar' and 'virtual private baz' are each base-specifiers. |
| 1103 | /// |
| 1104 | /// base-specifier: [C++ class.derived] |
| 1105 | /// ::[opt] nested-name-specifier[opt] class-name |
| 1106 | /// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt] |
| 1107 | /// class-name |
| 1108 | /// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt] |
| 1109 | /// class-name |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1110 | Parser::BaseResult Parser::ParseBaseSpecifier(DeclPtrTy ClassDecl) { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1111 | bool IsVirtual = false; |
| 1112 | SourceLocation StartLoc = Tok.getLocation(); |
| 1113 | |
| 1114 | // Parse the 'virtual' keyword. |
| 1115 | if (Tok.is(tok::kw_virtual)) { |
| 1116 | ConsumeToken(); |
| 1117 | IsVirtual = true; |
| 1118 | } |
| 1119 | |
| 1120 | // Parse an (optional) access specifier. |
| 1121 | AccessSpecifier Access = getAccessSpecifierIfPresent(); |
John McCall | 92f8831 | 2010-01-23 00:46:32 +0000 | [diff] [blame] | 1122 | if (Access != AS_none) |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1123 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1125 | // Parse the 'virtual' keyword (again!), in case it came after the |
| 1126 | // access specifier. |
| 1127 | if (Tok.is(tok::kw_virtual)) { |
| 1128 | SourceLocation VirtualLoc = ConsumeToken(); |
| 1129 | if (IsVirtual) { |
| 1130 | // Complain about duplicate 'virtual' |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1131 | Diag(VirtualLoc, diag::err_dup_virtual) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1132 | << FixItHint::CreateRemoval(VirtualLoc); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | IsVirtual = true; |
| 1136 | } |
| 1137 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1138 | // Parse optional '::' and optional nested-name-specifier. |
| 1139 | CXXScopeSpec SS; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1140 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, |
Douglas Gregor | d2b43bf | 2010-03-02 00:25:00 +0000 | [diff] [blame] | 1141 | /*EnteringContext=*/false); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1143 | // The location of the base class itself. |
| 1144 | SourceLocation BaseLoc = Tok.getLocation(); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1145 | |
| 1146 | // Parse the class-name. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1147 | SourceLocation EndLocation; |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1148 | TypeResult BaseType = ParseClassName(EndLocation, &SS); |
| 1149 | if (BaseType.isInvalid()) |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1150 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | |
| 1152 | // Find the complete source range for the base-specifier. |
Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1153 | SourceRange Range(StartLoc, EndLocation); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1154 | |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1155 | // Notify semantic analysis that we have parsed a complete |
| 1156 | // base-specifier. |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1157 | return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access, |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1158 | BaseType.get(), BaseLoc); |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /// getAccessSpecifierIfPresent - Determine whether the next token is |
| 1162 | /// a C++ access-specifier. |
| 1163 | /// |
| 1164 | /// access-specifier: [C++ class.derived] |
| 1165 | /// 'private' |
| 1166 | /// 'protected' |
| 1167 | /// 'public' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const { |
Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1169 | switch (Tok.getKind()) { |
| 1170 | default: return AS_none; |
| 1171 | case tok::kw_private: return AS_private; |
| 1172 | case tok::kw_protected: return AS_protected; |
| 1173 | case tok::kw_public: return AS_public; |
| 1174 | } |
| 1175 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1176 | |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1177 | void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, |
| 1178 | DeclPtrTy ThisDecl) { |
| 1179 | // We just declared a member function. If this member function |
| 1180 | // has any default arguments, we'll need to parse them later. |
| 1181 | LateParsedMethodDeclaration *LateMethod = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | DeclaratorChunk::FunctionTypeInfo &FTI |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1183 | = DeclaratorInfo.getTypeObject(0).Fun; |
| 1184 | for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { |
| 1185 | if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { |
| 1186 | if (!LateMethod) { |
| 1187 | // Push this method onto the stack of late-parsed method |
| 1188 | // declarations. |
| 1189 | getCurrentClass().MethodDecls.push_back( |
| 1190 | LateParsedMethodDeclaration(ThisDecl)); |
| 1191 | LateMethod = &getCurrentClass().MethodDecls.back(); |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1192 | LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1193 | |
| 1194 | // Add all of the parameters prior to this one (they don't |
| 1195 | // have default arguments). |
| 1196 | LateMethod->DefaultArgs.reserve(FTI.NumArgs); |
| 1197 | for (unsigned I = 0; I < ParamIdx; ++I) |
| 1198 | LateMethod->DefaultArgs.push_back( |
Douglas Gregor | 8f8210c | 2010-03-02 01:29:43 +0000 | [diff] [blame] | 1199 | LateParsedDefaultArgument(FTI.ArgInfo[I].Param)); |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | // Add this parameter to the list of parameters (it or may |
| 1203 | // not have a default argument). |
| 1204 | LateMethod->DefaultArgs.push_back( |
| 1205 | LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, |
| 1206 | FTI.ArgInfo[ParamIdx].DefaultArgTokens)); |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1211 | /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. |
| 1212 | /// |
| 1213 | /// member-declaration: |
| 1214 | /// decl-specifier-seq[opt] member-declarator-list[opt] ';' |
| 1215 | /// function-definition ';'[opt] |
| 1216 | /// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] |
| 1217 | /// using-declaration [TODO] |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1218 | /// [C++0x] static_assert-declaration |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1219 | /// template-declaration |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1220 | /// [GNU] '__extension__' member-declaration |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1221 | /// |
| 1222 | /// member-declarator-list: |
| 1223 | /// member-declarator |
| 1224 | /// member-declarator-list ',' member-declarator |
| 1225 | /// |
| 1226 | /// member-declarator: |
| 1227 | /// declarator pure-specifier[opt] |
| 1228 | /// declarator constant-initializer[opt] |
| 1229 | /// identifier[opt] ':' constant-expression |
| 1230 | /// |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1231 | /// pure-specifier: |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1232 | /// '= 0' |
| 1233 | /// |
| 1234 | /// constant-initializer: |
| 1235 | /// '=' constant-expression |
| 1236 | /// |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1237 | void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, |
John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1238 | const ParsedTemplateInfo &TemplateInfo, |
| 1239 | ParsingDeclRAIIObject *TemplateDiags) { |
John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1240 | // Access declarations. |
| 1241 | if (!TemplateInfo.Kind && |
| 1242 | (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) && |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1243 | !TryAnnotateCXXScopeToken() && |
John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1244 | Tok.is(tok::annot_cxxscope)) { |
| 1245 | bool isAccessDecl = false; |
| 1246 | if (NextToken().is(tok::identifier)) |
| 1247 | isAccessDecl = GetLookAheadToken(2).is(tok::semi); |
| 1248 | else |
| 1249 | isAccessDecl = NextToken().is(tok::kw_operator); |
| 1250 | |
| 1251 | if (isAccessDecl) { |
| 1252 | // Collect the scope specifier token we annotated earlier. |
| 1253 | CXXScopeSpec SS; |
| 1254 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType*/ 0, false); |
| 1255 | |
| 1256 | // Try to parse an unqualified-id. |
| 1257 | UnqualifiedId Name; |
| 1258 | if (ParseUnqualifiedId(SS, false, true, true, /*ObjectType*/ 0, Name)) { |
| 1259 | SkipUntil(tok::semi); |
| 1260 | return; |
| 1261 | } |
| 1262 | |
| 1263 | // TODO: recover from mistakenly-qualified operator declarations. |
| 1264 | if (ExpectAndConsume(tok::semi, |
| 1265 | diag::err_expected_semi_after, |
| 1266 | "access declaration", |
| 1267 | tok::semi)) |
| 1268 | return; |
| 1269 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1270 | Actions.ActOnUsingDeclaration(getCurScope(), AS, |
John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1271 | false, SourceLocation(), |
| 1272 | SS, Name, |
| 1273 | /* AttrList */ 0, |
| 1274 | /* IsTypeName */ false, |
| 1275 | SourceLocation()); |
| 1276 | return; |
| 1277 | } |
| 1278 | } |
| 1279 | |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1280 | // static_assert-declaration |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1281 | if (Tok.is(tok::kw_static_assert)) { |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1282 | // FIXME: Check for templates |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1283 | SourceLocation DeclEnd; |
| 1284 | ParseStaticAssertDeclaration(DeclEnd); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1285 | return; |
| 1286 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1288 | if (Tok.is(tok::kw_template)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1289 | assert(!TemplateInfo.TemplateParams && |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1290 | "Nested template improperly parsed?"); |
Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1291 | SourceLocation DeclEnd; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, |
Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1293 | AS); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1294 | return; |
| 1295 | } |
Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1296 | |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1297 | // Handle: member-declaration ::= '__extension__' member-declaration |
| 1298 | if (Tok.is(tok::kw___extension__)) { |
| 1299 | // __extension__ silences extension warnings in the subexpression. |
| 1300 | ExtensionRAIIObject O(Diags); // Use RAII to do this. |
| 1301 | ConsumeToken(); |
John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1302 | return ParseCXXClassMemberDeclaration(AS, TemplateInfo, TemplateDiags); |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1303 | } |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1304 | |
Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1305 | // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it |
| 1306 | // is a bitfield. |
Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 1307 | ColonProtectionRAIIObject X(*this); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1308 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1309 | CXX0XAttributeList AttrList; |
| 1310 | // Optional C++0x attribute-specifier |
Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 1311 | if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1312 | AttrList = ParseCXX0XAttributes(); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1313 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1314 | if (Tok.is(tok::kw_using)) { |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1315 | // FIXME: Check for template aliases |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1316 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1317 | if (AttrList.HasAttr) |
| 1318 | Diag(AttrList.Range.getBegin(), diag::err_attributes_not_allowed) |
| 1319 | << AttrList.Range; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1321 | // Eat 'using'. |
| 1322 | SourceLocation UsingLoc = ConsumeToken(); |
| 1323 | |
| 1324 | if (Tok.is(tok::kw_namespace)) { |
| 1325 | Diag(UsingLoc, diag::err_using_namespace_in_class); |
| 1326 | SkipUntil(tok::semi, true, true); |
Chris Lattner | ae50d50 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 1327 | } else { |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1328 | SourceLocation DeclEnd; |
| 1329 | // Otherwise, it must be using-declaration. |
Anders Carlsson | 595adc1 | 2009-08-29 19:54:19 +0000 | [diff] [blame] | 1330 | ParseUsingDeclaration(Declarator::MemberContext, UsingLoc, DeclEnd, AS); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1331 | } |
| 1332 | return; |
| 1333 | } |
| 1334 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1335 | SourceLocation DSStart = Tok.getLocation(); |
| 1336 | // decl-specifier-seq: |
| 1337 | // Parse the common declaration-specifiers piece. |
John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1338 | ParsingDeclSpec DS(*this, TemplateDiags); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1339 | DS.AddAttributes(AttrList.AttrList); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1340 | ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1341 | |
John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 1342 | Action::MultiTemplateParamsArg TemplateParams(Actions, |
| 1343 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, |
| 1344 | TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); |
| 1345 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1346 | if (Tok.is(tok::semi)) { |
| 1347 | ConsumeToken(); |
John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1348 | DeclPtrTy TheDecl = |
| 1349 | Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS); |
| 1350 | DS.complete(TheDecl); |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1351 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1352 | } |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1353 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1354 | ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1355 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1356 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 1357 | // Don't parse FOO:BAR as if it were a typo for FOO::BAR. |
| 1358 | ColonProtectionRAIIObject X(*this); |
| 1359 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1360 | // Parse the first declarator. |
| 1361 | ParseDeclarator(DeclaratorInfo); |
| 1362 | // Error parsing the declarator? |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 1363 | if (!DeclaratorInfo.hasName()) { |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1364 | // If so, skip until the semi-colon or a }. |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1365 | SkipUntil(tok::r_brace, true); |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1366 | if (Tok.is(tok::semi)) |
| 1367 | ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1368 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
John Thompson | 1b2fc0f | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 1371 | // If attributes exist after the declarator, but before an '{', parse them. |
| 1372 | if (Tok.is(tok::kw___attribute)) { |
| 1373 | SourceLocation Loc; |
| 1374 | AttributeList *AttrList = ParseGNUAttributes(&Loc); |
| 1375 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 1376 | } |
| 1377 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1378 | // function-definition: |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1379 | if (Tok.is(tok::l_brace) |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 1380 | || (DeclaratorInfo.isFunctionDeclarator() && |
| 1381 | (Tok.is(tok::colon) || Tok.is(tok::kw_try)))) { |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1382 | if (!DeclaratorInfo.isFunctionDeclarator()) { |
| 1383 | Diag(Tok, diag::err_func_def_no_params); |
| 1384 | ConsumeBrace(); |
| 1385 | SkipUntil(tok::r_brace, true); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1386 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1387 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1388 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1389 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 1390 | Diag(Tok, diag::err_function_declared_typedef); |
| 1391 | // This recovery skips the entire function body. It would be nice |
| 1392 | // to simply call ParseCXXInlineMethodDef() below, however Sema |
| 1393 | // assumes the declarator represents a function, not a typedef. |
| 1394 | ConsumeBrace(); |
| 1395 | SkipUntil(tok::r_brace, true); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1396 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1399 | ParseCXXInlineMethodDef(AS, DeclaratorInfo, TemplateInfo); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1400 | return; |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1401 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | // member-declarator-list: |
| 1405 | // member-declarator |
| 1406 | // member-declarator-list ',' member-declarator |
| 1407 | |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1408 | llvm::SmallVector<DeclPtrTy, 8> DeclsInGroup; |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1409 | OwningExprResult BitfieldSize(Actions); |
| 1410 | OwningExprResult Init(Actions); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1411 | bool Deleted = false; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1412 | |
| 1413 | while (1) { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1414 | // member-declarator: |
| 1415 | // declarator pure-specifier[opt] |
| 1416 | // declarator constant-initializer[opt] |
| 1417 | // identifier[opt] ':' constant-expression |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1418 | if (Tok.is(tok::colon)) { |
| 1419 | ConsumeToken(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1420 | BitfieldSize = ParseConstantExpression(); |
| 1421 | if (BitfieldSize.isInvalid()) |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1422 | SkipUntil(tok::comma, true, true); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1423 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1425 | // pure-specifier: |
| 1426 | // '= 0' |
| 1427 | // |
| 1428 | // constant-initializer: |
| 1429 | // '=' constant-expression |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1430 | // |
| 1431 | // defaulted/deleted function-definition: |
| 1432 | // '=' 'default' [TODO] |
| 1433 | // '=' 'delete' |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1434 | if (Tok.is(tok::equal)) { |
| 1435 | ConsumeToken(); |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1436 | if (getLang().CPlusPlus0x && Tok.is(tok::kw_delete)) { |
| 1437 | ConsumeToken(); |
| 1438 | Deleted = true; |
| 1439 | } else { |
| 1440 | Init = ParseInitializer(); |
| 1441 | if (Init.isInvalid()) |
| 1442 | SkipUntil(tok::comma, true, true); |
| 1443 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Chris Lattner | e656325 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 1446 | // If a simple-asm-expr is present, parse it. |
| 1447 | if (Tok.is(tok::kw_asm)) { |
| 1448 | SourceLocation Loc; |
| 1449 | OwningExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
| 1450 | if (AsmLabel.isInvalid()) |
| 1451 | SkipUntil(tok::comma, true, true); |
| 1452 | |
| 1453 | DeclaratorInfo.setAsmLabel(AsmLabel.release()); |
| 1454 | DeclaratorInfo.SetRangeEnd(Loc); |
| 1455 | } |
| 1456 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1457 | // If attributes exist after the declarator, parse them. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1458 | if (Tok.is(tok::kw___attribute)) { |
| 1459 | SourceLocation Loc; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1460 | AttributeList *AttrList = ParseGNUAttributes(&Loc); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1461 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 1462 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1463 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1464 | // 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] | 1465 | // this call will *not* return the created decl; It will return null. |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1466 | // See Sema::ActOnCXXMemberDeclarator for details. |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1467 | |
| 1468 | DeclPtrTy ThisDecl; |
| 1469 | if (DS.isFriendSpecified()) { |
John McCall | bbbcdd9 | 2009-09-11 21:02:39 +0000 | [diff] [blame] | 1470 | // TODO: handle initializers, bitfields, 'delete' |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1471 | ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, |
John McCall | bbbcdd9 | 2009-09-11 21:02:39 +0000 | [diff] [blame] | 1472 | /*IsDefinition*/ false, |
| 1473 | move(TemplateParams)); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1474 | } else { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1475 | ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1476 | DeclaratorInfo, |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1477 | move(TemplateParams), |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1478 | BitfieldSize.release(), |
| 1479 | Init.release(), |
Sebastian Redl | d1a7846 | 2009-11-24 23:38:44 +0000 | [diff] [blame] | 1480 | /*IsDefinition*/Deleted, |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1481 | Deleted); |
Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1482 | } |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1483 | if (ThisDecl) |
| 1484 | DeclsInGroup.push_back(ThisDecl); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1485 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1486 | if (DeclaratorInfo.isFunctionDeclarator() && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1487 | DeclaratorInfo.getDeclSpec().getStorageClassSpec() |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1488 | != DeclSpec::SCS_typedef) { |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1489 | HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1492 | DeclaratorInfo.complete(ThisDecl); |
| 1493 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1494 | // If we don't have a comma, it is either the end of the list (a ';') |
| 1495 | // or an error, bail out. |
| 1496 | if (Tok.isNot(tok::comma)) |
| 1497 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1499 | // Consume the comma. |
| 1500 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1502 | // Parse the next declarator. |
| 1503 | DeclaratorInfo.clear(); |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1504 | BitfieldSize = 0; |
| 1505 | Init = 0; |
Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1506 | Deleted = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1507 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1508 | // Attributes are only allowed on the second declarator. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1509 | if (Tok.is(tok::kw___attribute)) { |
| 1510 | SourceLocation Loc; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1511 | AttributeList *AttrList = ParseGNUAttributes(&Loc); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1512 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 1513 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1514 | |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 1515 | if (Tok.isNot(tok::colon)) |
| 1516 | ParseDeclarator(DeclaratorInfo); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Chris Lattner | ae50d50 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 1519 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { |
| 1520 | // Skip to end of block or statement. |
| 1521 | SkipUntil(tok::r_brace, true, true); |
| 1522 | // If we stopped at a ';', eat it. |
| 1523 | if (Tok.is(tok::semi)) ConsumeToken(); |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1524 | return; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1527 | Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup.data(), |
Chris Lattner | ae50d50 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 1528 | DeclsInGroup.size()); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | /// ParseCXXMemberSpecification - Parse the class definition. |
| 1532 | /// |
| 1533 | /// member-specification: |
| 1534 | /// member-declaration member-specification[opt] |
| 1535 | /// access-specifier ':' member-specification[opt] |
| 1536 | /// |
| 1537 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1538 | unsigned TagType, DeclPtrTy TagDecl) { |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1539 | assert((TagType == DeclSpec::TST_struct || |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1540 | TagType == DeclSpec::TST_union || |
Sanjiv Gupta | 31fc07d | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 1541 | TagType == DeclSpec::TST_class) && "Invalid TagType!"); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1542 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 1543 | PrettyStackTraceActionsDecl CrashInfo(TagDecl, RecordLoc, Actions, |
| 1544 | PP.getSourceManager(), |
| 1545 | "parsing struct/union/class body"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1546 | |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1547 | // Determine whether this is a non-nested class. Note that local |
| 1548 | // classes are *not* considered to be nested classes. |
| 1549 | bool NonNestedClass = true; |
| 1550 | if (!ClassStack.empty()) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1551 | for (const Scope *S = getCurScope(); S; S = S->getParent()) { |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1552 | if (S->isClassScope()) { |
| 1553 | // We're inside a class scope, so this is a nested class. |
| 1554 | NonNestedClass = false; |
| 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | if ((S->getFlags() & Scope::FnScope)) { |
| 1559 | // If we're in a function or function template declared in the |
| 1560 | // body of a class, then this is a local class rather than a |
| 1561 | // nested class. |
| 1562 | const Scope *Parent = S->getParent(); |
| 1563 | if (Parent->isTemplateParamScope()) |
| 1564 | Parent = Parent->getParent(); |
| 1565 | if (Parent->isClassScope()) |
| 1566 | break; |
| 1567 | } |
| 1568 | } |
| 1569 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1570 | |
| 1571 | // Enter a scope for the class. |
Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 1572 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1573 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1574 | // Note that we are parsing a new (potentially-nested) class definition. |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1575 | ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1576 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1577 | if (TagDecl) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1578 | Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); |
John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1579 | |
| 1580 | if (Tok.is(tok::colon)) { |
| 1581 | ParseBaseClause(TagDecl); |
| 1582 | |
| 1583 | if (!Tok.is(tok::l_brace)) { |
| 1584 | Diag(Tok, diag::err_expected_lbrace_after_base_specifiers); |
John McCall | db7bb4a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 1585 | |
| 1586 | if (TagDecl) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1587 | Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); |
John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1588 | return; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | assert(Tok.is(tok::l_brace)); |
| 1593 | |
| 1594 | SourceLocation LBraceLoc = ConsumeBrace(); |
| 1595 | |
John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1596 | if (TagDecl) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1597 | Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, LBraceLoc); |
John McCall | f936815 | 2009-12-20 07:58:13 +0000 | [diff] [blame] | 1598 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1599 | // C++ 11p3: Members of a class defined with the keyword class are private |
| 1600 | // by default. Members of a class defined with the keywords struct or union |
| 1601 | // are public by default. |
| 1602 | AccessSpecifier CurAS; |
| 1603 | if (TagType == DeclSpec::TST_class) |
| 1604 | CurAS = AS_private; |
| 1605 | else |
| 1606 | CurAS = AS_public; |
| 1607 | |
Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1608 | SourceLocation RBraceLoc; |
| 1609 | if (TagDecl) { |
| 1610 | // While we still have something to read, read the member-declarations. |
| 1611 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
| 1612 | // Each iteration of this loop reads one member-declaration. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1613 | |
Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1614 | // Check for extraneous top-level semicolon. |
| 1615 | if (Tok.is(tok::semi)) { |
| 1616 | Diag(Tok, diag::ext_extra_struct_semi) |
| 1617 | << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) |
| 1618 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 1619 | ConsumeToken(); |
| 1620 | continue; |
| 1621 | } |
| 1622 | |
| 1623 | AccessSpecifier AS = getAccessSpecifierIfPresent(); |
| 1624 | if (AS != AS_none) { |
| 1625 | // Current token is a C++ access specifier. |
| 1626 | CurAS = AS; |
| 1627 | SourceLocation ASLoc = Tok.getLocation(); |
| 1628 | ConsumeToken(); |
| 1629 | if (Tok.is(tok::colon)) |
| 1630 | Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); |
| 1631 | else |
| 1632 | Diag(Tok, diag::err_expected_colon); |
| 1633 | ConsumeToken(); |
| 1634 | continue; |
| 1635 | } |
| 1636 | |
| 1637 | // FIXME: Make sure we don't have a template here. |
| 1638 | |
| 1639 | // Parse all the comma separated declarators. |
| 1640 | ParseCXXClassMemberDeclaration(CurAS); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1643 | RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
| 1644 | } else { |
| 1645 | SkipUntil(tok::r_brace, false, false); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1646 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1648 | // If attributes exist after class contents, parse them. |
Ted Kremenek | 1e37765 | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 1649 | llvm::OwningPtr<AttributeList> AttrList; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1650 | if (Tok.is(tok::kw___attribute)) |
Douglas Gregor | 0b4c9b5 | 2010-03-29 14:42:08 +0000 | [diff] [blame] | 1651 | AttrList.reset(ParseGNUAttributes()); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1652 | |
John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1653 | if (TagDecl) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1654 | Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, |
John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1655 | LBraceLoc, RBraceLoc, |
| 1656 | AttrList.get()); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1657 | |
| 1658 | // C++ 9.2p2: Within the class member-specification, the class is regarded as |
| 1659 | // complete within function bodies, default arguments, |
| 1660 | // exception-specifications, and constructor ctor-initializers (including |
| 1661 | // such things in nested classes). |
| 1662 | // |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 1663 | // FIXME: Only function bodies and constructor ctor-initializers are |
| 1664 | // parsed correctly, fix the rest. |
Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 1665 | if (TagDecl && NonNestedClass) { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1666 | // 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] | 1667 | // are complete and we can parse the delayed portions of method |
| 1668 | // declarations and the lexed inline method definitions. |
Douglas Gregor | e0cc047 | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 1669 | SourceLocation SavedPrevTokLocation = PrevTokLocation; |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1670 | ParseLexedMethodDeclarations(getCurrentClass()); |
| 1671 | ParseLexedMethodDefs(getCurrentClass()); |
Douglas Gregor | e0cc047 | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 1672 | PrevTokLocation = SavedPrevTokLocation; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 1675 | if (TagDecl) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1676 | Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, RBraceLoc); |
John McCall | db7bb4a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 1677 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1678 | // Leave the class scope. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1679 | ParsingDef.Pop(); |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1680 | ClassScope.Exit(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1681 | } |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1682 | |
| 1683 | /// ParseConstructorInitializer - Parse a C++ constructor initializer, |
| 1684 | /// which explicitly initializes the members or base classes of a |
| 1685 | /// class (C++ [class.base.init]). For example, the three initializers |
| 1686 | /// after the ':' in the Derived constructor below: |
| 1687 | /// |
| 1688 | /// @code |
| 1689 | /// class Base { }; |
| 1690 | /// class Derived : Base { |
| 1691 | /// int x; |
| 1692 | /// float f; |
| 1693 | /// public: |
| 1694 | /// Derived(float f) : Base(), x(17), f(f) { } |
| 1695 | /// }; |
| 1696 | /// @endcode |
| 1697 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1698 | /// [C++] ctor-initializer: |
| 1699 | /// ':' mem-initializer-list |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1700 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1701 | /// [C++] mem-initializer-list: |
| 1702 | /// mem-initializer |
| 1703 | /// mem-initializer , mem-initializer-list |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1704 | void Parser::ParseConstructorInitializer(DeclPtrTy ConstructorDecl) { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1705 | assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); |
| 1706 | |
| 1707 | SourceLocation ColonLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1709 | llvm::SmallVector<MemInitTy*, 4> MemInitializers; |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 1710 | bool AnyErrors = false; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1711 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1712 | do { |
| 1713 | MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1714 | if (!MemInit.isInvalid()) |
| 1715 | MemInitializers.push_back(MemInit.get()); |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 1716 | else |
| 1717 | AnyErrors = true; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1718 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1719 | if (Tok.is(tok::comma)) |
| 1720 | ConsumeToken(); |
| 1721 | else if (Tok.is(tok::l_brace)) |
| 1722 | break; |
| 1723 | else { |
| 1724 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 1725 | Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1726 | SkipUntil(tok::l_brace, true, true); |
| 1727 | break; |
| 1728 | } |
| 1729 | } while (true); |
| 1730 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, |
Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 1732 | MemInitializers.data(), MemInitializers.size(), |
| 1733 | AnyErrors); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | /// ParseMemInitializer - Parse a C++ member initializer, which is |
| 1737 | /// part of a constructor initializer that explicitly initializes one |
| 1738 | /// member or base class (C++ [class.base.init]). See |
| 1739 | /// ParseConstructorInitializer for an example. |
| 1740 | /// |
| 1741 | /// [C++] mem-initializer: |
| 1742 | /// mem-initializer-id '(' expression-list[opt] ')' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | /// |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1744 | /// [C++] mem-initializer-id: |
| 1745 | /// '::'[opt] nested-name-specifier[opt] class-name |
| 1746 | /// identifier |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1747 | Parser::MemInitResult Parser::ParseMemInitializer(DeclPtrTy ConstructorDecl) { |
Fariborz Jahanian | bcfad54 | 2009-06-30 23:26:25 +0000 | [diff] [blame] | 1748 | // parse '::'[opt] nested-name-specifier[opt] |
| 1749 | CXXScopeSpec SS; |
Douglas Gregor | 2dd078a | 2009-09-02 22:59:36 +0000 | [diff] [blame] | 1750 | ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, false); |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1751 | TypeTy *TemplateTypeTy = 0; |
| 1752 | if (Tok.is(tok::annot_template_id)) { |
| 1753 | TemplateIdAnnotation *TemplateId |
| 1754 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
Douglas Gregor | d9b600c | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 1755 | if (TemplateId->Kind == TNK_Type_template || |
| 1756 | TemplateId->Kind == TNK_Dependent_template_name) { |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1757 | AnnotateTemplateIdTokenAsType(&SS); |
| 1758 | assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); |
| 1759 | TemplateTypeTy = Tok.getAnnotationValue(); |
| 1760 | } |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1761 | } |
| 1762 | if (!TemplateTypeTy && Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1763 | Diag(Tok, diag::err_expected_member_or_base_name); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1764 | return true; |
| 1765 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1767 | // Get the identifier. This may be a member name or a class name, |
| 1768 | // but we'll let the semantic analysis determine which it is. |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1769 | IdentifierInfo *II = Tok.is(tok::identifier) ? Tok.getIdentifierInfo() : 0; |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1770 | SourceLocation IdLoc = ConsumeToken(); |
| 1771 | |
| 1772 | // Parse the '('. |
| 1773 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1774 | Diag(Tok, diag::err_expected_lparen); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1775 | return true; |
| 1776 | } |
| 1777 | SourceLocation LParenLoc = ConsumeParen(); |
| 1778 | |
| 1779 | // Parse the optional expression-list. |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1780 | ExprVector ArgExprs(Actions); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1781 | CommaLocsTy CommaLocs; |
| 1782 | if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { |
| 1783 | SkipUntil(tok::r_paren); |
| 1784 | return true; |
| 1785 | } |
| 1786 | |
| 1787 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 1788 | |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1789 | return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, |
Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 1790 | TemplateTypeTy, IdLoc, |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1791 | LParenLoc, ArgExprs.take(), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1792 | ArgExprs.size(), CommaLocs.data(), |
| 1793 | RParenLoc); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1794 | } |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1795 | |
| 1796 | /// ParseExceptionSpecification - Parse a C++ exception-specification |
| 1797 | /// (C++ [except.spec]). |
| 1798 | /// |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1799 | /// exception-specification: |
| 1800 | /// 'throw' '(' type-id-list [opt] ')' |
| 1801 | /// [MS] 'throw' '(' '...' ')' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1802 | /// |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1803 | /// type-id-list: |
| 1804 | /// type-id |
| 1805 | /// type-id-list ',' type-id |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1806 | /// |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1807 | bool Parser::ParseExceptionSpecification(SourceLocation &EndLoc, |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1808 | llvm::SmallVector<TypeTy*, 2> |
| 1809 | &Exceptions, |
| 1810 | llvm::SmallVector<SourceRange, 2> |
| 1811 | &Ranges, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1812 | bool &hasAnyExceptionSpec) { |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1813 | assert(Tok.is(tok::kw_throw) && "expected throw"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1814 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1815 | SourceLocation ThrowLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1816 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1817 | if (!Tok.is(tok::l_paren)) { |
| 1818 | return Diag(Tok, diag::err_expected_lparen_after) << "throw"; |
| 1819 | } |
| 1820 | SourceLocation LParenLoc = ConsumeParen(); |
| 1821 | |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1822 | // Parse throw(...), a Microsoft extension that means "this function |
| 1823 | // can throw anything". |
| 1824 | if (Tok.is(tok::ellipsis)) { |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1825 | hasAnyExceptionSpec = true; |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1826 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 1827 | if (!getLang().Microsoft) |
| 1828 | Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1829 | EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 1830 | return false; |
| 1831 | } |
| 1832 | |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1833 | // Parse the sequence of type-ids. |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1834 | SourceRange Range; |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1835 | while (Tok.isNot(tok::r_paren)) { |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1836 | TypeResult Res(ParseTypeName(&Range)); |
| 1837 | if (!Res.isInvalid()) { |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1838 | Exceptions.push_back(Res.get()); |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 1839 | Ranges.push_back(Range); |
| 1840 | } |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1841 | if (Tok.is(tok::comma)) |
| 1842 | ConsumeToken(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 1843 | else |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1844 | break; |
| 1845 | } |
| 1846 | |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 1847 | EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 1848 | return false; |
| 1849 | } |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1850 | |
| 1851 | /// \brief We have just started parsing the definition of a new class, |
| 1852 | /// so push that class onto our stack of classes that is currently |
| 1853 | /// being parsed. |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1854 | void Parser::PushParsingClass(DeclPtrTy ClassDecl, bool NonNestedClass) { |
| 1855 | assert((NonNestedClass || !ClassStack.empty()) && |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1856 | "Nested class without outer class"); |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 1857 | ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass)); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | /// \brief Deallocate the given parsed class and all of its nested |
| 1861 | /// classes. |
| 1862 | void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { |
| 1863 | for (unsigned I = 0, N = Class->NestedClasses.size(); I != N; ++I) |
| 1864 | DeallocateParsedClasses(Class->NestedClasses[I]); |
| 1865 | delete Class; |
| 1866 | } |
| 1867 | |
| 1868 | /// \brief Pop the top class of the stack of classes that are |
| 1869 | /// currently being parsed. |
| 1870 | /// |
| 1871 | /// This routine should be called when we have finished parsing the |
| 1872 | /// definition of a class, but have not yet popped the Scope |
| 1873 | /// associated with the class's definition. |
| 1874 | /// |
| 1875 | /// \returns true if the class we've popped is a top-level class, |
| 1876 | /// false otherwise. |
| 1877 | void Parser::PopParsingClass() { |
| 1878 | assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1880 | ParsingClass *Victim = ClassStack.top(); |
| 1881 | ClassStack.pop(); |
| 1882 | if (Victim->TopLevelClass) { |
| 1883 | // Deallocate all of the nested classes of this class, |
| 1884 | // recursively: we don't need to keep any of this information. |
| 1885 | DeallocateParsedClasses(Victim); |
| 1886 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1887 | } |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1888 | assert(!ClassStack.empty() && "Missing top-level class?"); |
| 1889 | |
| 1890 | if (Victim->MethodDecls.empty() && Victim->MethodDefs.empty() && |
| 1891 | Victim->NestedClasses.empty()) { |
| 1892 | // The victim is a nested class, but we will not need to perform |
| 1893 | // any processing after the definition of this class since it has |
| 1894 | // no members whose handling was delayed. Therefore, we can just |
| 1895 | // remove this nested class. |
| 1896 | delete Victim; |
| 1897 | return; |
| 1898 | } |
| 1899 | |
| 1900 | // This nested class has some members that will need to be processed |
| 1901 | // after the top-level class is completely defined. Therefore, add |
| 1902 | // it to the list of nested classes within its parent. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1903 | assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1904 | ClassStack.top()->NestedClasses.push_back(Victim); |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1905 | Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 1906 | } |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1907 | |
| 1908 | /// ParseCXX0XAttributes - Parse a C++0x attribute-specifier. Currently only |
| 1909 | /// parses standard attributes. |
| 1910 | /// |
| 1911 | /// [C++0x] attribute-specifier: |
| 1912 | /// '[' '[' attribute-list ']' ']' |
| 1913 | /// |
| 1914 | /// [C++0x] attribute-list: |
| 1915 | /// attribute[opt] |
| 1916 | /// attribute-list ',' attribute[opt] |
| 1917 | /// |
| 1918 | /// [C++0x] attribute: |
| 1919 | /// attribute-token attribute-argument-clause[opt] |
| 1920 | /// |
| 1921 | /// [C++0x] attribute-token: |
| 1922 | /// identifier |
| 1923 | /// attribute-scoped-token |
| 1924 | /// |
| 1925 | /// [C++0x] attribute-scoped-token: |
| 1926 | /// attribute-namespace '::' identifier |
| 1927 | /// |
| 1928 | /// [C++0x] attribute-namespace: |
| 1929 | /// identifier |
| 1930 | /// |
| 1931 | /// [C++0x] attribute-argument-clause: |
| 1932 | /// '(' balanced-token-seq ')' |
| 1933 | /// |
| 1934 | /// [C++0x] balanced-token-seq: |
| 1935 | /// balanced-token |
| 1936 | /// balanced-token-seq balanced-token |
| 1937 | /// |
| 1938 | /// [C++0x] balanced-token: |
| 1939 | /// '(' balanced-token-seq ')' |
| 1940 | /// '[' balanced-token-seq ']' |
| 1941 | /// '{' balanced-token-seq '}' |
| 1942 | /// any token but '(', ')', '[', ']', '{', or '}' |
| 1943 | CXX0XAttributeList Parser::ParseCXX0XAttributes(SourceLocation *EndLoc) { |
| 1944 | assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) |
| 1945 | && "Not a C++0x attribute list"); |
| 1946 | |
| 1947 | SourceLocation StartLoc = Tok.getLocation(), Loc; |
| 1948 | AttributeList *CurrAttr = 0; |
| 1949 | |
| 1950 | ConsumeBracket(); |
| 1951 | ConsumeBracket(); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1952 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1953 | if (Tok.is(tok::comma)) { |
| 1954 | Diag(Tok.getLocation(), diag::err_expected_ident); |
| 1955 | ConsumeToken(); |
| 1956 | } |
| 1957 | |
| 1958 | while (Tok.is(tok::identifier) || Tok.is(tok::comma)) { |
| 1959 | // attribute not present |
| 1960 | if (Tok.is(tok::comma)) { |
| 1961 | ConsumeToken(); |
| 1962 | continue; |
| 1963 | } |
| 1964 | |
| 1965 | IdentifierInfo *ScopeName = 0, *AttrName = Tok.getIdentifierInfo(); |
| 1966 | SourceLocation ScopeLoc, AttrLoc = ConsumeToken(); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1967 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1968 | // scoped attribute |
| 1969 | if (Tok.is(tok::coloncolon)) { |
| 1970 | ConsumeToken(); |
| 1971 | |
| 1972 | if (!Tok.is(tok::identifier)) { |
| 1973 | Diag(Tok.getLocation(), diag::err_expected_ident); |
| 1974 | SkipUntil(tok::r_square, tok::comma, true, true); |
| 1975 | continue; |
| 1976 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1977 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1978 | ScopeName = AttrName; |
| 1979 | ScopeLoc = AttrLoc; |
| 1980 | |
| 1981 | AttrName = Tok.getIdentifierInfo(); |
| 1982 | AttrLoc = ConsumeToken(); |
| 1983 | } |
| 1984 | |
| 1985 | bool AttrParsed = false; |
| 1986 | // No scoped names are supported; ideally we could put all non-standard |
| 1987 | // attributes into namespaces. |
| 1988 | if (!ScopeName) { |
| 1989 | switch(AttributeList::getKind(AttrName)) |
| 1990 | { |
| 1991 | // No arguments |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1992 | case AttributeList::AT_base_check: |
| 1993 | case AttributeList::AT_carries_dependency: |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1994 | case AttributeList::AT_final: |
Sean Hunt | 7725e67 | 2009-11-25 04:20:27 +0000 | [diff] [blame] | 1995 | case AttributeList::AT_hiding: |
| 1996 | case AttributeList::AT_noreturn: |
| 1997 | case AttributeList::AT_override: { |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1998 | if (Tok.is(tok::l_paren)) { |
| 1999 | Diag(Tok.getLocation(), diag::err_cxx0x_attribute_forbids_arguments) |
| 2000 | << AttrName->getName(); |
| 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | CurrAttr = new AttributeList(AttrName, AttrLoc, 0, AttrLoc, 0, |
| 2005 | SourceLocation(), 0, 0, CurrAttr, false, |
| 2006 | true); |
| 2007 | AttrParsed = true; |
| 2008 | break; |
| 2009 | } |
| 2010 | |
| 2011 | // One argument; must be a type-id or assignment-expression |
| 2012 | case AttributeList::AT_aligned: { |
| 2013 | if (Tok.isNot(tok::l_paren)) { |
| 2014 | Diag(Tok.getLocation(), diag::err_cxx0x_attribute_requires_arguments) |
| 2015 | << AttrName->getName(); |
| 2016 | break; |
| 2017 | } |
| 2018 | SourceLocation ParamLoc = ConsumeParen(); |
| 2019 | |
| 2020 | OwningExprResult ArgExpr = ParseCXX0XAlignArgument(ParamLoc); |
| 2021 | |
| 2022 | MatchRHSPunctuation(tok::r_paren, ParamLoc); |
| 2023 | |
| 2024 | ExprVector ArgExprs(Actions); |
| 2025 | ArgExprs.push_back(ArgExpr.release()); |
| 2026 | CurrAttr = new AttributeList(AttrName, AttrLoc, 0, AttrLoc, |
| 2027 | 0, ParamLoc, ArgExprs.take(), 1, CurrAttr, |
| 2028 | false, true); |
| 2029 | |
| 2030 | AttrParsed = true; |
| 2031 | break; |
| 2032 | } |
| 2033 | |
| 2034 | // Silence warnings |
| 2035 | default: break; |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | // Skip the entire parameter clause, if any |
| 2040 | if (!AttrParsed && Tok.is(tok::l_paren)) { |
| 2041 | ConsumeParen(); |
| 2042 | // SkipUntil maintains the balancedness of tokens. |
| 2043 | SkipUntil(tok::r_paren, false); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) |
| 2048 | SkipUntil(tok::r_square, false); |
| 2049 | Loc = Tok.getLocation(); |
| 2050 | if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) |
| 2051 | SkipUntil(tok::r_square, false); |
| 2052 | |
| 2053 | CXX0XAttributeList Attr (CurrAttr, SourceRange(StartLoc, Loc), true); |
| 2054 | return Attr; |
| 2055 | } |
| 2056 | |
| 2057 | /// ParseCXX0XAlignArgument - Parse the argument to C++0x's [[align]] |
| 2058 | /// attribute. |
| 2059 | /// |
| 2060 | /// FIXME: Simply returns an alignof() expression if the argument is a |
| 2061 | /// type. Ideally, the type should be propagated directly into Sema. |
| 2062 | /// |
| 2063 | /// [C++0x] 'align' '(' type-id ')' |
| 2064 | /// [C++0x] 'align' '(' assignment-expression ')' |
| 2065 | Parser::OwningExprResult Parser::ParseCXX0XAlignArgument(SourceLocation Start) { |
| 2066 | if (isTypeIdInParens()) { |
| 2067 | EnterExpressionEvaluationContext Unevaluated(Actions, |
| 2068 | Action::Unevaluated); |
| 2069 | SourceLocation TypeLoc = Tok.getLocation(); |
| 2070 | TypeTy *Ty = ParseTypeName().get(); |
| 2071 | SourceRange TypeRange(Start, Tok.getLocation()); |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 2072 | return Actions.ActOnSizeOfAlignOfExpr(TypeLoc, false, true, Ty, TypeRange); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2073 | } else |
| 2074 | return ParseConstantExpression(); |
| 2075 | } |