Chris Lattner | 7ad0fbe | 2006-11-05 07:46:30 +0000 | [diff] [blame] | 1 | //===--- ParseDecl.cpp - Declaration Parsing ------------------------------===// |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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 | 288e86ff1 | 2006-11-11 23:03:42 +0000 | [diff] [blame] | 15 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | using namespace clang; |
| 18 | |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | // C99 6.7: Declarations. |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 23 | /// ParseTypeName |
| 24 | /// type-name: [C99 6.7.6] |
| 25 | /// specifier-qualifier-list abstract-declarator[opt] |
Chris Lattner | e550a4e | 2006-08-24 06:37:51 +0000 | [diff] [blame] | 26 | Parser::TypeTy *Parser::ParseTypeName() { |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 27 | // Parse the common declaration-specifiers piece. |
| 28 | DeclSpec DS; |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 29 | ParseSpecifierQualifierList(DS); |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 30 | |
| 31 | // Parse the abstract-declarator, if present. |
| 32 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
| 33 | ParseDeclarator(DeclaratorInfo); |
Chris Lattner | e550a4e | 2006-08-24 06:37:51 +0000 | [diff] [blame] | 34 | |
Chris Lattner | 558cb29 | 2006-11-19 01:31:06 +0000 | [diff] [blame] | 35 | return Actions.ParseTypeName(CurScope, DeclaratorInfo).Val; |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Chris Lattner | b8cd5c2 | 2006-08-15 04:10:46 +0000 | [diff] [blame] | 38 | /// ParseAttributes - Parse a non-empty attributes list. |
| 39 | /// |
| 40 | /// [GNU] attributes: |
| 41 | /// attribute |
| 42 | /// attributes attribute |
| 43 | /// |
| 44 | /// [GNU] attribute: |
| 45 | /// '__attribute__' '(' '(' attribute-list ')' ')' |
| 46 | /// |
| 47 | /// [GNU] attribute-list: |
| 48 | /// attrib |
| 49 | /// attribute_list ',' attrib |
| 50 | /// |
| 51 | /// [GNU] attrib: |
| 52 | /// empty |
| 53 | /// any-word |
| 54 | /// any-word '(' identifier ')' |
| 55 | /// any-word '(' identifier ',' nonempty-expr-list ')' |
| 56 | /// any-word '(' expr-list ')' |
| 57 | /// |
| 58 | void Parser::ParseAttributes() { |
| 59 | assert(Tok.getKind() == tok::kw___attribute && "Not an attribute list!"); |
| 60 | ConsumeToken(); |
| 61 | |
| 62 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
| 63 | "attribute")) |
| 64 | return; |
| 65 | |
| 66 | // TODO: Parse the attributes. |
| 67 | SkipUntil(tok::r_paren, false); |
| 68 | } |
| 69 | |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 71 | /// ParseDeclaration - Parse a full 'declaration', which consists of |
| 72 | /// declaration-specifiers, some number of declarators, and a semicolon. |
| 73 | /// 'Context' should be a Declarator::TheContext value. |
Chris Lattner | 302b4be | 2006-11-19 02:31:38 +0000 | [diff] [blame] | 74 | Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) { |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 75 | // Parse the common declaration-specifiers piece. |
| 76 | DeclSpec DS; |
| 77 | ParseDeclarationSpecifiers(DS); |
| 78 | |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 79 | // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };" |
| 80 | // declaration-specifiers init-declarator-list[opt] ';' |
| 81 | if (Tok.getKind() == tok::semi) { |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 82 | ConsumeToken(); |
Chris Lattner | 200bdc3 | 2006-11-19 02:43:37 +0000 | [diff] [blame] | 83 | return Actions.ParsedFreeStandingDeclSpec(CurScope, DS); |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 86 | Declarator DeclaratorInfo(DS, (Declarator::TheContext)Context); |
| 87 | ParseDeclarator(DeclaratorInfo); |
| 88 | |
Chris Lattner | 302b4be | 2006-11-19 02:31:38 +0000 | [diff] [blame] | 89 | return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo); |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Chris Lattner | f0f3baa | 2006-08-14 00:15:20 +0000 | [diff] [blame] | 92 | /// ParseInitDeclaratorListAfterFirstDeclarator - Parse 'declaration' after |
| 93 | /// parsing 'declaration-specifiers declarator'. This method is split out this |
| 94 | /// way to handle the ambiguity between top-level function-definitions and |
| 95 | /// declarations. |
| 96 | /// |
| 97 | /// declaration: [C99 6.7] |
| 98 | /// declaration-specifiers init-declarator-list[opt] ';' [TODO] |
| 99 | /// [!C99] init-declarator-list ';' [TODO] |
| 100 | /// [OMP] threadprivate-directive [TODO] |
| 101 | /// |
| 102 | /// init-declarator-list: [C99 6.7] |
| 103 | /// init-declarator |
| 104 | /// init-declarator-list ',' init-declarator |
| 105 | /// init-declarator: [C99 6.7] |
| 106 | /// declarator |
| 107 | /// declarator '=' initializer |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 108 | /// [GNU] declarator simple-asm-expr[opt] attributes[opt] |
| 109 | /// [GNU] declarator simple-asm-expr[opt] attributes[opt] '=' initializer |
Chris Lattner | f0f3baa | 2006-08-14 00:15:20 +0000 | [diff] [blame] | 110 | /// |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 111 | Parser::DeclTy *Parser:: |
| 112 | ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) { |
| 113 | |
| 114 | // Declarators may be grouped together ("int X, *Y, Z();"). Provide info so |
| 115 | // that they can be chained properly if the actions want this. |
| 116 | Parser::DeclTy *LastDeclInGroup = 0; |
| 117 | |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 118 | // At this point, we know that it is not a function definition. Parse the |
| 119 | // rest of the init-declarator-list. |
| 120 | while (1) { |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 121 | // If a simple-asm-expr is present, parse it. |
| 122 | if (Tok.getKind() == tok::kw_asm) |
| 123 | ParseSimpleAsm(); |
| 124 | |
Chris Lattner | b8cd5c2 | 2006-08-15 04:10:46 +0000 | [diff] [blame] | 125 | // If attributes are present, parse them. |
| 126 | if (Tok.getKind() == tok::kw___attribute) |
| 127 | ParseAttributes(); |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 128 | |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 129 | // Parse declarator '=' initializer. |
Chris Lattner | f0f3baa | 2006-08-14 00:15:20 +0000 | [diff] [blame] | 130 | ExprResult Init; |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 131 | if (Tok.getKind() == tok::equal) { |
| 132 | ConsumeToken(); |
Chris Lattner | f0f3baa | 2006-08-14 00:15:20 +0000 | [diff] [blame] | 133 | Init = ParseInitializer(); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 134 | if (Init.isInvalid) { |
Chris Lattner | f0f3baa | 2006-08-14 00:15:20 +0000 | [diff] [blame] | 135 | SkipUntil(tok::semi); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 136 | return 0; |
Chris Lattner | f0f3baa | 2006-08-14 00:15:20 +0000 | [diff] [blame] | 137 | } |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 140 | // Inform the current actions module that we just parsed this declarator. |
Chris Lattner | 289ab7b | 2006-11-08 06:54:53 +0000 | [diff] [blame] | 141 | // FIXME: pass asm & attributes. |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 142 | LastDeclInGroup = Actions.ParseDeclarator(CurScope, D, Init.Val, |
| 143 | LastDeclInGroup); |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 144 | |
| 145 | // If we don't have a comma, it is either the end of the list (a ';') or an |
| 146 | // error, bail out. |
| 147 | if (Tok.getKind() != tok::comma) |
| 148 | break; |
| 149 | |
| 150 | // Consume the comma. |
| 151 | ConsumeToken(); |
| 152 | |
| 153 | // Parse the next declarator. |
| 154 | D.clear(); |
| 155 | ParseDeclarator(D); |
| 156 | } |
| 157 | |
| 158 | if (Tok.getKind() == tok::semi) { |
| 159 | ConsumeToken(); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 160 | return LastDeclInGroup; |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 161 | } else { |
| 162 | Diag(Tok, diag::err_parse_error); |
| 163 | // Skip to end of block or statement |
| 164 | SkipUntil(tok::r_brace, true); |
| 165 | if (Tok.getKind() == tok::semi) |
| 166 | ConsumeToken(); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 167 | return 0; |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 171 | /// ParseSpecifierQualifierList |
| 172 | /// specifier-qualifier-list: |
| 173 | /// type-specifier specifier-qualifier-list[opt] |
| 174 | /// type-qualifier specifier-qualifier-list[opt] |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 175 | /// [GNU] attributes specifier-qualifier-list[opt] |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 176 | /// |
| 177 | void Parser::ParseSpecifierQualifierList(DeclSpec &DS) { |
| 178 | /// specifier-qualifier-list is a subset of declaration-specifiers. Just |
| 179 | /// parse declaration-specifiers and complain about extra stuff. |
| 180 | SourceLocation Loc = Tok.getLocation(); |
| 181 | ParseDeclarationSpecifiers(DS); |
| 182 | |
| 183 | // Validate declspec for type-name. |
| 184 | unsigned Specs = DS.getParsedSpecifiers(); |
| 185 | if (Specs == DeclSpec::PQ_None) |
| 186 | Diag(Tok, diag::err_typename_requires_specqual); |
| 187 | |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 188 | // Issue diagnostic and remove storage class if present. |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 189 | if (Specs & DeclSpec::PQ_StorageClassSpecifier) { |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 190 | if (DS.getStorageClassSpecLoc().isValid()) |
| 191 | Diag(DS.getStorageClassSpecLoc(),diag::err_typename_invalid_storageclass); |
| 192 | else |
| 193 | Diag(DS.getThreadSpecLoc(), diag::err_typename_invalid_storageclass); |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 194 | DS.ClearStorageClassSpecs(); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 195 | } |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 196 | |
| 197 | // Issue diagnostic and remove function specfier if present. |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 198 | if (Specs & DeclSpec::PQ_FunctionSpecifier) { |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 199 | Diag(DS.getInlineSpecLoc(), diag::err_typename_invalid_functionspec); |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 200 | DS.ClearFunctionSpecs(); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 201 | } |
| 202 | } |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 203 | |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 204 | /// ParseDeclarationSpecifiers |
| 205 | /// declaration-specifiers: [C99 6.7] |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 206 | /// storage-class-specifier declaration-specifiers[opt] |
| 207 | /// type-specifier declaration-specifiers[opt] |
| 208 | /// type-qualifier declaration-specifiers[opt] |
| 209 | /// [C99] function-specifier declaration-specifiers[opt] |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 210 | /// [GNU] attributes declaration-specifiers[opt] |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 211 | /// |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 212 | /// storage-class-specifier: [C99 6.7.1] |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 213 | /// 'typedef' |
| 214 | /// 'extern' |
| 215 | /// 'static' |
| 216 | /// 'auto' |
| 217 | /// 'register' |
| 218 | /// [GNU] '__thread' |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 219 | /// type-specifier: [C99 6.7.2] |
| 220 | /// 'void' |
| 221 | /// 'char' |
| 222 | /// 'short' |
| 223 | /// 'int' |
| 224 | /// 'long' |
| 225 | /// 'float' |
| 226 | /// 'double' |
| 227 | /// 'signed' |
| 228 | /// 'unsigned' |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 229 | /// struct-or-union-specifier |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 230 | /// enum-specifier |
Chris Lattner | 3b4fdda3 | 2006-08-14 00:45:39 +0000 | [diff] [blame] | 231 | /// typedef-name |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 232 | /// [C99] '_Bool' |
| 233 | /// [C99] '_Complex' |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 234 | /// [C99] '_Imaginary' // Removed in TC2? |
| 235 | /// [GNU] '_Decimal32' |
| 236 | /// [GNU] '_Decimal64' |
| 237 | /// [GNU] '_Decimal128' |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 238 | /// [GNU] typeof-specifier [TODO] |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 239 | /// [OBJC] class-name objc-protocol-refs[opt] [TODO] |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 240 | /// [OBJC] typedef-name objc-protocol-refs [TODO] |
| 241 | /// [OBJC] objc-protocol-refs [TODO] |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 242 | /// type-qualifier: |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 243 | /// 'const' |
| 244 | /// 'volatile' |
| 245 | /// [C99] 'restrict' |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 246 | /// function-specifier: [C99 6.7.4] |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 247 | /// [C99] 'inline' |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 248 | /// |
| 249 | void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 250 | while (1) { |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 251 | int isInvalid = false; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 252 | const char *PrevSpec = 0; |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 253 | SourceLocation Loc = Tok.getLocation(); |
| 254 | |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 255 | switch (Tok.getKind()) { |
Chris Lattner | 3b4fdda3 | 2006-08-14 00:45:39 +0000 | [diff] [blame] | 256 | // typedef-name |
| 257 | case tok::identifier: |
| 258 | // This identifier can only be a typedef name if we haven't already seen |
Chris Lattner | 5646b3e | 2006-08-15 05:12:01 +0000 | [diff] [blame] | 259 | // a type-specifier. Without this check we misparse: |
| 260 | // typedef int X; struct Y { short X; }; as 'short int'. |
Chris Lattner | f055d43 | 2006-11-28 04:28:12 +0000 | [diff] [blame] | 261 | if (!DS.hasTypeSpecifier()) { |
Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 262 | // It has to be available as a typedef too! |
| 263 | if (void *TypeRep = Actions.isTypeName(*Tok.getIdentifierInfo(), |
| 264 | CurScope)) { |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 265 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typedef, Loc, PrevSpec, |
Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 266 | TypeRep); |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 267 | break; |
Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 268 | } |
Chris Lattner | 3b4fdda3 | 2006-08-14 00:45:39 +0000 | [diff] [blame] | 269 | } |
| 270 | // FALL THROUGH. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 271 | default: |
| 272 | // If this is not a declaration specifier token, we're done reading decl |
| 273 | // specifiers. First verify that DeclSpec's are consistent. |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 274 | DS.Finish(Diags, getLang()); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 275 | return; |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 276 | |
| 277 | // GNU attributes support. |
| 278 | case tok::kw___attribute: |
| 279 | ParseAttributes(); |
Chris Lattner | b95cca0 | 2006-10-17 03:01:08 +0000 | [diff] [blame] | 280 | continue; |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 281 | |
| 282 | // storage-class-specifier |
| 283 | case tok::kw_typedef: |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 284 | isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 285 | break; |
| 286 | case tok::kw_extern: |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 287 | if (DS.isThreadSpecified()) |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 288 | Diag(Tok, diag::ext_thread_before, "extern"); |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 289 | isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 290 | break; |
| 291 | case tok::kw_static: |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 292 | if (DS.isThreadSpecified()) |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 293 | Diag(Tok, diag::ext_thread_before, "static"); |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 294 | isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 295 | break; |
| 296 | case tok::kw_auto: |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 297 | isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 298 | break; |
| 299 | case tok::kw_register: |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 300 | isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 301 | break; |
| 302 | case tok::kw___thread: |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 303 | isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec)*2; |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 304 | break; |
| 305 | |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 306 | // type-specifiers |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 307 | case tok::kw_short: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 308 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 309 | break; |
| 310 | case tok::kw_long: |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 311 | if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 312 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec); |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 313 | else |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 314 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 315 | break; |
| 316 | case tok::kw_signed: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 317 | isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 318 | break; |
| 319 | case tok::kw_unsigned: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 320 | isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 321 | break; |
| 322 | case tok::kw__Complex: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 323 | isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 324 | break; |
| 325 | case tok::kw__Imaginary: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 326 | isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 327 | break; |
| 328 | case tok::kw_void: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 329 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 330 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 331 | case tok::kw_char: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 332 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 333 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 334 | case tok::kw_int: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 335 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 336 | break; |
| 337 | case tok::kw_float: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 338 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 339 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 340 | case tok::kw_double: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 341 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 342 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 343 | case tok::kw__Bool: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 344 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 345 | break; |
| 346 | case tok::kw__Decimal32: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 347 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 348 | break; |
| 349 | case tok::kw__Decimal64: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 350 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 351 | break; |
| 352 | case tok::kw__Decimal128: |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 353 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec); |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 354 | break; |
| 355 | |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 356 | case tok::kw_struct: |
| 357 | case tok::kw_union: |
| 358 | ParseStructUnionSpecifier(DS); |
| 359 | continue; |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 360 | case tok::kw_enum: |
| 361 | ParseEnumSpecifier(DS); |
| 362 | continue; |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 363 | |
| 364 | // type-qualifier |
| 365 | case tok::kw_const: |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 366 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, |
| 367 | getLang())*2; |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 368 | break; |
| 369 | case tok::kw_volatile: |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 370 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, |
| 371 | getLang())*2; |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 372 | break; |
| 373 | case tok::kw_restrict: |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 374 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, |
| 375 | getLang())*2; |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 376 | break; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 377 | |
| 378 | // function-specifier |
| 379 | case tok::kw_inline: |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 380 | isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 381 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 382 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 383 | // If the specifier combination wasn't legal, issue a diagnostic. |
| 384 | if (isInvalid) { |
| 385 | assert(PrevSpec && "Method did not return previous specifier!"); |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 386 | if (isInvalid == 1) // Error. |
| 387 | Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec); |
| 388 | else // extwarn. |
| 389 | Diag(Tok, diag::ext_duplicate_declspec, PrevSpec); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 390 | } |
| 391 | ConsumeToken(); |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 395 | |
| 396 | /// ParseStructUnionSpecifier |
| 397 | /// struct-or-union-specifier: [C99 6.7.2.1] |
Chris Lattner | 476c3ad | 2006-08-13 22:09:58 +0000 | [diff] [blame] | 398 | /// struct-or-union identifier[opt] '{' struct-contents '}' |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 399 | /// struct-or-union identifier |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 400 | /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents |
| 401 | /// '}' attributes[opt] |
| 402 | /// [GNU] struct-or-union attributes[opt] identifier |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 403 | /// struct-or-union: |
| 404 | /// 'struct' |
| 405 | /// 'union' |
Chris Lattner | 476c3ad | 2006-08-13 22:09:58 +0000 | [diff] [blame] | 406 | /// struct-contents: |
| 407 | /// struct-declaration-list |
| 408 | /// [EXT] empty |
| 409 | /// [GNU] "struct-declaration-list" without terminatoring ';' [TODO] |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 410 | /// struct-declaration-list: |
Chris Lattner | 476c3ad | 2006-08-13 22:09:58 +0000 | [diff] [blame] | 411 | /// struct-declaration |
| 412 | /// struct-declaration-list struct-declaration |
| 413 | /// [OBC] '@' 'defs' '(' class-name ')' [TODO] |
| 414 | /// struct-declaration: |
| 415 | /// specifier-qualifier-list struct-declarator-list ';' |
| 416 | /// [GNU] __extension__ struct-declaration [TODO] |
| 417 | /// [GNU] specifier-qualifier-list ';' [TODO] |
| 418 | /// struct-declarator-list: |
| 419 | /// struct-declarator |
| 420 | /// struct-declarator-list ',' struct-declarator |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 421 | /// [GNU] struct-declarator-list ',' attributes[opt] struct-declarator |
Chris Lattner | 476c3ad | 2006-08-13 22:09:58 +0000 | [diff] [blame] | 422 | /// struct-declarator: |
| 423 | /// declarator |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 424 | /// [GNU] declarator attributes[opt] |
Chris Lattner | 476c3ad | 2006-08-13 22:09:58 +0000 | [diff] [blame] | 425 | /// declarator[opt] ':' constant-expression |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 426 | /// [GNU] declarator[opt] ':' constant-expression attributes[opt] |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 427 | /// |
| 428 | void Parser::ParseStructUnionSpecifier(DeclSpec &DS) { |
| 429 | assert((Tok.getKind() == tok::kw_struct || |
| 430 | Tok.getKind() == tok::kw_union) && "Not a struct/union specifier"); |
| 431 | bool isUnion = Tok.getKind() == tok::kw_union; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 432 | SourceLocation StartLoc = ConsumeToken(); |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 433 | |
| 434 | // If attributes exist after tag, parse them. |
| 435 | if (Tok.getKind() == tok::kw___attribute) |
| 436 | ParseAttributes(); |
| 437 | |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 438 | // Must have either 'struct name' or 'struct {...}'. |
| 439 | if (Tok.getKind() != tok::identifier && |
| 440 | Tok.getKind() != tok::l_brace) { |
| 441 | Diag(Tok, diag::err_expected_ident_lbrace); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | if (Tok.getKind() == tok::identifier) |
| 446 | ConsumeToken(); |
| 447 | |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 448 | if (Tok.getKind() == tok::l_brace) { |
Chris Lattner | 0413237 | 2006-10-16 06:12:55 +0000 | [diff] [blame] | 449 | SourceLocation LBraceLoc = ConsumeBrace(); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 450 | |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 451 | if (Tok.getKind() == tok::r_brace) |
| 452 | Diag(Tok, diag::ext_empty_struct_union_enum, isUnion ? "union":"struct"); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 453 | |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 454 | while (Tok.getKind() != tok::r_brace && |
| 455 | Tok.getKind() != tok::eof) { |
| 456 | // Each iteration of this loop reads one struct-declaration. |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 457 | |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 458 | // Parse the common specifier-qualifiers-list piece. |
| 459 | DeclSpec DS; |
| 460 | SourceLocation SpecQualLoc = Tok.getLocation(); |
| 461 | ParseSpecifierQualifierList(DS); |
| 462 | // TODO: Does specifier-qualifier list correctly check that *something* is |
| 463 | // specified? |
| 464 | |
| 465 | Declarator DeclaratorInfo(DS, Declarator::MemberContext); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 466 | |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 467 | // If there are no declarators, issue a warning. |
| 468 | if (Tok.getKind() == tok::semi) { |
| 469 | Diag(SpecQualLoc, diag::w_no_declarators); |
| 470 | } else { |
| 471 | // Read struct-declarators until we find the semicolon. |
| 472 | while (1) { |
| 473 | /// struct-declarator: declarator |
| 474 | /// struct-declarator: declarator[opt] ':' constant-expression |
| 475 | if (Tok.getKind() != tok::colon) |
| 476 | ParseDeclarator(DeclaratorInfo); |
| 477 | |
| 478 | if (Tok.getKind() == tok::colon) { |
| 479 | ConsumeToken(); |
| 480 | ExprResult Res = ParseConstantExpression(); |
| 481 | if (Res.isInvalid) { |
| 482 | SkipUntil(tok::semi, true, true); |
| 483 | } else { |
| 484 | // Process it. |
| 485 | } |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 486 | } |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 487 | |
| 488 | // If attributes exist after the declarator, parse them. |
| 489 | if (Tok.getKind() == tok::kw___attribute) |
| 490 | ParseAttributes(); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 491 | |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 492 | // TODO: install declarator. |
| 493 | |
| 494 | // If we don't have a comma, it is either the end of the list (a ';') |
| 495 | // or an error, bail out. |
| 496 | if (Tok.getKind() != tok::comma) |
| 497 | break; |
| 498 | |
| 499 | // Consume the comma. |
| 500 | ConsumeToken(); |
| 501 | |
| 502 | // Parse the next declarator. |
| 503 | DeclaratorInfo.clear(); |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 504 | |
| 505 | // Attributes are only allowed on the second declarator. |
| 506 | if (Tok.getKind() == tok::kw___attribute) |
| 507 | ParseAttributes(); |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
| 511 | if (Tok.getKind() == tok::semi) { |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 512 | ConsumeToken(); |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 513 | } else { |
| 514 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 515 | // Skip to end of block or statement |
| 516 | SkipUntil(tok::r_brace, true, true); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 519 | |
Chris Lattner | 04f8019 | 2006-08-15 04:55:54 +0000 | [diff] [blame] | 520 | MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 521 | |
| 522 | // If attributes exist after struct contents, parse them. |
| 523 | if (Tok.getKind() == tok::kw___attribute) |
| 524 | ParseAttributes(); |
Chris Lattner | b8bbad7 | 2006-08-13 22:21:02 +0000 | [diff] [blame] | 525 | } |
Chris Lattner | da72c82 | 2006-08-13 22:16:42 +0000 | [diff] [blame] | 526 | |
| 527 | const char *PrevSpec = 0; |
| 528 | if (DS.SetTypeSpecType(isUnion ? DeclSpec::TST_union : DeclSpec::TST_struct, |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 529 | StartLoc, PrevSpec)) |
| 530 | Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 534 | /// ParseEnumSpecifier |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 535 | /// enum-specifier: [C99 6.7.2.2] |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 536 | /// 'enum' identifier[opt] '{' enumerator-list '}' |
| 537 | /// [C99] 'enum' identifier[opt] '{' enumerator-list ',' '}' |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 538 | /// [GNU] 'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt] |
| 539 | /// '}' attributes[opt] |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 540 | /// 'enum' identifier |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 541 | /// [GNU] 'enum' attributes[opt] identifier |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 542 | /// enumerator-list: |
| 543 | /// enumerator |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 544 | /// enumerator-list ',' enumerator |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 545 | /// enumerator: |
| 546 | /// enumeration-constant |
Chris Lattner | 1890ac8 | 2006-08-13 01:16:23 +0000 | [diff] [blame] | 547 | /// enumeration-constant '=' constant-expression |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 548 | /// enumeration-constant: |
| 549 | /// identifier |
| 550 | /// |
| 551 | void Parser::ParseEnumSpecifier(DeclSpec &DS) { |
| 552 | assert(Tok.getKind() == tok::kw_enum && "Not an enum specifier"); |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 553 | SourceLocation StartLoc = ConsumeToken(); |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 554 | |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 555 | if (Tok.getKind() == tok::kw___attribute) |
| 556 | ParseAttributes(); |
| 557 | |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 558 | // Must have either 'enum name' or 'enum {...}'. |
| 559 | if (Tok.getKind() != tok::identifier && |
| 560 | Tok.getKind() != tok::l_brace) { |
| 561 | Diag(Tok, diag::err_expected_ident_lbrace); |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | if (Tok.getKind() == tok::identifier) |
| 566 | ConsumeToken(); |
| 567 | |
Chris Lattner | 0fb8b36 | 2006-08-14 01:30:12 +0000 | [diff] [blame] | 568 | if (Tok.getKind() == tok::l_brace) { |
Chris Lattner | 0413237 | 2006-10-16 06:12:55 +0000 | [diff] [blame] | 569 | SourceLocation LBraceLoc = ConsumeBrace(); |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 570 | |
Chris Lattner | 0fb8b36 | 2006-08-14 01:30:12 +0000 | [diff] [blame] | 571 | if (Tok.getKind() == tok::r_brace) |
| 572 | Diag(Tok, diag::ext_empty_struct_union_enum, "enum"); |
| 573 | |
| 574 | // Parse the enumerator-list. |
| 575 | while (Tok.getKind() == tok::identifier) { |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 576 | ConsumeToken(); |
Chris Lattner | 0fb8b36 | 2006-08-14 01:30:12 +0000 | [diff] [blame] | 577 | |
| 578 | if (Tok.getKind() == tok::equal) { |
| 579 | ConsumeToken(); |
| 580 | ExprResult Res = ParseConstantExpression(); |
| 581 | if (Res.isInvalid) SkipUntil(tok::comma, true, false); |
| 582 | } |
| 583 | |
| 584 | if (Tok.getKind() != tok::comma) |
| 585 | break; |
Chris Lattner | af63531 | 2006-10-16 06:06:51 +0000 | [diff] [blame] | 586 | SourceLocation CommaLoc = ConsumeToken(); |
Chris Lattner | 0fb8b36 | 2006-08-14 01:30:12 +0000 | [diff] [blame] | 587 | |
| 588 | if (Tok.getKind() != tok::identifier && !getLang().C99) |
| 589 | Diag(CommaLoc, diag::ext_c99_enumerator_list_comma); |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Chris Lattner | 0fb8b36 | 2006-08-14 01:30:12 +0000 | [diff] [blame] | 592 | // Eat the }. |
Chris Lattner | 04f8019 | 2006-08-15 04:55:54 +0000 | [diff] [blame] | 593 | MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 594 | |
| 595 | // If attributes exist after the identifier list, parse them. |
| 596 | if (Tok.getKind() == tok::kw___attribute) |
| 597 | ParseAttributes(); |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 598 | } |
| 599 | // TODO: semantic analysis on the declspec for enums. |
Chris Lattner | da72c82 | 2006-08-13 22:16:42 +0000 | [diff] [blame] | 600 | |
| 601 | |
| 602 | const char *PrevSpec = 0; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 603 | if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec)) |
| 604 | Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec); |
Chris Lattner | 3b561a3 | 2006-08-13 00:12:11 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 608 | /// isTypeSpecifierQualifier - Return true if the current token could be the |
| 609 | /// start of a specifier-qualifier-list. |
| 610 | bool Parser::isTypeSpecifierQualifier() const { |
| 611 | switch (Tok.getKind()) { |
| 612 | default: return false; |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 613 | // GNU attributes support. |
| 614 | case tok::kw___attribute: |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 615 | // type-specifiers |
| 616 | case tok::kw_short: |
| 617 | case tok::kw_long: |
| 618 | case tok::kw_signed: |
| 619 | case tok::kw_unsigned: |
| 620 | case tok::kw__Complex: |
| 621 | case tok::kw__Imaginary: |
| 622 | case tok::kw_void: |
| 623 | case tok::kw_char: |
| 624 | case tok::kw_int: |
| 625 | case tok::kw_float: |
| 626 | case tok::kw_double: |
| 627 | case tok::kw__Bool: |
| 628 | case tok::kw__Decimal32: |
| 629 | case tok::kw__Decimal64: |
| 630 | case tok::kw__Decimal128: |
| 631 | |
| 632 | // struct-or-union-specifier |
| 633 | case tok::kw_struct: |
| 634 | case tok::kw_union: |
| 635 | // enum-specifier |
| 636 | case tok::kw_enum: |
| 637 | |
| 638 | // type-qualifier |
| 639 | case tok::kw_const: |
| 640 | case tok::kw_volatile: |
| 641 | case tok::kw_restrict: |
| 642 | return true; |
| 643 | |
| 644 | // typedef-name |
| 645 | case tok::identifier: |
Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 646 | return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0; |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 647 | |
| 648 | // TODO: Attributes. |
| 649 | } |
| 650 | } |
| 651 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 652 | /// isDeclarationSpecifier() - Return true if the current token is part of a |
| 653 | /// declaration specifier. |
| 654 | bool Parser::isDeclarationSpecifier() const { |
| 655 | switch (Tok.getKind()) { |
| 656 | default: return false; |
| 657 | // storage-class-specifier |
| 658 | case tok::kw_typedef: |
| 659 | case tok::kw_extern: |
| 660 | case tok::kw_static: |
| 661 | case tok::kw_auto: |
| 662 | case tok::kw_register: |
| 663 | case tok::kw___thread: |
| 664 | |
| 665 | // type-specifiers |
| 666 | case tok::kw_short: |
| 667 | case tok::kw_long: |
| 668 | case tok::kw_signed: |
| 669 | case tok::kw_unsigned: |
| 670 | case tok::kw__Complex: |
| 671 | case tok::kw__Imaginary: |
| 672 | case tok::kw_void: |
| 673 | case tok::kw_char: |
| 674 | case tok::kw_int: |
| 675 | case tok::kw_float: |
| 676 | case tok::kw_double: |
| 677 | case tok::kw__Bool: |
| 678 | case tok::kw__Decimal32: |
| 679 | case tok::kw__Decimal64: |
| 680 | case tok::kw__Decimal128: |
| 681 | |
| 682 | // struct-or-union-specifier |
| 683 | case tok::kw_struct: |
| 684 | case tok::kw_union: |
| 685 | // enum-specifier |
| 686 | case tok::kw_enum: |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 687 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 688 | // type-qualifier |
| 689 | case tok::kw_const: |
| 690 | case tok::kw_volatile: |
| 691 | case tok::kw_restrict: |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 692 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 693 | // function-specifier |
| 694 | case tok::kw_inline: |
| 695 | return true; |
Chris Lattner | f5fbd79 | 2006-08-10 23:56:11 +0000 | [diff] [blame] | 696 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 697 | // typedef-name |
| 698 | case tok::identifier: |
Chris Lattner | 2ebe4bb | 2006-11-20 01:29:42 +0000 | [diff] [blame] | 699 | return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 700 | // TODO: Attributes. |
| 701 | } |
| 702 | } |
| 703 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 704 | |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 705 | /// ParseTypeQualifierListOpt |
| 706 | /// type-qualifier-list: [C99 6.7.5] |
| 707 | /// type-qualifier |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 708 | /// [GNU] attributes |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 709 | /// type-qualifier-list type-qualifier |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 710 | /// [GNU] type-qualifier-list attributes |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 711 | /// |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 712 | void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) { |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 713 | while (1) { |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 714 | int isInvalid = false; |
| 715 | const char *PrevSpec = 0; |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 716 | SourceLocation Loc = Tok.getLocation(); |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 717 | |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 718 | switch (Tok.getKind()) { |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 719 | default: |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 720 | // If this is not a type-qualifier token, we're done reading type |
| 721 | // qualifiers. First verify that DeclSpec's are consistent. |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 722 | DS.Finish(Diags, getLang()); |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 723 | return; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 724 | case tok::kw_const: |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 725 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, |
| 726 | getLang())*2; |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 727 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 728 | case tok::kw_volatile: |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 729 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, |
| 730 | getLang())*2; |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 731 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 732 | case tok::kw_restrict: |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 733 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, |
| 734 | getLang())*2; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 735 | break; |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 736 | |
| 737 | case tok::kw___attribute: |
| 738 | ParseAttributes(); |
| 739 | break; |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 740 | } |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 741 | |
| 742 | // If the specifier combination wasn't legal, issue a diagnostic. |
| 743 | if (isInvalid) { |
| 744 | assert(PrevSpec && "Method did not return previous specifier!"); |
| 745 | if (isInvalid == 1) // Error. |
| 746 | Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec); |
| 747 | else // extwarn. |
| 748 | Diag(Tok, diag::ext_duplicate_declspec, PrevSpec); |
| 749 | } |
| 750 | ConsumeToken(); |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 754 | |
| 755 | /// ParseDeclarator - Parse and verify a newly-initialized declarator. |
| 756 | /// |
| 757 | void Parser::ParseDeclarator(Declarator &D) { |
| 758 | /// This implements the 'declarator' production in the C grammar, then checks |
| 759 | /// for well-formedness and issues diagnostics. |
| 760 | ParseDeclaratorInternal(D); |
| 761 | |
Chris Lattner | 9fab3b9 | 2006-08-12 18:25:42 +0000 | [diff] [blame] | 762 | // TODO: validate D. |
Chris Lattner | bf320c8 | 2006-08-07 05:05:30 +0000 | [diff] [blame] | 763 | |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /// ParseDeclaratorInternal |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 767 | /// declarator: [C99 6.7.5] |
| 768 | /// pointer[opt] direct-declarator |
| 769 | /// |
| 770 | /// pointer: [C99 6.7.5] |
| 771 | /// '*' type-qualifier-list[opt] |
| 772 | /// '*' type-qualifier-list[opt] pointer |
| 773 | /// |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 774 | void Parser::ParseDeclaratorInternal(Declarator &D) { |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 775 | if (Tok.getKind() != tok::star) |
| 776 | return ParseDirectDeclarator(D); |
| 777 | |
| 778 | // Otherwise, '*' -> pointer. |
Chris Lattner | af63531 | 2006-10-16 06:06:51 +0000 | [diff] [blame] | 779 | SourceLocation Loc = ConsumeToken(); // Eat the *. |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 780 | DeclSpec DS; |
| 781 | ParseTypeQualifierListOpt(DS); |
| 782 | |
| 783 | // Recursively parse the declarator. |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 784 | ParseDeclaratorInternal(D); |
Chris Lattner | 9dfdb3c | 2006-11-13 07:38:09 +0000 | [diff] [blame] | 785 | |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 786 | // Remember that we parsed a pointer type, and remember the type-quals. |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 787 | D.AddTypeInfo(DeclaratorTypeInfo::getPointer(DS.getTypeQualifiers(), Loc)); |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 790 | |
| 791 | /// ParseDirectDeclarator |
| 792 | /// direct-declarator: [C99 6.7.5] |
| 793 | /// identifier |
| 794 | /// '(' declarator ')' |
| 795 | /// [GNU] '(' attributes declarator ')' |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 796 | /// [C90] direct-declarator '[' constant-expression[opt] ']' |
| 797 | /// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']' |
| 798 | /// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']' |
| 799 | /// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']' |
| 800 | /// [C99] direct-declarator '[' type-qual-list[opt] '*' ']' |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 801 | /// direct-declarator '(' parameter-type-list ')' |
| 802 | /// direct-declarator '(' identifier-list[opt] ')' |
| 803 | /// [GNU] direct-declarator '(' parameter-forward-declarations |
| 804 | /// parameter-type-list[opt] ')' |
| 805 | /// |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 806 | void Parser::ParseDirectDeclarator(Declarator &D) { |
| 807 | // Parse the first direct-declarator seen. |
| 808 | if (Tok.getKind() == tok::identifier && D.mayHaveIdentifier()) { |
| 809 | assert(Tok.getIdentifierInfo() && "Not an identifier?"); |
| 810 | D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 811 | ConsumeToken(); |
| 812 | } else if (Tok.getKind() == tok::l_paren) { |
| 813 | // direct-declarator: '(' declarator ')' |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 814 | // direct-declarator: '(' attributes declarator ')' |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 815 | // Example: 'char (*X)' or 'int (*XX)(void)' |
| 816 | ParseParenDeclarator(D); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 817 | } else if (D.mayOmitIdentifier()) { |
| 818 | // This could be something simple like "int" (in which case the declarator |
| 819 | // portion is empty), if an abstract-declarator is allowed. |
| 820 | D.SetIdentifier(0, Tok.getLocation()); |
| 821 | } else { |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 822 | // Expected identifier or '('. |
| 823 | Diag(Tok, diag::err_expected_ident_lparen); |
| 824 | D.SetIdentifier(0, Tok.getLocation()); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | assert(D.isPastIdentifier() && |
| 828 | "Haven't past the location of the identifier yet?"); |
| 829 | |
| 830 | while (1) { |
| 831 | if (Tok.getKind() == tok::l_paren) { |
| 832 | ParseParenDeclarator(D); |
| 833 | } else if (Tok.getKind() == tok::l_square) { |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 834 | ParseBracketDeclarator(D); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 835 | } else { |
| 836 | break; |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | /// ParseParenDeclarator - We parsed the declarator D up to a paren. This may |
| 842 | /// either be before the identifier (in which case these are just grouping |
| 843 | /// parens for precedence) or it may be after the identifier, in which case |
| 844 | /// these are function arguments. |
| 845 | /// |
| 846 | /// This method also handles this portion of the grammar: |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 847 | /// parameter-type-list: [C99 6.7.5] |
| 848 | /// parameter-list |
| 849 | /// parameter-list ',' '...' |
| 850 | /// |
| 851 | /// parameter-list: [C99 6.7.5] |
| 852 | /// parameter-declaration |
| 853 | /// parameter-list ',' parameter-declaration |
| 854 | /// |
| 855 | /// parameter-declaration: [C99 6.7.5] |
| 856 | /// declaration-specifiers declarator |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 857 | /// [GNU] declaration-specifiers declarator attributes |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 858 | /// declaration-specifiers abstract-declarator[opt] |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 859 | /// [GNU] declaration-specifiers abstract-declarator[opt] attributes |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 860 | /// |
| 861 | /// identifier-list: [C99 6.7.5] |
| 862 | /// identifier |
| 863 | /// identifier-list ',' identifier |
| 864 | /// |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 865 | #include <iostream> |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 866 | void Parser::ParseParenDeclarator(Declarator &D) { |
Chris Lattner | 0413237 | 2006-10-16 06:12:55 +0000 | [diff] [blame] | 867 | SourceLocation StartLoc = ConsumeParen(); |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 868 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 869 | // If we haven't past the identifier yet (or where the identifier would be |
| 870 | // stored, if this is an abstract declarator), then this is probably just |
| 871 | // grouping parens. |
| 872 | if (!D.isPastIdentifier()) { |
| 873 | // Okay, this is probably a grouping paren. However, if this could be an |
| 874 | // abstract-declarator, then this could also be the start of function |
| 875 | // arguments (consider 'void()'). |
| 876 | bool isGrouping; |
| 877 | |
| 878 | if (!D.mayOmitIdentifier()) { |
| 879 | // If this can't be an abstract-declarator, this *must* be a grouping |
| 880 | // paren, because we haven't seen the identifier yet. |
| 881 | isGrouping = true; |
| 882 | } else if (Tok.getKind() == tok::r_paren || // 'int()' is a function. |
| 883 | isDeclarationSpecifier()) { // 'int(int)' is a function. |
Chris Lattner | bb233fe | 2006-11-21 23:13:27 +0000 | [diff] [blame] | 884 | // This handles C99 6.7.5.3p11: in "typedef int X; void foo(X)", X is |
| 885 | // considered to be a type, not a K&R identifier-list. |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 886 | isGrouping = false; |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 887 | } else { |
Chris Lattner | bb233fe | 2006-11-21 23:13:27 +0000 | [diff] [blame] | 888 | // Otherwise, this is a grouping paren, e.g. 'int (*X)' or 'int(X)'. |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 889 | isGrouping = true; |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 890 | } |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 891 | |
| 892 | // If this is a grouping paren, handle: |
| 893 | // direct-declarator: '(' declarator ')' |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 894 | // direct-declarator: '(' attributes declarator ')' |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 895 | if (isGrouping) { |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 896 | if (Tok.getKind() == tok::kw___attribute) |
| 897 | ParseAttributes(); |
| 898 | |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 899 | ParseDeclaratorInternal(D); |
Chris Lattner | 4564bc1 | 2006-08-10 23:14:52 +0000 | [diff] [blame] | 900 | // Match the ')'. |
Chris Lattner | 04f8019 | 2006-08-15 04:55:54 +0000 | [diff] [blame] | 901 | MatchRHSPunctuation(tok::r_paren, StartLoc); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 902 | return; |
| 903 | } |
| 904 | |
| 905 | // Okay, if this wasn't a grouping paren, it must be the start of a function |
Chris Lattner | a350722 | 2006-08-07 00:33:37 +0000 | [diff] [blame] | 906 | // argument list. Recognize that this declarator will never have an |
| 907 | // identifier (and remember where it would have been), then fall through to |
| 908 | // the handling of argument lists. |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 909 | D.SetIdentifier(0, Tok.getLocation()); |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 912 | // Okay, this is the parameter list of a function definition, or it is an |
| 913 | // identifier list of a K&R-style function. |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 914 | bool IsVariadic; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 915 | bool HasPrototype; |
Chris Lattner | 14776b9 | 2006-08-06 22:27:40 +0000 | [diff] [blame] | 916 | bool ErrorEmitted = false; |
| 917 | |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 918 | // Build up an array of information about the parsed arguments. |
| 919 | SmallVector<DeclaratorTypeInfo::ParamInfo, 16> ParamInfo; |
| 920 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 921 | if (Tok.getKind() == tok::r_paren) { |
| 922 | // int() -> no prototype, no '...'. |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 923 | IsVariadic = false; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 924 | HasPrototype = false; |
| 925 | } else if (Tok.getKind() == tok::identifier && |
Chris Lattner | bb233fe | 2006-11-21 23:13:27 +0000 | [diff] [blame] | 926 | // K&R identifier lists can't have typedefs as identifiers, per |
| 927 | // C99 6.7.5.3p11. |
Steve Naroff | b419d3a | 2006-10-27 23:18:49 +0000 | [diff] [blame] | 928 | !Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) { |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 929 | // Identifier list. Note that '(' identifier-list ')' is only allowed for |
| 930 | // normal declarators, not for abstract-declarators. |
| 931 | assert(D.isPastIdentifier() && "Identifier (if present) must be passed!"); |
| 932 | |
| 933 | // If there was no identifier specified, either we are in an |
| 934 | // abstract-declarator, or we are in a parameter declarator which was found |
| 935 | // to be abstract. In abstract-declarators, identifier lists are not valid, |
| 936 | // diagnose this. |
| 937 | if (!D.getIdentifier()) |
| 938 | Diag(Tok, diag::ext_ident_list_in_param); |
| 939 | |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 940 | // FIXME: pass stuff. |
| 941 | ParamInfo.push_back(DeclaratorTypeInfo::ParamInfo()); |
| 942 | |
Chris Lattner | 9fab3b9 | 2006-08-12 18:25:42 +0000 | [diff] [blame] | 943 | // TODO: Remember token. |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 944 | ConsumeToken(); |
| 945 | while (Tok.getKind() == tok::comma) { |
| 946 | // Eat the comma. |
| 947 | ConsumeToken(); |
| 948 | |
Chris Lattner | 0be454e | 2006-08-12 19:30:51 +0000 | [diff] [blame] | 949 | if (ExpectAndConsume(tok::identifier, diag::err_expected_ident)) { |
Chris Lattner | 14776b9 | 2006-08-06 22:27:40 +0000 | [diff] [blame] | 950 | ErrorEmitted = true; |
| 951 | break; |
| 952 | } |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 953 | |
| 954 | // FIXME: pass stuff. |
| 955 | ParamInfo.push_back(DeclaratorTypeInfo::ParamInfo()); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 958 | // K&R 'prototype'. |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 959 | IsVariadic = false; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 960 | HasPrototype = false; |
| 961 | } else { |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 962 | // Finally, a normal, non-empty parameter type list. |
| 963 | |
| 964 | // Enter function-declaration scope, limiting any declarators for arguments |
| 965 | // to the function scope. |
| 966 | EnterScope(0); |
| 967 | |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 968 | IsVariadic = false; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 969 | bool ReadArg = false; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 970 | while (1) { |
| 971 | if (Tok.getKind() == tok::ellipsis) { |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 972 | IsVariadic = true; |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 973 | |
| 974 | // Check to see if this is "void(...)" which is not allowed. |
| 975 | if (!ReadArg) { |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 976 | // Otherwise, parse parameter type list. If it starts with an |
| 977 | // ellipsis, diagnose the malformed function. |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 978 | Diag(Tok, diag::err_ellipsis_first_arg); |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 979 | IsVariadic = false; // Treat this like 'void()'. |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | // Consume the ellipsis. |
| 983 | ConsumeToken(); |
| 984 | break; |
| 985 | } |
| 986 | |
| 987 | ReadArg = true; |
| 988 | |
| 989 | // Parse the declaration-specifiers. |
| 990 | DeclSpec DS; |
| 991 | ParseDeclarationSpecifiers(DS); |
| 992 | |
| 993 | // Parse the declarator. This is "PrototypeContext", because we must |
| 994 | // accept either 'declarator' or 'abstract-declarator' here. |
| 995 | Declarator DeclaratorInfo(DS, Declarator::PrototypeContext); |
| 996 | ParseDeclarator(DeclaratorInfo); |
| 997 | |
Chris Lattner | e37e233 | 2006-08-15 04:50:22 +0000 | [diff] [blame] | 998 | // Parse GNU attributes, if present. |
| 999 | if (Tok.getKind() == tok::kw___attribute) |
| 1000 | ParseAttributes(); |
| 1001 | |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1002 | // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'. |
Chris Lattner | f055d43 | 2006-11-28 04:28:12 +0000 | [diff] [blame] | 1003 | switch (DS.getStorageClassSpec()) { |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1004 | case DeclSpec::SCS_unspecified: |
| 1005 | case DeclSpec::SCS_register: |
| 1006 | break; |
| 1007 | case DeclSpec::SCS_auto: |
| 1008 | // NOTE: we could trivially allow 'int foo(auto int X)' if we wanted. |
| 1009 | default: |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 1010 | Diag(DS.getStorageClassSpecLoc(), |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1011 | diag::err_invalid_storage_class_in_func_decl); |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 1012 | DS.ClearStorageClassSpecs(); |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1013 | break; |
| 1014 | } |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 1015 | if (DS.isThreadSpecified()) { |
| 1016 | Diag(DS.getThreadSpecLoc(), |
| 1017 | diag::err_invalid_storage_class_in_func_decl); |
| 1018 | DS.ClearStorageClassSpecs(); |
| 1019 | } |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1020 | |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 1021 | |
| 1022 | // FIXME: pass stuff. |
| 1023 | ParamInfo.push_back(DeclaratorTypeInfo::ParamInfo()); |
| 1024 | |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1025 | // Inform the actions module about the parameter declarator, so it gets |
| 1026 | // added to the current scope. |
| 1027 | Actions.ParseDeclarator(CurScope, DeclaratorInfo, 0, 0); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 1028 | |
| 1029 | // If the next token is a comma, consume it and keep reading arguments. |
| 1030 | if (Tok.getKind() != tok::comma) break; |
| 1031 | |
| 1032 | // Consume the comma. |
| 1033 | ConsumeToken(); |
| 1034 | } |
| 1035 | |
| 1036 | HasPrototype = true; |
Chris Lattner | 43e956c | 2006-11-28 04:05:37 +0000 | [diff] [blame] | 1037 | |
| 1038 | // Leave prototype scope. |
| 1039 | ExitScope(); |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 1042 | DeclaratorTypeInfo::ParamInfo *ParamArray = 0; |
| 1043 | if (!ParamInfo.empty()) { |
| 1044 | ParamArray = new DeclaratorTypeInfo::ParamInfo[ParamInfo.size()]; |
| 1045 | memcpy(ParamArray, &ParamInfo[0], sizeof(ParamInfo[0])*ParamInfo.size()); |
| 1046 | } |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 1047 | |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 1048 | // Remember that we parsed a function type, and remember the attributes. |
| 1049 | D.AddTypeInfo(DeclaratorTypeInfo::getFunction(HasPrototype, IsVariadic, |
Chris Lattner | edc9e39 | 2006-12-02 06:21:46 +0000 | [diff] [blame^] | 1050 | ParamInfo.size(), ParamArray, |
| 1051 | StartLoc)); |
Chris Lattner | d5d0a6c | 2006-08-07 00:58:14 +0000 | [diff] [blame] | 1052 | |
Chris Lattner | 14776b9 | 2006-08-06 22:27:40 +0000 | [diff] [blame] | 1053 | |
| 1054 | // If we have the closing ')', eat it and we're done. |
| 1055 | if (Tok.getKind() == tok::r_paren) { |
| 1056 | ConsumeParen(); |
| 1057 | } else { |
| 1058 | // If an error happened earlier parsing something else in the proto, don't |
| 1059 | // issue another error. |
| 1060 | if (!ErrorEmitted) |
| 1061 | Diag(Tok, diag::err_expected_rparen); |
| 1062 | SkipUntil(tok::r_paren); |
| 1063 | } |
Chris Lattner | c0acd3d | 2006-07-31 05:13:43 +0000 | [diff] [blame] | 1064 | } |
Chris Lattner | acd58a3 | 2006-08-06 17:24:14 +0000 | [diff] [blame] | 1065 | |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1066 | |
| 1067 | /// [C90] direct-declarator '[' constant-expression[opt] ']' |
| 1068 | /// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']' |
| 1069 | /// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']' |
| 1070 | /// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']' |
| 1071 | /// [C99] direct-declarator '[' type-qual-list[opt] '*' ']' |
| 1072 | void Parser::ParseBracketDeclarator(Declarator &D) { |
Chris Lattner | 0413237 | 2006-10-16 06:12:55 +0000 | [diff] [blame] | 1073 | SourceLocation StartLoc = ConsumeBracket(); |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1074 | |
| 1075 | // If valid, this location is the position where we read the 'static' keyword. |
| 1076 | SourceLocation StaticLoc; |
Chris Lattner | af63531 | 2006-10-16 06:06:51 +0000 | [diff] [blame] | 1077 | if (Tok.getKind() == tok::kw_static) |
| 1078 | StaticLoc = ConsumeToken(); |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1079 | |
| 1080 | // If there is a type-qualifier-list, read it now. |
| 1081 | DeclSpec DS; |
| 1082 | ParseTypeQualifierListOpt(DS); |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1083 | |
| 1084 | // If we haven't already read 'static', check to see if there is one after the |
| 1085 | // type-qualifier-list. |
Chris Lattner | af63531 | 2006-10-16 06:06:51 +0000 | [diff] [blame] | 1086 | if (!StaticLoc.isValid() && Tok.getKind() == tok::kw_static) |
| 1087 | StaticLoc = ConsumeToken(); |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1088 | |
| 1089 | // Handle "direct-declarator [ type-qual-list[opt] * ]". |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1090 | bool isStar = false; |
Chris Lattner | 6259172 | 2006-08-12 18:40:58 +0000 | [diff] [blame] | 1091 | ExprResult NumElements(false); |
Chris Lattner | 1906f80 | 2006-08-06 19:14:46 +0000 | [diff] [blame] | 1092 | if (Tok.getKind() == tok::star) { |
| 1093 | // Remember the '*' token, in case we have to un-get it. |
| 1094 | LexerToken StarTok = Tok; |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1095 | ConsumeToken(); |
Chris Lattner | 1906f80 | 2006-08-06 19:14:46 +0000 | [diff] [blame] | 1096 | |
| 1097 | // Check that the ']' token is present to avoid incorrectly parsing |
| 1098 | // expressions starting with '*' as [*]. |
| 1099 | if (Tok.getKind() == tok::r_square) { |
| 1100 | if (StaticLoc.isValid()) |
| 1101 | Diag(StaticLoc, diag::err_unspecified_vla_size_with_static); |
| 1102 | StaticLoc = SourceLocation(); // Drop the static. |
| 1103 | isStar = true; |
Chris Lattner | 1906f80 | 2006-08-06 19:14:46 +0000 | [diff] [blame] | 1104 | } else { |
| 1105 | // Otherwise, the * must have been some expression (such as '*ptr') that |
Chris Lattner | 9fab3b9 | 2006-08-12 18:25:42 +0000 | [diff] [blame] | 1106 | // started an assignment-expr. We already consumed the token, but now we |
Chris Lattner | 6259172 | 2006-08-12 18:40:58 +0000 | [diff] [blame] | 1107 | // need to reparse it. This handles cases like 'X[*p + 4]' |
| 1108 | NumElements = ParseAssignmentExpressionWithLeadingStar(StarTok); |
Chris Lattner | 1906f80 | 2006-08-06 19:14:46 +0000 | [diff] [blame] | 1109 | } |
Chris Lattner | 9fab3b9 | 2006-08-12 18:25:42 +0000 | [diff] [blame] | 1110 | } else if (Tok.getKind() != tok::r_square) { |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1111 | // Parse the assignment-expression now. |
Chris Lattner | 6259172 | 2006-08-12 18:40:58 +0000 | [diff] [blame] | 1112 | NumElements = ParseAssignmentExpression(); |
| 1113 | } |
| 1114 | |
| 1115 | // If there was an error parsing the assignment-expression, recover. |
| 1116 | if (NumElements.isInvalid) { |
| 1117 | // If the expression was invalid, skip it. |
| 1118 | SkipUntil(tok::r_square); |
| 1119 | return; |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Chris Lattner | 04f8019 | 2006-08-15 04:55:54 +0000 | [diff] [blame] | 1122 | MatchRHSPunctuation(tok::r_square, StartLoc); |
Chris Lattner | 9fab3b9 | 2006-08-12 18:25:42 +0000 | [diff] [blame] | 1123 | |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1124 | // If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if |
| 1125 | // it was not a constant expression. |
| 1126 | if (!getLang().C99) { |
| 1127 | // TODO: check C90 array constant exprness. |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 1128 | if (isStar || StaticLoc.isValid() || |
| 1129 | 0/*TODO: NumElts is not a C90 constantexpr */) |
Chris Lattner | 8a39edc | 2006-08-06 18:33:32 +0000 | [diff] [blame] | 1130 | Diag(StartLoc, diag::ext_c99_array_usage); |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1131 | } |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 1132 | |
| 1133 | // Remember that we parsed a pointer type, and remember the type-quals. |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 1134 | D.AddTypeInfo(DeclaratorTypeInfo::getArray(DS.getTypeQualifiers(), |
Chris Lattner | 6c7416c | 2006-08-07 00:19:33 +0000 | [diff] [blame] | 1135 | StaticLoc.isValid(), isStar, |
Chris Lattner | 6259172 | 2006-08-12 18:40:58 +0000 | [diff] [blame] | 1136 | NumElements.Val, StartLoc)); |
Chris Lattner | e8074e6 | 2006-08-06 18:30:15 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |