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