| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- ParseDecl.cpp - 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. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // | 
 | 8 | //===----------------------------------------------------------------------===// | 
 | 9 | // | 
 | 10 | //  This file implements the Declaration portions of the Parser interfaces. | 
 | 11 | // | 
 | 12 | //===----------------------------------------------------------------------===// | 
 | 13 |  | 
 | 14 | #include "clang/Parse/Parser.h" | 
| Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 15 | #include "clang/Parse/ParseDiagnostic.h" | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 16 | #include "clang/Basic/OpenCL.h" | 
| John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/Scope.h" | 
 | 18 | #include "clang/Sema/ParsedTemplate.h" | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 19 | #include "clang/Sema/PrettyDeclStackTrace.h" | 
| Chris Lattner | d167ca0 | 2009-12-10 00:21:05 +0000 | [diff] [blame] | 20 | #include "RAIIObjectsForParser.h" | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallSet.h" | 
| Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringSwitch.h" | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 23 | using namespace clang; | 
 | 24 |  | 
 | 25 | //===----------------------------------------------------------------------===// | 
 | 26 | // C99 6.7: Declarations. | 
 | 27 | //===----------------------------------------------------------------------===// | 
 | 28 |  | 
 | 29 | /// ParseTypeName | 
 | 30 | ///       type-name: [C99 6.7.6] | 
 | 31 | ///         specifier-qualifier-list abstract-declarator[opt] | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 32 | /// | 
 | 33 | /// Called type-id in C++. | 
| Douglas Gregor | 683a81f | 2011-01-31 16:09:46 +0000 | [diff] [blame] | 34 | TypeResult Parser::ParseTypeName(SourceRange *Range, | 
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 35 |                                  Declarator::TheContext Context, | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 36 |                                  AccessSpecifier AS, | 
 | 37 |                                  Decl **OwnedType) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 38 |   // Parse the common declaration-specifiers piece. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 39 |   DeclSpec DS(AttrFactory); | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 40 |   ParseSpecifierQualifierList(DS, AS); | 
 | 41 |   if (OwnedType) | 
 | 42 |     *OwnedType = DS.isTypeSpecOwned() ? DS.getRepAsDecl() : 0; | 
| Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 43 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 |   // Parse the abstract-declarator, if present. | 
| Douglas Gregor | 683a81f | 2011-01-31 16:09:46 +0000 | [diff] [blame] | 45 |   Declarator DeclaratorInfo(DS, Context); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 |   ParseDeclarator(DeclaratorInfo); | 
| Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 47 |   if (Range) | 
 | 48 |     *Range = DeclaratorInfo.getSourceRange(); | 
 | 49 |  | 
| Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 50 |   if (DeclaratorInfo.isInvalidType()) | 
| Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 51 |     return true; | 
 | 52 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 53 |   return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 54 | } | 
 | 55 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 56 |  | 
 | 57 | /// isAttributeLateParsed - Return true if the attribute has arguments that | 
 | 58 | /// require late parsing. | 
 | 59 | static bool isAttributeLateParsed(const IdentifierInfo &II) { | 
 | 60 |     return llvm::StringSwitch<bool>(II.getName()) | 
 | 61 | #include "clang/Parse/AttrLateParsed.inc" | 
 | 62 |         .Default(false); | 
 | 63 | } | 
 | 64 |  | 
 | 65 |  | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 66 | /// ParseGNUAttributes - Parse a non-empty attributes list. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 67 | /// | 
 | 68 | /// [GNU] attributes: | 
 | 69 | ///         attribute | 
 | 70 | ///         attributes attribute | 
 | 71 | /// | 
 | 72 | /// [GNU]  attribute: | 
 | 73 | ///          '__attribute__' '(' '(' attribute-list ')' ')' | 
 | 74 | /// | 
 | 75 | /// [GNU]  attribute-list: | 
 | 76 | ///          attrib | 
 | 77 | ///          attribute_list ',' attrib | 
 | 78 | /// | 
 | 79 | /// [GNU]  attrib: | 
 | 80 | ///          empty | 
 | 81 | ///          attrib-name | 
 | 82 | ///          attrib-name '(' identifier ')' | 
 | 83 | ///          attrib-name '(' identifier ',' nonempty-expr-list ')' | 
 | 84 | ///          attrib-name '(' argument-expression-list [C99 6.5.2] ')' | 
 | 85 | /// | 
 | 86 | /// [GNU]  attrib-name: | 
 | 87 | ///          identifier | 
 | 88 | ///          typespec | 
 | 89 | ///          typequal | 
 | 90 | ///          storageclass | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 91 | /// | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 92 | /// FIXME: The GCC grammar/code for this construct implies we need two | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 93 | /// token lookahead. Comment from gcc: "If they start with an identifier | 
 | 94 | /// which is followed by a comma or close parenthesis, then the arguments | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 95 | /// start with that identifier; otherwise they are an expression list." | 
 | 96 | /// | 
 | 97 | /// At the moment, I am not doing 2 token lookahead. I am also unaware of | 
 | 98 | /// any attributes that don't work (based on my limited testing). Most | 
 | 99 | /// attributes are very simple in practice. Until we find a bug, I don't see | 
 | 100 | /// a pressing need to implement the 2 token lookahead. | 
 | 101 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 102 | void Parser::ParseGNUAttributes(ParsedAttributes &attrs, | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 103 |                                 SourceLocation *endLoc, | 
 | 104 |                                 LateParsedAttrList *LateAttrs) { | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 105 |   assert(Tok.is(tok::kw___attribute) && "Not a GNU attribute list!"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 |  | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 107 |   while (Tok.is(tok::kw___attribute)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 108 |     ConsumeToken(); | 
 | 109 |     if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, | 
 | 110 |                          "attribute")) { | 
 | 111 |       SkipUntil(tok::r_paren, true); // skip until ) or ; | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 112 |       return; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 113 |     } | 
 | 114 |     if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "(")) { | 
 | 115 |       SkipUntil(tok::r_paren, true); // skip until ) or ; | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 116 |       return; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 117 |     } | 
 | 118 |     // Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") )) | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 119 |     while (Tok.is(tok::identifier) || isDeclarationSpecifier() || | 
 | 120 |            Tok.is(tok::comma)) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 |       if (Tok.is(tok::comma)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 122 |         // allows for empty/non-empty attributes. ((__vector_size__(16),,,,)) | 
 | 123 |         ConsumeToken(); | 
 | 124 |         continue; | 
 | 125 |       } | 
 | 126 |       // we have an identifier or declaration specifier (const, int, etc.) | 
 | 127 |       IdentifierInfo *AttrName = Tok.getIdentifierInfo(); | 
 | 128 |       SourceLocation AttrNameLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 130 |       if (Tok.is(tok::l_paren)) { | 
 | 131 |         // handle "parameterized" attributes | 
 | 132 |         if (LateAttrs && !ClassStack.empty() && | 
 | 133 |             isAttributeLateParsed(*AttrName)) { | 
 | 134 |           // Delayed parsing is only available for attributes that occur | 
 | 135 |           // in certain locations within a class scope. | 
 | 136 |           LateParsedAttribute *LA = | 
 | 137 |             new LateParsedAttribute(this, *AttrName, AttrNameLoc); | 
 | 138 |           LateAttrs->push_back(LA); | 
 | 139 |           getCurrentClass().LateParsedDeclarations.push_back(LA); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 140 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 141 |           // consume everything up to and including the matching right parens | 
 | 142 |           ConsumeAndStoreUntil(tok::r_paren, LA->Toks, true, false); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 144 |           Token Eof; | 
 | 145 |           Eof.startToken(); | 
 | 146 |           Eof.setLocation(Tok.getLocation()); | 
 | 147 |           LA->Toks.push_back(Eof); | 
 | 148 |         } else { | 
 | 149 |           ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 150 |         } | 
 | 151 |       } else { | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 152 |         attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, | 
 | 153 |                      0, SourceLocation(), 0, 0); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 154 |       } | 
 | 155 |     } | 
 | 156 |     if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen)) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 157 |       SkipUntil(tok::r_paren, false); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 158 |     SourceLocation Loc = Tok.getLocation(); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 159 |     if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen)) { | 
 | 160 |       SkipUntil(tok::r_paren, false); | 
 | 161 |     } | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 162 |     if (endLoc) | 
 | 163 |       *endLoc = Loc; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 164 |   } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 165 | } | 
 | 166 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 167 |  | 
 | 168 | /// Parse the arguments to a parameterized GNU attribute | 
 | 169 | void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName, | 
 | 170 |                                    SourceLocation AttrNameLoc, | 
 | 171 |                                    ParsedAttributes &Attrs, | 
 | 172 |                                    SourceLocation *EndLoc) { | 
 | 173 |  | 
 | 174 |   assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); | 
 | 175 |  | 
 | 176 |   // Availability attributes have their own grammar. | 
 | 177 |   if (AttrName->isStr("availability")) { | 
 | 178 |     ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc); | 
 | 179 |     return; | 
 | 180 |   } | 
 | 181 |   // Thread safety attributes fit into the FIXME case above, so we | 
 | 182 |   // just parse the arguments as a list of expressions | 
 | 183 |   if (IsThreadSafetyAttribute(AttrName->getName())) { | 
 | 184 |     ParseThreadSafetyAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc); | 
 | 185 |     return; | 
 | 186 |   } | 
 | 187 |  | 
 | 188 |   ConsumeParen(); // ignore the left paren loc for now | 
 | 189 |  | 
 | 190 |   if (Tok.is(tok::identifier)) { | 
 | 191 |     IdentifierInfo *ParmName = Tok.getIdentifierInfo(); | 
 | 192 |     SourceLocation ParmLoc = ConsumeToken(); | 
 | 193 |  | 
 | 194 |     if (Tok.is(tok::r_paren)) { | 
 | 195 |       // __attribute__(( mode(byte) )) | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 196 |       SourceLocation RParen = ConsumeParen(); | 
 | 197 |       Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc, | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 198 |                    ParmName, ParmLoc, 0, 0); | 
 | 199 |     } else if (Tok.is(tok::comma)) { | 
 | 200 |       ConsumeToken(); | 
 | 201 |       // __attribute__(( format(printf, 1, 2) )) | 
 | 202 |       ExprVector ArgExprs(Actions); | 
 | 203 |       bool ArgExprsOk = true; | 
 | 204 |  | 
 | 205 |       // now parse the non-empty comma separated list of expressions | 
 | 206 |       while (1) { | 
 | 207 |         ExprResult ArgExpr(ParseAssignmentExpression()); | 
 | 208 |         if (ArgExpr.isInvalid()) { | 
 | 209 |           ArgExprsOk = false; | 
 | 210 |           SkipUntil(tok::r_paren); | 
 | 211 |           break; | 
 | 212 |         } else { | 
 | 213 |           ArgExprs.push_back(ArgExpr.release()); | 
 | 214 |         } | 
 | 215 |         if (Tok.isNot(tok::comma)) | 
 | 216 |           break; | 
 | 217 |         ConsumeToken(); // Eat the comma, move to the next argument | 
 | 218 |       } | 
 | 219 |       if (ArgExprsOk && Tok.is(tok::r_paren)) { | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 220 |         SourceLocation RParen = ConsumeParen(); | 
 | 221 |         Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc, | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 222 |                      ParmName, ParmLoc, ArgExprs.take(), ArgExprs.size()); | 
 | 223 |       } | 
 | 224 |     } | 
 | 225 |   } else { // not an identifier | 
 | 226 |     switch (Tok.getKind()) { | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 227 |     case tok::r_paren: { | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 228 |     // parse a possibly empty comma separated list of expressions | 
 | 229 |       // __attribute__(( nonnull() )) | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 230 |       SourceLocation RParen = ConsumeParen(); | 
 | 231 |       Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc, | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 232 |                    0, SourceLocation(), 0, 0); | 
 | 233 |       break; | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 234 |     } | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 235 |     case tok::kw_char: | 
 | 236 |     case tok::kw_wchar_t: | 
 | 237 |     case tok::kw_char16_t: | 
 | 238 |     case tok::kw_char32_t: | 
 | 239 |     case tok::kw_bool: | 
 | 240 |     case tok::kw_short: | 
 | 241 |     case tok::kw_int: | 
 | 242 |     case tok::kw_long: | 
 | 243 |     case tok::kw___int64: | 
 | 244 |     case tok::kw_signed: | 
 | 245 |     case tok::kw_unsigned: | 
 | 246 |     case tok::kw_float: | 
 | 247 |     case tok::kw_double: | 
 | 248 |     case tok::kw_void: | 
 | 249 |     case tok::kw_typeof: { | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 250 |       // If it's a builtin type name, eat it and expect a rparen | 
 | 251 |       // __attribute__(( vec_type_hint(char) )) | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 252 |       SourceLocation EndLoc = ConsumeToken(); | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 253 |       if (Tok.is(tok::r_paren)) | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 254 |         EndLoc = ConsumeParen(); | 
 | 255 |       AttributeList *attr | 
 | 256 |         = Attrs.addNew(AttrName, SourceRange(AttrNameLoc, EndLoc), 0, | 
 | 257 |                        AttrNameLoc, 0, SourceLocation(), 0, 0); | 
 | 258 |       if (attr->getKind() == AttributeList::AT_IBOutletCollection) | 
 | 259 |         Diag(Tok, diag::err_iboutletcollection_builtintype); | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 260 |       break; | 
 | 261 |     } | 
 | 262 |     default: | 
 | 263 |       // __attribute__(( aligned(16) )) | 
 | 264 |       ExprVector ArgExprs(Actions); | 
 | 265 |       bool ArgExprsOk = true; | 
 | 266 |  | 
 | 267 |       // now parse the list of expressions | 
 | 268 |       while (1) { | 
 | 269 |         ExprResult ArgExpr(ParseAssignmentExpression()); | 
 | 270 |         if (ArgExpr.isInvalid()) { | 
 | 271 |           ArgExprsOk = false; | 
 | 272 |           SkipUntil(tok::r_paren); | 
 | 273 |           break; | 
 | 274 |         } else { | 
 | 275 |           ArgExprs.push_back(ArgExpr.release()); | 
 | 276 |         } | 
 | 277 |         if (Tok.isNot(tok::comma)) | 
 | 278 |           break; | 
 | 279 |         ConsumeToken(); // Eat the comma, move to the next argument | 
 | 280 |       } | 
 | 281 |       // Match the ')'. | 
 | 282 |       if (ArgExprsOk && Tok.is(tok::r_paren)) { | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 283 |         SourceLocation RParen = ConsumeParen(); | 
 | 284 |         Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 285 |                      AttrNameLoc, 0, SourceLocation(), | 
 | 286 |                      ArgExprs.take(), ArgExprs.size()); | 
 | 287 |       } | 
 | 288 |       break; | 
 | 289 |     } | 
 | 290 |   } | 
 | 291 | } | 
 | 292 |  | 
 | 293 |  | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 294 | /// ParseMicrosoftDeclSpec - Parse an __declspec construct | 
 | 295 | /// | 
 | 296 | /// [MS] decl-specifier: | 
 | 297 | ///             __declspec ( extended-decl-modifier-seq ) | 
 | 298 | /// | 
 | 299 | /// [MS] extended-decl-modifier-seq: | 
 | 300 | ///             extended-decl-modifier[opt] | 
 | 301 | ///             extended-decl-modifier extended-decl-modifier-seq | 
 | 302 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 303 | void Parser::ParseMicrosoftDeclSpec(ParsedAttributes &attrs) { | 
| Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 304 |   assert(Tok.is(tok::kw___declspec) && "Not a declspec!"); | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 305 |  | 
| Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 306 |   ConsumeToken(); | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 307 |   if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, | 
 | 308 |                        "declspec")) { | 
 | 309 |     SkipUntil(tok::r_paren, true); // skip until ) or ; | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 310 |     return; | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 311 |   } | 
| Francois Pichet | 373197b | 2011-05-07 19:04:49 +0000 | [diff] [blame] | 312 |  | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 313 |   while (Tok.getIdentifierInfo()) { | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 314 |     IdentifierInfo *AttrName = Tok.getIdentifierInfo(); | 
 | 315 |     SourceLocation AttrNameLoc = ConsumeToken(); | 
| Francois Pichet | 373197b | 2011-05-07 19:04:49 +0000 | [diff] [blame] | 316 |      | 
 | 317 |     // FIXME: Remove this when we have proper __declspec(property()) support. | 
 | 318 |     // Just skip everything inside property(). | 
 | 319 |     if (AttrName->getName() == "property") { | 
 | 320 |       ConsumeParen(); | 
 | 321 |       SkipUntil(tok::r_paren); | 
 | 322 |     } | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 323 |     if (Tok.is(tok::l_paren)) { | 
 | 324 |       ConsumeParen(); | 
 | 325 |       // FIXME: This doesn't parse __declspec(property(get=get_func_name)) | 
 | 326 |       // correctly. | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 327 |       ExprResult ArgExpr(ParseAssignmentExpression()); | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 328 |       if (!ArgExpr.isInvalid()) { | 
| John McCall | ca0408f | 2010-08-23 06:44:23 +0000 | [diff] [blame] | 329 |         Expr *ExprList = ArgExpr.take(); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 330 |         attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, | 
 | 331 |                      SourceLocation(), &ExprList, 1, true); | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 332 |       } | 
 | 333 |       if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen)) | 
 | 334 |         SkipUntil(tok::r_paren, false); | 
 | 335 |     } else { | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 336 |       attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, | 
 | 337 |                    0, SourceLocation(), 0, 0, true); | 
| Eli Friedman | a23b485 | 2009-06-08 07:21:15 +0000 | [diff] [blame] | 338 |     } | 
 | 339 |   } | 
 | 340 |   if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen)) | 
 | 341 |     SkipUntil(tok::r_paren, false); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 342 |   return; | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 343 | } | 
 | 344 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 345 | void Parser::ParseMicrosoftTypeAttributes(ParsedAttributes &attrs) { | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 346 |   // Treat these like attributes | 
 | 347 |   // FIXME: Allow Sema to distinguish between these and real attributes! | 
 | 348 |   while (Tok.is(tok::kw___fastcall) || Tok.is(tok::kw___stdcall) || | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 349 |          Tok.is(tok::kw___thiscall) || Tok.is(tok::kw___cdecl)   || | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 350 |          Tok.is(tok::kw___ptr64) || Tok.is(tok::kw___w64) || | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 351 |          Tok.is(tok::kw___ptr32) || | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 352 |          Tok.is(tok::kw___unaligned)) { | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 353 |     IdentifierInfo *AttrName = Tok.getIdentifierInfo(); | 
 | 354 |     SourceLocation AttrNameLoc = ConsumeToken(); | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 355 |     if (Tok.is(tok::kw___ptr64) || Tok.is(tok::kw___w64) || | 
 | 356 |         Tok.is(tok::kw___ptr32)) | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 357 |       // FIXME: Support these properly! | 
 | 358 |       continue; | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 359 |     attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, | 
 | 360 |                  SourceLocation(), 0, 0, true); | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 361 |   } | 
| Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 362 | } | 
 | 363 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 364 | void Parser::ParseBorlandTypeAttributes(ParsedAttributes &attrs) { | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 365 |   // Treat these like attributes | 
 | 366 |   while (Tok.is(tok::kw___pascal)) { | 
 | 367 |     IdentifierInfo *AttrName = Tok.getIdentifierInfo(); | 
 | 368 |     SourceLocation AttrNameLoc = ConsumeToken(); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 369 |     attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, | 
 | 370 |                  SourceLocation(), 0, 0, true); | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 371 |   } | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 372 | } | 
 | 373 |  | 
| Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 374 | void Parser::ParseOpenCLAttributes(ParsedAttributes &attrs) { | 
 | 375 |   // Treat these like attributes | 
 | 376 |   while (Tok.is(tok::kw___kernel)) { | 
 | 377 |     SourceLocation AttrNameLoc = ConsumeToken(); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 378 |     attrs.addNew(PP.getIdentifierInfo("opencl_kernel_function"), | 
 | 379 |                  AttrNameLoc, 0, AttrNameLoc, 0, | 
 | 380 |                  SourceLocation(), 0, 0, false); | 
| Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 381 |   } | 
 | 382 | } | 
 | 383 |  | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 384 | void Parser::ParseOpenCLQualifiers(DeclSpec &DS) { | 
 | 385 |   SourceLocation Loc = Tok.getLocation(); | 
 | 386 |   switch(Tok.getKind()) { | 
 | 387 |     // OpenCL qualifiers: | 
 | 388 |     case tok::kw___private: | 
 | 389 |     case tok::kw_private:  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 390 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 391 |           Actions.getASTContext(),  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 392 |           PP.getIdentifierInfo("address_space"), Loc, 0); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 393 |       break; | 
 | 394 |        | 
 | 395 |     case tok::kw___global: | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 396 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 397 |           Actions.getASTContext(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 398 |           PP.getIdentifierInfo("address_space"), Loc, LangAS::opencl_global); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 399 |       break; | 
 | 400 |        | 
 | 401 |     case tok::kw___local: | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 402 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 403 |           Actions.getASTContext(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 404 |           PP.getIdentifierInfo("address_space"), Loc, LangAS::opencl_local); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 405 |       break; | 
 | 406 |        | 
 | 407 |     case tok::kw___constant: | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 408 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 409 |           Actions.getASTContext(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 410 |           PP.getIdentifierInfo("address_space"), Loc, LangAS::opencl_constant); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 411 |       break; | 
 | 412 |        | 
 | 413 |     case tok::kw___read_only: | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 414 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 415 |           Actions.getASTContext(),  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 416 |           PP.getIdentifierInfo("opencl_image_access"), Loc, CLIA_read_only); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 417 |       break; | 
 | 418 |        | 
 | 419 |     case tok::kw___write_only: | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 420 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 421 |           Actions.getASTContext(),  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 422 |           PP.getIdentifierInfo("opencl_image_access"), Loc, CLIA_write_only); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 423 |       break; | 
 | 424 |        | 
 | 425 |     case tok::kw___read_write: | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 426 |       DS.getAttributes().addNewInteger( | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 427 |           Actions.getASTContext(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 428 |           PP.getIdentifierInfo("opencl_image_access"), Loc, CLIA_read_write); | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 429 |       break; | 
 | 430 |     default: break; | 
 | 431 |   } | 
 | 432 | } | 
 | 433 |  | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 434 | /// \brief Parse a version number. | 
 | 435 | /// | 
 | 436 | /// version: | 
 | 437 | ///   simple-integer | 
 | 438 | ///   simple-integer ',' simple-integer | 
 | 439 | ///   simple-integer ',' simple-integer ',' simple-integer | 
 | 440 | VersionTuple Parser::ParseVersionTuple(SourceRange &Range) { | 
 | 441 |   Range = Tok.getLocation(); | 
 | 442 |  | 
 | 443 |   if (!Tok.is(tok::numeric_constant)) { | 
 | 444 |     Diag(Tok, diag::err_expected_version); | 
 | 445 |     SkipUntil(tok::comma, tok::r_paren, true, true, true); | 
 | 446 |     return VersionTuple(); | 
 | 447 |   } | 
 | 448 |  | 
 | 449 |   // Parse the major (and possibly minor and subminor) versions, which | 
 | 450 |   // are stored in the numeric constant. We utilize a quirk of the | 
 | 451 |   // lexer, which is that it handles something like 1.2.3 as a single | 
 | 452 |   // numeric constant, rather than two separate tokens. | 
 | 453 |   llvm::SmallString<512> Buffer; | 
 | 454 |   Buffer.resize(Tok.getLength()+1); | 
 | 455 |   const char *ThisTokBegin = &Buffer[0]; | 
 | 456 |  | 
 | 457 |   // Get the spelling of the token, which eliminates trigraphs, etc. | 
 | 458 |   bool Invalid = false; | 
 | 459 |   unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin, &Invalid); | 
 | 460 |   if (Invalid) | 
 | 461 |     return VersionTuple(); | 
 | 462 |  | 
 | 463 |   // Parse the major version. | 
 | 464 |   unsigned AfterMajor = 0; | 
 | 465 |   unsigned Major = 0; | 
 | 466 |   while (AfterMajor < ActualLength && isdigit(ThisTokBegin[AfterMajor])) { | 
 | 467 |     Major = Major * 10 + ThisTokBegin[AfterMajor] - '0'; | 
 | 468 |     ++AfterMajor; | 
 | 469 |   } | 
 | 470 |  | 
 | 471 |   if (AfterMajor == 0) { | 
 | 472 |     Diag(Tok, diag::err_expected_version); | 
 | 473 |     SkipUntil(tok::comma, tok::r_paren, true, true, true); | 
 | 474 |     return VersionTuple(); | 
 | 475 |   } | 
 | 476 |  | 
 | 477 |   if (AfterMajor == ActualLength) { | 
 | 478 |     ConsumeToken(); | 
 | 479 |  | 
 | 480 |     // We only had a single version component. | 
 | 481 |     if (Major == 0) { | 
 | 482 |       Diag(Tok, diag::err_zero_version); | 
 | 483 |       return VersionTuple(); | 
 | 484 |     } | 
 | 485 |  | 
 | 486 |     return VersionTuple(Major); | 
 | 487 |   } | 
 | 488 |  | 
 | 489 |   if (ThisTokBegin[AfterMajor] != '.' || (AfterMajor + 1 == ActualLength)) { | 
 | 490 |     Diag(Tok, diag::err_expected_version); | 
 | 491 |     SkipUntil(tok::comma, tok::r_paren, true, true, true); | 
 | 492 |     return VersionTuple(); | 
 | 493 |   } | 
 | 494 |  | 
 | 495 |   // Parse the minor version. | 
 | 496 |   unsigned AfterMinor = AfterMajor + 1; | 
 | 497 |   unsigned Minor = 0; | 
 | 498 |   while (AfterMinor < ActualLength && isdigit(ThisTokBegin[AfterMinor])) { | 
 | 499 |     Minor = Minor * 10 + ThisTokBegin[AfterMinor] - '0'; | 
 | 500 |     ++AfterMinor; | 
 | 501 |   } | 
 | 502 |  | 
 | 503 |   if (AfterMinor == ActualLength) { | 
 | 504 |     ConsumeToken(); | 
 | 505 |      | 
 | 506 |     // We had major.minor. | 
 | 507 |     if (Major == 0 && Minor == 0) { | 
 | 508 |       Diag(Tok, diag::err_zero_version); | 
 | 509 |       return VersionTuple(); | 
 | 510 |     } | 
 | 511 |  | 
 | 512 |     return VersionTuple(Major, Minor);       | 
 | 513 |   } | 
 | 514 |  | 
 | 515 |   // If what follows is not a '.', we have a problem. | 
 | 516 |   if (ThisTokBegin[AfterMinor] != '.') { | 
 | 517 |     Diag(Tok, diag::err_expected_version); | 
 | 518 |     SkipUntil(tok::comma, tok::r_paren, true, true, true); | 
 | 519 |     return VersionTuple();     | 
 | 520 |   } | 
 | 521 |  | 
 | 522 |   // Parse the subminor version. | 
 | 523 |   unsigned AfterSubminor = AfterMinor + 1; | 
 | 524 |   unsigned Subminor = 0; | 
 | 525 |   while (AfterSubminor < ActualLength && isdigit(ThisTokBegin[AfterSubminor])) { | 
 | 526 |     Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] - '0'; | 
 | 527 |     ++AfterSubminor; | 
 | 528 |   } | 
 | 529 |  | 
 | 530 |   if (AfterSubminor != ActualLength) { | 
 | 531 |     Diag(Tok, diag::err_expected_version); | 
 | 532 |     SkipUntil(tok::comma, tok::r_paren, true, true, true); | 
 | 533 |     return VersionTuple(); | 
 | 534 |   } | 
 | 535 |   ConsumeToken(); | 
 | 536 |   return VersionTuple(Major, Minor, Subminor); | 
 | 537 | } | 
 | 538 |  | 
 | 539 | /// \brief Parse the contents of the "availability" attribute. | 
 | 540 | /// | 
 | 541 | /// availability-attribute: | 
 | 542 | ///   'availability' '(' platform ',' version-arg-list ')' | 
 | 543 | /// | 
 | 544 | /// platform: | 
 | 545 | ///   identifier | 
 | 546 | /// | 
 | 547 | /// version-arg-list: | 
 | 548 | ///   version-arg | 
 | 549 | ///   version-arg ',' version-arg-list | 
 | 550 | /// | 
 | 551 | /// version-arg: | 
 | 552 | ///   'introduced' '=' version | 
 | 553 | ///   'deprecated' '=' version | 
 | 554 | ///   'removed' = version | 
| Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 555 | ///   'unavailable' | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 556 | void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability, | 
 | 557 |                                         SourceLocation AvailabilityLoc, | 
 | 558 |                                         ParsedAttributes &attrs, | 
 | 559 |                                         SourceLocation *endLoc) { | 
 | 560 |   SourceLocation PlatformLoc; | 
 | 561 |   IdentifierInfo *Platform = 0; | 
 | 562 |  | 
 | 563 |   enum { Introduced, Deprecated, Obsoleted, Unknown }; | 
 | 564 |   AvailabilityChange Changes[Unknown]; | 
 | 565 |  | 
 | 566 |   // Opening '('. | 
 | 567 |   SourceLocation LParenLoc; | 
 | 568 |   if (!Tok.is(tok::l_paren)) { | 
 | 569 |     Diag(Tok, diag::err_expected_lparen); | 
 | 570 |     return; | 
 | 571 |   } | 
 | 572 |   LParenLoc = ConsumeParen(); | 
 | 573 |  | 
 | 574 |   // Parse the platform name, | 
 | 575 |   if (Tok.isNot(tok::identifier)) { | 
 | 576 |     Diag(Tok, diag::err_availability_expected_platform); | 
 | 577 |     SkipUntil(tok::r_paren); | 
 | 578 |     return; | 
 | 579 |   } | 
 | 580 |   Platform = Tok.getIdentifierInfo(); | 
 | 581 |   PlatformLoc = ConsumeToken(); | 
 | 582 |  | 
 | 583 |   // Parse the ',' following the platform name. | 
 | 584 |   if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::r_paren)) | 
 | 585 |     return; | 
 | 586 |  | 
 | 587 |   // If we haven't grabbed the pointers for the identifiers | 
 | 588 |   // "introduced", "deprecated", and "obsoleted", do so now. | 
 | 589 |   if (!Ident_introduced) { | 
 | 590 |     Ident_introduced = PP.getIdentifierInfo("introduced"); | 
 | 591 |     Ident_deprecated = PP.getIdentifierInfo("deprecated"); | 
 | 592 |     Ident_obsoleted = PP.getIdentifierInfo("obsoleted"); | 
| Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 593 |     Ident_unavailable = PP.getIdentifierInfo("unavailable"); | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 594 |   } | 
 | 595 |  | 
 | 596 |   // Parse the set of introductions/deprecations/removals. | 
| Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 597 |   SourceLocation UnavailableLoc; | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 598 |   do { | 
 | 599 |     if (Tok.isNot(tok::identifier)) { | 
 | 600 |       Diag(Tok, diag::err_availability_expected_change); | 
 | 601 |       SkipUntil(tok::r_paren); | 
 | 602 |       return; | 
 | 603 |     } | 
 | 604 |     IdentifierInfo *Keyword = Tok.getIdentifierInfo(); | 
 | 605 |     SourceLocation KeywordLoc = ConsumeToken(); | 
 | 606 |  | 
| Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 607 |     if (Keyword == Ident_unavailable) { | 
 | 608 |       if (UnavailableLoc.isValid()) { | 
 | 609 |         Diag(KeywordLoc, diag::err_availability_redundant) | 
 | 610 |           << Keyword << SourceRange(UnavailableLoc); | 
 | 611 |       }  | 
 | 612 |       UnavailableLoc = KeywordLoc; | 
 | 613 |  | 
 | 614 |       if (Tok.isNot(tok::comma)) | 
 | 615 |         break; | 
 | 616 |  | 
 | 617 |       ConsumeToken(); | 
 | 618 |       continue; | 
 | 619 |     }  | 
 | 620 |  | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 621 |     if (Tok.isNot(tok::equal)) { | 
 | 622 |       Diag(Tok, diag::err_expected_equal_after) | 
 | 623 |         << Keyword; | 
 | 624 |       SkipUntil(tok::r_paren); | 
 | 625 |       return; | 
 | 626 |     } | 
 | 627 |     ConsumeToken(); | 
 | 628 |      | 
 | 629 |     SourceRange VersionRange; | 
 | 630 |     VersionTuple Version = ParseVersionTuple(VersionRange); | 
 | 631 |      | 
 | 632 |     if (Version.empty()) { | 
 | 633 |       SkipUntil(tok::r_paren); | 
 | 634 |       return; | 
 | 635 |     } | 
 | 636 |  | 
 | 637 |     unsigned Index; | 
 | 638 |     if (Keyword == Ident_introduced) | 
 | 639 |       Index = Introduced; | 
 | 640 |     else if (Keyword == Ident_deprecated) | 
 | 641 |       Index = Deprecated; | 
 | 642 |     else if (Keyword == Ident_obsoleted) | 
 | 643 |       Index = Obsoleted; | 
 | 644 |     else  | 
 | 645 |       Index = Unknown; | 
 | 646 |  | 
 | 647 |     if (Index < Unknown) { | 
 | 648 |       if (!Changes[Index].KeywordLoc.isInvalid()) { | 
 | 649 |         Diag(KeywordLoc, diag::err_availability_redundant) | 
 | 650 |           << Keyword  | 
 | 651 |           << SourceRange(Changes[Index].KeywordLoc, | 
 | 652 |                          Changes[Index].VersionRange.getEnd()); | 
 | 653 |       } | 
 | 654 |  | 
 | 655 |       Changes[Index].KeywordLoc = KeywordLoc; | 
 | 656 |       Changes[Index].Version = Version; | 
 | 657 |       Changes[Index].VersionRange = VersionRange; | 
 | 658 |     } else { | 
 | 659 |       Diag(KeywordLoc, diag::err_availability_unknown_change) | 
 | 660 |         << Keyword << VersionRange; | 
 | 661 |     } | 
 | 662 |  | 
 | 663 |     if (Tok.isNot(tok::comma)) | 
 | 664 |       break; | 
 | 665 |  | 
 | 666 |     ConsumeToken(); | 
 | 667 |   } while (true); | 
 | 668 |  | 
 | 669 |   // Closing ')'. | 
 | 670 |   SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); | 
 | 671 |   if (RParenLoc.isInvalid()) | 
 | 672 |     return; | 
 | 673 |  | 
 | 674 |   if (endLoc) | 
 | 675 |     *endLoc = RParenLoc; | 
 | 676 |  | 
| Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 677 |   // The 'unavailable' availability cannot be combined with any other | 
 | 678 |   // availability changes. Make sure that hasn't happened. | 
 | 679 |   if (UnavailableLoc.isValid()) { | 
 | 680 |     bool Complained = false; | 
 | 681 |     for (unsigned Index = Introduced; Index != Unknown; ++Index) { | 
 | 682 |       if (Changes[Index].KeywordLoc.isValid()) { | 
 | 683 |         if (!Complained) { | 
 | 684 |           Diag(UnavailableLoc, diag::warn_availability_and_unavailable) | 
 | 685 |             << SourceRange(Changes[Index].KeywordLoc, | 
 | 686 |                            Changes[Index].VersionRange.getEnd()); | 
 | 687 |           Complained = true; | 
 | 688 |         } | 
 | 689 |  | 
 | 690 |         // Clear out the availability. | 
 | 691 |         Changes[Index] = AvailabilityChange(); | 
 | 692 |       } | 
 | 693 |     } | 
 | 694 |   } | 
 | 695 |  | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 696 |   // Record this attribute | 
| Argyrios Kyrtzidis | ffcc310 | 2011-09-13 16:05:53 +0000 | [diff] [blame] | 697 |   attrs.addNew(&Availability, SourceRange(AvailabilityLoc, RParenLoc),  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 698 |                0, SourceLocation(), | 
 | 699 |                Platform, PlatformLoc, | 
 | 700 |                Changes[Introduced], | 
 | 701 |                Changes[Deprecated], | 
| Douglas Gregor | b53e417 | 2011-03-26 03:35:55 +0000 | [diff] [blame] | 702 |                Changes[Obsoleted],  | 
 | 703 |                UnavailableLoc, false, false); | 
| Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 704 | } | 
 | 705 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 706 |  | 
 | 707 | // Late Parsed Attributes: | 
 | 708 | // See other examples of late parsing in lib/Parse/ParseCXXInlineMethods | 
 | 709 |  | 
 | 710 | void Parser::LateParsedDeclaration::ParseLexedAttributes() {} | 
 | 711 |  | 
 | 712 | void Parser::LateParsedClass::ParseLexedAttributes() { | 
 | 713 |   Self->ParseLexedAttributes(*Class); | 
 | 714 | } | 
 | 715 |  | 
 | 716 | void Parser::LateParsedAttribute::ParseLexedAttributes() { | 
 | 717 |   Self->ParseLexedAttribute(*this); | 
 | 718 | } | 
 | 719 |  | 
 | 720 | /// Wrapper class which calls ParseLexedAttribute, after setting up the | 
 | 721 | /// scope appropriately. | 
 | 722 | void Parser::ParseLexedAttributes(ParsingClass &Class) { | 
 | 723 |   // Deal with templates | 
 | 724 |   // FIXME: Test cases to make sure this does the right thing for templates. | 
 | 725 |   bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; | 
 | 726 |   ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, | 
 | 727 |                                 HasTemplateScope); | 
 | 728 |   if (HasTemplateScope) | 
 | 729 |     Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); | 
 | 730 |  | 
 | 731 |   // Set or update the scope flags to include Scope::ThisScope. | 
 | 732 |   bool AlreadyHasClassScope = Class.TopLevelClass; | 
 | 733 |   unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope|Scope::ThisScope; | 
 | 734 |   ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope); | 
 | 735 |   ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope); | 
 | 736 |  | 
 | 737 |   for (unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i) { | 
 | 738 |     Class.LateParsedDeclarations[i]->ParseLexedAttributes(); | 
 | 739 |   } | 
 | 740 | } | 
 | 741 |  | 
 | 742 | /// \brief Finish parsing an attribute for which parsing was delayed. | 
 | 743 | /// This will be called at the end of parsing a class declaration | 
 | 744 | /// for each LateParsedAttribute. We consume the saved tokens and | 
 | 745 | /// create an attribute with the arguments filled in. We add this  | 
 | 746 | /// to the Attribute list for the decl. | 
 | 747 | void Parser::ParseLexedAttribute(LateParsedAttribute &LA) { | 
 | 748 |   // Save the current token position. | 
 | 749 |   SourceLocation OrigLoc = Tok.getLocation(); | 
 | 750 |  | 
 | 751 |   // Append the current token at the end of the new token stream so that it | 
 | 752 |   // doesn't get lost. | 
 | 753 |   LA.Toks.push_back(Tok); | 
 | 754 |   PP.EnterTokenStream(LA.Toks.data(), LA.Toks.size(), true, false); | 
 | 755 |   // Consume the previously pushed token. | 
 | 756 |   ConsumeAnyToken(); | 
 | 757 |  | 
 | 758 |   ParsedAttributes Attrs(AttrFactory); | 
 | 759 |   SourceLocation endLoc; | 
 | 760 |  | 
| Caitlin Sadowski | ed9d84a | 2011-09-08 17:42:31 +0000 | [diff] [blame] | 761 |   // If the Decl is templatized, add template parameters to scope. | 
 | 762 |   bool HasTemplateScope = LA.D && LA.D->isTemplateDecl(); | 
 | 763 |   ParseScope TempScope(this, Scope::TemplateParamScope, HasTemplateScope); | 
 | 764 |   if (HasTemplateScope) | 
 | 765 |     Actions.ActOnReenterTemplateScope(Actions.CurScope, LA.D); | 
 | 766 |  | 
 | 767 |   // If the Decl is on a function, add function parameters to the scope. | 
 | 768 |   bool HasFunctionScope = LA.D && LA.D->isFunctionOrFunctionTemplate(); | 
 | 769 |   ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope, HasFunctionScope); | 
 | 770 |   if (HasFunctionScope) | 
 | 771 |     Actions.ActOnReenterFunctionContext(Actions.CurScope, LA.D); | 
 | 772 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 773 |   ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc); | 
 | 774 |  | 
| Caitlin Sadowski | ed9d84a | 2011-09-08 17:42:31 +0000 | [diff] [blame] | 775 |   if (HasFunctionScope) { | 
 | 776 |     Actions.ActOnExitFunctionContext(); | 
 | 777 |     FnScope.Exit();  // Pop scope, and remove Decls from IdResolver | 
 | 778 |   } | 
 | 779 |   if (HasTemplateScope) { | 
 | 780 |     TempScope.Exit(); | 
 | 781 |   } | 
 | 782 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 783 |   // Late parsed attributes must be attached to Decls by hand.  If the | 
 | 784 |   // LA.D is not set, then this was not done properly. | 
 | 785 |   assert(LA.D && "No decl attached to late parsed attribute"); | 
 | 786 |   Actions.ActOnFinishDelayedAttribute(getCurScope(), LA.D, Attrs); | 
 | 787 |  | 
 | 788 |   if (Tok.getLocation() != OrigLoc) { | 
 | 789 |     // Due to a parsing error, we either went over the cached tokens or | 
 | 790 |     // there are still cached tokens left, so we skip the leftover tokens. | 
 | 791 |     // Since this is an uncommon situation that should be avoided, use the | 
 | 792 |     // expensive isBeforeInTranslationUnit call. | 
 | 793 |     if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(), | 
 | 794 |                                                         OrigLoc)) | 
 | 795 |     while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof)) | 
 | 796 |         ConsumeAnyToken(); | 
 | 797 |   } | 
 | 798 | } | 
 | 799 |  | 
| Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 800 | /// \brief Wrapper around a case statement checking if AttrName is | 
 | 801 | /// one of the thread safety attributes | 
 | 802 | bool Parser::IsThreadSafetyAttribute(llvm::StringRef AttrName){ | 
 | 803 |   return llvm::StringSwitch<bool>(AttrName) | 
 | 804 |       .Case("guarded_by", true) | 
 | 805 |       .Case("guarded_var", true) | 
 | 806 |       .Case("pt_guarded_by", true) | 
 | 807 |       .Case("pt_guarded_var", true) | 
 | 808 |       .Case("lockable", true) | 
 | 809 |       .Case("scoped_lockable", true) | 
 | 810 |       .Case("no_thread_safety_analysis", true) | 
 | 811 |       .Case("acquired_after", true) | 
 | 812 |       .Case("acquired_before", true) | 
 | 813 |       .Case("exclusive_lock_function", true) | 
 | 814 |       .Case("shared_lock_function", true) | 
 | 815 |       .Case("exclusive_trylock_function", true) | 
 | 816 |       .Case("shared_trylock_function", true) | 
 | 817 |       .Case("unlock_function", true) | 
 | 818 |       .Case("lock_returned", true) | 
 | 819 |       .Case("locks_excluded", true) | 
 | 820 |       .Case("exclusive_locks_required", true) | 
 | 821 |       .Case("shared_locks_required", true) | 
 | 822 |       .Default(false); | 
 | 823 | } | 
 | 824 |  | 
 | 825 | /// \brief Parse the contents of thread safety attributes. These | 
 | 826 | /// should always be parsed as an expression list. | 
 | 827 | /// | 
 | 828 | /// We need to special case the parsing due to the fact that if the first token | 
 | 829 | /// of the first argument is an identifier, the main parse loop will store | 
 | 830 | /// that token as a "parameter" and the rest of | 
 | 831 | /// the arguments will be added to a list of "arguments". However, | 
 | 832 | /// subsequent tokens in the first argument are lost. We instead parse each | 
 | 833 | /// argument as an expression and add all arguments to the list of "arguments". | 
 | 834 | /// In future, we will take advantage of this special case to also | 
 | 835 | /// deal with some argument scoping issues here (for example, referring to a | 
 | 836 | /// function parameter in the attribute on that function). | 
 | 837 | void Parser::ParseThreadSafetyAttribute(IdentifierInfo &AttrName, | 
 | 838 |                                         SourceLocation AttrNameLoc, | 
 | 839 |                                         ParsedAttributes &Attrs, | 
 | 840 |                                         SourceLocation *EndLoc) { | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 841 |   assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); | 
| Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 842 |  | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 843 |   SourceLocation LeftParenLoc = Tok.getLocation(); | 
 | 844 |   ConsumeParen(); | 
 | 845 |    | 
 | 846 |   ExprVector ArgExprs(Actions); | 
 | 847 |   bool ArgExprsOk = true; | 
 | 848 |    | 
 | 849 |   // now parse the list of expressions | 
 | 850 |   while (1) { | 
 | 851 |     ExprResult ArgExpr(ParseAssignmentExpression()); | 
 | 852 |     if (ArgExpr.isInvalid()) { | 
 | 853 |       ArgExprsOk = false; | 
 | 854 |       MatchRHSPunctuation(tok::r_paren, LeftParenLoc); | 
 | 855 |       break; | 
 | 856 |     } else { | 
 | 857 |       ArgExprs.push_back(ArgExpr.release()); | 
| Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 858 |     } | 
| Caitlin Sadowski | eff98fc | 2011-09-08 17:42:22 +0000 | [diff] [blame] | 859 |     if (Tok.isNot(tok::comma)) | 
 | 860 |       break; | 
 | 861 |     ConsumeToken(); // Eat the comma, move to the next argument | 
 | 862 |   } | 
 | 863 |   // Match the ')'. | 
 | 864 |   if (ArgExprsOk && Tok.is(tok::r_paren)) { | 
 | 865 |     if (EndLoc) | 
 | 866 |       *EndLoc = Tok.getLocation(); | 
 | 867 |     ConsumeParen(); | 
 | 868 |     Attrs.addNew(&AttrName, AttrNameLoc, 0, AttrNameLoc, 0, SourceLocation(), | 
 | 869 |                  ArgExprs.take(), ArgExprs.size()); | 
| Caitlin Sadowski | b51e031 | 2011-08-09 17:59:31 +0000 | [diff] [blame] | 870 |   } | 
 | 871 | } | 
 | 872 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 873 | void Parser::DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs) { | 
 | 874 |   Diag(attrs.Range.getBegin(), diag::err_attributes_not_allowed) | 
 | 875 |     << attrs.Range; | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 876 | } | 
 | 877 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 878 | /// ParseDeclaration - Parse a full 'declaration', which consists of | 
 | 879 | /// declaration-specifiers, some number of declarators, and a semicolon. | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 880 | /// 'Context' should be a Declarator::TheContext value.  This returns the | 
 | 881 | /// location of the semicolon in DeclEnd. | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 882 | /// | 
 | 883 | ///       declaration: [C99 6.7] | 
 | 884 | ///         block-declaration -> | 
 | 885 | ///           simple-declaration | 
 | 886 | ///           others                   [FIXME] | 
| Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 887 | /// [C++]   template-declaration | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 888 | /// [C++]   namespace-definition | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 889 | /// [C++]   using-directive | 
| Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 890 | /// [C++]   using-declaration | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 891 | /// [C++0x/C1X] static_assert-declaration | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 892 | ///         others... [FIXME] | 
 | 893 | /// | 
| Fariborz Jahanian | c5be7b0 | 2010-09-28 20:42:35 +0000 | [diff] [blame] | 894 | Parser::DeclGroupPtrTy Parser::ParseDeclaration(StmtVector &Stmts, | 
 | 895 |                                                 unsigned Context, | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 896 |                                                 SourceLocation &DeclEnd, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 897 |                                           ParsedAttributesWithRange &attrs) { | 
| Argyrios Kyrtzidis | 36d3680 | 2010-06-17 10:52:18 +0000 | [diff] [blame] | 898 |   ParenBraceBracketBalancer BalancerRAIIObj(*this); | 
| Fariborz Jahanian | e8cff36 | 2011-08-30 17:10:52 +0000 | [diff] [blame] | 899 |   // Must temporarily exit the objective-c container scope for | 
 | 900 |   // parsing c none objective-c decls. | 
 | 901 |   ObjCDeclContextSwitch ObjCDC(*this); | 
| Argyrios Kyrtzidis | 36d3680 | 2010-06-17 10:52:18 +0000 | [diff] [blame] | 902 |    | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 903 |   Decl *SingleDecl = 0; | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 904 |   Decl *OwnedType = 0; | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 905 |   switch (Tok.getKind()) { | 
| Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 906 |   case tok::kw_template: | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 907 |   case tok::kw_export: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 908 |     ProhibitAttributes(attrs); | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 909 |     SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 910 |     break; | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 911 |   case tok::kw_inline: | 
| Sebastian Redl | 88e64ca | 2010-08-31 00:36:45 +0000 | [diff] [blame] | 912 |     // Could be the start of an inline namespace. Allowed as an ext in C++03. | 
 | 913 |     if (getLang().CPlusPlus && NextToken().is(tok::kw_namespace)) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 914 |       ProhibitAttributes(attrs); | 
| Sebastian Redl | d078e64 | 2010-08-27 23:12:46 +0000 | [diff] [blame] | 915 |       SourceLocation InlineLoc = ConsumeToken(); | 
 | 916 |       SingleDecl = ParseNamespace(Context, DeclEnd, InlineLoc); | 
 | 917 |       break; | 
 | 918 |     } | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 919 |     return ParseSimpleDeclaration(Stmts, Context, DeclEnd, attrs,  | 
| Fariborz Jahanian | c5be7b0 | 2010-09-28 20:42:35 +0000 | [diff] [blame] | 920 |                                   true); | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 921 |   case tok::kw_namespace: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 922 |     ProhibitAttributes(attrs); | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 923 |     SingleDecl = ParseNamespace(Context, DeclEnd); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 924 |     break; | 
| Douglas Gregor | f780abc | 2008-12-30 03:27:21 +0000 | [diff] [blame] | 925 |   case tok::kw_using: | 
| John McCall | 78b8105 | 2010-11-10 02:40:36 +0000 | [diff] [blame] | 926 |     SingleDecl = ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(), | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 927 |                                                   DeclEnd, attrs, &OwnedType); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 928 |     break; | 
| Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 929 |   case tok::kw_static_assert: | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 930 |   case tok::kw__Static_assert: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 931 |     ProhibitAttributes(attrs); | 
| Chris Lattner | 97144fc | 2009-04-02 04:16:50 +0000 | [diff] [blame] | 932 |     SingleDecl = ParseStaticAssertDeclaration(DeclEnd); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 933 |     break; | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 934 |   default: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 935 |     return ParseSimpleDeclaration(Stmts, Context, DeclEnd, attrs, true); | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 936 |   } | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 937 |    | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 938 |   // This routine returns a DeclGroup, if the thing we parsed only contains a | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 939 |   // single decl, convert it now. Alias declarations can also declare a type; | 
 | 940 |   // include that too if it is present. | 
 | 941 |   return Actions.ConvertDeclToDeclGroup(SingleDecl, OwnedType); | 
| Chris Lattner | 8f08cb7 | 2007-08-25 06:57:03 +0000 | [diff] [blame] | 942 | } | 
 | 943 |  | 
 | 944 | ///       simple-declaration: [C99 6.7: declaration] [C++ 7p1: dcl.dcl] | 
 | 945 | ///         declaration-specifiers init-declarator-list[opt] ';' | 
 | 946 | ///[C90/C++]init-declarator-list ';'                             [TODO] | 
 | 947 | /// [OMP]   threadprivate-directive                              [TODO] | 
| Chris Lattner | cd14775 | 2009-03-29 17:27:48 +0000 | [diff] [blame] | 948 | /// | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 949 | ///       for-range-declaration: [C++0x 6.5p1: stmt.ranged] | 
 | 950 | ///         attribute-specifier-seq[opt] type-specifier-seq declarator | 
 | 951 | /// | 
| Chris Lattner | cd14775 | 2009-03-29 17:27:48 +0000 | [diff] [blame] | 952 | /// If RequireSemi is false, this does not check for a ';' at the end of the | 
| Chris Lattner | 5c5db55 | 2010-04-05 18:18:31 +0000 | [diff] [blame] | 953 | /// declaration.  If it is true, it checks for and eats it. | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 954 | /// | 
 | 955 | /// If FRI is non-null, we might be parsing a for-range-declaration instead | 
 | 956 | /// of a simple-declaration. If we find that we are, we also parse the | 
 | 957 | /// for-range-initializer, and place it here. | 
| Fariborz Jahanian | c5be7b0 | 2010-09-28 20:42:35 +0000 | [diff] [blame] | 958 | Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(StmtVector &Stmts,  | 
 | 959 |                                                       unsigned Context, | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 960 |                                                       SourceLocation &DeclEnd, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 961 |                                                       ParsedAttributes &attrs, | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 962 |                                                       bool RequireSemi, | 
 | 963 |                                                       ForRangeInit *FRI) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 964 |   // Parse the common declaration-specifiers piece. | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 965 |   ParsingDeclSpec DS(*this); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 966 |   DS.takeAttributesFrom(attrs); | 
| Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 967 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 968 |   ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none, | 
| Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 969 |                              getDeclSpecContextFromDeclaratorContext(Context)); | 
| Fariborz Jahanian | c5be7b0 | 2010-09-28 20:42:35 +0000 | [diff] [blame] | 970 |   StmtResult R = Actions.ActOnVlaStmt(DS); | 
 | 971 |   if (R.isUsable()) | 
 | 972 |     Stmts.push_back(R.release()); | 
| Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 973 |    | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 974 |   // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };" | 
 | 975 |   // declaration-specifiers init-declarator-list[opt] ';' | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 976 |   if (Tok.is(tok::semi)) { | 
| Chris Lattner | 5c5db55 | 2010-04-05 18:18:31 +0000 | [diff] [blame] | 977 |     if (RequireSemi) ConsumeToken(); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 978 |     Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, | 
| Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 979 |                                                        DS); | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 980 |     DS.complete(TheDecl); | 
| Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 981 |     return Actions.ConvertDeclToDeclGroup(TheDecl); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 982 |   } | 
| Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 983 |    | 
 | 984 |   return ParseDeclGroup(DS, Context, /*FunctionDefs=*/ false, &DeclEnd, FRI);   | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 985 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 |  | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 987 | /// ParseDeclGroup - Having concluded that this is either a function | 
 | 988 | /// definition or a group of object declarations, actually parse the | 
 | 989 | /// result. | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 990 | Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, | 
 | 991 |                                               unsigned Context, | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 992 |                                               bool AllowFunctionDefinitions, | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 993 |                                               SourceLocation *DeclEnd, | 
 | 994 |                                               ForRangeInit *FRI) { | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 995 |   // Parse the first declarator. | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 996 |   ParsingDeclarator D(*this, DS, static_cast<Declarator::TheContext>(Context)); | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 997 |   ParseDeclarator(D); | 
| Chris Lattner | cd14775 | 2009-03-29 17:27:48 +0000 | [diff] [blame] | 998 |  | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 999 |   // Bail out if the first declarator didn't seem well-formed. | 
 | 1000 |   if (!D.hasName() && !D.mayOmitIdentifier()) { | 
 | 1001 |     // Skip until ; or }. | 
 | 1002 |     SkipUntil(tok::r_brace, true, true); | 
 | 1003 |     if (Tok.is(tok::semi)) | 
 | 1004 |       ConsumeToken(); | 
 | 1005 |     return DeclGroupPtrTy(); | 
| Chris Lattner | 23c4b18 | 2009-03-29 17:18:04 +0000 | [diff] [blame] | 1006 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 |  | 
| Chris Lattner | c82daef | 2010-07-11 22:24:20 +0000 | [diff] [blame] | 1008 |   // Check to see if we have a function *definition* which must have a body. | 
 | 1009 |   if (AllowFunctionDefinitions && D.isFunctionDeclarator() && | 
 | 1010 |       // Look at the next token to make sure that this isn't a function | 
 | 1011 |       // declaration.  We have to check this because __attribute__ might be the | 
 | 1012 |       // start of a function definition in GCC-extended K&R C. | 
 | 1013 |       !isDeclarationAfterDeclarator()) { | 
 | 1014 |      | 
| Chris Lattner | 004659a | 2010-07-11 22:42:07 +0000 | [diff] [blame] | 1015 |     if (isStartOfFunctionDefinition(D)) { | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1016 |       if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { | 
 | 1017 |         Diag(Tok, diag::err_function_declared_typedef); | 
 | 1018 |  | 
 | 1019 |         // Recover by treating the 'typedef' as spurious. | 
 | 1020 |         DS.ClearStorageClassSpecs(); | 
 | 1021 |       } | 
 | 1022 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1023 |       Decl *TheDecl = ParseFunctionDefinition(D); | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1024 |       return Actions.ConvertDeclToDeclGroup(TheDecl); | 
| Chris Lattner | 004659a | 2010-07-11 22:42:07 +0000 | [diff] [blame] | 1025 |     } | 
 | 1026 |      | 
 | 1027 |     if (isDeclarationSpecifier()) { | 
 | 1028 |       // If there is an invalid declaration specifier right after the function | 
 | 1029 |       // prototype, then we must be in a missing semicolon case where this isn't | 
 | 1030 |       // actually a body.  Just fall through into the code that handles it as a | 
 | 1031 |       // prototype, and let the top-level code handle the erroneous declspec | 
 | 1032 |       // where it would otherwise expect a comma or semicolon. | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1033 |     } else { | 
 | 1034 |       Diag(Tok, diag::err_expected_fn_body); | 
 | 1035 |       SkipUntil(tok::semi); | 
 | 1036 |       return DeclGroupPtrTy(); | 
 | 1037 |     } | 
 | 1038 |   } | 
 | 1039 |  | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1040 |   if (ParseAttributesAfterDeclarator(D)) | 
 | 1041 |     return DeclGroupPtrTy(); | 
 | 1042 |  | 
 | 1043 |   // C++0x [stmt.iter]p1: Check if we have a for-range-declarator. If so, we | 
 | 1044 |   // must parse and analyze the for-range-initializer before the declaration is | 
 | 1045 |   // analyzed. | 
 | 1046 |   if (FRI && Tok.is(tok::colon)) { | 
 | 1047 |     FRI->ColonLoc = ConsumeToken(); | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1048 |     if (Tok.is(tok::l_brace)) | 
 | 1049 |       FRI->RangeExpr = ParseBraceInitializer(); | 
 | 1050 |     else | 
 | 1051 |       FRI->RangeExpr = ParseExpression(); | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1052 |     Decl *ThisDecl = Actions.ActOnDeclarator(getCurScope(), D); | 
 | 1053 |     Actions.ActOnCXXForRangeDecl(ThisDecl); | 
 | 1054 |     Actions.FinalizeDeclaration(ThisDecl); | 
 | 1055 |     return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, &ThisDecl, 1); | 
 | 1056 |   } | 
 | 1057 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1058 |   SmallVector<Decl *, 8> DeclsInGroup; | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1059 |   Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(D); | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1060 |   D.complete(FirstDecl); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1061 |   if (FirstDecl) | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1062 |     DeclsInGroup.push_back(FirstDecl); | 
 | 1063 |  | 
 | 1064 |   // If we don't have a comma, it is either the end of the list (a ';') or an | 
 | 1065 |   // error, bail out. | 
 | 1066 |   while (Tok.is(tok::comma)) { | 
 | 1067 |     // Consume the comma. | 
| Chris Lattner | 23c4b18 | 2009-03-29 17:18:04 +0000 | [diff] [blame] | 1068 |     ConsumeToken(); | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1069 |  | 
 | 1070 |     // Parse the next declarator. | 
 | 1071 |     D.clear(); | 
 | 1072 |  | 
 | 1073 |     // Accept attributes in an init-declarator.  In the first declarator in a | 
 | 1074 |     // declaration, these would be part of the declspec.  In subsequent | 
 | 1075 |     // declarators, they become part of the declarator itself, so that they | 
 | 1076 |     // don't apply to declarators after *this* one.  Examples: | 
 | 1077 |     //    short __attribute__((common)) var;    -> declspec | 
 | 1078 |     //    short var __attribute__((common));    -> declarator | 
 | 1079 |     //    short x, __attribute__((common)) var;    -> declarator | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1080 |     MaybeParseGNUAttributes(D); | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1081 |  | 
 | 1082 |     ParseDeclarator(D); | 
 | 1083 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1084 |     Decl *ThisDecl = ParseDeclarationAfterDeclarator(D); | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1085 |     D.complete(ThisDecl); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1086 |     if (ThisDecl) | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1087 |       DeclsInGroup.push_back(ThisDecl);     | 
 | 1088 |   } | 
 | 1089 |  | 
 | 1090 |   if (DeclEnd) | 
 | 1091 |     *DeclEnd = Tok.getLocation(); | 
 | 1092 |  | 
 | 1093 |   if (Context != Declarator::ForContext && | 
 | 1094 |       ExpectAndConsume(tok::semi, | 
 | 1095 |                        Context == Declarator::FileContext | 
 | 1096 |                          ? diag::err_invalid_token_after_toplevel_declarator | 
 | 1097 |                          : diag::err_expected_semi_declaration)) { | 
| Chris Lattner | 004659a | 2010-07-11 22:42:07 +0000 | [diff] [blame] | 1098 |     // Okay, there was no semicolon and one was expected.  If we see a | 
 | 1099 |     // declaration specifier, just assume it was missing and continue parsing. | 
 | 1100 |     // Otherwise things are very confused and we skip to recover. | 
 | 1101 |     if (!isDeclarationSpecifier()) { | 
 | 1102 |       SkipUntil(tok::r_brace, true, true); | 
 | 1103 |       if (Tok.is(tok::semi)) | 
 | 1104 |         ConsumeToken(); | 
 | 1105 |     } | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1106 |   } | 
 | 1107 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1108 |   return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, | 
| John McCall | d8ac057 | 2009-11-03 19:26:08 +0000 | [diff] [blame] | 1109 |                                          DeclsInGroup.data(), | 
 | 1110 |                                          DeclsInGroup.size()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1111 | } | 
 | 1112 |  | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1113 | /// Parse an optional simple-asm-expr and attributes, and attach them to a | 
 | 1114 | /// declarator. Returns true on an error. | 
 | 1115 | bool Parser::ParseAttributesAfterDeclarator(Declarator &D) { | 
 | 1116 |   // If a simple-asm-expr is present, parse it. | 
 | 1117 |   if (Tok.is(tok::kw_asm)) { | 
 | 1118 |     SourceLocation Loc; | 
 | 1119 |     ExprResult AsmLabel(ParseSimpleAsm(&Loc)); | 
 | 1120 |     if (AsmLabel.isInvalid()) { | 
 | 1121 |       SkipUntil(tok::semi, true, true); | 
 | 1122 |       return true; | 
 | 1123 |     } | 
 | 1124 |  | 
 | 1125 |     D.setAsmLabel(AsmLabel.release()); | 
 | 1126 |     D.SetRangeEnd(Loc); | 
 | 1127 |   } | 
 | 1128 |  | 
 | 1129 |   MaybeParseGNUAttributes(D); | 
 | 1130 |   return false; | 
 | 1131 | } | 
 | 1132 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1133 | /// \brief Parse 'declaration' after parsing 'declaration-specifiers | 
 | 1134 | /// declarator'. This method parses the remainder of the declaration | 
 | 1135 | /// (including any attributes or initializer, among other things) and | 
 | 1136 | /// finalizes the declaration. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1137 | /// | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1138 | ///       init-declarator: [C99 6.7] | 
 | 1139 | ///         declarator | 
 | 1140 | ///         declarator '=' initializer | 
 | 1141 | /// [GNU]   declarator simple-asm-expr[opt] attributes[opt] | 
 | 1142 | /// [GNU]   declarator simple-asm-expr[opt] attributes[opt] '=' initializer | 
| Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1143 | /// [C++]   declarator initializer[opt] | 
 | 1144 | /// | 
 | 1145 | /// [C++] initializer: | 
 | 1146 | /// [C++]   '=' initializer-clause | 
 | 1147 | /// [C++]   '(' expression-list ')' | 
| Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 1148 | /// [C++0x] '=' 'default'                                                [TODO] | 
 | 1149 | /// [C++0x] '=' 'delete' | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1150 | /// [C++0x] braced-init-list | 
| Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 1151 | /// | 
 | 1152 | /// According to the standard grammar, =default and =delete are function | 
 | 1153 | /// definitions, but that definitely doesn't fit with the parser here. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1154 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1155 | Decl *Parser::ParseDeclarationAfterDeclarator(Declarator &D, | 
| Douglas Gregor | e542c86 | 2009-06-23 23:11:28 +0000 | [diff] [blame] | 1156 |                                      const ParsedTemplateInfo &TemplateInfo) { | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1157 |   if (ParseAttributesAfterDeclarator(D)) | 
 | 1158 |     return 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 |  | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1160 |   return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo); | 
 | 1161 | } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 |  | 
| Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1163 | Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D, | 
 | 1164 |                                      const ParsedTemplateInfo &TemplateInfo) { | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1165 |   // Inform the current actions module that we just parsed this declarator. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1166 |   Decl *ThisDecl = 0; | 
| Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 1167 |   switch (TemplateInfo.Kind) { | 
 | 1168 |   case ParsedTemplateInfo::NonTemplate: | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1169 |     ThisDecl = Actions.ActOnDeclarator(getCurScope(), D); | 
| Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 1170 |     break; | 
 | 1171 |        | 
 | 1172 |   case ParsedTemplateInfo::Template: | 
 | 1173 |   case ParsedTemplateInfo::ExplicitSpecialization: | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1174 |     ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(), | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1175 |                              MultiTemplateParamsArg(Actions, | 
| Douglas Gregor | e542c86 | 2009-06-23 23:11:28 +0000 | [diff] [blame] | 1176 |                                           TemplateInfo.TemplateParams->data(), | 
 | 1177 |                                           TemplateInfo.TemplateParams->size()), | 
| Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 1178 |                                                D); | 
 | 1179 |     break; | 
 | 1180 |        | 
 | 1181 |   case ParsedTemplateInfo::ExplicitInstantiation: { | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1182 |     DeclResult ThisRes  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1183 |       = Actions.ActOnExplicitInstantiation(getCurScope(), | 
| Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 1184 |                                            TemplateInfo.ExternLoc, | 
 | 1185 |                                            TemplateInfo.TemplateLoc, | 
 | 1186 |                                            D); | 
 | 1187 |     if (ThisRes.isInvalid()) { | 
 | 1188 |       SkipUntil(tok::semi, true, true); | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1189 |       return 0; | 
| Douglas Gregor | d5a423b | 2009-09-25 18:43:00 +0000 | [diff] [blame] | 1190 |     } | 
 | 1191 |      | 
 | 1192 |     ThisDecl = ThisRes.get(); | 
 | 1193 |     break; | 
 | 1194 |     } | 
 | 1195 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 |  | 
| Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1197 |   bool TypeContainsAuto = | 
 | 1198 |     D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto; | 
 | 1199 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1200 |   // Parse declarator '=' initializer. | 
| Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 1201 |   if (isTokenEqualOrMistypedEqualEqual( | 
 | 1202 |                                diag::err_invalid_equalequal_after_declarator)) { | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1203 |     ConsumeToken(); | 
| Anders Carlsson | 37bf9d2 | 2010-09-24 21:25:25 +0000 | [diff] [blame] | 1204 |     if (Tok.is(tok::kw_delete)) { | 
| Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1205 |       if (D.isFunctionDeclarator()) | 
 | 1206 |         Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) | 
 | 1207 |           << 1 /* delete */; | 
 | 1208 |       else | 
 | 1209 |         Diag(ConsumeToken(), diag::err_deleted_non_function); | 
| Sean Hunt | fe2695e | 2011-05-06 01:42:00 +0000 | [diff] [blame] | 1210 |     } else if (Tok.is(tok::kw_default)) { | 
| Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 1211 |       if (D.isFunctionDeclarator()) | 
 | 1212 |         Diag(Tok, diag::err_default_delete_in_multiple_declaration) | 
 | 1213 |           << 1 /* delete */; | 
 | 1214 |       else | 
 | 1215 |         Diag(ConsumeToken(), diag::err_default_special_members); | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1216 |     } else { | 
| John McCall | 731ad84 | 2009-12-19 09:28:58 +0000 | [diff] [blame] | 1217 |       if (getLang().CPlusPlus && D.getCXXScopeSpec().isSet()) { | 
 | 1218 |         EnterScope(0); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1219 |         Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); | 
| John McCall | 731ad84 | 2009-12-19 09:28:58 +0000 | [diff] [blame] | 1220 |       } | 
| Argyrios Kyrtzidis | 0ffd9ff | 2009-06-17 22:50:06 +0000 | [diff] [blame] | 1221 |  | 
| Douglas Gregor | 5ac3bdb | 2010-05-30 01:49:25 +0000 | [diff] [blame] | 1222 |       if (Tok.is(tok::code_completion)) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1223 |         Actions.CodeCompleteInitializer(getCurScope(), ThisDecl); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1224 |         cutOffParsing(); | 
 | 1225 |         return 0; | 
| Douglas Gregor | 5ac3bdb | 2010-05-30 01:49:25 +0000 | [diff] [blame] | 1226 |       } | 
 | 1227 |        | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1228 |       ExprResult Init(ParseInitializer()); | 
| Argyrios Kyrtzidis | 0ffd9ff | 2009-06-17 22:50:06 +0000 | [diff] [blame] | 1229 |  | 
| John McCall | 731ad84 | 2009-12-19 09:28:58 +0000 | [diff] [blame] | 1230 |       if (getLang().CPlusPlus && D.getCXXScopeSpec().isSet()) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1231 |         Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); | 
| John McCall | 731ad84 | 2009-12-19 09:28:58 +0000 | [diff] [blame] | 1232 |         ExitScope(); | 
 | 1233 |       } | 
| Argyrios Kyrtzidis | 0ffd9ff | 2009-06-17 22:50:06 +0000 | [diff] [blame] | 1234 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1235 |       if (Init.isInvalid()) { | 
| Douglas Gregor | 0022554 | 2010-03-01 18:27:54 +0000 | [diff] [blame] | 1236 |         SkipUntil(tok::comma, true, true); | 
 | 1237 |         Actions.ActOnInitializerError(ThisDecl); | 
 | 1238 |       } else | 
| Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1239 |         Actions.AddInitializerToDecl(ThisDecl, Init.take(), | 
 | 1240 |                                      /*DirectInit=*/false, TypeContainsAuto); | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1241 |     } | 
 | 1242 |   } else if (Tok.is(tok::l_paren)) { | 
 | 1243 |     // Parse C++ direct initializer: '(' expression-list ')' | 
 | 1244 |     SourceLocation LParenLoc = ConsumeParen(); | 
 | 1245 |     ExprVector Exprs(Actions); | 
 | 1246 |     CommaLocsTy CommaLocs; | 
 | 1247 |  | 
| Douglas Gregor | b4debae | 2009-12-22 17:47:17 +0000 | [diff] [blame] | 1248 |     if (getLang().CPlusPlus && D.getCXXScopeSpec().isSet()) { | 
 | 1249 |       EnterScope(0); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1250 |       Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); | 
| Douglas Gregor | b4debae | 2009-12-22 17:47:17 +0000 | [diff] [blame] | 1251 |     } | 
 | 1252 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1253 |     if (ParseExpressionList(Exprs, CommaLocs)) { | 
 | 1254 |       SkipUntil(tok::r_paren); | 
| Douglas Gregor | b4debae | 2009-12-22 17:47:17 +0000 | [diff] [blame] | 1255 |  | 
 | 1256 |       if (getLang().CPlusPlus && D.getCXXScopeSpec().isSet()) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1257 |         Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); | 
| Douglas Gregor | b4debae | 2009-12-22 17:47:17 +0000 | [diff] [blame] | 1258 |         ExitScope(); | 
 | 1259 |       } | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1260 |     } else { | 
 | 1261 |       // Match the ')'. | 
 | 1262 |       SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); | 
 | 1263 |  | 
 | 1264 |       assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() && | 
 | 1265 |              "Unexpected number of commas!"); | 
| Douglas Gregor | b4debae | 2009-12-22 17:47:17 +0000 | [diff] [blame] | 1266 |  | 
 | 1267 |       if (getLang().CPlusPlus && D.getCXXScopeSpec().isSet()) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1268 |         Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); | 
| Douglas Gregor | b4debae | 2009-12-22 17:47:17 +0000 | [diff] [blame] | 1269 |         ExitScope(); | 
 | 1270 |       } | 
 | 1271 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1272 |       Actions.AddCXXDirectInitializerToDecl(ThisDecl, LParenLoc, | 
 | 1273 |                                             move_arg(Exprs), | 
| Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1274 |                                             RParenLoc, | 
 | 1275 |                                             TypeContainsAuto); | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1276 |     } | 
| Sebastian Redl | dbef1bb | 2011-06-05 12:23:16 +0000 | [diff] [blame] | 1277 |   } else if (getLang().CPlusPlus0x && Tok.is(tok::l_brace)) { | 
 | 1278 |     // Parse C++0x braced-init-list. | 
 | 1279 |     if (D.getCXXScopeSpec().isSet()) { | 
 | 1280 |       EnterScope(0); | 
 | 1281 |       Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl); | 
 | 1282 |     } | 
 | 1283 |  | 
 | 1284 |     ExprResult Init(ParseBraceInitializer()); | 
 | 1285 |  | 
 | 1286 |     if (D.getCXXScopeSpec().isSet()) { | 
 | 1287 |       Actions.ActOnCXXExitDeclInitializer(getCurScope(), ThisDecl); | 
 | 1288 |       ExitScope(); | 
 | 1289 |     } | 
 | 1290 |  | 
 | 1291 |     if (Init.isInvalid()) { | 
 | 1292 |       Actions.ActOnInitializerError(ThisDecl); | 
 | 1293 |     } else | 
 | 1294 |       Actions.AddInitializerToDecl(ThisDecl, Init.take(), | 
 | 1295 |                                    /*DirectInit=*/true, TypeContainsAuto); | 
 | 1296 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1297 |   } else { | 
| Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1298 |     Actions.ActOnUninitializedDecl(ThisDecl, TypeContainsAuto); | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1299 |   } | 
 | 1300 |  | 
| Richard Smith | 483b9f3 | 2011-02-21 20:05:19 +0000 | [diff] [blame] | 1301 |   Actions.FinalizeDeclaration(ThisDecl); | 
 | 1302 |  | 
| Douglas Gregor | 1426e53 | 2009-05-12 21:31:51 +0000 | [diff] [blame] | 1303 |   return ThisDecl; | 
 | 1304 | } | 
 | 1305 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1306 | /// ParseSpecifierQualifierList | 
 | 1307 | ///        specifier-qualifier-list: | 
 | 1308 | ///          type-specifier specifier-qualifier-list[opt] | 
 | 1309 | ///          type-qualifier specifier-qualifier-list[opt] | 
 | 1310 | /// [GNU]    attributes     specifier-qualifier-list[opt] | 
 | 1311 | /// | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 1312 | void Parser::ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1313 |   /// specifier-qualifier-list is a subset of declaration-specifiers.  Just | 
 | 1314 |   /// parse declaration-specifiers and complain about extra stuff. | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 1315 |   /// TODO: diagnose attribute-specifiers and alignment-specifiers. | 
| Richard Smith | c89edf5 | 2011-07-01 19:46:12 +0000 | [diff] [blame] | 1316 |   ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1318 |   // Validate declspec for type-name. | 
 | 1319 |   unsigned Specs = DS.getParsedSpecifiers(); | 
| Chris Lattner | b6645dd | 2009-04-14 21:16:09 +0000 | [diff] [blame] | 1320 |   if (Specs == DeclSpec::PQ_None && !DS.getNumProtocolQualifiers() && | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1321 |       !DS.hasAttributes()) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1322 |     Diag(Tok, diag::err_typename_requires_specqual); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1324 |   // Issue diagnostic and remove storage class if present. | 
 | 1325 |   if (Specs & DeclSpec::PQ_StorageClassSpecifier) { | 
 | 1326 |     if (DS.getStorageClassSpecLoc().isValid()) | 
 | 1327 |       Diag(DS.getStorageClassSpecLoc(),diag::err_typename_invalid_storageclass); | 
 | 1328 |     else | 
 | 1329 |       Diag(DS.getThreadSpecLoc(), diag::err_typename_invalid_storageclass); | 
 | 1330 |     DS.ClearStorageClassSpecs(); | 
 | 1331 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1332 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1333 |   // Issue diagnostic and remove function specfier if present. | 
 | 1334 |   if (Specs & DeclSpec::PQ_FunctionSpecifier) { | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1335 |     if (DS.isInlineSpecified()) | 
 | 1336 |       Diag(DS.getInlineSpecLoc(), diag::err_typename_invalid_functionspec); | 
 | 1337 |     if (DS.isVirtualSpecified()) | 
 | 1338 |       Diag(DS.getVirtualSpecLoc(), diag::err_typename_invalid_functionspec); | 
 | 1339 |     if (DS.isExplicitSpecified()) | 
 | 1340 |       Diag(DS.getExplicitSpecLoc(), diag::err_typename_invalid_functionspec); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1341 |     DS.ClearFunctionSpecs(); | 
 | 1342 |   } | 
 | 1343 | } | 
 | 1344 |  | 
| Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 1345 | /// isValidAfterIdentifierInDeclaratorAfterDeclSpec - Return true if the | 
 | 1346 | /// specified token is valid after the identifier in a declarator which | 
 | 1347 | /// immediately follows the declspec.  For example, these things are valid: | 
 | 1348 | /// | 
 | 1349 | ///      int x   [             4];         // direct-declarator | 
 | 1350 | ///      int x   (             int y);     // direct-declarator | 
 | 1351 | ///  int(int x   )                         // direct-declarator | 
 | 1352 | ///      int x   ;                         // simple-declaration | 
 | 1353 | ///      int x   =             17;         // init-declarator-list | 
 | 1354 | ///      int x   ,             y;          // init-declarator-list | 
 | 1355 | ///      int x   __asm__       ("foo");    // init-declarator-list | 
| Chris Lattner | b6645dd | 2009-04-14 21:16:09 +0000 | [diff] [blame] | 1356 | ///      int x   :             4;          // struct-declarator | 
| Chris Lattner | c83c27a | 2009-04-12 22:29:43 +0000 | [diff] [blame] | 1357 | ///      int x   {             5};         // C++'0x unified initializers | 
| Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 1358 | /// | 
 | 1359 | /// This is not, because 'x' does not immediately follow the declspec (though | 
 | 1360 | /// ')' happens to be valid anyway). | 
 | 1361 | ///    int (x) | 
 | 1362 | /// | 
 | 1363 | static bool isValidAfterIdentifierInDeclarator(const Token &T) { | 
 | 1364 |   return T.is(tok::l_square) || T.is(tok::l_paren) || T.is(tok::r_paren) || | 
 | 1365 |          T.is(tok::semi) || T.is(tok::comma) || T.is(tok::equal) || | 
| Chris Lattner | b6645dd | 2009-04-14 21:16:09 +0000 | [diff] [blame] | 1366 |          T.is(tok::kw_asm) || T.is(tok::l_brace) || T.is(tok::colon); | 
| Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 1367 | } | 
 | 1368 |  | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1369 |  | 
 | 1370 | /// ParseImplicitInt - This method is called when we have an non-typename | 
 | 1371 | /// identifier in a declspec (which normally terminates the decl spec) when | 
 | 1372 | /// the declspec has no type specifier.  In this case, the declspec is either | 
 | 1373 | /// malformed or is "implicit int" (in K&R and C89). | 
 | 1374 | /// | 
 | 1375 | /// This method handles diagnosing this prettily and returns false if the | 
 | 1376 | /// declspec is done being processed.  If it recovers and thinks there may be | 
 | 1377 | /// other pieces of declspec after it, it returns true. | 
 | 1378 | /// | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1379 | bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1380 |                               const ParsedTemplateInfo &TemplateInfo, | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1381 |                               AccessSpecifier AS) { | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1382 |   assert(Tok.is(tok::identifier) && "should have identifier"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1383 |  | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1384 |   SourceLocation Loc = Tok.getLocation(); | 
 | 1385 |   // If we see an identifier that is not a type name, we normally would | 
 | 1386 |   // parse it as the identifer being declared.  However, when a typename | 
 | 1387 |   // is typo'd or the definition is not included, this will incorrectly | 
 | 1388 |   // parse the typename as the identifier name and fall over misparsing | 
 | 1389 |   // later parts of the diagnostic. | 
 | 1390 |   // | 
 | 1391 |   // As such, we try to do some look-ahead in cases where this would | 
 | 1392 |   // otherwise be an "implicit-int" case to see if this is invalid.  For | 
 | 1393 |   // example: "static foo_t x = 4;"  In this case, if we parsed foo_t as | 
 | 1394 |   // an identifier with implicit int, we'd get a parse error because the | 
 | 1395 |   // next token is obviously invalid for a type.  Parse these as a case | 
 | 1396 |   // with an invalid type specifier. | 
 | 1397 |   assert(!DS.hasTypeSpecifier() && "Type specifier checked above"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 |  | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1399 |   // Since we know that this either implicit int (which is rare) or an | 
 | 1400 |   // error, we'd do lookahead to try to do better recovery. | 
 | 1401 |   if (isValidAfterIdentifierInDeclarator(NextToken())) { | 
 | 1402 |     // If this token is valid for implicit int, e.g. "static x = 4", then | 
 | 1403 |     // we just avoid eating the identifier, so it will be parsed as the | 
 | 1404 |     // identifier in the declarator. | 
 | 1405 |     return false; | 
 | 1406 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 |  | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1408 |   // Otherwise, if we don't consume this token, we are going to emit an | 
 | 1409 |   // error anyway.  Try to recover from various common problems.  Check | 
 | 1410 |   // to see if this was a reference to a tag name without a tag specified. | 
 | 1411 |   // This is a common problem in C (saying 'foo' instead of 'struct foo'). | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1412 |   // | 
 | 1413 |   // C++ doesn't need this, and isTagName doesn't take SS. | 
 | 1414 |   if (SS == 0) { | 
| Argyrios Kyrtzidis | b8a9d3b | 2011-04-21 17:29:47 +0000 | [diff] [blame] | 1415 |     const char *TagName = 0, *FixitTagName = 0; | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1416 |     tok::TokenKind TagKind = tok::unknown; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1417 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1418 |     switch (Actions.isTagName(*Tok.getIdentifierInfo(), getCurScope())) { | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1419 |       default: break; | 
| Argyrios Kyrtzidis | b8a9d3b | 2011-04-21 17:29:47 +0000 | [diff] [blame] | 1420 |       case DeclSpec::TST_enum: | 
 | 1421 |         TagName="enum"  ; FixitTagName = "enum "  ; TagKind=tok::kw_enum ;break; | 
 | 1422 |       case DeclSpec::TST_union: | 
 | 1423 |         TagName="union" ; FixitTagName = "union " ;TagKind=tok::kw_union ;break; | 
 | 1424 |       case DeclSpec::TST_struct: | 
 | 1425 |         TagName="struct"; FixitTagName = "struct ";TagKind=tok::kw_struct;break; | 
 | 1426 |       case DeclSpec::TST_class: | 
 | 1427 |         TagName="class" ; FixitTagName = "class " ;TagKind=tok::kw_class ;break; | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1428 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1429 |  | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1430 |     if (TagName) { | 
 | 1431 |       Diag(Loc, diag::err_use_of_tag_name_without_tag) | 
| John McCall | 23e907a | 2010-02-14 01:03:10 +0000 | [diff] [blame] | 1432 |         << Tok.getIdentifierInfo() << TagName << getLang().CPlusPlus | 
| Argyrios Kyrtzidis | b8a9d3b | 2011-04-21 17:29:47 +0000 | [diff] [blame] | 1433 |         << FixItHint::CreateInsertion(Tok.getLocation(),FixitTagName); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 |  | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1435 |       // Parse this as a tag as if the missing tag were present. | 
 | 1436 |       if (TagKind == tok::kw_enum) | 
| Douglas Gregor | 9b9edd6 | 2010-03-02 17:53:14 +0000 | [diff] [blame] | 1437 |         ParseEnumSpecifier(Loc, DS, TemplateInfo, AS); | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1438 |       else | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1439 |         ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS); | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1440 |       return true; | 
 | 1441 |     } | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1442 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 |  | 
| Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 1444 |   // This is almost certainly an invalid type name. Let the action emit a  | 
 | 1445 |   // diagnostic and attempt to recover. | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1446 |   ParsedType T; | 
| Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 1447 |   if (Actions.DiagnoseUnknownTypeName(*Tok.getIdentifierInfo(), Loc, | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1448 |                                       getCurScope(), SS, T)) { | 
| Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 1449 |     // The action emitted a diagnostic, so we don't have to. | 
 | 1450 |     if (T) { | 
 | 1451 |       // The action has suggested that the type T could be used. Set that as | 
 | 1452 |       // the type in the declaration specifiers, consume the would-be type | 
 | 1453 |       // name token, and we're done. | 
 | 1454 |       const char *PrevSpec; | 
 | 1455 |       unsigned DiagID; | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1456 |       DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, T); | 
| Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 1457 |       DS.SetRangeEnd(Tok.getLocation()); | 
 | 1458 |       ConsumeToken(); | 
 | 1459 |        | 
 | 1460 |       // There may be other declaration specifiers after this. | 
 | 1461 |       return true; | 
 | 1462 |     } | 
 | 1463 |      | 
 | 1464 |     // Fall through; the action had no suggestion for us. | 
 | 1465 |   } else { | 
 | 1466 |     // The action did not emit a diagnostic, so emit one now. | 
 | 1467 |     SourceRange R; | 
 | 1468 |     if (SS) R = SS->getRange(); | 
 | 1469 |     Diag(Loc, diag::err_unknown_typename) << Tok.getIdentifierInfo() << R; | 
 | 1470 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1471 |  | 
| Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 1472 |   // Mark this as an error. | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1473 |   const char *PrevSpec; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1474 |   unsigned DiagID; | 
 | 1475 |   DS.SetTypeSpecType(DeclSpec::TST_error, Loc, PrevSpec, DiagID); | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1476 |   DS.SetRangeEnd(Tok.getLocation()); | 
 | 1477 |   ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1478 |  | 
| Chris Lattner | e40c295 | 2009-04-14 21:34:55 +0000 | [diff] [blame] | 1479 |   // TODO: Could inject an invalid typedef decl in an enclosing scope to | 
 | 1480 |   // avoid rippling error messages on subsequent uses of the same type, | 
 | 1481 |   // could be useful if #include was forgotten. | 
 | 1482 |   return false; | 
 | 1483 | } | 
 | 1484 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1485 | /// \brief Determine the declaration specifier context from the declarator | 
 | 1486 | /// context. | 
 | 1487 | /// | 
 | 1488 | /// \param Context the declarator context, which is one of the | 
 | 1489 | /// Declarator::TheContext enumerator values. | 
 | 1490 | Parser::DeclSpecContext  | 
 | 1491 | Parser::getDeclSpecContextFromDeclaratorContext(unsigned Context) { | 
 | 1492 |   if (Context == Declarator::MemberContext) | 
 | 1493 |     return DSC_class; | 
 | 1494 |   if (Context == Declarator::FileContext) | 
 | 1495 |     return DSC_top_level; | 
 | 1496 |   return DSC_normal; | 
 | 1497 | } | 
 | 1498 |  | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 1499 | /// ParseAlignArgument - Parse the argument to an alignment-specifier. | 
 | 1500 | /// | 
 | 1501 | /// FIXME: Simply returns an alignof() expression if the argument is a | 
 | 1502 | /// type. Ideally, the type should be propagated directly into Sema. | 
 | 1503 | /// | 
 | 1504 | /// [C1X/C++0x] type-id | 
 | 1505 | /// [C1X]       constant-expression | 
 | 1506 | /// [C++0x]     assignment-expression | 
 | 1507 | ExprResult Parser::ParseAlignArgument(SourceLocation Start) { | 
 | 1508 |   if (isTypeIdInParens()) { | 
 | 1509 |     EnterExpressionEvaluationContext Unevaluated(Actions, Sema::Unevaluated); | 
 | 1510 |     SourceLocation TypeLoc = Tok.getLocation(); | 
 | 1511 |     ParsedType Ty = ParseTypeName().get(); | 
 | 1512 |     SourceRange TypeRange(Start, Tok.getLocation()); | 
 | 1513 |     return Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, | 
 | 1514 |                                                 Ty.getAsOpaquePtr(), TypeRange); | 
 | 1515 |   } else | 
 | 1516 |     return ParseConstantExpression(); | 
 | 1517 | } | 
 | 1518 |  | 
 | 1519 | /// ParseAlignmentSpecifier - Parse an alignment-specifier, and add the | 
 | 1520 | /// attribute to Attrs. | 
 | 1521 | /// | 
 | 1522 | /// alignment-specifier: | 
 | 1523 | /// [C1X]   '_Alignas' '(' type-id ')' | 
 | 1524 | /// [C1X]   '_Alignas' '(' constant-expression ')' | 
 | 1525 | /// [C++0x] 'alignas' '(' type-id ')' | 
 | 1526 | /// [C++0x] 'alignas' '(' assignment-expression ')' | 
 | 1527 | void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, | 
 | 1528 |                                      SourceLocation *endLoc) { | 
 | 1529 |   assert((Tok.is(tok::kw_alignas) || Tok.is(tok::kw__Alignas)) && | 
 | 1530 |          "Not an alignment-specifier!"); | 
 | 1531 |  | 
 | 1532 |   SourceLocation KWLoc = Tok.getLocation(); | 
 | 1533 |   ConsumeToken(); | 
 | 1534 |  | 
 | 1535 |   SourceLocation ParamLoc = Tok.getLocation(); | 
 | 1536 |   if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen)) | 
 | 1537 |     return; | 
 | 1538 |  | 
 | 1539 |   ExprResult ArgExpr = ParseAlignArgument(ParamLoc); | 
 | 1540 |   if (ArgExpr.isInvalid()) { | 
 | 1541 |     SkipUntil(tok::r_paren); | 
 | 1542 |     return; | 
 | 1543 |   } | 
 | 1544 |  | 
 | 1545 |   SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, ParamLoc); | 
 | 1546 |   if (endLoc) | 
 | 1547 |     *endLoc = RParenLoc; | 
 | 1548 |  | 
 | 1549 |   ExprVector ArgExprs(Actions); | 
 | 1550 |   ArgExprs.push_back(ArgExpr.release()); | 
 | 1551 |   Attrs.addNew(PP.getIdentifierInfo("aligned"), KWLoc, 0, KWLoc, | 
 | 1552 |                0, ParamLoc, ArgExprs.take(), 1, false, true); | 
 | 1553 | } | 
 | 1554 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1555 | /// ParseDeclarationSpecifiers | 
 | 1556 | ///       declaration-specifiers: [C99 6.7] | 
 | 1557 | ///         storage-class-specifier declaration-specifiers[opt] | 
 | 1558 | ///         type-specifier declaration-specifiers[opt] | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1559 | /// [C99]   function-specifier declaration-specifiers[opt] | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 1560 | /// [C1X]   alignment-specifier declaration-specifiers[opt] | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1561 | /// [GNU]   attributes declaration-specifiers[opt] | 
| Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 1562 | /// [Clang] '__module_private__' declaration-specifiers[opt] | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1563 | /// | 
 | 1564 | ///       storage-class-specifier: [C99 6.7.1] | 
 | 1565 | ///         'typedef' | 
 | 1566 | ///         'extern' | 
 | 1567 | ///         'static' | 
 | 1568 | ///         'auto' | 
 | 1569 | ///         'register' | 
| Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 1570 | /// [C++]   'mutable' | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1571 | /// [GNU]   '__thread' | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1572 | ///       function-specifier: [C99 6.7.4] | 
 | 1573 | /// [C99]   'inline' | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1574 | /// [C++]   'virtual' | 
 | 1575 | /// [C++]   'explicit' | 
| Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1576 | /// [OpenCL] '__kernel' | 
| Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 1577 | ///       'friend': [C++ dcl.friend] | 
| Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 1578 | ///       'constexpr': [C++0x dcl.constexpr] | 
| Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 1579 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1580 | /// | 
| Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 1581 | void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1582 |                                         const ParsedTemplateInfo &TemplateInfo, | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1583 |                                         AccessSpecifier AS, | 
| Douglas Gregor | 312eadb | 2011-04-24 05:37:28 +0000 | [diff] [blame] | 1584 |                                         DeclSpecContext DSContext) {  | 
 | 1585 |   if (DS.getSourceRange().isInvalid()) { | 
 | 1586 |     DS.SetRangeStart(Tok.getLocation()); | 
 | 1587 |     DS.SetRangeEnd(Tok.getLocation()); | 
 | 1588 |   } | 
 | 1589 |    | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1590 |   while (1) { | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1591 |     bool isInvalid = false; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1592 |     const char *PrevSpec = 0; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1593 |     unsigned DiagID = 0; | 
 | 1594 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1595 |     SourceLocation Loc = Tok.getLocation(); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 1596 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1597 |     switch (Tok.getKind()) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1598 |     default: | 
| Chris Lattner | bce6135 | 2008-07-26 00:20:22 +0000 | [diff] [blame] | 1599 |     DoneWithDeclSpec: | 
| Peter Collingbourne | f190768 | 2011-09-29 18:03:57 +0000 | [diff] [blame] | 1600 |       // [C++0x] decl-specifier-seq: decl-specifier attribute-specifier-seq[opt] | 
 | 1601 |       MaybeParseCXX0XAttributes(DS.getAttributes()); | 
 | 1602 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1603 |       // If this is not a declaration specifier token, we're done reading decl | 
 | 1604 |       // specifiers.  First verify that DeclSpec's are consistent. | 
| Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 1605 |       DS.Finish(Diags, PP); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1606 |       return; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 |  | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1608 |     case tok::code_completion: { | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1609 |       Sema::ParserCompletionContext CCC = Sema::PCC_Namespace; | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1610 |       if (DS.hasTypeSpecifier()) { | 
 | 1611 |         bool AllowNonIdentifiers | 
 | 1612 |           = (getCurScope()->getFlags() & (Scope::ControlScope | | 
 | 1613 |                                           Scope::BlockScope | | 
 | 1614 |                                           Scope::TemplateParamScope | | 
 | 1615 |                                           Scope::FunctionPrototypeScope | | 
 | 1616 |                                           Scope::AtCatchScope)) == 0; | 
 | 1617 |         bool AllowNestedNameSpecifiers | 
 | 1618 |           = DSContext == DSC_top_level ||  | 
 | 1619 |             (DSContext == DSC_class && DS.isFriendSpecified()); | 
 | 1620 |  | 
| Douglas Gregor | c7b6d88 | 2010-09-16 15:14:18 +0000 | [diff] [blame] | 1621 |         Actions.CodeCompleteDeclSpec(getCurScope(), DS, | 
 | 1622 |                                      AllowNonIdentifiers,  | 
 | 1623 |                                      AllowNestedNameSpecifiers); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1624 |         return cutOffParsing(); | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1625 |       }  | 
 | 1626 |        | 
| Douglas Gregor | 68e3c2e | 2011-02-15 20:33:25 +0000 | [diff] [blame] | 1627 |       if (getCurScope()->getFnParent() || getCurScope()->getBlockParent()) | 
 | 1628 |         CCC = Sema::PCC_LocalDeclarationSpecifiers; | 
 | 1629 |       else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1630 |         CCC = DSContext == DSC_class? Sema::PCC_MemberTemplate  | 
 | 1631 |                                     : Sema::PCC_Template; | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1632 |       else if (DSContext == DSC_class) | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1633 |         CCC = Sema::PCC_Class; | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1634 |       else if (ObjCImpDecl) | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1635 |         CCC = Sema::PCC_ObjCImplementation; | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1636 |        | 
 | 1637 |       Actions.CodeCompleteOrdinaryName(getCurScope(), CCC); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1638 |       return cutOffParsing(); | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 1639 |     } | 
 | 1640 |  | 
| Chris Lattner | 5e02c47 | 2009-01-05 00:07:25 +0000 | [diff] [blame] | 1641 |     case tok::coloncolon: // ::foo::bar | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1642 |       // C++ scope specifier.  Annotate and loop, or bail out on error. | 
 | 1643 |       if (TryAnnotateCXXScopeToken(true)) { | 
 | 1644 |         if (!DS.hasTypeSpecifier()) | 
 | 1645 |           DS.SetTypeSpecError(); | 
 | 1646 |         goto DoneWithDeclSpec; | 
 | 1647 |       } | 
| John McCall | 2e0a715 | 2010-03-01 18:20:46 +0000 | [diff] [blame] | 1648 |       if (Tok.is(tok::coloncolon)) // ::new or ::delete | 
 | 1649 |         goto DoneWithDeclSpec; | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1650 |       continue; | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1651 |  | 
 | 1652 |     case tok::annot_cxxscope: { | 
 | 1653 |       if (DS.hasTypeSpecifier()) | 
 | 1654 |         goto DoneWithDeclSpec; | 
 | 1655 |  | 
| John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1656 |       CXXScopeSpec SS; | 
| Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 1657 |       Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), | 
 | 1658 |                                                    Tok.getAnnotationRange(), | 
 | 1659 |                                                    SS); | 
| John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1660 |  | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1661 |       // We are looking for a qualified typename. | 
| Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 1662 |       Token Next = NextToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1663 |       if (Next.is(tok::annot_template_id) && | 
| Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 1664 |           static_cast<TemplateIdAnnotation *>(Next.getAnnotationValue()) | 
| Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 1665 |             ->Kind == TNK_Type_template) { | 
| Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 1666 |         // We have a qualified template-id, e.g., N::A<int> | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1667 |  | 
 | 1668 |         // C++ [class.qual]p2: | 
 | 1669 |         //   In a lookup in which the constructor is an acceptable lookup | 
 | 1670 |         //   result and the nested-name-specifier nominates a class C: | 
 | 1671 |         // | 
 | 1672 |         //     - if the name specified after the | 
 | 1673 |         //       nested-name-specifier, when looked up in C, is the | 
 | 1674 |         //       injected-class-name of C (Clause 9), or | 
 | 1675 |         // | 
 | 1676 |         //     - if the name specified after the nested-name-specifier | 
 | 1677 |         //       is the same as the identifier or the | 
 | 1678 |         //       simple-template-id's template-name in the last | 
 | 1679 |         //       component of the nested-name-specifier, | 
 | 1680 |         // | 
 | 1681 |         //   the name is instead considered to name the constructor of | 
 | 1682 |         //   class C. | 
 | 1683 |         //  | 
 | 1684 |         // Thus, if the template-name is actually the constructor | 
 | 1685 |         // name, then the code is ill-formed; this interpretation is | 
 | 1686 |         // reinforced by the NAD status of core issue 635.  | 
| Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 1687 |         TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next); | 
| John McCall | ba9d853 | 2010-04-13 06:39:49 +0000 | [diff] [blame] | 1688 |         if ((DSContext == DSC_top_level || | 
 | 1689 |              (DSContext == DSC_class && DS.isFriendSpecified())) && | 
 | 1690 |             TemplateId->Name && | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1691 |             Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) { | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1692 |           if (isConstructorDeclarator()) { | 
 | 1693 |             // The user meant this to be an out-of-line constructor | 
 | 1694 |             // definition, but template arguments are not allowed | 
 | 1695 |             // there.  Just allow this as a constructor; we'll | 
 | 1696 |             // complain about it later. | 
 | 1697 |             goto DoneWithDeclSpec; | 
 | 1698 |           } | 
 | 1699 |  | 
 | 1700 |           // The user meant this to name a type, but it actually names | 
 | 1701 |           // a constructor with some extraneous template | 
 | 1702 |           // arguments. Complain, then parse it as a type as the user | 
 | 1703 |           // intended. | 
 | 1704 |           Diag(TemplateId->TemplateNameLoc, | 
 | 1705 |                diag::err_out_of_line_template_id_names_constructor) | 
 | 1706 |             << TemplateId->Name; | 
 | 1707 |         } | 
 | 1708 |  | 
| John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1709 |         DS.getTypeSpecScope() = SS; | 
 | 1710 |         ConsumeToken(); // The C++ scope. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1711 |         assert(Tok.is(tok::annot_template_id) && | 
| Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 1712 |                "ParseOptionalCXXScopeSpecifier not working"); | 
| Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 1713 |         AnnotateTemplateIdTokenAsType(); | 
| Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 1714 |         continue; | 
 | 1715 |       } | 
 | 1716 |  | 
| Douglas Gregor | 9d7b353 | 2009-09-28 07:26:33 +0000 | [diff] [blame] | 1717 |       if (Next.is(tok::annot_typename)) { | 
| John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1718 |         DS.getTypeSpecScope() = SS; | 
 | 1719 |         ConsumeToken(); // The C++ scope. | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1720 |         if (Tok.getAnnotationValue()) { | 
 | 1721 |           ParsedType T = getTypeAnnotation(Tok); | 
| Nico Weber | 253e80b | 2010-11-22 10:30:56 +0000 | [diff] [blame] | 1722 |           isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, | 
 | 1723 |                                          Tok.getAnnotationEndLoc(),  | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1724 |                                          PrevSpec, DiagID, T); | 
 | 1725 |         } | 
| Douglas Gregor | 9d7b353 | 2009-09-28 07:26:33 +0000 | [diff] [blame] | 1726 |         else | 
 | 1727 |           DS.SetTypeSpecError(); | 
 | 1728 |         DS.SetRangeEnd(Tok.getAnnotationEndLoc()); | 
 | 1729 |         ConsumeToken(); // The typename | 
 | 1730 |       } | 
 | 1731 |  | 
| Douglas Gregor | 9135c72 | 2009-03-25 15:40:00 +0000 | [diff] [blame] | 1732 |       if (Next.isNot(tok::identifier)) | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1733 |         goto DoneWithDeclSpec; | 
 | 1734 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1735 |       // If we're in a context where the identifier could be a class name, | 
 | 1736 |       // check whether this is a constructor declaration. | 
| John McCall | ba9d853 | 2010-04-13 06:39:49 +0000 | [diff] [blame] | 1737 |       if ((DSContext == DSC_top_level || | 
 | 1738 |            (DSContext == DSC_class && DS.isFriendSpecified())) && | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1739 |           Actions.isCurrentClassName(*Next.getIdentifierInfo(), getCurScope(),  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1740 |                                      &SS)) { | 
 | 1741 |         if (isConstructorDeclarator()) | 
 | 1742 |           goto DoneWithDeclSpec; | 
 | 1743 |  | 
 | 1744 |         // As noted in C++ [class.qual]p2 (cited above), when the name | 
 | 1745 |         // of the class is qualified in a context where it could name | 
 | 1746 |         // a constructor, its a constructor name. However, we've | 
 | 1747 |         // looked at the declarator, and the user probably meant this | 
 | 1748 |         // to be a type. Complain that it isn't supposed to be treated | 
 | 1749 |         // as a type, then proceed to parse it as a type. | 
 | 1750 |         Diag(Next.getLocation(), diag::err_out_of_line_type_names_constructor) | 
 | 1751 |           << Next.getIdentifierInfo(); | 
 | 1752 |       } | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1753 |  | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1754 |       ParsedType TypeRep = Actions.getTypeName(*Next.getIdentifierInfo(), | 
 | 1755 |                                                Next.getLocation(), | 
| Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 1756 |                                                getCurScope(), &SS, | 
 | 1757 |                                                false, false, ParsedType(), | 
 | 1758 |                                                /*NonTrivialSourceInfo=*/true); | 
| Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1759 |  | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1760 |       // If the referenced identifier is not a type, then this declspec is | 
 | 1761 |       // erroneous: We already checked about that it has no type specifier, and | 
 | 1762 |       // C++ doesn't have implicit int.  Diagnose it as a typo w.r.t. to the | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 |       // typename. | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1764 |       if (TypeRep == 0) { | 
 | 1765 |         ConsumeToken();   // Eat the scope spec so the identifier is current. | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1766 |         if (ParseImplicitInt(DS, &SS, TemplateInfo, AS)) continue; | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1767 |         goto DoneWithDeclSpec; | 
| Chris Lattner | f4382f5 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 1768 |       } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1769 |  | 
| John McCall | aa87d33 | 2009-12-12 11:40:51 +0000 | [diff] [blame] | 1770 |       DS.getTypeSpecScope() = SS; | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1771 |       ConsumeToken(); // The C++ scope. | 
 | 1772 |  | 
| Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 1773 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1774 |                                      DiagID, TypeRep); | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1775 |       if (isInvalid) | 
 | 1776 |         break; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 |  | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 1778 |       DS.SetRangeEnd(Tok.getLocation()); | 
 | 1779 |       ConsumeToken(); // The typename. | 
 | 1780 |  | 
 | 1781 |       continue; | 
 | 1782 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 |  | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 1784 |     case tok::annot_typename: { | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1785 |       if (Tok.getAnnotationValue()) { | 
 | 1786 |         ParsedType T = getTypeAnnotation(Tok); | 
| Nico Weber | c43271e | 2010-11-22 12:50:03 +0000 | [diff] [blame] | 1787 |         isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1788 |                                        DiagID, T); | 
 | 1789 |       } else | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1790 |         DS.SetTypeSpecError(); | 
| Chris Lattner | 5c5db55 | 2010-04-05 18:18:31 +0000 | [diff] [blame] | 1791 |        | 
 | 1792 |       if (isInvalid) | 
 | 1793 |         break; | 
 | 1794 |  | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 1795 |       DS.SetRangeEnd(Tok.getAnnotationEndLoc()); | 
 | 1796 |       ConsumeToken(); // The typename | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1797 |  | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 1798 |       // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id' | 
 | 1799 |       // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an | 
| Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1800 |       // Objective-C interface.  | 
 | 1801 |       if (Tok.is(tok::less) && getLang().ObjC1) | 
 | 1802 |         ParseObjCProtocolQualifiers(DS); | 
 | 1803 |        | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 1804 |       continue; | 
 | 1805 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1806 |  | 
| Douglas Gregor | bfad915 | 2011-04-28 15:48:45 +0000 | [diff] [blame] | 1807 |     case tok::kw___is_signed: | 
 | 1808 |       // GNU libstdc++ 4.4 uses __is_signed as an identifier, but Clang | 
 | 1809 |       // typically treats it as a trait. If we see __is_signed as it appears | 
 | 1810 |       // in libstdc++, e.g., | 
 | 1811 |       // | 
 | 1812 |       //   static const bool __is_signed; | 
 | 1813 |       // | 
 | 1814 |       // then treat __is_signed as an identifier rather than as a keyword. | 
 | 1815 |       if (DS.getTypeSpecType() == TST_bool && | 
 | 1816 |           DS.getTypeQualifiers() == DeclSpec::TQ_const && | 
 | 1817 |           DS.getStorageClassSpec() == DeclSpec::SCS_static) { | 
 | 1818 |         Tok.getIdentifierInfo()->RevertTokenIDToIdentifier(); | 
 | 1819 |         Tok.setKind(tok::identifier); | 
 | 1820 |       } | 
 | 1821 |  | 
 | 1822 |       // We're done with the declaration-specifiers. | 
 | 1823 |       goto DoneWithDeclSpec; | 
 | 1824 |          | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1825 |       // typedef-name | 
 | 1826 |     case tok::identifier: { | 
| Chris Lattner | 5e02c47 | 2009-01-05 00:07:25 +0000 | [diff] [blame] | 1827 |       // In C++, check to see if this is a scope specifier like foo::bar::, if | 
 | 1828 |       // so handle it as such.  This is important for ctor parsing. | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 1829 |       if (getLang().CPlusPlus) { | 
 | 1830 |         if (TryAnnotateCXXScopeToken(true)) { | 
 | 1831 |           if (!DS.hasTypeSpecifier()) | 
 | 1832 |             DS.SetTypeSpecError(); | 
 | 1833 |           goto DoneWithDeclSpec; | 
 | 1834 |         } | 
 | 1835 |         if (!Tok.is(tok::identifier)) | 
 | 1836 |           continue; | 
 | 1837 |       } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1838 |  | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1839 |       // This identifier can only be a typedef name if we haven't already seen | 
 | 1840 |       // a type-specifier.  Without this check we misparse: | 
 | 1841 |       //  typedef int X; struct Y { short X; };  as 'short int'. | 
 | 1842 |       if (DS.hasTypeSpecifier()) | 
 | 1843 |         goto DoneWithDeclSpec; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 |  | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 1845 |       // Check for need to substitute AltiVec keyword tokens. | 
 | 1846 |       if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid)) | 
 | 1847 |         break; | 
 | 1848 |  | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1849 |       // It has to be available as a typedef too! | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1850 |       ParsedType TypeRep = | 
 | 1851 |         Actions.getTypeName(*Tok.getIdentifierInfo(), | 
 | 1852 |                             Tok.getLocation(), getCurScope()); | 
| Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1853 |  | 
| Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 1854 |       // If this is not a typedef name, don't parse it as part of the declspec, | 
 | 1855 |       // it must be an implicit int or an error. | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1856 |       if (!TypeRep) { | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 1857 |         if (ParseImplicitInt(DS, 0, TemplateInfo, AS)) continue; | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1858 |         goto DoneWithDeclSpec; | 
| Chris Lattner | c199ab3 | 2009-04-12 20:42:31 +0000 | [diff] [blame] | 1859 |       } | 
| Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1860 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1861 |       // If we're in a context where the identifier could be a class name, | 
 | 1862 |       // check whether this is a constructor declaration. | 
 | 1863 |       if (getLang().CPlusPlus && DSContext == DSC_class && | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1864 |           Actions.isCurrentClassName(*Tok.getIdentifierInfo(), getCurScope()) && | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1865 |           isConstructorDeclarator()) | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1866 |         goto DoneWithDeclSpec; | 
 | 1867 |  | 
| Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 1868 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1869 |                                      DiagID, TypeRep); | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1870 |       if (isInvalid) | 
 | 1871 |         break; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 |  | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1873 |       DS.SetRangeEnd(Tok.getLocation()); | 
 | 1874 |       ConsumeToken(); // The identifier | 
 | 1875 |  | 
 | 1876 |       // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id' | 
 | 1877 |       // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an | 
| Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1878 |       // Objective-C interface.  | 
 | 1879 |       if (Tok.is(tok::less) && getLang().ObjC1) | 
 | 1880 |         ParseObjCProtocolQualifiers(DS); | 
 | 1881 |        | 
| Steve Naroff | 4f9b9f1 | 2008-09-22 10:28:57 +0000 | [diff] [blame] | 1882 |       // Need to support trailing type qualifiers (e.g. "id<p> const"). | 
 | 1883 |       // If a type specifier follows, it will be diagnosed elsewhere. | 
 | 1884 |       continue; | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 1885 |     } | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1886 |  | 
 | 1887 |       // type-name | 
 | 1888 |     case tok::annot_template_id: { | 
| Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 1889 |       TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); | 
| Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 1890 |       if (TemplateId->Kind != TNK_Type_template) { | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1891 |         // This template-id does not refer to a type name, so we're | 
 | 1892 |         // done with the type-specifiers. | 
 | 1893 |         goto DoneWithDeclSpec; | 
 | 1894 |       } | 
 | 1895 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1896 |       // If we're in a context where the template-id could be a | 
 | 1897 |       // constructor name or specialization, check whether this is a | 
 | 1898 |       // constructor declaration. | 
 | 1899 |       if (getLang().CPlusPlus && DSContext == DSC_class && | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1900 |           Actions.isCurrentClassName(*TemplateId->Name, getCurScope()) && | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 1901 |           isConstructorDeclarator()) | 
 | 1902 |         goto DoneWithDeclSpec; | 
 | 1903 |  | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1904 |       // Turn the template-id annotation token into a type annotation | 
 | 1905 |       // token, then try again to parse it as a type-specifier. | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 1906 |       AnnotateTemplateIdTokenAsType(); | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 1907 |       continue; | 
 | 1908 |     } | 
 | 1909 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1910 |     // GNU attributes support. | 
 | 1911 |     case tok::kw___attribute: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1912 |       ParseGNUAttributes(DS.getAttributes()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1913 |       continue; | 
| Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 1914 |  | 
 | 1915 |     // Microsoft declspec support. | 
 | 1916 |     case tok::kw___declspec: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1917 |       ParseMicrosoftDeclSpec(DS.getAttributes()); | 
| Steve Naroff | f59e17e | 2008-12-24 20:59:21 +0000 | [diff] [blame] | 1918 |       continue; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1919 |  | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 1920 |     // Microsoft single token adornments. | 
| Steve Naroff | 86bc6cf | 2008-12-25 14:41:26 +0000 | [diff] [blame] | 1921 |     case tok::kw___forceinline: | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 1922 |       // FIXME: Add handling here! | 
 | 1923 |       break; | 
 | 1924 |  | 
 | 1925 |     case tok::kw___ptr64: | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 1926 |     case tok::kw___ptr32: | 
| Steve Naroff | 86bc6cf | 2008-12-25 14:41:26 +0000 | [diff] [blame] | 1927 |     case tok::kw___w64: | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 1928 |     case tok::kw___cdecl: | 
 | 1929 |     case tok::kw___stdcall: | 
 | 1930 |     case tok::kw___fastcall: | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 1931 |     case tok::kw___thiscall: | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 1932 |     case tok::kw___unaligned: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1933 |       ParseMicrosoftTypeAttributes(DS.getAttributes()); | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 1934 |       continue; | 
 | 1935 |  | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 1936 |     // Borland single token adornments. | 
 | 1937 |     case tok::kw___pascal: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1938 |       ParseBorlandTypeAttributes(DS.getAttributes()); | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 1939 |       continue; | 
 | 1940 |  | 
| Peter Collingbourne | f315fa8 | 2011-02-14 01:42:53 +0000 | [diff] [blame] | 1941 |     // OpenCL single token adornments. | 
 | 1942 |     case tok::kw___kernel: | 
 | 1943 |       ParseOpenCLAttributes(DS.getAttributes()); | 
 | 1944 |       continue; | 
 | 1945 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1946 |     // storage-class-specifier | 
 | 1947 |     case tok::kw_typedef: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1948 |       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1949 |                                          DiagID, getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1950 |       break; | 
 | 1951 |     case tok::kw_extern: | 
 | 1952 |       if (DS.isThreadSpecified()) | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1953 |         Diag(Tok, diag::ext_thread_before) << "extern"; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1954 |       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1955 |                                          DiagID, getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1956 |       break; | 
| Steve Naroff | 8d54bf2 | 2007-12-18 00:16:02 +0000 | [diff] [blame] | 1957 |     case tok::kw___private_extern__: | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 1958 |       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_private_extern, Loc, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1959 |                                          PrevSpec, DiagID, getLang()); | 
| Steve Naroff | 8d54bf2 | 2007-12-18 00:16:02 +0000 | [diff] [blame] | 1960 |       break; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1961 |     case tok::kw_static: | 
 | 1962 |       if (DS.isThreadSpecified()) | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1963 |         Diag(Tok, diag::ext_thread_before) << "static"; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1964 |       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1965 |                                          DiagID, getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1966 |       break; | 
 | 1967 |     case tok::kw_auto: | 
| Douglas Gregor | 18d8b79 | 2011-03-14 21:43:30 +0000 | [diff] [blame] | 1968 |       if (getLang().CPlusPlus0x) { | 
| Fariborz Jahanian | 12e3ece | 2011-02-22 23:17:49 +0000 | [diff] [blame] | 1969 |         if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { | 
 | 1970 |           isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec, | 
| Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1971 |                                              DiagID, getLang()); | 
| Fariborz Jahanian | 12e3ece | 2011-02-22 23:17:49 +0000 | [diff] [blame] | 1972 |           if (!isInvalid) | 
| Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1973 |             Diag(Tok, diag::ext_auto_storage_class) | 
| Fariborz Jahanian | 12e3ece | 2011-02-22 23:17:49 +0000 | [diff] [blame] | 1974 |               << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc()); | 
| Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1975 |         } else | 
| Fariborz Jahanian | 12e3ece | 2011-02-22 23:17:49 +0000 | [diff] [blame] | 1976 |           isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, | 
 | 1977 |                                          DiagID); | 
| Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1978 |       } else | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1979 |         isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1980 |                                            DiagID, getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1981 |       break; | 
 | 1982 |     case tok::kw_register: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1983 |       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1984 |                                          DiagID, getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1985 |       break; | 
| Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 1986 |     case tok::kw_mutable: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1987 |       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_mutable, Loc, PrevSpec, | 
| Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 1988 |                                          DiagID, getLang()); | 
| Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 1989 |       break; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1990 |     case tok::kw___thread: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1991 |       isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec, DiagID); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1992 |       break; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1993 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1994 |     // function-specifier | 
 | 1995 |     case tok::kw_inline: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1996 |       isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec, DiagID); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1997 |       break; | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1998 |     case tok::kw_virtual: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 1999 |       isInvalid = DS.SetFunctionSpecVirtual(Loc, PrevSpec, DiagID); | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 2000 |       break; | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 2001 |     case tok::kw_explicit: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2002 |       isInvalid = DS.SetFunctionSpecExplicit(Loc, PrevSpec, DiagID); | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 2003 |       break; | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2004 |  | 
| Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 2005 |     // alignment-specifier | 
 | 2006 |     case tok::kw__Alignas: | 
 | 2007 |       if (!getLang().C1X) | 
 | 2008 |         Diag(Tok, diag::ext_c1x_alignas); | 
 | 2009 |       ParseAlignmentSpecifier(DS.getAttributes()); | 
 | 2010 |       continue; | 
 | 2011 |  | 
| Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 2012 |     // friend | 
 | 2013 |     case tok::kw_friend: | 
| John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 2014 |       if (DSContext == DSC_class) | 
 | 2015 |         isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID); | 
 | 2016 |       else { | 
 | 2017 |         PrevSpec = ""; // not actually used by the diagnostic | 
 | 2018 |         DiagID = diag::err_friend_invalid_in_context; | 
 | 2019 |         isInvalid = true; | 
 | 2020 |       } | 
| Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 2021 |       break; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2022 |  | 
| Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 2023 |     // Modules | 
 | 2024 |     case tok::kw___module_private__: | 
 | 2025 |       isInvalid = DS.setModulePrivateSpec(Loc, PrevSpec, DiagID); | 
 | 2026 |       break; | 
 | 2027 |          | 
| Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 2028 |     // constexpr | 
 | 2029 |     case tok::kw_constexpr: | 
 | 2030 |       isInvalid = DS.SetConstexprSpec(Loc, PrevSpec, DiagID); | 
 | 2031 |       break; | 
 | 2032 |  | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2033 |     // type-specifier | 
 | 2034 |     case tok::kw_short: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2035 |       isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, | 
 | 2036 |                                       DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2037 |       break; | 
 | 2038 |     case tok::kw_long: | 
 | 2039 |       if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2040 |         isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, | 
 | 2041 |                                         DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2042 |       else | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2043 |         isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, | 
 | 2044 |                                         DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2045 |       break; | 
| Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 2046 |     case tok::kw___int64: | 
 | 2047 |         isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, | 
 | 2048 |                                         DiagID); | 
 | 2049 |       break; | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2050 |     case tok::kw_signed: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2051 |       isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, | 
 | 2052 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2053 |       break; | 
 | 2054 |     case tok::kw_unsigned: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2055 |       isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, | 
 | 2056 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2057 |       break; | 
 | 2058 |     case tok::kw__Complex: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2059 |       isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec, | 
 | 2060 |                                         DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2061 |       break; | 
 | 2062 |     case tok::kw__Imaginary: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2063 |       isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec, | 
 | 2064 |                                         DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2065 |       break; | 
 | 2066 |     case tok::kw_void: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2067 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, | 
 | 2068 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2069 |       break; | 
 | 2070 |     case tok::kw_char: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2071 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, | 
 | 2072 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2073 |       break; | 
 | 2074 |     case tok::kw_int: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2075 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, | 
 | 2076 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2077 |       break; | 
 | 2078 |     case tok::kw_float: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2079 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, | 
 | 2080 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2081 |       break; | 
 | 2082 |     case tok::kw_double: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2083 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, | 
 | 2084 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2085 |       break; | 
 | 2086 |     case tok::kw_wchar_t: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2087 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, | 
 | 2088 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2089 |       break; | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2090 |     case tok::kw_char16_t: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2091 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, | 
 | 2092 |                                      DiagID); | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2093 |       break; | 
 | 2094 |     case tok::kw_char32_t: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2095 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, | 
 | 2096 |                                      DiagID); | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2097 |       break; | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2098 |     case tok::kw_bool: | 
 | 2099 |     case tok::kw__Bool: | 
| Argyrios Kyrtzidis | 4383e18 | 2010-11-16 18:18:13 +0000 | [diff] [blame] | 2100 |       if (Tok.is(tok::kw_bool) && | 
 | 2101 |           DS.getTypeSpecType() != DeclSpec::TST_unspecified && | 
 | 2102 |           DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { | 
 | 2103 |         PrevSpec = ""; // Not used by the diagnostic. | 
 | 2104 |         DiagID = diag::err_bool_redeclaration; | 
| Fariborz Jahanian | e106a0b | 2011-04-19 21:42:37 +0000 | [diff] [blame] | 2105 |         // For better error recovery. | 
 | 2106 |         Tok.setKind(tok::identifier); | 
| Argyrios Kyrtzidis | 4383e18 | 2010-11-16 18:18:13 +0000 | [diff] [blame] | 2107 |         isInvalid = true; | 
 | 2108 |       } else { | 
 | 2109 |         isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, | 
 | 2110 |                                        DiagID); | 
 | 2111 |       } | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2112 |       break; | 
 | 2113 |     case tok::kw__Decimal32: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2114 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec, | 
 | 2115 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2116 |       break; | 
 | 2117 |     case tok::kw__Decimal64: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2118 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec, | 
 | 2119 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2120 |       break; | 
 | 2121 |     case tok::kw__Decimal128: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2122 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec, | 
 | 2123 |                                      DiagID); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2124 |       break; | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2125 |     case tok::kw___vector: | 
 | 2126 |       isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID); | 
 | 2127 |       break; | 
 | 2128 |     case tok::kw___pixel: | 
 | 2129 |       isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID); | 
 | 2130 |       break; | 
| John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 2131 |     case tok::kw___unknown_anytype: | 
 | 2132 |       isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc, | 
 | 2133 |                                      PrevSpec, DiagID); | 
 | 2134 |       break; | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2135 |  | 
 | 2136 |     // class-specifier: | 
 | 2137 |     case tok::kw_class: | 
 | 2138 |     case tok::kw_struct: | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2139 |     case tok::kw_union: { | 
 | 2140 |       tok::TokenKind Kind = Tok.getKind(); | 
 | 2141 |       ConsumeToken(); | 
| Douglas Gregor | 4d9a16f | 2009-05-12 23:25:50 +0000 | [diff] [blame] | 2142 |       ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2143 |       continue; | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2144 |     } | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2145 |  | 
 | 2146 |     // enum-specifier: | 
 | 2147 |     case tok::kw_enum: | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2148 |       ConsumeToken(); | 
| Douglas Gregor | 9b9edd6 | 2010-03-02 17:53:14 +0000 | [diff] [blame] | 2149 |       ParseEnumSpecifier(Loc, DS, TemplateInfo, AS); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2150 |       continue; | 
 | 2151 |  | 
 | 2152 |     // cv-qualifier: | 
 | 2153 |     case tok::kw_const: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2154 |       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec, DiagID, | 
 | 2155 |                                  getLang()); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2156 |       break; | 
 | 2157 |     case tok::kw_volatile: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2158 |       isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID, | 
 | 2159 |                                  getLang()); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2160 |       break; | 
 | 2161 |     case tok::kw_restrict: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2162 |       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID, | 
 | 2163 |                                  getLang()); | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2164 |       break; | 
 | 2165 |  | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 2166 |     // C++ typename-specifier: | 
 | 2167 |     case tok::kw_typename: | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 2168 |       if (TryAnnotateTypeOrScopeToken()) { | 
 | 2169 |         DS.SetTypeSpecError(); | 
 | 2170 |         goto DoneWithDeclSpec; | 
 | 2171 |       } | 
 | 2172 |       if (!Tok.is(tok::kw_typename)) | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 2173 |         continue; | 
 | 2174 |       break; | 
 | 2175 |  | 
| Chris Lattner | 80d0c89 | 2009-01-21 19:48:37 +0000 | [diff] [blame] | 2176 |     // GNU typeof support. | 
 | 2177 |     case tok::kw_typeof: | 
 | 2178 |       ParseTypeofSpecifier(DS); | 
 | 2179 |       continue; | 
 | 2180 |  | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 2181 |     case tok::kw_decltype: | 
 | 2182 |       ParseDecltypeSpecifier(DS); | 
 | 2183 |       continue; | 
 | 2184 |  | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 2185 |     case tok::kw___underlying_type: | 
 | 2186 |       ParseUnderlyingTypeSpecifier(DS); | 
 | 2187 |  | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 2188 |     // OpenCL qualifiers: | 
 | 2189 |     case tok::kw_private:  | 
 | 2190 |       if (!getLang().OpenCL) | 
 | 2191 |         goto DoneWithDeclSpec; | 
 | 2192 |     case tok::kw___private: | 
 | 2193 |     case tok::kw___global: | 
 | 2194 |     case tok::kw___local: | 
 | 2195 |     case tok::kw___constant: | 
 | 2196 |     case tok::kw___read_only: | 
 | 2197 |     case tok::kw___write_only: | 
 | 2198 |     case tok::kw___read_write: | 
 | 2199 |       ParseOpenCLQualifiers(DS); | 
 | 2200 |       break; | 
 | 2201 |        | 
| Steve Naroff | d3ded1f | 2008-06-05 00:02:44 +0000 | [diff] [blame] | 2202 |     case tok::less: | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 2203 |       // GCC ObjC supports types like "<SomeProtocol>" as a synonym for | 
| Chris Lattner | bce6135 | 2008-07-26 00:20:22 +0000 | [diff] [blame] | 2204 |       // "id<SomeProtocol>".  This is hopelessly old fashioned and dangerous, | 
 | 2205 |       // but we support it. | 
| Chris Lattner | 3bd934a | 2008-07-26 01:18:38 +0000 | [diff] [blame] | 2206 |       if (DS.hasTypeSpecifier() || !getLang().ObjC1) | 
| Chris Lattner | bce6135 | 2008-07-26 00:20:22 +0000 | [diff] [blame] | 2207 |         goto DoneWithDeclSpec; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2208 |  | 
| Douglas Gregor | 46f936e | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 2209 |       if (!ParseObjCProtocolQualifiers(DS)) | 
 | 2210 |         Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id) | 
 | 2211 |           << FixItHint::CreateInsertion(Loc, "id") | 
 | 2212 |           << SourceRange(Loc, DS.getSourceRange().getEnd()); | 
| Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 2213 |        | 
 | 2214 |       // Need to support trailing type qualifiers (e.g. "id<p> const"). | 
 | 2215 |       // If a type specifier follows, it will be diagnosed elsewhere. | 
 | 2216 |       continue; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2217 |     } | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2218 |     // If the specifier wasn't legal, issue a diagnostic. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2219 |     if (isInvalid) { | 
 | 2220 |       assert(PrevSpec && "Method did not return previous specifier!"); | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2221 |       assert(DiagID); | 
| Douglas Gregor | ae2fb14 | 2010-08-23 14:34:43 +0000 | [diff] [blame] | 2222 |        | 
 | 2223 |       if (DiagID == diag::ext_duplicate_declspec) | 
 | 2224 |         Diag(Tok, DiagID) | 
 | 2225 |           << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation()); | 
 | 2226 |       else | 
 | 2227 |         Diag(Tok, DiagID) << PrevSpec; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2228 |     } | 
| Fariborz Jahanian | 12e3ece | 2011-02-22 23:17:49 +0000 | [diff] [blame] | 2229 |  | 
| Chris Lattner | 81c018d | 2008-03-13 06:29:04 +0000 | [diff] [blame] | 2230 |     DS.SetRangeEnd(Tok.getLocation()); | 
| Fariborz Jahanian | e106a0b | 2011-04-19 21:42:37 +0000 | [diff] [blame] | 2231 |     if (DiagID != diag::err_bool_redeclaration) | 
 | 2232 |       ConsumeToken(); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2233 |   } | 
 | 2234 | } | 
| Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 2235 |  | 
| Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 2236 | /// ParseOptionalTypeSpecifier - Try to parse a single type-specifier. We | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2237 | /// primarily follow the C++ grammar with additions for C99 and GNU, | 
 | 2238 | /// which together subsume the C grammar. Note that the C++ | 
 | 2239 | /// type-specifier also includes the C type-qualifier (for const, | 
 | 2240 | /// volatile, and C99 restrict). Returns true if a type-specifier was | 
 | 2241 | /// found (and parsed), false otherwise. | 
 | 2242 | /// | 
 | 2243 | ///       type-specifier: [C++ 7.1.5] | 
 | 2244 | ///         simple-type-specifier | 
 | 2245 | ///         class-specifier | 
 | 2246 | ///         enum-specifier | 
 | 2247 | ///         elaborated-type-specifier  [TODO] | 
 | 2248 | ///         cv-qualifier | 
 | 2249 | /// | 
 | 2250 | ///       cv-qualifier: [C++ 7.1.5.1] | 
 | 2251 | ///         'const' | 
 | 2252 | ///         'volatile' | 
 | 2253 | /// [C99]   'restrict' | 
 | 2254 | /// | 
 | 2255 | ///       simple-type-specifier: [ C++ 7.1.5.2] | 
 | 2256 | ///         '::'[opt] nested-name-specifier[opt] type-name [TODO] | 
 | 2257 | ///         '::'[opt] nested-name-specifier 'template' template-id [TODO] | 
 | 2258 | ///         'char' | 
 | 2259 | ///         'wchar_t' | 
 | 2260 | ///         'bool' | 
 | 2261 | ///         'short' | 
 | 2262 | ///         'int' | 
 | 2263 | ///         'long' | 
 | 2264 | ///         'signed' | 
 | 2265 | ///         'unsigned' | 
 | 2266 | ///         'float' | 
 | 2267 | ///         'double' | 
 | 2268 | ///         'void' | 
 | 2269 | /// [C99]   '_Bool' | 
 | 2270 | /// [C99]   '_Complex' | 
 | 2271 | /// [C99]   '_Imaginary'  // Removed in TC2? | 
 | 2272 | /// [GNU]   '_Decimal32' | 
 | 2273 | /// [GNU]   '_Decimal64' | 
 | 2274 | /// [GNU]   '_Decimal128' | 
 | 2275 | /// [GNU]   typeof-specifier | 
 | 2276 | /// [OBJC]  class-name objc-protocol-refs[opt]    [TODO] | 
 | 2277 | /// [OBJC]  typedef-name objc-protocol-refs[opt]  [TODO] | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 2278 | /// [C++0x] 'decltype' ( expression ) | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2279 | /// [AltiVec] '__vector' | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2280 | bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, bool& isInvalid, | 
| Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 2281 |                                         const char *&PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2282 |                                         unsigned &DiagID, | 
| Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 2283 |                                         const ParsedTemplateInfo &TemplateInfo, | 
 | 2284 |                                         bool SuppressDeclarations) { | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2285 |   SourceLocation Loc = Tok.getLocation(); | 
 | 2286 |  | 
 | 2287 |   switch (Tok.getKind()) { | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 2288 |   case tok::identifier:   // foo::bar | 
| Douglas Gregor | c0b3964 | 2010-04-15 23:40:53 +0000 | [diff] [blame] | 2289 |     // If we already have a type specifier, this identifier is not a type. | 
 | 2290 |     if (DS.getTypeSpecType() != DeclSpec::TST_unspecified || | 
 | 2291 |         DS.getTypeSpecWidth() != DeclSpec::TSW_unspecified || | 
 | 2292 |         DS.getTypeSpecSign() != DeclSpec::TSS_unspecified) | 
 | 2293 |       return false; | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2294 |     // Check for need to substitute AltiVec keyword tokens. | 
 | 2295 |     if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid)) | 
 | 2296 |       break; | 
 | 2297 |     // Fall through. | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 2298 |   case tok::kw_typename:  // typename foo::bar | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 2299 |     // Annotate typenames and C++ scope specifiers.  If we get one, just | 
 | 2300 |     // recurse to handle whatever we get. | 
 | 2301 |     if (TryAnnotateTypeOrScopeToken()) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 2302 |       return true; | 
 | 2303 |     if (Tok.is(tok::identifier)) | 
 | 2304 |       return false; | 
 | 2305 |     return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID, | 
 | 2306 |                                       TemplateInfo, SuppressDeclarations); | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 2307 |   case tok::coloncolon:   // ::foo::bar | 
 | 2308 |     if (NextToken().is(tok::kw_new) ||    // ::new | 
 | 2309 |         NextToken().is(tok::kw_delete))   // ::delete | 
 | 2310 |       return false; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2311 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 2312 |     // Annotate typenames and C++ scope specifiers.  If we get one, just | 
 | 2313 |     // recurse to handle whatever we get. | 
 | 2314 |     if (TryAnnotateTypeOrScopeToken()) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 2315 |       return true; | 
 | 2316 |     return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec, DiagID, | 
 | 2317 |                                       TemplateInfo, SuppressDeclarations); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2318 |  | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2319 |   // simple-type-specifier: | 
| Chris Lattner | b31757b | 2009-01-06 05:06:21 +0000 | [diff] [blame] | 2320 |   case tok::annot_typename: { | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2321 |     if (ParsedType T = getTypeAnnotation(Tok)) { | 
| Nico Weber | 253e80b | 2010-11-22 10:30:56 +0000 | [diff] [blame] | 2322 |       isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, | 
 | 2323 |                                      Tok.getAnnotationEndLoc(), PrevSpec, | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2324 |                                      DiagID, T); | 
 | 2325 |     } else | 
| Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 2326 |       DS.SetTypeSpecError(); | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2327 |     DS.SetRangeEnd(Tok.getAnnotationEndLoc()); | 
 | 2328 |     ConsumeToken(); // The typename | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2329 |  | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2330 |     // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id' | 
 | 2331 |     // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an | 
 | 2332 |     // Objective-C interface.  If we don't have Objective-C or a '<', this is | 
 | 2333 |     // just a normal reference to a typedef name. | 
| Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 2334 |     if (Tok.is(tok::less) && getLang().ObjC1) | 
 | 2335 |       ParseObjCProtocolQualifiers(DS); | 
 | 2336 |      | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2337 |     return true; | 
 | 2338 |   } | 
 | 2339 |  | 
 | 2340 |   case tok::kw_short: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2341 |     isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2342 |     break; | 
 | 2343 |   case tok::kw_long: | 
 | 2344 |     if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2345 |       isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, | 
 | 2346 |                                       DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2347 |     else | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2348 |       isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, | 
 | 2349 |                                       DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2350 |     break; | 
| Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 2351 |   case tok::kw___int64: | 
 | 2352 |       isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, | 
 | 2353 |                                       DiagID); | 
 | 2354 |     break; | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2355 |   case tok::kw_signed: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2356 |     isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2357 |     break; | 
 | 2358 |   case tok::kw_unsigned: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2359 |     isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, | 
 | 2360 |                                    DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2361 |     break; | 
 | 2362 |   case tok::kw__Complex: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2363 |     isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec, | 
 | 2364 |                                       DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2365 |     break; | 
 | 2366 |   case tok::kw__Imaginary: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2367 |     isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec, | 
 | 2368 |                                       DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2369 |     break; | 
 | 2370 |   case tok::kw_void: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2371 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2372 |     break; | 
 | 2373 |   case tok::kw_char: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2374 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2375 |     break; | 
 | 2376 |   case tok::kw_int: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2377 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2378 |     break; | 
 | 2379 |   case tok::kw_float: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2380 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2381 |     break; | 
 | 2382 |   case tok::kw_double: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2383 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2384 |     break; | 
 | 2385 |   case tok::kw_wchar_t: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2386 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2387 |     break; | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2388 |   case tok::kw_char16_t: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2389 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID); | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2390 |     break; | 
 | 2391 |   case tok::kw_char32_t: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2392 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID); | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 2393 |     break; | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2394 |   case tok::kw_bool: | 
 | 2395 |   case tok::kw__Bool: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2396 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2397 |     break; | 
 | 2398 |   case tok::kw__Decimal32: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2399 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec, | 
 | 2400 |                                    DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2401 |     break; | 
 | 2402 |   case tok::kw__Decimal64: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2403 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec, | 
 | 2404 |                                    DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2405 |     break; | 
 | 2406 |   case tok::kw__Decimal128: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2407 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec, | 
 | 2408 |                                    DiagID); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2409 |     break; | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 2410 |   case tok::kw___vector: | 
 | 2411 |     isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID); | 
 | 2412 |     break; | 
 | 2413 |   case tok::kw___pixel: | 
 | 2414 |     isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID); | 
 | 2415 |     break; | 
 | 2416 |    | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2417 |   // class-specifier: | 
 | 2418 |   case tok::kw_class: | 
 | 2419 |   case tok::kw_struct: | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2420 |   case tok::kw_union: { | 
 | 2421 |     tok::TokenKind Kind = Tok.getKind(); | 
 | 2422 |     ConsumeToken(); | 
| Sebastian Redl | d9bafa7 | 2010-02-03 21:21:43 +0000 | [diff] [blame] | 2423 |     ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS_none, | 
 | 2424 |                         SuppressDeclarations); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2425 |     return true; | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2426 |   } | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2427 |  | 
 | 2428 |   // enum-specifier: | 
 | 2429 |   case tok::kw_enum: | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2430 |     ConsumeToken(); | 
| Douglas Gregor | 9b9edd6 | 2010-03-02 17:53:14 +0000 | [diff] [blame] | 2431 |     ParseEnumSpecifier(Loc, DS, TemplateInfo, AS_none); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2432 |     return true; | 
 | 2433 |  | 
 | 2434 |   // cv-qualifier: | 
 | 2435 |   case tok::kw_const: | 
 | 2436 |     isInvalid = DS.SetTypeQual(DeclSpec::TQ_const   , Loc, PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2437 |                                DiagID, getLang()); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2438 |     break; | 
 | 2439 |   case tok::kw_volatile: | 
 | 2440 |     isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2441 |                                DiagID, getLang()); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2442 |     break; | 
 | 2443 |   case tok::kw_restrict: | 
 | 2444 |     isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2445 |                                DiagID, getLang()); | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2446 |     break; | 
 | 2447 |  | 
 | 2448 |   // GNU typeof support. | 
 | 2449 |   case tok::kw_typeof: | 
 | 2450 |     ParseTypeofSpecifier(DS); | 
 | 2451 |     return true; | 
 | 2452 |  | 
| Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 2453 |   // C++0x decltype support. | 
 | 2454 |   case tok::kw_decltype: | 
 | 2455 |     ParseDecltypeSpecifier(DS); | 
 | 2456 |     return true; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2457 |  | 
| Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 2458 |   // C++0x type traits support. | 
 | 2459 |   case tok::kw___underlying_type: | 
 | 2460 |     ParseUnderlyingTypeSpecifier(DS); | 
 | 2461 |     return true; | 
 | 2462 |  | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 2463 |   // OpenCL qualifiers: | 
 | 2464 |   case tok::kw_private:  | 
 | 2465 |     if (!getLang().OpenCL) | 
 | 2466 |       return false; | 
 | 2467 |   case tok::kw___private: | 
 | 2468 |   case tok::kw___global: | 
 | 2469 |   case tok::kw___local: | 
 | 2470 |   case tok::kw___constant: | 
 | 2471 |   case tok::kw___read_only: | 
 | 2472 |   case tok::kw___write_only: | 
 | 2473 |   case tok::kw___read_write: | 
 | 2474 |     ParseOpenCLQualifiers(DS); | 
 | 2475 |     break; | 
 | 2476 |  | 
| Anders Carlsson | 0b7f789 | 2009-06-26 23:44:14 +0000 | [diff] [blame] | 2477 |   // C++0x auto support. | 
 | 2478 |   case tok::kw_auto: | 
| Richard Smith | 87e96eb | 2011-09-04 20:24:20 +0000 | [diff] [blame] | 2479 |     // This is only called in situations where a storage-class specifier is | 
 | 2480 |     // illegal, so we can assume an auto type specifier was intended even in | 
 | 2481 |     // C++98. In C++98 mode, DeclSpec::Finish will produce an appropriate | 
 | 2482 |     // extension diagnostic. | 
 | 2483 |     if (!getLang().CPlusPlus) | 
| Anders Carlsson | 0b7f789 | 2009-06-26 23:44:14 +0000 | [diff] [blame] | 2484 |       return false; | 
 | 2485 |  | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2486 |     isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, DiagID); | 
| Anders Carlsson | 0b7f789 | 2009-06-26 23:44:14 +0000 | [diff] [blame] | 2487 |     break; | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 2488 |  | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 2489 |   case tok::kw___ptr64: | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 2490 |   case tok::kw___ptr32: | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 2491 |   case tok::kw___w64: | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 2492 |   case tok::kw___cdecl: | 
 | 2493 |   case tok::kw___stdcall: | 
 | 2494 |   case tok::kw___fastcall: | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 2495 |   case tok::kw___thiscall: | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 2496 |   case tok::kw___unaligned: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2497 |     ParseMicrosoftTypeAttributes(DS.getAttributes()); | 
| Chris Lattner | 837acd0 | 2009-01-21 19:19:26 +0000 | [diff] [blame] | 2498 |     return true; | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 2499 |  | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 2500 |   case tok::kw___pascal: | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2501 |     ParseBorlandTypeAttributes(DS.getAttributes()); | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 2502 |     return true; | 
 | 2503 |  | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2504 |   default: | 
 | 2505 |     // Not a type-specifier; do nothing. | 
 | 2506 |     return false; | 
 | 2507 |   } | 
 | 2508 |  | 
 | 2509 |   // If the specifier combination wasn't legal, issue a diagnostic. | 
 | 2510 |   if (isInvalid) { | 
 | 2511 |     assert(PrevSpec && "Method did not return previous specifier!"); | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 2512 |     // Pick between error or extwarn. | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 2513 |     Diag(Tok, DiagID) << PrevSpec; | 
| Douglas Gregor | 12e083c | 2008-11-07 15:42:26 +0000 | [diff] [blame] | 2514 |   } | 
 | 2515 |   DS.SetRangeEnd(Tok.getLocation()); | 
 | 2516 |   ConsumeToken(); // whatever we parsed above. | 
 | 2517 |   return true; | 
 | 2518 | } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2519 |  | 
| Chris Lattner | cd4b83c | 2007-10-29 04:42:53 +0000 | [diff] [blame] | 2520 | /// ParseStructDeclaration - Parse a struct declaration without the terminating | 
 | 2521 | /// semicolon. | 
 | 2522 | /// | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2523 | ///       struct-declaration: | 
| Chris Lattner | cd4b83c | 2007-10-29 04:42:53 +0000 | [diff] [blame] | 2524 | ///         specifier-qualifier-list struct-declarator-list | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2525 | /// [GNU]   __extension__ struct-declaration | 
| Chris Lattner | cd4b83c | 2007-10-29 04:42:53 +0000 | [diff] [blame] | 2526 | /// [GNU]   specifier-qualifier-list | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2527 | ///       struct-declarator-list: | 
 | 2528 | ///         struct-declarator | 
 | 2529 | ///         struct-declarator-list ',' struct-declarator | 
 | 2530 | /// [GNU]   struct-declarator-list ',' attributes[opt] struct-declarator | 
 | 2531 | ///       struct-declarator: | 
 | 2532 | ///         declarator | 
 | 2533 | /// [GNU]   declarator attributes[opt] | 
 | 2534 | ///         declarator[opt] ':' constant-expression | 
 | 2535 | /// [GNU]   declarator[opt] ':' constant-expression attributes[opt] | 
 | 2536 | /// | 
| Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 2537 | void Parser:: | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2538 | ParseStructDeclaration(DeclSpec &DS, FieldCallback &Fields) { | 
| Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 2539 |      | 
| Chris Lattner | c46d1a1 | 2008-10-20 06:45:43 +0000 | [diff] [blame] | 2540 |   if (Tok.is(tok::kw___extension__)) { | 
 | 2541 |     // __extension__ silences extension warnings in the subexpression. | 
 | 2542 |     ExtensionRAIIObject O(Diags);  // Use RAII to do this. | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2543 |     ConsumeToken(); | 
| Chris Lattner | c46d1a1 | 2008-10-20 06:45:43 +0000 | [diff] [blame] | 2544 |     return ParseStructDeclaration(DS, Fields); | 
 | 2545 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2546 |  | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2547 |   // Parse the common specifier-qualifiers-list piece. | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2548 |   ParseSpecifierQualifierList(DS); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2549 |  | 
| Douglas Gregor | 4920f1f | 2009-01-12 22:49:06 +0000 | [diff] [blame] | 2550 |   // If there are no declarators, this is a free-standing declaration | 
 | 2551 |   // specifier. Let the actions module cope with it. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2552 |   if (Tok.is(tok::semi)) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2553 |     Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, DS); | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2554 |     return; | 
 | 2555 |   } | 
 | 2556 |  | 
 | 2557 |   // Read struct-declarators until we find the semicolon. | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2558 |   bool FirstDeclarator = true; | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2559 |   while (1) { | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2560 |     ParsingDeclRAIIObject PD(*this); | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2561 |     FieldDeclarator DeclaratorInfo(DS); | 
 | 2562 |  | 
 | 2563 |     // Attributes are only allowed here on successive declarators. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2564 |     if (!FirstDeclarator) | 
 | 2565 |       MaybeParseGNUAttributes(DeclaratorInfo.D); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2566 |  | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2567 |     /// struct-declarator: declarator | 
 | 2568 |     /// struct-declarator: declarator[opt] ':' constant-expression | 
| Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 2569 |     if (Tok.isNot(tok::colon)) { | 
 | 2570 |       // Don't parse FOO:BAR as if it were a typo for FOO::BAR. | 
 | 2571 |       ColonProtectionRAIIObject X(*this); | 
| Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 2572 |       ParseDeclarator(DeclaratorInfo.D); | 
| Chris Lattner | a1efc8c | 2009-12-10 01:59:24 +0000 | [diff] [blame] | 2573 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 |  | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2575 |     if (Tok.is(tok::colon)) { | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2576 |       ConsumeToken(); | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2577 |       ExprResult Res(ParseConstantExpression()); | 
| Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2578 |       if (Res.isInvalid()) | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2579 |         SkipUntil(tok::semi, true, true); | 
| Chris Lattner | 60b1e3e | 2008-04-10 06:15:14 +0000 | [diff] [blame] | 2580 |       else | 
| Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2581 |         DeclaratorInfo.BitfieldSize = Res.release(); | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2582 |     } | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2583 |  | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2584 |     // If attributes exist after the declarator, parse them. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2585 |     MaybeParseGNUAttributes(DeclaratorInfo.D); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2586 |  | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2587 |     // We're done with this declarator;  invoke the callback. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2588 |     Decl *D = Fields.invoke(DeclaratorInfo); | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2589 |     PD.complete(D); | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2590 |  | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2591 |     // If we don't have a comma, it is either the end of the list (a ';') | 
 | 2592 |     // or an error, bail out. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2593 |     if (Tok.isNot(tok::comma)) | 
| Chris Lattner | cd4b83c | 2007-10-29 04:42:53 +0000 | [diff] [blame] | 2594 |       return; | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2595 |  | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2596 |     // Consume the comma. | 
 | 2597 |     ConsumeToken(); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 2598 |  | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2599 |     FirstDeclarator = false; | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2600 |   } | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2601 | } | 
 | 2602 |  | 
 | 2603 | /// ParseStructUnionBody | 
 | 2604 | ///       struct-contents: | 
 | 2605 | ///         struct-declaration-list | 
 | 2606 | /// [EXT]   empty | 
 | 2607 | /// [GNU]   "struct-declaration-list" without terminatoring ';' | 
 | 2608 | ///       struct-declaration-list: | 
 | 2609 | ///         struct-declaration | 
 | 2610 | ///         struct-declaration-list struct-declaration | 
| Chris Lattner | 5a6ddbf | 2008-06-21 19:39:06 +0000 | [diff] [blame] | 2611 | /// [OBC]   '@' 'defs' '(' class-name ')' | 
| Steve Naroff | 28a7ca8 | 2007-08-20 22:28:22 +0000 | [diff] [blame] | 2612 | /// | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2613 | void Parser::ParseStructUnionBody(SourceLocation RecordLoc, | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2614 |                                   unsigned TagType, Decl *TagDecl) { | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2615 |   PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, RecordLoc, | 
 | 2616 |                                       "parsing struct/union body"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2617 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2618 |   SourceLocation LBraceLoc = ConsumeBrace(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2619 |  | 
| Douglas Gregor | 3218c4b | 2009-01-09 22:42:13 +0000 | [diff] [blame] | 2620 |   ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2621 |   Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); | 
| Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 2622 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2623 |   // Empty structs are an extension in C (C99 6.7.2.1p7), but are allowed in | 
 | 2624 |   // C++. | 
| Douglas Gregor | e37ac4f | 2008-04-13 21:30:24 +0000 | [diff] [blame] | 2625 |   if (Tok.is(tok::r_brace) && !getLang().CPlusPlus) | 
| Douglas Gregor | 0333296 | 2010-07-29 14:29:34 +0000 | [diff] [blame] | 2626 |     Diag(Tok, diag::ext_empty_struct_union) | 
 | 2627 |       << (TagType == TST_union); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2628 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2629 |   SmallVector<Decl *, 32> FieldDecls; | 
| Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 2630 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2631 |   // While we still have something to read, read the declarations in the struct. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2632 |   while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2633 |     // Each iteration of this loop reads one struct-declaration. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2634 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2635 |     // Check for extraneous top-level semicolon. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2636 |     if (Tok.is(tok::semi)) { | 
| Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 2637 |       Diag(Tok, diag::ext_extra_struct_semi) | 
| Douglas Gregor | f13ca06 | 2010-06-16 23:08:59 +0000 | [diff] [blame] | 2638 |         << DeclSpec::getSpecifierName((DeclSpec::TST)TagType) | 
| Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 2639 |         << FixItHint::CreateRemoval(Tok.getLocation()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2640 |       ConsumeToken(); | 
 | 2641 |       continue; | 
 | 2642 |     } | 
| Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 2643 |  | 
 | 2644 |     // Parse all the comma separated declarators. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2645 |     DeclSpec DS(AttrFactory); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2646 |  | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2647 |     if (!Tok.is(tok::at)) { | 
 | 2648 |       struct CFieldCallback : FieldCallback { | 
 | 2649 |         Parser &P; | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2650 |         Decl *TagDecl; | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2651 |         SmallVectorImpl<Decl *> &FieldDecls; | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2652 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2653 |         CFieldCallback(Parser &P, Decl *TagDecl, | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2654 |                        SmallVectorImpl<Decl *> &FieldDecls) : | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2655 |           P(P), TagDecl(TagDecl), FieldDecls(FieldDecls) {} | 
 | 2656 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2657 |         virtual Decl *invoke(FieldDeclarator &FD) { | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2658 |           // Install the declarator into the current TagDecl. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2659 |           Decl *Field = P.Actions.ActOnField(P.getCurScope(), TagDecl, | 
| John McCall | 4ba3971 | 2009-11-03 21:13:47 +0000 | [diff] [blame] | 2660 |                               FD.D.getDeclSpec().getSourceRange().getBegin(), | 
 | 2661 |                                                  FD.D, FD.BitfieldSize); | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2662 |           FieldDecls.push_back(Field); | 
 | 2663 |           return Field; | 
| Douglas Gregor | 91a2886 | 2009-08-26 14:27:30 +0000 | [diff] [blame] | 2664 |         } | 
| John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 2665 |       } Callback(*this, TagDecl, FieldDecls); | 
 | 2666 |  | 
 | 2667 |       ParseStructDeclaration(DS, Callback); | 
| Chris Lattner | 5a6ddbf | 2008-06-21 19:39:06 +0000 | [diff] [blame] | 2668 |     } else { // Handle @defs | 
 | 2669 |       ConsumeToken(); | 
 | 2670 |       if (!Tok.isObjCAtKeyword(tok::objc_defs)) { | 
 | 2671 |         Diag(Tok, diag::err_unexpected_at); | 
| Chris Lattner | 3e156ad | 2010-02-02 00:37:27 +0000 | [diff] [blame] | 2672 |         SkipUntil(tok::semi, true); | 
| Chris Lattner | 5a6ddbf | 2008-06-21 19:39:06 +0000 | [diff] [blame] | 2673 |         continue; | 
 | 2674 |       } | 
 | 2675 |       ConsumeToken(); | 
 | 2676 |       ExpectAndConsume(tok::l_paren, diag::err_expected_lparen); | 
 | 2677 |       if (!Tok.is(tok::identifier)) { | 
 | 2678 |         Diag(Tok, diag::err_expected_ident); | 
| Chris Lattner | 3e156ad | 2010-02-02 00:37:27 +0000 | [diff] [blame] | 2679 |         SkipUntil(tok::semi, true); | 
| Chris Lattner | 5a6ddbf | 2008-06-21 19:39:06 +0000 | [diff] [blame] | 2680 |         continue; | 
 | 2681 |       } | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2682 |       SmallVector<Decl *, 16> Fields; | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2683 |       Actions.ActOnDefs(getCurScope(), TagDecl, Tok.getLocation(), | 
| Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 2684 |                         Tok.getIdentifierInfo(), Fields); | 
| Chris Lattner | 5a6ddbf | 2008-06-21 19:39:06 +0000 | [diff] [blame] | 2685 |       FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end()); | 
 | 2686 |       ConsumeToken(); | 
 | 2687 |       ExpectAndConsume(tok::r_paren, diag::err_expected_rparen); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2688 |     } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2689 |  | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2690 |     if (Tok.is(tok::semi)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2691 |       ConsumeToken(); | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2692 |     } else if (Tok.is(tok::r_brace)) { | 
| Chris Lattner | 3e156ad | 2010-02-02 00:37:27 +0000 | [diff] [blame] | 2693 |       ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2694 |       break; | 
 | 2695 |     } else { | 
| Chris Lattner | 3e156ad | 2010-02-02 00:37:27 +0000 | [diff] [blame] | 2696 |       ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); | 
 | 2697 |       // Skip to end of block or statement to avoid ext-warning on extra ';'. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2698 |       SkipUntil(tok::r_brace, true, true); | 
| Chris Lattner | 3e156ad | 2010-02-02 00:37:27 +0000 | [diff] [blame] | 2699 |       // If we stopped at a ';', eat it. | 
 | 2700 |       if (Tok.is(tok::semi)) ConsumeToken(); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2701 |     } | 
 | 2702 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2703 |  | 
| Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 2704 |   SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2705 |  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2706 |   ParsedAttributes attrs(AttrFactory); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2707 |   // If attributes exist after struct contents, parse them. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2708 |   MaybeParseGNUAttributes(attrs); | 
| Daniel Dunbar | 1bfe1c2 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 2709 |  | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2710 |   Actions.ActOnFields(getCurScope(), | 
| David Blaikie | 77b6de0 | 2011-09-22 02:58:26 +0000 | [diff] [blame] | 2711 |                       RecordLoc, TagDecl, FieldDecls, | 
| Daniel Dunbar | 1bfe1c2 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 2712 |                       LBraceLoc, RBraceLoc, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2713 |                       attrs.getList()); | 
| Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 2714 |   StructScope.Exit(); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2715 |   Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, RBraceLoc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2716 | } | 
 | 2717 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2718 | /// ParseEnumSpecifier | 
 | 2719 | ///       enum-specifier: [C99 6.7.2.2] | 
 | 2720 | ///         'enum' identifier[opt] '{' enumerator-list '}' | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2721 | ///[C99/C++]'enum' identifier[opt] '{' enumerator-list ',' '}' | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2722 | /// [GNU]   'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt] | 
 | 2723 | ///                                                 '}' attributes[opt] | 
 | 2724 | ///         'enum' identifier | 
 | 2725 | /// [GNU]   'enum' attributes[opt] identifier | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2726 | /// | 
| Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 2727 | /// [C++0x] enum-head '{' enumerator-list[opt] '}' | 
 | 2728 | /// [C++0x] enum-head '{' enumerator-list ','  '}' | 
 | 2729 | /// | 
 | 2730 | ///       enum-head: [C++0x] | 
 | 2731 | ///         enum-key attributes[opt] identifier[opt] enum-base[opt] | 
 | 2732 | ///         enum-key attributes[opt] nested-name-specifier identifier enum-base[opt] | 
 | 2733 | /// | 
 | 2734 | ///       enum-key: [C++0x] | 
 | 2735 | ///         'enum' | 
 | 2736 | ///         'enum' 'class' | 
 | 2737 | ///         'enum' 'struct' | 
 | 2738 | /// | 
 | 2739 | ///       enum-base: [C++0x] | 
 | 2740 | ///         ':' type-specifier-seq | 
 | 2741 | /// | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2742 | /// [C++] elaborated-type-specifier: | 
 | 2743 | /// [C++]   'enum' '::'[opt] nested-name-specifier[opt] identifier | 
 | 2744 | /// | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2745 | void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, | 
| Douglas Gregor | 9b9edd6 | 2010-03-02 17:53:14 +0000 | [diff] [blame] | 2746 |                                 const ParsedTemplateInfo &TemplateInfo, | 
| Chris Lattner | 4c97d76 | 2009-04-12 21:49:30 +0000 | [diff] [blame] | 2747 |                                 AccessSpecifier AS) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2748 |   // Parse the tag portion of this. | 
| Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 2749 |   if (Tok.is(tok::code_completion)) { | 
 | 2750 |     // Code completion for an enum name. | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2751 |     Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2752 |     return cutOffParsing(); | 
| Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 2753 |   } | 
| John McCall | 57c1300 | 2011-07-06 05:58:41 +0000 | [diff] [blame] | 2754 |  | 
 | 2755 |   bool IsScopedEnum = false; | 
 | 2756 |   bool IsScopedUsingClassTag = false; | 
 | 2757 |  | 
 | 2758 |   if (getLang().CPlusPlus0x && | 
 | 2759 |       (Tok.is(tok::kw_class) || Tok.is(tok::kw_struct))) { | 
 | 2760 |     IsScopedEnum = true; | 
 | 2761 |     IsScopedUsingClassTag = Tok.is(tok::kw_class); | 
 | 2762 |     ConsumeToken(); | 
 | 2763 |   } | 
| Douglas Gregor | 374929f | 2009-09-18 15:37:17 +0000 | [diff] [blame] | 2764 |    | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2765 |   // If attributes exist after tag, parse them. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2766 |   ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2767 |   MaybeParseGNUAttributes(attrs); | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2768 |  | 
| Douglas Gregor | 5471bc8 | 2011-09-08 17:18:35 +0000 | [diff] [blame] | 2769 |   bool AllowFixedUnderlyingType  | 
| Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 2770 |     = getLang().CPlusPlus0x || getLang().MicrosoftExt || getLang().ObjC2; | 
| John McCall | 57c1300 | 2011-07-06 05:58:41 +0000 | [diff] [blame] | 2771 |  | 
| Abramo Bagnara | e4da7a0 | 2010-05-19 21:37:53 +0000 | [diff] [blame] | 2772 |   CXXScopeSpec &SS = DS.getTypeSpecScope(); | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 2773 |   if (getLang().CPlusPlus) { | 
| John McCall | 57c1300 | 2011-07-06 05:58:41 +0000 | [diff] [blame] | 2774 |     // "enum foo : bar;" is not a potential typo for "enum foo::bar;" | 
 | 2775 |     // if a fixed underlying type is allowed. | 
 | 2776 |     ColonProtectionRAIIObject X(*this, AllowFixedUnderlyingType); | 
 | 2777 |      | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2778 |     if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 2779 |       return; | 
 | 2780 |  | 
 | 2781 |     if (SS.isSet() && Tok.isNot(tok::identifier)) { | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 2782 |       Diag(Tok, diag::err_expected_ident); | 
 | 2783 |       if (Tok.isNot(tok::l_brace)) { | 
 | 2784 |         // Has no name and is not a definition. | 
 | 2785 |         // Skip the rest of this declarator, up until the comma or semicolon. | 
 | 2786 |         SkipUntil(tok::comma, true); | 
 | 2787 |         return; | 
 | 2788 |       } | 
 | 2789 |     } | 
 | 2790 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2791 |  | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2792 |   // Must have either 'enum name' or 'enum {...}'. | 
| Douglas Gregor | b907560 | 2011-02-22 02:55:24 +0000 | [diff] [blame] | 2793 |   if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) && | 
 | 2794 |       (AllowFixedUnderlyingType && Tok.isNot(tok::colon))) { | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2795 |     Diag(Tok, diag::err_expected_ident_lbrace); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2796 |  | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2797 |     // Skip the rest of this declarator, up until the comma or semicolon. | 
 | 2798 |     SkipUntil(tok::comma, true); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2799 |     return; | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2800 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2801 |  | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2802 |   // If an identifier is present, consume and remember it. | 
 | 2803 |   IdentifierInfo *Name = 0; | 
 | 2804 |   SourceLocation NameLoc; | 
 | 2805 |   if (Tok.is(tok::identifier)) { | 
 | 2806 |     Name = Tok.getIdentifierInfo(); | 
 | 2807 |     NameLoc = ConsumeToken(); | 
 | 2808 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2809 |  | 
| Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 2810 |   if (!Name && IsScopedEnum) { | 
 | 2811 |     // C++0x 7.2p2: The optional identifier shall not be omitted in the | 
 | 2812 |     // declaration of a scoped enumeration. | 
 | 2813 |     Diag(Tok, diag::err_scoped_enum_missing_identifier); | 
 | 2814 |     IsScopedEnum = false; | 
| Abramo Bagnara | a88cefd | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 2815 |     IsScopedUsingClassTag = false; | 
| Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 2816 |   } | 
 | 2817 |  | 
 | 2818 |   TypeResult BaseType; | 
 | 2819 |  | 
| Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 2820 |   // Parse the fixed underlying type. | 
| Douglas Gregor | b907560 | 2011-02-22 02:55:24 +0000 | [diff] [blame] | 2821 |   if (AllowFixedUnderlyingType && Tok.is(tok::colon)) { | 
| Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 2822 |     bool PossibleBitfield = false; | 
 | 2823 |     if (getCurScope()->getFlags() & Scope::ClassScope) { | 
 | 2824 |       // If we're in class scope, this can either be an enum declaration with | 
 | 2825 |       // an underlying type, or a declaration of a bitfield member. We try to | 
 | 2826 |       // use a simple disambiguation scheme first to catch the common cases | 
 | 2827 |       // (integer literal, sizeof); if it's still ambiguous, we then consider  | 
 | 2828 |       // anything that's a simple-type-specifier followed by '(' as an  | 
 | 2829 |       // expression. This suffices because function types are not valid  | 
 | 2830 |       // underlying types anyway. | 
 | 2831 |       TPResult TPR = isExpressionOrTypeSpecifierSimple(NextToken().getKind()); | 
 | 2832 |       // If the next token starts an expression, we know we're parsing a  | 
 | 2833 |       // bit-field. This is the common case. | 
 | 2834 |       if (TPR == TPResult::True()) | 
 | 2835 |         PossibleBitfield = true; | 
 | 2836 |       // If the next token starts a type-specifier-seq, it may be either a | 
 | 2837 |       // a fixed underlying type or the start of a function-style cast in C++; | 
 | 2838 |       // lookahead one more token to see if it's obvious that we have a  | 
 | 2839 |       // fixed underlying type. | 
 | 2840 |       else if (TPR == TPResult::False() &&  | 
 | 2841 |                GetLookAheadToken(2).getKind() == tok::semi) { | 
 | 2842 |         // Consume the ':'. | 
 | 2843 |         ConsumeToken(); | 
 | 2844 |       } else { | 
 | 2845 |         // We have the start of a type-specifier-seq, so we have to perform | 
 | 2846 |         // tentative parsing to determine whether we have an expression or a | 
 | 2847 |         // type. | 
 | 2848 |         TentativeParsingAction TPA(*this); | 
 | 2849 |  | 
 | 2850 |         // Consume the ':'. | 
 | 2851 |         ConsumeToken(); | 
 | 2852 |        | 
| Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 2853 |         if ((getLang().CPlusPlus &&  | 
 | 2854 |              isCXXDeclarationSpecifier() != TPResult::True()) || | 
 | 2855 |             (!getLang().CPlusPlus && !isDeclarationSpecifier(true))) { | 
| Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 2856 |           // We'll parse this as a bitfield later. | 
 | 2857 |           PossibleBitfield = true; | 
 | 2858 |           TPA.Revert(); | 
 | 2859 |         } else { | 
 | 2860 |           // We have a type-specifier-seq. | 
 | 2861 |           TPA.Commit(); | 
 | 2862 |         } | 
 | 2863 |       } | 
 | 2864 |     } else { | 
 | 2865 |       // Consume the ':'. | 
 | 2866 |       ConsumeToken(); | 
 | 2867 |     } | 
 | 2868 |  | 
 | 2869 |     if (!PossibleBitfield) { | 
 | 2870 |       SourceRange Range; | 
 | 2871 |       BaseType = ParseTypeName(&Range); | 
| Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 2872 |        | 
| Douglas Gregor | 5471bc8 | 2011-09-08 17:18:35 +0000 | [diff] [blame] | 2873 |       if (!getLang().CPlusPlus0x && !getLang().ObjC2) | 
| Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 2874 |         Diag(StartLoc, diag::ext_ms_enum_fixed_underlying_type) | 
 | 2875 |           << Range; | 
| Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 2876 |     } | 
| Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 2877 |   } | 
 | 2878 |  | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2879 |   // There are three options here.  If we have 'enum foo;', then this is a | 
 | 2880 |   // forward declaration.  If we have 'enum foo {...' then this is a | 
 | 2881 |   // definition. Otherwise we have something like 'enum foo xyz', a reference. | 
 | 2882 |   // | 
 | 2883 |   // This is needed to handle stuff like this right (C99 6.7.2.3p11): | 
 | 2884 |   // enum foo {..};  void bar() { enum foo; }    <- new foo in bar. | 
 | 2885 |   // enum foo {..};  void bar() { enum foo x; }  <- use of old foo. | 
 | 2886 |   // | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2887 |   Sema::TagUseKind TUK; | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2888 |   if (Tok.is(tok::l_brace)) | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2889 |     TUK = Sema::TUK_Definition; | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2890 |   else if (Tok.is(tok::semi)) | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2891 |     TUK = Sema::TUK_Declaration; | 
| Argyrios Kyrtzidis | e281b4c | 2008-09-11 00:21:41 +0000 | [diff] [blame] | 2892 |   else | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2893 |     TUK = Sema::TUK_Reference; | 
| Douglas Gregor | 8fc6d23 | 2010-05-03 17:48:54 +0000 | [diff] [blame] | 2894 |    | 
 | 2895 |   // enums cannot be templates, although they can be referenced from a  | 
 | 2896 |   // template. | 
 | 2897 |   if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2898 |       TUK != Sema::TUK_Reference) { | 
| Douglas Gregor | 8fc6d23 | 2010-05-03 17:48:54 +0000 | [diff] [blame] | 2899 |     Diag(Tok, diag::err_enum_template); | 
 | 2900 |      | 
 | 2901 |     // Skip the rest of this declarator, up until the comma or semicolon. | 
 | 2902 |     SkipUntil(tok::comma, true); | 
 | 2903 |     return;       | 
 | 2904 |   } | 
 | 2905 |    | 
| Douglas Gregor | b907560 | 2011-02-22 02:55:24 +0000 | [diff] [blame] | 2906 |   if (!Name && TUK != Sema::TUK_Definition) { | 
 | 2907 |     Diag(Tok, diag::err_enumerator_unnamed_no_def); | 
 | 2908 |      | 
 | 2909 |     // Skip the rest of this declarator, up until the comma or semicolon. | 
 | 2910 |     SkipUntil(tok::comma, true); | 
 | 2911 |     return; | 
 | 2912 |   } | 
 | 2913 |        | 
| Douglas Gregor | 402abb5 | 2009-05-28 23:31:59 +0000 | [diff] [blame] | 2914 |   bool Owned = false; | 
| John McCall | c4e7019 | 2009-09-11 04:59:25 +0000 | [diff] [blame] | 2915 |   bool IsDependent = false; | 
| Douglas Gregor | 48c89f4 | 2010-04-24 16:38:41 +0000 | [diff] [blame] | 2916 |   const char *PrevSpec = 0; | 
 | 2917 |   unsigned DiagID; | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2918 |   Decl *TagDecl = Actions.ActOnTag(getCurScope(), DeclSpec::TST_enum, TUK, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 2919 |                                    StartLoc, SS, Name, NameLoc, attrs.getList(), | 
| Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 2920 |                                    AS, DS.getModulePrivateSpecLoc(), | 
| John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2921 |                                    MultiTemplateParamsArg(Actions), | 
| Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 2922 |                                    Owned, IsDependent, IsScopedEnum, | 
| Abramo Bagnara | a88cefd | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 2923 |                                    IsScopedUsingClassTag, BaseType); | 
| Douglas Gregor | 1274ccd | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 2924 |  | 
| Douglas Gregor | 48c89f4 | 2010-04-24 16:38:41 +0000 | [diff] [blame] | 2925 |   if (IsDependent) { | 
 | 2926 |     // This enum has a dependent nested-name-specifier. Handle it as a  | 
 | 2927 |     // dependent tag. | 
 | 2928 |     if (!Name) { | 
 | 2929 |       DS.SetTypeSpecError(); | 
 | 2930 |       Diag(Tok, diag::err_expected_type_name_after_typename); | 
 | 2931 |       return; | 
 | 2932 |     } | 
 | 2933 |      | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2934 |     TypeResult Type = Actions.ActOnDependentTag(getCurScope(), DeclSpec::TST_enum, | 
| Douglas Gregor | 48c89f4 | 2010-04-24 16:38:41 +0000 | [diff] [blame] | 2935 |                                                 TUK, SS, Name, StartLoc,  | 
 | 2936 |                                                 NameLoc); | 
 | 2937 |     if (Type.isInvalid()) { | 
 | 2938 |       DS.SetTypeSpecError(); | 
 | 2939 |       return; | 
 | 2940 |     } | 
 | 2941 |      | 
| Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 2942 |     if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, | 
 | 2943 |                            NameLoc.isValid() ? NameLoc : StartLoc, | 
 | 2944 |                            PrevSpec, DiagID, Type.get())) | 
| Douglas Gregor | 48c89f4 | 2010-04-24 16:38:41 +0000 | [diff] [blame] | 2945 |       Diag(StartLoc, DiagID) << PrevSpec; | 
 | 2946 |      | 
 | 2947 |     return; | 
 | 2948 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2949 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2950 |   if (!TagDecl) { | 
| Douglas Gregor | 48c89f4 | 2010-04-24 16:38:41 +0000 | [diff] [blame] | 2951 |     // The action failed to produce an enumeration tag. If this is a  | 
 | 2952 |     // definition, consume the entire definition. | 
 | 2953 |     if (Tok.is(tok::l_brace)) { | 
 | 2954 |       ConsumeBrace(); | 
 | 2955 |       SkipUntil(tok::r_brace); | 
 | 2956 |     } | 
 | 2957 |      | 
 | 2958 |     DS.SetTypeSpecError(); | 
 | 2959 |     return; | 
 | 2960 |   } | 
 | 2961 |    | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2962 |   if (Tok.is(tok::l_brace)) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2963 |     ParseEnumBody(StartLoc, TagDecl); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2964 |  | 
| Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 2965 |   if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, | 
 | 2966 |                          NameLoc.isValid() ? NameLoc : StartLoc, | 
 | 2967 |                          PrevSpec, DiagID, TagDecl, Owned)) | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 2968 |     Diag(StartLoc, DiagID) << PrevSpec; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2969 | } | 
 | 2970 |  | 
 | 2971 | /// ParseEnumBody - Parse a {} enclosed enumerator-list. | 
 | 2972 | ///       enumerator-list: | 
 | 2973 | ///         enumerator | 
 | 2974 | ///         enumerator-list ',' enumerator | 
 | 2975 | ///       enumerator: | 
 | 2976 | ///         enumeration-constant | 
 | 2977 | ///         enumeration-constant '=' constant-expression | 
 | 2978 | ///       enumeration-constant: | 
 | 2979 | ///         identifier | 
 | 2980 | /// | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2981 | void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) { | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 2982 |   // Enter the scope of the enum body and start the definition. | 
 | 2983 |   ParseScope EnumScope(this, Scope::DeclScope); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2984 |   Actions.ActOnTagStartDefinition(getCurScope(), EnumDecl); | 
| Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 2985 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2986 |   SourceLocation LBraceLoc = ConsumeBrace(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2987 |  | 
| Chris Lattner | 7946dd3 | 2007-08-27 17:24:30 +0000 | [diff] [blame] | 2988 |   // C does not allow an empty enumerator-list, C++ does [dcl.enum]. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2989 |   if (Tok.is(tok::r_brace) && !getLang().CPlusPlus) | 
| Fariborz Jahanian | 0511552 | 2010-05-28 22:23:22 +0000 | [diff] [blame] | 2990 |     Diag(Tok, diag::error_empty_enum); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2991 |  | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2992 |   SmallVector<Decl *, 32> EnumConstantDecls; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2993 |  | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 2994 |   Decl *LastEnumConstDecl = 0; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2995 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2996 |   // Parse the enumerator-list. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 2997 |   while (Tok.is(tok::identifier)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2998 |     IdentifierInfo *Ident = Tok.getIdentifierInfo(); | 
 | 2999 |     SourceLocation IdentLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3000 |  | 
| John McCall | 5b629aa | 2010-10-22 23:36:17 +0000 | [diff] [blame] | 3001 |     // If attributes exist after the enumerator, parse them. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3002 |     ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3003 |     MaybeParseGNUAttributes(attrs); | 
| John McCall | 5b629aa | 2010-10-22 23:36:17 +0000 | [diff] [blame] | 3004 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3005 |     SourceLocation EqualLoc; | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 3006 |     ExprResult AssignedVal; | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 3007 |     if (Tok.is(tok::equal)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3008 |       EqualLoc = ConsumeToken(); | 
| Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 3009 |       AssignedVal = ParseConstantExpression(); | 
 | 3010 |       if (AssignedVal.isInvalid()) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3011 |         SkipUntil(tok::comma, tok::r_brace, true, true); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3012 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3013 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3014 |     // Install the enumerator constant into EnumDecl. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3015 |     Decl *EnumConstDecl = Actions.ActOnEnumConstant(getCurScope(), EnumDecl, | 
 | 3016 |                                                     LastEnumConstDecl, | 
 | 3017 |                                                     IdentLoc, Ident, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3018 |                                                     attrs.getList(), EqualLoc, | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3019 |                                                     AssignedVal.release()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3020 |     EnumConstantDecls.push_back(EnumConstDecl); | 
 | 3021 |     LastEnumConstDecl = EnumConstDecl; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3022 |  | 
| Douglas Gregor | 751f692 | 2010-09-07 14:51:08 +0000 | [diff] [blame] | 3023 |     if (Tok.is(tok::identifier)) { | 
 | 3024 |       // We're missing a comma between enumerators. | 
 | 3025 |       SourceLocation Loc = PP.getLocForEndOfToken(PrevTokLocation); | 
 | 3026 |       Diag(Loc, diag::err_enumerator_list_missing_comma)       | 
 | 3027 |         << FixItHint::CreateInsertion(Loc, ", "); | 
 | 3028 |       continue; | 
 | 3029 |     } | 
 | 3030 |      | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 3031 |     if (Tok.isNot(tok::comma)) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3032 |       break; | 
 | 3033 |     SourceLocation CommaLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 |  | 
 | 3035 |     if (Tok.isNot(tok::identifier) && | 
| Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 3036 |         !(getLang().C99 || getLang().CPlusPlus0x)) | 
 | 3037 |       Diag(CommaLoc, diag::ext_enumerator_list_comma) | 
 | 3038 |         << getLang().CPlusPlus | 
| Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 3039 |         << FixItHint::CreateRemoval(CommaLoc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3040 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3041 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3042 |   // Eat the }. | 
| Mike Stump | c6e35aa | 2009-05-16 07:06:02 +0000 | [diff] [blame] | 3043 |   SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3044 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3045 |   // If attributes exist after the identifier list, parse them. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3046 |   ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3047 |   MaybeParseGNUAttributes(attrs); | 
| Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 3048 |  | 
| Edward O'Callaghan | fee1381 | 2009-08-08 14:36:57 +0000 | [diff] [blame] | 3049 |   Actions.ActOnEnumBody(StartLoc, LBraceLoc, RBraceLoc, EnumDecl, | 
 | 3050 |                         EnumConstantDecls.data(), EnumConstantDecls.size(), | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3051 |                         getCurScope(), attrs.getList()); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3052 |  | 
| Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 3053 |   EnumScope.Exit(); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3054 |   Actions.ActOnTagFinishDefinition(getCurScope(), EnumDecl, RBraceLoc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3055 | } | 
 | 3056 |  | 
 | 3057 | /// isTypeSpecifierQualifier - Return true if the current token could be the | 
| Steve Naroff | 5f8aa69 | 2008-02-11 23:15:56 +0000 | [diff] [blame] | 3058 | /// start of a type-qualifier-list. | 
 | 3059 | bool Parser::isTypeQualifier() const { | 
 | 3060 |   switch (Tok.getKind()) { | 
 | 3061 |   default: return false; | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3062 |  | 
 | 3063 |     // type-qualifier only in OpenCL | 
 | 3064 |   case tok::kw_private: | 
 | 3065 |     return getLang().OpenCL; | 
 | 3066 |  | 
| Steve Naroff | 5f8aa69 | 2008-02-11 23:15:56 +0000 | [diff] [blame] | 3067 |     // type-qualifier | 
 | 3068 |   case tok::kw_const: | 
 | 3069 |   case tok::kw_volatile: | 
 | 3070 |   case tok::kw_restrict: | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3071 |   case tok::kw___private: | 
 | 3072 |   case tok::kw___local: | 
 | 3073 |   case tok::kw___global: | 
 | 3074 |   case tok::kw___constant: | 
 | 3075 |   case tok::kw___read_only: | 
 | 3076 |   case tok::kw___read_write: | 
 | 3077 |   case tok::kw___write_only: | 
| Steve Naroff | 5f8aa69 | 2008-02-11 23:15:56 +0000 | [diff] [blame] | 3078 |     return true; | 
 | 3079 |   } | 
 | 3080 | } | 
 | 3081 |  | 
| Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 3082 | /// isKnownToBeTypeSpecifier - Return true if we know that the specified token | 
 | 3083 | /// is definitely a type-specifier.  Return false if it isn't part of a type | 
 | 3084 | /// specifier or if we're not sure. | 
 | 3085 | bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const { | 
 | 3086 |   switch (Tok.getKind()) { | 
 | 3087 |   default: return false; | 
 | 3088 |     // type-specifiers | 
 | 3089 |   case tok::kw_short: | 
 | 3090 |   case tok::kw_long: | 
| Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 3091 |   case tok::kw___int64: | 
| Chris Lattner | b3a4e43 | 2010-02-28 18:18:36 +0000 | [diff] [blame] | 3092 |   case tok::kw_signed: | 
 | 3093 |   case tok::kw_unsigned: | 
 | 3094 |   case tok::kw__Complex: | 
 | 3095 |   case tok::kw__Imaginary: | 
 | 3096 |   case tok::kw_void: | 
 | 3097 |   case tok::kw_char: | 
 | 3098 |   case tok::kw_wchar_t: | 
 | 3099 |   case tok::kw_char16_t: | 
 | 3100 |   case tok::kw_char32_t: | 
 | 3101 |   case tok::kw_int: | 
 | 3102 |   case tok::kw_float: | 
 | 3103 |   case tok::kw_double: | 
 | 3104 |   case tok::kw_bool: | 
 | 3105 |   case tok::kw__Bool: | 
 | 3106 |   case tok::kw__Decimal32: | 
 | 3107 |   case tok::kw__Decimal64: | 
 | 3108 |   case tok::kw__Decimal128: | 
 | 3109 |   case tok::kw___vector: | 
 | 3110 |      | 
 | 3111 |     // struct-or-union-specifier (C99) or class-specifier (C++) | 
 | 3112 |   case tok::kw_class: | 
 | 3113 |   case tok::kw_struct: | 
 | 3114 |   case tok::kw_union: | 
 | 3115 |     // enum-specifier | 
 | 3116 |   case tok::kw_enum: | 
 | 3117 |      | 
 | 3118 |     // typedef-name | 
 | 3119 |   case tok::annot_typename: | 
 | 3120 |     return true; | 
 | 3121 |   } | 
 | 3122 | } | 
 | 3123 |  | 
| Steve Naroff | 5f8aa69 | 2008-02-11 23:15:56 +0000 | [diff] [blame] | 3124 | /// isTypeSpecifierQualifier - Return true if the current token could be the | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3125 | /// start of a specifier-qualifier-list. | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 3126 | bool Parser::isTypeSpecifierQualifier() { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3127 |   switch (Tok.getKind()) { | 
 | 3128 |   default: return false; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3129 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3130 |   case tok::identifier:   // foo::bar | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3131 |     if (TryAltiVecVectorToken()) | 
 | 3132 |       return true; | 
 | 3133 |     // Fall through. | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 3134 |   case tok::kw_typename:  // typename T::type | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3135 |     // Annotate typenames and C++ scope specifiers.  If we get one, just | 
 | 3136 |     // recurse to handle whatever we get. | 
 | 3137 |     if (TryAnnotateTypeOrScopeToken()) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3138 |       return true; | 
 | 3139 |     if (Tok.is(tok::identifier)) | 
 | 3140 |       return false; | 
 | 3141 |     return isTypeSpecifierQualifier(); | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 3142 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3143 |   case tok::coloncolon:   // ::foo::bar | 
 | 3144 |     if (NextToken().is(tok::kw_new) ||    // ::new | 
 | 3145 |         NextToken().is(tok::kw_delete))   // ::delete | 
 | 3146 |       return false; | 
 | 3147 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3148 |     if (TryAnnotateTypeOrScopeToken()) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3149 |       return true; | 
 | 3150 |     return isTypeSpecifierQualifier(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3151 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3152 |     // GNU attributes support. | 
 | 3153 |   case tok::kw___attribute: | 
| Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 3154 |     // GNU typeof support. | 
 | 3155 |   case tok::kw_typeof: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3156 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3157 |     // type-specifiers | 
 | 3158 |   case tok::kw_short: | 
 | 3159 |   case tok::kw_long: | 
| Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 3160 |   case tok::kw___int64: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3161 |   case tok::kw_signed: | 
 | 3162 |   case tok::kw_unsigned: | 
 | 3163 |   case tok::kw__Complex: | 
 | 3164 |   case tok::kw__Imaginary: | 
 | 3165 |   case tok::kw_void: | 
 | 3166 |   case tok::kw_char: | 
| Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 3167 |   case tok::kw_wchar_t: | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 3168 |   case tok::kw_char16_t: | 
 | 3169 |   case tok::kw_char32_t: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3170 |   case tok::kw_int: | 
 | 3171 |   case tok::kw_float: | 
 | 3172 |   case tok::kw_double: | 
| Chris Lattner | 9298d96 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 3173 |   case tok::kw_bool: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3174 |   case tok::kw__Bool: | 
 | 3175 |   case tok::kw__Decimal32: | 
 | 3176 |   case tok::kw__Decimal64: | 
 | 3177 |   case tok::kw__Decimal128: | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3178 |   case tok::kw___vector: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3179 |  | 
| Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 3180 |     // struct-or-union-specifier (C99) or class-specifier (C++) | 
 | 3181 |   case tok::kw_class: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3182 |   case tok::kw_struct: | 
 | 3183 |   case tok::kw_union: | 
 | 3184 |     // enum-specifier | 
 | 3185 |   case tok::kw_enum: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3186 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3187 |     // type-qualifier | 
 | 3188 |   case tok::kw_const: | 
 | 3189 |   case tok::kw_volatile: | 
 | 3190 |   case tok::kw_restrict: | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 3191 |  | 
 | 3192 |     // typedef-name | 
| Chris Lattner | b31757b | 2009-01-06 05:06:21 +0000 | [diff] [blame] | 3193 |   case tok::annot_typename: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3194 |     return true; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3195 |  | 
| Chris Lattner | 7c186be | 2008-10-20 00:25:30 +0000 | [diff] [blame] | 3196 |     // GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'. | 
 | 3197 |   case tok::less: | 
 | 3198 |     return getLang().ObjC1; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3199 |  | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 3200 |   case tok::kw___cdecl: | 
 | 3201 |   case tok::kw___stdcall: | 
 | 3202 |   case tok::kw___fastcall: | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 3203 |   case tok::kw___thiscall: | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3204 |   case tok::kw___w64: | 
 | 3205 |   case tok::kw___ptr64: | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 3206 |   case tok::kw___ptr32: | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3207 |   case tok::kw___pascal: | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 3208 |   case tok::kw___unaligned: | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3209 |  | 
 | 3210 |   case tok::kw___private: | 
 | 3211 |   case tok::kw___local: | 
 | 3212 |   case tok::kw___global: | 
 | 3213 |   case tok::kw___constant: | 
 | 3214 |   case tok::kw___read_only: | 
 | 3215 |   case tok::kw___read_write: | 
 | 3216 |   case tok::kw___write_only: | 
 | 3217 |  | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3218 |     return true; | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3219 |  | 
 | 3220 |   case tok::kw_private: | 
 | 3221 |     return getLang().OpenCL; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3222 |   } | 
 | 3223 | } | 
 | 3224 |  | 
 | 3225 | /// isDeclarationSpecifier() - Return true if the current token is part of a | 
 | 3226 | /// declaration specifier. | 
| Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 3227 | /// | 
 | 3228 | /// \param DisambiguatingWithExpression True to indicate that the purpose of | 
 | 3229 | /// this check is to disambiguate between an expression and a declaration. | 
 | 3230 | bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3231 |   switch (Tok.getKind()) { | 
 | 3232 |   default: return false; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3233 |  | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3234 |   case tok::kw_private: | 
 | 3235 |     return getLang().OpenCL; | 
 | 3236 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3237 |   case tok::identifier:   // foo::bar | 
| Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 3238 |     // Unfortunate hack to support "Class.factoryMethod" notation. | 
 | 3239 |     if (getLang().ObjC1 && NextToken().is(tok::period)) | 
 | 3240 |       return false; | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3241 |     if (TryAltiVecVectorToken()) | 
 | 3242 |       return true; | 
 | 3243 |     // Fall through. | 
| Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 3244 |   case tok::kw_typename: // typename T::type | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3245 |     // Annotate typenames and C++ scope specifiers.  If we get one, just | 
 | 3246 |     // recurse to handle whatever we get. | 
 | 3247 |     if (TryAnnotateTypeOrScopeToken()) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3248 |       return true; | 
 | 3249 |     if (Tok.is(tok::identifier)) | 
 | 3250 |       return false; | 
| Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 3251 |        | 
 | 3252 |     // If we're in Objective-C and we have an Objective-C class type followed | 
 | 3253 |     // by an identifier and then either ':' or ']', in a place where an  | 
 | 3254 |     // expression is permitted, then this is probably a class message send | 
 | 3255 |     // missing the initial '['. In this case, we won't consider this to be | 
 | 3256 |     // the start of a declaration. | 
 | 3257 |     if (DisambiguatingWithExpression &&  | 
 | 3258 |         isStartOfObjCClassMessageMissingOpenBracket()) | 
 | 3259 |       return false; | 
 | 3260 |        | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3261 |     return isDeclarationSpecifier(); | 
 | 3262 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3263 |   case tok::coloncolon:   // ::foo::bar | 
 | 3264 |     if (NextToken().is(tok::kw_new) ||    // ::new | 
 | 3265 |         NextToken().is(tok::kw_delete))   // ::delete | 
 | 3266 |       return false; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3267 |  | 
| Chris Lattner | 166a8fc | 2009-01-04 23:41:41 +0000 | [diff] [blame] | 3268 |     // Annotate typenames and C++ scope specifiers.  If we get one, just | 
 | 3269 |     // recurse to handle whatever we get. | 
 | 3270 |     if (TryAnnotateTypeOrScopeToken()) | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3271 |       return true; | 
 | 3272 |     return isDeclarationSpecifier(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3273 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3274 |     // storage-class-specifier | 
 | 3275 |   case tok::kw_typedef: | 
 | 3276 |   case tok::kw_extern: | 
| Steve Naroff | 8d54bf2 | 2007-12-18 00:16:02 +0000 | [diff] [blame] | 3277 |   case tok::kw___private_extern__: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3278 |   case tok::kw_static: | 
 | 3279 |   case tok::kw_auto: | 
 | 3280 |   case tok::kw_register: | 
 | 3281 |   case tok::kw___thread: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3282 |  | 
| Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 3283 |     // Modules | 
 | 3284 |   case tok::kw___module_private__: | 
 | 3285 |        | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3286 |     // type-specifiers | 
 | 3287 |   case tok::kw_short: | 
 | 3288 |   case tok::kw_long: | 
| Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 3289 |   case tok::kw___int64: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3290 |   case tok::kw_signed: | 
 | 3291 |   case tok::kw_unsigned: | 
 | 3292 |   case tok::kw__Complex: | 
 | 3293 |   case tok::kw__Imaginary: | 
 | 3294 |   case tok::kw_void: | 
 | 3295 |   case tok::kw_char: | 
| Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 3296 |   case tok::kw_wchar_t: | 
| Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 3297 |   case tok::kw_char16_t: | 
 | 3298 |   case tok::kw_char32_t: | 
 | 3299 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3300 |   case tok::kw_int: | 
 | 3301 |   case tok::kw_float: | 
 | 3302 |   case tok::kw_double: | 
| Chris Lattner | 9298d96 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 3303 |   case tok::kw_bool: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3304 |   case tok::kw__Bool: | 
 | 3305 |   case tok::kw__Decimal32: | 
 | 3306 |   case tok::kw__Decimal64: | 
 | 3307 |   case tok::kw__Decimal128: | 
| John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 3308 |   case tok::kw___vector: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 |  | 
| Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 3310 |     // struct-or-union-specifier (C99) or class-specifier (C++) | 
 | 3311 |   case tok::kw_class: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3312 |   case tok::kw_struct: | 
 | 3313 |   case tok::kw_union: | 
 | 3314 |     // enum-specifier | 
 | 3315 |   case tok::kw_enum: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3316 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3317 |     // type-qualifier | 
 | 3318 |   case tok::kw_const: | 
 | 3319 |   case tok::kw_volatile: | 
 | 3320 |   case tok::kw_restrict: | 
| Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 3321 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3322 |     // function-specifier | 
 | 3323 |   case tok::kw_inline: | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 3324 |   case tok::kw_virtual: | 
 | 3325 |   case tok::kw_explicit: | 
| Chris Lattner | d6c7c18 | 2007-08-09 16:40:21 +0000 | [diff] [blame] | 3326 |  | 
| Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 3327 |     // static_assert-declaration | 
 | 3328 |   case tok::kw__Static_assert: | 
 | 3329 |  | 
| Chris Lattner | 1ef0876 | 2007-08-09 17:01:07 +0000 | [diff] [blame] | 3330 |     // GNU typeof support. | 
 | 3331 |   case tok::kw_typeof: | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3332 |  | 
| Chris Lattner | 1ef0876 | 2007-08-09 17:01:07 +0000 | [diff] [blame] | 3333 |     // GNU attributes. | 
| Chris Lattner | d6c7c18 | 2007-08-09 16:40:21 +0000 | [diff] [blame] | 3334 |   case tok::kw___attribute: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3335 |     return true; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3336 |  | 
| Francois Pichet | e3d49b4 | 2011-06-19 08:02:06 +0000 | [diff] [blame] | 3337 |     // C++0x decltype. | 
 | 3338 |   case tok::kw_decltype: | 
 | 3339 |     return true; | 
 | 3340 |  | 
| Chris Lattner | f3948c4 | 2008-07-26 03:38:44 +0000 | [diff] [blame] | 3341 |     // GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'. | 
 | 3342 |   case tok::less: | 
 | 3343 |     return getLang().ObjC1; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3344 |  | 
| Douglas Gregor | d9d75e5 | 2011-04-27 05:41:15 +0000 | [diff] [blame] | 3345 |     // typedef-name | 
 | 3346 |   case tok::annot_typename: | 
 | 3347 |     return !DisambiguatingWithExpression || | 
 | 3348 |            !isStartOfObjCClassMessageMissingOpenBracket(); | 
 | 3349 |        | 
| Steve Naroff | 47f5209 | 2009-01-06 19:34:12 +0000 | [diff] [blame] | 3350 |   case tok::kw___declspec: | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 3351 |   case tok::kw___cdecl: | 
 | 3352 |   case tok::kw___stdcall: | 
 | 3353 |   case tok::kw___fastcall: | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 3354 |   case tok::kw___thiscall: | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3355 |   case tok::kw___w64: | 
 | 3356 |   case tok::kw___ptr64: | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 3357 |   case tok::kw___ptr32: | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3358 |   case tok::kw___forceinline: | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3359 |   case tok::kw___pascal: | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 3360 |   case tok::kw___unaligned: | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3361 |  | 
 | 3362 |   case tok::kw___private: | 
 | 3363 |   case tok::kw___local: | 
 | 3364 |   case tok::kw___global: | 
 | 3365 |   case tok::kw___constant: | 
 | 3366 |   case tok::kw___read_only: | 
 | 3367 |   case tok::kw___read_write: | 
 | 3368 |   case tok::kw___write_only: | 
 | 3369 |  | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3370 |     return true; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3371 |   } | 
 | 3372 | } | 
 | 3373 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3374 | bool Parser::isConstructorDeclarator() { | 
 | 3375 |   TentativeParsingAction TPA(*this); | 
 | 3376 |  | 
 | 3377 |   // Parse the C++ scope specifier. | 
 | 3378 |   CXXScopeSpec SS; | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 3379 |   if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), true)) { | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3380 |     TPA.Revert(); | 
 | 3381 |     return false; | 
 | 3382 |   } | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3383 |  | 
 | 3384 |   // Parse the constructor name. | 
 | 3385 |   if (Tok.is(tok::identifier) || Tok.is(tok::annot_template_id)) { | 
 | 3386 |     // We already know that we have a constructor name; just consume | 
 | 3387 |     // the token. | 
 | 3388 |     ConsumeToken(); | 
 | 3389 |   } else { | 
 | 3390 |     TPA.Revert(); | 
 | 3391 |     return false; | 
 | 3392 |   } | 
 | 3393 |  | 
 | 3394 |   // Current class name must be followed by a left parentheses. | 
 | 3395 |   if (Tok.isNot(tok::l_paren)) { | 
 | 3396 |     TPA.Revert(); | 
 | 3397 |     return false; | 
 | 3398 |   } | 
 | 3399 |   ConsumeParen(); | 
 | 3400 |  | 
 | 3401 |   // A right parentheses or ellipsis signals that we have a constructor. | 
 | 3402 |   if (Tok.is(tok::r_paren) || Tok.is(tok::ellipsis)) { | 
 | 3403 |     TPA.Revert(); | 
 | 3404 |     return true; | 
 | 3405 |   } | 
 | 3406 |  | 
 | 3407 |   // If we need to, enter the specified scope. | 
 | 3408 |   DeclaratorScopeObj DeclScopeObj(*this, SS); | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3409 |   if (SS.isSet() && Actions.ShouldEnterDeclaratorScope(getCurScope(), SS)) | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3410 |     DeclScopeObj.EnterDeclaratorScope(); | 
 | 3411 |  | 
| Francois Pichet | dfaa5fb | 2011-01-31 04:54:32 +0000 | [diff] [blame] | 3412 |   // Optionally skip Microsoft attributes. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3413 |   ParsedAttributes Attrs(AttrFactory); | 
| Francois Pichet | dfaa5fb | 2011-01-31 04:54:32 +0000 | [diff] [blame] | 3414 |   MaybeParseMicrosoftAttributes(Attrs); | 
 | 3415 |  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3416 |   // Check whether the next token(s) are part of a declaration | 
 | 3417 |   // specifier, in which case we have the start of a parameter and, | 
 | 3418 |   // therefore, we know that this is a constructor. | 
 | 3419 |   bool IsConstructor = isDeclarationSpecifier(); | 
 | 3420 |   TPA.Revert(); | 
 | 3421 |   return IsConstructor; | 
 | 3422 | } | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3423 |  | 
 | 3424 | /// ParseTypeQualifierListOpt | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3425 | ///          type-qualifier-list: [C99 6.7.5] | 
 | 3426 | ///            type-qualifier | 
 | 3427 | /// [vendor]   attributes                         | 
 | 3428 | ///              [ only if VendorAttributesAllowed=true ] | 
 | 3429 | ///            type-qualifier-list type-qualifier | 
 | 3430 | /// [vendor]   type-qualifier-list attributes     | 
 | 3431 | ///              [ only if VendorAttributesAllowed=true ] | 
 | 3432 | /// [C++0x]    attribute-specifier[opt] is allowed before cv-qualifier-seq | 
 | 3433 | ///              [ only if CXX0XAttributesAllowed=true ] | 
 | 3434 | /// Note: vendor can be GNU, MS, etc. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3435 | /// | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3436 | void Parser::ParseTypeQualifierListOpt(DeclSpec &DS, | 
 | 3437 |                                        bool VendorAttributesAllowed, | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3438 |                                        bool CXX0XAttributesAllowed) { | 
 | 3439 |   if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { | 
 | 3440 |     SourceLocation Loc = Tok.getLocation(); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3441 |     ParsedAttributesWithRange attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3442 |     ParseCXX0XAttributes(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3443 |     if (CXX0XAttributesAllowed) | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3444 |       DS.takeAttributesFrom(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3445 |     else | 
 | 3446 |       Diag(Loc, diag::err_attributes_not_allowed); | 
 | 3447 |   } | 
| Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3448 |  | 
 | 3449 |   SourceLocation EndLoc; | 
 | 3450 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3451 |   while (1) { | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 3452 |     bool isInvalid = false; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3453 |     const char *PrevSpec = 0; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 3454 |     unsigned DiagID = 0; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3455 |     SourceLocation Loc = Tok.getLocation(); | 
 | 3456 |  | 
 | 3457 |     switch (Tok.getKind()) { | 
| Douglas Gregor | 1a480c4 | 2010-08-27 17:35:51 +0000 | [diff] [blame] | 3458 |     case tok::code_completion: | 
 | 3459 |       Actions.CodeCompleteTypeQualifiers(DS); | 
| Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 3460 |       return cutOffParsing(); | 
| Douglas Gregor | 1a480c4 | 2010-08-27 17:35:51 +0000 | [diff] [blame] | 3461 |          | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3462 |     case tok::kw_const: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 3463 |       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const   , Loc, PrevSpec, DiagID, | 
 | 3464 |                                  getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3465 |       break; | 
 | 3466 |     case tok::kw_volatile: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 3467 |       isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID, | 
 | 3468 |                                  getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3469 |       break; | 
 | 3470 |     case tok::kw_restrict: | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 3471 |       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID, | 
 | 3472 |                                  getLang()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3473 |       break; | 
| Peter Collingbourne | 207f4d8 | 2011-03-18 22:38:29 +0000 | [diff] [blame] | 3474 |  | 
 | 3475 |     // OpenCL qualifiers: | 
 | 3476 |     case tok::kw_private:  | 
 | 3477 |       if (!getLang().OpenCL) | 
 | 3478 |         goto DoneWithTypeQuals; | 
 | 3479 |     case tok::kw___private: | 
 | 3480 |     case tok::kw___global: | 
 | 3481 |     case tok::kw___local: | 
 | 3482 |     case tok::kw___constant: | 
 | 3483 |     case tok::kw___read_only: | 
 | 3484 |     case tok::kw___write_only: | 
 | 3485 |     case tok::kw___read_write: | 
 | 3486 |       ParseOpenCLQualifiers(DS); | 
 | 3487 |       break; | 
 | 3488 |  | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3489 |     case tok::kw___w64: | 
| Steve Naroff | 86bc6cf | 2008-12-25 14:41:26 +0000 | [diff] [blame] | 3490 |     case tok::kw___ptr64: | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 3491 |     case tok::kw___ptr32: | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 3492 |     case tok::kw___cdecl: | 
 | 3493 |     case tok::kw___stdcall: | 
 | 3494 |     case tok::kw___fastcall: | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 3495 |     case tok::kw___thiscall: | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 3496 |     case tok::kw___unaligned: | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3497 |       if (VendorAttributesAllowed) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3498 |         ParseMicrosoftTypeAttributes(DS.getAttributes()); | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3499 |         continue; | 
 | 3500 |       } | 
 | 3501 |       goto DoneWithTypeQuals; | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3502 |     case tok::kw___pascal: | 
 | 3503 |       if (VendorAttributesAllowed) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3504 |         ParseBorlandTypeAttributes(DS.getAttributes()); | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3505 |         continue; | 
 | 3506 |       } | 
 | 3507 |       goto DoneWithTypeQuals; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3508 |     case tok::kw___attribute: | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3509 |       if (VendorAttributesAllowed) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3510 |         ParseGNUAttributes(DS.getAttributes()); | 
| Chris Lattner | 5a69d1c | 2008-12-18 07:02:59 +0000 | [diff] [blame] | 3511 |         continue; // do *not* consume the next token! | 
 | 3512 |       } | 
 | 3513 |       // otherwise, FALL THROUGH! | 
 | 3514 |     default: | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 3515 |       DoneWithTypeQuals: | 
| Chris Lattner | 5a69d1c | 2008-12-18 07:02:59 +0000 | [diff] [blame] | 3516 |       // If this is not a type-qualifier token, we're done reading type | 
 | 3517 |       // qualifiers.  First verify that DeclSpec's are consistent. | 
| Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 3518 |       DS.Finish(Diags, PP); | 
| Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3519 |       if (EndLoc.isValid()) | 
 | 3520 |         DS.SetRangeEnd(EndLoc); | 
| Chris Lattner | 5a69d1c | 2008-12-18 07:02:59 +0000 | [diff] [blame] | 3521 |       return; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3522 |     } | 
| Chris Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 3523 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3524 |     // If the specifier combination wasn't legal, issue a diagnostic. | 
 | 3525 |     if (isInvalid) { | 
 | 3526 |       assert(PrevSpec && "Method did not return previous specifier!"); | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 3527 |       Diag(Tok, DiagID) << PrevSpec; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3528 |     } | 
| Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3529 |     EndLoc = ConsumeToken(); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3530 |   } | 
 | 3531 | } | 
 | 3532 |  | 
 | 3533 |  | 
 | 3534 | /// ParseDeclarator - Parse and verify a newly-initialized declarator. | 
 | 3535 | /// | 
 | 3536 | void Parser::ParseDeclarator(Declarator &D) { | 
 | 3537 |   /// This implements the 'declarator' production in the C grammar, then checks | 
 | 3538 |   /// for well-formedness and issues diagnostics. | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3539 |   ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3540 | } | 
 | 3541 |  | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3542 | /// ParseDeclaratorInternal - Parse a C or C++ declarator. The direct-declarator | 
 | 3543 | /// is parsed by the function passed to it. Pass null, and the direct-declarator | 
 | 3544 | /// isn't parsed at all, making this function effectively parse the C++ | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 3545 | /// ptr-operator production. | 
 | 3546 | /// | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3547 | ///       declarator: [C99 6.7.5] [C++ 8p4, dcl.decl] | 
 | 3548 | /// [C]     pointer[opt] direct-declarator | 
 | 3549 | /// [C++]   direct-declarator | 
 | 3550 | /// [C++]   ptr-operator declarator | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3551 | /// | 
 | 3552 | ///       pointer: [C99 6.7.5] | 
 | 3553 | ///         '*' type-qualifier-list[opt] | 
 | 3554 | ///         '*' type-qualifier-list[opt] pointer | 
 | 3555 | /// | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 3556 | ///       ptr-operator: | 
 | 3557 | ///         '*' cv-qualifier-seq[opt] | 
 | 3558 | ///         '&' | 
| Sebastian Redl | 05532f2 | 2009-03-15 22:02:01 +0000 | [diff] [blame] | 3559 | /// [C++0x] '&&' | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 3560 | /// [GNU]   '&' restrict[opt] attributes[opt] | 
| Sebastian Redl | 05532f2 | 2009-03-15 22:02:01 +0000 | [diff] [blame] | 3561 | /// [GNU?]  '&&' restrict[opt] attributes[opt] | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3562 | ///         '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt] | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3563 | void Parser::ParseDeclaratorInternal(Declarator &D, | 
 | 3564 |                                      DirectDeclParseFunction DirectDeclParser) { | 
| Douglas Gregor | 91a2886 | 2009-08-26 14:27:30 +0000 | [diff] [blame] | 3565 |   if (Diags.hasAllExtensionsSilenced()) | 
 | 3566 |     D.setExtension(); | 
| Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 3567 |    | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3568 |   // C++ member pointers start with a '::' or a nested-name. | 
 | 3569 |   // Member pointers get special handling, since there's no place for the | 
 | 3570 |   // scope spec in the generic path below. | 
| Chris Lattner | f919bfe | 2009-03-24 17:04:48 +0000 | [diff] [blame] | 3571 |   if (getLang().CPlusPlus && | 
 | 3572 |       (Tok.is(tok::coloncolon) || Tok.is(tok::identifier) || | 
 | 3573 |        Tok.is(tok::annot_cxxscope))) { | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3574 |     CXXScopeSpec SS; | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 3575 |     ParseOptionalCXXScopeSpecifier(SS, ParsedType(), true); // ignore fail | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3576 |  | 
| Jeffrey Yasskin | edc2877 | 2010-04-07 23:29:58 +0000 | [diff] [blame] | 3577 |     if (SS.isNotEmpty()) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3578 |       if (Tok.isNot(tok::star)) { | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3579 |         // The scope spec really belongs to the direct-declarator. | 
 | 3580 |         D.getCXXScopeSpec() = SS; | 
 | 3581 |         if (DirectDeclParser) | 
 | 3582 |           (this->*DirectDeclParser)(D); | 
 | 3583 |         return; | 
 | 3584 |       } | 
 | 3585 |  | 
 | 3586 |       SourceLocation Loc = ConsumeToken(); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3587 |       D.SetRangeEnd(Loc); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3588 |       DeclSpec DS(AttrFactory); | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3589 |       ParseTypeQualifierListOpt(DS); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3590 |       D.ExtendWithDeclSpec(DS); | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3591 |  | 
 | 3592 |       // Recurse to parse whatever is left. | 
 | 3593 |       ParseDeclaratorInternal(D, DirectDeclParser); | 
 | 3594 |  | 
 | 3595 |       // Sema will have to catch (syntactically invalid) pointers into global | 
 | 3596 |       // scope. It has to catch pointers into namespace scope anyway. | 
 | 3597 |       D.AddTypeInfo(DeclaratorChunk::getMemberPointer(SS,DS.getTypeQualifiers(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3598 |                                                       Loc), | 
 | 3599 |                     DS.getAttributes(), | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3600 |                     /* Don't replace range end. */SourceLocation()); | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3601 |       return; | 
 | 3602 |     } | 
 | 3603 |   } | 
 | 3604 |  | 
 | 3605 |   tok::TokenKind Kind = Tok.getKind(); | 
| Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 3606 |   // Not a pointer, C++ reference, or block. | 
| Chris Lattner | 9af5500 | 2009-03-27 04:18:06 +0000 | [diff] [blame] | 3607 |   if (Kind != tok::star && Kind != tok::caret && | 
| Chris Lattner | f919bfe | 2009-03-24 17:04:48 +0000 | [diff] [blame] | 3608 |       (Kind != tok::amp || !getLang().CPlusPlus) && | 
| Sebastian Redl | 743de1f | 2009-03-23 00:00:23 +0000 | [diff] [blame] | 3609 |       // We parse rvalue refs in C++03, because otherwise the errors are scary. | 
| Chris Lattner | 9af5500 | 2009-03-27 04:18:06 +0000 | [diff] [blame] | 3610 |       (Kind != tok::ampamp || !getLang().CPlusPlus)) { | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3611 |     if (DirectDeclParser) | 
 | 3612 |       (this->*DirectDeclParser)(D); | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 3613 |     return; | 
 | 3614 |   } | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3615 |  | 
| Sebastian Redl | 05532f2 | 2009-03-15 22:02:01 +0000 | [diff] [blame] | 3616 |   // Otherwise, '*' -> pointer, '^' -> block, '&' -> lvalue reference, | 
 | 3617 |   // '&&' -> rvalue reference | 
| Sebastian Redl | 743de1f | 2009-03-23 00:00:23 +0000 | [diff] [blame] | 3618 |   SourceLocation Loc = ConsumeToken();  // Eat the *, ^, & or &&. | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3619 |   D.SetRangeEnd(Loc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3620 |  | 
| Chris Lattner | 9af5500 | 2009-03-27 04:18:06 +0000 | [diff] [blame] | 3621 |   if (Kind == tok::star || Kind == tok::caret) { | 
| Chris Lattner | 7654914 | 2008-02-21 01:32:26 +0000 | [diff] [blame] | 3622 |     // Is a pointer. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3623 |     DeclSpec DS(AttrFactory); | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3624 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3625 |     ParseTypeQualifierListOpt(DS); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3626 |     D.ExtendWithDeclSpec(DS); | 
| Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 3627 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3628 |     // Recursively parse the declarator. | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3629 |     ParseDeclaratorInternal(D, DirectDeclParser); | 
| Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 3630 |     if (Kind == tok::star) | 
 | 3631 |       // Remember that we parsed a pointer type, and remember the type-quals. | 
 | 3632 |       D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc, | 
| Chandler Carruth | d067c07 | 2011-02-23 18:51:59 +0000 | [diff] [blame] | 3633 |                                                 DS.getConstSpecLoc(), | 
 | 3634 |                                                 DS.getVolatileSpecLoc(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3635 |                                                 DS.getRestrictSpecLoc()), | 
 | 3636 |                     DS.getAttributes(), | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3637 |                     SourceLocation()); | 
| Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 3638 |     else | 
 | 3639 |       // Remember that we parsed a Block type, and remember the type-quals. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3640 |       D.AddTypeInfo(DeclaratorChunk::getBlockPointer(DS.getTypeQualifiers(), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3641 |                                                      Loc), | 
 | 3642 |                     DS.getAttributes(), | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3643 |                     SourceLocation()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3644 |   } else { | 
 | 3645 |     // Is a reference | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3646 |     DeclSpec DS(AttrFactory); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3647 |  | 
| Sebastian Redl | 743de1f | 2009-03-23 00:00:23 +0000 | [diff] [blame] | 3648 |     // Complain about rvalue references in C++03, but then go on and build | 
 | 3649 |     // the declarator. | 
 | 3650 |     if (Kind == tok::ampamp && !getLang().CPlusPlus0x) | 
| Douglas Gregor | 16cf8f5 | 2011-01-25 02:17:32 +0000 | [diff] [blame] | 3651 |       Diag(Loc, diag::ext_rvalue_reference); | 
| Sebastian Redl | 743de1f | 2009-03-23 00:00:23 +0000 | [diff] [blame] | 3652 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3653 |     // C++ 8.3.2p1: cv-qualified references are ill-formed except when the | 
 | 3654 |     // cv-qualifiers are introduced through the use of a typedef or of a | 
 | 3655 |     // template type argument, in which case the cv-qualifiers are ignored. | 
 | 3656 |     // | 
 | 3657 |     // [GNU] Retricted references are allowed. | 
 | 3658 |     // [GNU] Attributes on references are allowed. | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3659 |     // [C++0x] Attributes on references are not allowed. | 
 | 3660 |     ParseTypeQualifierListOpt(DS, true, false); | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3661 |     D.ExtendWithDeclSpec(DS); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3662 |  | 
 | 3663 |     if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) { | 
 | 3664 |       if (DS.getTypeQualifiers() & DeclSpec::TQ_const) | 
 | 3665 |         Diag(DS.getConstSpecLoc(), | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 3666 |              diag::err_invalid_reference_qualifier_application) << "const"; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3667 |       if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile) | 
 | 3668 |         Diag(DS.getVolatileSpecLoc(), | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 3669 |              diag::err_invalid_reference_qualifier_application) << "volatile"; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3670 |     } | 
 | 3671 |  | 
 | 3672 |     // Recursively parse the declarator. | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3673 |     ParseDeclaratorInternal(D, DirectDeclParser); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3674 |  | 
| Douglas Gregor | f1f9b4e | 2008-11-03 15:51:28 +0000 | [diff] [blame] | 3675 |     if (D.getNumTypeObjects() > 0) { | 
 | 3676 |       // C++ [dcl.ref]p4: There shall be no references to references. | 
 | 3677 |       DeclaratorChunk& InnerChunk = D.getTypeObject(D.getNumTypeObjects() - 1); | 
 | 3678 |       if (InnerChunk.Kind == DeclaratorChunk::Reference) { | 
| Chris Lattner | da83bac | 2008-11-19 07:37:42 +0000 | [diff] [blame] | 3679 |         if (const IdentifierInfo *II = D.getIdentifier()) | 
 | 3680 |           Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference) | 
 | 3681 |            << II; | 
 | 3682 |         else | 
 | 3683 |           Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference) | 
 | 3684 |             << "type name"; | 
| Douglas Gregor | f1f9b4e | 2008-11-03 15:51:28 +0000 | [diff] [blame] | 3685 |  | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3686 |         // Once we've complained about the reference-to-reference, we | 
| Douglas Gregor | f1f9b4e | 2008-11-03 15:51:28 +0000 | [diff] [blame] | 3687 |         // can go ahead and build the (technically ill-formed) | 
 | 3688 |         // declarator: reference collapsing will take care of it. | 
 | 3689 |       } | 
 | 3690 |     } | 
 | 3691 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3692 |     // Remember that we parsed a reference type. It doesn't have type-quals. | 
| Chris Lattner | 7654914 | 2008-02-21 01:32:26 +0000 | [diff] [blame] | 3693 |     D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc, | 
| Sebastian Redl | 05532f2 | 2009-03-15 22:02:01 +0000 | [diff] [blame] | 3694 |                                                 Kind == tok::amp), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3695 |                   DS.getAttributes(), | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 3696 |                   SourceLocation()); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3697 |   } | 
 | 3698 | } | 
 | 3699 |  | 
 | 3700 | /// ParseDirectDeclarator | 
 | 3701 | ///       direct-declarator: [C99 6.7.5] | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 3702 | /// [C99]   identifier | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3703 | ///         '(' declarator ')' | 
 | 3704 | /// [GNU]   '(' attributes declarator ')' | 
 | 3705 | /// [C90]   direct-declarator '[' constant-expression[opt] ']' | 
 | 3706 | /// [C99]   direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']' | 
 | 3707 | /// [C99]   direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']' | 
 | 3708 | /// [C99]   direct-declarator '[' type-qual-list 'static' assignment-expr ']' | 
 | 3709 | /// [C99]   direct-declarator '[' type-qual-list[opt] '*' ']' | 
 | 3710 | ///         direct-declarator '(' parameter-type-list ')' | 
 | 3711 | ///         direct-declarator '(' identifier-list[opt] ')' | 
 | 3712 | /// [GNU]   direct-declarator '(' parameter-forward-declarations | 
 | 3713 | ///                    parameter-type-list[opt] ')' | 
| Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 3714 | /// [C++]   direct-declarator '(' parameter-declaration-clause ')' | 
 | 3715 | ///                    cv-qualifier-seq[opt] exception-specification[opt] | 
| Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 3716 | /// [C++]   declarator-id | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 3717 | /// | 
 | 3718 | ///       declarator-id: [C++ 8] | 
| Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 3719 | ///         '...'[opt] id-expression | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 3720 | ///         '::'[opt] nested-name-specifier[opt] type-name | 
 | 3721 | /// | 
 | 3722 | ///       id-expression: [C++ 5.1] | 
 | 3723 | ///         unqualified-id | 
| Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 3724 | ///         qualified-id | 
| Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 3725 | /// | 
 | 3726 | ///       unqualified-id: [C++ 5.1] | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3727 | ///         identifier | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 3728 | ///         operator-function-id | 
| Douglas Gregor | db422df | 2009-09-25 21:45:23 +0000 | [diff] [blame] | 3729 | ///         conversion-function-id | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3730 | ///          '~' class-name | 
| Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 3731 | ///         template-id | 
| Argyrios Kyrtzidis | c7ed9c6 | 2008-11-07 22:02:30 +0000 | [diff] [blame] | 3732 | /// | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3733 | void Parser::ParseDirectDeclarator(Declarator &D) { | 
| Argyrios Kyrtzidis | 314fe78 | 2008-11-26 22:40:03 +0000 | [diff] [blame] | 3734 |   DeclaratorScopeObj DeclScopeObj(*this, D.getCXXScopeSpec()); | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 3735 |  | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3736 |   if (getLang().CPlusPlus && D.mayHaveIdentifier()) { | 
 | 3737 |     // ParseDeclaratorInternal might already have parsed the scope. | 
| Jeffrey Yasskin | 9ab1454 | 2010-04-08 16:38:48 +0000 | [diff] [blame] | 3738 |     if (D.getCXXScopeSpec().isEmpty()) { | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 3739 |       ParseOptionalCXXScopeSpecifier(D.getCXXScopeSpec(), ParsedType(), true); | 
| John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 3740 |     } | 
 | 3741 |  | 
| Jeffrey Yasskin | 9ab1454 | 2010-04-08 16:38:48 +0000 | [diff] [blame] | 3742 |     if (D.getCXXScopeSpec().isValid()) { | 
| Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 3743 |       if (Actions.ShouldEnterDeclaratorScope(getCurScope(), D.getCXXScopeSpec())) | 
| John McCall | e7e278b | 2009-12-11 20:04:54 +0000 | [diff] [blame] | 3744 |         // Change the declaration context for name lookup, until this function | 
 | 3745 |         // is exited (and the declarator has been parsed). | 
 | 3746 |         DeclScopeObj.EnterDeclaratorScope(); | 
| Jeffrey Yasskin | 9ab1454 | 2010-04-08 16:38:48 +0000 | [diff] [blame] | 3747 |     } | 
 | 3748 |  | 
| Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 3749 |     // C++0x [dcl.fct]p14: | 
 | 3750 |     //   There is a syntactic ambiguity when an ellipsis occurs at the end | 
 | 3751 |     //   of a parameter-declaration-clause without a preceding comma. In  | 
 | 3752 |     //   this case, the ellipsis is parsed as part of the  | 
 | 3753 |     //   abstract-declarator if the type of the parameter names a template  | 
 | 3754 |     //   parameter pack that has not been expanded; otherwise, it is parsed | 
 | 3755 |     //   as part of the parameter-declaration-clause. | 
 | 3756 |     if (Tok.is(tok::ellipsis) && | 
 | 3757 |         !((D.getContext() == Declarator::PrototypeContext || | 
 | 3758 |            D.getContext() == Declarator::BlockLiteralContext) && | 
| Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 3759 |           NextToken().is(tok::r_paren) && | 
 | 3760 |           !Actions.containsUnexpandedParameterPacks(D))) | 
 | 3761 |       D.setEllipsisLoc(ConsumeToken()); | 
 | 3762 |      | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3763 |     if (Tok.is(tok::identifier) || Tok.is(tok::kw_operator) || | 
 | 3764 |         Tok.is(tok::annot_template_id) || Tok.is(tok::tilde)) { | 
 | 3765 |       // We found something that indicates the start of an unqualified-id. | 
 | 3766 |       // Parse that unqualified-id. | 
| John McCall | ba9d853 | 2010-04-13 06:39:49 +0000 | [diff] [blame] | 3767 |       bool AllowConstructorName; | 
 | 3768 |       if (D.getDeclSpec().hasTypeSpecifier()) | 
 | 3769 |         AllowConstructorName = false; | 
 | 3770 |       else if (D.getCXXScopeSpec().isSet()) | 
 | 3771 |         AllowConstructorName = | 
 | 3772 |           (D.getContext() == Declarator::FileContext || | 
 | 3773 |            (D.getContext() == Declarator::MemberContext && | 
 | 3774 |             D.getDeclSpec().isFriendSpecified())); | 
 | 3775 |       else | 
 | 3776 |         AllowConstructorName = (D.getContext() == Declarator::MemberContext); | 
 | 3777 |  | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3778 |       if (ParseUnqualifiedId(D.getCXXScopeSpec(),  | 
 | 3779 |                              /*EnteringContext=*/true,  | 
 | 3780 |                              /*AllowDestructorName=*/true,  | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3781 |                              AllowConstructorName, | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 3782 |                              ParsedType(), | 
| Jeffrey Yasskin | 9ab1454 | 2010-04-08 16:38:48 +0000 | [diff] [blame] | 3783 |                              D.getName()) || | 
 | 3784 |           // Once we're past the identifier, if the scope was bad, mark the | 
 | 3785 |           // whole declarator bad. | 
 | 3786 |           D.getCXXScopeSpec().isInvalid()) { | 
| Argyrios Kyrtzidis | 314fe78 | 2008-11-26 22:40:03 +0000 | [diff] [blame] | 3787 |         D.SetIdentifier(0, Tok.getLocation()); | 
 | 3788 |         D.setInvalidType(true); | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3789 |       } else { | 
 | 3790 |         // Parsed the unqualified-id; update range information and move along. | 
 | 3791 |         if (D.getSourceRange().getBegin().isInvalid()) | 
 | 3792 |           D.SetRangeBegin(D.getName().getSourceRange().getBegin()); | 
 | 3793 |         D.SetRangeEnd(D.getName().getSourceRange().getEnd()); | 
| Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 3794 |       } | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3795 |       goto PastIdentifier; | 
| Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 3796 |     } | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3797 |   } else if (Tok.is(tok::identifier) && D.mayHaveIdentifier()) { | 
| Argyrios Kyrtzidis | 314fe78 | 2008-11-26 22:40:03 +0000 | [diff] [blame] | 3798 |     assert(!getLang().CPlusPlus && | 
 | 3799 |            "There's a C++-specific check for tok::identifier above"); | 
 | 3800 |     assert(Tok.getIdentifierInfo() && "Not an identifier?"); | 
 | 3801 |     D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); | 
 | 3802 |     ConsumeToken(); | 
| Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 3803 |     goto PastIdentifier; | 
 | 3804 |   } | 
 | 3805 |      | 
 | 3806 |   if (Tok.is(tok::l_paren)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3807 |     // direct-declarator: '(' declarator ')' | 
 | 3808 |     // direct-declarator: '(' attributes declarator ')' | 
 | 3809 |     // Example: 'char (*X)'   or 'int (*XX)(void)' | 
 | 3810 |     ParseParenDeclarator(D); | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3811 |  | 
 | 3812 |     // If the declarator was parenthesized, we entered the declarator | 
 | 3813 |     // scope when parsing the parenthesized declarator, then exited | 
 | 3814 |     // the scope already. Re-enter the scope, if we need to. | 
 | 3815 |     if (D.getCXXScopeSpec().isSet()) { | 
| Fariborz Jahanian | 46877cd | 2010-08-17 23:50:37 +0000 | [diff] [blame] | 3816 |       // If there was an error parsing parenthesized declarator, declarator | 
 | 3817 |       // scope may have been enterred before. Don't do it again. | 
 | 3818 |       if (!D.isInvalidType() && | 
 | 3819 |           Actions.ShouldEnterDeclaratorScope(getCurScope(), D.getCXXScopeSpec())) | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3820 |         // Change the declaration context for name lookup, until this function | 
 | 3821 |         // is exited (and the declarator has been parsed). | 
| Fariborz Jahanian | 46877cd | 2010-08-17 23:50:37 +0000 | [diff] [blame] | 3822 |         DeclScopeObj.EnterDeclaratorScope(); | 
| Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 3823 |     } | 
| Argyrios Kyrtzidis | 314fe78 | 2008-11-26 22:40:03 +0000 | [diff] [blame] | 3824 |   } else if (D.mayOmitIdentifier()) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3825 |     // This could be something simple like "int" (in which case the declarator | 
 | 3826 |     // portion is empty), if an abstract-declarator is allowed. | 
 | 3827 |     D.SetIdentifier(0, Tok.getLocation()); | 
 | 3828 |   } else { | 
| Douglas Gregor | e950d4b | 2009-03-06 23:28:18 +0000 | [diff] [blame] | 3829 |     if (D.getContext() == Declarator::MemberContext) | 
 | 3830 |       Diag(Tok, diag::err_expected_member_name_or_semi) | 
 | 3831 |         << D.getDeclSpec().getSourceRange(); | 
 | 3832 |     else if (getLang().CPlusPlus) | 
| Douglas Gregor | 2d1c214 | 2009-11-03 19:44:04 +0000 | [diff] [blame] | 3833 |       Diag(Tok, diag::err_expected_unqualified_id) << getLang().CPlusPlus; | 
| Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 3834 |     else | 
| Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 3835 |       Diag(Tok, diag::err_expected_ident_lparen); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3836 |     D.SetIdentifier(0, Tok.getLocation()); | 
| Chris Lattner | 1f6f54b | 2008-11-11 06:13:16 +0000 | [diff] [blame] | 3837 |     D.setInvalidType(true); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3838 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3839 |  | 
| Argyrios Kyrtzidis | 314fe78 | 2008-11-26 22:40:03 +0000 | [diff] [blame] | 3840 |  PastIdentifier: | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3841 |   assert(D.isPastIdentifier() && | 
 | 3842 |          "Haven't past the location of the identifier yet?"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3843 |  | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3844 |   // Don't parse attributes unless we have an identifier. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3845 |   if (D.getIdentifier()) | 
 | 3846 |     MaybeParseCXX0XAttributes(D); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 3847 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3848 |   while (1) { | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 3849 |     if (Tok.is(tok::l_paren)) { | 
| Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 3850 |       // The paren may be part of a C++ direct initializer, eg. "int x(1);". | 
 | 3851 |       // In such a case, check if we actually have a function declarator; if it | 
 | 3852 |       // is not, the declarator has been fully parsed. | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3853 |       if (getLang().CPlusPlus && D.mayBeFollowedByCXXDirectInit()) { | 
 | 3854 |         // When not in file scope, warn for ambiguous function declarators, just | 
 | 3855 |         // in case the author intended it as a variable definition. | 
 | 3856 |         bool warnIfAmbiguous = D.getContext() != Declarator::FileContext; | 
 | 3857 |         if (!isCXXFunctionDeclarator(warnIfAmbiguous)) | 
 | 3858 |           break; | 
 | 3859 |       } | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3860 |       ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3861 |       ParseFunctionDeclarator(ConsumeParen(), D, attrs); | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 3862 |     } else if (Tok.is(tok::l_square)) { | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3863 |       ParseBracketDeclarator(D); | 
 | 3864 |     } else { | 
 | 3865 |       break; | 
 | 3866 |     } | 
 | 3867 |   } | 
 | 3868 | } | 
 | 3869 |  | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3870 | /// ParseParenDeclarator - We parsed the declarator D up to a paren.  This is | 
 | 3871 | /// only called before the identifier, so these are most likely just grouping | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3872 | /// parens for precedence.  If we find that these are actually function | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3873 | /// parameter parens in an abstract-declarator, we call ParseFunctionDeclarator. | 
 | 3874 | /// | 
 | 3875 | ///       direct-declarator: | 
 | 3876 | ///         '(' declarator ')' | 
 | 3877 | /// [GNU]   '(' attributes declarator ')' | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3878 | ///         direct-declarator '(' parameter-type-list ')' | 
 | 3879 | ///         direct-declarator '(' identifier-list[opt] ')' | 
 | 3880 | /// [GNU]   direct-declarator '(' parameter-forward-declarations | 
 | 3881 | ///                    parameter-type-list[opt] ')' | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3882 | /// | 
 | 3883 | void Parser::ParseParenDeclarator(Declarator &D) { | 
 | 3884 |   SourceLocation StartLoc = ConsumeParen(); | 
 | 3885 |   assert(!D.isPastIdentifier() && "Should be called before passing identifier"); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3886 |  | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3887 |   // Eat any attributes before we look at whether this is a grouping or function | 
 | 3888 |   // declarator paren.  If this is a grouping paren, the attribute applies to | 
 | 3889 |   // the type being built up, for example: | 
 | 3890 |   //     int (__attribute__(()) *x)(long y) | 
 | 3891 |   // If this ends up not being a grouping paren, the attribute applies to the | 
 | 3892 |   // first argument, for example: | 
 | 3893 |   //     int (__attribute__(()) int x) | 
 | 3894 |   // In either case, we need to eat any attributes to be able to determine what | 
 | 3895 |   // sort of paren this is. | 
 | 3896 |   // | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3897 |   ParsedAttributes attrs(AttrFactory); | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3898 |   bool RequiresArg = false; | 
 | 3899 |   if (Tok.is(tok::kw___attribute)) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3900 |     ParseGNUAttributes(attrs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3901 |  | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3902 |     // We require that the argument list (if this is a non-grouping paren) be | 
 | 3903 |     // present even if the attribute list was empty. | 
 | 3904 |     RequiresArg = true; | 
 | 3905 |   } | 
| Steve Naroff | 239f073 | 2008-12-25 14:16:32 +0000 | [diff] [blame] | 3906 |   // Eat any Microsoft extensions. | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3907 |   if  (Tok.is(tok::kw___cdecl) || Tok.is(tok::kw___stdcall) || | 
| Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 3908 |        Tok.is(tok::kw___thiscall) || Tok.is(tok::kw___fastcall) || | 
| Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 3909 |        Tok.is(tok::kw___w64) || Tok.is(tok::kw___ptr64) || | 
| Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 3910 |        Tok.is(tok::kw___ptr32) || Tok.is(tok::kw___unaligned)) { | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3911 |     ParseMicrosoftTypeAttributes(attrs); | 
| Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 3912 |   } | 
| Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 3913 |   // Eat any Borland extensions. | 
| Ted Kremenek | 8113ecf | 2010-11-10 05:59:39 +0000 | [diff] [blame] | 3914 |   if  (Tok.is(tok::kw___pascal)) | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3915 |     ParseBorlandTypeAttributes(attrs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3916 |  | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3917 |   // If we haven't past the identifier yet (or where the identifier would be | 
 | 3918 |   // stored, if this is an abstract declarator), then this is probably just | 
 | 3919 |   // grouping parens. However, if this could be an abstract-declarator, then | 
 | 3920 |   // this could also be the start of function arguments (consider 'void()'). | 
 | 3921 |   bool isGrouping; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3922 |  | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3923 |   if (!D.mayOmitIdentifier()) { | 
 | 3924 |     // If this can't be an abstract-declarator, this *must* be a grouping | 
 | 3925 |     // paren, because we haven't seen the identifier yet. | 
 | 3926 |     isGrouping = true; | 
 | 3927 |   } else if (Tok.is(tok::r_paren) ||           // 'int()' is a function. | 
| Argyrios Kyrtzidis | e25d270 | 2008-10-06 00:07:55 +0000 | [diff] [blame] | 3928 |              (getLang().CPlusPlus && Tok.is(tok::ellipsis)) || // C++ int(...) | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3929 |              isDeclarationSpecifier()) {       // 'int(int)' is a function. | 
 | 3930 |     // This handles C99 6.7.5.3p11: in "typedef int X; void foo(X)", X is | 
 | 3931 |     // considered to be a type, not a K&R identifier-list. | 
 | 3932 |     isGrouping = false; | 
 | 3933 |   } else { | 
 | 3934 |     // Otherwise, this is a grouping paren, e.g. 'int (*X)' or 'int(X)'. | 
 | 3935 |     isGrouping = true; | 
 | 3936 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3937 |  | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3938 |   // If this is a grouping paren, handle: | 
 | 3939 |   // direct-declarator: '(' declarator ')' | 
 | 3940 |   // direct-declarator: '(' attributes declarator ')' | 
 | 3941 |   if (isGrouping) { | 
| Argyrios Kyrtzidis | 3f2a8a0 | 2008-10-07 10:21:57 +0000 | [diff] [blame] | 3942 |     bool hadGroupingParens = D.hasGroupingParens(); | 
| Argyrios Kyrtzidis | 73a0d88 | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 3943 |     D.setGroupingParens(true); | 
 | 3944 |  | 
| Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3945 |     ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator); | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3946 |     // Match the ')'. | 
| Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3947 |     SourceLocation EndLoc = MatchRHSPunctuation(tok::r_paren, StartLoc); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 3948 |     D.AddTypeInfo(DeclaratorChunk::getParen(StartLoc, EndLoc), | 
 | 3949 |                   attrs, EndLoc); | 
| Argyrios Kyrtzidis | 3f2a8a0 | 2008-10-07 10:21:57 +0000 | [diff] [blame] | 3950 |  | 
 | 3951 |     D.setGroupingParens(hadGroupingParens); | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3952 |     return; | 
 | 3953 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3954 |  | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3955 |   // Okay, if this wasn't a grouping paren, it must be the start of a function | 
 | 3956 |   // argument list.  Recognize that this declarator will never have an | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3957 |   // identifier (and remember where it would have been), then call into | 
 | 3958 |   // ParseFunctionDeclarator to handle of argument list. | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3959 |   D.SetIdentifier(0, Tok.getLocation()); | 
 | 3960 |  | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 3961 |   ParseFunctionDeclarator(StartLoc, D, attrs, RequiresArg); | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 3962 | } | 
 | 3963 |  | 
 | 3964 | /// ParseFunctionDeclarator - We are after the identifier and have parsed the | 
 | 3965 | /// declarator D up to a paren, which indicates that we are parsing function | 
 | 3966 | /// arguments. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 3967 | /// | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 3968 | /// If attrs is non-null, then the caller parsed those arguments immediately | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 3969 | /// after the open paren - they should be considered to be the first argument of | 
 | 3970 | /// a parameter.  If RequiresArg is true, then the first argument of the | 
 | 3971 | /// function is required to be present and required to not be an identifier | 
 | 3972 | /// list. | 
 | 3973 | /// | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 3974 | /// For C++, after the parameter-list, it also parses cv-qualifier-seq[opt], | 
 | 3975 | /// (C++0x) ref-qualifier[opt], exception-specification[opt], and | 
 | 3976 | /// (C++0x) trailing-return-type[opt]. | 
 | 3977 | /// | 
 | 3978 | /// [C++0x] exception-specification: | 
 | 3979 | ///           dynamic-exception-specification | 
 | 3980 | ///           noexcept-specification | 
 | 3981 | /// | 
 | 3982 | void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, | 
 | 3983 |                                      ParsedAttributes &attrs, | 
 | 3984 |                                      bool RequiresArg) { | 
 | 3985 |   // lparen is already consumed! | 
 | 3986 |   assert(D.isPastIdentifier() && "Should not call before identifier!"); | 
 | 3987 |  | 
 | 3988 |   // This should be true when the function has typed arguments. | 
 | 3989 |   // Otherwise, it is treated as a K&R-style function. | 
 | 3990 |   bool HasProto = false; | 
 | 3991 |   // Build up an array of information about the parsed arguments. | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3992 |   SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 3993 |   // Remember where we see an ellipsis, if any. | 
 | 3994 |   SourceLocation EllipsisLoc; | 
 | 3995 |  | 
 | 3996 |   DeclSpec DS(AttrFactory); | 
 | 3997 |   bool RefQualifierIsLValueRef = true; | 
 | 3998 |   SourceLocation RefQualifierLoc; | 
 | 3999 |   ExceptionSpecificationType ESpecType = EST_None; | 
 | 4000 |   SourceRange ESpecRange; | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4001 |   SmallVector<ParsedType, 2> DynamicExceptions; | 
 | 4002 |   SmallVector<SourceRange, 2> DynamicExceptionRanges; | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4003 |   ExprResult NoexceptExpr; | 
 | 4004 |   ParsedType TrailingReturnType; | 
 | 4005 |    | 
 | 4006 |   SourceLocation EndLoc; | 
 | 4007 |  | 
 | 4008 |   if (isFunctionDeclaratorIdentifierList()) { | 
 | 4009 |     if (RequiresArg) | 
 | 4010 |       Diag(Tok, diag::err_argument_required_after_attribute); | 
 | 4011 |  | 
 | 4012 |     ParseFunctionDeclaratorIdentifierList(D, ParamInfo); | 
 | 4013 |  | 
 | 4014 |     EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); | 
 | 4015 |   } else { | 
 | 4016 |     // Enter function-declaration scope, limiting any declarators to the | 
 | 4017 |     // function prototype scope, including parameter declarators. | 
 | 4018 |     ParseScope PrototypeScope(this, | 
 | 4019 |                               Scope::FunctionPrototypeScope|Scope::DeclScope); | 
 | 4020 |  | 
 | 4021 |     if (Tok.isNot(tok::r_paren)) | 
 | 4022 |       ParseParameterDeclarationClause(D, attrs, ParamInfo, EllipsisLoc); | 
 | 4023 |     else if (RequiresArg) | 
 | 4024 |       Diag(Tok, diag::err_argument_required_after_attribute); | 
 | 4025 |  | 
 | 4026 |     HasProto = ParamInfo.size() || getLang().CPlusPlus; | 
 | 4027 |  | 
 | 4028 |     // If we have the closing ')', eat it. | 
 | 4029 |     EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); | 
 | 4030 |  | 
 | 4031 |     if (getLang().CPlusPlus) { | 
 | 4032 |       MaybeParseCXX0XAttributes(attrs); | 
 | 4033 |  | 
 | 4034 |       // Parse cv-qualifier-seq[opt]. | 
 | 4035 |       ParseTypeQualifierListOpt(DS, false /*no attributes*/); | 
 | 4036 |         if (!DS.getSourceRange().getEnd().isInvalid()) | 
 | 4037 |           EndLoc = DS.getSourceRange().getEnd(); | 
 | 4038 |  | 
 | 4039 |       // Parse ref-qualifier[opt]. | 
 | 4040 |       if (Tok.is(tok::amp) || Tok.is(tok::ampamp)) { | 
 | 4041 |         if (!getLang().CPlusPlus0x) | 
 | 4042 |           Diag(Tok, diag::ext_ref_qualifier); | 
 | 4043 |          | 
 | 4044 |         RefQualifierIsLValueRef = Tok.is(tok::amp); | 
 | 4045 |         RefQualifierLoc = ConsumeToken(); | 
 | 4046 |         EndLoc = RefQualifierLoc; | 
 | 4047 |       } | 
 | 4048 |  | 
 | 4049 |       // Parse exception-specification[opt]. | 
 | 4050 |       ESpecType = MaybeParseExceptionSpecification(ESpecRange, | 
 | 4051 |                                                    DynamicExceptions, | 
 | 4052 |                                                    DynamicExceptionRanges, | 
 | 4053 |                                                    NoexceptExpr); | 
 | 4054 |       if (ESpecType != EST_None) | 
 | 4055 |         EndLoc = ESpecRange.getEnd(); | 
 | 4056 |  | 
 | 4057 |       // Parse trailing-return-type[opt]. | 
 | 4058 |       if (getLang().CPlusPlus0x && Tok.is(tok::arrow)) { | 
| Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 4059 |         SourceRange Range; | 
 | 4060 |         TrailingReturnType = ParseTrailingReturnType(Range).get(); | 
 | 4061 |         if (Range.getEnd().isValid()) | 
 | 4062 |           EndLoc = Range.getEnd(); | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4063 |       } | 
 | 4064 |     } | 
 | 4065 |  | 
 | 4066 |     // Leave prototype scope. | 
 | 4067 |     PrototypeScope.Exit(); | 
 | 4068 |   } | 
 | 4069 |  | 
 | 4070 |   // Remember that we parsed a function type, and remember the attributes. | 
 | 4071 |   D.AddTypeInfo(DeclaratorChunk::getFunction(HasProto, | 
 | 4072 |                                              /*isVariadic=*/EllipsisLoc.isValid(), | 
 | 4073 |                                              EllipsisLoc, | 
 | 4074 |                                              ParamInfo.data(), ParamInfo.size(), | 
 | 4075 |                                              DS.getTypeQualifiers(), | 
 | 4076 |                                              RefQualifierIsLValueRef, | 
 | 4077 |                                              RefQualifierLoc, | 
| Douglas Gregor | 90ebed0 | 2011-07-13 21:47:47 +0000 | [diff] [blame] | 4078 |                                              /*MutableLoc=*/SourceLocation(), | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4079 |                                              ESpecType, ESpecRange.getBegin(), | 
 | 4080 |                                              DynamicExceptions.data(), | 
 | 4081 |                                              DynamicExceptionRanges.data(), | 
 | 4082 |                                              DynamicExceptions.size(), | 
 | 4083 |                                              NoexceptExpr.isUsable() ? | 
 | 4084 |                                                NoexceptExpr.get() : 0, | 
 | 4085 |                                              LParenLoc, EndLoc, D, | 
 | 4086 |                                              TrailingReturnType), | 
 | 4087 |                 attrs, EndLoc); | 
 | 4088 | } | 
 | 4089 |  | 
 | 4090 | /// isFunctionDeclaratorIdentifierList - This parameter list may have an | 
 | 4091 | /// identifier list form for a K&R-style function:  void foo(a,b,c) | 
 | 4092 | /// | 
 | 4093 | /// Note that identifier-lists are only allowed for normal declarators, not for | 
 | 4094 | /// abstract-declarators. | 
 | 4095 | bool Parser::isFunctionDeclaratorIdentifierList() { | 
 | 4096 |   return !getLang().CPlusPlus | 
 | 4097 |          && Tok.is(tok::identifier) | 
 | 4098 |          && !TryAltiVecVectorToken() | 
 | 4099 |          // K&R identifier lists can't have typedefs as identifiers, per C99 | 
 | 4100 |          // 6.7.5.3p11. | 
 | 4101 |          && (TryAnnotateTypeOrScopeToken() || !Tok.is(tok::annot_typename)) | 
 | 4102 |          // Identifier lists follow a really simple grammar: the identifiers can | 
 | 4103 |          // be followed *only* by a ", identifier" or ")".  However, K&R | 
 | 4104 |          // identifier lists are really rare in the brave new modern world, and | 
 | 4105 |          // it is very common for someone to typo a type in a non-K&R style | 
 | 4106 |          // list.  If we are presented with something like: "void foo(intptr x, | 
 | 4107 |          // float y)", we don't want to start parsing the function declarator as | 
 | 4108 |          // though it is a K&R style declarator just because intptr is an | 
 | 4109 |          // invalid type. | 
 | 4110 |          // | 
 | 4111 |          // To handle this, we check to see if the token after the first | 
 | 4112 |          // identifier is a "," or ")".  Only then do we parse it as an | 
 | 4113 |          // identifier list. | 
 | 4114 |          && (NextToken().is(tok::comma) || NextToken().is(tok::r_paren)); | 
 | 4115 | } | 
 | 4116 |  | 
 | 4117 | /// ParseFunctionDeclaratorIdentifierList - While parsing a function declarator | 
 | 4118 | /// we found a K&R-style identifier list instead of a typed parameter list. | 
 | 4119 | /// | 
 | 4120 | /// After returning, ParamInfo will hold the parsed parameters. | 
 | 4121 | /// | 
 | 4122 | ///       identifier-list: [C99 6.7.5] | 
 | 4123 | ///         identifier | 
 | 4124 | ///         identifier-list ',' identifier | 
 | 4125 | /// | 
 | 4126 | void Parser::ParseFunctionDeclaratorIdentifierList( | 
 | 4127 |        Declarator &D, | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4128 |        SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo) { | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4129 |   // If there was no identifier specified for the declarator, either we are in | 
 | 4130 |   // an abstract-declarator, or we are in a parameter declarator which was found | 
 | 4131 |   // to be abstract.  In abstract-declarators, identifier lists are not valid: | 
 | 4132 |   // diagnose this. | 
 | 4133 |   if (!D.getIdentifier()) | 
 | 4134 |     Diag(Tok, diag::ext_ident_list_in_param); | 
 | 4135 |  | 
 | 4136 |   // Maintain an efficient lookup of params we have seen so far. | 
 | 4137 |   llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar; | 
 | 4138 |  | 
 | 4139 |   while (1) { | 
 | 4140 |     // If this isn't an identifier, report the error and skip until ')'. | 
 | 4141 |     if (Tok.isNot(tok::identifier)) { | 
 | 4142 |       Diag(Tok, diag::err_expected_ident); | 
 | 4143 |       SkipUntil(tok::r_paren, /*StopAtSemi=*/true, /*DontConsume=*/true); | 
 | 4144 |       // Forget we parsed anything. | 
 | 4145 |       ParamInfo.clear(); | 
 | 4146 |       return; | 
 | 4147 |     } | 
 | 4148 |  | 
 | 4149 |     IdentifierInfo *ParmII = Tok.getIdentifierInfo(); | 
 | 4150 |  | 
 | 4151 |     // Reject 'typedef int y; int test(x, y)', but continue parsing. | 
 | 4152 |     if (Actions.getTypeName(*ParmII, Tok.getLocation(), getCurScope())) | 
 | 4153 |       Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII; | 
 | 4154 |  | 
 | 4155 |     // Verify that the argument identifier has not already been mentioned. | 
 | 4156 |     if (!ParamsSoFar.insert(ParmII)) { | 
 | 4157 |       Diag(Tok, diag::err_param_redefinition) << ParmII; | 
 | 4158 |     } else { | 
 | 4159 |       // Remember this identifier in ParamInfo. | 
 | 4160 |       ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, | 
 | 4161 |                                                      Tok.getLocation(), | 
 | 4162 |                                                      0)); | 
 | 4163 |     } | 
 | 4164 |  | 
 | 4165 |     // Eat the identifier. | 
 | 4166 |     ConsumeToken(); | 
 | 4167 |  | 
 | 4168 |     // The list continues if we see a comma. | 
 | 4169 |     if (Tok.isNot(tok::comma)) | 
 | 4170 |       break; | 
 | 4171 |     ConsumeToken(); | 
 | 4172 |   } | 
 | 4173 | } | 
 | 4174 |  | 
 | 4175 | /// ParseParameterDeclarationClause - Parse a (possibly empty) parameter-list | 
 | 4176 | /// after the opening parenthesis. This function will not parse a K&R-style | 
 | 4177 | /// identifier list. | 
 | 4178 | /// | 
 | 4179 | /// D is the declarator being parsed.  If attrs is non-null, then the caller | 
 | 4180 | /// parsed those arguments immediately after the open paren - they should be | 
 | 4181 | /// considered to be the first argument of a parameter. | 
 | 4182 | /// | 
 | 4183 | /// After returning, ParamInfo will hold the parsed parameters. EllipsisLoc will | 
 | 4184 | /// be the location of the ellipsis, if any was parsed. | 
 | 4185 | /// | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4186 | ///       parameter-type-list: [C99 6.7.5] | 
 | 4187 | ///         parameter-list | 
 | 4188 | ///         parameter-list ',' '...' | 
| Douglas Gregor | ed5d651 | 2009-09-22 21:41:40 +0000 | [diff] [blame] | 4189 | /// [C++]   parameter-list '...' | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4190 | /// | 
 | 4191 | ///       parameter-list: [C99 6.7.5] | 
 | 4192 | ///         parameter-declaration | 
 | 4193 | ///         parameter-list ',' parameter-declaration | 
 | 4194 | /// | 
 | 4195 | ///       parameter-declaration: [C99 6.7.5] | 
 | 4196 | ///         declaration-specifiers declarator | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 4197 | /// [C++]   declaration-specifiers declarator '=' assignment-expression | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4198 | /// [GNU]   declaration-specifiers declarator attributes | 
| Sebastian Redl | 50de12f | 2009-03-24 22:27:57 +0000 | [diff] [blame] | 4199 | ///         declaration-specifiers abstract-declarator[opt] | 
 | 4200 | /// [C++]   declaration-specifiers abstract-declarator[opt] | 
| Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 4201 | ///           '=' assignment-expression | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4202 | /// [GNU]   declaration-specifiers abstract-declarator[opt] attributes | 
 | 4203 | /// | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4204 | void Parser::ParseParameterDeclarationClause( | 
 | 4205 |        Declarator &D, | 
 | 4206 |        ParsedAttributes &attrs, | 
| Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4207 |        SmallVector<DeclaratorChunk::ParamInfo, 16> &ParamInfo, | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4208 |        SourceLocation &EllipsisLoc) { | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4209 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4210 |   while (1) { | 
 | 4211 |     if (Tok.is(tok::ellipsis)) { | 
| Douglas Gregor | 965acbb | 2009-02-18 07:07:28 +0000 | [diff] [blame] | 4212 |       EllipsisLoc = ConsumeToken();     // Consume the ellipsis. | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4213 |       break; | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4214 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4215 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4216 |     // Parse the declaration-specifiers. | 
| John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 4217 |     // Just use the ParsingDeclaration "scope" of the declarator. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4218 |     DeclSpec DS(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4219 | 	 | 
 | 4220 |     // Skip any Microsoft attributes before a param. | 
| Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 4221 |     if (getLang().MicrosoftExt && Tok.is(tok::l_square)) | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4222 |       ParseMicrosoftAttributes(DS.getAttributes()); | 
 | 4223 |  | 
 | 4224 |     SourceLocation DSStart = Tok.getLocation(); | 
| Chris Lattner | 7399ee0 | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 4225 |  | 
 | 4226 |     // If the caller parsed attributes for the first argument, add them now. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4227 |     // Take them so that we only apply the attributes to the first parameter. | 
| Douglas Gregor | 3fd1ba0 | 2011-07-05 16:44:18 +0000 | [diff] [blame] | 4228 |     // FIXME: If we saw an ellipsis first, this code is not reached. Are the | 
 | 4229 |     // attributes lost? Should they even be allowed? | 
 | 4230 |     // FIXME: If we can leave the attributes in the token stream somehow, we can | 
 | 4231 |     // get rid of a parameter (attrs) and this statement. It might be too much | 
 | 4232 |     // hassle. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4233 |     DS.takeAttributesFrom(attrs); | 
 | 4234 |  | 
| Chris Lattner | e64c549 | 2009-02-27 18:38:20 +0000 | [diff] [blame] | 4235 |     ParseDeclarationSpecifiers(DS); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4236 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4237 |     // Parse the declarator.  This is "PrototypeContext", because we must | 
 | 4238 |     // accept either 'declarator' or 'abstract-declarator' here. | 
 | 4239 |     Declarator ParmDecl(DS, Declarator::PrototypeContext); | 
 | 4240 |     ParseDeclarator(ParmDecl); | 
 | 4241 |  | 
 | 4242 |     // Parse GNU attributes, if present. | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4243 |     MaybeParseGNUAttributes(ParmDecl); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4244 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4245 |     // Remember this parsed parameter in ParamInfo. | 
 | 4246 |     IdentifierInfo *ParmII = ParmDecl.getIdentifier(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4247 |  | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4248 |     // DefArgToks is used when the parsing of default arguments needs | 
 | 4249 |     // to be delayed. | 
 | 4250 |     CachedTokens *DefArgToks = 0; | 
 | 4251 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4252 |     // If no parameter was specified, verify that *something* was specified, | 
 | 4253 |     // otherwise we have a missing type and identifier. | 
| Chris Lattner | e64c549 | 2009-02-27 18:38:20 +0000 | [diff] [blame] | 4254 |     if (DS.isEmpty() && ParmDecl.getIdentifier() == 0 && | 
 | 4255 |         ParmDecl.getNumTypeObjects() == 0) { | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4256 |       // Completely missing, emit error. | 
 | 4257 |       Diag(DSStart, diag::err_missing_param); | 
 | 4258 |     } else { | 
 | 4259 |       // Otherwise, we have something.  Add it and let semantic analysis try | 
 | 4260 |       // to grok it and add the result to the ParamInfo we are building. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4261 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4262 |       // Inform the actions module about the parameter declarator, so it gets | 
 | 4263 |       // added to the current scope. | 
| John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4264 |       Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 4265 |  | 
 | 4266 |       // Parse the default argument, if any. We parse the default | 
 | 4267 |       // arguments in all dialects; the semantic analysis in | 
 | 4268 |       // ActOnParamDefaultArgument will reject the default argument in | 
 | 4269 |       // C. | 
 | 4270 |       if (Tok.is(tok::equal)) { | 
| Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 4271 |         SourceLocation EqualLoc = Tok.getLocation(); | 
 | 4272 |  | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 4273 |         // Parse the default argument | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4274 |         if (D.getContext() == Declarator::MemberContext) { | 
 | 4275 |           // If we're inside a class definition, cache the tokens | 
 | 4276 |           // corresponding to the default argument. We'll actually parse | 
 | 4277 |           // them when we see the end of the class definition. | 
 | 4278 |           // FIXME: Templates will require something similar. | 
 | 4279 |           // FIXME: Can we use a smart pointer for Toks? | 
 | 4280 |           DefArgToks = new CachedTokens; | 
 | 4281 |  | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4282 |           if (!ConsumeAndStoreUntil(tok::comma, tok::r_paren, *DefArgToks, | 
| Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 4283 |                                     /*StopAtSemi=*/true, | 
 | 4284 |                                     /*ConsumeFinalToken=*/false)) { | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4285 |             delete DefArgToks; | 
 | 4286 |             DefArgToks = 0; | 
| Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 4287 |             Actions.ActOnParamDefaultArgumentError(Param); | 
| Argyrios Kyrtzidis | 2b602ad | 2010-08-06 09:47:24 +0000 | [diff] [blame] | 4288 |           } else { | 
 | 4289 |             // Mark the end of the default argument so that we know when to | 
 | 4290 |             // stop when we parse it later on. | 
 | 4291 |             Token DefArgEnd; | 
 | 4292 |             DefArgEnd.startToken(); | 
 | 4293 |             DefArgEnd.setKind(tok::cxx_defaultarg_end); | 
 | 4294 |             DefArgEnd.setLocation(Tok.getLocation()); | 
 | 4295 |             DefArgToks->push_back(DefArgEnd); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 |             Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc, | 
| Anders Carlsson | 5e300d1 | 2009-06-12 16:51:40 +0000 | [diff] [blame] | 4297 |                                                 (*DefArgToks)[1].getLocation()); | 
| Argyrios Kyrtzidis | 2b602ad | 2010-08-06 09:47:24 +0000 | [diff] [blame] | 4298 |           } | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 4299 |         } else { | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4300 |           // Consume the '='. | 
| Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 4301 |           ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4302 |  | 
| Douglas Gregor | be0f7bd | 2010-09-11 20:24:53 +0000 | [diff] [blame] | 4303 |           // The argument isn't actually potentially evaluated unless it is  | 
 | 4304 |           // used. | 
 | 4305 |           EnterExpressionEvaluationContext Eval(Actions, | 
 | 4306 |                                               Sema::PotentiallyEvaluatedIfUsed); | 
 | 4307 |  | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4308 |           ExprResult DefArgResult(ParseAssignmentExpression()); | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4309 |           if (DefArgResult.isInvalid()) { | 
 | 4310 |             Actions.ActOnParamDefaultArgumentError(Param); | 
 | 4311 |             SkipUntil(tok::comma, tok::r_paren, true, true); | 
 | 4312 |           } else { | 
 | 4313 |             // Inform the actions module about the default argument | 
 | 4314 |             Actions.ActOnParamDefaultArgument(Param, EqualLoc, | 
| John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 4315 |                                               DefArgResult.take()); | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4316 |           } | 
| Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 4317 |         } | 
 | 4318 |       } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4319 |  | 
 | 4320 |       ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, | 
 | 4321 |                                           ParmDecl.getIdentifierLoc(), Param, | 
| Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 4322 |                                           DefArgToks)); | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4323 |     } | 
 | 4324 |  | 
 | 4325 |     // If the next token is a comma, consume it and keep reading arguments. | 
| Douglas Gregor | ed5d651 | 2009-09-22 21:41:40 +0000 | [diff] [blame] | 4326 |     if (Tok.isNot(tok::comma)) { | 
 | 4327 |       if (Tok.is(tok::ellipsis)) { | 
| Douglas Gregor | ed5d651 | 2009-09-22 21:41:40 +0000 | [diff] [blame] | 4328 |         EllipsisLoc = ConsumeToken();     // Consume the ellipsis. | 
 | 4329 |          | 
 | 4330 |         if (!getLang().CPlusPlus) { | 
 | 4331 |           // We have ellipsis without a preceding ',', which is ill-formed | 
 | 4332 |           // in C. Complain and provide the fix. | 
 | 4333 |           Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis) | 
| Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 4334 |             << FixItHint::CreateInsertion(EllipsisLoc, ", "); | 
| Douglas Gregor | ed5d651 | 2009-09-22 21:41:40 +0000 | [diff] [blame] | 4335 |         } | 
 | 4336 |       } | 
 | 4337 |        | 
 | 4338 |       break; | 
 | 4339 |     } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4340 |  | 
| Chris Lattner | f97409f | 2008-04-06 06:57:35 +0000 | [diff] [blame] | 4341 |     // Consume the comma. | 
 | 4342 |     ConsumeToken(); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4343 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4344 |  | 
| Chris Lattner | 66d2865 | 2008-04-06 06:34:08 +0000 | [diff] [blame] | 4345 | } | 
| Chris Lattner | ef4715c | 2008-04-06 05:45:57 +0000 | [diff] [blame] | 4346 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4347 | /// [C90]   direct-declarator '[' constant-expression[opt] ']' | 
 | 4348 | /// [C99]   direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']' | 
 | 4349 | /// [C99]   direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']' | 
 | 4350 | /// [C99]   direct-declarator '[' type-qual-list 'static' assignment-expr ']' | 
 | 4351 | /// [C99]   direct-declarator '[' type-qual-list[opt] '*' ']' | 
 | 4352 | void Parser::ParseBracketDeclarator(Declarator &D) { | 
 | 4353 |   SourceLocation StartLoc = ConsumeBracket(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4354 |  | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4355 |   // C array syntax has many features, but by-far the most common is [] and [4]. | 
 | 4356 |   // This code does a fast path to handle some of the most obvious cases. | 
 | 4357 |   if (Tok.getKind() == tok::r_square) { | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 4358 |     SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4359 |     ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4360 |     MaybeParseCXX0XAttributes(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 4361 |      | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4362 |     // Remember that we parsed the empty array type. | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4363 |     ExprResult NumElements; | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4364 |     D.AddTypeInfo(DeclaratorChunk::getArray(0, false, false, 0, | 
| Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4365 |                                             StartLoc, EndLoc), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4366 |                   attrs, EndLoc); | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4367 |     return; | 
 | 4368 |   } else if (Tok.getKind() == tok::numeric_constant && | 
 | 4369 |              GetLookAheadToken(1).is(tok::r_square)) { | 
 | 4370 |     // [4] is very common.  Parse the numeric constant expression. | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4371 |     ExprResult ExprRes(Actions.ActOnNumericConstant(Tok)); | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4372 |     ConsumeToken(); | 
 | 4373 |  | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 4374 |     SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc); | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4375 |     ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4376 |     MaybeParseCXX0XAttributes(attrs); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4377 |  | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4378 |     // Remember that we parsed a array type, and remember its features. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4379 |     D.AddTypeInfo(DeclaratorChunk::getArray(0, false, 0, | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4380 |                                             ExprRes.release(), | 
| Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4381 |                                             StartLoc, EndLoc), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4382 |                   attrs, EndLoc); | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4383 |     return; | 
 | 4384 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4385 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4386 |   // If valid, this location is the position where we read the 'static' keyword. | 
 | 4387 |   SourceLocation StaticLoc; | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 4388 |   if (Tok.is(tok::kw_static)) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4389 |     StaticLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4390 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4391 |   // If there is a type-qualifier-list, read it now. | 
| Chris Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 4392 |   // Type qualifiers in an array subscript are a C99 feature. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4393 |   DeclSpec DS(AttrFactory); | 
| Chris Lattner | 5a69d1c | 2008-12-18 07:02:59 +0000 | [diff] [blame] | 4394 |   ParseTypeQualifierListOpt(DS, false /*no attributes*/); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4395 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4396 |   // If we haven't already read 'static', check to see if there is one after the | 
 | 4397 |   // type-qualifier-list. | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 4398 |   if (!StaticLoc.isValid() && Tok.is(tok::kw_static)) | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4399 |     StaticLoc = ConsumeToken(); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4400 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4401 |   // Handle "direct-declarator [ type-qual-list[opt] * ]". | 
 | 4402 |   bool isStar = false; | 
| John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 4403 |   ExprResult NumElements; | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4404 |  | 
| Chris Lattner | 5dcc6ce | 2008-04-06 05:26:30 +0000 | [diff] [blame] | 4405 |   // Handle the case where we have '[*]' as the array size.  However, a leading | 
 | 4406 |   // star could be the start of an expression, for example 'X[*p + 4]'.  Verify | 
 | 4407 |   // the the token after the star is a ']'.  Since stars in arrays are | 
 | 4408 |   // infrequent, use of lookahead is not costly here. | 
 | 4409 |   if (Tok.is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) { | 
| Chris Lattner | a711dd0 | 2008-04-06 05:27:21 +0000 | [diff] [blame] | 4410 |     ConsumeToken();  // Eat the '*'. | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4411 |  | 
| Chris Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 4412 |     if (StaticLoc.isValid()) { | 
| Chris Lattner | 5dcc6ce | 2008-04-06 05:26:30 +0000 | [diff] [blame] | 4413 |       Diag(StaticLoc, diag::err_unspecified_vla_size_with_static); | 
| Chris Lattner | a1fcbad | 2008-12-18 06:50:14 +0000 | [diff] [blame] | 4414 |       StaticLoc = SourceLocation();  // Drop the static. | 
 | 4415 |     } | 
| Chris Lattner | 5dcc6ce | 2008-04-06 05:26:30 +0000 | [diff] [blame] | 4416 |     isStar = true; | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 4417 |   } else if (Tok.isNot(tok::r_square)) { | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4418 |     // Note, in C89, this production uses the constant-expr production instead | 
 | 4419 |     // of assignment-expr.  The only difference is that assignment-expr allows | 
 | 4420 |     // things like '=' and '*='.  Sema rejects these in C89 mode because they | 
 | 4421 |     // are not i-c-e's, so we don't need to distinguish between the two here. | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4422 |  | 
| Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 4423 |     // Parse the constant-expression or assignment-expression now (depending | 
 | 4424 |     // on dialect). | 
 | 4425 |     if (getLang().CPlusPlus) | 
 | 4426 |       NumElements = ParseConstantExpression(); | 
 | 4427 |     else | 
 | 4428 |       NumElements = ParseAssignmentExpression(); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4429 |   } | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4430 |  | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4431 |   // If there was an error parsing the assignment-expression, recover. | 
| Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 4432 |   if (NumElements.isInvalid()) { | 
| Chris Lattner | 5cb10d3 | 2009-04-24 22:30:50 +0000 | [diff] [blame] | 4433 |     D.setInvalidType(true); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4434 |     // If the expression was invalid, skip it. | 
 | 4435 |     SkipUntil(tok::r_square); | 
 | 4436 |     return; | 
 | 4437 |   } | 
| Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 4438 |  | 
 | 4439 |   SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc); | 
 | 4440 |  | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4441 |   ParsedAttributes attrs(AttrFactory); | 
| John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 4442 |   MaybeParseCXX0XAttributes(attrs); | 
| Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 4443 |  | 
| Chris Lattner | 378c7e4 | 2008-12-18 07:27:21 +0000 | [diff] [blame] | 4444 |   // Remember that we parsed a array type, and remember its features. | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4445 |   D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(), | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4446 |                                           StaticLoc.isValid(), isStar, | 
| Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 4447 |                                           NumElements.release(), | 
 | 4448 |                                           StartLoc, EndLoc), | 
| John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 4449 |                 attrs, EndLoc); | 
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4450 | } | 
 | 4451 |  | 
| Argyrios Kyrtzidis | 0f07203 | 2008-09-05 11:26:19 +0000 | [diff] [blame] | 4452 | /// [GNU]   typeof-specifier: | 
 | 4453 | ///           typeof ( expressions ) | 
 | 4454 | ///           typeof ( type-name ) | 
 | 4455 | /// [GNU/C++] typeof unary-expression | 
| Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 4456 | /// | 
 | 4457 | void Parser::ParseTypeofSpecifier(DeclSpec &DS) { | 
| Chris Lattner | 04d6666 | 2007-10-09 17:33:22 +0000 | [diff] [blame] | 4458 |   assert(Tok.is(tok::kw_typeof) && "Not a typeof specifier"); | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4459 |   Token OpTok = Tok; | 
| Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 4460 |   SourceLocation StartLoc = ConsumeToken(); | 
 | 4461 |  | 
| John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4462 |   const bool hasParens = Tok.is(tok::l_paren); | 
 | 4463 |  | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4464 |   bool isCastExpr; | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 4465 |   ParsedType CastTy; | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4466 |   SourceRange CastRange; | 
| Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 4467 |   ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, | 
 | 4468 |                                                           CastTy, CastRange); | 
| John McCall | cfb708c | 2010-01-13 20:03:27 +0000 | [diff] [blame] | 4469 |   if (hasParens) | 
 | 4470 |     DS.setTypeofParensRange(CastRange); | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4471 |  | 
 | 4472 |   if (CastRange.getEnd().isInvalid()) | 
| Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 4473 |     // FIXME: Not accurate, the range gets one token more than it should. | 
 | 4474 |     DS.SetRangeEnd(Tok.getLocation()); | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4475 |   else | 
 | 4476 |     DS.SetRangeEnd(CastRange.getEnd()); | 
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4477 |  | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4478 |   if (isCastExpr) { | 
 | 4479 |     if (!CastTy) { | 
 | 4480 |       DS.SetTypeSpecError(); | 
| Argyrios Kyrtzidis | 0f07203 | 2008-09-05 11:26:19 +0000 | [diff] [blame] | 4481 |       return; | 
| Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 4482 |     } | 
| Argyrios Kyrtzidis | 0f07203 | 2008-09-05 11:26:19 +0000 | [diff] [blame] | 4483 |  | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4484 |     const char *PrevSpec = 0; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 4485 |     unsigned DiagID; | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4486 |     // Check for duplicate type specifiers (e.g. "int typeof(int)"). | 
 | 4487 |     if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 4488 |                            DiagID, CastTy)) | 
 | 4489 |       Diag(StartLoc, DiagID) << PrevSpec; | 
| Argyrios Kyrtzidis | 5ab0640 | 2009-05-22 10:22:50 +0000 | [diff] [blame] | 4490 |     return; | 
| Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 4491 |   } | 
| Argyrios Kyrtzidis | 0f07203 | 2008-09-05 11:26:19 +0000 | [diff] [blame] | 4492 |  | 
| Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 4493 |   // If we get here, the operand to the typeof was an expresion. | 
 | 4494 |   if (Operand.isInvalid()) { | 
 | 4495 |     DS.SetTypeSpecError(); | 
| Steve Naroff | 9dfa7b4 | 2007-08-02 02:53:48 +0000 | [diff] [blame] | 4496 |     return; | 
| Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 4497 |   } | 
| Argyrios Kyrtzidis | 0f07203 | 2008-09-05 11:26:19 +0000 | [diff] [blame] | 4498 |  | 
| Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 4499 |   const char *PrevSpec = 0; | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 4500 |   unsigned DiagID; | 
| Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 4501 |   // Check for duplicate type specifiers (e.g. "int typeof(int)"). | 
 | 4502 |   if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, | 
| John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 4503 |                          DiagID, Operand.get())) | 
| John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 4504 |     Diag(StartLoc, DiagID) << PrevSpec; | 
| Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 4505 | } | 
| Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 4506 |  | 
 | 4507 |  | 
 | 4508 | /// TryAltiVecVectorTokenOutOfLine - Out of line body that should only be called | 
 | 4509 | /// from TryAltiVecVectorToken. | 
 | 4510 | bool Parser::TryAltiVecVectorTokenOutOfLine() { | 
 | 4511 |   Token Next = NextToken(); | 
 | 4512 |   switch (Next.getKind()) { | 
 | 4513 |   default: return false; | 
 | 4514 |   case tok::kw_short: | 
 | 4515 |   case tok::kw_long: | 
 | 4516 |   case tok::kw_signed: | 
 | 4517 |   case tok::kw_unsigned: | 
 | 4518 |   case tok::kw_void: | 
 | 4519 |   case tok::kw_char: | 
 | 4520 |   case tok::kw_int: | 
 | 4521 |   case tok::kw_float: | 
 | 4522 |   case tok::kw_double: | 
 | 4523 |   case tok::kw_bool: | 
 | 4524 |   case tok::kw___pixel: | 
 | 4525 |     Tok.setKind(tok::kw___vector); | 
 | 4526 |     return true; | 
 | 4527 |   case tok::identifier: | 
 | 4528 |     if (Next.getIdentifierInfo() == Ident_pixel) { | 
 | 4529 |       Tok.setKind(tok::kw___vector); | 
 | 4530 |       return true; | 
 | 4531 |     } | 
 | 4532 |     return false; | 
 | 4533 |   } | 
 | 4534 | } | 
 | 4535 |  | 
 | 4536 | bool Parser::TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, | 
 | 4537 |                                       const char *&PrevSpec, unsigned &DiagID, | 
 | 4538 |                                       bool &isInvalid) { | 
 | 4539 |   if (Tok.getIdentifierInfo() == Ident_vector) { | 
 | 4540 |     Token Next = NextToken(); | 
 | 4541 |     switch (Next.getKind()) { | 
 | 4542 |     case tok::kw_short: | 
 | 4543 |     case tok::kw_long: | 
 | 4544 |     case tok::kw_signed: | 
 | 4545 |     case tok::kw_unsigned: | 
 | 4546 |     case tok::kw_void: | 
 | 4547 |     case tok::kw_char: | 
 | 4548 |     case tok::kw_int: | 
 | 4549 |     case tok::kw_float: | 
 | 4550 |     case tok::kw_double: | 
 | 4551 |     case tok::kw_bool: | 
 | 4552 |     case tok::kw___pixel: | 
 | 4553 |       isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID); | 
 | 4554 |       return true; | 
 | 4555 |     case tok::identifier: | 
 | 4556 |       if (Next.getIdentifierInfo() == Ident_pixel) { | 
 | 4557 |         isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID); | 
 | 4558 |         return true; | 
 | 4559 |       } | 
 | 4560 |       break; | 
 | 4561 |     default: | 
 | 4562 |       break; | 
 | 4563 |     } | 
| Douglas Gregor | a8f031f | 2010-06-16 15:28:57 +0000 | [diff] [blame] | 4564 |   } else if ((Tok.getIdentifierInfo() == Ident_pixel) && | 
| Chris Lattner | 1b49242 | 2010-02-28 18:33:55 +0000 | [diff] [blame] | 4565 |              DS.isTypeAltiVecVector()) { | 
 | 4566 |     isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID); | 
 | 4567 |     return true; | 
 | 4568 |   } | 
 | 4569 |   return false; | 
 | 4570 | } |