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