| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 1 | //===--- ParseDeclCXX.cpp - C++ Declaration Parsing -----------------------===// | 
 | 2 | // | 
 | 3 | //                     The LLVM Compiler Infrastructure | 
 | 4 | // | 
| Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source | 
 | 6 | // License. See LICENSE.TXT for details. | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 7 | // | 
 | 8 | //===----------------------------------------------------------------------===// | 
 | 9 | // | 
 | 10 | //  This file implements the C++ Declaration portions of the Parser interfaces. | 
 | 11 | // | 
 | 12 | //===----------------------------------------------------------------------===// | 
 | 13 |  | 
| Douglas Gregor | 1b7f898 | 2008-04-14 00:13:42 +0000 | [diff] [blame] | 14 | #include "clang/Parse/Parser.h" | 
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "RAIIObjectsForParser.h" | 
| Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 16 | #include "clang/Basic/CharInfo.h" | 
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "clang/Basic/OperatorKinds.h" | 
| Larisse Voufo | ef4579c | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" | 
| Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 19 | #include "clang/Parse/ParseDiagnostic.h" | 
| John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 20 | #include "clang/Sema/DeclSpec.h" | 
| John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 21 | #include "clang/Sema/ParsedTemplate.h" | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 22 | #include "clang/Sema/PrettyDeclStackTrace.h" | 
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 23 | #include "clang/Sema/Scope.h" | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 24 | #include "clang/Sema/SemaDiagnostic.h" | 
| Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 26 | using namespace clang; | 
 | 27 |  | 
 | 28 | /// ParseNamespace - We know that the current token is a namespace keyword. This | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 29 | /// may either be a top level namespace or a block-level namespace alias. If | 
 | 30 | /// there was an inline keyword, it has already been parsed. | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 31 | /// | 
 | 32 | ///       namespace-definition: [C++ 7.3: basic.namespace] | 
 | 33 | ///         named-namespace-definition | 
 | 34 | ///         unnamed-namespace-definition | 
 | 35 | /// | 
 | 36 | ///       unnamed-namespace-definition: | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 37 | ///         'inline'[opt] 'namespace' attributes[opt] '{' namespace-body '}' | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 38 | /// | 
 | 39 | ///       named-namespace-definition: | 
 | 40 | ///         original-namespace-definition | 
 | 41 | ///         extension-namespace-definition | 
 | 42 | /// | 
 | 43 | ///       original-namespace-definition: | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 44 | ///         'inline'[opt] 'namespace' identifier attributes[opt] | 
 | 45 | ///             '{' namespace-body '}' | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 46 | /// | 
 | 47 | ///       extension-namespace-definition: | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 48 | ///         'inline'[opt] 'namespace' original-namespace-name | 
 | 49 | ///             '{' namespace-body '}' | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 50 | /// | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 51 | ///       namespace-alias-definition:  [C++ 7.3.2: namespace.alias] | 
 | 52 | ///         'namespace' identifier '=' qualified-namespace-specifier ';' | 
 | 53 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 54 | Decl *Parser::ParseNamespace(unsigned Context, | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 55 |                              SourceLocation &DeclEnd, | 
 | 56 |                              SourceLocation InlineLoc) { | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 57 |   assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 58 |   SourceLocation NamespaceLoc = ConsumeToken();  // eat the 'namespace'. | 
| Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 59 |   ObjCDeclContextSwitch ObjCDC(*this); | 
| Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 60 |      | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 61 |   if (Tok.is(tok::code_completion)) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 62 |     Actions.CodeCompleteNamespaceDecl(getCurScope()); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 63 |     cutOffParsing(); | 
 | 64 |     return 0; | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 65 |   } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 66 |  | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 67 |   SourceLocation IdentLoc; | 
 | 68 |   IdentifierInfo *Ident = 0; | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 69 |   std::vector<SourceLocation> ExtraIdentLoc; | 
 | 70 |   std::vector<IdentifierInfo*> ExtraIdent; | 
 | 71 |   std::vector<SourceLocation> ExtraNamespaceLoc; | 
| Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 72 |  | 
 | 73 |   Token attrTok; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 74 |  | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 75 |   if (Tok.is(tok::identifier)) { | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 76 |     Ident = Tok.getIdentifierInfo(); | 
 | 77 |     IdentLoc = ConsumeToken();  // eat the identifier. | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 78 |     while (Tok.is(tok::coloncolon) && NextToken().is(tok::identifier)) { | 
 | 79 |       ExtraNamespaceLoc.push_back(ConsumeToken()); | 
 | 80 |       ExtraIdent.push_back(Tok.getIdentifierInfo()); | 
 | 81 |       ExtraIdentLoc.push_back(ConsumeToken()); | 
 | 82 |     } | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 83 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 |  | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 85 |   // Read label attributes, if present. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 86 |   ParsedAttributes attrs(AttrFactory); | 
| Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 87 |   if (Tok.is(tok::kw___attribute)) { | 
 | 88 |     attrTok = Tok; | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 89 |     ParseGNUAttributes(attrs); | 
| Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 90 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 91 |  | 
| Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 92 |   if (Tok.is(tok::equal)) { | 
| Nico Weber | e1bb329 | 2012-10-27 23:44:27 +0000 | [diff] [blame] | 93 |     if (Ident == 0) { | 
 | 94 |       Diag(Tok, diag::err_expected_ident); | 
 | 95 |       // Skip to end of the definition and eat the ';'. | 
 | 96 |       SkipUntil(tok::semi); | 
 | 97 |       return 0; | 
 | 98 |     } | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 99 |     if (!attrs.empty()) | 
| Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 100 |       Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 101 |     if (InlineLoc.isValid()) | 
 | 102 |       Diag(InlineLoc, diag::err_inline_namespace_alias) | 
 | 103 |           << FixItHint::CreateRemoval(InlineLoc); | 
| Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 104 |     return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); | 
| Douglas Gregor | 6a588dd | 2009-06-17 19:49:00 +0000 | [diff] [blame] | 105 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 |  | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 107 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 108 |   BalancedDelimiterTracker T(*this, tok::l_brace); | 
 | 109 |   if (T.consumeOpen()) { | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 110 |     if (!ExtraIdent.empty()) { | 
 | 111 |       Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) | 
 | 112 |           << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); | 
 | 113 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 |     Diag(Tok, Ident ? diag::err_expected_lbrace : | 
| Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 115 |          diag::err_expected_ident_lbrace); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 116 |     return 0; | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 117 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 119 |   if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() ||  | 
 | 120 |       getCurScope()->isInObjcMethodScope() || getCurScope()->getBlockParent() ||  | 
 | 121 |       getCurScope()->getFnParent()) { | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 122 |     if (!ExtraIdent.empty()) { | 
 | 123 |       Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) | 
 | 124 |           << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); | 
 | 125 |     } | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 126 |     Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope); | 
| Douglas Gregor | 95f1b15 | 2010-05-14 05:08:22 +0000 | [diff] [blame] | 127 |     SkipUntil(tok::r_brace, false); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 128 |     return 0; | 
| Douglas Gregor | 95f1b15 | 2010-05-14 05:08:22 +0000 | [diff] [blame] | 129 |   } | 
 | 130 |  | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 131 |   if (!ExtraIdent.empty()) { | 
 | 132 |     TentativeParsingAction TPA(*this); | 
 | 133 |     SkipUntil(tok::r_brace, /*StopAtSemi*/false, /*DontConsume*/true); | 
 | 134 |     Token rBraceToken = Tok; | 
 | 135 |     TPA.Revert(); | 
 | 136 |  | 
 | 137 |     if (!rBraceToken.is(tok::r_brace)) { | 
 | 138 |       Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) | 
 | 139 |           << SourceRange(ExtraNamespaceLoc.front(), ExtraIdentLoc.back()); | 
 | 140 |     } else { | 
| Benjamin Kramer | 9910df0 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 141 |       std::string NamespaceFix; | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 142 |       for (std::vector<IdentifierInfo*>::iterator I = ExtraIdent.begin(), | 
 | 143 |            E = ExtraIdent.end(); I != E; ++I) { | 
 | 144 |         NamespaceFix += " { namespace "; | 
 | 145 |         NamespaceFix += (*I)->getName(); | 
 | 146 |       } | 
| Benjamin Kramer | 9910df0 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 147 |  | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 148 |       std::string RBraces; | 
| Benjamin Kramer | 9910df0 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 149 |       for (unsigned i = 0, e = ExtraIdent.size(); i != e; ++i) | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 150 |         RBraces +=  "} "; | 
| Benjamin Kramer | 9910df0 | 2011-05-26 21:32:30 +0000 | [diff] [blame] | 151 |  | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 152 |       Diag(ExtraNamespaceLoc[0], diag::err_nested_namespaces_with_double_colon) | 
 | 153 |           << FixItHint::CreateReplacement(SourceRange(ExtraNamespaceLoc.front(), | 
 | 154 |                                                       ExtraIdentLoc.back()), | 
 | 155 |                                           NamespaceFix) | 
 | 156 |           << FixItHint::CreateInsertion(rBraceToken.getLocation(), RBraces); | 
 | 157 |     } | 
 | 158 |   } | 
 | 159 |  | 
| Sebastian Redl | 88e64ca | 2010-08-31 00:36:45 +0000 | [diff] [blame] | 160 |   // If we're still good, complain about inline namespaces in non-C++0x now. | 
| Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 161 |   if (InlineLoc.isValid()) | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 162 |     Diag(InlineLoc, getLangOpts().CPlusPlus11 ? | 
| Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 163 |          diag::warn_cxx98_compat_inline_namespace : diag::ext_inline_namespace); | 
| Sebastian Redl | 88e64ca | 2010-08-31 00:36:45 +0000 | [diff] [blame] | 164 |  | 
| Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 165 |   // Enter a scope for the namespace. | 
 | 166 |   ParseScope NamespaceScope(this, Scope::DeclScope); | 
 | 167 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 168 |   Decl *NamespcDecl = | 
| Abramo Bagnara | acba90f | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 169 |     Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 170 |                                    IdentLoc, Ident, T.getOpenLocation(),  | 
 | 171 |                                    attrs.getList()); | 
| Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 172 |  | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 173 |   PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc, | 
 | 174 |                                       "parsing namespace"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 |  | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 176 |   // Parse the contents of the namespace.  This includes parsing recovery on  | 
 | 177 |   // any improperly nested namespaces. | 
 | 178 |   ParseInnerNamespace(ExtraIdentLoc, ExtraIdent, ExtraNamespaceLoc, 0, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 179 |                       InlineLoc, attrs, T); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 |  | 
| Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 181 |   // Leave the namespace scope. | 
 | 182 |   NamespaceScope.Exit(); | 
 | 183 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 184 |   DeclEnd = T.getCloseLocation(); | 
 | 185 |   Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd); | 
| Chris Lattner | 5144832 | 2009-03-29 14:02:43 +0000 | [diff] [blame] | 186 |  | 
 | 187 |   return NamespcDecl; | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 188 | } | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 189 |  | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 190 | /// ParseInnerNamespace - Parse the contents of a namespace. | 
 | 191 | void Parser::ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc, | 
 | 192 |                                  std::vector<IdentifierInfo*>& Ident, | 
 | 193 |                                  std::vector<SourceLocation>& NamespaceLoc, | 
 | 194 |                                  unsigned int index, SourceLocation& InlineLoc, | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 195 |                                  ParsedAttributes& attrs, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 196 |                                  BalancedDelimiterTracker &Tracker) { | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 197 |   if (index == Ident.size()) { | 
 | 198 |     while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { | 
 | 199 |       ParsedAttributesWithRange attrs(AttrFactory); | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 200 |       MaybeParseCXX11Attributes(attrs); | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 201 |       MaybeParseMicrosoftAttributes(attrs); | 
 | 202 |       ParseExternalDeclaration(attrs); | 
 | 203 |     } | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 204 |  | 
 | 205 |     // The caller is what called check -- we are simply calling | 
 | 206 |     // the close for it. | 
 | 207 |     Tracker.consumeClose(); | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 208 |  | 
 | 209 |     return; | 
 | 210 |   } | 
 | 211 |  | 
 | 212 |   // Parse improperly nested namespaces. | 
 | 213 |   ParseScope NamespaceScope(this, Scope::DeclScope); | 
 | 214 |   Decl *NamespcDecl = | 
 | 215 |     Actions.ActOnStartNamespaceDef(getCurScope(), SourceLocation(), | 
 | 216 |                                    NamespaceLoc[index], IdentLoc[index], | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 217 |                                    Ident[index], Tracker.getOpenLocation(),  | 
 | 218 |                                    attrs.getList()); | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 219 |  | 
 | 220 |   ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 221 |                       attrs, Tracker); | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 222 |  | 
 | 223 |   NamespaceScope.Exit(); | 
 | 224 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 225 |   Actions.ActOnFinishNamespaceDef(NamespcDecl, Tracker.getCloseLocation()); | 
| Richard Trieu | f858bd8 | 2011-05-26 20:11:09 +0000 | [diff] [blame] | 226 | } | 
 | 227 |  | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 228 | /// ParseNamespaceAlias - Parse the part after the '=' in a namespace | 
 | 229 | /// alias definition. | 
 | 230 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 231 | Decl *Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc, | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 232 |                                   SourceLocation AliasLoc, | 
 | 233 |                                   IdentifierInfo *Alias, | 
 | 234 |                                   SourceLocation &DeclEnd) { | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 235 |   assert(Tok.is(tok::equal) && "Not equal token"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 236 |  | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 237 |   ConsumeToken(); // eat the '='. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 238 |  | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 239 |   if (Tok.is(tok::code_completion)) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 240 |     Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 241 |     cutOffParsing(); | 
 | 242 |     return 0; | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 243 |   } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 244 |  | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 245 |   CXXScopeSpec SS; | 
 | 246 |   // Parse (optional) nested-name-specifier. | 
| Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 247 |   ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 248 |  | 
 | 249 |   if (SS.isInvalid() || Tok.isNot(tok::identifier)) { | 
 | 250 |     Diag(Tok, diag::err_expected_namespace_name); | 
 | 251 |     // Skip to end of the definition and eat the ';'. | 
 | 252 |     SkipUntil(tok::semi); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 253 |     return 0; | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 254 |   } | 
 | 255 |  | 
 | 256 |   // Parse identifier. | 
| Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 257 |   IdentifierInfo *Ident = Tok.getIdentifierInfo(); | 
 | 258 |   SourceLocation IdentLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 259 |  | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 260 |   // Eat the ';'. | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 261 |   DeclEnd = Tok.getLocation(); | 
| Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 262 |   ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name, | 
 | 263 |                    "", tok::semi); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 265 |   return Actions.ActOnNamespaceAliasDef(getCurScope(), NamespaceLoc, AliasLoc, Alias, | 
| Anders Carlsson | 03bd5a1 | 2009-03-28 22:53:22 +0000 | [diff] [blame] | 266 |                                         SS, IdentLoc, Ident); | 
| Anders Carlsson | f67606a | 2009-03-28 04:07:16 +0000 | [diff] [blame] | 267 | } | 
 | 268 |  | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 269 | /// ParseLinkage - We know that the current token is a string_literal | 
 | 270 | /// and just before that, that extern was seen. | 
 | 271 | /// | 
 | 272 | ///       linkage-specification: [C++ 7.5p2: dcl.link] | 
 | 273 | ///         'extern' string-literal '{' declaration-seq[opt] '}' | 
 | 274 | ///         'extern' string-literal declaration | 
 | 275 | /// | 
| Chris Lattner | 7d64271 | 2010-11-09 20:15:55 +0000 | [diff] [blame] | 276 | Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, unsigned Context) { | 
| Douglas Gregor | c19923d | 2008-11-21 16:10:08 +0000 | [diff] [blame] | 277 |   assert(Tok.is(tok::string_literal) && "Not a string literal!"); | 
| Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 278 |   SmallString<8> LangBuffer; | 
| Douglas Gregor | 453091c | 2010-03-16 22:30:13 +0000 | [diff] [blame] | 279 |   bool Invalid = false; | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 280 |   StringRef Lang = PP.getSpelling(Tok, LangBuffer, &Invalid); | 
| Douglas Gregor | 453091c | 2010-03-16 22:30:13 +0000 | [diff] [blame] | 281 |   if (Invalid) | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 282 |     return 0; | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 283 |  | 
| Richard Smith | 99831e4 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 284 |   // FIXME: This is incorrect: linkage-specifiers are parsed in translation | 
 | 285 |   // phase 7, so string-literal concatenation is supposed to occur. | 
 | 286 |   //   extern "" "C" "" "+" "+" { } is legal. | 
 | 287 |   if (Tok.hasUDSuffix()) | 
 | 288 |     Diag(Tok, diag::err_invalid_string_udl); | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 289 |   SourceLocation Loc = ConsumeStringToken(); | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 290 |  | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 291 |   ParseScope LinkageScope(this, Scope::DeclScope); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 292 |   Decl *LinkageSpec | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 293 |     = Actions.ActOnStartLinkageSpecification(getCurScope(), | 
| Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 294 |                                              DS.getSourceRange().getBegin(), | 
| Benjamin Kramer | d566381 | 2010-05-03 13:08:54 +0000 | [diff] [blame] | 295 |                                              Loc, Lang, | 
| Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 296 |                                       Tok.is(tok::l_brace) ? Tok.getLocation() | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 297 |                                                            : SourceLocation()); | 
 | 298 |  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 299 |   ParsedAttributesWithRange attrs(AttrFactory); | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 300 |   MaybeParseCXX11Attributes(attrs); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 301 |   MaybeParseMicrosoftAttributes(attrs); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 302 |  | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 303 |   if (Tok.isNot(tok::l_brace)) { | 
| Abramo Bagnara | f41e33c | 2011-05-01 16:25:54 +0000 | [diff] [blame] | 304 |     // Reset the source range in DS, as the leading "extern" | 
 | 305 |     // does not really belong to the inner declaration ... | 
 | 306 |     DS.SetRangeStart(SourceLocation()); | 
 | 307 |     DS.SetRangeEnd(SourceLocation()); | 
 | 308 |     // ... but anyway remember that such an "extern" was seen. | 
| Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 309 |     DS.setExternInLinkageSpec(true); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 310 |     ParseExternalDeclaration(attrs, &DS); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 311 |     return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 312 |                                                    SourceLocation()); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 |   } | 
| Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 314 |  | 
| Douglas Gregor | 63a0113 | 2010-02-07 08:38:28 +0000 | [diff] [blame] | 315 |   DS.abort(); | 
 | 316 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 317 |   ProhibitAttributes(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 318 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 319 |   BalancedDelimiterTracker T(*this, tok::l_brace); | 
 | 320 |   T.consumeOpen(); | 
| Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 321 |   while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 322 |     ParsedAttributesWithRange attrs(AttrFactory); | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 323 |     MaybeParseCXX11Attributes(attrs); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 324 |     MaybeParseMicrosoftAttributes(attrs); | 
 | 325 |     ParseExternalDeclaration(attrs); | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 326 |   } | 
 | 327 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 328 |   T.consumeClose(); | 
| Chris Lattner | 7d64271 | 2010-11-09 20:15:55 +0000 | [diff] [blame] | 329 |   return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 330 |                                                  T.getCloseLocation()); | 
| Chris Lattner | c6fdc34 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 331 | } | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 332 |  | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 333 | /// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or | 
 | 334 | /// using-directive. Assumes that current token is 'using'. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 335 | Decl *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context, | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 336 |                                          const ParsedTemplateInfo &TemplateInfo, | 
 | 337 |                                                SourceLocation &DeclEnd, | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 338 |                                              ParsedAttributesWithRange &attrs, | 
 | 339 |                                                Decl **OwnedType) { | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 340 |   assert(Tok.is(tok::kw_using) && "Not using token"); | 
| Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 341 |   ObjCDeclContextSwitch ObjCDC(*this); | 
 | 342 |    | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 343 |   // Eat 'using'. | 
 | 344 |   SourceLocation UsingLoc = ConsumeToken(); | 
 | 345 |  | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 346 |   if (Tok.is(tok::code_completion)) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 347 |     Actions.CodeCompleteUsing(getCurScope()); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 348 |     cutOffParsing(); | 
 | 349 |     return 0; | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 350 |   } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 351 |  | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 352 |   // 'using namespace' means this is a using-directive. | 
 | 353 |   if (Tok.is(tok::kw_namespace)) { | 
 | 354 |     // Template parameters are always an error here. | 
 | 355 |     if (TemplateInfo.Kind) { | 
 | 356 |       SourceRange R = TemplateInfo.getSourceRange(); | 
 | 357 |       Diag(UsingLoc, diag::err_templated_using_directive) | 
 | 358 |         << R << FixItHint::CreateRemoval(R); | 
 | 359 |     } | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 360 |  | 
| Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 361 |     return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs); | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 362 |   } | 
 | 363 |  | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 364 |   // Otherwise, it must be a using-declaration or an alias-declaration. | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 365 |  | 
 | 366 |   // Using declarations can't have attributes. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 367 |   ProhibitAttributes(attrs); | 
| Chris Lattner | 2f27477 | 2009-01-06 06:55:51 +0000 | [diff] [blame] | 368 |  | 
| Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 369 |   return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd, | 
| Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 370 |                                     AS_none, OwnedType); | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 371 | } | 
 | 372 |  | 
 | 373 | /// ParseUsingDirective - Parse C++ using-directive, assumes | 
 | 374 | /// that current token is 'namespace' and 'using' was already parsed. | 
 | 375 | /// | 
 | 376 | ///       using-directive: [C++ 7.3.p4: namespace.udir] | 
 | 377 | ///        'using' 'namespace' ::[opt] nested-name-specifier[opt] | 
 | 378 | ///                 namespace-name ; | 
 | 379 | /// [GNU] using-directive: | 
 | 380 | ///        'using' 'namespace' ::[opt] nested-name-specifier[opt] | 
 | 381 | ///                 namespace-name attributes[opt] ; | 
 | 382 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 383 | Decl *Parser::ParseUsingDirective(unsigned Context, | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 384 |                                   SourceLocation UsingLoc, | 
 | 385 |                                   SourceLocation &DeclEnd, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 386 |                                   ParsedAttributes &attrs) { | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 387 |   assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token"); | 
 | 388 |  | 
 | 389 |   // Eat 'namespace'. | 
 | 390 |   SourceLocation NamespcLoc = ConsumeToken(); | 
 | 391 |  | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 392 |   if (Tok.is(tok::code_completion)) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 393 |     Actions.CodeCompleteUsingDirective(getCurScope()); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 394 |     cutOffParsing(); | 
 | 395 |     return 0; | 
| Douglas Gregor | 49f40bd | 2009-09-18 19:03:04 +0000 | [diff] [blame] | 396 |   } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 397 |  | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 398 |   CXXScopeSpec SS; | 
 | 399 |   // Parse (optional) nested-name-specifier. | 
| Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 400 |   ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 401 |  | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 402 |   IdentifierInfo *NamespcName = 0; | 
 | 403 |   SourceLocation IdentLoc = SourceLocation(); | 
 | 404 |  | 
 | 405 |   // Parse namespace-name. | 
| Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 406 |   if (SS.isInvalid() || Tok.isNot(tok::identifier)) { | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 407 |     Diag(Tok, diag::err_expected_namespace_name); | 
 | 408 |     // If there was invalid namespace name, skip to end of decl, and eat ';'. | 
 | 409 |     SkipUntil(tok::semi); | 
 | 410 |     // FIXME: Are there cases, when we would like to call ActOnUsingDirective? | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 411 |     return 0; | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 412 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 |  | 
| Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 414 |   // Parse identifier. | 
 | 415 |   NamespcName = Tok.getIdentifierInfo(); | 
 | 416 |   IdentLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 |  | 
| Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 418 |   // Parse (optional) attributes (most likely GNU strong-using extension). | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 419 |   bool GNUAttr = false; | 
 | 420 |   if (Tok.is(tok::kw___attribute)) { | 
 | 421 |     GNUAttr = true; | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 422 |     ParseGNUAttributes(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 423 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 424 |  | 
| Chris Lattner | 823c44e | 2009-01-06 07:27:21 +0000 | [diff] [blame] | 425 |   // Eat ';'. | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 426 |   DeclEnd = Tok.getLocation(); | 
| Chris Lattner | 6869d8e | 2009-06-14 00:07:48 +0000 | [diff] [blame] | 427 |   ExpectAndConsume(tok::semi, | 
| Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 428 |                    GNUAttr ? diag::err_expected_semi_after_attribute_list | 
 | 429 |                            : diag::err_expected_semi_after_namespace_name,  | 
 | 430 |                    "", tok::semi); | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 431 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 432 |   return Actions.ActOnUsingDirective(getCurScope(), UsingLoc, NamespcLoc, SS, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 433 |                                      IdentLoc, NamespcName, attrs.getList()); | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 434 | } | 
 | 435 |  | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 436 | /// ParseUsingDeclaration - Parse C++ using-declaration or alias-declaration. | 
 | 437 | /// Assumes that 'using' was already seen. | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 438 | /// | 
 | 439 | ///     using-declaration: [C++ 7.3.p3: namespace.udecl] | 
 | 440 | ///       'using' 'typename'[opt] ::[opt] nested-name-specifier | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 441 | ///               unqualified-id | 
 | 442 | ///       'using' :: unqualified-id | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 443 | /// | 
| Richard Smith | d03de6a | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 444 | ///     alias-declaration: C++11 [dcl.dcl]p1 | 
 | 445 | ///       'using' identifier attribute-specifier-seq[opt] = type-id ; | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 446 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 447 | Decl *Parser::ParseUsingDeclaration(unsigned Context, | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 448 |                                     const ParsedTemplateInfo &TemplateInfo, | 
 | 449 |                                     SourceLocation UsingLoc, | 
 | 450 |                                     SourceLocation &DeclEnd, | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 451 |                                     AccessSpecifier AS, | 
 | 452 |                                     Decl **OwnedType) { | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 453 |   CXXScopeSpec SS; | 
| John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 454 |   SourceLocation TypenameLoc; | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 455 |   bool HasTypenameKeyword = false; | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 456 |   ParsedAttributesWithRange Attrs(AttrFactory); | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 457 |  | 
 | 458 |   // FIXME: Simply skip the attributes and diagnose, don't bother parsing them. | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 459 |   MaybeParseCXX11Attributes(Attrs); | 
 | 460 |   ProhibitAttributes(Attrs); | 
 | 461 |   Attrs.clear(); | 
 | 462 |   Attrs.Range = SourceRange(); | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 463 |  | 
 | 464 |   // Ignore optional 'typename'. | 
| Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 465 |   // FIXME: This is wrong; we should parse this as a typename-specifier. | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 466 |   if (Tok.is(tok::kw_typename)) { | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 467 |     TypenameLoc = ConsumeToken(); | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 468 |     HasTypenameKeyword = true; | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 469 |   } | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 470 |  | 
 | 471 |   // Parse nested-name-specifier. | 
| Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 472 |   IdentifierInfo *LastII = 0; | 
 | 473 |   ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false, | 
 | 474 |                                  /*MayBePseudoDtor=*/0, /*IsTypename=*/false, | 
 | 475 |                                  /*LastII=*/&LastII); | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 476 |  | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 477 |   // Check nested-name specifier. | 
 | 478 |   if (SS.isInvalid()) { | 
 | 479 |     SkipUntil(tok::semi); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 480 |     return 0; | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 481 |   } | 
| Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 482 |  | 
| Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 483 |   SourceLocation TemplateKWLoc; | 
 | 484 |   UnqualifiedId Name; | 
 | 485 |  | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 486 |   // Parse the unqualified-id. We allow parsing of both constructor and | 
| Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 487 |   // destructor names and allow the action module to diagnose any semantic | 
 | 488 |   // errors. | 
| Richard Smith | 2db075b | 2013-03-26 01:15:19 +0000 | [diff] [blame] | 489 |   // | 
 | 490 |   // C++11 [class.qual]p2: | 
 | 491 |   //   [...] in a using-declaration that is a member-declaration, if the name | 
 | 492 |   //   specified after the nested-name-specifier is the same as the identifier | 
 | 493 |   //   or the simple-template-id's template-name in the last component of the | 
 | 494 |   //   nested-name-specifier, the name is [...] considered to name the | 
 | 495 |   //   constructor. | 
 | 496 |   if (getLangOpts().CPlusPlus11 && Context == Declarator::MemberContext && | 
 | 497 |       Tok.is(tok::identifier) && NextToken().is(tok::semi) && | 
 | 498 |       SS.isNotEmpty() && LastII == Tok.getIdentifierInfo() && | 
 | 499 |       !SS.getScopeRep()->getAsNamespace() && | 
 | 500 |       !SS.getScopeRep()->getAsNamespaceAlias()) { | 
 | 501 |     SourceLocation IdLoc = ConsumeToken(); | 
 | 502 |     ParsedType Type = Actions.getInheritingConstructorName(SS, IdLoc, *LastII); | 
 | 503 |     Name.setConstructorName(Type, IdLoc, IdLoc); | 
 | 504 |   } else if (ParseUnqualifiedId(SS, /*EnteringContext=*/ false, | 
 | 505 |                                 /*AllowDestructorName=*/ true, | 
 | 506 |                                 /*AllowConstructorName=*/ true, ParsedType(), | 
 | 507 |                                 TemplateKWLoc, Name)) { | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 508 |     SkipUntil(tok::semi); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 509 |     return 0; | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 510 |   } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 511 |  | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 512 |   MaybeParseCXX11Attributes(Attrs); | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 513 |  | 
 | 514 |   // Maybe this is an alias-declaration. | 
 | 515 |   bool IsAliasDecl = Tok.is(tok::equal); | 
 | 516 |   TypeResult TypeAlias; | 
 | 517 |   if (IsAliasDecl) { | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 518 |     // TODO: Can GNU attributes appear here? | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 519 |     ConsumeToken(); | 
 | 520 |  | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 521 |     Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 ? | 
| Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 522 |          diag::warn_cxx98_compat_alias_declaration : | 
 | 523 |          diag::ext_alias_declaration); | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 524 |  | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 525 |     // Type alias templates cannot be specialized. | 
 | 526 |     int SpecKind = -1; | 
| Richard Smith | 536e9c1 | 2011-05-05 22:36:10 +0000 | [diff] [blame] | 527 |     if (TemplateInfo.Kind == ParsedTemplateInfo::Template && | 
 | 528 |         Name.getKind() == UnqualifiedId::IK_TemplateId) | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 529 |       SpecKind = 0; | 
 | 530 |     if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization) | 
 | 531 |       SpecKind = 1; | 
 | 532 |     if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) | 
 | 533 |       SpecKind = 2; | 
 | 534 |     if (SpecKind != -1) { | 
 | 535 |       SourceRange Range; | 
 | 536 |       if (SpecKind == 0) | 
 | 537 |         Range = SourceRange(Name.TemplateId->LAngleLoc, | 
 | 538 |                             Name.TemplateId->RAngleLoc); | 
 | 539 |       else | 
 | 540 |         Range = TemplateInfo.getSourceRange(); | 
 | 541 |       Diag(Range.getBegin(), diag::err_alias_declaration_specialization) | 
 | 542 |         << SpecKind << Range; | 
 | 543 |       SkipUntil(tok::semi); | 
 | 544 |       return 0; | 
 | 545 |     } | 
 | 546 |  | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 547 |     // Name must be an identifier. | 
 | 548 |     if (Name.getKind() != UnqualifiedId::IK_Identifier) { | 
 | 549 |       Diag(Name.StartLocation, diag::err_alias_declaration_not_identifier); | 
 | 550 |       // No removal fixit: can't recover from this. | 
 | 551 |       SkipUntil(tok::semi); | 
 | 552 |       return 0; | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 553 |     } else if (HasTypenameKeyword) | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 554 |       Diag(TypenameLoc, diag::err_alias_declaration_not_identifier) | 
 | 555 |         << FixItHint::CreateRemoval(SourceRange(TypenameLoc, | 
 | 556 |                              SS.isNotEmpty() ? SS.getEndLoc() : TypenameLoc)); | 
 | 557 |     else if (SS.isNotEmpty()) | 
 | 558 |       Diag(SS.getBeginLoc(), diag::err_alias_declaration_not_identifier) | 
 | 559 |         << FixItHint::CreateRemoval(SS.getRange()); | 
 | 560 |  | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 561 |     TypeAlias = ParseTypeName(0, TemplateInfo.Kind ? | 
 | 562 |                               Declarator::AliasTemplateContext : | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 563 |                               Declarator::AliasDeclContext, AS, OwnedType, | 
 | 564 |                               &Attrs); | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 565 |   } else { | 
 | 566 |     // C++11 attributes are not allowed on a using-declaration, but GNU ones | 
 | 567 |     // are. | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 568 |     ProhibitAttributes(Attrs); | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 569 |  | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 570 |     // Parse (optional) attributes (most likely GNU strong-using extension). | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 571 |     MaybeParseGNUAttributes(Attrs); | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 572 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 |  | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 574 |   // Eat ';'. | 
 | 575 |   DeclEnd = Tok.getLocation(); | 
 | 576 |   ExpectAndConsume(tok::semi, diag::err_expected_semi_after, | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 577 |                    !Attrs.empty() ? "attributes list" : | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 578 |                    IsAliasDecl ? "alias declaration" : "using declaration", | 
| Douglas Gregor | 12c118a | 2009-11-04 16:30:06 +0000 | [diff] [blame] | 579 |                    tok::semi); | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 580 |  | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 581 |   // Diagnose an attempt to declare a templated using-declaration. | 
| Richard Smith | d03de6a | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 582 |   // In C++11, alias-declarations can be templates: | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 583 |   //   template <...> using id = type; | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 584 |   if (TemplateInfo.Kind && !IsAliasDecl) { | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 585 |     SourceRange R = TemplateInfo.getSourceRange(); | 
 | 586 |     Diag(UsingLoc, diag::err_templated_using_declaration) | 
 | 587 |       << R << FixItHint::CreateRemoval(R); | 
 | 588 |  | 
 | 589 |     // Unfortunately, we have to bail out instead of recovering by | 
 | 590 |     // ignoring the parameters, just in case the nested name specifier | 
 | 591 |     // depends on the parameters. | 
 | 592 |     return 0; | 
 | 593 |   } | 
 | 594 |  | 
| Douglas Gregor | 480b53c | 2011-09-26 14:30:28 +0000 | [diff] [blame] | 595 |   // "typename" keyword is allowed for identifiers only, | 
 | 596 |   // because it may be a type definition. | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 597 |   if (HasTypenameKeyword && Name.getKind() != UnqualifiedId::IK_Identifier) { | 
| Douglas Gregor | 480b53c | 2011-09-26 14:30:28 +0000 | [diff] [blame] | 598 |     Diag(Name.getSourceRange().getBegin(), diag::err_typename_identifiers_only) | 
 | 599 |       << FixItHint::CreateRemoval(SourceRange(TypenameLoc)); | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 600 |     // Proceed parsing, but reset the HasTypenameKeyword flag. | 
 | 601 |     HasTypenameKeyword = false; | 
| Douglas Gregor | 480b53c | 2011-09-26 14:30:28 +0000 | [diff] [blame] | 602 |   } | 
 | 603 |  | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 604 |   if (IsAliasDecl) { | 
 | 605 |     TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; | 
| Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 606 |     MultiTemplateParamsArg TemplateParamsArg( | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 607 |       TemplateParams ? TemplateParams->data() : 0, | 
 | 608 |       TemplateParams ? TemplateParams->size() : 0); | 
 | 609 |     return Actions.ActOnAliasDeclaration(getCurScope(), AS, TemplateParamsArg, | 
| Richard Smith | 6b3d3e5 | 2013-02-20 19:22:51 +0000 | [diff] [blame] | 610 |                                          UsingLoc, Name, Attrs.getList(), | 
 | 611 |                                          TypeAlias); | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 612 |   } | 
| Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 613 |  | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 614 |   return Actions.ActOnUsingDeclaration(getCurScope(), AS, | 
 | 615 |                                        /* HasUsingKeyword */ true, UsingLoc, | 
 | 616 |                                        SS, Name, Attrs.getList(), | 
 | 617 |                                        HasTypenameKeyword, TypenameLoc); | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 618 | } | 
 | 619 |  | 
| Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 620 | /// ParseStaticAssertDeclaration - Parse C++0x or C11 static_assert-declaration. | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 621 | /// | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 622 | /// [C++0x] static_assert-declaration: | 
 | 623 | ///           static_assert ( constant-expression  ,  string-literal  ) ; | 
 | 624 | /// | 
| Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 625 | /// [C11]   static_assert-declaration: | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 626 | ///           _Static_assert ( constant-expression  ,  string-literal  ) ; | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 627 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 628 | Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 629 |   assert((Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) && | 
 | 630 |          "Not a static_assert declaration"); | 
 | 631 |  | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 632 |   if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11) | 
| Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 633 |     Diag(Tok, diag::ext_c11_static_assert); | 
| Richard Smith | 841804b | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 634 |   if (Tok.is(tok::kw_static_assert)) | 
 | 635 |     Diag(Tok, diag::warn_cxx98_compat_static_assert); | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 636 |  | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 637 |   SourceLocation StaticAssertLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 639 |   BalancedDelimiterTracker T(*this, tok::l_paren); | 
 | 640 |   if (T.consumeOpen()) { | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 641 |     Diag(Tok, diag::err_expected_lparen); | 
| Richard Smith | 3686c71 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 642 |     SkipMalformedDecl(); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 643 |     return 0; | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 644 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 645 |  | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 646 |   ExprResult AssertExpr(ParseConstantExpression()); | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 647 |   if (AssertExpr.isInvalid()) { | 
| Richard Smith | 3686c71 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 648 |     SkipMalformedDecl(); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 649 |     return 0; | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 650 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 |  | 
| Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 652 |   if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi)) | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 653 |     return 0; | 
| Anders Carlsson | ad5f960 | 2009-03-13 23:29:20 +0000 | [diff] [blame] | 654 |  | 
| Richard Smith | 0cc323c | 2012-03-05 23:20:05 +0000 | [diff] [blame] | 655 |   if (!isTokenStringLiteral()) { | 
| Andy Gibbs | 97f8461 | 2012-11-17 19:16:52 +0000 | [diff] [blame] | 656 |     Diag(Tok, diag::err_expected_string_literal) | 
 | 657 |       << /*Source='static_assert'*/1; | 
| Richard Smith | 3686c71 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 658 |     SkipMalformedDecl(); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 659 |     return 0; | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 660 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 |  | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 662 |   ExprResult AssertMessage(ParseStringLiteralExpression()); | 
| Richard Smith | 99831e4 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 663 |   if (AssertMessage.isInvalid()) { | 
| Richard Smith | 3686c71 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 664 |     SkipMalformedDecl(); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 665 |     return 0; | 
| Richard Smith | 99831e4 | 2012-03-06 03:21:47 +0000 | [diff] [blame] | 666 |   } | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 667 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 668 |   T.consumeClose(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 |  | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 670 |   DeclEnd = Tok.getLocation(); | 
| Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 671 |   ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert); | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 672 |  | 
| John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 673 |   return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, | 
 | 674 |                                               AssertExpr.take(), | 
| Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 675 |                                               AssertMessage.take(), | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 676 |                                               T.getCloseLocation()); | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 677 | } | 
 | 678 |  | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 679 | /// ParseDecltypeSpecifier - Parse a C++11 decltype specifier. | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 680 | /// | 
 | 681 | /// 'decltype' ( expression ) | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 682 | /// 'decltype' ( 'auto' )      [C++1y] | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 683 | /// | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 684 | SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) { | 
 | 685 |   assert((Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) | 
 | 686 |            && "Not a decltype specifier"); | 
 | 687 |    | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 688 |   ExprResult Result; | 
 | 689 |   SourceLocation StartLoc = Tok.getLocation(); | 
 | 690 |   SourceLocation EndLoc; | 
 | 691 |  | 
 | 692 |   if (Tok.is(tok::annot_decltype)) { | 
 | 693 |     Result = getExprAnnotation(Tok); | 
 | 694 |     EndLoc = Tok.getAnnotationEndLoc(); | 
 | 695 |     ConsumeToken(); | 
 | 696 |     if (Result.isInvalid()) { | 
 | 697 |       DS.SetTypeSpecError(); | 
 | 698 |       return EndLoc; | 
 | 699 |     } | 
 | 700 |   } else { | 
| Richard Smith | c7b5543 | 2012-02-24 22:30:04 +0000 | [diff] [blame] | 701 |     if (Tok.getIdentifierInfo()->isStr("decltype")) | 
 | 702 |       Diag(Tok, diag::warn_cxx98_compat_decltype); | 
| Richard Smith | 39304fa | 2012-02-24 18:10:23 +0000 | [diff] [blame] | 703 |  | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 704 |     ConsumeToken(); | 
 | 705 |  | 
 | 706 |     BalancedDelimiterTracker T(*this, tok::l_paren); | 
 | 707 |     if (T.expectAndConsume(diag::err_expected_lparen_after, | 
 | 708 |                            "decltype", tok::r_paren)) { | 
 | 709 |       DS.SetTypeSpecError(); | 
 | 710 |       return T.getOpenLocation() == Tok.getLocation() ? | 
 | 711 |              StartLoc : T.getOpenLocation(); | 
 | 712 |     } | 
 | 713 |  | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 714 |     // Check for C++1y 'decltype(auto)'. | 
 | 715 |     if (Tok.is(tok::kw_auto)) { | 
 | 716 |       // No need to disambiguate here: an expression can't start with 'auto', | 
 | 717 |       // because the typename-specifier in a function-style cast operation can't | 
 | 718 |       // be 'auto'. | 
 | 719 |       Diag(Tok.getLocation(), | 
 | 720 |            getLangOpts().CPlusPlus1y | 
 | 721 |              ? diag::warn_cxx11_compat_decltype_auto_type_specifier | 
 | 722 |              : diag::ext_decltype_auto_type_specifier); | 
 | 723 |       ConsumeToken(); | 
 | 724 |     } else { | 
 | 725 |       // Parse the expression | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 726 |  | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 727 |       // C++11 [dcl.type.simple]p4: | 
 | 728 |       //   The operand of the decltype specifier is an unevaluated operand. | 
 | 729 |       EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated, | 
 | 730 |                                                    0, /*IsDecltype=*/true); | 
 | 731 |       Result = ParseExpression(); | 
 | 732 |       if (Result.isInvalid()) { | 
 | 733 |         DS.SetTypeSpecError(); | 
 | 734 |         if (SkipUntil(tok::r_paren, /*StopAtSemi=*/true, | 
 | 735 |                       /*DontConsume=*/true)) { | 
 | 736 |           EndLoc = ConsumeParen(); | 
| Argyrios Kyrtzidis | 1e58469 | 2012-10-26 22:53:44 +0000 | [diff] [blame] | 737 |         } else { | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 738 |           if (PP.isBacktrackEnabled() && Tok.is(tok::semi)) { | 
 | 739 |             // Backtrack to get the location of the last token before the semi. | 
 | 740 |             PP.RevertCachedTokens(2); | 
 | 741 |             ConsumeToken(); // the semi. | 
 | 742 |             EndLoc = ConsumeAnyToken(); | 
 | 743 |             assert(Tok.is(tok::semi)); | 
 | 744 |           } else { | 
 | 745 |             EndLoc = Tok.getLocation(); | 
 | 746 |           } | 
| Argyrios Kyrtzidis | 1e58469 | 2012-10-26 22:53:44 +0000 | [diff] [blame] | 747 |         } | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 748 |         return EndLoc; | 
| Argyrios Kyrtzidis | 1e58469 | 2012-10-26 22:53:44 +0000 | [diff] [blame] | 749 |       } | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 750 |  | 
 | 751 |       Result = Actions.ActOnDecltypeExpression(Result.take()); | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 752 |     } | 
 | 753 |  | 
 | 754 |     // Match the ')' | 
 | 755 |     T.consumeClose(); | 
 | 756 |     if (T.getCloseLocation().isInvalid()) { | 
 | 757 |       DS.SetTypeSpecError(); | 
 | 758 |       // FIXME: this should return the location of the last token | 
 | 759 |       //        that was consumed (by "consumeClose()") | 
 | 760 |       return T.getCloseLocation(); | 
 | 761 |     } | 
 | 762 |  | 
| Richard Smith | 76f3f69 | 2012-02-22 02:04:18 +0000 | [diff] [blame] | 763 |     if (Result.isInvalid()) { | 
 | 764 |       DS.SetTypeSpecError(); | 
 | 765 |       return T.getCloseLocation(); | 
 | 766 |     } | 
 | 767 |  | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 768 |     EndLoc = T.getCloseLocation(); | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 769 |   } | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 770 |   assert(!Result.isInvalid()); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 771 |  | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 772 |   const char *PrevSpec = 0; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 773 |   unsigned DiagID; | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 774 |   // Check for duplicate type specifiers (e.g. "int decltype(a)"). | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 775 |   if (Result.get() | 
 | 776 |         ? DS.SetTypeSpecType(DeclSpec::TST_decltype, StartLoc, PrevSpec, | 
 | 777 |                              DiagID, Result.release()) | 
 | 778 |         : DS.SetTypeSpecType(DeclSpec::TST_decltype_auto, StartLoc, PrevSpec, | 
 | 779 |                              DiagID)) { | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 780 |     Diag(StartLoc, DiagID) << PrevSpec; | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 781 |     DS.SetTypeSpecError(); | 
 | 782 |   } | 
 | 783 |   return EndLoc; | 
 | 784 | } | 
 | 785 |  | 
 | 786 | void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec& DS,  | 
 | 787 |                                                SourceLocation StartLoc, | 
 | 788 |                                                SourceLocation EndLoc) { | 
 | 789 |   // make sure we have a token we can turn into an annotation token | 
 | 790 |   if (PP.isBacktrackEnabled()) | 
 | 791 |     PP.RevertCachedTokens(1); | 
 | 792 |   else | 
 | 793 |     PP.EnterToken(Tok); | 
 | 794 |  | 
 | 795 |   Tok.setKind(tok::annot_decltype); | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 796 |   setExprAnnotation(Tok, | 
 | 797 |                     DS.getTypeSpecType() == TST_decltype ? DS.getRepAsExpr() : | 
 | 798 |                     DS.getTypeSpecType() == TST_decltype_auto ? ExprResult() : | 
 | 799 |                     ExprError()); | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 800 |   Tok.setAnnotationEndLoc(EndLoc); | 
 | 801 |   Tok.setLocation(StartLoc); | 
 | 802 |   PP.AnnotateCachedTokens(Tok); | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 803 | } | 
 | 804 |  | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 805 | void Parser::ParseUnderlyingTypeSpecifier(DeclSpec &DS) { | 
 | 806 |   assert(Tok.is(tok::kw___underlying_type) && | 
 | 807 |          "Not an underlying type specifier"); | 
 | 808 |  | 
 | 809 |   SourceLocation StartLoc = ConsumeToken(); | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 810 |   BalancedDelimiterTracker T(*this, tok::l_paren); | 
 | 811 |   if (T.expectAndConsume(diag::err_expected_lparen_after, | 
 | 812 |                        "__underlying_type", tok::r_paren)) { | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 813 |     return; | 
 | 814 |   } | 
 | 815 |  | 
 | 816 |   TypeResult Result = ParseTypeName(); | 
 | 817 |   if (Result.isInvalid()) { | 
 | 818 |     SkipUntil(tok::r_paren); | 
 | 819 |     return; | 
 | 820 |   } | 
 | 821 |  | 
 | 822 |   // Match the ')' | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 823 |   T.consumeClose(); | 
 | 824 |   if (T.getCloseLocation().isInvalid()) | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 825 |     return; | 
 | 826 |  | 
 | 827 |   const char *PrevSpec = 0; | 
 | 828 |   unsigned DiagID; | 
| Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 829 |   if (DS.SetTypeSpecType(DeclSpec::TST_underlyingType, StartLoc, PrevSpec, | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 830 |                          DiagID, Result.release())) | 
 | 831 |     Diag(StartLoc, DiagID) << PrevSpec; | 
| Enea Zaffanella | 2d77634 | 2013-07-06 18:54:58 +0000 | [diff] [blame] | 832 |   DS.setTypeofParensRange(T.getRange()); | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 833 | } | 
 | 834 |  | 
| David Blaikie | 09048df | 2011-10-25 15:01:20 +0000 | [diff] [blame] | 835 | /// ParseBaseTypeSpecifier - Parse a C++ base-type-specifier which is either a | 
 | 836 | /// class name or decltype-specifier. Note that we only check that the result  | 
 | 837 | /// names a type; semantic analysis will need to verify that the type names a  | 
 | 838 | /// class. The result is either a type or null, depending on whether a type  | 
 | 839 | /// name was found. | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 840 | /// | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 841 | ///       base-type-specifier: [C++11 class.derived] | 
| David Blaikie | 09048df | 2011-10-25 15:01:20 +0000 | [diff] [blame] | 842 | ///         class-or-decltype | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 843 | ///       class-or-decltype: [C++11 class.derived] | 
| David Blaikie | 09048df | 2011-10-25 15:01:20 +0000 | [diff] [blame] | 844 | ///         nested-name-specifier[opt] class-name | 
 | 845 | ///         decltype-specifier | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 846 | ///       class-name: [C++ class.name] | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 847 | ///         identifier | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 848 | ///         simple-template-id | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 849 | /// | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 850 | /// In C++98, instead of base-type-specifier, we have: | 
 | 851 | /// | 
 | 852 | ///         ::[opt] nested-name-specifier[opt] class-name | 
| David Blaikie | 22216eb | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 853 | Parser::TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation &BaseLoc, | 
 | 854 |                                                   SourceLocation &EndLocation) { | 
| David Blaikie | 7fe3878 | 2011-10-25 18:46:41 +0000 | [diff] [blame] | 855 |   // Ignore attempts to use typename | 
 | 856 |   if (Tok.is(tok::kw_typename)) { | 
 | 857 |     Diag(Tok, diag::err_expected_class_name_not_template) | 
 | 858 |       << FixItHint::CreateRemoval(Tok.getLocation()); | 
 | 859 |     ConsumeToken(); | 
 | 860 |   } | 
 | 861 |  | 
| David Blaikie | 152aa4b | 2011-10-25 18:17:58 +0000 | [diff] [blame] | 862 |   // Parse optional nested-name-specifier | 
 | 863 |   CXXScopeSpec SS; | 
 | 864 |   ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); | 
 | 865 |  | 
 | 866 |   BaseLoc = Tok.getLocation(); | 
 | 867 |  | 
| David Blaikie | 22216eb | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 868 |   // Parse decltype-specifier | 
| David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 869 |   // tok == kw_decltype is just error recovery, it can only happen when SS  | 
 | 870 |   // isn't empty | 
 | 871 |   if (Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype)) { | 
| David Blaikie | 152aa4b | 2011-10-25 18:17:58 +0000 | [diff] [blame] | 872 |     if (SS.isNotEmpty()) | 
 | 873 |       Diag(SS.getBeginLoc(), diag::err_unexpected_scope_on_base_decltype) | 
 | 874 |         << FixItHint::CreateRemoval(SS.getRange()); | 
| David Blaikie | 22216eb | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 875 |     // Fake up a Declarator to use with ActOnTypeName. | 
 | 876 |     DeclSpec DS(AttrFactory); | 
 | 877 |  | 
| David Blaikie | b577757 | 2011-12-08 04:53:15 +0000 | [diff] [blame] | 878 |     EndLocation = ParseDecltypeSpecifier(DS); | 
| David Blaikie | 22216eb | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 879 |  | 
 | 880 |     Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); | 
 | 881 |     return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); | 
 | 882 |   } | 
 | 883 |  | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 884 |   // Check whether we have a template-id that names a type. | 
 | 885 |   if (Tok.is(tok::annot_template_id)) { | 
| Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 886 |     TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); | 
| Douglas Gregor | d9b600c | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 887 |     if (TemplateId->Kind == TNK_Type_template || | 
 | 888 |         TemplateId->Kind == TNK_Dependent_template_name) { | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 889 |       AnnotateTemplateIdTokenAsType(); | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 890 |  | 
 | 891 |       assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 892 |       ParsedType Type = getTypeAnnotation(Tok); | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 893 |       EndLocation = Tok.getAnnotationEndLoc(); | 
 | 894 |       ConsumeToken(); | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 895 |  | 
 | 896 |       if (Type) | 
 | 897 |         return Type; | 
 | 898 |       return true; | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 899 |     } | 
 | 900 |  | 
 | 901 |     // Fall through to produce an error below. | 
 | 902 |   } | 
 | 903 |  | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 904 |   if (Tok.isNot(tok::identifier)) { | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 905 |     Diag(Tok, diag::err_expected_class_name); | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 906 |     return true; | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 907 |   } | 
 | 908 |  | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 909 |   IdentifierInfo *Id = Tok.getIdentifierInfo(); | 
 | 910 |   SourceLocation IdLoc = ConsumeToken(); | 
 | 911 |  | 
 | 912 |   if (Tok.is(tok::less)) { | 
 | 913 |     // It looks the user intended to write a template-id here, but the | 
 | 914 |     // template-name was wrong. Try to fix that. | 
 | 915 |     TemplateNameKind TNK = TNK_Type_template; | 
 | 916 |     TemplateTy Template; | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 917 |     if (!Actions.DiagnoseUnknownTemplateName(*Id, IdLoc, getCurScope(), | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 918 |                                              &SS, Template, TNK)) { | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 919 |       Diag(IdLoc, diag::err_unknown_template_name) | 
 | 920 |         << Id; | 
 | 921 |     } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 922 |  | 
| Serge Pavlov | 62f675c | 2013-08-10 05:54:47 +0000 | [diff] [blame^] | 923 |     if (!Template) { | 
 | 924 |       TemplateArgList TemplateArgs; | 
 | 925 |       SourceLocation LAngleLoc, RAngleLoc; | 
 | 926 |       ParseTemplateIdAfterTemplateName(TemplateTy(), IdLoc, SS, | 
 | 927 |           true, LAngleLoc, TemplateArgs, RAngleLoc); | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 928 |       return true; | 
| Serge Pavlov | 62f675c | 2013-08-10 05:54:47 +0000 | [diff] [blame^] | 929 |     } | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 930 |  | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 931 |     // Form the template name | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 932 |     UnqualifiedId TemplateName; | 
 | 933 |     TemplateName.setIdentifier(Id, IdLoc); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 934 |  | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 935 |     // Parse the full template-id, then turn it into a type. | 
| Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 936 |     if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(), | 
 | 937 |                                 TemplateName, true)) | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 938 |       return true; | 
 | 939 |     if (TNK == TNK_Dependent_template_name) | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 940 |       AnnotateTemplateIdTokenAsType(); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 941 |  | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 942 |     // If we didn't end up with a typename token, there's nothing more we | 
 | 943 |     // can do. | 
 | 944 |     if (Tok.isNot(tok::annot_typename)) | 
 | 945 |       return true; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 946 |  | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 947 |     // Retrieve the type from the annotation token, consume that token, and | 
 | 948 |     // return. | 
 | 949 |     EndLocation = Tok.getAnnotationEndLoc(); | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 950 |     ParsedType Type = getTypeAnnotation(Tok); | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 951 |     ConsumeToken(); | 
 | 952 |     return Type; | 
 | 953 |   } | 
 | 954 |  | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 955 |   // We have an identifier; check whether it is actually a type. | 
| Kaelyn Uhrain | c1fb542 | 2012-06-22 23:37:05 +0000 | [diff] [blame] | 956 |   IdentifierInfo *CorrectedII = 0; | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 957 |   ParsedType Type = Actions.getTypeName(*Id, IdLoc, getCurScope(), &SS, true, | 
| Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 958 |                                         false, ParsedType(), | 
| Abramo Bagnara | fad03b7 | 2012-01-27 08:46:19 +0000 | [diff] [blame] | 959 |                                         /*IsCtorOrDtorName=*/false, | 
| Kaelyn Uhrain | c1fb542 | 2012-06-22 23:37:05 +0000 | [diff] [blame] | 960 |                                         /*NonTrivialTypeSourceInfo=*/true, | 
 | 961 |                                         &CorrectedII); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 962 |   if (!Type) { | 
| Douglas Gregor | 124b878 | 2010-02-16 19:09:40 +0000 | [diff] [blame] | 963 |     Diag(IdLoc, diag::err_expected_class_name); | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 964 |     return true; | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 965 |   } | 
 | 966 |  | 
 | 967 |   // Consume the identifier. | 
| Douglas Gregor | 84d0a19 | 2010-01-12 21:28:44 +0000 | [diff] [blame] | 968 |   EndLocation = IdLoc; | 
| Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 969 |  | 
 | 970 |   // Fake up a Declarator to use with ActOnTypeName. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 971 |   DeclSpec DS(AttrFactory); | 
| Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 972 |   DS.SetRangeStart(IdLoc); | 
 | 973 |   DS.SetRangeEnd(EndLocation); | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 974 |   DS.getTypeSpecScope() = SS; | 
| Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 975 |  | 
 | 976 |   const char *PrevSpec = 0; | 
 | 977 |   unsigned DiagID; | 
 | 978 |   DS.SetTypeSpecType(TST_typename, IdLoc, PrevSpec, DiagID, Type); | 
 | 979 |  | 
 | 980 |   Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); | 
 | 981 |   return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 982 | } | 
 | 983 |  | 
| John McCall | c052dbb | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 984 | void Parser::ParseMicrosoftInheritanceClassAttributes(ParsedAttributes &attrs) { | 
 | 985 |   while (Tok.is(tok::kw___single_inheritance) || | 
 | 986 |          Tok.is(tok::kw___multiple_inheritance) || | 
 | 987 |          Tok.is(tok::kw___virtual_inheritance)) { | 
 | 988 |     IdentifierInfo *AttrName = Tok.getIdentifierInfo(); | 
 | 989 |     SourceLocation AttrNameLoc = ConsumeToken(); | 
 | 990 |     attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, | 
| Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame] | 991 |                  SourceLocation(), 0, 0, AttributeList::AS_GNU); | 
| John McCall | c052dbb | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 992 |   } | 
 | 993 | } | 
 | 994 |  | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 995 | /// Determine whether the following tokens are valid after a type-specifier | 
 | 996 | /// which could be a standalone declaration. This will conservatively return | 
 | 997 | /// true if there's any doubt, and is appropriate for insert-';' fixits. | 
| Richard Smith | 139be70 | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 998 | bool Parser::isValidAfterTypeSpecifier(bool CouldBeBitfield) { | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 999 |   // This switch enumerates the valid "follow" set for type-specifiers. | 
 | 1000 |   switch (Tok.getKind()) { | 
 | 1001 |   default: break; | 
 | 1002 |   case tok::semi:               // struct foo {...} ; | 
 | 1003 |   case tok::star:               // struct foo {...} *         P; | 
 | 1004 |   case tok::amp:                // struct foo {...} &         R = ... | 
| Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1005 |   case tok::ampamp:             // struct foo {...} &&        R = ... | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1006 |   case tok::identifier:         // struct foo {...} V         ; | 
 | 1007 |   case tok::r_paren:            //(struct foo {...} )         {4} | 
 | 1008 |   case tok::annot_cxxscope:     // struct foo {...} a::       b; | 
 | 1009 |   case tok::annot_typename:     // struct foo {...} a         ::b; | 
 | 1010 |   case tok::annot_template_id:  // struct foo {...} a<int>    ::b; | 
 | 1011 |   case tok::l_paren:            // struct foo {...} (         x); | 
 | 1012 |   case tok::comma:              // __builtin_offsetof(struct foo{...} , | 
| Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1013 |   case tok::kw_operator:        // struct foo       operator  ++() {...} | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1014 |     return true; | 
| Richard Smith | 139be70 | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 1015 |   case tok::colon: | 
 | 1016 |     return CouldBeBitfield;     // enum E { ... }   :         2; | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1017 |   // Type qualifiers | 
 | 1018 |   case tok::kw_const:           // struct foo {...} const     x; | 
 | 1019 |   case tok::kw_volatile:        // struct foo {...} volatile  x; | 
 | 1020 |   case tok::kw_restrict:        // struct foo {...} restrict  x; | 
| Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1021 |   // Function specifiers | 
 | 1022 |   // Note, no 'explicit'. An explicit function must be either a conversion | 
 | 1023 |   // operator or a constructor. Either way, it can't have a return type. | 
 | 1024 |   case tok::kw_inline:          // struct foo       inline    f(); | 
 | 1025 |   case tok::kw_virtual:         // struct foo       virtual   f(); | 
 | 1026 |   case tok::kw_friend:          // struct foo       friend    f(); | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1027 |   // Storage-class specifiers | 
 | 1028 |   case tok::kw_static:          // struct foo {...} static    x; | 
 | 1029 |   case tok::kw_extern:          // struct foo {...} extern    x; | 
 | 1030 |   case tok::kw_typedef:         // struct foo {...} typedef   x; | 
 | 1031 |   case tok::kw_register:        // struct foo {...} register  x; | 
 | 1032 |   case tok::kw_auto:            // struct foo {...} auto      x; | 
 | 1033 |   case tok::kw_mutable:         // struct foo {...} mutable   x; | 
| Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1034 |   case tok::kw_thread_local:    // struct foo {...} thread_local x; | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1035 |   case tok::kw_constexpr:       // struct foo {...} constexpr x; | 
 | 1036 |     // As shown above, type qualifiers and storage class specifiers absolutely | 
 | 1037 |     // can occur after class specifiers according to the grammar.  However, | 
 | 1038 |     // almost no one actually writes code like this.  If we see one of these, | 
 | 1039 |     // it is much more likely that someone missed a semi colon and the | 
 | 1040 |     // type/storage class specifier we're seeing is part of the *next* | 
 | 1041 |     // intended declaration, as in: | 
 | 1042 |     // | 
 | 1043 |     //   struct foo { ... } | 
 | 1044 |     //   typedef int X; | 
 | 1045 |     // | 
 | 1046 |     // We'd really like to emit a missing semicolon error instead of emitting | 
 | 1047 |     // an error on the 'int' saying that you can't have two type specifiers in | 
 | 1048 |     // the same declaration of X.  Because of this, we look ahead past this | 
 | 1049 |     // token to see if it's a type specifier.  If so, we know the code is | 
 | 1050 |     // otherwise invalid, so we can produce the expected semi error. | 
 | 1051 |     if (!isKnownToBeTypeSpecifier(NextToken())) | 
 | 1052 |       return true; | 
 | 1053 |     break; | 
 | 1054 |   case tok::r_brace:  // struct bar { struct foo {...} } | 
 | 1055 |     // Missing ';' at end of struct is accepted as an extension in C mode. | 
 | 1056 |     if (!getLangOpts().CPlusPlus) | 
 | 1057 |       return true; | 
 | 1058 |     break; | 
| Richard Smith | ba65f50 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 1059 |     // C++11 attributes | 
 | 1060 |   case tok::l_square: // enum E [[]] x | 
 | 1061 |     // Note, no tok::kw_alignas here; alignas cannot appertain to a type. | 
 | 1062 |     return getLangOpts().CPlusPlus11 && NextToken().is(tok::l_square); | 
| Richard Smith | 8338a9d | 2013-01-29 04:13:32 +0000 | [diff] [blame] | 1063 |   case tok::greater: | 
 | 1064 |     // template<class T = class X> | 
 | 1065 |     return getLangOpts().CPlusPlus; | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1066 |   } | 
 | 1067 |   return false; | 
 | 1068 | } | 
 | 1069 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1070 | /// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or | 
 | 1071 | /// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which | 
 | 1072 | /// until we reach the start of a definition or see a token that | 
| Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1073 | /// cannot start a definition. | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1074 | /// | 
 | 1075 | ///       class-specifier: [C++ class] | 
 | 1076 | ///         class-head '{' member-specification[opt] '}' | 
 | 1077 | ///         class-head '{' member-specification[opt] '}' attributes[opt] | 
 | 1078 | ///       class-head: | 
 | 1079 | ///         class-key identifier[opt] base-clause[opt] | 
 | 1080 | ///         class-key nested-name-specifier identifier base-clause[opt] | 
 | 1081 | ///         class-key nested-name-specifier[opt] simple-template-id | 
 | 1082 | ///                          base-clause[opt] | 
 | 1083 | /// [GNU]   class-key attributes[opt] identifier[opt] base-clause[opt] | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | /// [GNU]   class-key attributes[opt] nested-name-specifier | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1085 | ///                          identifier base-clause[opt] | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | /// [GNU]   class-key attributes[opt] nested-name-specifier[opt] | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1087 | ///                          simple-template-id base-clause[opt] | 
 | 1088 | ///       class-key: | 
 | 1089 | ///         'class' | 
 | 1090 | ///         'struct' | 
 | 1091 | ///         'union' | 
 | 1092 | /// | 
 | 1093 | ///       elaborated-type-specifier: [C++ dcl.type.elab] | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | ///         class-key ::[opt] nested-name-specifier[opt] identifier | 
 | 1095 | ///         class-key ::[opt] nested-name-specifier[opt] 'template'[opt] | 
 | 1096 | ///                          simple-template-id | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1097 | /// | 
 | 1098 | ///  Note that the C++ class-specifier and elaborated-type-specifier, | 
 | 1099 | ///  together, subsume the C99 struct-or-union-specifier: | 
 | 1100 | /// | 
 | 1101 | ///       struct-or-union-specifier: [C99 6.7.2.1] | 
 | 1102 | ///         struct-or-union identifier[opt] '{' struct-contents '}' | 
 | 1103 | ///         struct-or-union identifier | 
 | 1104 | /// [GNU]   struct-or-union attributes[opt] identifier[opt] '{' struct-contents | 
 | 1105 | ///                                                         '}' attributes[opt] | 
 | 1106 | /// [GNU]   struct-or-union attributes[opt] identifier | 
 | 1107 | ///       struct-or-union: | 
 | 1108 | ///         'struct' | 
 | 1109 | ///         'union' | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 1110 | void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, | 
 | 1111 |                                  SourceLocation StartLoc, DeclSpec &DS, | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1112 |                                  const ParsedTemplateInfo &TemplateInfo, | 
| Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 1113 |                                  AccessSpecifier AS,  | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1114 |                                  bool EnteringContext, DeclSpecContext DSC,  | 
| Bill Wendling | ad017fa | 2012-12-20 19:22:21 +0000 | [diff] [blame] | 1115 |                                  ParsedAttributesWithRange &Attributes) { | 
| Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1116 |   DeclSpec::TST TagType; | 
 | 1117 |   if (TagTokKind == tok::kw_struct) | 
 | 1118 |     TagType = DeclSpec::TST_struct; | 
 | 1119 |   else if (TagTokKind == tok::kw___interface) | 
 | 1120 |     TagType = DeclSpec::TST_interface; | 
 | 1121 |   else if (TagTokKind == tok::kw_class) | 
 | 1122 |     TagType = DeclSpec::TST_class; | 
 | 1123 |   else { | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 1124 |     assert(TagTokKind == tok::kw_union && "Not a class specifier"); | 
 | 1125 |     TagType = DeclSpec::TST_union; | 
 | 1126 |   } | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1127 |  | 
| Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 1128 |   if (Tok.is(tok::code_completion)) { | 
 | 1129 |     // Code completion for a struct, class, or union name. | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1130 |     Actions.CodeCompleteTag(getCurScope(), TagType); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1131 |     return cutOffParsing(); | 
| Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 1132 |   } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1133 |  | 
| Chandler Carruth | 926c4b4 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 1134 |   // C++03 [temp.explicit] 14.7.2/8: | 
 | 1135 |   //   The usual access checking rules do not apply to names used to specify | 
 | 1136 |   //   explicit instantiations. | 
 | 1137 |   // | 
 | 1138 |   // As an extension we do not perform access checking on the names used to | 
 | 1139 |   // specify explicit specializations either. This is important to allow | 
 | 1140 |   // specializing traits classes for private types. | 
| John McCall | 1348967 | 2012-05-07 06:16:58 +0000 | [diff] [blame] | 1141 |   // | 
 | 1142 |   // Note that we don't suppress if this turns out to be an elaborated | 
 | 1143 |   // type specifier. | 
 | 1144 |   bool shouldDelayDiagsInTag = | 
 | 1145 |     (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || | 
 | 1146 |      TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization); | 
 | 1147 |   SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag); | 
| Chandler Carruth | 926c4b4 | 2010-06-28 08:39:25 +0000 | [diff] [blame] | 1148 |  | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1149 |   ParsedAttributesWithRange attrs(AttrFactory); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1150 |   // If attributes exist after tag, parse them. | 
 | 1151 |   if (Tok.is(tok::kw___attribute)) | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1152 |     ParseGNUAttributes(attrs); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1153 |  | 
| Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 1154 |   // If declspecs exist after tag, parse them. | 
| John McCall | b1d397c | 2010-08-05 17:13:11 +0000 | [diff] [blame] | 1155 |   while (Tok.is(tok::kw___declspec)) | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1156 |     ParseMicrosoftDeclSpec(attrs); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1157 |  | 
| John McCall | c052dbb | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 1158 |   // Parse inheritance specifiers. | 
 | 1159 |   if (Tok.is(tok::kw___single_inheritance) || | 
 | 1160 |       Tok.is(tok::kw___multiple_inheritance) || | 
 | 1161 |       Tok.is(tok::kw___virtual_inheritance)) | 
 | 1162 |       ParseMicrosoftInheritanceClassAttributes(attrs); | 
 | 1163 |  | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 1164 |   // If C++0x attributes exist here, parse them. | 
 | 1165 |   // FIXME: Are we consistent with the ordering of parsing of different | 
 | 1166 |   // styles of attributes? | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1167 |   MaybeParseCXX11Attributes(attrs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 |  | 
| Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 1169 |   // Source location used by FIXIT to insert misplaced | 
 | 1170 |   // C++11 attributes | 
 | 1171 |   SourceLocation AttrFixitLoc = Tok.getLocation(); | 
 | 1172 |  | 
| John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1173 |   if (TagType == DeclSpec::TST_struct && | 
| Douglas Gregor | b467cda | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 1174 |       !Tok.is(tok::identifier) && | 
 | 1175 |       Tok.getIdentifierInfo() && | 
 | 1176 |       (Tok.is(tok::kw___is_arithmetic) || | 
 | 1177 |        Tok.is(tok::kw___is_convertible) || | 
| John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1178 |        Tok.is(tok::kw___is_empty) || | 
| Douglas Gregor | b467cda | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 1179 |        Tok.is(tok::kw___is_floating_point) || | 
 | 1180 |        Tok.is(tok::kw___is_function) || | 
| John Wiegley | 20c0da7 | 2011-04-27 23:09:49 +0000 | [diff] [blame] | 1181 |        Tok.is(tok::kw___is_fundamental) || | 
| Douglas Gregor | b467cda | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 1182 |        Tok.is(tok::kw___is_integral) || | 
 | 1183 |        Tok.is(tok::kw___is_member_function_pointer) || | 
 | 1184 |        Tok.is(tok::kw___is_member_pointer) || | 
 | 1185 |        Tok.is(tok::kw___is_pod) || | 
 | 1186 |        Tok.is(tok::kw___is_pointer) || | 
 | 1187 |        Tok.is(tok::kw___is_same) || | 
| Douglas Gregor | 877222e | 2011-04-29 01:38:03 +0000 | [diff] [blame] | 1188 |        Tok.is(tok::kw___is_scalar) || | 
| Douglas Gregor | b467cda | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 1189 |        Tok.is(tok::kw___is_signed) || | 
 | 1190 |        Tok.is(tok::kw___is_unsigned) || | 
 | 1191 |        Tok.is(tok::kw___is_void))) { | 
| Douglas Gregor | 6887614 | 2011-07-30 07:01:49 +0000 | [diff] [blame] | 1192 |     // GNU libstdc++ 4.2 and libc++ use certain intrinsic names as the | 
| Douglas Gregor | b467cda | 2011-04-29 15:31:39 +0000 | [diff] [blame] | 1193 |     // name of struct templates, but some are keywords in GCC >= 4.3 | 
 | 1194 |     // and Clang. Therefore, when we see the token sequence "struct | 
 | 1195 |     // X", make X into a normal identifier rather than a keyword, to | 
 | 1196 |     // allow libstdc++ 4.2 and libc++ to work properly. | 
| Argyrios Kyrtzidis | 646395b | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 1197 |     Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); | 
| Douglas Gregor | b117a60 | 2009-09-04 05:53:02 +0000 | [diff] [blame] | 1198 |     Tok.setKind(tok::identifier); | 
 | 1199 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1200 |  | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1201 |   // Parse the (optional) nested-name-specifier. | 
| John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1202 |   CXXScopeSpec &SS = DS.getTypeSpecScope(); | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1203 |   if (getLangOpts().CPlusPlus) { | 
| Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 1204 |     // "FOO : BAR" is not a potential typo for "FOO::BAR". | 
 | 1205 |     ColonProtectionRAIIObject X(*this); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1206 |  | 
| Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 1207 |     if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext)) | 
| John McCall | 207014e | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1208 |       DS.SetTypeSpecError(); | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1209 |     if (SS.isSet()) | 
| Chris Lattner | 08d92ec | 2009-12-10 00:32:41 +0000 | [diff] [blame] | 1210 |       if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id)) | 
 | 1211 |         Diag(Tok, diag::err_expected_ident); | 
 | 1212 |   } | 
| Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1213 |  | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1214 |   TemplateParameterLists *TemplateParams = TemplateInfo.TemplateParams; | 
 | 1215 |  | 
| Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1216 |   // Parse the (optional) class name or simple-template-id. | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1217 |   IdentifierInfo *Name = 0; | 
 | 1218 |   SourceLocation NameLoc; | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1219 |   TemplateIdAnnotation *TemplateId = 0; | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1220 |   if (Tok.is(tok::identifier)) { | 
 | 1221 |     Name = Tok.getIdentifierInfo(); | 
 | 1222 |     NameLoc = ConsumeToken(); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1223 |  | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1224 |     if (Tok.is(tok::less) && getLangOpts().CPlusPlus) { | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1225 |       // The name was supposed to refer to a template, but didn't. | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1226 |       // Eat the template argument list and try to continue parsing this as | 
 | 1227 |       // a class (or template thereof). | 
 | 1228 |       TemplateArgList TemplateArgs; | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1229 |       SourceLocation LAngleLoc, RAngleLoc; | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1230 |       if (ParseTemplateIdAfterTemplateName(TemplateTy(), NameLoc, SS, | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1231 |                                            true, LAngleLoc, | 
| Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 1232 |                                            TemplateArgs, RAngleLoc)) { | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1233 |         // We couldn't parse the template argument list at all, so don't | 
 | 1234 |         // try to give any location information for the list. | 
 | 1235 |         LAngleLoc = RAngleLoc = SourceLocation(); | 
 | 1236 |       } | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1237 |  | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1238 |       Diag(NameLoc, diag::err_explicit_spec_non_template) | 
| Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1239 |         << (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) | 
 | 1240 |         << (TagType == DeclSpec::TST_class? 0 | 
 | 1241 |             : TagType == DeclSpec::TST_struct? 1 | 
 | 1242 |             : TagType == DeclSpec::TST_interface? 2 | 
 | 1243 |             : 3) | 
 | 1244 |         << Name | 
 | 1245 |         << SourceRange(LAngleLoc, RAngleLoc); | 
 | 1246 |  | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1247 |       // Strip off the last template parameter list if it was empty, since | 
| Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1248 |       // we've removed its template argument list. | 
 | 1249 |       if (TemplateParams && TemplateInfo.LastParameterListWasEmpty) { | 
 | 1250 |         if (TemplateParams && TemplateParams->size() > 1) { | 
 | 1251 |           TemplateParams->pop_back(); | 
 | 1252 |         } else { | 
 | 1253 |           TemplateParams = 0; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1254 |           const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind | 
| Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1255 |             = ParsedTemplateInfo::NonTemplate; | 
 | 1256 |         } | 
 | 1257 |       } else if (TemplateInfo.Kind | 
 | 1258 |                                 == ParsedTemplateInfo::ExplicitInstantiation) { | 
 | 1259 |         // Pretend this is just a forward declaration. | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1260 |         TemplateParams = 0; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1261 |         const_cast<ParsedTemplateInfo&>(TemplateInfo).Kind | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1262 |           = ParsedTemplateInfo::NonTemplate; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1263 |         const_cast<ParsedTemplateInfo&>(TemplateInfo).TemplateLoc | 
| Douglas Gregor | c78c06d | 2009-10-30 22:09:44 +0000 | [diff] [blame] | 1264 |           = SourceLocation(); | 
 | 1265 |         const_cast<ParsedTemplateInfo&>(TemplateInfo).ExternLoc | 
 | 1266 |           = SourceLocation(); | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1267 |       } | 
| Douglas Gregor | 2cc782f | 2009-10-30 21:46:58 +0000 | [diff] [blame] | 1268 |     } | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1269 |   } else if (Tok.is(tok::annot_template_id)) { | 
| Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 1270 |     TemplateId = takeTemplateIdAnnotation(Tok); | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1271 |     NameLoc = ConsumeToken(); | 
| Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1272 |  | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1273 |     if (TemplateId->Kind != TNK_Type_template && | 
 | 1274 |         TemplateId->Kind != TNK_Dependent_template_name) { | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1275 |       // The template-name in the simple-template-id refers to | 
 | 1276 |       // something other than a class template. Give an appropriate | 
 | 1277 |       // error message and skip to the ';'. | 
 | 1278 |       SourceRange Range(NameLoc); | 
 | 1279 |       if (SS.isNotEmpty()) | 
 | 1280 |         Range.setBegin(SS.getBeginLoc()); | 
| Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1281 |  | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1282 |       Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template) | 
| Richard Trieu | 6e91f4b | 2013-06-19 22:25:01 +0000 | [diff] [blame] | 1283 |         << TemplateId->Name << static_cast<int>(TemplateId->Kind) << Range; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 |  | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1285 |       DS.SetTypeSpecError(); | 
 | 1286 |       SkipUntil(tok::semi, false, true); | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1287 |       return; | 
| Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1288 |     } | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1289 |   } | 
 | 1290 |  | 
| Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 1291 |   // There are four options here. | 
 | 1292 |   //  - If we are in a trailing return type, this is always just a reference, | 
 | 1293 |   //    and we must not try to parse a definition. For instance, | 
 | 1294 |   //      [] () -> struct S { }; | 
 | 1295 |   //    does not define a type. | 
 | 1296 |   //  - If we have 'struct foo {...', 'struct foo :...', | 
 | 1297 |   //    'struct foo final :' or 'struct foo final {', then this is a definition. | 
 | 1298 |   //  - If we have 'struct foo;', then this is either a forward declaration | 
 | 1299 |   //    or a friend declaration, which have to be treated differently. | 
 | 1300 |   //  - Otherwise we have something like 'struct foo xyz', a reference. | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1301 |   // | 
 | 1302 |   //  We also detect these erroneous cases to provide better diagnostic for | 
 | 1303 |   //  C++11 attributes parsing. | 
 | 1304 |   //  - attributes follow class name: | 
 | 1305 |   //    struct foo [[]] {}; | 
 | 1306 |   //  - attributes appear before or after 'final': | 
 | 1307 |   //    struct foo [[]] final [[]] {}; | 
 | 1308 |   // | 
| Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1309 |   // However, in type-specifier-seq's, things look like declarations but are | 
 | 1310 |   // just references, e.g. | 
 | 1311 |   //   new struct s; | 
| Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 1312 |   // or | 
| Richard Smith | 69730c1 | 2012-03-12 07:56:15 +0000 | [diff] [blame] | 1313 |   //   &T::operator struct s; | 
 | 1314 |   // For these, DSC is DSC_type_specifier. | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1315 |  | 
 | 1316 |   // If there are attributes after class name, parse them. | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1317 |   MaybeParseCXX11Attributes(Attributes); | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1318 |  | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1319 |   Sema::TagUseKind TUK; | 
| Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 1320 |   if (DSC == DSC_trailing) | 
 | 1321 |     TUK = Sema::TUK_Reference; | 
 | 1322 |   else if (Tok.is(tok::l_brace) || | 
 | 1323 |            (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1324 |            (isCXX11FinalKeyword() && | 
| David Blaikie | 6f42669 | 2012-03-12 15:39:49 +0000 | [diff] [blame] | 1325 |             (NextToken().is(tok::l_brace) || NextToken().is(tok::colon)))) { | 
| Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1326 |     if (DS.isFriendSpecified()) { | 
 | 1327 |       // C++ [class.friend]p2: | 
 | 1328 |       //   A class shall not be defined in a friend declaration. | 
| Richard Smith | bdad7a2 | 2012-01-10 01:33:14 +0000 | [diff] [blame] | 1329 |       Diag(Tok.getLocation(), diag::err_friend_decl_defines_type) | 
| Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1330 |         << SourceRange(DS.getFriendSpecLoc()); | 
 | 1331 |  | 
 | 1332 |       // Skip everything up to the semicolon, so that this looks like a proper | 
 | 1333 |       // friend class (or template thereof) declaration. | 
 | 1334 |       SkipUntil(tok::semi, true, true); | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1335 |       TUK = Sema::TUK_Friend; | 
| Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1336 |     } else { | 
 | 1337 |       // Okay, this is a class definition. | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1338 |       TUK = Sema::TUK_Definition; | 
| Douglas Gregor | d85bea2 | 2009-09-26 06:47:28 +0000 | [diff] [blame] | 1339 |     } | 
| Richard Smith | 150d853 | 2013-02-22 06:46:23 +0000 | [diff] [blame] | 1340 |   } else if (isCXX11FinalKeyword() && (NextToken().is(tok::l_square) || | 
 | 1341 |                                        NextToken().is(tok::kw_alignas))) { | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1342 |     // We can't tell if this is a definition or reference | 
 | 1343 |     // until we skipped the 'final' and C++11 attribute specifiers. | 
 | 1344 |     TentativeParsingAction PA(*this); | 
 | 1345 |  | 
 | 1346 |     // Skip the 'final' keyword. | 
 | 1347 |     ConsumeToken(); | 
 | 1348 |  | 
 | 1349 |     // Skip C++11 attribute specifiers. | 
 | 1350 |     while (true) { | 
 | 1351 |       if (Tok.is(tok::l_square) && NextToken().is(tok::l_square)) { | 
 | 1352 |         ConsumeBracket(); | 
 | 1353 |         if (!SkipUntil(tok::r_square)) | 
 | 1354 |           break; | 
| Richard Smith | 150d853 | 2013-02-22 06:46:23 +0000 | [diff] [blame] | 1355 |       } else if (Tok.is(tok::kw_alignas) && NextToken().is(tok::l_paren)) { | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1356 |         ConsumeToken(); | 
 | 1357 |         ConsumeParen(); | 
 | 1358 |         if (!SkipUntil(tok::r_paren)) | 
 | 1359 |           break; | 
 | 1360 |       } else { | 
 | 1361 |         break; | 
 | 1362 |       } | 
 | 1363 |     } | 
 | 1364 |  | 
 | 1365 |     if (Tok.is(tok::l_brace) || Tok.is(tok::colon)) | 
 | 1366 |       TUK = Sema::TUK_Definition; | 
 | 1367 |     else | 
 | 1368 |       TUK = Sema::TUK_Reference; | 
 | 1369 |  | 
 | 1370 |     PA.Revert(); | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1371 |   } else if (DSC != DSC_type_specifier && | 
 | 1372 |              (Tok.is(tok::semi) || | 
| Richard Smith | 139be70 | 2012-07-02 19:14:01 +0000 | [diff] [blame] | 1373 |               (Tok.isAtStartOfLine() && !isValidAfterTypeSpecifier(false)))) { | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1374 |     TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; | 
| Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1375 |     if (Tok.isNot(tok::semi)) { | 
 | 1376 |       // A semicolon was missing after this declaration. Diagnose and recover. | 
 | 1377 |       ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl, | 
 | 1378 |         DeclSpec::getSpecifierName(TagType)); | 
 | 1379 |       PP.EnterToken(Tok); | 
 | 1380 |       Tok.setKind(tok::semi); | 
 | 1381 |     } | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1382 |   } else | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1383 |     TUK = Sema::TUK_Reference; | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1384 |  | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1385 |   // Forbid misplaced attributes. In cases of a reference, we pass attributes | 
 | 1386 |   // to caller to handle. | 
| Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 1387 |   if (TUK != Sema::TUK_Reference) { | 
 | 1388 |     // If this is not a reference, then the only possible | 
 | 1389 |     // valid place for C++11 attributes to appear here | 
 | 1390 |     // is between class-key and class-name. If there are | 
 | 1391 |     // any attributes after class-name, we try a fixit to move | 
 | 1392 |     // them to the right place. | 
 | 1393 |     SourceRange AttrRange = Attributes.Range; | 
 | 1394 |     if (AttrRange.isValid()) { | 
 | 1395 |       Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) | 
 | 1396 |         << AttrRange | 
 | 1397 |         << FixItHint::CreateInsertionFromRange(AttrFixitLoc, | 
 | 1398 |                                                CharSourceRange(AttrRange, true)) | 
 | 1399 |         << FixItHint::CreateRemoval(AttrRange); | 
 | 1400 |  | 
 | 1401 |       // Recover by adding misplaced attributes to the attribute list | 
 | 1402 |       // of the class so they can be applied on the class later. | 
 | 1403 |       attrs.takeAllFrom(Attributes); | 
 | 1404 |     } | 
 | 1405 |   } | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 1406 |  | 
| John McCall | 1348967 | 2012-05-07 06:16:58 +0000 | [diff] [blame] | 1407 |   // If this is an elaborated type specifier, and we delayed | 
 | 1408 |   // diagnostics before, just merge them into the current pool. | 
 | 1409 |   if (shouldDelayDiagsInTag) { | 
 | 1410 |     diagsFromTag.done(); | 
 | 1411 |     if (TUK == Sema::TUK_Reference) | 
 | 1412 |       diagsFromTag.redelay(); | 
 | 1413 |   } | 
 | 1414 |  | 
| John McCall | 207014e | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1415 |   if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error || | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1416 |                                TUK != Sema::TUK_Definition)) { | 
| John McCall | 207014e | 2010-07-30 06:26:29 +0000 | [diff] [blame] | 1417 |     if (DS.getTypeSpecType() != DeclSpec::TST_error) { | 
 | 1418 |       // We have a declaration or reference to an anonymous class. | 
 | 1419 |       Diag(StartLoc, diag::err_anon_type_definition) | 
 | 1420 |         << DeclSpec::getSpecifierName(TagType); | 
 | 1421 |     } | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1422 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1423 |     SkipUntil(tok::comma, true); | 
 | 1424 |     return; | 
 | 1425 |   } | 
 | 1426 |  | 
| Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1427 |   // Create the tag portion of the class or class template. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1428 |   DeclResult TagOrTempResult = true; // invalid | 
 | 1429 |   TypeResult TypeResult = true; // invalid | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1430 |  | 
| Douglas Gregor | 402abb5 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 1431 |   bool Owned = false; | 
| John McCall | f1bbbb4 | 2009-09-04 01:14:41 +0000 | [diff] [blame] | 1432 |   if (TemplateId) { | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1433 |     // Explicit specialization, class template partial specialization, | 
 | 1434 |     // or explicit instantiation. | 
| Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1435 |     ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1436 |                                        TemplateId->NumArgs); | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1437 |     if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1438 |         TUK == Sema::TUK_Declaration) { | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1439 |       // This is an explicit instantiation of a class template. | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1440 |       ProhibitAttributes(attrs); | 
 | 1441 |  | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1442 |       TagOrTempResult | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1443 |         = Actions.ActOnExplicitInstantiation(getCurScope(), | 
| Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1444 |                                              TemplateInfo.ExternLoc, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1445 |                                              TemplateInfo.TemplateLoc, | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1446 |                                              TagType, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 |                                              StartLoc, | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1448 |                                              SS, | 
| John McCall | 2b5289b | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1449 |                                              TemplateId->Template, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 |                                              TemplateId->TemplateNameLoc, | 
 | 1451 |                                              TemplateId->LAngleLoc, | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1452 |                                              TemplateArgsPtr, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 |                                              TemplateId->RAngleLoc, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1454 |                                              attrs.getList()); | 
| John McCall | 74256f5 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 1455 |  | 
 | 1456 |     // Friend template-ids are treated as references unless | 
 | 1457 |     // they have template headers, in which case they're ill-formed | 
 | 1458 |     // (FIXME: "template <class T> friend class A<T>::B<int>;"). | 
 | 1459 |     // We diagnose this error in ActOnClassTemplateSpecialization. | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1460 |     } else if (TUK == Sema::TUK_Reference || | 
 | 1461 |                (TUK == Sema::TUK_Friend && | 
| John McCall | 74256f5 | 2010-04-14 00:24:33 +0000 | [diff] [blame] | 1462 |                 TemplateInfo.Kind == ParsedTemplateInfo::NonTemplate)) { | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1463 |       ProhibitAttributes(attrs); | 
| Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1464 |       TypeResult = Actions.ActOnTagTemplateIdType(TUK, TagType, StartLoc, | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1465 |                                                   TemplateId->SS, | 
| Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1466 |                                                   TemplateId->TemplateKWLoc, | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1467 |                                                   TemplateId->Template, | 
 | 1468 |                                                   TemplateId->TemplateNameLoc, | 
 | 1469 |                                                   TemplateId->LAngleLoc, | 
 | 1470 |                                                   TemplateArgsPtr, | 
| Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 1471 |                                                   TemplateId->RAngleLoc); | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1472 |     } else { | 
 | 1473 |       // This is an explicit specialization or a class template | 
 | 1474 |       // partial specialization. | 
 | 1475 |       TemplateParameterLists FakedParamLists; | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1476 |       if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { | 
 | 1477 |         // This looks like an explicit instantiation, because we have | 
 | 1478 |         // something like | 
 | 1479 |         // | 
 | 1480 |         //   template class Foo<X> | 
 | 1481 |         // | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1482 |         // but it actually has a definition. Most likely, this was | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1483 |         // meant to be an explicit specialization, but the user forgot | 
 | 1484 |         // the '<>' after 'template'. | 
| Larisse Voufo | 4985429 | 2013-06-22 13:56:11 +0000 | [diff] [blame] | 1485 | 	// It this is friend declaration however, since it cannot have a | 
 | 1486 | 	// template header, it is most likely that the user meant to | 
 | 1487 | 	// remove the 'template' keyword. | 
 | 1488 |         assert((TUK == Sema::TUK_Definition || TUK == Sema::TUK_Friend) && | 
 | 1489 | 	       "Expected a definition here"); | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1490 |  | 
| Larisse Voufo | 4985429 | 2013-06-22 13:56:11 +0000 | [diff] [blame] | 1491 | 	if (TUK == Sema::TUK_Friend) { | 
 | 1492 | 	  Diag(DS.getFriendSpecLoc(),  | 
 | 1493 | 	       diag::err_friend_explicit_instantiation); | 
 | 1494 | 	  TemplateParams = 0; | 
 | 1495 | 	} else { | 
 | 1496 | 	  SourceLocation LAngleLoc | 
 | 1497 | 	    = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); | 
 | 1498 | 	  Diag(TemplateId->TemplateNameLoc, | 
 | 1499 | 	       diag::err_explicit_instantiation_with_definition) | 
 | 1500 | 	    << SourceRange(TemplateInfo.TemplateLoc) | 
 | 1501 | 	    << FixItHint::CreateInsertion(LAngleLoc, "<>"); | 
 | 1502 | 	   | 
 | 1503 | 	  // Create a fake template parameter list that contains only | 
 | 1504 | 	  // "template<>", so that we treat this construct as a class | 
 | 1505 | 	  // template specialization. | 
 | 1506 | 	  FakedParamLists.push_back( | 
 | 1507 | 	    Actions.ActOnTemplateParameterList(0, SourceLocation(), | 
 | 1508 | 					       TemplateInfo.TemplateLoc, | 
 | 1509 | 					       LAngleLoc, | 
 | 1510 | 					       0, 0, | 
 | 1511 | 					       LAngleLoc)); | 
 | 1512 | 	  TemplateParams = &FakedParamLists; | 
 | 1513 | 	} | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1514 |       } | 
 | 1515 |  | 
 | 1516 |       // Build the class template specialization. | 
 | 1517 |       TagOrTempResult | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1518 |         = Actions.ActOnClassTemplateSpecialization(getCurScope(), TagType, TUK, | 
| Douglas Gregor | d023aec | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 1519 |                        StartLoc, DS.getModulePrivateSpecLoc(), SS, | 
| John McCall | 2b5289b | 2010-08-23 07:28:44 +0000 | [diff] [blame] | 1520 |                        TemplateId->Template, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1521 |                        TemplateId->TemplateNameLoc, | 
 | 1522 |                        TemplateId->LAngleLoc, | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1523 |                        TemplateArgsPtr, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 |                        TemplateId->RAngleLoc, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1525 |                        attrs.getList(), | 
| Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1526 |                        MultiTemplateParamsArg( | 
| Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 1527 |                                     TemplateParams? &(*TemplateParams)[0] : 0, | 
 | 1528 |                                  TemplateParams? TemplateParams->size() : 0)); | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1529 |     } | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1530 |   } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1531 |              TUK == Sema::TUK_Declaration) { | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1532 |     // Explicit instantiation of a member of a class template | 
 | 1533 |     // specialization, e.g., | 
 | 1534 |     // | 
 | 1535 |     //   template struct Outer<int>::Inner; | 
 | 1536 |     // | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1537 |     ProhibitAttributes(attrs); | 
 | 1538 |  | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1539 |     TagOrTempResult | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1540 |       = Actions.ActOnExplicitInstantiation(getCurScope(), | 
| Douglas Gregor | 45f9655 | 2009-09-04 06:33:52 +0000 | [diff] [blame] | 1541 |                                            TemplateInfo.ExternLoc, | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1542 |                                            TemplateInfo.TemplateLoc, | 
 | 1543 |                                            TagType, StartLoc, SS, Name, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1544 |                                            NameLoc, attrs.getList()); | 
| John McCall | 9a34edb | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1545 |   } else if (TUK == Sema::TUK_Friend && | 
 | 1546 |              TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) { | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1547 |     ProhibitAttributes(attrs); | 
 | 1548 |  | 
| John McCall | 9a34edb | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1549 |     TagOrTempResult = | 
 | 1550 |       Actions.ActOnTemplatedFriendTag(getCurScope(), DS.getFriendSpecLoc(), | 
 | 1551 |                                       TagType, StartLoc, SS, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1552 |                                       Name, NameLoc, attrs.getList(), | 
| Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 1553 |                                       MultiTemplateParamsArg( | 
| John McCall | 9a34edb | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1554 |                                     TemplateParams? &(*TemplateParams)[0] : 0, | 
 | 1555 |                                  TemplateParams? TemplateParams->size() : 0)); | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1556 |   } else { | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1557 |     if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition) | 
 | 1558 |       ProhibitAttributes(attrs); | 
| Larisse Voufo | 7c64ef0 | 2013-06-21 00:08:46 +0000 | [diff] [blame] | 1559 |      | 
 | 1560 |     if (TUK == Sema::TUK_Definition && | 
 | 1561 |         TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { | 
 | 1562 |       // If the declarator-id is not a template-id, issue a diagnostic and | 
 | 1563 |       // recover by ignoring the 'template' keyword. | 
 | 1564 |       Diag(Tok, diag::err_template_defn_explicit_instantiation) | 
 | 1565 |         << 1 << FixItHint::CreateRemoval(TemplateInfo.TemplateLoc); | 
| Larisse Voufo | 4985429 | 2013-06-22 13:56:11 +0000 | [diff] [blame] | 1566 |       TemplateParams = 0; | 
| Larisse Voufo | 7c64ef0 | 2013-06-21 00:08:46 +0000 | [diff] [blame] | 1567 |     } | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 1568 |  | 
| John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1569 |     bool IsDependent = false; | 
 | 1570 |  | 
| John McCall | a25c408 | 2010-10-19 18:40:57 +0000 | [diff] [blame] | 1571 |     // Don't pass down template parameter lists if this is just a tag | 
 | 1572 |     // reference.  For example, we don't need the template parameters here: | 
 | 1573 |     //   template <class T> class A *makeA(T t); | 
 | 1574 |     MultiTemplateParamsArg TParams; | 
 | 1575 |     if (TUK != Sema::TUK_Reference && TemplateParams) | 
 | 1576 |       TParams = | 
 | 1577 |         MultiTemplateParamsArg(&(*TemplateParams)[0], TemplateParams->size()); | 
 | 1578 |  | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1579 |     // Declaration or definition of a class type | 
| John McCall | 9a34edb | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1580 |     TagOrTempResult = Actions.ActOnTag(getCurScope(), TagType, TUK, StartLoc, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1581 |                                        SS, Name, NameLoc, attrs.getList(), AS, | 
| Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 1582 |                                        DS.getModulePrivateSpecLoc(), | 
| Richard Smith | bdad7a2 | 2012-01-10 01:33:14 +0000 | [diff] [blame] | 1583 |                                        TParams, Owned, IsDependent, | 
 | 1584 |                                        SourceLocation(), false, | 
 | 1585 |                                        clang::TypeResult()); | 
| John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1586 |  | 
 | 1587 |     // If ActOnTag said the type was dependent, try again with the | 
 | 1588 |     // less common call. | 
| John McCall | 9a34edb | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1589 |     if (IsDependent) { | 
 | 1590 |       assert(TUK == Sema::TUK_Reference || TUK == Sema::TUK_Friend); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1591 |       TypeResult = Actions.ActOnDependentTag(getCurScope(), TagType, TUK, | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1592 |                                              SS, Name, StartLoc, NameLoc); | 
| John McCall | 9a34edb | 2010-10-19 01:40:49 +0000 | [diff] [blame] | 1593 |     } | 
| Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 1594 |   } | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1595 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1596 |   // If there is a body, parse it and inform the actions module. | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1597 |   if (TUK == Sema::TUK_Definition) { | 
| John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 1598 |     assert(Tok.is(tok::l_brace) || | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1599 |            (getLangOpts().CPlusPlus && Tok.is(tok::colon)) || | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1600 |            isCXX11FinalKeyword()); | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1601 |     if (getLangOpts().CPlusPlus) | 
| Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 1602 |       ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType, | 
 | 1603 |                                   TagOrTempResult.get()); | 
| Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1604 |     else | 
| Douglas Gregor | 212e81c | 2009-03-25 00:13:59 +0000 | [diff] [blame] | 1605 |       ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get()); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1606 |   } | 
 | 1607 |  | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1608 |   const char *PrevSpec = 0; | 
 | 1609 |   unsigned DiagID; | 
 | 1610 |   bool Result; | 
| John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1611 |   if (!TypeResult.isInvalid()) { | 
| Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 1612 |     Result = DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, | 
 | 1613 |                                 NameLoc.isValid() ? NameLoc : StartLoc, | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1614 |                                 PrevSpec, DiagID, TypeResult.get()); | 
| John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1615 |   } else if (!TagOrTempResult.isInvalid()) { | 
| Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 1616 |     Result = DS.SetTypeSpecType(TagType, StartLoc, | 
 | 1617 |                                 NameLoc.isValid() ? NameLoc : StartLoc, | 
 | 1618 |                                 PrevSpec, DiagID, TagOrTempResult.get(), Owned); | 
| John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 1619 |   } else { | 
| Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 1620 |     DS.SetTypeSpecError(); | 
| Anders Carlsson | 66e9977 | 2009-05-11 22:27:47 +0000 | [diff] [blame] | 1621 |     return; | 
 | 1622 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1623 |  | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1624 |   if (Result) | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1625 |     Diag(StartLoc, DiagID) << PrevSpec; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1626 |  | 
| Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1627 |   // At this point, we've successfully parsed a class-specifier in 'definition' | 
 | 1628 |   // form (e.g. "struct foo { int x; }".  While we could just return here, we're | 
 | 1629 |   // going to look at what comes after it to improve error recovery.  If an | 
 | 1630 |   // impossible token occurs next, we assume that the programmer forgot a ; at | 
 | 1631 |   // the end of the declaration and recover that way. | 
 | 1632 |   // | 
| Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 1633 |   // Also enforce C++ [temp]p3: | 
 | 1634 |   //   In a template-declaration which defines a class, no declarator | 
 | 1635 |   //   is permitted. | 
| Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1636 |   if (TUK == Sema::TUK_Definition && | 
 | 1637 |       (TemplateInfo.Kind || !isValidAfterTypeSpecifier(false))) { | 
| Argyrios Kyrtzidis | 7d033b2 | 2012-12-17 20:10:43 +0000 | [diff] [blame] | 1638 |     if (Tok.isNot(tok::semi)) { | 
 | 1639 |       ExpectAndConsume(tok::semi, diag::err_expected_semi_after_tagdecl, | 
 | 1640 |         DeclSpec::getSpecifierName(TagType)); | 
 | 1641 |       // Push this token back into the preprocessor and change our current token | 
 | 1642 |       // to ';' so that the rest of the code recovers as though there were an | 
 | 1643 |       // ';' after the definition. | 
 | 1644 |       PP.EnterToken(Tok); | 
 | 1645 |       Tok.setKind(tok::semi); | 
 | 1646 |     } | 
| Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 1647 |   } | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1648 | } | 
 | 1649 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | /// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived]. | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1651 | /// | 
 | 1652 | ///       base-clause : [C++ class.derived] | 
 | 1653 | ///         ':' base-specifier-list | 
 | 1654 | ///       base-specifier-list: | 
 | 1655 | ///         base-specifier '...'[opt] | 
 | 1656 | ///         base-specifier-list ',' base-specifier '...'[opt] | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1657 | void Parser::ParseBaseClause(Decl *ClassDecl) { | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1658 |   assert(Tok.is(tok::colon) && "Not a base clause"); | 
 | 1659 |   ConsumeToken(); | 
 | 1660 |  | 
| Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1661 |   // Build up an array of parsed base specifiers. | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1662 |   SmallVector<CXXBaseSpecifier *, 8> BaseInfo; | 
| Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1663 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1664 |   while (true) { | 
 | 1665 |     // Parse a base-specifier. | 
| Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1666 |     BaseResult Result = ParseBaseSpecifier(ClassDecl); | 
| Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1667 |     if (Result.isInvalid()) { | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1668 |       // Skip the rest of this base specifier, up until the comma or | 
 | 1669 |       // opening brace. | 
| Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1670 |       SkipUntil(tok::comma, tok::l_brace, true, true); | 
 | 1671 |     } else { | 
 | 1672 |       // Add this to our array of base specifiers. | 
| Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 1673 |       BaseInfo.push_back(Result.get()); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1674 |     } | 
 | 1675 |  | 
 | 1676 |     // If the next token is a comma, consume it and keep reading | 
 | 1677 |     // base-specifiers. | 
 | 1678 |     if (Tok.isNot(tok::comma)) break; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1680 |     // Consume the comma. | 
 | 1681 |     ConsumeToken(); | 
 | 1682 |   } | 
| Douglas Gregor | f8268ae | 2008-10-22 17:49:05 +0000 | [diff] [blame] | 1683 |  | 
 | 1684 |   // Attach the base specifiers | 
| Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1685 |   Actions.ActOnBaseSpecifiers(ClassDecl, BaseInfo.data(), BaseInfo.size()); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1686 | } | 
 | 1687 |  | 
 | 1688 | /// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is | 
 | 1689 | /// one entry in the base class list of a class specifier, for example: | 
 | 1690 | ///    class foo : public bar, virtual private baz { | 
 | 1691 | /// 'public bar' and 'virtual private baz' are each base-specifiers. | 
 | 1692 | /// | 
 | 1693 | ///       base-specifier: [C++ class.derived] | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1694 | ///         attribute-specifier-seq[opt] base-type-specifier | 
 | 1695 | ///         attribute-specifier-seq[opt] 'virtual' access-specifier[opt] | 
 | 1696 | ///                 base-type-specifier | 
 | 1697 | ///         attribute-specifier-seq[opt] access-specifier 'virtual'[opt] | 
 | 1698 | ///                 base-type-specifier | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1699 | Parser::BaseResult Parser::ParseBaseSpecifier(Decl *ClassDecl) { | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1700 |   bool IsVirtual = false; | 
 | 1701 |   SourceLocation StartLoc = Tok.getLocation(); | 
 | 1702 |  | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1703 |   ParsedAttributesWithRange Attributes(AttrFactory); | 
 | 1704 |   MaybeParseCXX11Attributes(Attributes); | 
 | 1705 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1706 |   // Parse the 'virtual' keyword. | 
 | 1707 |   if (Tok.is(tok::kw_virtual))  { | 
 | 1708 |     ConsumeToken(); | 
 | 1709 |     IsVirtual = true; | 
 | 1710 |   } | 
 | 1711 |  | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1712 |   CheckMisplacedCXX11Attribute(Attributes, StartLoc); | 
 | 1713 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1714 |   // Parse an (optional) access specifier. | 
 | 1715 |   AccessSpecifier Access = getAccessSpecifierIfPresent(); | 
| John McCall | 92f8831 | 2010-01-23 00:46:32 +0000 | [diff] [blame] | 1716 |   if (Access != AS_none) | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1717 |     ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 |  | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1719 |   CheckMisplacedCXX11Attribute(Attributes, StartLoc); | 
 | 1720 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1721 |   // Parse the 'virtual' keyword (again!), in case it came after the | 
 | 1722 |   // access specifier. | 
 | 1723 |   if (Tok.is(tok::kw_virtual))  { | 
 | 1724 |     SourceLocation VirtualLoc = ConsumeToken(); | 
 | 1725 |     if (IsVirtual) { | 
 | 1726 |       // Complain about duplicate 'virtual' | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1727 |       Diag(VirtualLoc, diag::err_dup_virtual) | 
| Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1728 |         << FixItHint::CreateRemoval(VirtualLoc); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1729 |     } | 
 | 1730 |  | 
 | 1731 |     IsVirtual = true; | 
 | 1732 |   } | 
 | 1733 |  | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1734 |   CheckMisplacedCXX11Attribute(Attributes, StartLoc); | 
 | 1735 |  | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1736 |   // Parse the class-name. | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1737 |   SourceLocation EndLocation; | 
| David Blaikie | 22216eb | 2011-10-25 17:10:12 +0000 | [diff] [blame] | 1738 |   SourceLocation BaseLoc; | 
 | 1739 |   TypeResult BaseType = ParseBaseTypeSpecifier(BaseLoc, EndLocation); | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1740 |   if (BaseType.isInvalid()) | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1741 |     return true; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1742 |  | 
| Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1743 |   // Parse the optional ellipsis (for a pack expansion). The ellipsis is  | 
 | 1744 |   // actually part of the base-specifier-list grammar productions, but we | 
 | 1745 |   // parse it here for convenience. | 
 | 1746 |   SourceLocation EllipsisLoc; | 
 | 1747 |   if (Tok.is(tok::ellipsis)) | 
 | 1748 |     EllipsisLoc = ConsumeToken(); | 
 | 1749 |    | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1750 |   // Find the complete source range for the base-specifier. | 
| Douglas Gregor | 7f43d67 | 2009-02-25 23:52:28 +0000 | [diff] [blame] | 1751 |   SourceRange Range(StartLoc, EndLocation); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1752 |  | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1753 |   // Notify semantic analysis that we have parsed a complete | 
 | 1754 |   // base-specifier. | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 1755 |   return Actions.ActOnBaseSpecifier(ClassDecl, Range, Attributes, IsVirtual, | 
 | 1756 |                                     Access, BaseType.get(), BaseLoc, | 
 | 1757 |                                     EllipsisLoc); | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1758 | } | 
 | 1759 |  | 
 | 1760 | /// getAccessSpecifierIfPresent - Determine whether the next token is | 
 | 1761 | /// a C++ access-specifier. | 
 | 1762 | /// | 
 | 1763 | ///       access-specifier: [C++ class.derived] | 
 | 1764 | ///         'private' | 
 | 1765 | ///         'protected' | 
 | 1766 | ///         'public' | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | AccessSpecifier Parser::getAccessSpecifierIfPresent() const { | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 1768 |   switch (Tok.getKind()) { | 
 | 1769 |   default: return AS_none; | 
 | 1770 |   case tok::kw_private: return AS_private; | 
 | 1771 |   case tok::kw_protected: return AS_protected; | 
 | 1772 |   case tok::kw_public: return AS_public; | 
 | 1773 |   } | 
 | 1774 | } | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1775 |  | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1776 | /// \brief If the given declarator has any parts for which parsing has to be | 
| Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 1777 | /// delayed, e.g., default arguments, create a late-parsed method declaration | 
 | 1778 | /// record to handle the parsing at the end of the class definition. | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1779 | void Parser::HandleMemberFunctionDeclDelays(Declarator& DeclaratorInfo, | 
 | 1780 |                                             Decl *ThisDecl) { | 
| Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1781 |   // We just declared a member function. If this member function | 
| Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 1782 |   // has any default arguments, we'll need to parse them later. | 
| Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1783 |   LateParsedMethodDeclaration *LateMethod = 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1784 |   DeclaratorChunk::FunctionTypeInfo &FTI | 
| Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 1785 |     = DeclaratorInfo.getFunctionTypeInfo(); | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1786 |  | 
| Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1787 |   for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { | 
 | 1788 |     if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { | 
 | 1789 |       if (!LateMethod) { | 
 | 1790 |         // Push this method onto the stack of late-parsed method | 
 | 1791 |         // declarations. | 
| Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 1792 |         LateMethod = new LateParsedMethodDeclaration(this, ThisDecl); | 
 | 1793 |         getCurrentClass().LateParsedDeclarations.push_back(LateMethod); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1794 |         LateMethod->TemplateScope = getCurScope()->isTemplateParamScope(); | 
| Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1795 |  | 
 | 1796 |         // Add all of the parameters prior to this one (they don't | 
 | 1797 |         // have default arguments). | 
 | 1798 |         LateMethod->DefaultArgs.reserve(FTI.NumArgs); | 
 | 1799 |         for (unsigned I = 0; I < ParamIdx; ++I) | 
 | 1800 |           LateMethod->DefaultArgs.push_back( | 
| Douglas Gregor | 8f8210c | 2010-03-02 01:29:43 +0000 | [diff] [blame] | 1801 |                              LateParsedDefaultArgument(FTI.ArgInfo[I].Param)); | 
| Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1802 |       } | 
 | 1803 |  | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 1804 |       // Add this parameter to the list of parameters (it may or may | 
| Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 1805 |       // not have a default argument). | 
 | 1806 |       LateMethod->DefaultArgs.push_back( | 
 | 1807 |         LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, | 
 | 1808 |                                   FTI.ArgInfo[ParamIdx].DefaultArgTokens)); | 
 | 1809 |     } | 
 | 1810 |   } | 
 | 1811 | } | 
 | 1812 |  | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1813 | /// isCXX11VirtSpecifier - Determine whether the given token is a C++11 | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1814 | /// virt-specifier. | 
 | 1815 | /// | 
 | 1816 | ///       virt-specifier: | 
 | 1817 | ///         override | 
 | 1818 | ///         final | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1819 | VirtSpecifiers::Specifier Parser::isCXX11VirtSpecifier(const Token &Tok) const { | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1820 |   if (!getLangOpts().CPlusPlus) | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1821 |     return VirtSpecifiers::VS_None; | 
 | 1822 |  | 
| Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1823 |   if (Tok.is(tok::identifier)) { | 
 | 1824 |     IdentifierInfo *II = Tok.getIdentifierInfo(); | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1825 |  | 
| Anders Carlsson | 7eeb4ec | 2011-01-20 03:47:08 +0000 | [diff] [blame] | 1826 |     // Initialize the contextual keywords. | 
 | 1827 |     if (!Ident_final) { | 
 | 1828 |       Ident_final = &PP.getIdentifierTable().get("final"); | 
 | 1829 |       Ident_override = &PP.getIdentifierTable().get("override"); | 
 | 1830 |     } | 
 | 1831 |  | 
| Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1832 |     if (II == Ident_override) | 
 | 1833 |       return VirtSpecifiers::VS_Override; | 
 | 1834 |  | 
 | 1835 |     if (II == Ident_final) | 
 | 1836 |       return VirtSpecifiers::VS_Final; | 
 | 1837 |   } | 
 | 1838 |  | 
 | 1839 |   return VirtSpecifiers::VS_None; | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1840 | } | 
 | 1841 |  | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1842 | /// ParseOptionalCXX11VirtSpecifierSeq - Parse a virt-specifier-seq. | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1843 | /// | 
 | 1844 | ///       virt-specifier-seq: | 
 | 1845 | ///         virt-specifier | 
 | 1846 | ///         virt-specifier-seq virt-specifier | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1847 | void Parser::ParseOptionalCXX11VirtSpecifierSeq(VirtSpecifiers &VS, | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1848 |                                                 bool IsInterface) { | 
| Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1849 |   while (true) { | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1850 |     VirtSpecifiers::Specifier Specifier = isCXX11VirtSpecifier(); | 
| Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1851 |     if (Specifier == VirtSpecifiers::VS_None) | 
 | 1852 |       return; | 
 | 1853 |  | 
 | 1854 |     // C++ [class.mem]p8: | 
 | 1855 |     //   A virt-specifier-seq shall contain at most one of each virt-specifier. | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1856 |     const char *PrevSpec = 0; | 
| Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 1857 |     if (VS.SetSpecifier(Specifier, Tok.getLocation(), PrevSpec)) | 
| Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1858 |       Diag(Tok.getLocation(), diag::err_duplicate_virt_specifier) | 
 | 1859 |         << PrevSpec | 
 | 1860 |         << FixItHint::CreateRemoval(Tok.getLocation()); | 
 | 1861 |  | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1862 |     if (IsInterface && Specifier == VirtSpecifiers::VS_Final) { | 
 | 1863 |       Diag(Tok.getLocation(), diag::err_override_control_interface) | 
 | 1864 |         << VirtSpecifiers::getSpecifierName(Specifier); | 
 | 1865 |     } else { | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1866 |       Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 ? | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 1867 |            diag::warn_cxx98_compat_override_control_keyword : | 
 | 1868 |            diag::ext_override_control_keyword) | 
 | 1869 |         << VirtSpecifiers::getSpecifierName(Specifier); | 
 | 1870 |     } | 
| Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1871 |     ConsumeToken(); | 
 | 1872 |   } | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1873 | } | 
 | 1874 |  | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1875 | /// isCXX11FinalKeyword - Determine whether the next token is a C++11 | 
| Anders Carlsson | 8a29ba0 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1876 | /// contextual 'final' keyword. | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1877 | bool Parser::isCXX11FinalKeyword() const { | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1878 |   if (!getLangOpts().CPlusPlus) | 
| Anders Carlsson | 8a29ba0 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1879 |     return false; | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1880 |  | 
| Anders Carlsson | 8a29ba0 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1881 |   if (!Tok.is(tok::identifier)) | 
 | 1882 |     return false; | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1883 |  | 
| Anders Carlsson | 8a29ba0 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1884 |   // Initialize the contextual keywords. | 
 | 1885 |   if (!Ident_final) { | 
 | 1886 |     Ident_final = &PP.getIdentifierTable().get("final"); | 
 | 1887 |     Ident_override = &PP.getIdentifierTable().get("override"); | 
 | 1888 |   } | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1889 |    | 
| Anders Carlsson | 8a29ba0 | 2011-03-25 14:53:29 +0000 | [diff] [blame] | 1890 |   return Tok.getIdentifierInfo() == Ident_final; | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1891 | } | 
 | 1892 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1893 | /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. | 
 | 1894 | /// | 
 | 1895 | ///       member-declaration: | 
 | 1896 | ///         decl-specifier-seq[opt] member-declarator-list[opt] ';' | 
 | 1897 | ///         function-definition ';'[opt] | 
 | 1898 | ///         ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] | 
 | 1899 | ///         using-declaration                                            [TODO] | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1900 | /// [C++0x] static_assert-declaration | 
| Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 1901 | ///         template-declaration | 
| Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 1902 | /// [GNU]   '__extension__' member-declaration | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1903 | /// | 
 | 1904 | ///       member-declarator-list: | 
 | 1905 | ///         member-declarator | 
 | 1906 | ///         member-declarator-list ',' member-declarator | 
 | 1907 | /// | 
 | 1908 | ///       member-declarator: | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1909 | ///         declarator virt-specifier-seq[opt] pure-specifier[opt] | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1910 | ///         declarator constant-initializer[opt] | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1911 | /// [C++11] declarator brace-or-equal-initializer[opt] | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1912 | ///         identifier[opt] ':' constant-expression | 
 | 1913 | /// | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1914 | ///       virt-specifier-seq: | 
 | 1915 | ///         virt-specifier | 
 | 1916 | ///         virt-specifier-seq virt-specifier | 
 | 1917 | /// | 
 | 1918 | ///       virt-specifier: | 
 | 1919 | ///         override | 
 | 1920 | ///         final | 
| Anders Carlsson | 1f3b6fd | 2011-01-16 23:56:42 +0000 | [diff] [blame] | 1921 | ///  | 
| Sebastian Redl | e2b6833 | 2009-04-12 17:16:29 +0000 | [diff] [blame] | 1922 | ///       pure-specifier: | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1923 | ///         '= 0' | 
 | 1924 | /// | 
 | 1925 | ///       constant-initializer: | 
 | 1926 | ///         '=' constant-expression | 
 | 1927 | /// | 
| Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1928 | void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 1929 |                                             AttributeList *AccessAttrs, | 
| John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 1930 |                                        const ParsedTemplateInfo &TemplateInfo, | 
 | 1931 |                                        ParsingDeclRAIIObject *TemplateDiags) { | 
| Douglas Gregor | 8a9013d | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1932 |   if (Tok.is(tok::at)) { | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1933 |     if (getLangOpts().ObjC1 && NextToken().isObjCAtKeyword(tok::objc_defs)) | 
| Douglas Gregor | 8a9013d | 2011-04-14 17:21:19 +0000 | [diff] [blame] | 1934 |       Diag(Tok, diag::err_at_defs_cxx); | 
 | 1935 |     else | 
 | 1936 |       Diag(Tok, diag::err_at_in_class); | 
 | 1937 |      | 
 | 1938 |     ConsumeToken(); | 
 | 1939 |     SkipUntil(tok::r_brace); | 
 | 1940 |     return; | 
 | 1941 |   } | 
 | 1942 |    | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1943 |   // Access declarations. | 
| Richard Smith | 83a22ec | 2012-05-09 08:23:23 +0000 | [diff] [blame] | 1944 |   bool MalformedTypeSpec = false; | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1945 |   if (!TemplateInfo.Kind && | 
| Richard Smith | 83a22ec | 2012-05-09 08:23:23 +0000 | [diff] [blame] | 1946 |       (Tok.is(tok::identifier) || Tok.is(tok::coloncolon))) { | 
 | 1947 |     if (TryAnnotateCXXScopeToken()) | 
 | 1948 |       MalformedTypeSpec = true; | 
 | 1949 |  | 
 | 1950 |     bool isAccessDecl; | 
 | 1951 |     if (Tok.isNot(tok::annot_cxxscope)) | 
 | 1952 |       isAccessDecl = false; | 
 | 1953 |     else if (NextToken().is(tok::identifier)) | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1954 |       isAccessDecl = GetLookAheadToken(2).is(tok::semi); | 
 | 1955 |     else | 
 | 1956 |       isAccessDecl = NextToken().is(tok::kw_operator); | 
 | 1957 |  | 
 | 1958 |     if (isAccessDecl) { | 
 | 1959 |       // Collect the scope specifier token we annotated earlier. | 
 | 1960 |       CXXScopeSpec SS; | 
| Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 1961 |       ParseOptionalCXXScopeSpecifier(SS, ParsedType(),  | 
 | 1962 |                                      /*EnteringContext=*/false); | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1963 |  | 
 | 1964 |       // Try to parse an unqualified-id. | 
| Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1965 |       SourceLocation TemplateKWLoc; | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1966 |       UnqualifiedId Name; | 
| Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 1967 |       if (ParseUnqualifiedId(SS, false, true, true, ParsedType(), | 
 | 1968 |                              TemplateKWLoc, Name)) { | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1969 |         SkipUntil(tok::semi); | 
 | 1970 |         return; | 
 | 1971 |       } | 
 | 1972 |  | 
 | 1973 |       // TODO: recover from mistakenly-qualified operator declarations. | 
 | 1974 |       if (ExpectAndConsume(tok::semi, | 
 | 1975 |                            diag::err_expected_semi_after, | 
 | 1976 |                            "access declaration", | 
 | 1977 |                            tok::semi)) | 
 | 1978 |         return; | 
 | 1979 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1980 |       Actions.ActOnUsingDeclaration(getCurScope(), AS, | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 1981 |                                     /* HasUsingKeyword */ false, | 
 | 1982 |                                     SourceLocation(), | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1983 |                                     SS, Name, | 
 | 1984 |                                     /* AttrList */ 0, | 
| Enea Zaffanella | 8d030c7 | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 1985 |                                     /* HasTypenameKeyword */ false, | 
| John McCall | 60fa3cf | 2009-12-11 02:10:03 +0000 | [diff] [blame] | 1986 |                                     SourceLocation()); | 
 | 1987 |       return; | 
 | 1988 |     } | 
 | 1989 |   } | 
 | 1990 |  | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 1991 |   // static_assert-declaration | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 1992 |   if (Tok.is(tok::kw_static_assert) || Tok.is(tok::kw__Static_assert)) { | 
| Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 1993 |     // FIXME: Check for templates | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 1994 |     SourceLocation DeclEnd; | 
 | 1995 |     ParseStaticAssertDeclaration(DeclEnd); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1996 |     return; | 
 | 1997 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1998 |  | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1999 |   if (Tok.is(tok::kw_template)) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2000 |     assert(!TemplateInfo.TemplateParams && | 
| Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2001 |            "Nested template improperly parsed?"); | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 2002 |     SourceLocation DeclEnd; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2003 |     ParseDeclarationStartingWithTemplate(Declarator::MemberContext, DeclEnd, | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2004 |                                          AS, AccessAttrs); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2005 |     return; | 
 | 2006 |   } | 
| Anders Carlsson | 5aeccdb | 2009-03-26 00:52:18 +0000 | [diff] [blame] | 2007 |  | 
| Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 2008 |   // Handle:  member-declaration ::= '__extension__' member-declaration | 
 | 2009 |   if (Tok.is(tok::kw___extension__)) { | 
 | 2010 |     // __extension__ silences extension warnings in the subexpression. | 
 | 2011 |     ExtensionRAIIObject O(Diags);  // Use RAII to do this. | 
 | 2012 |     ConsumeToken(); | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2013 |     return ParseCXXClassMemberDeclaration(AS, AccessAttrs, | 
 | 2014 |                                           TemplateInfo, TemplateDiags); | 
| Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 2015 |   } | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2016 |  | 
| Chris Lattner | 4ed5d91 | 2010-02-02 01:23:29 +0000 | [diff] [blame] | 2017 |   // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it | 
 | 2018 |   // is a bitfield. | 
| Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 2019 |   ColonProtectionRAIIObject X(*this); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2020 |  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2021 |   ParsedAttributesWithRange attrs(AttrFactory); | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2022 |   ParsedAttributesWithRange FnAttrs(AttrFactory); | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2023 |   // Optional C++11 attribute-specifier | 
 | 2024 |   MaybeParseCXX11Attributes(attrs); | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2025 |   // We need to keep these attributes for future diagnostic | 
 | 2026 |   // before they are taken over by declaration specifier. | 
 | 2027 |   FnAttrs.addAll(attrs.getList()); | 
 | 2028 |   FnAttrs.Range = attrs.Range; | 
 | 2029 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2030 |   MaybeParseMicrosoftAttributes(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2031 |  | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2032 |   if (Tok.is(tok::kw_using)) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2033 |     ProhibitAttributes(attrs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 |  | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2035 |     // Eat 'using'. | 
 | 2036 |     SourceLocation UsingLoc = ConsumeToken(); | 
 | 2037 |  | 
 | 2038 |     if (Tok.is(tok::kw_namespace)) { | 
 | 2039 |       Diag(UsingLoc, diag::err_using_namespace_in_class); | 
 | 2040 |       SkipUntil(tok::semi, true, true); | 
| Chris Lattner | ae50d50 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 2041 |     } else { | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2042 |       SourceLocation DeclEnd; | 
| Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 2043 |       // Otherwise, it must be a using-declaration or an alias-declaration. | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 2044 |       ParseUsingDeclaration(Declarator::MemberContext, TemplateInfo, | 
 | 2045 |                             UsingLoc, DeclEnd, AS); | 
| Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 2046 |     } | 
 | 2047 |     return; | 
 | 2048 |   } | 
 | 2049 |  | 
| DeLesley Hutchins | 2287c5e | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 2050 |   // Hold late-parsed attributes so we can attach a Decl to them later. | 
 | 2051 |   LateParsedAttrList CommonLateParsedAttrs; | 
 | 2052 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2053 |   // decl-specifier-seq: | 
 | 2054 |   // Parse the common declaration-specifiers piece. | 
| John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 2055 |   ParsingDeclSpec DS(*this, TemplateDiags); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2056 |   DS.takeAttributesFrom(attrs); | 
| Richard Smith | 83a22ec | 2012-05-09 08:23:23 +0000 | [diff] [blame] | 2057 |   if (MalformedTypeSpec) | 
 | 2058 |     DS.SetTypeSpecError(); | 
| DeLesley Hutchins | 2287c5e | 2012-03-02 22:12:59 +0000 | [diff] [blame] | 2059 |   ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class, | 
 | 2060 |                              &CommonLateParsedAttrs); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2061 |  | 
| Benjamin Kramer | 5354e77 | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 2062 |   MultiTemplateParamsArg TemplateParams( | 
| John McCall | dd4a3b0 | 2009-09-16 22:47:08 +0000 | [diff] [blame] | 2063 |       TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->data() : 0, | 
 | 2064 |       TemplateInfo.TemplateParams? TemplateInfo.TemplateParams->size() : 0); | 
 | 2065 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2066 |   if (Tok.is(tok::semi)) { | 
 | 2067 |     ConsumeToken(); | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2068 |  | 
 | 2069 |     if (DS.isFriendSpecified()) | 
 | 2070 |       ProhibitAttributes(FnAttrs); | 
 | 2071 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2072 |     Decl *TheDecl = | 
| Chandler Carruth | 0f4be74 | 2011-05-03 18:35:10 +0000 | [diff] [blame] | 2073 |       Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS, TemplateParams); | 
| John McCall | c9068d7 | 2010-07-16 08:13:16 +0000 | [diff] [blame] | 2074 |     DS.complete(TheDecl); | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2075 |     return; | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2076 |   } | 
| Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2077 |  | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2078 |   ParsingDeclarator DeclaratorInfo(*this, DS, Declarator::MemberContext); | 
| Nico Weber | 4867347 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 2079 |   VirtSpecifiers VS; | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2080 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2081 |   // Hold late-parsed attributes so we can attach a Decl to them later. | 
 | 2082 |   LateParsedAttrList LateParsedAttrs; | 
 | 2083 |  | 
| Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2084 |   SourceLocation EqualLoc; | 
 | 2085 |   bool HasInitializer = false; | 
 | 2086 |   ExprResult Init; | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2087 |   if (Tok.isNot(tok::colon)) { | 
| Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 2088 |     // Don't parse FOO:BAR as if it were a typo for FOO::BAR. | 
 | 2089 |     ColonProtectionRAIIObject X(*this); | 
 | 2090 |  | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2091 |     // Parse the first declarator. | 
 | 2092 |     ParseDeclarator(DeclaratorInfo); | 
| Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2093 |     // Error parsing the declarator? | 
| Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 2094 |     if (!DeclaratorInfo.hasName()) { | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2095 |       // If so, skip until the semi-colon or a }. | 
| Sebastian Redl | d941fa4 | 2011-04-24 16:27:48 +0000 | [diff] [blame] | 2096 |       SkipUntil(tok::r_brace, true, true); | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2097 |       if (Tok.is(tok::semi)) | 
 | 2098 |         ConsumeToken(); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2099 |       return; | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2100 |     } | 
 | 2101 |  | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2102 |     ParseOptionalCXX11VirtSpecifierSeq(VS, getCurrentClass().IsInterface); | 
| Nico Weber | 4867347 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 2103 |  | 
| John Thompson | 1b2fc0f | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 2104 |     // If attributes exist after the declarator, but before an '{', parse them. | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2105 |     MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs); | 
| John Thompson | 1b2fc0f | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 2106 |  | 
| Francois Pichet | 6a24747 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2107 |     // MSVC permits pure specifier on inline functions declared at class scope. | 
 | 2108 |     // Hence check for =0 before checking for function definition. | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2109 |     if (getLangOpts().MicrosoftExt && Tok.is(tok::equal) && | 
| Francois Pichet | 6a24747 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2110 |         DeclaratorInfo.isFunctionDeclarator() &&  | 
 | 2111 |         NextToken().is(tok::numeric_constant)) { | 
| Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2112 |       EqualLoc = ConsumeToken(); | 
| Francois Pichet | 6a24747 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2113 |       Init = ParseInitializer(); | 
 | 2114 |       if (Init.isInvalid()) | 
 | 2115 |         SkipUntil(tok::comma, true, true); | 
| Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2116 |       else | 
 | 2117 |         HasInitializer = true; | 
| Francois Pichet | 6a24747 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 2118 |     } | 
 | 2119 |  | 
| Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2120 |     FunctionDefinitionKind DefinitionKind = FDK_Declaration; | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2121 |     // function-definition: | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2122 |     // | 
 | 2123 |     // In C++11, a non-function declarator followed by an open brace is a | 
 | 2124 |     // braced-init-list for an in-class member initialization, not an | 
 | 2125 |     // erroneous function definition. | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2126 |     if (Tok.is(tok::l_brace) && !getLangOpts().CPlusPlus11) { | 
| Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2127 |       DefinitionKind = FDK_Definition; | 
| Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2128 |     } else if (DeclaratorInfo.isFunctionDeclarator()) { | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2129 |       if (Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) { | 
| Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2130 |         DefinitionKind = FDK_Definition; | 
| Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2131 |       } else if (Tok.is(tok::equal)) { | 
 | 2132 |         const Token &KW = NextToken(); | 
| Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2133 |         if (KW.is(tok::kw_default)) | 
 | 2134 |           DefinitionKind = FDK_Defaulted; | 
 | 2135 |         else if (KW.is(tok::kw_delete)) | 
 | 2136 |           DefinitionKind = FDK_Deleted; | 
| Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2137 |       } | 
 | 2138 |     } | 
 | 2139 |  | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2140 |     // C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains  | 
 | 2141 |     // to a friend declaration, that declaration shall be a definition. | 
 | 2142 |     if (DeclaratorInfo.isFunctionDeclarator() &&  | 
 | 2143 |         DefinitionKind != FDK_Definition && DS.isFriendSpecified()) { | 
 | 2144 |       // Diagnose attributes that appear before decl specifier: | 
 | 2145 |       // [[]] friend int foo(); | 
 | 2146 |       ProhibitAttributes(FnAttrs); | 
 | 2147 |     } | 
 | 2148 |  | 
| Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2149 |     if (DefinitionKind) { | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2150 |       if (!DeclaratorInfo.isFunctionDeclarator()) { | 
| Richard Trieu | 65ba948 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 2151 |         Diag(DeclaratorInfo.getIdentifierLoc(), diag::err_func_def_no_params); | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2152 |         ConsumeBrace(); | 
| Richard Trieu | 65ba948 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 2153 |         SkipUntil(tok::r_brace, /*StopAtSemi*/false); | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2154 |  | 
| Douglas Gregor | 9ea416e | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 2155 |         // Consume the optional ';' | 
 | 2156 |         if (Tok.is(tok::semi)) | 
 | 2157 |           ConsumeToken(); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2158 |         return; | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2159 |       } | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2160 |  | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2161 |       if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { | 
| Richard Trieu | 65ba948 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 2162 |         Diag(DeclaratorInfo.getIdentifierLoc(), | 
 | 2163 |              diag::err_function_declared_typedef); | 
| Douglas Gregor | 9ea416e | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 2164 |  | 
| Richard Smith | 6f9a445 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 2165 |         // Recover by treating the 'typedef' as spurious. | 
 | 2166 |         DS.ClearStorageClassSpecs(); | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2167 |       } | 
 | 2168 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2169 |       Decl *FunDecl = | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2170 |         ParseCXXInlineMethodDef(AS, AccessAttrs, DeclaratorInfo, TemplateInfo, | 
| Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 2171 |                                 VS, DefinitionKind, Init); | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2172 |  | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2173 |       if (FunDecl) { | 
 | 2174 |         for (unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) { | 
 | 2175 |           CommonLateParsedAttrs[i]->addDecl(FunDecl); | 
 | 2176 |         } | 
 | 2177 |         for (unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) { | 
 | 2178 |           LateParsedAttrs[i]->addDecl(FunDecl); | 
 | 2179 |         } | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2180 |       } | 
 | 2181 |       LateParsedAttrs.clear(); | 
| Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 2182 |  | 
 | 2183 |       // Consume the ';' - it's optional unless we have a delete or default | 
| Richard Trieu | 4b0e6f1 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 2184 |       if (Tok.is(tok::semi)) | 
| Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 2185 |         ConsumeExtraSemi(AfterMemberFunctionDefinition); | 
| Douglas Gregor | 9ea416e | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 2186 |  | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2187 |       return; | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2188 |     } | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2189 |   } | 
 | 2190 |  | 
 | 2191 |   // member-declarator-list: | 
 | 2192 |   //   member-declarator | 
 | 2193 |   //   member-declarator-list ',' member-declarator | 
 | 2194 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2195 |   SmallVector<Decl *, 8> DeclsInGroup; | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2196 |   ExprResult BitfieldSize; | 
| Richard Smith | 1c94c16 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 2197 |   bool ExpectSemi = true; | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2198 |  | 
 | 2199 |   while (1) { | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2200 |     // member-declarator: | 
 | 2201 |     //   declarator pure-specifier[opt] | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2202 |     //   declarator brace-or-equal-initializer[opt] | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2203 |     //   identifier[opt] ':' constant-expression | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2204 |     if (Tok.is(tok::colon)) { | 
 | 2205 |       ConsumeToken(); | 
| Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2206 |       BitfieldSize = ParseConstantExpression(); | 
 | 2207 |       if (BitfieldSize.isInvalid()) | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2208 |         SkipUntil(tok::comma, true, true); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2209 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2210 |  | 
| Chris Lattner | e656325 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 2211 |     // If a simple-asm-expr is present, parse it. | 
 | 2212 |     if (Tok.is(tok::kw_asm)) { | 
 | 2213 |       SourceLocation Loc; | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2214 |       ExprResult AsmLabel(ParseSimpleAsm(&Loc)); | 
| Chris Lattner | e656325 | 2010-06-13 05:34:18 +0000 | [diff] [blame] | 2215 |       if (AsmLabel.isInvalid()) | 
 | 2216 |         SkipUntil(tok::comma, true, true); | 
 | 2217 |   | 
 | 2218 |       DeclaratorInfo.setAsmLabel(AsmLabel.release()); | 
 | 2219 |       DeclaratorInfo.SetRangeEnd(Loc); | 
 | 2220 |     } | 
 | 2221 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2222 |     // If attributes exist after the declarator, parse them. | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2223 |     MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2224 |  | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2225 |     // FIXME: When g++ adds support for this, we'll need to check whether it | 
 | 2226 |     // goes before or after the GNU attributes and __asm__. | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2227 |     ParseOptionalCXX11VirtSpecifierSeq(VS, getCurrentClass().IsInterface); | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2228 |  | 
| Richard Smith | ca52330 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2229 |     InClassInitStyle HasInClassInit = ICIS_NoInit; | 
| Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2230 |     if ((Tok.is(tok::equal) || Tok.is(tok::l_brace)) && !HasInitializer) { | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2231 |       if (BitfieldSize.get()) { | 
 | 2232 |         Diag(Tok, diag::err_bitfield_member_init); | 
 | 2233 |         SkipUntil(tok::comma, true, true); | 
 | 2234 |       } else { | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2235 |         HasInitializer = true; | 
| Richard Smith | ca52330 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2236 |         if (!DeclaratorInfo.isDeclarationOfFunction() && | 
 | 2237 |             DeclaratorInfo.getDeclSpec().getStorageClassSpec() | 
| Richard Smith | ca52330 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2238 |               != DeclSpec::SCS_typedef) | 
 | 2239 |           HasInClassInit = Tok.is(tok::equal) ? ICIS_CopyInit : ICIS_ListInit; | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2240 |       } | 
 | 2241 |     } | 
 | 2242 |  | 
| Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2243 |     // 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] | 2244 |     // this call will *not* return the created decl; It will return null. | 
| Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2245 |     // See Sema::ActOnCXXMemberDeclarator for details. | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2246 |  | 
| Rafael Espindola | fc35cbc | 2013-01-08 20:44:06 +0000 | [diff] [blame] | 2247 |     NamedDecl *ThisDecl = 0; | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2248 |     if (DS.isFriendSpecified()) { | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2249 |       // C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains  | 
 | 2250 |       // to a friend declaration, that declaration shall be a definition. | 
 | 2251 |       // | 
 | 2252 |       // Diagnose attributes appear after friend member function declarator: | 
 | 2253 |       // foo [[]] (); | 
 | 2254 |       SmallVector<SourceRange, 4> Ranges; | 
 | 2255 |       DeclaratorInfo.getCXX11AttributeRanges(Ranges); | 
 | 2256 |       if (!Ranges.empty()) { | 
| Craig Topper | 09d19ef | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 2257 |         for (SmallVectorImpl<SourceRange>::iterator I = Ranges.begin(), | 
| Michael Han | 52b501c | 2012-11-28 23:17:40 +0000 | [diff] [blame] | 2258 |              E = Ranges.end(); I != E; ++I) { | 
 | 2259 |           Diag((*I).getBegin(), diag::err_attributes_not_allowed)  | 
 | 2260 |             << *I; | 
 | 2261 |         } | 
 | 2262 |       } | 
 | 2263 |  | 
| John McCall | bbbcdd9 | 2009-09-11 21:02:39 +0000 | [diff] [blame] | 2264 |       // TODO: handle initializers, bitfields, 'delete' | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2265 |       ThisDecl = Actions.ActOnFriendFunctionDecl(getCurScope(), DeclaratorInfo, | 
| Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2266 |                                                  TemplateParams); | 
| Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2267 |     } else { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2268 |       ThisDecl = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2269 |                                                   DeclaratorInfo, | 
| Benjamin Kramer | 3fe198b | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2270 |                                                   TemplateParams, | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2271 |                                                   BitfieldSize.release(), | 
| Richard Smith | ca52330 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2272 |                                                   VS, HasInClassInit); | 
| Larisse Voufo | ef4579c | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2273 |  | 
 | 2274 |       if (VarTemplateDecl *VT = | 
 | 2275 |               ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) : 0) | 
 | 2276 |         // Re-direct this decl to refer to the templated decl so that we can | 
 | 2277 |         // initialize it. | 
 | 2278 |         ThisDecl = VT->getTemplatedDecl(); | 
 | 2279 |  | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2280 |       if (ThisDecl && AccessAttrs) | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2281 |         Actions.ProcessDeclAttributeList(getCurScope(), ThisDecl, AccessAttrs, | 
 | 2282 |                                          false, true); | 
| Douglas Gregor | 37b372b | 2009-08-20 22:52:58 +0000 | [diff] [blame] | 2283 |     } | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2284 |  | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2285 |     // Handle the initializer. | 
| David Blaikie | 1d87fba | 2013-01-30 01:22:18 +0000 | [diff] [blame] | 2286 |     if (HasInClassInit != ICIS_NoInit && | 
 | 2287 |         DeclaratorInfo.getDeclSpec().getStorageClassSpec() != | 
 | 2288 |         DeclSpec::SCS_static) { | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2289 |       // The initializer was deferred; parse it and cache the tokens. | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2290 |       Diag(Tok, getLangOpts().CPlusPlus11 | 
 | 2291 |                     ? diag::warn_cxx98_compat_nonstatic_member_init | 
 | 2292 |                     : diag::ext_nonstatic_member_init); | 
| Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 2293 |  | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2294 |       if (DeclaratorInfo.isArrayOfUnknownBound()) { | 
| Richard Smith | ca52330 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2295 |         // C++11 [dcl.array]p3: An array bound may also be omitted when the | 
 | 2296 |         // declarator is followed by an initializer. | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2297 |         // | 
 | 2298 |         // A brace-or-equal-initializer for a member-declarator is not an | 
| David Blaikie | 3164c14 | 2012-02-14 09:00:46 +0000 | [diff] [blame] | 2299 |         // initializer in the grammar, so this is ill-formed. | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2300 |         Diag(Tok, diag::err_incomplete_array_member_init); | 
 | 2301 |         SkipUntil(tok::comma, true, true); | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2302 |  | 
 | 2303 |         // Avoid later warnings about a class member of incomplete type. | 
| David Blaikie | 3164c14 | 2012-02-14 09:00:46 +0000 | [diff] [blame] | 2304 |         if (ThisDecl) | 
| David Blaikie | 3164c14 | 2012-02-14 09:00:46 +0000 | [diff] [blame] | 2305 |           ThisDecl->setInvalidDecl(); | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2306 |       } else | 
 | 2307 |         ParseCXXNonStaticMemberInitializer(ThisDecl); | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2308 |     } else if (HasInitializer) { | 
 | 2309 |       // Normal initializer. | 
| Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2310 |       if (!Init.isUsable()) | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2311 |         Init = ParseCXXMemberInitializer( | 
 | 2312 |             ThisDecl, DeclaratorInfo.isDeclarationOfFunction(), EqualLoc); | 
 | 2313 |  | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2314 |       if (Init.isInvalid()) | 
 | 2315 |         SkipUntil(tok::comma, true, true); | 
 | 2316 |       else if (ThisDecl) | 
| Sebastian Redl | 33deb35 | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2317 |         Actions.AddInitializerToDecl(ThisDecl, Init.get(), EqualLoc.isInvalid(), | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 2318 |                                      DS.containsPlaceholderType()); | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2319 |     } else if (ThisDecl && DS.getStorageClassSpec() == DeclSpec::SCS_static) | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2320 |       // No initializer. | 
| Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 2321 |       Actions.ActOnUninitializedDecl(ThisDecl, DS.containsPlaceholderType()); | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2322 |  | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2323 |     if (ThisDecl) { | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2324 |       if (!ThisDecl->isInvalidDecl()) { | 
 | 2325 |         // Set the Decl for any late parsed attributes | 
 | 2326 |         for (unsigned i = 0, ni = CommonLateParsedAttrs.size(); i < ni; ++i) | 
 | 2327 |           CommonLateParsedAttrs[i]->addDecl(ThisDecl); | 
 | 2328 |  | 
 | 2329 |         for (unsigned i = 0, ni = LateParsedAttrs.size(); i < ni; ++i) | 
 | 2330 |           LateParsedAttrs[i]->addDecl(ThisDecl); | 
 | 2331 |       } | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2332 |       Actions.FinalizeDeclaration(ThisDecl); | 
 | 2333 |       DeclsInGroup.push_back(ThisDecl); | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2334 |  | 
 | 2335 |       if (DeclaratorInfo.isFunctionDeclarator() && | 
 | 2336 |           DeclaratorInfo.getDeclSpec().getStorageClassSpec() != | 
 | 2337 |               DeclSpec::SCS_typedef) | 
 | 2338 |         HandleMemberFunctionDeclDelays(DeclaratorInfo, ThisDecl); | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2339 |     } | 
| David Majnemer | fcbe208 | 2013-08-01 04:22:55 +0000 | [diff] [blame] | 2340 |     LateParsedAttrs.clear(); | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2341 |  | 
 | 2342 |     DeclaratorInfo.complete(ThisDecl); | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2343 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2344 |     // If we don't have a comma, it is either the end of the list (a ';') | 
 | 2345 |     // or an error, bail out. | 
 | 2346 |     if (Tok.isNot(tok::comma)) | 
 | 2347 |       break; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2348 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2349 |     // Consume the comma. | 
| Richard Smith | 1c94c16 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 2350 |     SourceLocation CommaLoc = ConsumeToken(); | 
 | 2351 |  | 
 | 2352 |     if (Tok.isAtStartOfLine() && | 
 | 2353 |         !MightBeDeclarator(Declarator::MemberContext)) { | 
 | 2354 |       // This comma was followed by a line-break and something which can't be | 
 | 2355 |       // the start of a declarator. The comma was probably a typo for a | 
 | 2356 |       // semicolon. | 
 | 2357 |       Diag(CommaLoc, diag::err_expected_semi_declaration) | 
 | 2358 |         << FixItHint::CreateReplacement(CommaLoc, ";"); | 
 | 2359 |       ExpectSemi = false; | 
 | 2360 |       break; | 
 | 2361 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2362 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2363 |     // Parse the next declarator. | 
 | 2364 |     DeclaratorInfo.clear(); | 
| Nico Weber | 4867347 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 2365 |     VS.clear(); | 
| Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 2366 |     BitfieldSize = true; | 
| Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 2367 |     Init = true; | 
 | 2368 |     HasInitializer = false; | 
| Richard Smith | 7984de3 | 2012-01-12 23:53:29 +0000 | [diff] [blame] | 2369 |     DeclaratorInfo.setCommaLoc(CommaLoc); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2370 |  | 
| Bill Wendling | ad017fa | 2012-12-20 19:22:21 +0000 | [diff] [blame] | 2371 |     // Attributes are only allowed on the second declarator. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2372 |     MaybeParseGNUAttributes(DeclaratorInfo); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2373 |  | 
| Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 2374 |     if (Tok.isNot(tok::colon)) | 
 | 2375 |       ParseDeclarator(DeclaratorInfo); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2376 |   } | 
 | 2377 |  | 
| Richard Smith | 1c94c16 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 2378 |   if (ExpectSemi && | 
 | 2379 |       ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list)) { | 
| Chris Lattner | ae50d50 | 2010-02-02 00:43:15 +0000 | [diff] [blame] | 2380 |     // Skip to end of block or statement. | 
 | 2381 |     SkipUntil(tok::r_brace, true, true); | 
 | 2382 |     // If we stopped at a ';', eat it. | 
 | 2383 |     if (Tok.is(tok::semi)) ConsumeToken(); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 2384 |     return; | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2385 |   } | 
 | 2386 |  | 
| Rafael Espindola | 4549d7f | 2013-07-09 12:05:01 +0000 | [diff] [blame] | 2387 |   Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2388 | } | 
 | 2389 |  | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2390 | /// ParseCXXMemberInitializer - Parse the brace-or-equal-initializer or | 
 | 2391 | /// pure-specifier. Also detect and reject any attempted defaulted/deleted | 
 | 2392 | /// function definition. The location of the '=', if any, will be placed in | 
 | 2393 | /// EqualLoc. | 
 | 2394 | /// | 
 | 2395 | ///   pure-specifier: | 
 | 2396 | ///     '= 0' | 
| Sebastian Redl | 33deb35 | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2397 | /// | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2398 | ///   brace-or-equal-initializer: | 
 | 2399 | ///     '=' initializer-expression | 
| Sebastian Redl | 33deb35 | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2400 | ///     braced-init-list | 
 | 2401 | /// | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2402 | ///   initializer-clause: | 
 | 2403 | ///     assignment-expression | 
| Sebastian Redl | 33deb35 | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2404 | ///     braced-init-list | 
 | 2405 | /// | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2406 | ///   defaulted/deleted function-definition:                                                                                                                                                                                                | 
 | 2407 | ///     '=' 'default' | 
 | 2408 | ///     '=' 'delete' | 
 | 2409 | /// | 
 | 2410 | /// Prior to C++0x, the assignment-expression in an initializer-clause must | 
 | 2411 | /// be a constant-expression. | 
| Douglas Gregor | 552e299 | 2012-02-21 02:22:07 +0000 | [diff] [blame] | 2412 | ExprResult Parser::ParseCXXMemberInitializer(Decl *D, bool IsFunction, | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2413 |                                              SourceLocation &EqualLoc) { | 
 | 2414 |   assert((Tok.is(tok::equal) || Tok.is(tok::l_brace)) | 
 | 2415 |          && "Data member initializer not starting with '=' or '{'"); | 
 | 2416 |  | 
| Douglas Gregor | 552e299 | 2012-02-21 02:22:07 +0000 | [diff] [blame] | 2417 |   EnterExpressionEvaluationContext Context(Actions,  | 
 | 2418 |                                            Sema::PotentiallyEvaluated, | 
 | 2419 |                                            D); | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2420 |   if (Tok.is(tok::equal)) { | 
 | 2421 |     EqualLoc = ConsumeToken(); | 
 | 2422 |     if (Tok.is(tok::kw_delete)) { | 
 | 2423 |       // In principle, an initializer of '= delete p;' is legal, but it will | 
 | 2424 |       // never type-check. It's better to diagnose it as an ill-formed expression | 
 | 2425 |       // than as an ill-formed deleted non-function member. | 
 | 2426 |       // An initializer of '= delete p, foo' will never be parsed, because | 
 | 2427 |       // a top-level comma always ends the initializer expression. | 
 | 2428 |       const Token &Next = NextToken(); | 
 | 2429 |       if (IsFunction || Next.is(tok::semi) || Next.is(tok::comma) || | 
 | 2430 |            Next.is(tok::eof)) { | 
 | 2431 |         if (IsFunction) | 
 | 2432 |           Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) | 
 | 2433 |             << 1 /* delete */; | 
 | 2434 |         else | 
 | 2435 |           Diag(ConsumeToken(), diag::err_deleted_non_function); | 
 | 2436 |         return ExprResult(); | 
 | 2437 |       } | 
 | 2438 |     } else if (Tok.is(tok::kw_default)) { | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2439 |       if (IsFunction) | 
 | 2440 |         Diag(Tok, diag::err_default_delete_in_multiple_declaration) | 
 | 2441 |           << 0 /* default */; | 
 | 2442 |       else | 
 | 2443 |         Diag(ConsumeToken(), diag::err_default_special_members); | 
 | 2444 |       return ExprResult(); | 
 | 2445 |     } | 
 | 2446 |  | 
| Sebastian Redl | 33deb35 | 2012-02-22 10:50:08 +0000 | [diff] [blame] | 2447 |   } | 
 | 2448 |   return ParseInitializer(); | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2449 | } | 
 | 2450 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2451 | /// ParseCXXMemberSpecification - Parse the class definition. | 
 | 2452 | /// | 
 | 2453 | ///       member-specification: | 
 | 2454 | ///         member-declaration member-specification[opt] | 
 | 2455 | ///         access-specifier ':' member-specification[opt] | 
 | 2456 | /// | 
| Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2457 | void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, | 
| Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 2458 |                                          SourceLocation AttrFixitLoc, | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 2459 |                                          ParsedAttributesWithRange &Attrs, | 
| Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2460 |                                          unsigned TagType, Decl *TagDecl) { | 
 | 2461 |   assert((TagType == DeclSpec::TST_struct || | 
 | 2462 |          TagType == DeclSpec::TST_interface || | 
 | 2463 |          TagType == DeclSpec::TST_union  || | 
 | 2464 |          TagType == DeclSpec::TST_class) && "Invalid TagType!"); | 
 | 2465 |  | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2466 |   PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc, | 
 | 2467 |                                       "parsing struct/union/class body"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2468 |  | 
| Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2469 |   // Determine whether this is a non-nested class. Note that local | 
 | 2470 |   // classes are *not* considered to be nested classes. | 
 | 2471 |   bool NonNestedClass = true; | 
 | 2472 |   if (!ClassStack.empty()) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2473 |     for (const Scope *S = getCurScope(); S; S = S->getParent()) { | 
| Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2474 |       if (S->isClassScope()) { | 
 | 2475 |         // We're inside a class scope, so this is a nested class. | 
 | 2476 |         NonNestedClass = false; | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2477 |  | 
 | 2478 |         // The Microsoft extension __interface does not permit nested classes. | 
 | 2479 |         if (getCurrentClass().IsInterface) { | 
 | 2480 |           Diag(RecordLoc, diag::err_invalid_member_in_interface) | 
 | 2481 |             << /*ErrorType=*/6 | 
 | 2482 |             << (isa<NamedDecl>(TagDecl) | 
 | 2483 |                   ? cast<NamedDecl>(TagDecl)->getQualifiedNameAsString() | 
 | 2484 |                   : "<anonymous>"); | 
 | 2485 |         } | 
| Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 2486 |         break; | 
 | 2487 |       } | 
 | 2488 |  | 
 | 2489 |       if ((S->getFlags() & Scope::FnScope)) { | 
 | 2490 |         // If we're in a function or function template declared in the | 
 | 2491 |         // body of a class, then this is a local class rather than a | 
 | 2492 |         // nested class. | 
 | 2493 |         const Scope *Parent = S->getParent(); | 
 | 2494 |         if (Parent->isTemplateParamScope()) | 
 | 2495 |           Parent = Parent->getParent(); | 
 | 2496 |         if (Parent->isClassScope()) | 
 | 2497 |           break; | 
 | 2498 |       } | 
 | 2499 |     } | 
 | 2500 |   } | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2501 |  | 
 | 2502 |   // Enter a scope for the class. | 
| Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 2503 |   ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2504 |  | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2505 |   // Note that we are parsing a new (potentially-nested) class definition. | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2506 |   ParsingClassDefinition ParsingDef(*this, TagDecl, NonNestedClass, | 
 | 2507 |                                     TagType == DeclSpec::TST_interface); | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2508 |  | 
| Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 2509 |   if (TagDecl) | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2510 |     Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); | 
| John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2511 |  | 
| Anders Carlsson | b184a18 | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2512 |   SourceLocation FinalLoc; | 
 | 2513 |  | 
 | 2514 |   // Parse the optional 'final' keyword. | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2515 |   if (getLangOpts().CPlusPlus && Tok.is(tok::identifier)) { | 
| Richard Smith | 4e24f0f | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 2516 |     assert(isCXX11FinalKeyword() && "not a class definition"); | 
| Richard Smith | 8b11b5e | 2011-10-15 04:21:46 +0000 | [diff] [blame] | 2517 |     FinalLoc = ConsumeToken(); | 
| Anders Carlsson | b184a18 | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2518 |  | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2519 |     if (TagType == DeclSpec::TST_interface) { | 
 | 2520 |       Diag(FinalLoc, diag::err_override_control_interface) | 
 | 2521 |         << "final"; | 
 | 2522 |     } else { | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2523 |       Diag(FinalLoc, getLangOpts().CPlusPlus11 ? | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2524 |            diag::warn_cxx98_compat_override_control_keyword : | 
 | 2525 |            diag::ext_override_control_keyword) << "final"; | 
 | 2526 |     } | 
| Michael Han | 2e39713 | 2012-11-26 22:54:45 +0000 | [diff] [blame] | 2527 |  | 
| Michael Han | 07fc1ba | 2013-01-07 16:57:11 +0000 | [diff] [blame] | 2528 |     // Parse any C++11 attributes after 'final' keyword. | 
 | 2529 |     // These attributes are not allowed to appear here, | 
 | 2530 |     // and the only possible place for them to appertain | 
 | 2531 |     // to the class would be between class-key and class-name. | 
| Richard Smith | 0532140 | 2013-02-19 23:47:15 +0000 | [diff] [blame] | 2532 |     CheckMisplacedCXX11Attribute(Attrs, AttrFixitLoc); | 
| Anders Carlsson | b184a18 | 2011-03-25 14:46:08 +0000 | [diff] [blame] | 2533 |   } | 
| Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 2534 |  | 
| John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2535 |   if (Tok.is(tok::colon)) { | 
 | 2536 |     ParseBaseClause(TagDecl); | 
 | 2537 |  | 
 | 2538 |     if (!Tok.is(tok::l_brace)) { | 
 | 2539 |       Diag(Tok, diag::err_expected_lbrace_after_base_specifiers); | 
| John McCall | db7bb4a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 2540 |  | 
 | 2541 |       if (TagDecl) | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2542 |         Actions.ActOnTagDefinitionError(getCurScope(), TagDecl); | 
| John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2543 |       return; | 
 | 2544 |     } | 
 | 2545 |   } | 
 | 2546 |  | 
 | 2547 |   assert(Tok.is(tok::l_brace)); | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2548 |   BalancedDelimiterTracker T(*this, tok::l_brace); | 
 | 2549 |   T.consumeOpen(); | 
| John McCall | bd0dfa5 | 2009-12-19 21:48:58 +0000 | [diff] [blame] | 2550 |  | 
| John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 2551 |   if (TagDecl) | 
| Anders Carlsson | 2c3ee54 | 2011-03-25 14:31:08 +0000 | [diff] [blame] | 2552 |     Actions.ActOnStartCXXMemberDeclarations(getCurScope(), TagDecl, FinalLoc, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2553 |                                             T.getOpenLocation()); | 
| John McCall | f936815 | 2009-12-20 07:58:13 +0000 | [diff] [blame] | 2554 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2555 |   // C++ 11p3: Members of a class defined with the keyword class are private | 
 | 2556 |   // by default. Members of a class defined with the keywords struct or union | 
 | 2557 |   // are public by default. | 
 | 2558 |   AccessSpecifier CurAS; | 
 | 2559 |   if (TagType == DeclSpec::TST_class) | 
 | 2560 |     CurAS = AS_private; | 
 | 2561 |   else | 
 | 2562 |     CurAS = AS_public; | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2563 |   ParsedAttributes AccessAttrs(AttrFactory); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2564 |  | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2565 |   if (TagDecl) { | 
 | 2566 |     // While we still have something to read, read the member-declarations. | 
 | 2567 |     while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { | 
 | 2568 |       // Each iteration of this loop reads one member-declaration. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2569 |  | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2570 |       if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) || | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 2571 |           Tok.is(tok::kw___if_not_exists))) { | 
 | 2572 |         ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); | 
 | 2573 |         continue; | 
 | 2574 |       } | 
 | 2575 |  | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2576 |       // Check for extraneous top-level semicolon. | 
 | 2577 |       if (Tok.is(tok::semi)) { | 
| Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 2578 |         ConsumeExtraSemi(InsideStruct, TagType); | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2579 |         continue; | 
 | 2580 |       } | 
 | 2581 |  | 
| Eli Friedman | aa5ab26 | 2012-02-23 23:47:16 +0000 | [diff] [blame] | 2582 |       if (Tok.is(tok::annot_pragma_vis)) { | 
 | 2583 |         HandlePragmaVisibility(); | 
 | 2584 |         continue; | 
 | 2585 |       } | 
 | 2586 |  | 
 | 2587 |       if (Tok.is(tok::annot_pragma_pack)) { | 
 | 2588 |         HandlePragmaPack(); | 
 | 2589 |         continue; | 
 | 2590 |       } | 
 | 2591 |  | 
| Argyrios Kyrtzidis | f4deaef | 2012-10-12 17:39:59 +0000 | [diff] [blame] | 2592 |       if (Tok.is(tok::annot_pragma_align)) { | 
 | 2593 |         HandlePragmaAlign(); | 
 | 2594 |         continue; | 
 | 2595 |       } | 
 | 2596 |  | 
| Alexey Bataev | c640058 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2597 |       if (Tok.is(tok::annot_pragma_openmp)) { | 
 | 2598 |         ParseOpenMPDeclarativeDirective(); | 
 | 2599 |         continue; | 
 | 2600 |       } | 
 | 2601 |  | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2602 |       AccessSpecifier AS = getAccessSpecifierIfPresent(); | 
 | 2603 |       if (AS != AS_none) { | 
 | 2604 |         // Current token is a C++ access specifier. | 
 | 2605 |         CurAS = AS; | 
 | 2606 |         SourceLocation ASLoc = Tok.getLocation(); | 
| David Blaikie | 13f8daf | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 2607 |         unsigned TokLength = Tok.getLength(); | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2608 |         ConsumeToken(); | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2609 |         AccessAttrs.clear(); | 
 | 2610 |         MaybeParseGNUAttributes(AccessAttrs); | 
 | 2611 |  | 
| David Blaikie | 13f8daf | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 2612 |         SourceLocation EndLoc; | 
 | 2613 |         if (Tok.is(tok::colon)) { | 
 | 2614 |           EndLoc = Tok.getLocation(); | 
 | 2615 |           ConsumeToken(); | 
 | 2616 |         } else if (Tok.is(tok::semi)) { | 
 | 2617 |           EndLoc = Tok.getLocation(); | 
 | 2618 |           ConsumeToken(); | 
 | 2619 |           Diag(EndLoc, diag::err_expected_colon)  | 
 | 2620 |             << FixItHint::CreateReplacement(EndLoc, ":"); | 
 | 2621 |         } else { | 
 | 2622 |           EndLoc = ASLoc.getLocWithOffset(TokLength); | 
 | 2623 |           Diag(EndLoc, diag::err_expected_colon)  | 
 | 2624 |             << FixItHint::CreateInsertion(EndLoc, ":"); | 
 | 2625 |         } | 
| Erik Verbruggen | c35cba4 | 2011-10-17 09:54:52 +0000 | [diff] [blame] | 2626 |  | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 2627 |         // The Microsoft extension __interface does not permit non-public | 
 | 2628 |         // access specifiers. | 
 | 2629 |         if (TagType == DeclSpec::TST_interface && CurAS != AS_public) { | 
 | 2630 |           Diag(ASLoc, diag::err_access_specifier_interface) | 
 | 2631 |             << (CurAS == AS_protected); | 
 | 2632 |         } | 
 | 2633 |  | 
| Erik Verbruggen | c35cba4 | 2011-10-17 09:54:52 +0000 | [diff] [blame] | 2634 |         if (Actions.ActOnAccessSpecifier(AS, ASLoc, EndLoc, | 
 | 2635 |                                          AccessAttrs.getList())) { | 
 | 2636 |           // found another attribute than only annotations | 
 | 2637 |           AccessAttrs.clear(); | 
 | 2638 |         } | 
 | 2639 |  | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2640 |         continue; | 
 | 2641 |       } | 
 | 2642 |  | 
 | 2643 |       // FIXME: Make sure we don't have a template here. | 
 | 2644 |  | 
 | 2645 |       // Parse all the comma separated declarators. | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 2646 |       ParseCXXClassMemberDeclaration(CurAS, AccessAttrs.getList()); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2647 |     } | 
 | 2648 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2649 |     T.consumeClose(); | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2650 |   } else { | 
 | 2651 |     SkipUntil(tok::r_brace, false, false); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2652 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2653 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2654 |   // If attributes exist after class contents, parse them. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2655 |   ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2656 |   MaybeParseGNUAttributes(attrs); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2657 |  | 
| John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 2658 |   if (TagDecl) | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2659 |     Actions.ActOnFinishCXXMemberSpecification(getCurScope(), RecordLoc, TagDecl, | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2660 |                                               T.getOpenLocation(),  | 
 | 2661 |                                               T.getCloseLocation(), | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2662 |                                               attrs.getList()); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2663 |  | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2664 |   // C++11 [class.mem]p2: | 
 | 2665 |   //   Within the class member-specification, the class is regarded as complete | 
| Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2666 |   //   within function bodies, default arguments, and | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2667 |   //   brace-or-equal-initializers for non-static data members (including such | 
 | 2668 |   //   things in nested classes). | 
| Douglas Gregor | 07976d2 | 2010-06-21 22:31:09 +0000 | [diff] [blame] | 2669 |   if (TagDecl && NonNestedClass) { | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2670 |     // 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] | 2671 |     // are complete and we can parse the delayed portions of method | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2672 |     // declarations and the lexed inline method definitions, along with any | 
 | 2673 |     // delayed attributes. | 
| Douglas Gregor | e0cc047 | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 2674 |     SourceLocation SavedPrevTokLocation = PrevTokLocation; | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 2675 |     ParseLexedAttributes(getCurrentClass()); | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2676 |     ParseLexedMethodDeclarations(getCurrentClass()); | 
| Richard Smith | a4156b8 | 2012-04-21 18:42:51 +0000 | [diff] [blame] | 2677 |  | 
 | 2678 |     // We've finished with all pending member declarations. | 
 | 2679 |     Actions.ActOnFinishCXXMemberDecls(); | 
 | 2680 |  | 
| Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2681 |     ParseLexedMemberInitializers(getCurrentClass()); | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2682 |     ParseLexedMethodDefs(getCurrentClass()); | 
| Douglas Gregor | e0cc047 | 2010-06-16 23:45:56 +0000 | [diff] [blame] | 2683 |     PrevTokLocation = SavedPrevTokLocation; | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2684 |   } | 
 | 2685 |  | 
| John McCall | 42a4f66 | 2010-05-28 08:11:17 +0000 | [diff] [blame] | 2686 |   if (TagDecl) | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2687 |     Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl,  | 
 | 2688 |                                      T.getCloseLocation()); | 
| John McCall | db7bb4a | 2010-03-17 00:38:33 +0000 | [diff] [blame] | 2689 |  | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2690 |   // Leave the class scope. | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 2691 |   ParsingDef.Pop(); | 
| Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 2692 |   ClassScope.Exit(); | 
| Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 2693 | } | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2694 |  | 
 | 2695 | /// ParseConstructorInitializer - Parse a C++ constructor initializer, | 
 | 2696 | /// which explicitly initializes the members or base classes of a | 
 | 2697 | /// class (C++ [class.base.init]). For example, the three initializers | 
 | 2698 | /// after the ':' in the Derived constructor below: | 
 | 2699 | /// | 
 | 2700 | /// @code | 
 | 2701 | /// class Base { }; | 
 | 2702 | /// class Derived : Base { | 
 | 2703 | ///   int x; | 
 | 2704 | ///   float f; | 
 | 2705 | /// public: | 
 | 2706 | ///   Derived(float f) : Base(), x(17), f(f) { } | 
 | 2707 | /// }; | 
 | 2708 | /// @endcode | 
 | 2709 | /// | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2710 | /// [C++]  ctor-initializer: | 
 | 2711 | ///          ':' mem-initializer-list | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2712 | /// | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | /// [C++]  mem-initializer-list: | 
| Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 2714 | ///          mem-initializer ...[opt] | 
 | 2715 | ///          mem-initializer ...[opt] , mem-initializer-list | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2716 | void Parser::ParseConstructorInitializer(Decl *ConstructorDecl) { | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2717 |   assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'"); | 
 | 2718 |  | 
| John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 2719 |   // Poison the SEH identifiers so they are flagged as illegal in constructor initializers | 
 | 2720 |   PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2721 |   SourceLocation ColonLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2722 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2723 |   SmallVector<CXXCtorInitializer*, 4> MemInitializers; | 
| Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 2724 |   bool AnyErrors = false; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2725 |  | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2726 |   do { | 
| Douglas Gregor | 0133f52 | 2010-08-28 00:00:50 +0000 | [diff] [blame] | 2727 |     if (Tok.is(tok::code_completion)) { | 
| Dmitri Gribenko | 572cf58 | 2013-06-23 22:58:02 +0000 | [diff] [blame] | 2728 |       Actions.CodeCompleteConstructorInitializer(ConstructorDecl, | 
 | 2729 |                                                  MemInitializers); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2730 |       return cutOffParsing(); | 
| Douglas Gregor | 0133f52 | 2010-08-28 00:00:50 +0000 | [diff] [blame] | 2731 |     } else { | 
 | 2732 |       MemInitResult MemInit = ParseMemInitializer(ConstructorDecl); | 
 | 2733 |       if (!MemInit.isInvalid()) | 
 | 2734 |         MemInitializers.push_back(MemInit.get()); | 
 | 2735 |       else | 
 | 2736 |         AnyErrors = true; | 
 | 2737 |     } | 
 | 2738 |      | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2739 |     if (Tok.is(tok::comma)) | 
 | 2740 |       ConsumeToken(); | 
 | 2741 |     else if (Tok.is(tok::l_brace)) | 
 | 2742 |       break; | 
| Douglas Gregor | b1f6fa4 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 2743 |     // If the next token looks like a base or member initializer, assume that | 
 | 2744 |     // we're just missing a comma. | 
| Douglas Gregor | 751f692 | 2010-09-07 14:51:08 +0000 | [diff] [blame] | 2745 |     else if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { | 
 | 2746 |       SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); | 
 | 2747 |       Diag(Loc, diag::err_ctor_init_missing_comma) | 
 | 2748 |         << FixItHint::CreateInsertion(Loc, ", "); | 
 | 2749 |     } else { | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2750 |       // Skip over garbage, until we get to '{'.  Don't eat the '{'. | 
| Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 2751 |       Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2752 |       SkipUntil(tok::l_brace, true, true); | 
 | 2753 |       break; | 
 | 2754 |     } | 
 | 2755 |   } while (true); | 
 | 2756 |  | 
| David Blaikie | 93c8617 | 2013-01-17 05:26:25 +0000 | [diff] [blame] | 2757 |   Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc, MemInitializers, | 
| Douglas Gregor | 9db7dbb | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 2758 |                                AnyErrors); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2759 | } | 
 | 2760 |  | 
 | 2761 | /// ParseMemInitializer - Parse a C++ member initializer, which is | 
 | 2762 | /// part of a constructor initializer that explicitly initializes one | 
 | 2763 | /// member or base class (C++ [class.base.init]). See | 
 | 2764 | /// ParseConstructorInitializer for an example. | 
 | 2765 | /// | 
 | 2766 | /// [C++] mem-initializer: | 
 | 2767 | ///         mem-initializer-id '(' expression-list[opt] ')' | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2768 | /// [C++0x] mem-initializer-id braced-init-list | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2769 | /// | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2770 | /// [C++] mem-initializer-id: | 
 | 2771 | ///         '::'[opt] nested-name-specifier[opt] class-name | 
 | 2772 | ///         identifier | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2773 | Parser::MemInitResult Parser::ParseMemInitializer(Decl *ConstructorDecl) { | 
| Fariborz Jahanian | bcfad54 | 2009-06-30 23:26:25 +0000 | [diff] [blame] | 2774 |   // parse '::'[opt] nested-name-specifier[opt] | 
 | 2775 |   CXXScopeSpec SS; | 
| Douglas Gregor | efaa93a | 2011-11-07 17:33:42 +0000 | [diff] [blame] | 2776 |   ParseOptionalCXXScopeSpecifier(SS, ParsedType(), /*EnteringContext=*/false); | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2777 |   ParsedType TemplateTypeTy; | 
| Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2778 |   if (Tok.is(tok::annot_template_id)) { | 
| Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 2779 |     TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); | 
| Douglas Gregor | d9b600c | 2010-01-12 17:52:59 +0000 | [diff] [blame] | 2780 |     if (TemplateId->Kind == TNK_Type_template || | 
 | 2781 |         TemplateId->Kind == TNK_Dependent_template_name) { | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 2782 |       AnnotateTemplateIdTokenAsType(); | 
| Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2783 |       assert(Tok.is(tok::annot_typename) && "template-id -> type failed"); | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2784 |       TemplateTypeTy = getTypeAnnotation(Tok); | 
| Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2785 |     } | 
| Fariborz Jahanian | 9617433 | 2009-07-01 19:21:19 +0000 | [diff] [blame] | 2786 |   } | 
| David Blaikie | f211662 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2787 |   // Uses of decltype will already have been converted to annot_decltype by | 
 | 2788 |   // ParseOptionalCXXScopeSpecifier at this point. | 
 | 2789 |   if (!TemplateTypeTy && Tok.isNot(tok::identifier) | 
 | 2790 |       && Tok.isNot(tok::annot_decltype)) { | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 2791 |     Diag(Tok, diag::err_expected_member_or_base_name); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2792 |     return true; | 
 | 2793 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2794 |  | 
| David Blaikie | f211662 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2795 |   IdentifierInfo *II = 0; | 
 | 2796 |   DeclSpec DS(AttrFactory); | 
 | 2797 |   SourceLocation IdLoc = Tok.getLocation(); | 
 | 2798 |   if (Tok.is(tok::annot_decltype)) { | 
 | 2799 |     // Get the decltype expression, if there is one. | 
 | 2800 |     ParseDecltypeSpecifier(DS); | 
 | 2801 |   } else { | 
 | 2802 |     if (Tok.is(tok::identifier)) | 
 | 2803 |       // Get the identifier. This may be a member name or a class name, | 
 | 2804 |       // but we'll let the semantic analysis determine which it is. | 
 | 2805 |       II = Tok.getIdentifierInfo(); | 
 | 2806 |     ConsumeToken(); | 
 | 2807 |   } | 
 | 2808 |  | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2809 |  | 
 | 2810 |   // Parse the '('. | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2811 |   if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { | 
| Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 2812 |     Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); | 
 | 2813 |  | 
| Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 2814 |     ExprResult InitList = ParseBraceInitializer(); | 
 | 2815 |     if (InitList.isInvalid()) | 
 | 2816 |       return true; | 
 | 2817 |  | 
 | 2818 |     SourceLocation EllipsisLoc; | 
 | 2819 |     if (Tok.is(tok::ellipsis)) | 
 | 2820 |       EllipsisLoc = ConsumeToken(); | 
 | 2821 |  | 
 | 2822 |     return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, | 
| David Blaikie | f211662 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2823 |                                        TemplateTypeTy, DS, IdLoc,  | 
 | 2824 |                                        InitList.take(), EllipsisLoc); | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2825 |   } else if(Tok.is(tok::l_paren)) { | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2826 |     BalancedDelimiterTracker T(*this, tok::l_paren); | 
 | 2827 |     T.consumeOpen(); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2828 |  | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2829 |     // Parse the optional expression-list. | 
| Benjamin Kramer | 4e28d9e | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2830 |     ExprVector ArgExprs; | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2831 |     CommaLocsTy CommaLocs; | 
 | 2832 |     if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) { | 
 | 2833 |       SkipUntil(tok::r_paren); | 
 | 2834 |       return true; | 
 | 2835 |     } | 
 | 2836 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2837 |     T.consumeClose(); | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2838 |  | 
 | 2839 |     SourceLocation EllipsisLoc; | 
 | 2840 |     if (Tok.is(tok::ellipsis)) | 
 | 2841 |       EllipsisLoc = ConsumeToken(); | 
 | 2842 |  | 
 | 2843 |     return Actions.ActOnMemInitializer(ConstructorDecl, getCurScope(), SS, II, | 
| David Blaikie | f211662 | 2012-01-24 06:03:59 +0000 | [diff] [blame] | 2844 |                                        TemplateTypeTy, DS, IdLoc, | 
| Dmitri Gribenko | a36bbac | 2013-05-09 23:51:52 +0000 | [diff] [blame] | 2845 |                                        T.getOpenLocation(), ArgExprs, | 
 | 2846 |                                        T.getCloseLocation(), EllipsisLoc); | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2847 |   } | 
 | 2848 |  | 
| Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 2849 |   Diag(Tok, getLangOpts().CPlusPlus11 ? diag::err_expected_lparen_or_lbrace | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 2850 |                                   : diag::err_expected_lparen); | 
 | 2851 |   return true; | 
| Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 2852 | } | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2853 |  | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2854 | /// \brief Parse a C++ exception-specification if present (C++0x [except.spec]). | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2855 | /// | 
| Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2856 | ///       exception-specification: | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2857 | ///         dynamic-exception-specification | 
 | 2858 | ///         noexcept-specification | 
 | 2859 | /// | 
 | 2860 | ///       noexcept-specification: | 
 | 2861 | ///         'noexcept' | 
 | 2862 | ///         'noexcept' '(' constant-expression ')' | 
 | 2863 | ExceptionSpecificationType | 
| Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2864 | Parser::tryParseExceptionSpecification( | 
| Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 2865 |                     SourceRange &SpecificationRange, | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2866 |                     SmallVectorImpl<ParsedType> &DynamicExceptions, | 
 | 2867 |                     SmallVectorImpl<SourceRange> &DynamicExceptionRanges, | 
| Richard Smith | a058fd4 | 2012-05-02 22:22:32 +0000 | [diff] [blame] | 2868 |                     ExprResult &NoexceptExpr) { | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2869 |   ExceptionSpecificationType Result = EST_None; | 
 | 2870 |  | 
 | 2871 |   // See if there's a dynamic specification. | 
 | 2872 |   if (Tok.is(tok::kw_throw)) { | 
 | 2873 |     Result = ParseDynamicExceptionSpecification(SpecificationRange, | 
 | 2874 |                                                 DynamicExceptions, | 
 | 2875 |                                                 DynamicExceptionRanges); | 
 | 2876 |     assert(DynamicExceptions.size() == DynamicExceptionRanges.size() && | 
 | 2877 |            "Produced different number of exception types and ranges."); | 
 | 2878 |   } | 
 | 2879 |  | 
 | 2880 |   // If there's no noexcept specification, we're done. | 
 | 2881 |   if (Tok.isNot(tok::kw_noexcept)) | 
 | 2882 |     return Result; | 
 | 2883 |  | 
| Richard Smith | 841804b | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 2884 |   Diag(Tok, diag::warn_cxx98_compat_noexcept_decl); | 
 | 2885 |  | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2886 |   // If we already had a dynamic specification, parse the noexcept for, | 
 | 2887 |   // recovery, but emit a diagnostic and don't store the results. | 
 | 2888 |   SourceRange NoexceptRange; | 
 | 2889 |   ExceptionSpecificationType NoexceptType = EST_None; | 
 | 2890 |  | 
 | 2891 |   SourceLocation KeywordLoc = ConsumeToken(); | 
 | 2892 |   if (Tok.is(tok::l_paren)) { | 
 | 2893 |     // There is an argument. | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2894 |     BalancedDelimiterTracker T(*this, tok::l_paren); | 
 | 2895 |     T.consumeOpen(); | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2896 |     NoexceptType = EST_ComputedNoexcept; | 
 | 2897 |     NoexceptExpr = ParseConstantExpression(); | 
| Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2898 |     // The argument must be contextually convertible to bool. We use | 
 | 2899 |     // ActOnBooleanCondition for this purpose. | 
 | 2900 |     if (!NoexceptExpr.isInvalid()) | 
 | 2901 |       NoexceptExpr = Actions.ActOnBooleanCondition(getCurScope(), KeywordLoc, | 
 | 2902 |                                                    NoexceptExpr.get()); | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2903 |     T.consumeClose(); | 
 | 2904 |     NoexceptRange = SourceRange(KeywordLoc, T.getCloseLocation()); | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2905 |   } else { | 
 | 2906 |     // There is no argument. | 
 | 2907 |     NoexceptType = EST_BasicNoexcept; | 
 | 2908 |     NoexceptRange = SourceRange(KeywordLoc, KeywordLoc); | 
 | 2909 |   } | 
 | 2910 |  | 
 | 2911 |   if (Result == EST_None) { | 
 | 2912 |     SpecificationRange = NoexceptRange; | 
 | 2913 |     Result = NoexceptType; | 
 | 2914 |  | 
 | 2915 |     // If there's a dynamic specification after a noexcept specification, | 
 | 2916 |     // parse that and ignore the results. | 
 | 2917 |     if (Tok.is(tok::kw_throw)) { | 
 | 2918 |       Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); | 
 | 2919 |       ParseDynamicExceptionSpecification(NoexceptRange, DynamicExceptions, | 
 | 2920 |                                          DynamicExceptionRanges); | 
 | 2921 |     } | 
 | 2922 |   } else { | 
 | 2923 |     Diag(Tok.getLocation(), diag::err_dynamic_and_noexcept_specification); | 
 | 2924 |   } | 
 | 2925 |  | 
 | 2926 |   return Result; | 
 | 2927 | } | 
 | 2928 |  | 
| Richard Smith | 79f4bb7 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 2929 | static void diagnoseDynamicExceptionSpecification( | 
 | 2930 |     Parser &P, const SourceRange &Range, bool IsNoexcept) { | 
 | 2931 |   if (P.getLangOpts().CPlusPlus11) { | 
 | 2932 |     const char *Replacement = IsNoexcept ? "noexcept" : "noexcept(false)"; | 
 | 2933 |     P.Diag(Range.getBegin(), diag::warn_exception_spec_deprecated) << Range; | 
 | 2934 |     P.Diag(Range.getBegin(), diag::note_exception_spec_deprecated) | 
 | 2935 |       << Replacement << FixItHint::CreateReplacement(Range, Replacement); | 
 | 2936 |   } | 
 | 2937 | } | 
 | 2938 |  | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2939 | /// ParseDynamicExceptionSpecification - Parse a C++ | 
 | 2940 | /// dynamic-exception-specification (C++ [except.spec]). | 
 | 2941 | /// | 
 | 2942 | ///       dynamic-exception-specification: | 
| Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2943 | ///         'throw' '(' type-id-list [opt] ')' | 
 | 2944 | /// [MS]    'throw' '(' '...' ')' | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2945 | /// | 
| Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2946 | ///       type-id-list: | 
| Douglas Gregor | a04426c | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2947 | ///         type-id ... [opt] | 
 | 2948 | ///         type-id-list ',' type-id ... [opt] | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2949 | /// | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2950 | ExceptionSpecificationType Parser::ParseDynamicExceptionSpecification( | 
 | 2951 |                                   SourceRange &SpecificationRange, | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2952 |                                   SmallVectorImpl<ParsedType> &Exceptions, | 
 | 2953 |                                   SmallVectorImpl<SourceRange> &Ranges) { | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2954 |   assert(Tok.is(tok::kw_throw) && "expected throw"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2955 |  | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2956 |   SpecificationRange.setBegin(ConsumeToken()); | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2957 |   BalancedDelimiterTracker T(*this, tok::l_paren); | 
 | 2958 |   if (T.consumeOpen()) { | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2959 |     Diag(Tok, diag::err_expected_lparen_after) << "throw"; | 
 | 2960 |     SpecificationRange.setEnd(SpecificationRange.getBegin()); | 
| Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2961 |     return EST_DynamicNone; | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2962 |   } | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2963 |  | 
| Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2964 |   // Parse throw(...), a Microsoft extension that means "this function | 
 | 2965 |   // can throw anything". | 
 | 2966 |   if (Tok.is(tok::ellipsis)) { | 
 | 2967 |     SourceLocation EllipsisLoc = ConsumeToken(); | 
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2968 |     if (!getLangOpts().MicrosoftExt) | 
| Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2969 |       Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec); | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2970 |     T.consumeClose(); | 
 | 2971 |     SpecificationRange.setEnd(T.getCloseLocation()); | 
| Richard Smith | 79f4bb7 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 2972 |     diagnoseDynamicExceptionSpecification(*this, SpecificationRange, false); | 
| Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 2973 |     return EST_MSAny; | 
| Douglas Gregor | a474561 | 2008-12-01 18:00:20 +0000 | [diff] [blame] | 2974 |   } | 
 | 2975 |  | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2976 |   // Parse the sequence of type-ids. | 
| Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2977 |   SourceRange Range; | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2978 |   while (Tok.isNot(tok::r_paren)) { | 
| Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2979 |     TypeResult Res(ParseTypeName(&Range)); | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2980 |  | 
| Douglas Gregor | a04426c | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2981 |     if (Tok.is(tok::ellipsis)) { | 
 | 2982 |       // C++0x [temp.variadic]p5: | 
 | 2983 |       //   - In a dynamic-exception-specification (15.4); the pattern is a  | 
 | 2984 |       //     type-id. | 
 | 2985 |       SourceLocation Ellipsis = ConsumeToken(); | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2986 |       Range.setEnd(Ellipsis); | 
| Douglas Gregor | a04426c | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2987 |       if (!Res.isInvalid()) | 
 | 2988 |         Res = Actions.ActOnPackExpansion(Res.get(), Ellipsis); | 
 | 2989 |     } | 
| Sebastian Redl | 7acafd0 | 2011-03-05 14:45:16 +0000 | [diff] [blame] | 2990 |  | 
| Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2991 |     if (!Res.isInvalid()) { | 
| Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 2992 |       Exceptions.push_back(Res.get()); | 
| Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 2993 |       Ranges.push_back(Range); | 
 | 2994 |     } | 
| Douglas Gregor | a04426c | 2010-12-20 23:57:46 +0000 | [diff] [blame] | 2995 |      | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2996 |     if (Tok.is(tok::comma)) | 
 | 2997 |       ConsumeToken(); | 
| Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 2998 |     else | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 2999 |       break; | 
 | 3000 |   } | 
 | 3001 |  | 
| Douglas Gregor | 4a8dfb5 | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 3002 |   T.consumeClose(); | 
 | 3003 |   SpecificationRange.setEnd(T.getCloseLocation()); | 
| Richard Smith | 79f4bb7 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 3004 |   diagnoseDynamicExceptionSpecification(*this, SpecificationRange, | 
 | 3005 |                                         Exceptions.empty()); | 
| Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3006 |   return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic; | 
| Douglas Gregor | 0fe7bea | 2008-11-25 03:22:00 +0000 | [diff] [blame] | 3007 | } | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3008 |  | 
| Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3009 | /// ParseTrailingReturnType - Parse a trailing return type on a new-style | 
 | 3010 | /// function declaration. | 
| Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 3011 | TypeResult Parser::ParseTrailingReturnType(SourceRange &Range) { | 
| Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3012 |   assert(Tok.is(tok::arrow) && "expected arrow"); | 
 | 3013 |  | 
 | 3014 |   ConsumeToken(); | 
 | 3015 |  | 
| Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 3016 |   return ParseTypeName(&Range, Declarator::TrailingReturnContext); | 
| Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3017 | } | 
 | 3018 |  | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3019 | /// \brief We have just started parsing the definition of a new class, | 
 | 3020 | /// so push that class onto our stack of classes that is currently | 
 | 3021 | /// being parsed. | 
| John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3022 | Sema::ParsingClassState | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 3023 | Parser::PushParsingClass(Decl *ClassDecl, bool NonNestedClass, | 
 | 3024 |                          bool IsInterface) { | 
| Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 3025 |   assert((NonNestedClass || !ClassStack.empty()) && | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3026 |          "Nested class without outer class"); | 
| John McCall | e402e72 | 2012-09-25 07:32:39 +0000 | [diff] [blame] | 3027 |   ClassStack.push(new ParsingClass(ClassDecl, NonNestedClass, IsInterface)); | 
| John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3028 |   return Actions.PushParsingClass(); | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3029 | } | 
 | 3030 |  | 
 | 3031 | /// \brief Deallocate the given parsed class and all of its nested | 
 | 3032 | /// classes. | 
 | 3033 | void Parser::DeallocateParsedClasses(Parser::ParsingClass *Class) { | 
| Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3034 |   for (unsigned I = 0, N = Class->LateParsedDeclarations.size(); I != N; ++I) | 
 | 3035 |     delete Class->LateParsedDeclarations[I]; | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3036 |   delete Class; | 
 | 3037 | } | 
 | 3038 |  | 
 | 3039 | /// \brief Pop the top class of the stack of classes that are | 
 | 3040 | /// currently being parsed. | 
 | 3041 | /// | 
 | 3042 | /// This routine should be called when we have finished parsing the | 
 | 3043 | /// definition of a class, but have not yet popped the Scope | 
 | 3044 | /// associated with the class's definition. | 
| John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3045 | void Parser::PopParsingClass(Sema::ParsingClassState state) { | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3046 |   assert(!ClassStack.empty() && "Mismatched push/pop for class parsing"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3047 |  | 
| John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 3048 |   Actions.PopParsingClass(state); | 
 | 3049 |  | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3050 |   ParsingClass *Victim = ClassStack.top(); | 
 | 3051 |   ClassStack.pop(); | 
 | 3052 |   if (Victim->TopLevelClass) { | 
 | 3053 |     // Deallocate all of the nested classes of this class, | 
 | 3054 |     // recursively: we don't need to keep any of this information. | 
 | 3055 |     DeallocateParsedClasses(Victim); | 
 | 3056 |     return; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 |   } | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3058 |   assert(!ClassStack.empty() && "Missing top-level class?"); | 
 | 3059 |  | 
| Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3060 |   if (Victim->LateParsedDeclarations.empty()) { | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3061 |     // The victim is a nested class, but we will not need to perform | 
 | 3062 |     // any processing after the definition of this class since it has | 
 | 3063 |     // no members whose handling was delayed. Therefore, we can just | 
 | 3064 |     // remove this nested class. | 
| Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3065 |     DeallocateParsedClasses(Victim); | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3066 |     return; | 
 | 3067 |   } | 
 | 3068 |  | 
 | 3069 |   // This nested class has some members that will need to be processed | 
 | 3070 |   // after the top-level class is completely defined. Therefore, add | 
 | 3071 |   // it to the list of nested classes within its parent. | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3072 |   assert(getCurScope()->isClassScope() && "Nested class outside of class scope?"); | 
| Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 3073 |   ClassStack.top()->LateParsedDeclarations.push_back(new LateParsedClass(this, Victim)); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3074 |   Victim->TemplateScope = getCurScope()->getParent()->isTemplateParamScope(); | 
| Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 3075 | } | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3076 |  | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3077 | /// \brief Try to parse an 'identifier' which appears within an attribute-token. | 
 | 3078 | /// | 
 | 3079 | /// \return the parsed identifier on success, and 0 if the next token is not an | 
 | 3080 | /// attribute-token. | 
 | 3081 | /// | 
 | 3082 | /// C++11 [dcl.attr.grammar]p3: | 
 | 3083 | ///   If a keyword or an alternative token that satisfies the syntactic | 
 | 3084 | ///   requirements of an identifier is contained in an attribute-token, | 
 | 3085 | ///   it is considered an identifier. | 
 | 3086 | IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc) { | 
 | 3087 |   switch (Tok.getKind()) { | 
 | 3088 |   default: | 
 | 3089 |     // Identifiers and keywords have identifier info attached. | 
 | 3090 |     if (IdentifierInfo *II = Tok.getIdentifierInfo()) { | 
 | 3091 |       Loc = ConsumeToken(); | 
 | 3092 |       return II; | 
 | 3093 |     } | 
 | 3094 |     return 0; | 
 | 3095 |  | 
 | 3096 |   case tok::ampamp:       // 'and' | 
 | 3097 |   case tok::pipe:         // 'bitor' | 
 | 3098 |   case tok::pipepipe:     // 'or' | 
 | 3099 |   case tok::caret:        // 'xor' | 
 | 3100 |   case tok::tilde:        // 'compl' | 
 | 3101 |   case tok::amp:          // 'bitand' | 
 | 3102 |   case tok::ampequal:     // 'and_eq' | 
 | 3103 |   case tok::pipeequal:    // 'or_eq' | 
 | 3104 |   case tok::caretequal:   // 'xor_eq' | 
 | 3105 |   case tok::exclaim:      // 'not' | 
 | 3106 |   case tok::exclaimequal: // 'not_eq' | 
 | 3107 |     // Alternative tokens do not have identifier info, but their spelling | 
 | 3108 |     // starts with an alphabetical character. | 
| Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3109 |     SmallString<8> SpellingBuf; | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3110 |     StringRef Spelling = PP.getSpelling(Tok.getLocation(), SpellingBuf); | 
| Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 3111 |     if (isLetter(Spelling[0])) { | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3112 |       Loc = ConsumeToken(); | 
| Benjamin Kramer | 0eb7526 | 2012-04-22 20:43:30 +0000 | [diff] [blame] | 3113 |       return &PP.getIdentifierTable().get(Spelling); | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3114 |     } | 
 | 3115 |     return 0; | 
 | 3116 |   } | 
 | 3117 | } | 
 | 3118 |  | 
| Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3119 | static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, | 
 | 3120 |                                                IdentifierInfo *ScopeName) { | 
 | 3121 |   switch (AttributeList::getKind(AttrName, ScopeName, | 
 | 3122 |                                  AttributeList::AS_CXX11)) { | 
 | 3123 |   case AttributeList::AT_CarriesDependency: | 
 | 3124 |   case AttributeList::AT_FallThrough: | 
| Richard Smith | cd8ab51 | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 3125 |   case AttributeList::AT_CXX11NoReturn: { | 
| Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3126 |     return true; | 
 | 3127 |   } | 
 | 3128 |  | 
 | 3129 |   default: | 
 | 3130 |     return false; | 
 | 3131 |   } | 
 | 3132 | } | 
 | 3133 |  | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3134 | /// ParseCXX11AttributeSpecifier - Parse a C++11 attribute-specifier. Currently | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3135 | /// only parses standard attributes. | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3136 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3137 | /// [C++11] attribute-specifier: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3138 | ///         '[' '[' attribute-list ']' ']' | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3139 | ///         alignment-specifier | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3140 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3141 | /// [C++11] attribute-list: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3142 | ///         attribute[opt] | 
 | 3143 | ///         attribute-list ',' attribute[opt] | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3144 | ///         attribute '...' | 
 | 3145 | ///         attribute-list ',' attribute '...' | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3146 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3147 | /// [C++11] attribute: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3148 | ///         attribute-token attribute-argument-clause[opt] | 
 | 3149 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3150 | /// [C++11] attribute-token: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3151 | ///         identifier | 
 | 3152 | ///         attribute-scoped-token | 
 | 3153 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3154 | /// [C++11] attribute-scoped-token: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3155 | ///         attribute-namespace '::' identifier | 
 | 3156 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3157 | /// [C++11] attribute-namespace: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3158 | ///         identifier | 
 | 3159 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3160 | /// [C++11] attribute-argument-clause: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3161 | ///         '(' balanced-token-seq ')' | 
 | 3162 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3163 | /// [C++11] balanced-token-seq: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3164 | ///         balanced-token | 
 | 3165 | ///         balanced-token-seq balanced-token | 
 | 3166 | /// | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3167 | /// [C++11] balanced-token: | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3168 | ///         '(' balanced-token-seq ')' | 
 | 3169 | ///         '[' balanced-token-seq ']' | 
 | 3170 | ///         '{' balanced-token-seq '}' | 
 | 3171 | ///         any token but '(', ')', '[', ']', '{', or '}' | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3172 | void Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs, | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3173 |                                           SourceLocation *endLoc) { | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3174 |   if (Tok.is(tok::kw_alignas)) { | 
| Richard Smith | 41be673 | 2011-10-14 20:48:27 +0000 | [diff] [blame] | 3175 |     Diag(Tok.getLocation(), diag::warn_cxx98_compat_alignas); | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3176 |     ParseAlignmentSpecifier(attrs, endLoc); | 
 | 3177 |     return; | 
 | 3178 |   } | 
 | 3179 |  | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3180 |   assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square) | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3181 |       && "Not a C++11 attribute list"); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3182 |  | 
| Richard Smith | 41be673 | 2011-10-14 20:48:27 +0000 | [diff] [blame] | 3183 |   Diag(Tok.getLocation(), diag::warn_cxx98_compat_attribute); | 
 | 3184 |  | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3185 |   ConsumeBracket(); | 
 | 3186 |   ConsumeBracket(); | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 3187 |  | 
| Richard Smith | cd8ab51 | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 3188 |   llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs; | 
 | 3189 |  | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3190 |   while (Tok.isNot(tok::r_square)) { | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3191 |     // attribute not present | 
 | 3192 |     if (Tok.is(tok::comma)) { | 
 | 3193 |       ConsumeToken(); | 
 | 3194 |       continue; | 
 | 3195 |     } | 
 | 3196 |  | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3197 |     SourceLocation ScopeLoc, AttrLoc; | 
 | 3198 |     IdentifierInfo *ScopeName = 0, *AttrName = 0; | 
 | 3199 |  | 
 | 3200 |     AttrName = TryParseCXX11AttributeIdentifier(AttrLoc); | 
 | 3201 |     if (!AttrName) | 
 | 3202 |       // Break out to the "expected ']'" diagnostic. | 
 | 3203 |       break; | 
| Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 3204 |  | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3205 |     // scoped attribute | 
 | 3206 |     if (Tok.is(tok::coloncolon)) { | 
 | 3207 |       ConsumeToken(); | 
 | 3208 |  | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3209 |       ScopeName = AttrName; | 
 | 3210 |       ScopeLoc = AttrLoc; | 
 | 3211 |  | 
 | 3212 |       AttrName = TryParseCXX11AttributeIdentifier(AttrLoc); | 
 | 3213 |       if (!AttrName) { | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3214 |         Diag(Tok.getLocation(), diag::err_expected_ident); | 
 | 3215 |         SkipUntil(tok::r_square, tok::comma, true, true); | 
 | 3216 |         continue; | 
 | 3217 |       } | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3218 |     } | 
 | 3219 |  | 
| Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3220 |     bool StandardAttr = IsBuiltInOrStandardCXX11Attribute(AttrName,ScopeName); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3221 |     bool AttrParsed = false; | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3222 |  | 
| Richard Smith | cd8ab51 | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 3223 |     if (StandardAttr && | 
 | 3224 |         !SeenAttrs.insert(std::make_pair(AttrName, AttrLoc)).second) | 
 | 3225 |       Diag(AttrLoc, diag::err_cxx11_attribute_repeated) | 
 | 3226 |         << AttrName << SourceRange(SeenAttrs[AttrName]); | 
 | 3227 |  | 
| Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3228 |     // Parse attribute arguments | 
 | 3229 |     if (Tok.is(tok::l_paren)) { | 
 | 3230 |       if (ScopeName && ScopeName->getName() == "gnu") { | 
 | 3231 |         ParseGNUAttributeArgs(AttrName, AttrLoc, attrs, endLoc, | 
 | 3232 |                               ScopeName, ScopeLoc, AttributeList::AS_CXX11); | 
 | 3233 |         AttrParsed = true; | 
 | 3234 |       } else { | 
 | 3235 |         if (StandardAttr) | 
 | 3236 |           Diag(Tok.getLocation(), diag::err_cxx11_attribute_forbids_arguments) | 
 | 3237 |             << AttrName->getName(); | 
 | 3238 |  | 
 | 3239 |         // FIXME: handle other formats of c++11 attribute arguments | 
 | 3240 |         ConsumeParen(); | 
 | 3241 |         SkipUntil(tok::r_paren, false); | 
 | 3242 |       } | 
 | 3243 |     } | 
 | 3244 |  | 
 | 3245 |     if (!AttrParsed) | 
| Richard Smith | e0d3b4c | 2012-05-03 18:27:39 +0000 | [diff] [blame] | 3246 |       attrs.addNew(AttrName, | 
 | 3247 |                    SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrLoc, | 
 | 3248 |                                AttrLoc), | 
 | 3249 |                    ScopeName, ScopeLoc, 0, | 
| Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame] | 3250 |                    SourceLocation(), 0, 0, AttributeList::AS_CXX11); | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3251 |  | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3252 |     if (Tok.is(tok::ellipsis)) { | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3253 |       ConsumeToken(); | 
| Michael Han | 6880f49 | 2012-10-03 01:56:22 +0000 | [diff] [blame] | 3254 |  | 
 | 3255 |       Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) | 
 | 3256 |         << AttrName->getName(); | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3257 |     } | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3258 |   } | 
 | 3259 |  | 
 | 3260 |   if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) | 
 | 3261 |     SkipUntil(tok::r_square, false); | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3262 |   if (endLoc) | 
 | 3263 |     *endLoc = Tok.getLocation(); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3264 |   if (ExpectAndConsume(tok::r_square, diag::err_expected_rsquare)) | 
 | 3265 |     SkipUntil(tok::r_square, false); | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3266 | } | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3267 |  | 
| Sean Hunt | 2edf0a2 | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 3268 | /// ParseCXX11Attributes - Parse a C++11 attribute-specifier-seq. | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3269 | /// | 
 | 3270 | /// attribute-specifier-seq: | 
 | 3271 | ///       attribute-specifier-seq[opt] attribute-specifier | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3272 | void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs, | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3273 |                                   SourceLocation *endLoc) { | 
| Richard Smith | 672edb0 | 2013-02-22 09:15:49 +0000 | [diff] [blame] | 3274 |   assert(getLangOpts().CPlusPlus11); | 
 | 3275 |  | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3276 |   SourceLocation StartLoc = Tok.getLocation(), Loc; | 
 | 3277 |   if (!endLoc) | 
 | 3278 |     endLoc = &Loc; | 
 | 3279 |  | 
| Douglas Gregor | 8828ee7 | 2011-10-07 20:35:25 +0000 | [diff] [blame] | 3280 |   do { | 
| Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame] | 3281 |     ParseCXX11AttributeSpecifier(attrs, endLoc); | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3282 |   } while (isCXX11AttributeSpecifier()); | 
| Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 3283 |  | 
 | 3284 |   attrs.Range = SourceRange(StartLoc, *endLoc); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3285 | } | 
 | 3286 |  | 
| Francois Pichet | 334d47e | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3287 | /// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr] | 
 | 3288 | /// | 
 | 3289 | /// [MS] ms-attribute: | 
 | 3290 | ///             '[' token-seq ']' | 
 | 3291 | /// | 
 | 3292 | /// [MS] ms-attribute-seq: | 
 | 3293 | ///             ms-attribute[opt] | 
 | 3294 | ///             ms-attribute ms-attribute-seq | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3295 | void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs, | 
 | 3296 |                                       SourceLocation *endLoc) { | 
| Francois Pichet | 334d47e | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3297 |   assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list"); | 
 | 3298 |  | 
 | 3299 |   while (Tok.is(tok::l_square)) { | 
| Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 3300 |     // FIXME: If this is actually a C++11 attribute, parse it as one. | 
| Francois Pichet | 334d47e | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3301 |     ConsumeBracket(); | 
 | 3302 |     SkipUntil(tok::r_square, true, true); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3303 |     if (endLoc) *endLoc = Tok.getLocation(); | 
| Francois Pichet | 334d47e | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 3304 |     ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); | 
 | 3305 |   } | 
 | 3306 | } | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3307 |  | 
 | 3308 | void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType, | 
 | 3309 |                                                     AccessSpecifier& CurAS) { | 
| Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3310 |   IfExistsCondition Result; | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3311 |   if (ParseMicrosoftIfExistsCondition(Result)) | 
 | 3312 |     return; | 
 | 3313 |    | 
| Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3314 |   BalancedDelimiterTracker Braces(*this, tok::l_brace); | 
 | 3315 |   if (Braces.consumeOpen()) { | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3316 |     Diag(Tok, diag::err_expected_lbrace); | 
 | 3317 |     return; | 
 | 3318 |   } | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3319 |  | 
| Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3320 |   switch (Result.Behavior) { | 
 | 3321 |   case IEB_Parse: | 
 | 3322 |     // Parse the declarations below. | 
 | 3323 |     break; | 
 | 3324 |          | 
 | 3325 |   case IEB_Dependent: | 
 | 3326 |     Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists) | 
 | 3327 |       << Result.IsIfExists; | 
 | 3328 |     // Fall through to skip. | 
 | 3329 |        | 
 | 3330 |   case IEB_Skip: | 
 | 3331 |     Braces.skipToEnd(); | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3332 |     return; | 
 | 3333 |   } | 
 | 3334 |  | 
| Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3335 |   while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3336 |     // __if_exists, __if_not_exists can nest. | 
 | 3337 |     if ((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists))) { | 
 | 3338 |       ParseMicrosoftIfExistsClassDeclaration((DeclSpec::TST)TagType, CurAS); | 
 | 3339 |       continue; | 
 | 3340 |     } | 
 | 3341 |  | 
 | 3342 |     // Check for extraneous top-level semicolon. | 
 | 3343 |     if (Tok.is(tok::semi)) { | 
| Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 3344 |       ConsumeExtraSemi(InsideStruct, TagType); | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3345 |       continue; | 
 | 3346 |     } | 
 | 3347 |  | 
 | 3348 |     AccessSpecifier AS = getAccessSpecifierIfPresent(); | 
 | 3349 |     if (AS != AS_none) { | 
 | 3350 |       // Current token is a C++ access specifier. | 
 | 3351 |       CurAS = AS; | 
 | 3352 |       SourceLocation ASLoc = Tok.getLocation(); | 
 | 3353 |       ConsumeToken(); | 
 | 3354 |       if (Tok.is(tok::colon)) | 
 | 3355 |         Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation()); | 
 | 3356 |       else | 
 | 3357 |         Diag(Tok, diag::err_expected_colon); | 
 | 3358 |       ConsumeToken(); | 
 | 3359 |       continue; | 
 | 3360 |     } | 
 | 3361 |  | 
 | 3362 |     // Parse all the comma separated declarators. | 
| Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 3363 |     ParseCXXClassMemberDeclaration(CurAS, 0); | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3364 |   } | 
| Douglas Gregor | 3896fc5 | 2011-10-24 22:31:10 +0000 | [diff] [blame] | 3365 |    | 
 | 3366 |   Braces.consumeClose(); | 
| Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 3367 | } |