00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "system.h"
00025 #include "coretypes.h"
00026 #include "tm.h"
00027 #include "dyn-string.h"
00028 #include "varray.h"
00029 #include "cpplib.h"
00030 #include "tree.h"
00031 #include "cp-tree.h"
00032 #include "c-pragma.h"
00033 #include "decl.h"
00034 #include "flags.h"
00035 #include "diagnostic.h"
00036 #include "toplev.h"
00037 #include "output.h"
00038 #include "target.h"
00039 #include "cgraph.h"
00040 #include "c-common.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 struct tree_check GTY(())
00052 {
00053
00054 tree value;
00055
00056 VEC (deferred_access_check, gc)* checks;
00057
00058
00059 tree qualifying_scope;
00060 };
00061
00062
00063
00064 typedef struct cp_token GTY (())
00065 {
00066
00067 ENUM_BITFIELD (cpp_ttype) type : 8;
00068
00069
00070 ENUM_BITFIELD (rid) keyword : 8;
00071
00072 unsigned char flags;
00073
00074 ENUM_BITFIELD (pragma_kind) pragma_kind : 6;
00075
00076 BOOL_BITFIELD in_system_header : 1;
00077
00078 BOOL_BITFIELD implicit_extern_c : 1;
00079
00080
00081
00082 BOOL_BITFIELD ambiguous_p : 1;
00083
00084 unsigned input_file_stack_index : INPUT_FILE_STACK_BITS;
00085
00086 union cp_token_value {
00087
00088 struct tree_check* GTY((tag ("1"))) tree_check_value;
00089
00090 tree GTY((tag ("0"))) value;
00091 } GTY((desc ("(%1.type == CPP_TEMPLATE_ID) || (%1.type == CPP_NESTED_NAME_SPECIFIER)"))) u;
00092
00093 location_t location;
00094 } cp_token;
00095
00096
00097 typedef struct cp_token *cp_token_position;
00098 DEF_VEC_P (cp_token_position);
00099 DEF_VEC_ALLOC_P (cp_token_position,heap);
00100
00101 static const cp_token eof_token =
00102 {
00103 CPP_EOF, RID_MAX, 0, PRAGMA_NONE, 0, 0, false, 0, { NULL },
00104 #if USE_MAPPED_LOCATION
00105 0
00106 #else
00107 {0, 0}
00108 #endif
00109 };
00110
00111
00112
00113
00114
00115
00116 typedef struct cp_lexer GTY (())
00117 {
00118
00119
00120 cp_token * GTY ((length ("%h.buffer_length"))) buffer;
00121
00122
00123 size_t buffer_length;
00124
00125
00126
00127 cp_token_position GTY ((skip)) last_token;
00128
00129
00130
00131 cp_token_position GTY ((skip)) next_token;
00132
00133
00134
00135
00136
00137 VEC(cp_token_position,heap) *GTY ((skip)) saved_tokens;
00138
00139
00140 struct cp_lexer *next;
00141
00142
00143 bool debugging_p;
00144
00145
00146
00147 bool in_pragma;
00148 } cp_lexer;
00149
00150
00151
00152
00153
00154
00155
00156 typedef struct cp_token_cache GTY(())
00157 {
00158
00159 cp_token * GTY((skip)) first;
00160
00161
00162 cp_token * GTY ((skip)) last;
00163 } cp_token_cache;
00164
00165
00166
00167 static cp_lexer *cp_lexer_new_main
00168 (void);
00169 static cp_lexer *cp_lexer_new_from_tokens
00170 (cp_token_cache *tokens);
00171 static void cp_lexer_destroy
00172 (cp_lexer *);
00173 static int cp_lexer_saving_tokens
00174 (const cp_lexer *);
00175 static cp_token_position cp_lexer_token_position
00176 (cp_lexer *, bool);
00177 static cp_token *cp_lexer_token_at
00178 (cp_lexer *, cp_token_position);
00179 static void cp_lexer_get_preprocessor_token
00180 (cp_lexer *, cp_token *);
00181 static inline cp_token *cp_lexer_peek_token
00182 (cp_lexer *);
00183 static cp_token *cp_lexer_peek_nth_token
00184 (cp_lexer *, size_t);
00185 static inline bool cp_lexer_next_token_is
00186 (cp_lexer *, enum cpp_ttype);
00187 static bool cp_lexer_next_token_is_not
00188 (cp_lexer *, enum cpp_ttype);
00189 static bool cp_lexer_next_token_is_keyword
00190 (cp_lexer *, enum rid);
00191 static cp_token *cp_lexer_consume_token
00192 (cp_lexer *);
00193 static void cp_lexer_purge_token
00194 (cp_lexer *);
00195 static void cp_lexer_purge_tokens_after
00196 (cp_lexer *, cp_token_position);
00197 static void cp_lexer_save_tokens
00198 (cp_lexer *);
00199 static void cp_lexer_commit_tokens
00200 (cp_lexer *);
00201 static void cp_lexer_rollback_tokens
00202 (cp_lexer *);
00203 #ifdef ENABLE_CHECKING
00204 static void cp_lexer_print_token
00205 (FILE *, cp_token *);
00206 static inline bool cp_lexer_debugging_p
00207 (cp_lexer *);
00208 static void cp_lexer_start_debugging
00209 (cp_lexer *) ATTRIBUTE_UNUSED;
00210 static void cp_lexer_stop_debugging
00211 (cp_lexer *) ATTRIBUTE_UNUSED;
00212 #else
00213
00214
00215
00216
00217 #define cp_lexer_debug_stream stdout
00218 #define cp_lexer_print_token(str, tok) (void) 0
00219 #define cp_lexer_debugging_p(lexer) 0
00220 #endif
00221
00222 static cp_token_cache *cp_token_cache_new
00223 (cp_token *, cp_token *);
00224
00225 static void cp_parser_initial_pragma
00226 (cp_token *);
00227
00228
00229 #define CP_LEXER_BUFFER_SIZE ((256 * 1024) / sizeof (cp_token))
00230 #define CP_SAVED_TOKEN_STACK 5
00231
00232
00233 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
00234
00235
00236
00237
00238
00239 #define CPP_TEMPLATE_ID ((enum cpp_ttype) (CPP_KEYWORD + 1))
00240
00241
00242
00243
00244
00245
00246 #define CPP_NESTED_NAME_SPECIFIER ((enum cpp_ttype) (CPP_TEMPLATE_ID + 1))
00247
00248
00249
00250
00251 #define CPP_PURGED ((enum cpp_ttype) (CPP_NESTED_NAME_SPECIFIER + 1))
00252
00253
00254 #define N_CP_TTYPES ((int) (CPP_PURGED + 1))
00255
00256
00257
00258 #ifdef ENABLE_CHECKING
00259
00260 static FILE *cp_lexer_debug_stream;
00261 #endif
00262
00263
00264
00265
00266 static cp_lexer *
00267 cp_lexer_new_main (void)
00268 {
00269 cp_token first_token;
00270 cp_lexer *lexer;
00271 cp_token *pos;
00272 size_t alloc;
00273 size_t space;
00274 cp_token *buffer;
00275
00276
00277
00278
00279 cp_parser_initial_pragma (&first_token);
00280
00281
00282 c_lex_return_raw_strings = true;
00283
00284 c_common_no_more_pch ();
00285
00286
00287 lexer = GGC_CNEW (cp_lexer);
00288
00289 #ifdef ENABLE_CHECKING
00290
00291 lexer->debugging_p = false;
00292 #endif
00293 lexer->saved_tokens = VEC_alloc (cp_token_position, heap,
00294 CP_SAVED_TOKEN_STACK);
00295
00296
00297 alloc = CP_LEXER_BUFFER_SIZE;
00298 buffer = GGC_NEWVEC (cp_token, alloc);
00299
00300
00301 space = alloc;
00302 pos = buffer;
00303 *pos = first_token;
00304
00305
00306 while (pos->type != CPP_EOF)
00307 {
00308 pos++;
00309 if (!--space)
00310 {
00311 space = alloc;
00312 alloc *= 2;
00313 buffer = GGC_RESIZEVEC (cp_token, buffer, alloc);
00314 pos = buffer + space;
00315 }
00316 cp_lexer_get_preprocessor_token (lexer, pos);
00317 }
00318 lexer->buffer = buffer;
00319 lexer->buffer_length = alloc - space;
00320 lexer->last_token = pos;
00321 lexer->next_token = lexer->buffer_length ? buffer : (cp_token *)&eof_token;
00322
00323
00324
00325 cpp_get_options (parse_in)->client_diagnostic = true;
00326 cpp_get_callbacks (parse_in)->error = cp_cpp_error;
00327
00328 gcc_assert (lexer->next_token->type != CPP_PURGED);
00329 return lexer;
00330 }
00331
00332
00333
00334
00335 static cp_lexer *
00336 cp_lexer_new_from_tokens (cp_token_cache *cache)
00337 {
00338 cp_token *first = cache->first;
00339 cp_token *last = cache->last;
00340 cp_lexer *lexer = GGC_CNEW (cp_lexer);
00341
00342
00343 lexer->buffer = NULL;
00344 lexer->buffer_length = 0;
00345 lexer->next_token = first == last ? (cp_token *)&eof_token : first;
00346 lexer->last_token = last;
00347
00348 lexer->saved_tokens = VEC_alloc (cp_token_position, heap,
00349 CP_SAVED_TOKEN_STACK);
00350
00351 #ifdef ENABLE_CHECKING
00352
00353 lexer->debugging_p = false;
00354 #endif
00355
00356 gcc_assert (lexer->next_token->type != CPP_PURGED);
00357 return lexer;
00358 }
00359
00360
00361
00362 static void
00363 cp_lexer_destroy (cp_lexer *lexer)
00364 {
00365 if (lexer->buffer)
00366 ggc_free (lexer->buffer);
00367 VEC_free (cp_token_position, heap, lexer->saved_tokens);
00368 ggc_free (lexer);
00369 }
00370
00371
00372
00373 #ifdef ENABLE_CHECKING
00374
00375 static inline bool
00376 cp_lexer_debugging_p (cp_lexer *lexer)
00377 {
00378 return lexer->debugging_p;
00379 }
00380
00381 #endif
00382
00383 static inline cp_token_position
00384 cp_lexer_token_position (cp_lexer *lexer, bool previous_p)
00385 {
00386 gcc_assert (!previous_p || lexer->next_token != &eof_token);
00387
00388 return lexer->next_token - previous_p;
00389 }
00390
00391 static inline cp_token *
00392 cp_lexer_token_at (cp_lexer *lexer ATTRIBUTE_UNUSED, cp_token_position pos)
00393 {
00394 return pos;
00395 }
00396
00397
00398
00399 static inline int
00400 cp_lexer_saving_tokens (const cp_lexer* lexer)
00401 {
00402 return VEC_length (cp_token_position, lexer->saved_tokens) != 0;
00403 }
00404
00405
00406
00407
00408 static void
00409 cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED ,
00410 cp_token *token)
00411 {
00412 static int is_extern_c = 0;
00413
00414
00415 token->type
00416 = c_lex_with_flags (&token->u.value, &token->location, &token->flags);
00417 token->input_file_stack_index = input_file_stack_tick;
00418 token->keyword = RID_MAX;
00419 token->pragma_kind = PRAGMA_NONE;
00420 token->in_system_header = in_system_header;
00421
00422
00423
00424
00425 is_extern_c += pending_lang_change;
00426 pending_lang_change = 0;
00427 token->implicit_extern_c = is_extern_c > 0;
00428
00429
00430 if (token->type == CPP_NAME)
00431 {
00432 if (C_IS_RESERVED_WORD (token->u.value))
00433 {
00434
00435 token->type = CPP_KEYWORD;
00436
00437 token->keyword = C_RID_CODE (token->u.value);
00438
00439
00440
00441
00442 token->u.value = ridpointers[token->keyword];
00443 }
00444 else
00445 {
00446 token->ambiguous_p = false;
00447 token->keyword = RID_MAX;
00448 }
00449 }
00450
00451 else if (token->type == CPP_AT_NAME)
00452 {
00453 token->type = CPP_KEYWORD;
00454 switch (C_RID_CODE (token->u.value))
00455 {
00456
00457 case RID_CLASS: token->keyword = RID_AT_CLASS; break;
00458 case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break;
00459 case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break;
00460 case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break;
00461 case RID_THROW: token->keyword = RID_AT_THROW; break;
00462 case RID_TRY: token->keyword = RID_AT_TRY; break;
00463 case RID_CATCH: token->keyword = RID_AT_CATCH; break;
00464 default: token->keyword = C_RID_CODE (token->u.value);
00465 }
00466 }
00467 else if (token->type == CPP_PRAGMA)
00468 {
00469
00470 token->pragma_kind = TREE_INT_CST_LOW (token->u.value);
00471 token->u.value = NULL_TREE;
00472 }
00473 }
00474
00475
00476
00477 static inline void
00478 cp_lexer_set_source_position_from_token (cp_token *token)
00479 {
00480 if (token->type != CPP_EOF)
00481 {
00482 input_location = token->location;
00483 in_system_header = token->in_system_header;
00484 restore_input_file_stack (token->input_file_stack_index);
00485 }
00486 }
00487
00488
00489
00490
00491 static inline cp_token *
00492 cp_lexer_peek_token (cp_lexer *lexer)
00493 {
00494 if (cp_lexer_debugging_p (lexer))
00495 {
00496 fputs ("cp_lexer: peeking at token: ", cp_lexer_debug_stream);
00497 cp_lexer_print_token (cp_lexer_debug_stream, lexer->next_token);
00498 putc ('\n', cp_lexer_debug_stream);
00499 }
00500 return lexer->next_token;
00501 }
00502
00503
00504
00505 static inline bool
00506 cp_lexer_next_token_is (cp_lexer* lexer, enum cpp_ttype type)
00507 {
00508 return cp_lexer_peek_token (lexer)->type == type;
00509 }
00510
00511
00512
00513 static inline bool
00514 cp_lexer_next_token_is_not (cp_lexer* lexer, enum cpp_ttype type)
00515 {
00516 return !cp_lexer_next_token_is (lexer, type);
00517 }
00518
00519
00520
00521 static inline bool
00522 cp_lexer_next_token_is_keyword (cp_lexer* lexer, enum rid keyword)
00523 {
00524 return cp_lexer_peek_token (lexer)->keyword == keyword;
00525 }
00526
00527
00528
00529 static bool
00530 cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer)
00531 {
00532 cp_token *token;
00533
00534 token = cp_lexer_peek_token (lexer);
00535 switch (token->keyword)
00536 {
00537
00538 case RID_AUTO:
00539 case RID_REGISTER:
00540 case RID_STATIC:
00541 case RID_EXTERN:
00542 case RID_MUTABLE:
00543 case RID_THREAD:
00544
00545 case RID_ENUM:
00546 case RID_CLASS:
00547 case RID_STRUCT:
00548 case RID_UNION:
00549 case RID_TYPENAME:
00550
00551 case RID_CHAR:
00552 case RID_WCHAR:
00553 case RID_BOOL:
00554 case RID_SHORT:
00555 case RID_INT:
00556 case RID_LONG:
00557 case RID_SIGNED:
00558 case RID_UNSIGNED:
00559 case RID_FLOAT:
00560 case RID_DOUBLE:
00561 case RID_VOID:
00562
00563 case RID_ATTRIBUTE:
00564 case RID_TYPEOF:
00565 return true;
00566
00567 default:
00568 return false;
00569 }
00570 }
00571
00572
00573
00574
00575
00576
00577
00578 static cp_token *
00579 cp_lexer_peek_nth_token (cp_lexer* lexer, size_t n)
00580 {
00581 cp_token *token;
00582
00583
00584 gcc_assert (n > 0);
00585
00586 if (cp_lexer_debugging_p (lexer))
00587 fprintf (cp_lexer_debug_stream,
00588 "cp_lexer: peeking ahead %ld at token: ", (long)n);
00589
00590 --n;
00591 token = lexer->next_token;
00592 gcc_assert (!n || token != &eof_token);
00593 while (n != 0)
00594 {
00595 ++token;
00596 if (token == lexer->last_token)
00597 {
00598 token = (cp_token *)&eof_token;
00599 break;
00600 }
00601
00602 if (token->type != CPP_PURGED)
00603 --n;
00604 }
00605
00606 if (cp_lexer_debugging_p (lexer))
00607 {
00608 cp_lexer_print_token (cp_lexer_debug_stream, token);
00609 putc ('\n', cp_lexer_debug_stream);
00610 }
00611
00612 return token;
00613 }
00614
00615
00616
00617
00618 static cp_token *
00619 cp_lexer_consume_token (cp_lexer* lexer)
00620 {
00621 cp_token *token = lexer->next_token;
00622
00623 gcc_assert (token != &eof_token);
00624 gcc_assert (!lexer->in_pragma || token->type != CPP_PRAGMA_EOL);
00625
00626 do
00627 {
00628 lexer->next_token++;
00629 if (lexer->next_token == lexer->last_token)
00630 {
00631 lexer->next_token = (cp_token *)&eof_token;
00632 break;
00633 }
00634
00635 }
00636 while (lexer->next_token->type == CPP_PURGED);
00637
00638 cp_lexer_set_source_position_from_token (token);
00639
00640
00641 if (cp_lexer_debugging_p (lexer))
00642 {
00643 fputs ("cp_lexer: consuming token: ", cp_lexer_debug_stream);
00644 cp_lexer_print_token (cp_lexer_debug_stream, token);
00645 putc ('\n', cp_lexer_debug_stream);
00646 }
00647
00648 return token;
00649 }
00650
00651
00652
00653
00654
00655 static void
00656 cp_lexer_purge_token (cp_lexer *lexer)
00657 {
00658 cp_token *tok = lexer->next_token;
00659
00660 gcc_assert (tok != &eof_token);
00661 tok->type = CPP_PURGED;
00662 tok->location = UNKNOWN_LOCATION;
00663 tok->u.value = NULL_TREE;
00664 tok->keyword = RID_MAX;
00665
00666 do
00667 {
00668 tok++;
00669 if (tok == lexer->last_token)
00670 {
00671 tok = (cp_token *)&eof_token;
00672 break;
00673 }
00674 }
00675 while (tok->type == CPP_PURGED);
00676 lexer->next_token = tok;
00677 }
00678
00679
00680
00681
00682
00683 static void
00684 cp_lexer_purge_tokens_after (cp_lexer *lexer, cp_token *tok)
00685 {
00686 cp_token *peek = lexer->next_token;
00687
00688 if (peek == &eof_token)
00689 peek = lexer->last_token;
00690
00691 gcc_assert (tok < peek);
00692
00693 for ( tok += 1; tok != peek; tok += 1)
00694 {
00695 tok->type = CPP_PURGED;
00696 tok->location = UNKNOWN_LOCATION;
00697 tok->u.value = NULL_TREE;
00698 tok->keyword = RID_MAX;
00699 }
00700 }
00701
00702
00703
00704
00705 static void
00706 cp_lexer_save_tokens (cp_lexer* lexer)
00707 {
00708
00709 if (cp_lexer_debugging_p (lexer))
00710 fprintf (cp_lexer_debug_stream, "cp_lexer: saving tokens\n");
00711
00712 VEC_safe_push (cp_token_position, heap,
00713 lexer->saved_tokens, lexer->next_token);
00714 }
00715
00716
00717
00718 static void
00719 cp_lexer_commit_tokens (cp_lexer* lexer)
00720 {
00721
00722 if (cp_lexer_debugging_p (lexer))
00723 fprintf (cp_lexer_debug_stream, "cp_lexer: committing tokens\n");
00724
00725 VEC_pop (cp_token_position, lexer->saved_tokens);
00726 }
00727
00728
00729
00730
00731 static void
00732 cp_lexer_rollback_tokens (cp_lexer* lexer)
00733 {
00734
00735 if (cp_lexer_debugging_p (lexer))
00736 fprintf (cp_lexer_debug_stream, "cp_lexer: restoring tokens\n");
00737
00738 lexer->next_token = VEC_pop (cp_token_position, lexer->saved_tokens);
00739 }
00740
00741
00742
00743 #ifdef ENABLE_CHECKING
00744
00745 static void
00746 cp_lexer_print_token (FILE * stream, cp_token *token)
00747 {
00748
00749
00750 static const char *const token_names[] = {
00751
00752 #define OP(e, s) #e,
00753 #define TK(e, s) #e,
00754 TTYPE_TABLE
00755 #undef OP
00756 #undef TK
00757
00758 "KEYWORD",
00759 "TEMPLATE_ID",
00760 "NESTED_NAME_SPECIFIER",
00761 "PURGED"
00762 };
00763
00764
00765
00766 gcc_assert (token->type < ARRAY_SIZE(token_names));
00767 fputs (token_names[token->type], stream);
00768
00769
00770 switch (token->type)
00771 {
00772 case CPP_KEYWORD:
00773
00774
00775 if (TREE_CODE (token->u.value) != IDENTIFIER_NODE)
00776 break;
00777
00778 case CPP_NAME:
00779 fputs (IDENTIFIER_POINTER (token->u.value), stream);
00780 break;
00781
00782 case CPP_STRING:
00783 case CPP_WSTRING:
00784 fprintf (stream, " \"%s\"", TREE_STRING_POINTER (token->u.value));
00785 break;
00786
00787 default:
00788 break;
00789 }
00790 }
00791
00792
00793
00794 static void
00795 cp_lexer_start_debugging (cp_lexer* lexer)
00796 {
00797 lexer->debugging_p = true;
00798 }
00799
00800
00801
00802 static void
00803 cp_lexer_stop_debugging (cp_lexer* lexer)
00804 {
00805 lexer->debugging_p = false;
00806 }
00807
00808 #endif
00809
00810
00811
00812 static cp_token_cache *
00813 cp_token_cache_new (cp_token *first, cp_token *last)
00814 {
00815 cp_token_cache *cache = GGC_NEW (cp_token_cache);
00816 cache->first = first;
00817 cache->last = last;
00818 return cache;
00819 }
00820
00821
00822
00823
00824
00825
00826 static void
00827 clear_decl_specs (cp_decl_specifier_seq *decl_specs)
00828 {
00829 memset (decl_specs, 0, sizeof (cp_decl_specifier_seq));
00830 }
00831
00832
00833
00834
00835
00836
00837
00838
00839 static cp_declarator *make_call_declarator
00840 (cp_declarator *, cp_parameter_declarator *, cp_cv_quals, tree);
00841 static cp_declarator *make_array_declarator
00842 (cp_declarator *, tree);
00843 static cp_declarator *make_pointer_declarator
00844 (cp_cv_quals, cp_declarator *);
00845 static cp_declarator *make_reference_declarator
00846 (cp_cv_quals, cp_declarator *);
00847 static cp_parameter_declarator *make_parameter_declarator
00848 (cp_decl_specifier_seq *, cp_declarator *, tree);
00849 static cp_declarator *make_ptrmem_declarator
00850 (cp_cv_quals, tree, cp_declarator *);
00851
00852
00853 static cp_declarator *cp_error_declarator;
00854
00855
00856
00857 static struct obstack declarator_obstack;
00858
00859
00860
00861 static inline void *
00862 alloc_declarator (size_t bytes)
00863 {
00864 return obstack_alloc (&declarator_obstack, bytes);
00865 }
00866
00867
00868
00869
00870 static cp_declarator *
00871 make_declarator (cp_declarator_kind kind)
00872 {
00873 cp_declarator *declarator;
00874
00875 declarator = (cp_declarator *) alloc_declarator (sizeof (cp_declarator));
00876 declarator->kind = kind;
00877 declarator->attributes = NULL_TREE;
00878 declarator->declarator = NULL;
00879
00880 return declarator;
00881 }
00882
00883
00884
00885
00886
00887
00888
00889 static cp_declarator *
00890 make_id_declarator (tree qualifying_scope, tree unqualified_name,
00891 special_function_kind sfk)
00892 {
00893 cp_declarator *declarator;
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905 if (qualifying_scope && TYPE_P (qualifying_scope))
00906 qualifying_scope = TYPE_MAIN_VARIANT (qualifying_scope);
00907
00908 gcc_assert (TREE_CODE (unqualified_name) == IDENTIFIER_NODE
00909 || TREE_CODE (unqualified_name) == BIT_NOT_EXPR
00910 || TREE_CODE (unqualified_name) == TEMPLATE_ID_EXPR);
00911
00912 declarator = make_declarator (cdk_id);
00913 declarator->u.id.qualifying_scope = qualifying_scope;
00914 declarator->u.id.unqualified_name = unqualified_name;
00915 declarator->u.id.sfk = sfk;
00916
00917 return declarator;
00918 }
00919
00920
00921
00922
00923
00924 cp_declarator *
00925 make_pointer_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
00926 {
00927 cp_declarator *declarator;
00928
00929 declarator = make_declarator (cdk_pointer);
00930 declarator->declarator = target;
00931 declarator->u.pointer.qualifiers = cv_qualifiers;
00932 declarator->u.pointer.class_type = NULL_TREE;
00933
00934 return declarator;
00935 }
00936
00937
00938
00939 cp_declarator *
00940 make_reference_declarator (cp_cv_quals cv_qualifiers, cp_declarator *target)
00941 {
00942 cp_declarator *declarator;
00943
00944 declarator = make_declarator (cdk_reference);
00945 declarator->declarator = target;
00946 declarator->u.pointer.qualifiers = cv_qualifiers;
00947 declarator->u.pointer.class_type = NULL_TREE;
00948
00949 return declarator;
00950 }
00951
00952
00953
00954
00955 cp_declarator *
00956 make_ptrmem_declarator (cp_cv_quals cv_qualifiers, tree class_type,
00957 cp_declarator *pointee)
00958 {
00959 cp_declarator *declarator;
00960
00961 declarator = make_declarator (cdk_ptrmem);
00962 declarator->declarator = pointee;
00963 declarator->u.pointer.qualifiers = cv_qualifiers;
00964 declarator->u.pointer.class_type = class_type;
00965
00966 return declarator;
00967 }
00968
00969
00970
00971
00972
00973
00974 cp_declarator *
00975 make_call_declarator (cp_declarator *target,
00976 cp_parameter_declarator *parms,
00977 cp_cv_quals cv_qualifiers,
00978 tree exception_specification)
00979 {
00980 cp_declarator *declarator;
00981
00982 declarator = make_declarator (cdk_function);
00983 declarator->declarator = target;
00984 declarator->u.function.parameters = parms;
00985 declarator->u.function.qualifiers = cv_qualifiers;
00986 declarator->u.function.exception_specification = exception_specification;
00987
00988 return declarator;
00989 }
00990
00991
00992
00993
00994 cp_declarator *
00995 make_array_declarator (cp_declarator *element, tree bounds)
00996 {
00997 cp_declarator *declarator;
00998
00999 declarator = make_declarator (cdk_array);
01000 declarator->declarator = element;
01001 declarator->u.array.bounds = bounds;
01002
01003 return declarator;
01004 }
01005
01006 cp_parameter_declarator *no_parameters;
01007
01008
01009
01010
01011 cp_parameter_declarator *
01012 make_parameter_declarator (cp_decl_specifier_seq *decl_specifiers,
01013 cp_declarator *declarator,
01014 tree default_argument)
01015 {
01016 cp_parameter_declarator *parameter;
01017
01018 parameter = ((cp_parameter_declarator *)
01019 alloc_declarator (sizeof (cp_parameter_declarator)));
01020 parameter->next = NULL;
01021 if (decl_specifiers)
01022 parameter->decl_specifiers = *decl_specifiers;
01023 else
01024 clear_decl_specs (¶meter->decl_specifiers);
01025 parameter->declarator = declarator;
01026 parameter->default_argument = default_argument;
01027 parameter->ellipsis_p = false;
01028
01029 return parameter;
01030 }
01031
01032
01033
01034 static bool
01035 function_declarator_p (const cp_declarator *declarator)
01036 {
01037 while (declarator)
01038 {
01039 if (declarator->kind == cdk_function
01040 && declarator->declarator->kind == cdk_id)
01041 return true;
01042 if (declarator->kind == cdk_id
01043 || declarator->kind == cdk_error)
01044 return false;
01045 declarator = declarator->declarator;
01046 }
01047 return false;
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108 typedef enum cp_parser_flags
01109 {
01110
01111 CP_PARSER_FLAGS_NONE = 0x0,
01112
01113
01114 CP_PARSER_FLAGS_OPTIONAL = 0x1,
01115
01116 CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES = 0x2
01117 } cp_parser_flags;
01118
01119
01120
01121 typedef enum cp_parser_declarator_kind
01122 {
01123
01124 CP_PARSER_DECLARATOR_ABSTRACT,
01125
01126 CP_PARSER_DECLARATOR_NAMED,
01127
01128 CP_PARSER_DECLARATOR_EITHER
01129 } cp_parser_declarator_kind;
01130
01131
01132
01133
01134
01135 enum cp_parser_prec
01136 {
01137 PREC_NOT_OPERATOR,
01138 PREC_LOGICAL_OR_EXPRESSION,
01139 PREC_LOGICAL_AND_EXPRESSION,
01140 PREC_INCLUSIVE_OR_EXPRESSION,
01141 PREC_EXCLUSIVE_OR_EXPRESSION,
01142 PREC_AND_EXPRESSION,
01143 PREC_EQUALITY_EXPRESSION,
01144 PREC_RELATIONAL_EXPRESSION,
01145 PREC_SHIFT_EXPRESSION,
01146 PREC_ADDITIVE_EXPRESSION,
01147 PREC_MULTIPLICATIVE_EXPRESSION,
01148 PREC_PM_EXPRESSION,
01149 NUM_PREC_VALUES = PREC_PM_EXPRESSION
01150 };
01151
01152
01153
01154
01155 typedef struct cp_parser_binary_operations_map_node
01156 {
01157
01158 enum cpp_ttype token_type;
01159
01160 enum tree_code tree_type;
01161
01162 enum cp_parser_prec prec;
01163 } cp_parser_binary_operations_map_node;
01164
01165
01166
01167 typedef enum cp_parser_status_kind
01168 {
01169
01170 CP_PARSER_STATUS_KIND_NO_ERROR,
01171
01172 CP_PARSER_STATUS_KIND_ERROR,
01173
01174
01175 CP_PARSER_STATUS_KIND_COMMITTED
01176 } cp_parser_status_kind;
01177
01178 typedef struct cp_parser_expression_stack_entry
01179 {
01180 tree lhs;
01181 enum tree_code tree_type;
01182 int prec;
01183 } cp_parser_expression_stack_entry;
01184
01185
01186
01187
01188 typedef struct cp_parser_expression_stack_entry
01189 cp_parser_expression_stack[NUM_PREC_VALUES];
01190
01191
01192 typedef struct cp_parser_context GTY (())
01193 {
01194
01195
01196 enum cp_parser_status_kind status;
01197
01198
01199
01200
01201 tree object_type;
01202
01203
01204 struct cp_parser_context *next;
01205 } cp_parser_context;
01206
01207
01208
01209
01210
01211 static cp_parser_context *cp_parser_context_new
01212 (cp_parser_context *);
01213
01214
01215
01216 static GTY((deletable)) cp_parser_context* cp_parser_context_free_list;
01217
01218
01219
01220
01221
01222 static const cp_parser_binary_operations_map_node binops[] = {
01223 { CPP_DEREF_STAR, MEMBER_REF, PREC_PM_EXPRESSION },
01224 { CPP_DOT_STAR, DOTSTAR_EXPR, PREC_PM_EXPRESSION },
01225
01226 { CPP_MULT, MULT_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
01227 { CPP_DIV, TRUNC_DIV_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
01228 { CPP_MOD, TRUNC_MOD_EXPR, PREC_MULTIPLICATIVE_EXPRESSION },
01229
01230 { CPP_PLUS, PLUS_EXPR, PREC_ADDITIVE_EXPRESSION },
01231 { CPP_MINUS, MINUS_EXPR, PREC_ADDITIVE_EXPRESSION },
01232
01233 { CPP_LSHIFT, LSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
01234 { CPP_RSHIFT, RSHIFT_EXPR, PREC_SHIFT_EXPRESSION },
01235
01236 { CPP_LESS, LT_EXPR, PREC_RELATIONAL_EXPRESSION },
01237 { CPP_GREATER, GT_EXPR, PREC_RELATIONAL_EXPRESSION },
01238 { CPP_LESS_EQ, LE_EXPR, PREC_RELATIONAL_EXPRESSION },
01239 { CPP_GREATER_EQ, GE_EXPR, PREC_RELATIONAL_EXPRESSION },
01240
01241 { CPP_EQ_EQ, EQ_EXPR, PREC_EQUALITY_EXPRESSION },
01242 { CPP_NOT_EQ, NE_EXPR, PREC_EQUALITY_EXPRESSION },
01243
01244 { CPP_AND, BIT_AND_EXPR, PREC_AND_EXPRESSION },
01245
01246 { CPP_XOR, BIT_XOR_EXPR, PREC_EXCLUSIVE_OR_EXPRESSION },
01247
01248 { CPP_OR, BIT_IOR_EXPR, PREC_INCLUSIVE_OR_EXPRESSION },
01249
01250 { CPP_AND_AND, TRUTH_ANDIF_EXPR, PREC_LOGICAL_AND_EXPRESSION },
01251
01252 { CPP_OR_OR, TRUTH_ORIF_EXPR, PREC_LOGICAL_OR_EXPRESSION }
01253 };
01254
01255
01256
01257
01258 static cp_parser_binary_operations_map_node binops_by_token[N_CP_TTYPES];
01259
01260
01261
01262
01263
01264
01265 static cp_parser_context *
01266 cp_parser_context_new (cp_parser_context* next)
01267 {
01268 cp_parser_context *context;
01269
01270
01271 if (cp_parser_context_free_list != NULL)
01272 {
01273
01274 context = cp_parser_context_free_list;
01275 cp_parser_context_free_list = context->next;
01276 memset (context, 0, sizeof (*context));
01277 }
01278 else
01279 context = GGC_CNEW (cp_parser_context);
01280
01281
01282 context->status = CP_PARSER_STATUS_KIND_NO_ERROR;
01283
01284
01285 if (next)
01286 {
01287
01288
01289 context->object_type = next->object_type;
01290
01291 context->next = next;
01292 }
01293
01294 return context;
01295 }
01296
01297
01298
01299 typedef struct cp_parser GTY(())
01300 {
01301
01302 cp_lexer *lexer;
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317 tree scope;
01318
01319
01320
01321
01322
01323
01324 tree object_scope;
01325 tree qualifying_scope;
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336 cp_parser_context *context;
01337
01338
01339
01340 bool allow_gnu_extensions_p;
01341
01342
01343
01344
01345 bool greater_than_is_operator_p;
01346
01347
01348
01349
01350 bool default_arg_ok_p;
01351
01352
01353
01354 bool integral_constant_expression_p;
01355
01356
01357
01358
01359
01360 bool allow_non_integral_constant_expression_p;
01361
01362
01363
01364 bool non_integral_constant_expression_p;
01365
01366
01367
01368 bool local_variables_forbidden_p;
01369
01370
01371
01372
01373 bool in_unbraced_linkage_specification_p;
01374
01375
01376
01377 bool in_declarator_p;
01378
01379
01380 bool in_template_argument_list_p;
01381
01382
01383
01384
01385
01386
01387 #define IN_SWITCH_STMT 1
01388 #define IN_ITERATION_STMT 2
01389 #define IN_OMP_BLOCK 4
01390 #define IN_OMP_FOR 8
01391 unsigned char in_statement;
01392
01393
01394
01395
01396
01397 bool in_switch_statement_p;
01398
01399
01400
01401
01402 bool in_type_id_in_expr_p;
01403
01404
01405
01406 bool implicit_extern_c;
01407
01408
01409
01410 bool translate_strings_p;
01411
01412
01413
01414 bool in_function_body;
01415
01416
01417
01418
01419 const char *type_definition_forbidden_message;
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435 tree unparsed_functions_queues;
01436
01437
01438
01439 unsigned num_classes_being_defined;
01440
01441
01442
01443 unsigned num_template_parameter_lists;
01444 } cp_parser;
01445
01446
01447
01448
01449
01450 static cp_parser *cp_parser_new
01451 (void);
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467 static tree cp_parser_identifier
01468 (cp_parser *);
01469 static tree cp_parser_string_literal
01470 (cp_parser *, bool, bool);
01471
01472
01473
01474 static bool cp_parser_translation_unit
01475 (cp_parser *);
01476
01477
01478
01479 static tree cp_parser_primary_expression
01480 (cp_parser *, bool, bool, bool, cp_id_kind *);
01481 static tree cp_parser_id_expression
01482 (cp_parser *, bool, bool, bool *, bool, bool);
01483 static tree cp_parser_unqualified_id
01484 (cp_parser *, bool, bool, bool, bool);
01485 static tree cp_parser_nested_name_specifier_opt
01486 (cp_parser *, bool, bool, bool, bool);
01487 static tree cp_parser_nested_name_specifier
01488 (cp_parser *, bool, bool, bool, bool);
01489 static tree cp_parser_class_or_namespace_name
01490 (cp_parser *, bool, bool, bool, bool, bool);
01491 static tree cp_parser_postfix_expression
01492 (cp_parser *, bool, bool);
01493 static tree cp_parser_postfix_open_square_expression
01494 (cp_parser *, tree, bool);
01495 static tree cp_parser_postfix_dot_deref_expression
01496 (cp_parser *, enum cpp_ttype, tree, bool, cp_id_kind *);
01497 static tree cp_parser_parenthesized_expression_list
01498 (cp_parser *, bool, bool, bool *);
01499 static void cp_parser_pseudo_destructor_name
01500 (cp_parser *, tree *, tree *);
01501 static tree cp_parser_unary_expression
01502 (cp_parser *, bool, bool);
01503 static enum tree_code cp_parser_unary_operator
01504 (cp_token *);
01505 static tree cp_parser_new_expression
01506 (cp_parser *);
01507 static tree cp_parser_new_placement
01508 (cp_parser *);
01509 static tree cp_parser_new_type_id
01510 (cp_parser *, tree *);
01511 static cp_declarator *cp_parser_new_declarator_opt
01512 (cp_parser *);
01513 static cp_declarator *cp_parser_direct_new_declarator
01514 (cp_parser *);
01515 static tree cp_parser_new_initializer
01516 (cp_parser *);
01517 static tree cp_parser_delete_expression
01518 (cp_parser *);
01519 static tree cp_parser_cast_expression
01520 (cp_parser *, bool, bool);
01521 static tree cp_parser_binary_expression
01522 (cp_parser *, bool);
01523 static tree cp_parser_question_colon_clause
01524 (cp_parser *, tree);
01525 static tree cp_parser_assignment_expression
01526 (cp_parser *, bool);
01527 static enum tree_code cp_parser_assignment_operator_opt
01528 (cp_parser *);
01529 static tree cp_parser_expression
01530 (cp_parser *, bool);
01531 static tree cp_parser_constant_expression
01532 (cp_parser *, bool, bool *);
01533 static tree cp_parser_builtin_offsetof
01534 (cp_parser *);
01535
01536
01537
01538 static void cp_parser_statement
01539 (cp_parser *, tree, bool);
01540 static void cp_parser_label_for_labeled_statement
01541 (cp_parser *);
01542 static tree cp_parser_expression_statement
01543 (cp_parser *, tree);
01544 static tree cp_parser_compound_statement
01545 (cp_parser *, tree, bool);
01546 static void cp_parser_statement_seq_opt
01547 (cp_parser *, tree);
01548 static tree cp_parser_selection_statement
01549 (cp_parser *);
01550 static tree cp_parser_condition
01551 (cp_parser *);
01552 static tree cp_parser_iteration_statement
01553 (cp_parser *);
01554 static void cp_parser_for_init_statement
01555 (cp_parser *);
01556 static tree cp_parser_jump_statement
01557 (cp_parser *);
01558 static void cp_parser_declaration_statement
01559 (cp_parser *);
01560
01561 static tree cp_parser_implicitly_scoped_statement
01562 (cp_parser *);
01563 static void cp_parser_already_scoped_statement
01564 (cp_parser *);
01565
01566
01567
01568 static void cp_parser_declaration_seq_opt
01569 (cp_parser *);
01570 static void cp_parser_declaration
01571 (cp_parser *);
01572 static void cp_parser_block_declaration
01573 (cp_parser *, bool);
01574 static void cp_parser_simple_declaration
01575 (cp_parser *, bool);
01576 static void cp_parser_decl_specifier_seq
01577 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, int *);
01578 static tree cp_parser_storage_class_specifier_opt
01579 (cp_parser *);
01580 static tree cp_parser_function_specifier_opt
01581 (cp_parser *, cp_decl_specifier_seq *);
01582 static tree cp_parser_type_specifier
01583 (cp_parser *, cp_parser_flags, cp_decl_specifier_seq *, bool,
01584 int *, bool *);
01585 static tree cp_parser_simple_type_specifier
01586 (cp_parser *, cp_decl_specifier_seq *, cp_parser_flags);
01587 static tree cp_parser_type_name
01588 (cp_parser *);
01589 static tree cp_parser_elaborated_type_specifier
01590 (cp_parser *, bool, bool);
01591 static tree cp_parser_enum_specifier
01592 (cp_parser *);
01593 static void cp_parser_enumerator_list
01594 (cp_parser *, tree);
01595 static void cp_parser_enumerator_definition
01596 (cp_parser *, tree);
01597 static tree cp_parser_namespace_name
01598 (cp_parser *);
01599 static void cp_parser_namespace_definition
01600 (cp_parser *);
01601 static void cp_parser_namespace_body
01602 (cp_parser *);
01603 static tree cp_parser_qualified_namespace_specifier
01604 (cp_parser *);
01605 static void cp_parser_namespace_alias_definition
01606 (cp_parser *);
01607 static bool cp_parser_using_declaration
01608 (cp_parser *, bool);
01609 static void cp_parser_using_directive
01610 (cp_parser *);
01611 static void cp_parser_asm_definition
01612 (cp_parser *);
01613 static void cp_parser_linkage_specification
01614 (cp_parser *);
01615
01616
01617
01618 static tree cp_parser_init_declarator
01619 (cp_parser *, cp_decl_specifier_seq *, VEC (deferred_access_check,gc)*, bool, bool, int, bool *);
01620 static cp_declarator *cp_parser_declarator
01621 (cp_parser *, cp_parser_declarator_kind, int *, bool *, bool);
01622 static cp_declarator *cp_parser_direct_declarator
01623 (cp_parser *, cp_parser_declarator_kind, int *, bool);
01624 static enum tree_code cp_parser_ptr_operator
01625 (cp_parser *, tree *, cp_cv_quals *);
01626 static cp_cv_quals cp_parser_cv_qualifier_seq_opt
01627 (cp_parser *);
01628 static tree cp_parser_declarator_id
01629 (cp_parser *, bool);
01630 static tree cp_parser_type_id
01631 (cp_parser *);
01632 static void cp_parser_type_specifier_seq
01633 (cp_parser *, bool, cp_decl_specifier_seq *);
01634 static cp_parameter_declarator *cp_parser_parameter_declaration_clause
01635 (cp_parser *);
01636 static cp_parameter_declarator *cp_parser_parameter_declaration_list
01637 (cp_parser *, bool *);
01638 static cp_parameter_declarator *cp_parser_parameter_declaration
01639 (cp_parser *, bool, bool *);
01640 static void cp_parser_function_body
01641 (cp_parser *);
01642 static tree cp_parser_initializer
01643 (cp_parser *, bool *, bool *);
01644 static tree cp_parser_initializer_clause
01645 (cp_parser *, bool *);
01646 static VEC(constructor_elt,gc) *cp_parser_initializer_list
01647 (cp_parser *, bool *);
01648
01649 static bool cp_parser_ctor_initializer_opt_and_function_body
01650 (cp_parser *);
01651
01652
01653
01654 static tree cp_parser_class_name
01655 (cp_parser *, bool, bool, enum tag_types, bool, bool, bool);
01656 static tree cp_parser_class_specifier
01657 (cp_parser *);
01658 static tree cp_parser_class_head
01659 (cp_parser *, bool *, tree *, tree *);
01660 static enum tag_types cp_parser_class_key
01661 (cp_parser *);
01662 static void cp_parser_member_specification_opt
01663 (cp_parser *);
01664 static void cp_parser_member_declaration
01665 (cp_parser *);
01666 static tree cp_parser_pure_specifier
01667 (cp_parser *);
01668 static tree cp_parser_constant_initializer
01669 (cp_parser *);
01670
01671
01672
01673 static tree cp_parser_base_clause
01674 (cp_parser *);
01675 static tree cp_parser_base_specifier
01676 (cp_parser *);
01677
01678
01679
01680 static tree cp_parser_conversion_function_id
01681 (cp_parser *);
01682 static tree cp_parser_conversion_type_id
01683 (cp_parser *);
01684 static cp_declarator *cp_parser_conversion_declarator_opt
01685 (cp_parser *);
01686 static bool cp_parser_ctor_initializer_opt
01687 (cp_parser *);
01688 static void cp_parser_mem_initializer_list
01689 (cp_parser *);
01690 static tree cp_parser_mem_initializer
01691 (cp_parser *);
01692 static tree cp_parser_mem_initializer_id
01693 (cp_parser *);
01694
01695
01696
01697 static tree cp_parser_operator_function_id
01698 (cp_parser *);
01699 static tree cp_parser_operator
01700 (cp_parser *);
01701
01702
01703
01704 static void cp_parser_template_declaration
01705 (cp_parser *, bool);
01706 static tree cp_parser_template_parameter_list
01707 (cp_parser *);
01708 static tree cp_parser_template_parameter
01709 (cp_parser *, bool *);
01710 static tree cp_parser_type_parameter
01711 (cp_parser *);
01712 static tree cp_parser_template_id
01713 (cp_parser *, bool, bool, bool);
01714 static tree cp_parser_template_name
01715 (cp_parser *, bool, bool, bool, bool *);
01716 static tree cp_parser_template_argument_list
01717 (cp_parser *);
01718 static tree cp_parser_template_argument
01719 (cp_parser *);
01720 static void cp_parser_explicit_instantiation
01721 (cp_parser *);
01722 static void cp_parser_explicit_specialization
01723 (cp_parser *);
01724
01725
01726
01727 static tree cp_parser_try_block
01728 (cp_parser *);
01729 static bool cp_parser_function_try_block
01730 (cp_parser *);
01731 static void cp_parser_handler_seq
01732 (cp_parser *);
01733 static void cp_parser_handler
01734 (cp_parser *);
01735 static tree cp_parser_exception_declaration
01736 (cp_parser *);
01737 static tree cp_parser_throw_expression
01738 (cp_parser *);
01739 static tree cp_parser_exception_specification_opt
01740 (cp_parser *);
01741 static tree cp_parser_type_id_list
01742 (cp_parser *);
01743
01744
01745
01746 static tree cp_parser_asm_specification_opt
01747 (cp_parser *);
01748 static tree cp_parser_asm_operand_list
01749 (cp_parser *);
01750 static tree cp_parser_asm_clobber_list
01751 (cp_parser *);
01752 static tree cp_parser_attributes_opt
01753 (cp_parser *);
01754 static tree cp_parser_attribute_list
01755 (cp_parser *);
01756 static bool cp_parser_extension_opt
01757 (cp_parser *, int *);
01758 static void cp_parser_label_declaration
01759 (cp_parser *);
01760
01761 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
01762 static bool cp_parser_pragma
01763 (cp_parser *, enum pragma_context);
01764
01765
01766
01767 static tree cp_parser_objc_message_receiver
01768 (cp_parser *);
01769 static tree cp_parser_objc_message_args
01770 (cp_parser *);
01771 static tree cp_parser_objc_message_expression
01772 (cp_parser *);
01773 static tree cp_parser_objc_encode_expression
01774 (cp_parser *);
01775 static tree cp_parser_objc_defs_expression
01776 (cp_parser *);
01777 static tree cp_parser_objc_protocol_expression
01778 (cp_parser *);
01779 static tree cp_parser_objc_selector_expression
01780 (cp_parser *);
01781 static tree cp_parser_objc_expression
01782 (cp_parser *);
01783 static bool cp_parser_objc_selector_p
01784 (enum cpp_ttype);
01785 static tree cp_parser_objc_selector
01786 (cp_parser *);
01787 static tree cp_parser_objc_protocol_refs_opt
01788 (cp_parser *);
01789 static void cp_parser_objc_declaration
01790 (cp_parser *);
01791 static tree cp_parser_objc_statement
01792 (cp_parser *);
01793
01794
01795
01796 static tree cp_parser_lookup_name
01797 (cp_parser *, tree, enum tag_types, bool, bool, bool, tree *);
01798 static tree cp_parser_lookup_name_simple
01799 (cp_parser *, tree);
01800 static tree cp_parser_maybe_treat_template_as_class
01801 (tree, bool);
01802 static bool cp_parser_check_declarator_template_parameters
01803 (cp_parser *, cp_declarator *);
01804 static bool cp_parser_check_template_parameters
01805 (cp_parser *, unsigned);
01806 static tree cp_parser_simple_cast_expression
01807 (cp_parser *);
01808 static tree cp_parser_global_scope_opt
01809 (cp_parser *, bool);
01810 static bool cp_parser_constructor_declarator_p
01811 (cp_parser *, bool);
01812 static tree cp_parser_function_definition_from_specifiers_and_declarator
01813 (cp_parser *, cp_decl_specifier_seq *, tree, const cp_declarator *);
01814 static tree cp_parser_function_definition_after_declarator
01815 (cp_parser *, bool);
01816 static void cp_parser_template_declaration_after_export
01817 (cp_parser *, bool);
01818 static void cp_parser_perform_template_parameter_access_checks
01819 (VEC (deferred_access_check,gc)*);
01820 static tree cp_parser_single_declaration
01821 (cp_parser *, VEC (deferred_access_check,gc)*, bool, bool *);
01822 static tree cp_parser_functional_cast
01823 (cp_parser *, tree);
01824 static tree cp_parser_save_member_function_body
01825 (cp_parser *, cp_decl_specifier_seq *, cp_declarator *, tree);
01826 static tree cp_parser_enclosed_template_argument_list
01827 (cp_parser *);
01828 static void cp_parser_save_default_args
01829 (cp_parser *, tree);
01830 static void cp_parser_late_parsing_for_member
01831 (cp_parser *, tree);
01832 static void cp_parser_late_parsing_default_args
01833 (cp_parser *, tree);
01834 static tree cp_parser_sizeof_operand
01835 (cp_parser *, enum rid);
01836 static bool cp_parser_declares_only_class_p
01837 (cp_parser *);
01838 static void cp_parser_set_storage_class
01839 (cp_parser *, cp_decl_specifier_seq *, enum rid);
01840 static void cp_parser_set_decl_spec_type
01841 (cp_decl_specifier_seq *, tree, bool);
01842 static bool cp_parser_friend_p
01843 (const cp_decl_specifier_seq *);
01844 static cp_token *cp_parser_require
01845 (cp_parser *, enum cpp_ttype, const char *);
01846 static cp_token *cp_parser_require_keyword
01847 (cp_parser *, enum rid, const char *);
01848 static bool cp_parser_token_starts_function_definition_p
01849 (cp_token *);
01850 static bool cp_parser_next_token_starts_class_definition_p
01851 (cp_parser *);
01852 static bool cp_parser_next_token_ends_template_argument_p
01853 (cp_parser *);
01854 static bool cp_parser_nth_token_starts_template_argument_list_p
01855 (cp_parser *, size_t);
01856 static enum tag_types cp_parser_token_is_class_key
01857 (cp_token *);
01858 static void cp_parser_check_class_key
01859 (enum tag_types, tree type);
01860 static void cp_parser_check_access_in_redeclaration
01861 (tree type);
01862 static bool cp_parser_optional_template_keyword
01863 (cp_parser *);
01864 static void cp_parser_pre_parsed_nested_name_specifier
01865 (cp_parser *);
01866 static void cp_parser_cache_group
01867 (cp_parser *, enum cpp_ttype, unsigned);
01868 static void cp_parser_parse_tentatively
01869 (cp_parser *);
01870 static void cp_parser_commit_to_tentative_parse
01871 (cp_parser *);
01872 static void cp_parser_abort_tentative_parse
01873 (cp_parser *);
01874 static bool cp_parser_parse_definitely
01875 (cp_parser *);
01876 static inline bool cp_parser_parsing_tentatively
01877 (cp_parser *);
01878 static bool cp_parser_uncommitted_to_tentative_parse_p
01879 (cp_parser *);
01880 static void cp_parser_error
01881 (cp_parser *, const char *);
01882 static void cp_parser_name_lookup_error
01883 (cp_parser *, tree, tree, const char *);
01884 static bool cp_parser_simulate_error
01885 (cp_parser *);
01886 static bool cp_parser_check_type_definition
01887 (cp_parser *);
01888 static void cp_parser_check_for_definition_in_return_type
01889 (cp_declarator *, tree);
01890 static void cp_parser_check_for_invalid_template_id
01891 (cp_parser *, tree);
01892 static bool cp_parser_non_integral_constant_expression
01893 (cp_parser *, const char *);
01894 static void cp_parser_diagnose_invalid_type_name
01895 (cp_parser *, tree, tree);
01896 static bool cp_parser_parse_and_diagnose_invalid_type_name
01897 (cp_parser *);
01898 static int cp_parser_skip_to_closing_parenthesis
01899 (cp_parser *, bool, bool, bool);
01900 static void cp_parser_skip_to_end_of_statement
01901 (cp_parser *);
01902 static void cp_parser_consume_semicolon_at_end_of_statement
01903 (cp_parser *);
01904 static void cp_parser_skip_to_end_of_block_or_statement
01905 (cp_parser *);
01906 static void cp_parser_skip_to_closing_brace
01907 (cp_parser *);
01908 static void cp_parser_skip_to_end_of_template_parameter_list
01909 (cp_parser *);
01910 static void cp_parser_skip_to_pragma_eol
01911 (cp_parser*, cp_token *);
01912 static bool cp_parser_error_occurred
01913 (cp_parser *);
01914 static bool cp_parser_allow_gnu_extensions_p
01915 (cp_parser *);
01916 static bool cp_parser_is_string_literal
01917 (cp_token *);
01918 static bool cp_parser_is_keyword
01919 (cp_token *, enum rid);
01920 static tree cp_parser_make_typename_type
01921 (cp_parser *, tree, tree);
01922
01923
01924
01925 static inline bool
01926 cp_parser_parsing_tentatively (cp_parser* parser)
01927 {
01928 return parser->context->next != NULL;
01929 }
01930
01931
01932
01933 static bool
01934 cp_parser_is_string_literal (cp_token* token)
01935 {
01936 return (token->type == CPP_STRING || token->type == CPP_WSTRING);
01937 }
01938
01939
01940
01941 static bool
01942 cp_parser_is_keyword (cp_token* token, enum rid keyword)
01943 {
01944 return token->keyword == keyword;
01945 }
01946
01947
01948
01949
01950
01951
01952
01953 static void
01954 cp_parser_error (cp_parser* parser, const char* message)
01955 {
01956 if (!cp_parser_simulate_error (parser))
01957 {
01958 cp_token *token = cp_lexer_peek_token (parser->lexer);
01959
01960
01961 cp_lexer_set_source_position_from_token (token);
01962
01963 if (token->type == CPP_PRAGMA)
01964 {
01965 error ("%<#pragma%> is not allowed here");
01966 cp_parser_skip_to_pragma_eol (parser, token);
01967 return;
01968 }
01969
01970 c_parse_error (message,
01971
01972
01973
01974 (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
01975 token->u.value);
01976 }
01977 }
01978
01979
01980
01981
01982
01983
01984 static void
01985 cp_parser_name_lookup_error (cp_parser* parser,
01986 tree name,
01987 tree decl,
01988 const char* desired)
01989 {
01990
01991
01992 if (decl == error_mark_node)
01993 {
01994 if (parser->scope && parser->scope != global_namespace)
01995 error ("%<%D::%D%> has not been declared",
01996 parser->scope, name);
01997 else if (parser->scope == global_namespace)
01998 error ("%<::%D%> has not been declared", name);
01999 else if (parser->object_scope
02000 && !CLASS_TYPE_P (parser->object_scope))
02001 error ("request for member %qD in non-class type %qT",
02002 name, parser->object_scope);
02003 else if (parser->object_scope)
02004 error ("%<%T::%D%> has not been declared",
02005 parser->object_scope, name);
02006 else
02007 error ("%qD has not been declared", name);
02008 }
02009 else if (parser->scope && parser->scope != global_namespace)
02010 error ("%<%D::%D%> %s", parser->scope, name, desired);
02011 else if (parser->scope == global_namespace)
02012 error ("%<::%D%> %s", name, desired);
02013 else
02014 error ("%qD %s", name, desired);
02015 }
02016
02017
02018
02019
02020
02021 static bool
02022 cp_parser_simulate_error (cp_parser* parser)
02023 {
02024 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
02025 {
02026 parser->context->status = CP_PARSER_STATUS_KIND_ERROR;
02027 return true;
02028 }
02029 return false;
02030 }
02031
02032
02033
02034 static void
02035 cp_parser_check_decl_spec (cp_decl_specifier_seq *decl_specs)
02036 {
02037 cp_decl_spec ds;
02038
02039 for (ds = ds_first; ds != ds_last; ++ds)
02040 {
02041 unsigned count = decl_specs->specs[(int)ds];
02042 if (count < 2)
02043 continue;
02044
02045 if (ds == ds_long)
02046 {
02047 if (count > 2)
02048 error ("%<long long long%> is too long for GCC");
02049 else if (pedantic && !in_system_header && warn_long_long)
02050 pedwarn ("ISO C++ does not support %<long long%>");
02051 }
02052 else if (count > 1)
02053 {
02054 static const char *const decl_spec_names[] = {
02055 "signed",
02056 "unsigned",
02057 "short",
02058 "long",
02059 "const",
02060 "volatile",
02061 "restrict",
02062 "inline",
02063 "virtual",
02064 "explicit",
02065 "friend",
02066 "typedef",
02067 "__complex",
02068 "__thread"
02069 };
02070 error ("duplicate %qs", decl_spec_names[(int)ds]);
02071 }
02072 }
02073 }
02074
02075
02076
02077
02078
02079 static bool
02080 cp_parser_check_type_definition (cp_parser* parser)
02081 {
02082
02083 if (parser->type_definition_forbidden_message)
02084 {
02085
02086
02087 error ("%s", parser->type_definition_forbidden_message);
02088 return false;
02089 }
02090 return true;
02091 }
02092
02093
02094
02095
02096
02097
02098 static void
02099 cp_parser_check_for_definition_in_return_type (cp_declarator *declarator,
02100 tree type)
02101 {
02102
02103
02104
02105 while (declarator
02106 && (declarator->kind == cdk_pointer
02107 || declarator->kind == cdk_reference
02108 || declarator->kind == cdk_ptrmem))
02109 declarator = declarator->declarator;
02110 if (declarator
02111 && declarator->kind == cdk_function)
02112 {
02113 error ("new types may not be defined in a return type");
02114 inform ("(perhaps a semicolon is missing after the definition of %qT)",
02115 type);
02116 }
02117 }
02118
02119
02120
02121
02122
02123
02124 static void
02125 cp_parser_check_for_invalid_template_id (cp_parser* parser,
02126 tree type)
02127 {
02128 cp_token_position start = 0;
02129
02130 if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
02131 {
02132 if (TYPE_P (type))
02133 error ("%qT is not a template", type);
02134 else if (TREE_CODE (type) == IDENTIFIER_NODE)
02135 error ("%qE is not a template", type);
02136 else
02137 error ("invalid template-id");
02138
02139 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
02140 start = cp_lexer_token_position (parser->lexer, true);
02141
02142 cp_lexer_consume_token (parser->lexer);
02143
02144 cp_parser_enclosed_template_argument_list (parser);
02145
02146
02147 if (start)
02148 cp_lexer_purge_tokens_after (parser->lexer, start);
02149 }
02150 }
02151
02152
02153
02154
02155
02156
02157 static bool
02158 cp_parser_non_integral_constant_expression (cp_parser *parser,
02159 const char *thing)
02160 {
02161 parser->non_integral_constant_expression_p = true;
02162 if (parser->integral_constant_expression_p)
02163 {
02164 if (!parser->allow_non_integral_constant_expression_p)
02165 {
02166 error ("%s cannot appear in a constant-expression", thing);
02167 return true;
02168 }
02169 }
02170 return false;
02171 }
02172
02173
02174
02175
02176
02177
02178
02179 static void
02180 cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree scope, tree id)
02181 {
02182 tree decl, old_scope;
02183
02184 old_scope = parser->scope;
02185 parser->scope = scope;
02186 decl = cp_parser_lookup_name_simple (parser, id);
02187 parser->scope = old_scope;
02188
02189
02190 if (TREE_CODE (decl) == TEMPLATE_DECL)
02191 error ("invalid use of template-name %qE without an argument list", decl);
02192 else if (TREE_CODE (id) == BIT_NOT_EXPR)
02193 error ("invalid use of destructor %qD as a type", id);
02194 else if (TREE_CODE (decl) == TYPE_DECL)
02195
02196 error ("invalid combination of multiple type-specifiers");
02197 else if (!parser->scope)
02198 {
02199
02200 error ("%qE does not name a type", id);
02201
02202
02203
02204
02205
02206
02207
02208 if (processing_template_decl && current_class_type
02209 && TYPE_BINFO (current_class_type))
02210 {
02211 tree b;
02212
02213 for (b = TREE_CHAIN (TYPE_BINFO (current_class_type));
02214 b;
02215 b = TREE_CHAIN (b))
02216 {
02217 tree base_type = BINFO_TYPE (b);
02218 if (CLASS_TYPE_P (base_type)
02219 && dependent_type_p (base_type))
02220 {
02221 tree field;
02222
02223
02224
02225 base_type = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (base_type);
02226 for (field = TYPE_FIELDS (base_type);
02227 field;
02228 field = TREE_CHAIN (field))
02229 if (TREE_CODE (field) == TYPE_DECL
02230 && DECL_NAME (field) == id)
02231 {
02232 inform ("(perhaps %<typename %T::%E%> was intended)",
02233 BINFO_TYPE (b), id);
02234 break;
02235 }
02236 if (field)
02237 break;
02238 }
02239 }
02240 }
02241 }
02242
02243
02244 else if (parser->scope != error_mark_node)
02245 {
02246 if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
02247 error ("%qE in namespace %qE does not name a type",
02248 id, parser->scope);
02249 else if (TYPE_P (parser->scope))
02250 error ("%qE in class %qT does not name a type", id, parser->scope);
02251 else
02252 gcc_unreachable ();
02253 }
02254 cp_parser_commit_to_tentative_parse (parser);
02255 }
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267 static bool
02268 cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser)
02269 {
02270 tree id;
02271
02272 cp_parser_parse_tentatively (parser);
02273 id = cp_parser_id_expression (parser,
02274 false,
02275 true,
02276 NULL,
02277 true,
02278 false);
02279
02280
02281
02282 if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME)
02283 || (parser->scope && TYPE_P (parser->scope)
02284 && dependent_type_p (parser->scope))
02285 || TREE_CODE (id) == TYPE_DECL)
02286 {
02287 cp_parser_abort_tentative_parse (parser);
02288 return false;
02289 }
02290 if (!cp_parser_parse_definitely (parser))
02291 return false;
02292
02293
02294 cp_parser_diagnose_invalid_type_name (parser, parser->scope, id);
02295
02296
02297 cp_parser_skip_to_end_of_block_or_statement (parser);
02298 return true;
02299 }
02300
02301
02302
02303
02304
02305
02306 static int
02307 cp_parser_skip_to_closing_parenthesis (cp_parser *parser,
02308 bool recovering,
02309 bool or_comma,
02310 bool consume_paren)
02311 {
02312 unsigned paren_depth = 0;
02313 unsigned brace_depth = 0;
02314
02315 if (recovering && !or_comma
02316 && cp_parser_uncommitted_to_tentative_parse_p (parser))
02317 return 0;
02318
02319 while (true)
02320 {
02321 cp_token * token = cp_lexer_peek_token (parser->lexer);
02322
02323 switch (token->type)
02324 {
02325 case CPP_EOF:
02326 case CPP_PRAGMA_EOL:
02327
02328 return 0;
02329
02330 case CPP_SEMICOLON:
02331
02332 if (!brace_depth)
02333 return 0;
02334 break;
02335
02336 case CPP_OPEN_BRACE:
02337 ++brace_depth;
02338 break;
02339 case CPP_CLOSE_BRACE:
02340 if (!brace_depth--)
02341 return 0;
02342 break;
02343
02344 case CPP_COMMA:
02345 if (recovering && or_comma && !brace_depth && !paren_depth)
02346 return -1;
02347 break;
02348
02349 case CPP_OPEN_PAREN:
02350 if (!brace_depth)
02351 ++paren_depth;
02352 break;
02353
02354 case CPP_CLOSE_PAREN:
02355 if (!brace_depth && !paren_depth--)
02356 {
02357 if (consume_paren)
02358 cp_lexer_consume_token (parser->lexer);
02359 return 1;
02360 }
02361 break;
02362
02363 default:
02364 break;
02365 }
02366
02367
02368 cp_lexer_consume_token (parser->lexer);
02369 }
02370 }
02371
02372
02373
02374
02375
02376 static void
02377 cp_parser_skip_to_end_of_statement (cp_parser* parser)
02378 {
02379 unsigned nesting_depth = 0;
02380
02381 while (true)
02382 {
02383 cp_token *token = cp_lexer_peek_token (parser->lexer);
02384
02385 switch (token->type)
02386 {
02387 case CPP_EOF:
02388 case CPP_PRAGMA_EOL:
02389
02390 return;
02391
02392 case CPP_SEMICOLON:
02393
02394
02395 if (!nesting_depth)
02396 return;
02397 break;
02398
02399 case CPP_CLOSE_BRACE:
02400
02401
02402
02403
02404
02405
02406
02407 if (nesting_depth == 0)
02408 return;
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420 if (--nesting_depth == 0)
02421 {
02422 cp_lexer_consume_token (parser->lexer);
02423 return;
02424 }
02425
02426 case CPP_OPEN_BRACE:
02427 ++nesting_depth;
02428 break;
02429
02430 default:
02431 break;
02432 }
02433
02434
02435 cp_lexer_consume_token (parser->lexer);
02436 }
02437 }
02438
02439
02440
02441
02442
02443 static void
02444 cp_parser_consume_semicolon_at_end_of_statement (cp_parser *parser)
02445 {
02446
02447 if (!cp_parser_require (parser, CPP_SEMICOLON, "`;'"))
02448 {
02449
02450
02451 cp_parser_skip_to_end_of_statement (parser);
02452
02453 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
02454 cp_lexer_consume_token (parser->lexer);
02455 }
02456 }
02457
02458
02459
02460
02461 static void
02462 cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
02463 {
02464 int nesting_depth = 0;
02465
02466 while (nesting_depth >= 0)
02467 {
02468 cp_token *token = cp_lexer_peek_token (parser->lexer);
02469
02470 switch (token->type)
02471 {
02472 case CPP_EOF:
02473 case CPP_PRAGMA_EOL:
02474
02475 return;
02476
02477 case CPP_SEMICOLON:
02478
02479 if (!nesting_depth)
02480 nesting_depth = -1;
02481 break;
02482
02483 case CPP_CLOSE_BRACE:
02484
02485
02486 nesting_depth--;
02487 if (!nesting_depth)
02488 nesting_depth = -1;
02489 break;
02490
02491 case CPP_OPEN_BRACE:
02492
02493 nesting_depth++;
02494 break;
02495
02496 default:
02497 break;
02498 }
02499
02500
02501 cp_lexer_consume_token (parser->lexer);
02502 }
02503 }
02504
02505
02506
02507
02508 static void
02509 cp_parser_skip_to_closing_brace (cp_parser *parser)
02510 {
02511 unsigned nesting_depth = 0;
02512
02513 while (true)
02514 {
02515 cp_token *token = cp_lexer_peek_token (parser->lexer);
02516
02517 switch (token->type)
02518 {
02519 case CPP_EOF:
02520 case CPP_PRAGMA_EOL:
02521
02522 return;
02523
02524 case CPP_CLOSE_BRACE:
02525
02526
02527 if (nesting_depth-- == 0)
02528 return;
02529 break;
02530
02531 case CPP_OPEN_BRACE:
02532
02533
02534 ++nesting_depth;
02535 break;
02536
02537 default:
02538 break;
02539 }
02540
02541
02542 cp_lexer_consume_token (parser->lexer);
02543 }
02544 }
02545
02546
02547
02548
02549
02550 static void
02551 cp_parser_skip_to_pragma_eol (cp_parser* parser, cp_token *pragma_tok)
02552 {
02553 cp_token *token;
02554
02555 parser->lexer->in_pragma = false;
02556
02557 do
02558 token = cp_lexer_consume_token (parser->lexer);
02559 while (token->type != CPP_PRAGMA_EOL && token->type != CPP_EOF);
02560
02561
02562 cp_lexer_purge_tokens_after (parser->lexer, pragma_tok);
02563 }
02564
02565
02566
02567
02568 static void
02569 cp_parser_require_pragma_eol (cp_parser *parser, cp_token *pragma_tok)
02570 {
02571 parser->lexer->in_pragma = false;
02572 if (!cp_parser_require (parser, CPP_PRAGMA_EOL, "end of line"))
02573 cp_parser_skip_to_pragma_eol (parser, pragma_tok);
02574 }
02575
02576
02577
02578
02579
02580 static tree
02581 cp_parser_make_typename_type (cp_parser *parser, tree scope, tree id)
02582 {
02583 tree result;
02584 if (TREE_CODE (id) == IDENTIFIER_NODE)
02585 {
02586 result = make_typename_type (scope, id, typename_type,
02587 tf_none);
02588 if (result == error_mark_node)
02589 cp_parser_diagnose_invalid_type_name (parser, scope, id);
02590 return result;
02591 }
02592 return make_typename_type (scope, id, typename_type, tf_error);
02593 }
02594
02595
02596
02597
02598 static cp_parser *
02599 cp_parser_new (void)
02600 {
02601 cp_parser *parser;
02602 cp_lexer *lexer;
02603 unsigned i;
02604
02605
02606
02607 lexer = cp_lexer_new_main ();
02608
02609
02610
02611 for (i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
02612 binops_by_token[binops[i].token_type] = binops[i];
02613
02614 parser = GGC_CNEW (cp_parser);
02615 parser->lexer = lexer;
02616 parser->context = cp_parser_context_new (NULL);
02617
02618
02619 parser->allow_gnu_extensions_p = 1;
02620
02621
02622
02623 parser->greater_than_is_operator_p = true;
02624
02625 parser->default_arg_ok_p = true;
02626
02627
02628 parser->integral_constant_expression_p = false;
02629 parser->allow_non_integral_constant_expression_p = false;
02630 parser->non_integral_constant_expression_p = false;
02631
02632
02633 parser->local_variables_forbidden_p = false;
02634
02635
02636 parser->in_unbraced_linkage_specification_p = false;
02637
02638
02639 parser->in_declarator_p = false;
02640
02641
02642 parser->in_template_argument_list_p = false;
02643
02644
02645 parser->in_statement = 0;
02646
02647
02648 parser->in_switch_statement_p = false;
02649
02650
02651 parser->in_type_id_in_expr_p = false;
02652
02653
02654 parser->implicit_extern_c = false;
02655
02656
02657 parser->translate_strings_p = true;
02658
02659
02660 parser->in_function_body = false;
02661
02662
02663 parser->unparsed_functions_queues = build_tree_list (NULL_TREE, NULL_TREE);
02664
02665
02666 parser->num_classes_being_defined = 0;
02667
02668
02669 parser->num_template_parameter_lists = 0;
02670
02671 return parser;
02672 }
02673
02674
02675
02676
02677
02678 static void
02679 cp_parser_push_lexer_for_tokens (cp_parser *parser, cp_token_cache *cache)
02680 {
02681 cp_lexer *lexer = cp_lexer_new_from_tokens (cache);
02682 lexer->next = parser->lexer;
02683 parser->lexer = lexer;
02684
02685
02686
02687 cp_lexer_set_source_position_from_token (lexer->next_token);
02688 }
02689
02690
02691
02692 static void
02693 cp_parser_pop_lexer (cp_parser *parser)
02694 {
02695 cp_lexer *lexer = parser->lexer;
02696 parser->lexer = lexer->next;
02697 cp_lexer_destroy (lexer);
02698
02699
02700
02701 cp_lexer_set_source_position_from_token (parser->lexer->next_token);
02702 }
02703
02704
02705
02706
02707
02708
02709 static tree
02710 cp_parser_identifier (cp_parser* parser)
02711 {
02712 cp_token *token;
02713
02714
02715 token = cp_parser_require (parser, CPP_NAME, "identifier");
02716
02717 return token ? token->u.value : error_mark_node;
02718 }
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734 static tree
02735 cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
02736 {
02737 tree value;
02738 bool wide = false;
02739 size_t count;
02740 struct obstack str_ob;
02741 cpp_string str, istr, *strs;
02742 cp_token *tok;
02743
02744 tok = cp_lexer_peek_token (parser->lexer);
02745 if (!cp_parser_is_string_literal (tok))
02746 {
02747 cp_parser_error (parser, "expected string-literal");
02748 return error_mark_node;
02749 }
02750
02751
02752
02753 if (!cp_parser_is_string_literal
02754 (cp_lexer_peek_nth_token (parser->lexer, 2)))
02755 {
02756 cp_lexer_consume_token (parser->lexer);
02757
02758 str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value);
02759 str.len = TREE_STRING_LENGTH (tok->u.value);
02760 count = 1;
02761 if (tok->type == CPP_WSTRING)
02762 wide = true;
02763
02764 strs = &str;
02765 }
02766 else
02767 {
02768 gcc_obstack_init (&str_ob);
02769 count = 0;
02770
02771 do
02772 {
02773 cp_lexer_consume_token (parser->lexer);
02774 count++;
02775 str.text = (unsigned char *)TREE_STRING_POINTER (tok->u.value);
02776 str.len = TREE_STRING_LENGTH (tok->u.value);
02777 if (tok->type == CPP_WSTRING)
02778 wide = true;
02779
02780 obstack_grow (&str_ob, &str, sizeof (cpp_string));
02781
02782 tok = cp_lexer_peek_token (parser->lexer);
02783 }
02784 while (cp_parser_is_string_literal (tok));
02785
02786 strs = (cpp_string *) obstack_finish (&str_ob);
02787 }
02788
02789 if (wide && !wide_ok)
02790 {
02791 cp_parser_error (parser, "a wide string is invalid in this context");
02792 wide = false;
02793 }
02794
02795 if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
02796 (parse_in, strs, count, &istr, wide))
02797 {
02798 value = build_string (istr.len, (char *)istr.text);
02799 free ((void *)istr.text);
02800
02801 TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node;
02802 value = fix_string_type (value);
02803 }
02804 else
02805
02806 value = error_mark_node;
02807
02808 if (count > 1)
02809 obstack_free (&str_ob, 0);
02810
02811 return value;
02812 }
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823
02824 static bool
02825 cp_parser_translation_unit (cp_parser* parser)
02826 {
02827
02828
02829 static void *declarator_obstack_base;
02830
02831 bool success;
02832
02833
02834 if (!cp_error_declarator)
02835 {
02836 gcc_obstack_init (&declarator_obstack);
02837
02838 cp_error_declarator = make_declarator (cdk_error);
02839
02840 no_parameters = make_parameter_declarator (NULL, NULL, NULL_TREE);
02841
02842 declarator_obstack_base = obstack_next_free (&declarator_obstack);
02843 }
02844
02845 cp_parser_declaration_seq_opt (parser);
02846
02847
02848 if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
02849 {
02850
02851 cp_lexer_destroy (parser->lexer);
02852 parser->lexer = NULL;
02853
02854
02855
02856 if (parser->implicit_extern_c)
02857 {
02858 pop_lang_context ();
02859 parser->implicit_extern_c = false;
02860 }
02861
02862
02863 finish_translation_unit ();
02864
02865 success = true;
02866 }
02867 else
02868 {
02869 cp_parser_error (parser, "expected declaration");
02870 success = false;
02871 }
02872
02873
02874 gcc_assert (obstack_next_free (&declarator_obstack)
02875 == declarator_obstack_base);
02876
02877
02878 return success;
02879 }
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914 static tree
02915 cp_parser_primary_expression (cp_parser *parser,
02916 bool address_p,
02917 bool cast_p,
02918 bool template_arg_p,
02919 cp_id_kind *idk)
02920 {
02921 cp_token *token;
02922
02923
02924 *idk = CP_ID_KIND_NONE;
02925
02926
02927 token = cp_lexer_peek_token (parser->lexer);
02928 switch (token->type)
02929 {
02930
02931
02932
02933
02934
02935
02936 case CPP_CHAR:
02937 case CPP_WCHAR:
02938 case CPP_NUMBER:
02939 token = cp_lexer_consume_token (parser->lexer);
02940
02941
02942
02943 if (TREE_CODE (token->u.value) == REAL_CST
02944 && parser->integral_constant_expression_p
02945 && pedantic)
02946 {
02947
02948
02949
02950 if (cast_p)
02951 {
02952 cp_token *next_token;
02953
02954 next_token = cp_lexer_peek_token (parser->lexer);
02955 if (
02956
02957 next_token->type != CPP_COMMA
02958
02959 && next_token->type != CPP_CLOSE_BRACE
02960
02961 && next_token->type != CPP_SEMICOLON
02962
02963 && next_token->type != CPP_CLOSE_PAREN
02964
02965 && next_token->type != CPP_CLOSE_SQUARE
02966
02967 && (next_token->type != CPP_GREATER
02968 || parser->greater_than_is_operator_p))
02969 cast_p = false;
02970 }
02971
02972
02973
02974
02975
02976 if (!cast_p)
02977 cp_parser_non_integral_constant_expression
02978 (parser, "floating-point literal");
02979 }
02980 return token->u.value;
02981
02982 case CPP_STRING:
02983 case CPP_WSTRING:
02984
02985
02986
02987 return cp_parser_string_literal (parser,
02988 parser->translate_strings_p,
02989 true);
02990
02991 case CPP_OPEN_PAREN:
02992 {
02993 tree expr;
02994 bool saved_greater_than_is_operator_p;
02995
02996
02997 cp_lexer_consume_token (parser->lexer);
02998
02999
03000 saved_greater_than_is_operator_p
03001 = parser->greater_than_is_operator_p;
03002 parser->greater_than_is_operator_p = true;
03003
03004
03005 if (cp_parser_allow_gnu_extensions_p (parser)
03006 && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
03007 {
03008
03009 if (pedantic)
03010 pedwarn ("ISO C++ forbids braced-groups within expressions");
03011
03012
03013
03014
03015
03016
03017
03018 if (!parser->in_function_body)
03019 error ("statement-expressions are allowed only inside functions");
03020
03021 expr = begin_stmt_expr ();
03022
03023 cp_parser_compound_statement (parser, expr, false);
03024
03025 expr = finish_stmt_expr (expr, false);
03026 }
03027 else
03028 {
03029
03030 expr = cp_parser_expression (parser, cast_p);
03031
03032
03033
03034
03035
03036 finish_parenthesized_expr (expr);
03037 }
03038
03039
03040 parser->greater_than_is_operator_p
03041 = saved_greater_than_is_operator_p;
03042
03043 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
03044 cp_parser_skip_to_end_of_statement (parser);
03045
03046 return expr;
03047 }
03048
03049 case CPP_KEYWORD:
03050 switch (token->keyword)
03051 {
03052
03053 case RID_TRUE:
03054 cp_lexer_consume_token (parser->lexer);
03055 return boolean_true_node;
03056 case RID_FALSE:
03057 cp_lexer_consume_token (parser->lexer);
03058 return boolean_false_node;
03059
03060
03061 case RID_NULL:
03062 cp_lexer_consume_token (parser->lexer);
03063 return null_node;
03064
03065
03066 case RID_THIS:
03067 cp_lexer_consume_token (parser->lexer);
03068 if (parser->local_variables_forbidden_p)
03069 {
03070 error ("%<this%> may not be used in this context");
03071 return error_mark_node;
03072 }
03073
03074 if (cp_parser_non_integral_constant_expression (parser,
03075 "`this'"))
03076 return error_mark_node;
03077 return finish_this_expr ();
03078
03079
03080
03081 case RID_OPERATOR:
03082 goto id_expression;
03083
03084 case RID_FUNCTION_NAME:
03085 case RID_PRETTY_FUNCTION_NAME:
03086 case RID_C99_FUNCTION_NAME:
03087
03088
03089
03090
03091
03092
03093
03094 token = cp_lexer_consume_token (parser->lexer);
03095
03096 return finish_fname (token->u.value);
03097
03098 case RID_VA_ARG:
03099 {
03100 tree expression;
03101 tree type;
03102
03103
03104
03105 cp_lexer_consume_token (parser->lexer);
03106
03107 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
03108
03109 expression = cp_parser_assignment_expression (parser,
03110 false);
03111
03112 cp_parser_require (parser, CPP_COMMA, "`,'");
03113
03114 type = cp_parser_type_id (parser);
03115
03116 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
03117
03118
03119 if (cp_parser_non_integral_constant_expression (parser,
03120 "`va_arg'"))
03121 return error_mark_node;
03122 return build_x_va_arg (expression, type);
03123 }
03124
03125 case RID_OFFSETOF:
03126 return cp_parser_builtin_offsetof (parser);
03127
03128
03129 case RID_AT_ENCODE:
03130 case RID_AT_PROTOCOL:
03131 case RID_AT_SELECTOR:
03132 return cp_parser_objc_expression (parser);
03133
03134 default:
03135 cp_parser_error (parser, "expected primary-expression");
03136 return error_mark_node;
03137 }
03138
03139
03140
03141
03142 case CPP_NAME:
03143 case CPP_SCOPE:
03144 case CPP_TEMPLATE_ID:
03145 case CPP_NESTED_NAME_SPECIFIER:
03146 {
03147 tree id_expression;
03148 tree decl;
03149 const char *error_msg;
03150 bool template_p;
03151 bool done;
03152
03153 id_expression:
03154
03155 id_expression
03156 = cp_parser_id_expression (parser,
03157 false,
03158 true,
03159 &template_p,
03160 false,
03161 false);
03162 if (id_expression == error_mark_node)
03163 return error_mark_node;
03164 token = cp_lexer_peek_token (parser->lexer);
03165 done = (token->type != CPP_OPEN_SQUARE
03166 && token->type != CPP_OPEN_PAREN
03167 && token->type != CPP_DOT
03168 && token->type != CPP_DEREF
03169 && token->type != CPP_PLUS_PLUS
03170 && token->type != CPP_MINUS_MINUS);
03171
03172
03173
03174 if (TREE_CODE (id_expression) == TEMPLATE_ID_EXPR
03175 || TREE_CODE (id_expression) == TYPE_DECL)
03176 decl = id_expression;
03177
03178 else
03179 {
03180 tree ambiguous_decls;
03181
03182 decl = cp_parser_lookup_name (parser, id_expression,
03183 none_type,
03184 template_p,
03185 false,
03186 true,
03187 &ambiguous_decls);
03188
03189
03190 if (ambiguous_decls)
03191 return error_mark_node;
03192
03193
03194
03195 decl = objc_lookup_ivar (decl, id_expression);
03196
03197
03198
03199 if (TREE_CODE (decl) == SCOPE_REF)
03200 return decl;
03201
03202
03203 if (parser->local_variables_forbidden_p
03204 && local_variable_p (decl))
03205 {
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218
03219 decl = check_for_out_of_scope_variable (decl);
03220 if (local_variable_p (decl))
03221 {
03222 error ("local variable %qD may not appear in this context",
03223 decl);
03224 return error_mark_node;
03225 }
03226 }
03227 }
03228
03229 decl = (finish_id_expression
03230 (id_expression, decl, parser->scope,
03231 idk,
03232 parser->integral_constant_expression_p,
03233 parser->allow_non_integral_constant_expression_p,
03234 &parser->non_integral_constant_expression_p,
03235 template_p, done, address_p,
03236 template_arg_p,
03237 &error_msg));
03238 if (error_msg)
03239 cp_parser_error (parser, error_msg);
03240 return decl;
03241 }
03242
03243
03244 default:
03245
03246 if (c_dialect_objc ()
03247 && (token->type == CPP_OPEN_SQUARE || token->type == CPP_OBJC_STRING))
03248 return cp_parser_objc_expression (parser);
03249
03250 cp_parser_error (parser, "expected primary-expression");
03251 return error_mark_node;
03252 }
03253 }
03254
03255
03256
03257
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286
03287
03288
03289 static tree
03290 cp_parser_id_expression (cp_parser *parser,
03291 bool template_keyword_p,
03292 bool check_dependency_p,
03293 bool *template_p,
03294 bool declarator_p,
03295 bool optional_p)
03296 {
03297 bool global_scope_p;
03298 bool nested_name_specifier_p;
03299
03300
03301 if (template_p)
03302 *template_p = template_keyword_p;
03303
03304
03305 global_scope_p
03306 = (cp_parser_global_scope_opt (parser, false)
03307 != NULL_TREE);
03308
03309 nested_name_specifier_p
03310 = (cp_parser_nested_name_specifier_opt (parser,
03311 false,
03312 check_dependency_p,
03313 false,
03314 declarator_p)
03315 != NULL_TREE);
03316
03317
03318 if (nested_name_specifier_p)
03319 {
03320 tree saved_scope;
03321 tree saved_object_scope;
03322 tree saved_qualifying_scope;
03323 tree unqualified_id;
03324 bool is_template;
03325
03326
03327 if (!template_p)
03328 template_p = &is_template;
03329 *template_p = cp_parser_optional_template_keyword (parser);
03330
03331
03332 saved_scope = parser->scope;
03333 saved_object_scope = parser->object_scope;
03334 saved_qualifying_scope = parser->qualifying_scope;
03335
03336 unqualified_id = cp_parser_unqualified_id (parser, *template_p,
03337 check_dependency_p,
03338 declarator_p,
03339 false);
03340
03341 parser->scope = saved_scope;
03342 parser->object_scope = saved_object_scope;
03343 parser->qualifying_scope = saved_qualifying_scope;
03344
03345 return unqualified_id;
03346 }
03347
03348
03349 else if (global_scope_p)
03350 {
03351 cp_token *token;
03352 tree id;
03353
03354
03355 token = cp_lexer_peek_token (parser->lexer);
03356
03357
03358
03359
03360 if (token->type == CPP_NAME
03361 && !cp_parser_nth_token_starts_template_argument_list_p
03362 (parser, 2))
03363 return cp_parser_identifier (parser);
03364
03365 cp_parser_parse_tentatively (parser);
03366
03367 id = cp_parser_template_id (parser,
03368 false,
03369 true,
03370 declarator_p);
03371
03372 if (cp_parser_parse_definitely (parser))
03373 return id;
03374
03375
03376
03377 token = cp_lexer_peek_token (parser->lexer);
03378
03379 switch (token->type)
03380 {
03381 case CPP_NAME:
03382 return cp_parser_identifier (parser);
03383
03384 case CPP_KEYWORD:
03385 if (token->keyword == RID_OPERATOR)
03386 return cp_parser_operator_function_id (parser);
03387
03388
03389 default:
03390 cp_parser_error (parser, "expected id-expression");
03391 return error_mark_node;
03392 }
03393 }
03394 else
03395 return cp_parser_unqualified_id (parser, template_keyword_p,
03396 true,
03397 declarator_p,
03398 optional_p);
03399 }
03400
03401
03402
03403
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419
03420
03421
03422
03423 static tree
03424 cp_parser_unqualified_id (cp_parser* parser,
03425 bool template_keyword_p,
03426 bool check_dependency_p,
03427 bool declarator_p,
03428 bool optional_p)
03429 {
03430 cp_token *token;
03431
03432
03433 token = cp_lexer_peek_token (parser->lexer);
03434
03435 switch (token->type)
03436 {
03437 case CPP_NAME:
03438 {
03439 tree id;
03440
03441
03442
03443 cp_parser_parse_tentatively (parser);
03444
03445 id = cp_parser_template_id (parser, template_keyword_p,
03446 check_dependency_p,
03447 declarator_p);
03448
03449 if (cp_parser_parse_definitely (parser))
03450 return id;
03451
03452 return cp_parser_identifier (parser);
03453 }
03454
03455 case CPP_TEMPLATE_ID:
03456 return cp_parser_template_id (parser, template_keyword_p,
03457 check_dependency_p,
03458 declarator_p);
03459
03460 case CPP_COMPL:
03461 {
03462 tree type_decl;
03463 tree qualifying_scope;
03464 tree object_scope;
03465 tree scope;
03466 bool done;
03467
03468
03469 cp_lexer_consume_token (parser->lexer);
03470
03471
03472
03473
03474
03475
03476
03477
03478
03479
03480
03481
03482
03483
03484
03485
03486
03487
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503
03504
03505 scope = parser->scope;
03506 object_scope = parser->object_scope;
03507 qualifying_scope = parser->qualifying_scope;
03508
03509
03510 if (scope == error_mark_node)
03511 {
03512 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
03513 cp_lexer_consume_token (parser->lexer);
03514 return error_mark_node;
03515 }
03516 if (scope && TREE_CODE (scope) == NAMESPACE_DECL)
03517 {
03518 if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
03519 error ("scope %qT before %<~%> is not a class-name", scope);
03520 cp_parser_simulate_error (parser);
03521 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
03522 cp_lexer_consume_token (parser->lexer);
03523 return error_mark_node;
03524 }
03525 gcc_assert (!scope || TYPE_P (scope));
03526
03527
03528 token = cp_lexer_peek_token (parser->lexer);
03529 if (scope
03530 && token->type == CPP_NAME
03531 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
03532 == CPP_OPEN_PAREN)
03533 && constructor_name_p (token->u.value, scope))
03534 {
03535 cp_lexer_consume_token (parser->lexer);
03536 return build_nt (BIT_NOT_EXPR, scope);
03537 }
03538
03539
03540
03541 done = false;
03542 type_decl = NULL_TREE;
03543 if (scope)
03544 {
03545 cp_parser_parse_tentatively (parser);
03546 type_decl = cp_parser_class_name (parser,
03547 false,
03548 false,
03549 none_type,
03550 false,
03551 false,
03552 declarator_p);
03553 if (cp_parser_parse_definitely (parser))
03554 done = true;
03555 }
03556
03557 if (!done && scope && qualifying_scope)
03558 {
03559 cp_parser_parse_tentatively (parser);
03560 parser->scope = qualifying_scope;
03561 parser->object_scope = NULL_TREE;
03562 parser->qualifying_scope = NULL_TREE;
03563 type_decl
03564 = cp_parser_class_name (parser,
03565 false,
03566 false,
03567 none_type,
03568 false,
03569 false,
03570 declarator_p);
03571 if (cp_parser_parse_definitely (parser))
03572 done = true;
03573 }
03574
03575 else if (!done && object_scope)
03576 {
03577 cp_parser_parse_tentatively (parser);
03578 parser->scope = object_scope;
03579 parser->object_scope = NULL_TREE;
03580 parser->qualifying_scope = NULL_TREE;
03581 type_decl
03582 = cp_parser_class_name (parser,
03583 false,
03584 false,
03585 none_type,
03586 false,
03587 false,
03588 declarator_p);
03589 if (cp_parser_parse_definitely (parser))
03590 done = true;
03591 }
03592
03593 if (!done)
03594 {
03595 parser->scope = NULL_TREE;
03596 parser->object_scope = NULL_TREE;
03597 parser->qualifying_scope = NULL_TREE;
03598 type_decl
03599 = cp_parser_class_name (parser,
03600 false,
03601 false,
03602 none_type,
03603 false,
03604 false,
03605 declarator_p);
03606 }
03607
03608
03609
03610
03611 if (type_decl == error_mark_node && scope)
03612 return build_nt (BIT_NOT_EXPR, scope);
03613 else if (type_decl == error_mark_node)
03614 return error_mark_node;
03615
03616
03617 if (declarator_p && scope && !check_dtor_name (scope, type_decl))
03618 {
03619 if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
03620 error ("declaration of %<~%T%> as member of %qT",
03621 type_decl, scope);
03622 cp_parser_simulate_error (parser);
03623 return error_mark_node;
03624 }
03625
03626
03627
03628
03629
03630 if (declarator_p
03631 && !DECL_IMPLICIT_TYPEDEF_P (type_decl)
03632 && !DECL_SELF_REFERENCE_P (type_decl)
03633 && !cp_parser_uncommitted_to_tentative_parse_p (parser))
03634 error ("typedef-name %qD used as destructor declarator",
03635 type_decl);
03636
03637 return build_nt (BIT_NOT_EXPR, TREE_TYPE (type_decl));
03638 }
03639
03640 case CPP_KEYWORD:
03641 if (token->keyword == RID_OPERATOR)
03642 {
03643 tree id;
03644
03645
03646 cp_parser_parse_tentatively (parser);
03647
03648 id = cp_parser_template_id (parser, template_keyword_p,
03649 true,
03650 declarator_p);
03651
03652 if (cp_parser_parse_definitely (parser))
03653 return id;
03654
03655
03656 cp_parser_parse_tentatively (parser);
03657
03658 id = cp_parser_operator_function_id (parser);
03659
03660 if (!cp_parser_parse_definitely (parser))
03661 id = cp_parser_conversion_function_id (parser);
03662
03663 return id;
03664 }
03665
03666
03667 default:
03668 if (optional_p)
03669 return NULL_TREE;
03670 cp_parser_error (parser, "expected unqualified-id");
03671 return error_mark_node;
03672 }
03673 }
03674
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685
03686
03687
03688
03689
03690
03691
03692
03693
03694 static tree
03695 cp_parser_nested_name_specifier_opt (cp_parser *parser,
03696 bool typename_keyword_p,
03697 bool check_dependency_p,
03698 bool type_p,
03699 bool is_declaration)
03700 {
03701 bool success = false;
03702 cp_token_position start = 0;
03703 cp_token *token;
03704
03705
03706 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
03707 {
03708 start = cp_lexer_token_position (parser->lexer, false);
03709 push_deferring_access_checks (dk_deferred);
03710 }
03711
03712 while (true)
03713 {
03714 tree new_scope;
03715 tree old_scope;
03716 tree saved_qualifying_scope;
03717 bool template_keyword_p;
03718
03719
03720
03721 token = cp_lexer_peek_token (parser->lexer);
03722
03723
03724
03725 if (token->type == CPP_NESTED_NAME_SPECIFIER)
03726 {
03727
03728 cp_parser_pre_parsed_nested_name_specifier (parser);
03729
03730
03731
03732 if (is_declaration
03733 && TREE_CODE (parser->scope) == TYPENAME_TYPE)
03734 {
03735 new_scope = resolve_typename_type (parser->scope,
03736 false);
03737 if (new_scope != error_mark_node)
03738 parser->scope = new_scope;
03739 }
03740 success = true;
03741 continue;
03742 }
03743
03744
03745
03746
03747 if (success && token->keyword == RID_TEMPLATE)
03748 ;
03749
03750 else if (token->type == CPP_TEMPLATE_ID)
03751 ;
03752 else
03753 {
03754
03755
03756 if (token->type != CPP_NAME)
03757 break;
03758
03759
03760
03761 token = cp_lexer_peek_nth_token (parser->lexer, 2);
03762 if (token->type != CPP_SCOPE
03763 && !cp_parser_nth_token_starts_template_argument_list_p
03764 (parser, 2))
03765 break;
03766 }
03767
03768
03769
03770 cp_parser_parse_tentatively (parser);
03771
03772
03773
03774 if (success)
03775 template_keyword_p = cp_parser_optional_template_keyword (parser);
03776 else
03777 template_keyword_p = false;
03778
03779
03780
03781 old_scope = parser->scope;
03782 saved_qualifying_scope = parser->qualifying_scope;
03783
03784
03785
03786
03787 if (is_declaration
03788 && !typename_keyword_p
03789 && parser->scope
03790 && TREE_CODE (parser->scope) == TYPENAME_TYPE)
03791 parser->scope = resolve_typename_type (parser->scope,
03792 false);
03793
03794 new_scope
03795 = cp_parser_class_or_namespace_name (parser,
03796 typename_keyword_p,
03797 template_keyword_p,
03798 check_dependency_p,
03799 type_p,
03800 is_declaration);
03801
03802 cp_parser_require (parser, CPP_SCOPE, "`::'");
03803
03804
03805
03806 if (!cp_parser_parse_definitely (parser))
03807 {
03808 bool error_p = false;
03809
03810
03811
03812
03813 parser->scope = old_scope;
03814 parser->qualifying_scope = saved_qualifying_scope;
03815 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
03816 break;
03817
03818
03819
03820 while (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
03821 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
03822 == CPP_SCOPE)
03823 && (cp_lexer_peek_nth_token (parser->lexer, 3)->type
03824 != CPP_COMPL))
03825 {
03826 token = cp_lexer_consume_token (parser->lexer);
03827 if (!error_p)
03828 {
03829 if (!token->ambiguous_p)
03830 {
03831 tree decl;
03832 tree ambiguous_decls;
03833
03834 decl = cp_parser_lookup_name (parser, token->u.value,
03835 none_type,
03836 false,
03837 false,
03838 true,
03839 &ambiguous_decls);
03840 if (TREE_CODE (decl) == TEMPLATE_DECL)
03841 error ("%qD used without template parameters", decl);
03842 else if (ambiguous_decls)
03843 {
03844 error ("reference to %qD is ambiguous",
03845 token->u.value);
03846 print_candidates (ambiguous_decls);
03847 decl = error_mark_node;
03848 }
03849 else
03850 cp_parser_name_lookup_error
03851 (parser, token->u.value, decl,
03852 "is not a class or namespace");
03853 }
03854 parser->scope = error_mark_node;
03855 error_p = true;
03856
03857
03858
03859
03860
03861
03862
03863
03864 success = true;
03865 }
03866 cp_lexer_consume_token (parser->lexer);
03867 }
03868 break;
03869 }
03870
03871 success = true;
03872
03873 if (TREE_CODE (new_scope) == TYPE_DECL)
03874 new_scope = TREE_TYPE (new_scope);
03875
03876 if (template_keyword_p
03877 && !(CLASS_TYPE_P (new_scope)
03878 && ((CLASSTYPE_USE_TEMPLATE (new_scope)
03879 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (new_scope)))
03880 || CLASSTYPE_IS_TEMPLATE (new_scope)))
03881 && !(TREE_CODE (new_scope) == TYPENAME_TYPE
03882 && (TREE_CODE (TYPENAME_TYPE_FULLNAME (new_scope))
03883 == TEMPLATE_ID_EXPR)))
03884 pedwarn (TYPE_P (new_scope)
03885 ? "%qT is not a template"
03886 : "%qD is not a template",
03887 new_scope);
03888
03889
03890 if (TYPE_P (new_scope)
03891
03892
03893 && !COMPLETE_TYPE_P (new_scope)
03894
03895 && !dependent_type_p (new_scope))
03896 new_scope = complete_type (new_scope);
03897
03898
03899 parser->scope = new_scope;
03900 }
03901
03902
03903
03904
03905
03906
03907 if (success && start)
03908 {
03909 cp_token *token;
03910
03911 token = cp_lexer_token_at (parser->lexer, start);
03912
03913 token->type = CPP_NESTED_NAME_SPECIFIER;
03914
03915
03916 token->u.tree_check_value = GGC_CNEW (struct tree_check);
03917 token->u.tree_check_value->value = parser->scope;
03918 token->u.tree_check_value->checks = get_deferred_access_checks ();
03919 token->u.tree_check_value->qualifying_scope =
03920 parser->qualifying_scope;
03921 token->keyword = RID_MAX;
03922
03923
03924 cp_lexer_purge_tokens_after (parser->lexer, start);
03925 }
03926
03927 if (start)
03928 pop_to_parent_deferring_access_checks ();
03929
03930 return success ? parser->scope : NULL_TREE;
03931 }
03932
03933
03934
03935
03936
03937
03938 static tree
03939 cp_parser_nested_name_specifier (cp_parser *parser,
03940 bool typename_keyword_p,
03941 bool check_dependency_p,
03942 bool type_p,
03943 bool is_declaration)
03944 {
03945 tree scope;
03946
03947
03948 scope = cp_parser_nested_name_specifier_opt (parser,
03949 typename_keyword_p,
03950 check_dependency_p,
03951 type_p,
03952 is_declaration);
03953
03954 if (!scope)
03955 {
03956 cp_parser_error (parser, "expected nested-name-specifier");
03957 parser->scope = NULL_TREE;
03958 }
03959
03960 return scope;
03961 }
03962
03963
03964
03965
03966
03967
03968
03969
03970
03971
03972
03973
03974
03975
03976
03977
03978
03979
03980 static tree
03981 cp_parser_class_or_namespace_name (cp_parser *parser,
03982 bool typename_keyword_p,
03983 bool template_keyword_p,
03984 bool check_dependency_p,
03985 bool type_p,
03986 bool is_declaration)
03987 {
03988 tree saved_scope;
03989 tree saved_qualifying_scope;
03990 tree saved_object_scope;
03991 tree scope;
03992 bool only_class_p;
03993
03994
03995
03996
03997 saved_scope = parser->scope;
03998 saved_qualifying_scope = parser->qualifying_scope;
03999 saved_object_scope = parser->object_scope;
04000
04001
04002 only_class_p = template_keyword_p || (saved_scope && TYPE_P (saved_scope));
04003 if (!only_class_p)
04004 cp_parser_parse_tentatively (parser);
04005 scope = cp_parser_class_name (parser,
04006 typename_keyword_p,
04007 template_keyword_p,
04008 type_p ? class_type : none_type,
04009 check_dependency_p,
04010 false,
04011 is_declaration);
04012
04013 if (!only_class_p && !cp_parser_parse_definitely (parser))
04014 {
04015
04016 parser->scope = saved_scope;
04017 parser->qualifying_scope = saved_qualifying_scope;
04018 parser->object_scope = saved_object_scope;
04019
04020
04021
04022
04023 if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)
04024 || cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
04025 return error_mark_node;
04026 scope = cp_parser_namespace_name (parser);
04027 }
04028
04029 return scope;
04030 }
04031
04032
04033
04034
04035
04036
04037
04038
04039
04040
04041
04042
04043
04044
04045
04046
04047
04048
04049
04050
04051
04052
04053
04054
04055
04056
04057
04058
04059
04060
04061
04062
04063
04064
04065
04066
04067
04068
04069
04070
04071 static tree
04072 cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p)
04073 {
04074 cp_token *token;
04075 enum rid keyword;
04076 cp_id_kind idk = CP_ID_KIND_NONE;
04077 tree postfix_expression = NULL_TREE;
04078
04079
04080 token = cp_lexer_peek_token (parser->lexer);
04081
04082 keyword = token->keyword;
04083 switch (keyword)
04084 {
04085 case RID_DYNCAST:
04086 case RID_STATCAST:
04087 case RID_REINTCAST:
04088 case RID_CONSTCAST:
04089 {
04090 tree type;
04091 tree expression;
04092 const char *saved_message;
04093
04094
04095
04096
04097 cp_lexer_consume_token (parser->lexer);
04098
04099
04100 saved_message = parser->type_definition_forbidden_message;
04101 parser->type_definition_forbidden_message
04102 = "types may not be defined in casts";
04103
04104
04105 cp_parser_require (parser, CPP_LESS, "`<'");
04106
04107 type = cp_parser_type_id (parser);
04108
04109 cp_parser_require (parser, CPP_GREATER, "`>'");
04110
04111 parser->type_definition_forbidden_message = saved_message;
04112
04113
04114 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
04115 expression = cp_parser_expression (parser, true);
04116 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04117
04118
04119
04120 if (!cast_valid_in_integral_constant_expression_p (type)
04121 && (cp_parser_non_integral_constant_expression
04122 (parser,
04123 "a cast to a type other than an integral or "
04124 "enumeration type")))
04125 return error_mark_node;
04126
04127 switch (keyword)
04128 {
04129 case RID_DYNCAST:
04130 postfix_expression
04131 = build_dynamic_cast (type, expression);
04132 break;
04133 case RID_STATCAST:
04134 postfix_expression
04135 = build_static_cast (type, expression);
04136 break;
04137 case RID_REINTCAST:
04138 postfix_expression
04139 = build_reinterpret_cast (type, expression);
04140 break;
04141 case RID_CONSTCAST:
04142 postfix_expression
04143 = build_const_cast (type, expression);
04144 break;
04145 default:
04146 gcc_unreachable ();
04147 }
04148 }
04149 break;
04150
04151 case RID_TYPEID:
04152 {
04153 tree type;
04154 const char *saved_message;
04155 bool saved_in_type_id_in_expr_p;
04156
04157
04158 cp_lexer_consume_token (parser->lexer);
04159
04160 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
04161
04162 saved_message = parser->type_definition_forbidden_message;
04163 parser->type_definition_forbidden_message
04164 = "types may not be defined in a `typeid\' expression";
04165
04166
04167 cp_parser_parse_tentatively (parser);
04168
04169 saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
04170 parser->in_type_id_in_expr_p = true;
04171 type = cp_parser_type_id (parser);
04172 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
04173
04174
04175
04176 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04177
04178 if (cp_parser_parse_definitely (parser))
04179 postfix_expression = get_typeid (type);
04180
04181 else
04182 {
04183 tree expression;
04184
04185
04186 expression = cp_parser_expression (parser, false);
04187
04188 postfix_expression = build_typeid (expression);
04189
04190 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04191 }
04192
04193 parser->type_definition_forbidden_message = saved_message;
04194
04195 if (cp_parser_non_integral_constant_expression(parser,
04196 "`typeid' operator"))
04197 return error_mark_node;
04198 }
04199 break;
04200
04201 case RID_TYPENAME:
04202 {
04203 tree type;
04204
04205
04206 type = cp_parser_elaborated_type_specifier (parser,
04207 false,
04208 false);
04209 postfix_expression = cp_parser_functional_cast (parser, type);
04210 }
04211 break;
04212
04213 default:
04214 {
04215 tree type;
04216
04217
04218
04219
04220
04221 cp_parser_parse_tentatively (parser);
04222
04223 type = cp_parser_simple_type_specifier (parser,
04224 NULL,
04225 CP_PARSER_FLAGS_NONE);
04226
04227 if (!cp_parser_error_occurred (parser))
04228 postfix_expression
04229 = cp_parser_functional_cast (parser, type);
04230
04231 if (cp_parser_parse_definitely (parser))
04232 break;
04233
04234
04235
04236 if (cp_parser_allow_gnu_extensions_p (parser)
04237 && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
04238 {
04239 VEC(constructor_elt,gc) *initializer_list = NULL;
04240 bool saved_in_type_id_in_expr_p;
04241
04242 cp_parser_parse_tentatively (parser);
04243
04244 cp_lexer_consume_token (parser->lexer);
04245
04246 saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
04247 parser->in_type_id_in_expr_p = true;
04248 type = cp_parser_type_id (parser);
04249 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
04250
04251 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
04252
04253 cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
04254
04255
04256 if (!cp_parser_error_occurred (parser))
04257 {
04258 bool non_constant_p;
04259
04260 initializer_list
04261 = cp_parser_initializer_list (parser, &non_constant_p);
04262
04263 if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
04264 cp_lexer_consume_token (parser->lexer);
04265
04266 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
04267 }
04268
04269
04270 if (cp_parser_parse_definitely (parser))
04271 {
04272
04273
04274 if (pedantic)
04275 pedwarn ("ISO C++ forbids compound-literals");
04276
04277
04278
04279
04280
04281
04282
04283
04284
04285 if (cp_parser_non_integral_constant_expression
04286 (parser, "non-constant compound literals"))
04287 {
04288 postfix_expression = error_mark_node;
04289 break;
04290 }
04291
04292 postfix_expression
04293 = finish_compound_literal (type, initializer_list);
04294 break;
04295 }
04296 }
04297
04298
04299 postfix_expression
04300 = cp_parser_primary_expression (parser, address_p, cast_p,
04301 false,
04302 &idk);
04303 }
04304 break;
04305 }
04306
04307
04308 while (true)
04309 {
04310 if (idk == CP_ID_KIND_UNQUALIFIED
04311 && TREE_CODE (postfix_expression) == IDENTIFIER_NODE
04312 && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
04313
04314 postfix_expression
04315 = unqualified_name_lookup_error (postfix_expression);
04316
04317
04318 token = cp_lexer_peek_token (parser->lexer);
04319
04320 switch (token->type)
04321 {
04322 case CPP_OPEN_SQUARE:
04323 postfix_expression
04324 = cp_parser_postfix_open_square_expression (parser,
04325 postfix_expression,
04326 false);
04327 idk = CP_ID_KIND_NONE;
04328 break;
04329
04330 case CPP_OPEN_PAREN:
04331
04332 {
04333 bool koenig_p;
04334 bool is_builtin_constant_p;
04335 bool saved_integral_constant_expression_p = false;
04336 bool saved_non_integral_constant_expression_p = false;
04337 tree args;
04338
04339 is_builtin_constant_p
04340 = DECL_IS_BUILTIN_CONSTANT_P (postfix_expression);
04341 if (is_builtin_constant_p)
04342 {
04343
04344
04345 saved_integral_constant_expression_p
04346 = parser->integral_constant_expression_p;
04347 saved_non_integral_constant_expression_p
04348 = parser->non_integral_constant_expression_p;
04349 parser->integral_constant_expression_p = false;
04350 }
04351 args = (cp_parser_parenthesized_expression_list
04352 (parser, false,
04353 false,
04354 NULL));
04355 if (is_builtin_constant_p)
04356 {
04357 parser->integral_constant_expression_p
04358 = saved_integral_constant_expression_p;
04359 parser->non_integral_constant_expression_p
04360 = saved_non_integral_constant_expression_p;
04361 }
04362
04363 if (args == error_mark_node)
04364 {
04365 postfix_expression = error_mark_node;
04366 break;
04367 }
04368
04369
04370
04371 if (! builtin_valid_in_constant_expr_p (postfix_expression)
04372 && cp_parser_non_integral_constant_expression (parser,
04373 "a function call"))
04374 {
04375 postfix_expression = error_mark_node;
04376 break;
04377 }
04378
04379 koenig_p = false;
04380 if (idk == CP_ID_KIND_UNQUALIFIED)
04381 {
04382 if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
04383 {
04384 if (args)
04385 {
04386 koenig_p = true;
04387 postfix_expression
04388 = perform_koenig_lookup (postfix_expression, args);
04389 }
04390 else
04391 postfix_expression
04392 = unqualified_fn_lookup_error (postfix_expression);
04393 }
04394
04395
04396
04397 else if (args && is_overloaded_fn (postfix_expression))
04398 {
04399 tree fn = get_first_fn (postfix_expression);
04400
04401 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
04402 fn = OVL_CURRENT (TREE_OPERAND (fn, 0));
04403
04404
04405
04406
04407 if (!DECL_FUNCTION_MEMBER_P (fn))
04408 {
04409 koenig_p = true;
04410 postfix_expression
04411 = perform_koenig_lookup (postfix_expression, args);
04412 }
04413 }
04414 }
04415
04416 if (TREE_CODE (postfix_expression) == COMPONENT_REF)
04417 {
04418 tree instance = TREE_OPERAND (postfix_expression, 0);
04419 tree fn = TREE_OPERAND (postfix_expression, 1);
04420
04421 if (processing_template_decl
04422 && (type_dependent_expression_p (instance)
04423 || (!BASELINK_P (fn)
04424 && TREE_CODE (fn) != FIELD_DECL)
04425 || type_dependent_expression_p (fn)
04426 || any_type_dependent_arguments_p (args)))
04427 {
04428 postfix_expression
04429 = build_min_nt (CALL_EXPR, postfix_expression,
04430 args, NULL_TREE);
04431 break;
04432 }
04433
04434 if (BASELINK_P (fn))
04435 postfix_expression
04436 = (build_new_method_call
04437 (instance, fn, args, NULL_TREE,
04438 (idk == CP_ID_KIND_QUALIFIED
04439 ? LOOKUP_NONVIRTUAL : LOOKUP_NORMAL),
04440 NULL));
04441 else
04442 postfix_expression
04443 = finish_call_expr (postfix_expression, args,
04444 false,
04445 false);
04446 }
04447 else if (TREE_CODE (postfix_expression) == OFFSET_REF
04448 || TREE_CODE (postfix_expression) == MEMBER_REF
04449 || TREE_CODE (postfix_expression) == DOTSTAR_EXPR)
04450 postfix_expression = (build_offset_ref_call_from_tree
04451 (postfix_expression, args));
04452 else if (idk == CP_ID_KIND_QUALIFIED)
04453
04454
04455 postfix_expression
04456 = finish_call_expr (postfix_expression, args,
04457 true,
04458 koenig_p);
04459 else
04460
04461 postfix_expression
04462 = finish_call_expr (postfix_expression, args,
04463 false,
04464 koenig_p);
04465
04466
04467 idk = CP_ID_KIND_NONE;
04468 }
04469 break;
04470
04471 case CPP_DOT:
04472 case CPP_DEREF:
04473
04474
04475
04476
04477
04478
04479 cp_lexer_consume_token (parser->lexer);
04480
04481 postfix_expression
04482 = cp_parser_postfix_dot_deref_expression (parser, token->type,
04483 postfix_expression,
04484 false, &idk);
04485 break;
04486
04487 case CPP_PLUS_PLUS:
04488
04489
04490 cp_lexer_consume_token (parser->lexer);
04491
04492 postfix_expression
04493 = finish_increment_expr (postfix_expression,
04494 POSTINCREMENT_EXPR);
04495
04496 if (cp_parser_non_integral_constant_expression (parser,
04497 "an increment"))
04498 postfix_expression = error_mark_node;
04499 idk = CP_ID_KIND_NONE;
04500 break;
04501
04502 case CPP_MINUS_MINUS:
04503
04504
04505 cp_lexer_consume_token (parser->lexer);
04506
04507 postfix_expression
04508 = finish_increment_expr (postfix_expression,
04509 POSTDECREMENT_EXPR);
04510
04511 if (cp_parser_non_integral_constant_expression (parser,
04512 "a decrement"))
04513 postfix_expression = error_mark_node;
04514 idk = CP_ID_KIND_NONE;
04515 break;
04516
04517 default:
04518 return postfix_expression;
04519 }
04520 }
04521
04522
04523 gcc_unreachable ();
04524 return error_mark_node;
04525 }
04526
04527
04528
04529
04530
04531
04532
04533
04534
04535 static tree
04536 cp_parser_postfix_open_square_expression (cp_parser *parser,
04537 tree postfix_expression,
04538 bool for_offsetof)
04539 {
04540 tree index;
04541
04542
04543 cp_lexer_consume_token (parser->lexer);
04544
04545
04546
04547
04548
04549
04550
04551
04552
04553 if (for_offsetof)
04554 index = cp_parser_constant_expression (parser, false, NULL);
04555 else
04556 index = cp_parser_expression (parser, false);
04557
04558
04559 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
04560
04561
04562 postfix_expression = grok_array_decl (postfix_expression, index);
04563
04564
04565
04566 if (!for_offsetof
04567 && (cp_parser_non_integral_constant_expression
04568 (parser, "an array reference")))
04569 postfix_expression = error_mark_node;
04570
04571 return postfix_expression;
04572 }
04573
04574
04575
04576
04577
04578
04579
04580
04581
04582
04583
04584
04585
04586
04587 static tree
04588 cp_parser_postfix_dot_deref_expression (cp_parser *parser,
04589 enum cpp_ttype token_type,
04590 tree postfix_expression,
04591 bool for_offsetof, cp_id_kind *idk)
04592 {
04593 tree name;
04594 bool dependent_p;
04595 bool pseudo_destructor_p;
04596 tree scope = NULL_TREE;
04597
04598
04599 if (token_type == CPP_DEREF)
04600 postfix_expression = build_x_arrow (postfix_expression);
04601
04602 dependent_p = type_dependent_expression_p (postfix_expression);
04603
04604 parser->scope = NULL_TREE;
04605 parser->qualifying_scope = NULL_TREE;
04606 parser->object_scope = NULL_TREE;
04607 *idk = CP_ID_KIND_NONE;
04608
04609
04610 if (!dependent_p && TREE_TYPE (postfix_expression) != NULL_TREE)
04611 {
04612 scope = TREE_TYPE (postfix_expression);
04613
04614
04615
04616
04617
04618
04619 scope = non_reference (scope);
04620
04621 if (scope == unknown_type_node)
04622 {
04623 error ("%qE does not have class type", postfix_expression);
04624 scope = NULL_TREE;
04625 }
04626 else
04627 scope = complete_type_or_else (scope, NULL_TREE);
04628
04629
04630 parser->context->object_type = scope;
04631
04632
04633
04634 if (!scope)
04635 scope = error_mark_node;
04636
04637
04638
04639 if (scope == error_mark_node)
04640 postfix_expression = error_mark_node;
04641 }
04642
04643
04644 pseudo_destructor_p = false;
04645
04646
04647
04648 if (scope && SCALAR_TYPE_P (scope))
04649 {
04650 tree s;
04651 tree type;
04652
04653 cp_parser_parse_tentatively (parser);
04654
04655 s = NULL_TREE;
04656 cp_parser_pseudo_destructor_name (parser, &s, &type);
04657 if (cp_parser_parse_definitely (parser))
04658 {
04659 pseudo_destructor_p = true;
04660 postfix_expression
04661 = finish_pseudo_destructor_expr (postfix_expression,
04662 s, TREE_TYPE (type));
04663 }
04664 }
04665
04666 if (!pseudo_destructor_p)
04667 {
04668
04669
04670
04671 bool template_p;
04672
04673 name = (cp_parser_id_expression
04674 (parser,
04675 cp_parser_optional_template_keyword (parser),
04676 true,
04677 &template_p,
04678 false,
04679 false));
04680
04681
04682
04683
04684
04685
04686
04687
04688
04689
04690
04691
04692 if (parser->scope)
04693 *idk = CP_ID_KIND_QUALIFIED;
04694
04695
04696
04697 if (TREE_CODE (name) == TYPE_DECL)
04698 {
04699 error ("invalid use of %qD", name);
04700 postfix_expression = error_mark_node;
04701 }
04702 else
04703 {
04704 if (name != error_mark_node && !BASELINK_P (name) && parser->scope)
04705 {
04706 name = build_qualified_name (NULL_TREE,
04707 parser->scope,
04708 name,
04709 template_p);
04710 parser->scope = NULL_TREE;
04711 parser->qualifying_scope = NULL_TREE;
04712 parser->object_scope = NULL_TREE;
04713 }
04714 if (scope && name && BASELINK_P (name))
04715 adjust_result_of_qualified_name_lookup
04716 (name, BINFO_TYPE (BASELINK_ACCESS_BINFO (name)), scope);
04717 postfix_expression
04718 = finish_class_member_access_expr (postfix_expression, name,
04719 template_p);
04720 }
04721 }
04722
04723
04724
04725 parser->context->object_type = NULL_TREE;
04726
04727
04728
04729 if (!for_offsetof
04730 && (cp_parser_non_integral_constant_expression
04731 (parser, token_type == CPP_DEREF ? "'->'" : "`.'")))
04732 postfix_expression = error_mark_node;
04733
04734 return postfix_expression;
04735 }
04736
04737
04738
04739
04740
04741
04742
04743
04744
04745
04746
04747
04748
04749
04750
04751
04752
04753
04754
04755
04756
04757
04758
04759
04760 static tree
04761 cp_parser_parenthesized_expression_list (cp_parser* parser,
04762 bool is_attribute_list,
04763 bool cast_p,
04764 bool *non_constant_p)
04765 {
04766 tree expression_list = NULL_TREE;
04767 bool fold_expr_p = is_attribute_list;
04768 tree identifier = NULL_TREE;
04769
04770
04771 if (non_constant_p)
04772 *non_constant_p = false;
04773
04774 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
04775 return error_mark_node;
04776
04777
04778 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
04779 while (true)
04780 {
04781 tree expr;
04782
04783
04784
04785 if (is_attribute_list
04786 && cp_lexer_peek_token (parser->lexer)->type == CPP_NAME)
04787 {
04788 cp_token *token;
04789
04790
04791 token = cp_lexer_consume_token (parser->lexer);
04792
04793 identifier = token->u.value;
04794 }
04795 else
04796 {
04797
04798 if (non_constant_p)
04799 {
04800 bool expr_non_constant_p;
04801 expr = (cp_parser_constant_expression
04802 (parser, true,
04803 &expr_non_constant_p));
04804 if (expr_non_constant_p)
04805 *non_constant_p = true;
04806 }
04807 else
04808 expr = cp_parser_assignment_expression (parser, cast_p);
04809
04810 if (fold_expr_p)
04811 expr = fold_non_dependent_expr (expr);
04812
04813
04814
04815
04816
04817 expression_list = tree_cons (NULL_TREE, expr, expression_list);
04818
04819 if (expr == error_mark_node)
04820 goto skip_comma;
04821 }
04822
04823
04824
04825 is_attribute_list = false;
04826
04827 get_comma:;
04828
04829 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
04830 break;
04831
04832
04833 cp_lexer_consume_token (parser->lexer);
04834 }
04835
04836 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
04837 {
04838 int ending;
04839
04840 skip_comma:;
04841
04842
04843 ending = cp_parser_skip_to_closing_parenthesis (parser,
04844 true,
04845 true,
04846 true);
04847 if (ending < 0)
04848 goto get_comma;
04849 if (!ending)
04850 return error_mark_node;
04851 }
04852
04853
04854 expression_list = nreverse (expression_list);
04855 if (identifier)
04856 expression_list = tree_cons (NULL_TREE, identifier, expression_list);
04857
04858 return expression_list;
04859 }
04860
04861
04862
04863
04864
04865
04866
04867
04868
04869
04870
04871
04872
04873 static void
04874 cp_parser_pseudo_destructor_name (cp_parser* parser,
04875 tree* scope,
04876 tree* type)
04877 {
04878 bool nested_name_specifier_p;
04879
04880
04881 *type = error_mark_node;
04882
04883
04884 cp_parser_global_scope_opt (parser, true);
04885
04886 nested_name_specifier_p
04887 = (cp_parser_nested_name_specifier_opt (parser,
04888 false,
04889 true,
04890 false,
04891 true)
04892 != NULL_TREE);
04893
04894
04895 if (nested_name_specifier_p
04896 && cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
04897 {
04898
04899 cp_lexer_consume_token (parser->lexer);
04900
04901 cp_parser_template_id (parser,
04902 true,
04903 false,
04904 true);
04905
04906 cp_parser_require (parser, CPP_SCOPE, "`::'");
04907 }
04908
04909
04910 else if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMPL))
04911 {
04912
04913 *scope = TREE_TYPE (cp_parser_type_name (parser));
04914
04915 if (*scope == error_mark_node)
04916 return;
04917
04918
04919
04920
04921
04922
04923 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SCOPE)
04924 || cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_COMPL)
04925 {
04926 cp_parser_error (parser, "request for member of non-aggregate type");
04927 return;
04928 }
04929
04930
04931 cp_parser_require (parser, CPP_SCOPE, "`::'");
04932 }
04933 else
04934 *scope = NULL_TREE;
04935
04936
04937 cp_parser_require (parser, CPP_COMPL, "`~'");
04938
04939
04940 *type = cp_parser_type_name (parser);
04941 }
04942
04943
04944
04945
04946
04947
04948
04949
04950
04951
04952
04953
04954
04955
04956
04957
04958
04959
04960
04961
04962
04963
04964
04965
04966
04967
04968
04969
04970
04971 static tree
04972 cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p)
04973 {
04974 cp_token *token;
04975 enum tree_code unary_operator;
04976
04977
04978 token = cp_lexer_peek_token (parser->lexer);
04979
04980 if (token->type == CPP_KEYWORD)
04981 {
04982 enum rid keyword = token->keyword;
04983
04984 switch (keyword)
04985 {
04986 case RID_ALIGNOF:
04987 case RID_SIZEOF:
04988 {
04989 tree operand;
04990 enum tree_code op;
04991
04992 op = keyword == RID_ALIGNOF ? ALIGNOF_EXPR : SIZEOF_EXPR;
04993
04994 cp_lexer_consume_token (parser->lexer);
04995
04996 operand = cp_parser_sizeof_operand (parser, keyword);
04997
04998 if (TYPE_P (operand))
04999 return cxx_sizeof_or_alignof_type (operand, op, true);
05000 else
05001 return cxx_sizeof_or_alignof_expr (operand, op);
05002 }
05003
05004 case RID_NEW:
05005 return cp_parser_new_expression (parser);
05006
05007 case RID_DELETE:
05008 return cp_parser_delete_expression (parser);
05009
05010 case RID_EXTENSION:
05011 {
05012
05013 int saved_pedantic;
05014 tree expr;
05015
05016
05017 cp_parser_extension_opt (parser, &saved_pedantic);
05018
05019 expr = cp_parser_simple_cast_expression (parser);
05020
05021 pedantic = saved_pedantic;
05022
05023 return expr;
05024 }
05025
05026 case RID_REALPART:
05027 case RID_IMAGPART:
05028 {
05029 tree expression;
05030
05031
05032 cp_lexer_consume_token (parser->lexer);
05033
05034 expression = cp_parser_simple_cast_expression (parser);
05035
05036 return build_x_unary_op ((keyword == RID_REALPART
05037 ? REALPART_EXPR : IMAGPART_EXPR),
05038 expression);
05039 }
05040 break;
05041
05042 default:
05043 break;
05044 }
05045 }
05046
05047
05048
05049
05050
05051 if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
05052 {
05053 enum rid keyword;
05054
05055
05056
05057 keyword = cp_lexer_peek_nth_token (parser->lexer, 2)->keyword;
05058
05059 if (keyword == RID_NEW)
05060 return cp_parser_new_expression (parser);
05061
05062 else if (keyword == RID_DELETE)
05063 return cp_parser_delete_expression (parser);
05064 }
05065
05066
05067 unary_operator = cp_parser_unary_operator (token);
05068
05069
05070 if (unary_operator == ERROR_MARK)
05071 {
05072 if (token->type == CPP_PLUS_PLUS)
05073 unary_operator = PREINCREMENT_EXPR;
05074 else if (token->type == CPP_MINUS_MINUS)
05075 unary_operator = PREDECREMENT_EXPR;
05076
05077 else if (cp_parser_allow_gnu_extensions_p (parser)
05078 && token->type == CPP_AND_AND)
05079 {
05080 tree identifier;
05081
05082
05083 cp_lexer_consume_token (parser->lexer);
05084
05085 identifier = cp_parser_identifier (parser);
05086
05087 return finish_label_address_expr (identifier);
05088 }
05089 }
05090 if (unary_operator != ERROR_MARK)
05091 {
05092 tree cast_expression;
05093 tree expression = error_mark_node;
05094 const char *non_constant_p = NULL;
05095
05096
05097 token = cp_lexer_consume_token (parser->lexer);
05098
05099 cast_expression
05100 = cp_parser_cast_expression (parser,
05101 unary_operator == ADDR_EXPR,
05102 false);
05103
05104 switch (unary_operator)
05105 {
05106 case INDIRECT_REF:
05107 non_constant_p = "`*'";
05108 expression = build_x_indirect_ref (cast_expression, "unary *");
05109 break;
05110
05111 case ADDR_EXPR:
05112 non_constant_p = "`&'";
05113
05114 case BIT_NOT_EXPR:
05115 expression = build_x_unary_op (unary_operator, cast_expression);
05116 break;
05117
05118 case PREINCREMENT_EXPR:
05119 case PREDECREMENT_EXPR:
05120 non_constant_p = (unary_operator == PREINCREMENT_EXPR
05121 ? "`++'" : "`--'");
05122
05123 case UNARY_PLUS_EXPR:
05124 case NEGATE_EXPR:
05125 case TRUTH_NOT_EXPR:
05126 expression = finish_unary_op_expr (unary_operator, cast_expression);
05127 break;
05128
05129 default:
05130 gcc_unreachable ();
05131 }
05132
05133 if (non_constant_p
05134 && cp_parser_non_integral_constant_expression (parser,
05135 non_constant_p))
05136 expression = error_mark_node;
05137
05138 return expression;
05139 }
05140
05141 return cp_parser_postfix_expression (parser, address_p, cast_p);
05142 }
05143
05144
05145
05146
05147 static enum tree_code
05148 cp_parser_unary_operator (cp_token* token)
05149 {
05150 switch (token->type)
05151 {
05152 case CPP_MULT:
05153 return INDIRECT_REF;
05154
05155 case CPP_AND:
05156 return ADDR_EXPR;
05157
05158 case CPP_PLUS:
05159 return UNARY_PLUS_EXPR;
05160
05161 case CPP_MINUS:
05162 return NEGATE_EXPR;
05163
05164 case CPP_NOT:
05165 return TRUTH_NOT_EXPR;
05166
05167 case CPP_COMPL:
05168 return BIT_NOT_EXPR;
05169
05170 default:
05171 return ERROR_MARK;
05172 }
05173 }
05174
05175
05176
05177
05178
05179
05180
05181
05182
05183 static tree
05184 cp_parser_new_expression (cp_parser* parser)
05185 {
05186 bool global_scope_p;
05187 tree placement;
05188 tree type;
05189 tree initializer;
05190 tree nelts;
05191
05192
05193 global_scope_p
05194 = (cp_parser_global_scope_opt (parser,
05195 false)
05196 != NULL_TREE);
05197
05198 cp_parser_require_keyword (parser, RID_NEW, "`new'");
05199
05200
05201 cp_parser_parse_tentatively (parser);
05202
05203 placement = cp_parser_new_placement (parser);
05204
05205 if (!cp_parser_parse_definitely (parser))
05206 placement = NULL_TREE;
05207
05208
05209
05210 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
05211 {
05212
05213 cp_lexer_consume_token (parser->lexer);
05214
05215 type = cp_parser_type_id (parser);
05216
05217 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
05218
05219
05220
05221 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
05222 {
05223 error ("array bound forbidden after parenthesized type-id");
05224 inform ("try removing the parentheses around the type-id");
05225 cp_parser_direct_new_declarator (parser);
05226 }
05227 nelts = NULL_TREE;
05228 }
05229
05230 else
05231 type = cp_parser_new_type_id (parser, &nelts);
05232
05233
05234 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
05235 initializer = cp_parser_new_initializer (parser);
05236 else
05237 initializer = NULL_TREE;
05238
05239
05240
05241 if (cp_parser_non_integral_constant_expression (parser, "`new'"))
05242 return error_mark_node;
05243
05244
05245 return build_new (placement, type, nelts, initializer, global_scope_p);
05246 }
05247
05248
05249
05250
05251
05252
05253
05254
05255 static tree
05256 cp_parser_new_placement (cp_parser* parser)
05257 {
05258 tree expression_list;
05259
05260
05261 expression_list = (cp_parser_parenthesized_expression_list
05262 (parser, false, false,
05263 NULL));
05264
05265 return expression_list;
05266 }
05267
05268
05269
05270
05271
05272
05273
05274
05275
05276
05277 static tree
05278 cp_parser_new_type_id (cp_parser* parser, tree *nelts)
05279 {
05280 cp_decl_specifier_seq type_specifier_seq;
05281 cp_declarator *new_declarator;
05282 cp_declarator *declarator;
05283 cp_declarator *outer_declarator;
05284 const char *saved_message;
05285 tree type;
05286
05287
05288
05289
05290
05291 saved_message = parser->type_definition_forbidden_message;
05292 parser->type_definition_forbidden_message
05293 = "types may not be defined in a new-type-id";
05294
05295 cp_parser_type_specifier_seq (parser, false,
05296 &type_specifier_seq);
05297
05298 parser->type_definition_forbidden_message = saved_message;
05299
05300 new_declarator = cp_parser_new_declarator_opt (parser);
05301
05302
05303
05304 *nelts = NULL_TREE;
05305
05306 declarator = new_declarator;
05307 outer_declarator = NULL;
05308 while (declarator && (declarator->kind == cdk_pointer
05309 || declarator->kind == cdk_ptrmem))
05310 {
05311 outer_declarator = declarator;
05312 declarator = declarator->declarator;
05313 }
05314 while (declarator
05315 && declarator->kind == cdk_array
05316 && declarator->declarator
05317 && declarator->declarator->kind == cdk_array)
05318 {
05319 outer_declarator = declarator;
05320 declarator = declarator->declarator;
05321 }
05322
05323 if (declarator && declarator->kind == cdk_array)
05324 {
05325 *nelts = declarator->u.array.bounds;
05326 if (*nelts == error_mark_node)
05327 *nelts = integer_one_node;
05328
05329 if (outer_declarator)
05330 outer_declarator->declarator = declarator->declarator;
05331 else
05332 new_declarator = NULL;
05333 }
05334
05335 type = groktypename (&type_specifier_seq, new_declarator);
05336 if (TREE_CODE (type) == ARRAY_TYPE && *nelts == NULL_TREE)
05337 {
05338 *nelts = array_type_nelts_top (type);
05339 type = TREE_TYPE (type);
05340 }
05341 return type;
05342 }
05343
05344
05345
05346
05347
05348
05349
05350
05351
05352 static cp_declarator *
05353 cp_parser_new_declarator_opt (cp_parser* parser)
05354 {
05355 enum tree_code code;
05356 tree type;
05357 cp_cv_quals cv_quals;
05358
05359
05360 cp_parser_parse_tentatively (parser);
05361
05362 code = cp_parser_ptr_operator (parser, &type, &cv_quals);
05363
05364 if (cp_parser_parse_definitely (parser))
05365 {
05366 cp_declarator *declarator;
05367
05368
05369 declarator = cp_parser_new_declarator_opt (parser);
05370
05371
05372 if (type)
05373 declarator = make_ptrmem_declarator (cv_quals, type, declarator);
05374 else if (code == INDIRECT_REF)
05375 declarator = make_pointer_declarator (cv_quals, declarator);
05376 else
05377 declarator = make_reference_declarator (cv_quals, declarator);
05378
05379 return declarator;
05380 }
05381
05382
05383 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
05384 return cp_parser_direct_new_declarator (parser);
05385
05386 return NULL;
05387 }
05388
05389
05390
05391
05392
05393
05394
05395
05396
05397 static cp_declarator *
05398 cp_parser_direct_new_declarator (cp_parser* parser)
05399 {
05400 cp_declarator *declarator = NULL;
05401
05402 while (true)
05403 {
05404 tree expression;
05405
05406
05407 cp_parser_require (parser, CPP_OPEN_SQUARE, "`['");
05408
05409 if (!declarator)
05410 {
05411 expression = cp_parser_expression (parser, false);
05412
05413
05414
05415
05416
05417
05418 if (!processing_template_decl)
05419 {
05420 expression
05421 = build_expr_type_conversion (WANT_INT | WANT_ENUM,
05422 expression,
05423 true);
05424 if (!expression)
05425 {
05426 error ("expression in new-declarator must have integral "
05427 "or enumeration type");
05428 expression = error_mark_node;
05429 }
05430 }
05431 }
05432
05433 else
05434 expression
05435 = cp_parser_constant_expression (parser,
05436 false,
05437 NULL);
05438
05439 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
05440
05441
05442 declarator = make_array_declarator (declarator, expression);
05443
05444
05445
05446 if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_SQUARE))
05447 break;
05448 }
05449
05450 return declarator;
05451 }
05452
05453
05454
05455
05456
05457
05458
05459
05460
05461 static tree
05462 cp_parser_new_initializer (cp_parser* parser)
05463 {
05464 tree expression_list;
05465
05466 expression_list = (cp_parser_parenthesized_expression_list
05467 (parser, false, false,
05468 NULL));
05469 if (!expression_list)
05470 expression_list = void_zero_node;
05471
05472 return expression_list;
05473 }
05474
05475
05476
05477
05478
05479
05480
05481
05482
05483 static tree
05484 cp_parser_delete_expression (cp_parser* parser)
05485 {
05486 bool global_scope_p;
05487 bool array_p;
05488 tree expression;
05489
05490
05491 global_scope_p
05492 = (cp_parser_global_scope_opt (parser,
05493 false)
05494 != NULL_TREE);
05495
05496 cp_parser_require_keyword (parser, RID_DELETE, "`delete'");
05497
05498 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
05499 {
05500
05501 cp_lexer_consume_token (parser->lexer);
05502
05503 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
05504
05505 array_p = true;
05506 }
05507 else
05508 array_p = false;
05509
05510
05511 expression = cp_parser_simple_cast_expression (parser);
05512
05513
05514
05515 if (cp_parser_non_integral_constant_expression (parser, "`delete'"))
05516 return error_mark_node;
05517
05518 return delete_sanity (expression, NULL_TREE, array_p, global_scope_p);
05519 }
05520
05521
05522
05523
05524
05525
05526
05527
05528
05529
05530
05531
05532
05533 static tree
05534 cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p)
05535 {
05536
05537 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
05538 {
05539 tree type = NULL_TREE;
05540 tree expr = NULL_TREE;
05541 bool compound_literal_p;
05542 const char *saved_message;
05543
05544
05545
05546
05547 cp_parser_parse_tentatively (parser);
05548
05549 saved_message = parser->type_definition_forbidden_message;
05550 parser->type_definition_forbidden_message
05551 = "types may not be defined in casts";
05552
05553 cp_lexer_consume_token (parser->lexer);
05554
05555
05556
05557
05558
05559
05560
05561
05562
05563
05564
05565
05566
05567
05568
05569
05570 cp_lexer_save_tokens (parser->lexer);
05571
05572
05573
05574 compound_literal_p
05575 = (cp_parser_skip_to_closing_parenthesis (parser, false, false,
05576 true)
05577 && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE));
05578
05579 cp_lexer_rollback_tokens (parser->lexer);
05580
05581
05582
05583 if (compound_literal_p)
05584 cp_parser_simulate_error (parser);
05585 else
05586 {
05587 bool saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
05588 parser->in_type_id_in_expr_p = true;
05589
05590 type = cp_parser_type_id (parser);
05591
05592 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
05593 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
05594 }
05595
05596
05597 parser->type_definition_forbidden_message = saved_message;
05598
05599
05600
05601
05602
05603 if (!cp_parser_error_occurred (parser))
05604 expr = cp_parser_cast_expression (parser,
05605 false,
05606 true);
05607
05608 if (cp_parser_parse_definitely (parser))
05609 {
05610
05611 if (warn_old_style_cast
05612 && !in_system_header
05613 && !VOID_TYPE_P (type)
05614 && current_lang_name != lang_name_c)
05615 warning (OPT_Wold_style_cast, "use of old-style cast");
05616
05617
05618
05619 if (!cast_valid_in_integral_constant_expression_p (type)
05620 && (cp_parser_non_integral_constant_expression
05621 (parser,
05622 "a cast to a type other than an integral or "
05623 "enumeration type")))
05624 return error_mark_node;
05625
05626
05627 expr = build_c_cast (type, expr);
05628 return expr;
05629 }
05630 }
05631
05632
05633
05634 return cp_parser_unary_expression (parser, address_p, cast_p);
05635 }
05636
05637
05638
05639
05640
05641
05642
05643
05644
05645
05646
05647
05648
05649
05650
05651
05652
05653
05654
05655
05656
05657
05658
05659
05660
05661
05662
05663
05664
05665
05666
05667
05668
05669
05670
05671
05672
05673
05674
05675
05676
05677
05678
05679
05680
05681
05682
05683
05684
05685
05686
05687
05688
05689
05690
05691
05692
05693
05694
05695
05696
05697
05698
05699
05700
05701
05702
05703
05704
05705
05706
05707
05708
05709 #define TOKEN_PRECEDENCE(token) \
05710 ((token->type == CPP_GREATER && !parser->greater_than_is_operator_p) \
05711 ? PREC_NOT_OPERATOR \
05712 : binops_by_token[token->type].prec)
05713
05714 static tree
05715 cp_parser_binary_expression (cp_parser* parser, bool cast_p)
05716 {
05717 cp_parser_expression_stack stack;
05718 cp_parser_expression_stack_entry *sp = &stack[0];
05719 tree lhs, rhs;
05720 cp_token *token;
05721 enum tree_code tree_type;
05722 enum cp_parser_prec prec = PREC_NOT_OPERATOR, new_prec, lookahead_prec;
05723 bool overloaded_p;
05724
05725
05726 lhs = cp_parser_cast_expression (parser, false, cast_p);
05727
05728 for (;;)
05729 {
05730
05731 token = cp_lexer_peek_token (parser->lexer);
05732
05733 new_prec = TOKEN_PRECEDENCE (token);
05734
05735
05736
05737
05738
05739
05740
05741
05742 if (new_prec <= prec)
05743 {
05744 if (sp == stack)
05745 break;
05746 else
05747 goto pop;
05748 }
05749
05750 get_rhs:
05751 tree_type = binops_by_token[token->type].tree_type;
05752
05753
05754 cp_lexer_consume_token (parser->lexer);
05755
05756
05757
05758 rhs = cp_parser_simple_cast_expression (parser);
05759
05760
05761
05762
05763 token = cp_lexer_peek_token (parser->lexer);
05764 lookahead_prec = TOKEN_PRECEDENCE (token);
05765 if (lookahead_prec > new_prec)
05766 {
05767
05768
05769
05770
05771 sp->prec = prec;
05772 sp->tree_type = tree_type;
05773 sp->lhs = lhs;
05774 sp++;
05775 lhs = rhs;
05776 prec = new_prec;
05777 new_prec = lookahead_prec;
05778 goto get_rhs;
05779
05780 pop:
05781
05782
05783
05784
05785
05786
05787
05788 --sp;
05789 prec = sp->prec;
05790 tree_type = sp->tree_type;
05791 rhs = lhs;
05792 lhs = sp->lhs;
05793 }
05794
05795 overloaded_p = false;
05796 lhs = build_x_binary_op (tree_type, lhs, rhs, &overloaded_p);
05797
05798
05799
05800
05801
05802
05803
05804 if (overloaded_p
05805 && (cp_parser_non_integral_constant_expression
05806 (parser, "calls to overloaded operators")))
05807 return error_mark_node;
05808 }
05809
05810 return lhs;
05811 }
05812
05813
05814
05815
05816
05817
05818
05819
05820
05821
05822
05823
05824
05825
05826
05827 static tree
05828 cp_parser_question_colon_clause (cp_parser* parser, tree logical_or_expr)
05829 {
05830 tree expr;
05831 tree assignment_expr;
05832
05833
05834 cp_lexer_consume_token (parser->lexer);
05835 if (cp_parser_allow_gnu_extensions_p (parser)
05836 && cp_lexer_next_token_is (parser->lexer, CPP_COLON))
05837
05838 expr = NULL_TREE;
05839 else
05840
05841 expr = cp_parser_expression (parser, false);
05842
05843
05844 cp_parser_require (parser, CPP_COLON, "`:'");
05845
05846 assignment_expr = cp_parser_assignment_expression (parser, false);
05847
05848
05849 return build_x_conditional_expr (logical_or_expr,
05850 expr,
05851 assignment_expr);
05852 }
05853
05854
05855
05856
05857
05858
05859
05860
05861
05862
05863
05864
05865 static tree
05866 cp_parser_assignment_expression (cp_parser* parser, bool cast_p)
05867 {
05868 tree expr;
05869
05870
05871
05872 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_THROW))
05873 expr = cp_parser_throw_expression (parser);
05874
05875
05876 else
05877 {
05878
05879 expr = cp_parser_binary_expression (parser, cast_p);
05880
05881
05882 if (cp_lexer_next_token_is (parser->lexer, CPP_QUERY))
05883 return cp_parser_question_colon_clause (parser, expr);
05884 else
05885 {
05886 enum tree_code assignment_operator;
05887
05888
05889
05890 assignment_operator
05891 = cp_parser_assignment_operator_opt (parser);
05892 if (assignment_operator != ERROR_MARK)
05893 {
05894 tree rhs;
05895
05896
05897 rhs = cp_parser_assignment_expression (parser, cast_p);
05898
05899
05900 if (cp_parser_non_integral_constant_expression (parser,
05901 "an assignment"))
05902 return error_mark_node;
05903
05904 expr = build_x_modify_expr (expr,
05905 assignment_operator,
05906 rhs);
05907 }
05908 }
05909 }
05910
05911 return expr;
05912 }
05913
05914
05915
05916
05917
05918
05919
05920
05921
05922
05923
05924
05925
05926
05927
05928
05929
05930
05931 static enum tree_code
05932 cp_parser_assignment_operator_opt (cp_parser* parser)
05933 {
05934 enum tree_code op;
05935 cp_token *token;
05936
05937
05938 token = cp_lexer_peek_token (parser->lexer);
05939
05940 switch (token->type)
05941 {
05942 case CPP_EQ:
05943 op = NOP_EXPR;
05944 break;
05945
05946 case CPP_MULT_EQ:
05947 op = MULT_EXPR;
05948 break;
05949
05950 case CPP_DIV_EQ:
05951 op = TRUNC_DIV_EXPR;
05952 break;
05953
05954 case CPP_MOD_EQ:
05955 op = TRUNC_MOD_EXPR;
05956 break;
05957
05958 case CPP_PLUS_EQ:
05959 op = PLUS_EXPR;
05960 break;
05961
05962 case CPP_MINUS_EQ:
05963 op = MINUS_EXPR;
05964 break;
05965
05966 case CPP_RSHIFT_EQ:
05967 op = RSHIFT_EXPR;
05968 break;
05969
05970 case CPP_LSHIFT_EQ:
05971 op = LSHIFT_EXPR;
05972 break;
05973
05974 case CPP_AND_EQ:
05975 op = BIT_AND_EXPR;
05976 break;
05977
05978 case CPP_XOR_EQ:
05979 op = BIT_XOR_EXPR;
05980 break;
05981
05982 case CPP_OR_EQ:
05983 op = BIT_IOR_EXPR;
05984 break;
05985
05986 default:
05987
05988 op = ERROR_MARK;
05989 }
05990
05991
05992 if (op != ERROR_MARK)
05993 cp_lexer_consume_token (parser->lexer);
05994
05995 return op;
05996 }
05997
05998
05999
06000
06001
06002
06003
06004
06005
06006
06007
06008 static tree
06009 cp_parser_expression (cp_parser* parser, bool cast_p)
06010 {
06011 tree expression = NULL_TREE;
06012
06013 while (true)
06014 {
06015 tree assignment_expression;
06016
06017
06018 assignment_expression
06019 = cp_parser_assignment_expression (parser, cast_p);
06020
06021
06022 if (!expression)
06023 expression = assignment_expression;
06024 else
06025 expression = build_x_compound_expr (expression,
06026 assignment_expression);
06027
06028
06029 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
06030 break;
06031
06032 cp_lexer_consume_token (parser->lexer);
06033
06034 if (cp_parser_non_integral_constant_expression (parser,
06035 "a comma operator"))
06036 expression = error_mark_node;
06037 }
06038
06039 return expression;
06040 }
06041
06042
06043
06044
06045
06046
06047
06048
06049
06050
06051
06052 static tree
06053 cp_parser_constant_expression (cp_parser* parser,
06054 bool allow_non_constant_p,
06055 bool *non_constant_p)
06056 {
06057 bool saved_integral_constant_expression_p;
06058 bool saved_allow_non_integral_constant_expression_p;
06059 bool saved_non_integral_constant_expression_p;
06060 tree expression;
06061
06062
06063
06064
06065
06066
06067
06068
06069
06070
06071
06072
06073
06074
06075
06076
06077
06078
06079
06080 saved_integral_constant_expression_p = parser->integral_constant_expression_p;
06081 saved_allow_non_integral_constant_expression_p
06082 = parser->allow_non_integral_constant_expression_p;
06083 saved_non_integral_constant_expression_p = parser->non_integral_constant_expression_p;
06084
06085 parser->integral_constant_expression_p = true;
06086 parser->allow_non_integral_constant_expression_p = allow_non_constant_p;
06087 parser->non_integral_constant_expression_p = false;
06088
06089
06090
06091
06092
06093
06094
06095
06096
06097 expression = cp_parser_assignment_expression (parser, false);
06098
06099 parser->integral_constant_expression_p
06100 = saved_integral_constant_expression_p;
06101 parser->allow_non_integral_constant_expression_p
06102 = saved_allow_non_integral_constant_expression_p;
06103 if (allow_non_constant_p)
06104 *non_constant_p = parser->non_integral_constant_expression_p;
06105 else if (parser->non_integral_constant_expression_p)
06106 expression = error_mark_node;
06107 parser->non_integral_constant_expression_p
06108 = saved_non_integral_constant_expression_p;
06109
06110 return expression;
06111 }
06112
06113
06114
06115
06116
06117
06118
06119
06120
06121
06122
06123 static tree
06124 cp_parser_builtin_offsetof (cp_parser *parser)
06125 {
06126 int save_ice_p, save_non_ice_p;
06127 tree type, expr;
06128 cp_id_kind dummy;
06129
06130
06131
06132
06133 save_ice_p = parser->integral_constant_expression_p;
06134 save_non_ice_p = parser->non_integral_constant_expression_p;
06135
06136
06137 cp_lexer_consume_token (parser->lexer);
06138
06139 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06140
06141 type = cp_parser_type_id (parser);
06142
06143 cp_parser_require (parser, CPP_COMMA, "`,'");
06144
06145
06146 expr = build_static_cast (build_pointer_type (type), null_pointer_node);
06147
06148
06149 expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DEREF, expr,
06150 true, &dummy);
06151 while (true)
06152 {
06153 cp_token *token = cp_lexer_peek_token (parser->lexer);
06154 switch (token->type)
06155 {
06156 case CPP_OPEN_SQUARE:
06157
06158 expr = cp_parser_postfix_open_square_expression (parser, expr, true);
06159 break;
06160
06161 case CPP_DOT:
06162
06163 cp_lexer_consume_token (parser->lexer);
06164 expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT, expr,
06165 true, &dummy);
06166 break;
06167
06168 case CPP_CLOSE_PAREN:
06169
06170 cp_lexer_consume_token (parser->lexer);
06171 goto success;
06172
06173 default:
06174
06175
06176 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06177 cp_parser_skip_to_closing_parenthesis (parser, true, false, true);
06178 expr = error_mark_node;
06179 goto failure;
06180 }
06181 }
06182
06183 success:
06184
06185
06186 if (processing_template_decl)
06187 expr = build1 (OFFSETOF_EXPR, size_type_node, expr);
06188 else
06189 expr = finish_offsetof (expr);
06190
06191 failure:
06192 parser->integral_constant_expression_p = save_ice_p;
06193 parser->non_integral_constant_expression_p = save_non_ice_p;
06194
06195 return expr;
06196 }
06197
06198
06199
06200
06201
06202
06203
06204
06205
06206
06207
06208
06209
06210
06211
06212
06213
06214
06215 static void
06216 cp_parser_statement (cp_parser* parser, tree in_statement_expr,
06217 bool in_compound)
06218 {
06219 tree statement;
06220 cp_token *token;
06221 location_t statement_location;
06222
06223 restart:
06224
06225 statement = NULL_TREE;
06226
06227 token = cp_lexer_peek_token (parser->lexer);
06228
06229 statement_location = token->location;
06230
06231
06232 if (token->type == CPP_KEYWORD)
06233 {
06234 enum rid keyword = token->keyword;
06235
06236 switch (keyword)
06237 {
06238 case RID_CASE:
06239 case RID_DEFAULT:
06240
06241
06242
06243 cp_parser_label_for_labeled_statement (parser);
06244 goto restart;
06245
06246 case RID_IF:
06247 case RID_SWITCH:
06248 statement = cp_parser_selection_statement (parser);
06249 break;
06250
06251 case RID_WHILE:
06252 case RID_DO:
06253 case RID_FOR:
06254 statement = cp_parser_iteration_statement (parser);
06255 break;
06256
06257 case RID_BREAK:
06258 case RID_CONTINUE:
06259 case RID_RETURN:
06260 case RID_GOTO:
06261 statement = cp_parser_jump_statement (parser);
06262 break;
06263
06264
06265 case RID_AT_TRY:
06266 case RID_AT_CATCH:
06267 case RID_AT_FINALLY:
06268 case RID_AT_SYNCHRONIZED:
06269 case RID_AT_THROW:
06270 statement = cp_parser_objc_statement (parser);
06271 break;
06272
06273 case RID_TRY:
06274 statement = cp_parser_try_block (parser);
06275 break;
06276
06277 default:
06278
06279
06280 break;
06281 }
06282 }
06283 else if (token->type == CPP_NAME)
06284 {
06285
06286
06287 token = cp_lexer_peek_nth_token (parser->lexer, 2);
06288 if (token->type == CPP_COLON)
06289 {
06290
06291
06292
06293 cp_parser_label_for_labeled_statement (parser);
06294 goto restart;
06295 }
06296 }
06297
06298 else if (token->type == CPP_OPEN_BRACE)
06299 statement = cp_parser_compound_statement (parser, NULL, false);
06300
06301
06302 else if (token->type == CPP_PRAGMA)
06303 {
06304
06305
06306
06307
06308
06309 if (in_compound)
06310 cp_parser_pragma (parser, pragma_compound);
06311 else if (!cp_parser_pragma (parser, pragma_stmt))
06312 goto restart;
06313 return;
06314 }
06315 else if (token->type == CPP_EOF)
06316 {
06317 cp_parser_error (parser, "expected statement");
06318 return;
06319 }
06320
06321
06322
06323
06324
06325 if (!statement)
06326 {
06327 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06328 {
06329 cp_parser_parse_tentatively (parser);
06330
06331 cp_parser_declaration_statement (parser);
06332
06333 if (cp_parser_parse_definitely (parser))
06334 return;
06335 }
06336
06337 statement = cp_parser_expression_statement (parser, in_statement_expr);
06338 }
06339
06340
06341 if (statement && STATEMENT_CODE_P (TREE_CODE (statement)))
06342 SET_EXPR_LOCATION (statement, statement_location);
06343 }
06344
06345
06346
06347
06348
06349
06350
06351
06352
06353
06354
06355
06356
06357
06358 static void
06359 cp_parser_label_for_labeled_statement (cp_parser* parser)
06360 {
06361 cp_token *token;
06362
06363
06364 token = cp_lexer_peek_token (parser->lexer);
06365 if (token->type != CPP_NAME
06366 && token->type != CPP_KEYWORD)
06367 {
06368 cp_parser_error (parser, "expected labeled-statement");
06369 return;
06370 }
06371
06372 switch (token->keyword)
06373 {
06374 case RID_CASE:
06375 {
06376 tree expr, expr_hi;
06377 cp_token *ellipsis;
06378
06379
06380 cp_lexer_consume_token (parser->lexer);
06381
06382 expr = cp_parser_constant_expression (parser,
06383 false,
06384 NULL);
06385
06386 ellipsis = cp_lexer_peek_token (parser->lexer);
06387 if (ellipsis->type == CPP_ELLIPSIS)
06388 {
06389
06390 cp_lexer_consume_token (parser->lexer);
06391 expr_hi =
06392 cp_parser_constant_expression (parser,
06393 false,
06394 NULL);
06395
06396
06397 }
06398 else
06399 expr_hi = NULL_TREE;
06400
06401 if (parser->in_switch_statement_p)
06402 finish_case_label (expr, expr_hi);
06403 else
06404 error ("case label %qE not within a switch statement", expr);
06405 }
06406 break;
06407
06408 case RID_DEFAULT:
06409
06410 cp_lexer_consume_token (parser->lexer);
06411
06412 if (parser->in_switch_statement_p)
06413 finish_case_label (NULL_TREE, NULL_TREE);
06414 else
06415 error ("case label not within a switch statement");
06416 break;
06417
06418 default:
06419
06420 finish_label_stmt (cp_parser_identifier (parser));
06421 break;
06422 }
06423
06424
06425 cp_parser_require (parser, CPP_COLON, "`:'");
06426 }
06427
06428
06429
06430
06431
06432
06433
06434
06435
06436
06437
06438 static tree
06439 cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr)
06440 {
06441 tree statement = NULL_TREE;
06442
06443
06444
06445 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06446 statement = cp_parser_expression (parser, false);
06447
06448
06449 cp_parser_consume_semicolon_at_end_of_statement (parser);
06450
06451 if (in_statement_expr
06452 && cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
06453
06454
06455 statement = finish_stmt_expr_expr (statement, in_statement_expr);
06456 else if (statement)
06457 statement = finish_expr_stmt (statement);
06458 else
06459 finish_stmt ();
06460
06461 return statement;
06462 }
06463
06464
06465
06466
06467
06468
06469
06470
06471 static tree
06472 cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr,
06473 bool in_try)
06474 {
06475 tree compound_stmt;
06476
06477
06478 if (!cp_parser_require (parser, CPP_OPEN_BRACE, "`{'"))
06479 return error_mark_node;
06480
06481 compound_stmt = begin_compound_stmt (in_try ? BCS_TRY_BLOCK : 0);
06482
06483 cp_parser_statement_seq_opt (parser, in_statement_expr);
06484
06485 finish_compound_stmt (compound_stmt);
06486
06487 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
06488
06489 return compound_stmt;
06490 }
06491
06492
06493
06494
06495
06496
06497
06498 static void
06499 cp_parser_statement_seq_opt (cp_parser* parser, tree in_statement_expr)
06500 {
06501
06502 while (true)
06503 {
06504 cp_token *token = cp_lexer_peek_token (parser->lexer);
06505
06506
06507 if (token->type == CPP_CLOSE_BRACE
06508 || token->type == CPP_EOF
06509 || token->type == CPP_PRAGMA_EOL)
06510 break;
06511
06512
06513 cp_parser_statement (parser, in_statement_expr, true);
06514 }
06515 }
06516
06517
06518
06519
06520
06521
06522
06523
06524
06525
06526 static tree
06527 cp_parser_selection_statement (cp_parser* parser)
06528 {
06529 cp_token *token;
06530 enum rid keyword;
06531
06532
06533 token = cp_parser_require (parser, CPP_KEYWORD, "selection-statement");
06534
06535
06536 keyword = token->keyword;
06537 switch (keyword)
06538 {
06539 case RID_IF:
06540 case RID_SWITCH:
06541 {
06542 tree statement;
06543 tree condition;
06544
06545
06546 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
06547 {
06548 cp_parser_skip_to_end_of_statement (parser);
06549 return error_mark_node;
06550 }
06551
06552
06553 if (keyword == RID_IF)
06554 statement = begin_if_stmt ();
06555 else
06556 statement = begin_switch_stmt ();
06557
06558
06559 condition = cp_parser_condition (parser);
06560
06561 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
06562 cp_parser_skip_to_closing_parenthesis (parser, true, false,
06563 true);
06564
06565 if (keyword == RID_IF)
06566 {
06567
06568 finish_if_stmt_cond (condition, statement);
06569
06570
06571 cp_parser_implicitly_scoped_statement (parser);
06572 finish_then_clause (statement);
06573
06574
06575 if (cp_lexer_next_token_is_keyword (parser->lexer,
06576 RID_ELSE))
06577 {
06578
06579 cp_lexer_consume_token (parser->lexer);
06580 begin_else_clause (statement);
06581
06582 cp_parser_implicitly_scoped_statement (parser);
06583 finish_else_clause (statement);
06584 }
06585
06586
06587 finish_if_stmt (statement);
06588 }
06589 else
06590 {
06591 bool in_switch_statement_p;
06592 unsigned char in_statement;
06593
06594
06595 finish_switch_cond (condition, statement);
06596
06597
06598 in_switch_statement_p = parser->in_switch_statement_p;
06599 in_statement = parser->in_statement;
06600 parser->in_switch_statement_p = true;
06601 parser->in_statement |= IN_SWITCH_STMT;
06602 cp_parser_implicitly_scoped_statement (parser);
06603 parser->in_switch_statement_p = in_switch_statement_p;
06604 parser->in_statement = in_statement;
06605
06606
06607 finish_switch_stmt (statement);
06608 }
06609
06610 return statement;
06611 }
06612 break;
06613
06614 default:
06615 cp_parser_error (parser, "expected selection-statement");
06616 return error_mark_node;
06617 }
06618 }
06619
06620
06621
06622
06623
06624
06625
06626
06627
06628
06629
06630
06631
06632
06633
06634 static tree
06635 cp_parser_condition (cp_parser* parser)
06636 {
06637 cp_decl_specifier_seq type_specifiers;
06638 const char *saved_message;
06639
06640
06641 cp_parser_parse_tentatively (parser);
06642
06643
06644 saved_message = parser->type_definition_forbidden_message;
06645 parser->type_definition_forbidden_message
06646 = "types may not be defined in conditions";
06647
06648 cp_parser_type_specifier_seq (parser, true,
06649 &type_specifiers);
06650
06651 parser->type_definition_forbidden_message = saved_message;
06652
06653 if (!cp_parser_error_occurred (parser))
06654 {
06655 tree decl;
06656 tree asm_specification;
06657 tree attributes;
06658 cp_declarator *declarator;
06659 tree initializer = NULL_TREE;
06660
06661
06662 declarator = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
06663 NULL,
06664 NULL,
06665 false);
06666
06667 attributes = cp_parser_attributes_opt (parser);
06668
06669 asm_specification = cp_parser_asm_specification_opt (parser);
06670
06671
06672
06673
06674
06675
06676
06677 cp_parser_require (parser, CPP_EQ, "`='");
06678
06679
06680 if (cp_parser_parse_definitely (parser))
06681 {
06682 tree pushed_scope;
06683 bool non_constant_p;
06684
06685
06686 decl = start_decl (declarator, &type_specifiers,
06687 true,
06688 attributes, NULL_TREE,
06689 &pushed_scope);
06690
06691 initializer
06692 = cp_parser_constant_expression (parser,
06693 true,
06694 &non_constant_p);
06695 if (!non_constant_p)
06696 initializer = fold_non_dependent_expr (initializer);
06697
06698
06699 cp_finish_decl (decl,
06700 initializer, !non_constant_p,
06701 asm_specification,
06702 LOOKUP_ONLYCONVERTING);
06703
06704 if (pushed_scope)
06705 pop_scope (pushed_scope);
06706
06707 return convert_from_reference (decl);
06708 }
06709 }
06710
06711
06712 else
06713 cp_parser_abort_tentative_parse (parser);
06714
06715
06716 return cp_parser_expression (parser, false);
06717 }
06718
06719
06720
06721
06722
06723
06724
06725
06726
06727
06728
06729 static tree
06730 cp_parser_iteration_statement (cp_parser* parser)
06731 {
06732 cp_token *token;
06733 enum rid keyword;
06734 tree statement;
06735 unsigned char in_statement;
06736
06737
06738 token = cp_parser_require (parser, CPP_KEYWORD, "iteration-statement");
06739 if (!token)
06740 return error_mark_node;
06741
06742
06743
06744 in_statement = parser->in_statement;
06745
06746
06747 keyword = token->keyword;
06748 switch (keyword)
06749 {
06750 case RID_WHILE:
06751 {
06752 tree condition;
06753
06754
06755 statement = begin_while_stmt ();
06756
06757 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06758
06759 condition = cp_parser_condition (parser);
06760 finish_while_stmt_cond (condition, statement);
06761
06762 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06763
06764 parser->in_statement = IN_ITERATION_STMT;
06765 cp_parser_already_scoped_statement (parser);
06766 parser->in_statement = in_statement;
06767
06768 finish_while_stmt (statement);
06769 }
06770 break;
06771
06772 case RID_DO:
06773 {
06774 tree expression;
06775
06776
06777 statement = begin_do_stmt ();
06778
06779 parser->in_statement = IN_ITERATION_STMT;
06780 cp_parser_implicitly_scoped_statement (parser);
06781 parser->in_statement = in_statement;
06782 finish_do_body (statement);
06783
06784 cp_parser_require_keyword (parser, RID_WHILE, "`while'");
06785
06786 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06787
06788 expression = cp_parser_expression (parser, false);
06789
06790 finish_do_stmt (expression, statement);
06791
06792 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06793
06794 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
06795 }
06796 break;
06797
06798 case RID_FOR:
06799 {
06800 tree condition = NULL_TREE;
06801 tree expression = NULL_TREE;
06802
06803
06804 statement = begin_for_stmt ();
06805
06806 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
06807
06808 cp_parser_for_init_statement (parser);
06809 finish_for_init_stmt (statement);
06810
06811
06812 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06813 condition = cp_parser_condition (parser);
06814 finish_for_cond (condition, statement);
06815
06816 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
06817
06818
06819 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
06820 expression = cp_parser_expression (parser, false);
06821 finish_for_expr (expression, statement);
06822
06823 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
06824
06825
06826 parser->in_statement = IN_ITERATION_STMT;
06827 cp_parser_already_scoped_statement (parser);
06828 parser->in_statement = in_statement;
06829
06830
06831 finish_for_stmt (statement);
06832 }
06833 break;
06834
06835 default:
06836 cp_parser_error (parser, "expected iteration-statement");
06837 statement = error_mark_node;
06838 break;
06839 }
06840
06841 return statement;
06842 }
06843
06844
06845
06846
06847
06848
06849
06850 static void
06851 cp_parser_for_init_statement (cp_parser* parser)
06852 {
06853
06854
06855
06856
06857
06858
06859 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06860 {
06861
06862
06863 cp_parser_parse_tentatively (parser);
06864
06865 cp_parser_simple_declaration (parser,
06866 false);
06867
06868
06869 if (cp_parser_parse_definitely (parser))
06870 return;
06871 }
06872
06873 cp_parser_expression_statement (parser, false);
06874 }
06875
06876
06877
06878
06879
06880
06881
06882
06883
06884
06885
06886
06887
06888
06889
06890
06891 static tree
06892 cp_parser_jump_statement (cp_parser* parser)
06893 {
06894 tree statement = error_mark_node;
06895 cp_token *token;
06896 enum rid keyword;
06897
06898
06899 token = cp_parser_require (parser, CPP_KEYWORD, "jump-statement");
06900 if (!token)
06901 return error_mark_node;
06902
06903
06904 keyword = token->keyword;
06905 switch (keyword)
06906 {
06907 case RID_BREAK:
06908 switch (parser->in_statement)
06909 {
06910 case 0:
06911 error ("break statement not within loop or switch");
06912 break;
06913 default:
06914 gcc_assert ((parser->in_statement & IN_SWITCH_STMT)
06915 || parser->in_statement == IN_ITERATION_STMT);
06916 statement = finish_break_stmt ();
06917 break;
06918 case IN_OMP_BLOCK:
06919 error ("invalid exit from OpenMP structured block");
06920 break;
06921 case IN_OMP_FOR:
06922 error ("break statement used with OpenMP for loop");
06923 break;
06924 }
06925 cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06926 break;
06927
06928 case RID_CONTINUE:
06929 switch (parser->in_statement & ~IN_SWITCH_STMT)
06930 {
06931 case 0:
06932 error ("continue statement not within a loop");
06933 break;
06934 case IN_ITERATION_STMT:
06935 case IN_OMP_FOR:
06936 statement = finish_continue_stmt ();
06937 break;
06938 case IN_OMP_BLOCK:
06939 error ("invalid exit from OpenMP structured block");
06940 break;
06941 default:
06942 gcc_unreachable ();
06943 }
06944 cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06945 break;
06946
06947 case RID_RETURN:
06948 {
06949 tree expr;
06950
06951
06952
06953 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
06954 expr = cp_parser_expression (parser, false);
06955 else
06956 expr = NULL_TREE;
06957
06958 statement = finish_return_stmt (expr);
06959
06960 cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06961 }
06962 break;
06963
06964 case RID_GOTO:
06965
06966 if (cp_lexer_next_token_is (parser->lexer, CPP_MULT))
06967 {
06968
06969 if (pedantic)
06970 pedwarn ("ISO C++ forbids computed gotos");
06971
06972 cp_lexer_consume_token (parser->lexer);
06973
06974 finish_goto_stmt (cp_parser_expression (parser, false));
06975 }
06976 else
06977 finish_goto_stmt (cp_parser_identifier (parser));
06978
06979 cp_parser_require (parser, CPP_SEMICOLON, "%<;%>");
06980 break;
06981
06982 default:
06983 cp_parser_error (parser, "expected jump-statement");
06984 break;
06985 }
06986
06987 return statement;
06988 }
06989
06990
06991
06992
06993
06994
06995 static void
06996 cp_parser_declaration_statement (cp_parser* parser)
06997 {
06998 void *p;
06999
07000
07001 p = obstack_alloc (&declarator_obstack, 0);
07002
07003
07004 cp_parser_block_declaration (parser, true);
07005
07006
07007 obstack_free (&declarator_obstack, p);
07008
07009
07010 finish_stmt ();
07011 }
07012
07013
07014
07015
07016
07017
07018
07019
07020
07021
07022
07023
07024 static tree
07025 cp_parser_implicitly_scoped_statement (cp_parser* parser)
07026 {
07027 tree statement;
07028
07029
07030 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
07031 {
07032 cp_lexer_consume_token (parser->lexer);
07033 statement = add_stmt (build_empty_stmt ());
07034 }
07035
07036 else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
07037 statement = cp_parser_compound_statement (parser, NULL, false);
07038
07039 else
07040 {
07041
07042 statement = begin_compound_stmt (0);
07043
07044 cp_parser_statement (parser, NULL_TREE, false);
07045
07046 finish_compound_stmt (statement);
07047 }
07048
07049
07050 return statement;
07051 }
07052
07053
07054
07055
07056
07057
07058 static void
07059 cp_parser_already_scoped_statement (cp_parser* parser)
07060 {
07061
07062 if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
07063 cp_parser_statement (parser, NULL_TREE, false);
07064 else
07065 {
07066
07067
07068 cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
07069 cp_parser_statement_seq_opt (parser, NULL_TREE);
07070 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
07071 }
07072 }
07073
07074
07075
07076
07077
07078
07079
07080
07081
07082 static void
07083 cp_parser_declaration_seq_opt (cp_parser* parser)
07084 {
07085 while (true)
07086 {
07087 cp_token *token;
07088
07089 token = cp_lexer_peek_token (parser->lexer);
07090
07091 if (token->type == CPP_CLOSE_BRACE
07092 || token->type == CPP_EOF
07093 || token->type == CPP_PRAGMA_EOL)
07094 break;
07095
07096 if (token->type == CPP_SEMICOLON)
07097 {
07098
07099
07100 cp_lexer_consume_token (parser->lexer);
07101 if (pedantic && !in_system_header)
07102 pedwarn ("extra %<;%>");
07103 continue;
07104 }
07105
07106
07107
07108 if (!parser->implicit_extern_c && token->implicit_extern_c)
07109 {
07110 push_lang_context (lang_name_c);
07111 parser->implicit_extern_c = true;
07112 }
07113 else if (parser->implicit_extern_c && !token->implicit_extern_c)
07114 {
07115 pop_lang_context ();
07116 parser->implicit_extern_c = false;
07117 }
07118
07119 if (token->type == CPP_PRAGMA)
07120 {
07121
07122
07123
07124
07125 cp_parser_pragma (parser, pragma_external);
07126 continue;
07127 }
07128
07129
07130 cp_parser_declaration (parser);
07131 }
07132 }
07133
07134
07135
07136
07137
07138
07139
07140
07141
07142
07143
07144
07145
07146
07147
07148
07149
07150 static void
07151 cp_parser_declaration (cp_parser* parser)
07152 {
07153 cp_token token1;
07154 cp_token token2;
07155 int saved_pedantic;
07156 void *p;
07157
07158
07159 if (cp_parser_extension_opt (parser, &saved_pedantic))
07160 {
07161
07162 cp_parser_declaration (parser);
07163
07164 pedantic = saved_pedantic;
07165
07166 return;
07167 }
07168
07169
07170 token1 = *cp_lexer_peek_token (parser->lexer);
07171
07172 if (token1.type != CPP_EOF)
07173 token2 = *cp_lexer_peek_nth_token (parser->lexer, 2);
07174 else
07175 {
07176 token2.type = CPP_EOF;
07177 token2.keyword = RID_MAX;
07178 }
07179
07180
07181 p = obstack_alloc (&declarator_obstack, 0);
07182
07183
07184
07185 if (token1.keyword == RID_EXTERN
07186 && cp_parser_is_string_literal (&token2))
07187 cp_parser_linkage_specification (parser);
07188
07189
07190
07191 else if (token1.keyword == RID_TEMPLATE)
07192 {
07193
07194 if (token2.type == CPP_LESS
07195 && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_GREATER)
07196 cp_parser_explicit_specialization (parser);
07197
07198 else if (token2.type == CPP_LESS)
07199 cp_parser_template_declaration (parser, false);
07200
07201 else
07202 cp_parser_explicit_instantiation (parser);
07203 }
07204
07205
07206 else if (token1.keyword == RID_EXPORT)
07207 cp_parser_template_declaration (parser, false);
07208
07209
07210
07211 else if (cp_parser_allow_gnu_extensions_p (parser)
07212 && (token1.keyword == RID_EXTERN
07213 || token1.keyword == RID_STATIC
07214 || token1.keyword == RID_INLINE)
07215 && token2.keyword == RID_TEMPLATE)
07216 cp_parser_explicit_instantiation (parser);
07217
07218
07219 else if (token1.keyword == RID_NAMESPACE
07220 && (
07221 (token2.type == CPP_NAME
07222 && (cp_lexer_peek_nth_token (parser->lexer, 3)->type
07223 != CPP_EQ))
07224
07225 || token2.type == CPP_OPEN_BRACE
07226 || token2.keyword == RID_ATTRIBUTE))
07227 cp_parser_namespace_definition (parser);
07228
07229 else if (c_dialect_objc () && OBJC_IS_AT_KEYWORD (token1.keyword))
07230 cp_parser_objc_declaration (parser);
07231
07232
07233 else
07234
07235 cp_parser_block_declaration (parser, false);
07236
07237
07238 obstack_free (&declarator_obstack, p);
07239 }
07240
07241
07242
07243
07244
07245
07246
07247
07248
07249
07250
07251
07252
07253
07254
07255
07256
07257
07258
07259 static void
07260 cp_parser_block_declaration (cp_parser *parser,
07261 bool statement_p)
07262 {
07263 cp_token *token1;
07264 int saved_pedantic;
07265
07266
07267 if (cp_parser_extension_opt (parser, &saved_pedantic))
07268 {
07269
07270 cp_parser_block_declaration (parser, statement_p);
07271
07272 pedantic = saved_pedantic;
07273
07274 return;
07275 }
07276
07277
07278
07279 token1 = cp_lexer_peek_token (parser->lexer);
07280
07281
07282 if (token1->keyword == RID_ASM)
07283 {
07284 if (statement_p)
07285 cp_parser_commit_to_tentative_parse (parser);
07286 cp_parser_asm_definition (parser);
07287 }
07288
07289
07290 else if (token1->keyword == RID_NAMESPACE)
07291 cp_parser_namespace_alias_definition (parser);
07292
07293
07294 else if (token1->keyword == RID_USING)
07295 {
07296 cp_token *token2;
07297
07298 if (statement_p)
07299 cp_parser_commit_to_tentative_parse (parser);
07300
07301
07302 token2 = cp_lexer_peek_nth_token (parser->lexer, 2);
07303 if (token2->keyword == RID_NAMESPACE)
07304 cp_parser_using_directive (parser);
07305
07306 else
07307 cp_parser_using_declaration (parser,
07308 false);
07309 }
07310
07311 else if (token1->keyword == RID_LABEL)
07312 {
07313 if (statement_p)
07314 cp_parser_commit_to_tentative_parse (parser);
07315 cp_parser_label_declaration (parser);
07316 }
07317
07318 else
07319 cp_parser_simple_declaration (parser, !statement_p);
07320 }
07321
07322
07323
07324
07325
07326
07327
07328
07329
07330
07331
07332
07333
07334 static void
07335 cp_parser_simple_declaration (cp_parser* parser,
07336 bool function_definition_allowed_p)
07337 {
07338 cp_decl_specifier_seq decl_specifiers;
07339 int declares_class_or_enum;
07340 bool saw_declarator;
07341
07342
07343
07344
07345 push_deferring_access_checks (dk_deferred);
07346
07347
07348
07349
07350
07351
07352
07353
07354
07355
07356
07357
07358 cp_parser_decl_specifier_seq (parser,
07359 CP_PARSER_FLAGS_OPTIONAL,
07360 &decl_specifiers,
07361 &declares_class_or_enum);
07362
07363 stop_deferring_access_checks ();
07364
07365
07366
07367
07368 if (!function_definition_allowed_p
07369 && !decl_specifiers.any_specifiers_p)
07370 {
07371 cp_parser_error (parser, "expected declaration");
07372 goto done;
07373 }
07374
07375
07376
07377
07378
07379
07380
07381 if (!decl_specifiers.type
07382 && cp_parser_parse_and_diagnose_invalid_type_name (parser))
07383 {
07384
07385
07386 cp_parser_commit_to_tentative_parse (parser);
07387
07388 goto done;
07389 }
07390
07391
07392
07393
07394 if (decl_specifiers.any_specifiers_p
07395 && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
07396 cp_parser_commit_to_tentative_parse (parser);
07397
07398
07399
07400 saw_declarator = false;
07401 while (cp_lexer_next_token_is_not (parser->lexer,
07402 CPP_SEMICOLON))
07403 {
07404 cp_token *token;
07405 bool function_definition_p;
07406 tree decl;
07407
07408 if (saw_declarator)
07409 {
07410
07411 token = cp_lexer_peek_token (parser->lexer);
07412 gcc_assert (token->type == CPP_COMMA);
07413 cp_lexer_consume_token (parser->lexer);
07414 }
07415 else
07416 saw_declarator = true;
07417
07418
07419 decl = cp_parser_init_declarator (parser, &decl_specifiers,
07420 NULL,
07421 function_definition_allowed_p,
07422 false,
07423 declares_class_or_enum,
07424 &function_definition_p);
07425
07426
07427
07428
07429 if (cp_parser_error_occurred (parser))
07430 goto done;
07431
07432 if (function_definition_p)
07433 {
07434
07435
07436
07437
07438
07439
07440 if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
07441 error ("mixing declarations and function-definitions is forbidden");
07442
07443 else
07444 {
07445 pop_deferring_access_checks ();
07446 return;
07447 }
07448 }
07449
07450 token = cp_lexer_peek_token (parser->lexer);
07451
07452 if (token->type == CPP_COMMA)
07453 ;
07454
07455 else if (token->type == CPP_SEMICOLON)
07456 break;
07457
07458 else
07459 {
07460
07461
07462 if (decl != error_mark_node
07463 || cp_parser_uncommitted_to_tentative_parse_p (parser))
07464 cp_parser_error (parser, "expected %<,%> or %<;%>");
07465
07466 cp_parser_skip_to_end_of_statement (parser);
07467
07468 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
07469 cp_lexer_consume_token (parser->lexer);
07470 goto done;
07471 }
07472
07473
07474
07475
07476
07477
07478 function_definition_allowed_p = false;
07479 }
07480
07481
07482
07483
07484 if (!saw_declarator)
07485 {
07486 if (cp_parser_declares_only_class_p (parser))
07487 shadow_tag (&decl_specifiers);
07488
07489 perform_deferred_access_checks ();
07490 }
07491
07492
07493 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
07494
07495 done:
07496 pop_deferring_access_checks ();
07497 }
07498
07499
07500
07501
07502
07503
07504
07505
07506
07507
07508
07509
07510
07511
07512
07513
07514
07515
07516
07517
07518
07519
07520
07521
07522
07523
07524
07525
07526
07527
07528
07529
07530 static void
07531 cp_parser_decl_specifier_seq (cp_parser* parser,
07532 cp_parser_flags flags,
07533 cp_decl_specifier_seq *decl_specs,
07534 int* declares_class_or_enum)
07535 {
07536 bool constructor_possible_p = !parser->in_declarator_p;
07537
07538
07539 clear_decl_specs (decl_specs);
07540
07541
07542 *declares_class_or_enum = 0;
07543
07544
07545 while (true)
07546 {
07547 bool constructor_p;
07548 bool found_decl_spec;
07549 cp_token *token;
07550
07551
07552 token = cp_lexer_peek_token (parser->lexer);
07553
07554 if (token->keyword == RID_ATTRIBUTE)
07555 {
07556
07557 decl_specs->attributes
07558 = chainon (decl_specs->attributes,
07559 cp_parser_attributes_opt (parser));
07560 continue;
07561 }
07562
07563 found_decl_spec = true;
07564
07565
07566 switch (token->keyword)
07567 {
07568
07569
07570 case RID_FRIEND:
07571 if (!at_class_scope_p ())
07572 {
07573 error ("%<friend%> used outside of class");
07574 cp_lexer_purge_token (parser->lexer);
07575 }
07576 else
07577 {
07578 ++decl_specs->specs[(int) ds_friend];
07579
07580 cp_lexer_consume_token (parser->lexer);
07581 }
07582 break;
07583
07584
07585
07586
07587
07588 case RID_INLINE:
07589 case RID_VIRTUAL:
07590 case RID_EXPLICIT:
07591 cp_parser_function_specifier_opt (parser, decl_specs);
07592 break;
07593
07594
07595
07596 case RID_TYPEDEF:
07597 ++decl_specs->specs[(int) ds_typedef];
07598
07599 cp_lexer_consume_token (parser->lexer);
07600
07601 constructor_possible_p = false;
07602
07603
07604 cp_parser_commit_to_tentative_parse (parser);
07605
07606 if (decl_specs->storage_class != sc_none)
07607 decl_specs->conflicting_specifiers_p = true;
07608 break;
07609
07610
07611
07612
07613
07614
07615
07616
07617
07618
07619 case RID_AUTO:
07620 case RID_REGISTER:
07621 case RID_STATIC:
07622 case RID_EXTERN:
07623 case RID_MUTABLE:
07624
07625 cp_lexer_consume_token (parser->lexer);
07626 cp_parser_set_storage_class (parser, decl_specs, token->keyword);
07627 break;
07628 case RID_THREAD:
07629
07630 cp_lexer_consume_token (parser->lexer);
07631 ++decl_specs->specs[(int) ds_thread];
07632 break;
07633
07634 default:
07635
07636 found_decl_spec = false;
07637 break;
07638 }
07639
07640
07641
07642 constructor_p
07643 = (!found_decl_spec
07644 && constructor_possible_p
07645 && (cp_parser_constructor_declarator_p
07646 (parser, decl_specs->specs[(int) ds_friend] != 0)));
07647
07648
07649
07650 if (!found_decl_spec && !constructor_p)
07651 {
07652 int decl_spec_declares_class_or_enum;
07653 bool is_cv_qualifier;
07654 tree type_spec;
07655
07656 type_spec
07657 = cp_parser_type_specifier (parser, flags,
07658 decl_specs,
07659 true,
07660 &decl_spec_declares_class_or_enum,
07661 &is_cv_qualifier);
07662
07663 *declares_class_or_enum |= decl_spec_declares_class_or_enum;
07664
07665
07666
07667
07668
07669
07670
07671
07672
07673
07674
07675
07676
07677
07678
07679
07680
07681
07682
07683
07684
07685
07686
07687
07688
07689
07690
07691
07692
07693
07694
07695
07696
07697
07698
07699
07700
07701 if (type_spec && !is_cv_qualifier)
07702 flags |= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES;
07703
07704 if (type_spec)
07705 {
07706 constructor_possible_p = false;
07707 found_decl_spec = true;
07708 }
07709 }
07710
07711
07712
07713 if (!found_decl_spec)
07714 break;
07715
07716 decl_specs->any_specifiers_p = true;
07717
07718
07719 flags |= CP_PARSER_FLAGS_OPTIONAL;
07720 }
07721
07722 cp_parser_check_decl_spec (decl_specs);
07723
07724
07725 if (decl_specs->specs[(int) ds_friend] != 0
07726 && (*declares_class_or_enum & 2))
07727 error ("class definition may not be declared a friend");
07728 }
07729
07730
07731
07732
07733
07734
07735
07736
07737
07738
07739
07740
07741
07742
07743
07744
07745
07746 static tree
07747 cp_parser_storage_class_specifier_opt (cp_parser* parser)
07748 {
07749 switch (cp_lexer_peek_token (parser->lexer)->keyword)
07750 {
07751 case RID_AUTO:
07752 case RID_REGISTER:
07753 case RID_STATIC:
07754 case RID_EXTERN:
07755 case RID_MUTABLE:
07756 case RID_THREAD:
07757
07758 return cp_lexer_consume_token (parser->lexer)->u.value;
07759
07760 default:
07761 return NULL_TREE;
07762 }
07763 }
07764
07765
07766
07767
07768
07769
07770
07771
07772
07773
07774
07775 static tree
07776 cp_parser_function_specifier_opt (cp_parser* parser,
07777 cp_decl_specifier_seq *decl_specs)
07778 {
07779 switch (cp_lexer_peek_token (parser->lexer)->keyword)
07780 {
07781 case RID_INLINE:
07782 if (decl_specs)
07783 ++decl_specs->specs[(int) ds_inline];
07784 break;
07785
07786 case RID_VIRTUAL:
07787
07788
07789
07790 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
07791 error ("templates may not be %<virtual%>");
07792 else if (decl_specs)
07793 ++decl_specs->specs[(int) ds_virtual];
07794 break;
07795
07796 case RID_EXPLICIT:
07797 if (decl_specs)
07798 ++decl_specs->specs[(int) ds_explicit];
07799 break;
07800
07801 default:
07802 return NULL_TREE;
07803 }
07804
07805
07806 return cp_lexer_consume_token (parser->lexer)->u.value;
07807 }
07808
07809
07810
07811
07812
07813
07814
07815 static void
07816 cp_parser_linkage_specification (cp_parser* parser)
07817 {
07818 tree linkage;
07819
07820
07821 cp_parser_require_keyword (parser, RID_EXTERN, "`extern'");
07822
07823
07824 linkage = cp_parser_string_literal (parser, false, false);
07825
07826
07827
07828
07829 if (strlen (TREE_STRING_POINTER (linkage))
07830 != (size_t) (TREE_STRING_LENGTH (linkage) - 1))
07831 {
07832 cp_parser_error (parser, "invalid linkage-specification");
07833
07834 linkage = lang_name_cplusplus;
07835 }
07836 else
07837 linkage = get_identifier (TREE_STRING_POINTER (linkage));
07838
07839
07840 push_lang_context (linkage);
07841
07842
07843
07844 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
07845 {
07846
07847 cp_lexer_consume_token (parser->lexer);
07848
07849 cp_parser_declaration_seq_opt (parser);
07850
07851 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
07852 }
07853
07854 else
07855 {
07856 bool saved_in_unbraced_linkage_specification_p;
07857
07858 saved_in_unbraced_linkage_specification_p
07859 = parser->in_unbraced_linkage_specification_p;
07860 parser->in_unbraced_linkage_specification_p = true;
07861 cp_parser_declaration (parser);
07862 parser->in_unbraced_linkage_specification_p
07863 = saved_in_unbraced_linkage_specification_p;
07864 }
07865
07866
07867 pop_lang_context ();
07868 }
07869
07870
07871
07872
07873
07874
07875
07876
07877
07878
07879 static tree
07880 cp_parser_conversion_function_id (cp_parser* parser)
07881 {
07882 tree type;
07883 tree saved_scope;
07884 tree saved_qualifying_scope;
07885 tree saved_object_scope;
07886 tree pushed_scope = NULL_TREE;
07887
07888
07889 if (!cp_parser_require_keyword (parser, RID_OPERATOR, "`operator'"))
07890 return error_mark_node;
07891
07892
07893
07894 saved_scope = parser->scope;
07895 saved_qualifying_scope = parser->qualifying_scope;
07896 saved_object_scope = parser->object_scope;
07897
07898
07899
07900
07901
07902
07903
07904
07905
07906
07907
07908
07909
07910 if (saved_scope)
07911 pushed_scope = push_scope (saved_scope);
07912
07913 type = cp_parser_conversion_type_id (parser);
07914
07915 if (pushed_scope)
07916 pop_scope (pushed_scope);
07917
07918 parser->scope = saved_scope;
07919 parser->qualifying_scope = saved_qualifying_scope;
07920 parser->object_scope = saved_object_scope;
07921
07922 if (type == error_mark_node)
07923 return error_mark_node;
07924 return mangle_conv_op_name_for_type (type);
07925 }
07926
07927
07928
07929
07930
07931
07932
07933
07934 static tree
07935 cp_parser_conversion_type_id (cp_parser* parser)
07936 {
07937 tree attributes;
07938 cp_decl_specifier_seq type_specifiers;
07939 cp_declarator *declarator;
07940 tree type_specified;
07941
07942
07943 attributes = cp_parser_attributes_opt (parser);
07944
07945 cp_parser_type_specifier_seq (parser, false,
07946 &type_specifiers);
07947
07948 if (type_specifiers.type == error_mark_node)
07949 return error_mark_node;
07950
07951 declarator = cp_parser_conversion_declarator_opt (parser);
07952
07953 type_specified = grokdeclarator (declarator, &type_specifiers, TYPENAME,
07954 0, &attributes);
07955 if (attributes)
07956 cplus_decl_attributes (&type_specified, attributes, 0);
07957 return type_specified;
07958 }
07959
07960
07961
07962
07963
07964
07965
07966
07967 static cp_declarator *
07968 cp_parser_conversion_declarator_opt (cp_parser* parser)
07969 {
07970 enum tree_code code;
07971 tree class_type;
07972 cp_cv_quals cv_quals;
07973
07974
07975 cp_parser_parse_tentatively (parser);
07976
07977 code = cp_parser_ptr_operator (parser, &class_type, &cv_quals);
07978
07979 if (cp_parser_parse_definitely (parser))
07980 {
07981 cp_declarator *declarator;
07982
07983
07984 declarator = cp_parser_conversion_declarator_opt (parser);
07985
07986
07987 if (class_type)
07988 declarator = make_ptrmem_declarator (cv_quals, class_type,
07989 declarator);
07990 else if (code == INDIRECT_REF)
07991 declarator = make_pointer_declarator (cv_quals, declarator);
07992 else
07993 declarator = make_reference_declarator (cv_quals, declarator);
07994
07995 return declarator;
07996 }
07997
07998 return NULL;
07999 }
08000
08001
08002
08003
08004
08005
08006
08007
08008 static bool
08009 cp_parser_ctor_initializer_opt (cp_parser* parser)
08010 {
08011
08012
08013 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
08014 {
08015
08016 if (DECL_CONSTRUCTOR_P (current_function_decl))
08017 finish_mem_initializers (NULL_TREE);
08018
08019 return false;
08020 }
08021
08022
08023 cp_lexer_consume_token (parser->lexer);
08024
08025 cp_parser_mem_initializer_list (parser);
08026
08027 return true;
08028 }
08029
08030
08031
08032
08033
08034
08035
08036 static void
08037 cp_parser_mem_initializer_list (cp_parser* parser)
08038 {
08039 tree mem_initializer_list = NULL_TREE;
08040
08041
08042
08043 if (!DECL_CONSTRUCTOR_P (current_function_decl))
08044 error ("only constructors take base initializers");
08045
08046
08047 while (true)
08048 {
08049 tree mem_initializer;
08050
08051
08052 mem_initializer = cp_parser_mem_initializer (parser);
08053
08054 if (mem_initializer != error_mark_node)
08055 {
08056 TREE_CHAIN (mem_initializer) = mem_initializer_list;
08057 mem_initializer_list = mem_initializer;
08058 }
08059
08060 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
08061 break;
08062
08063 cp_lexer_consume_token (parser->lexer);
08064 }
08065
08066
08067 if (DECL_CONSTRUCTOR_P (current_function_decl))
08068 finish_mem_initializers (mem_initializer_list);
08069 }
08070
08071
08072
08073
08074
08075
08076
08077
08078
08079
08080
08081
08082
08083
08084
08085
08086 static tree
08087 cp_parser_mem_initializer (cp_parser* parser)
08088 {
08089 tree mem_initializer_id;
08090 tree expression_list;
08091 tree member;
08092
08093
08094 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
08095 {
08096 pedwarn ("anachronistic old-style base class initializer");
08097 mem_initializer_id = NULL_TREE;
08098 }
08099 else
08100 mem_initializer_id = cp_parser_mem_initializer_id (parser);
08101 member = expand_member_init (mem_initializer_id);
08102 if (member && !DECL_P (member))
08103 in_base_initializer = 1;
08104
08105 expression_list
08106 = cp_parser_parenthesized_expression_list (parser, false,
08107 false,
08108 NULL);
08109 if (expression_list == error_mark_node)
08110 return error_mark_node;
08111 if (!expression_list)
08112 expression_list = void_type_node;
08113
08114 in_base_initializer = 0;
08115
08116 return member ? build_tree_list (member, expression_list) : error_mark_node;
08117 }
08118
08119
08120
08121
08122
08123
08124
08125
08126
08127
08128
08129 static tree
08130 cp_parser_mem_initializer_id (cp_parser* parser)
08131 {
08132 bool global_scope_p;
08133 bool nested_name_specifier_p;
08134 bool template_p = false;
08135 tree id;
08136
08137
08138 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME))
08139 {
08140 error ("keyword %<typename%> not allowed in this context (a qualified "
08141 "member initializer is implicitly a type)");
08142 cp_lexer_consume_token (parser->lexer);
08143 }
08144
08145 global_scope_p
08146 = (cp_parser_global_scope_opt (parser,
08147 false)
08148 != NULL_TREE);
08149
08150
08151
08152
08153
08154
08155
08156
08157
08158
08159
08160
08161 nested_name_specifier_p
08162 = (cp_parser_nested_name_specifier_opt (parser,
08163 true,
08164 true,
08165 true,
08166 true)
08167 != NULL_TREE);
08168 if (nested_name_specifier_p)
08169 template_p = cp_parser_optional_template_keyword (parser);
08170
08171
08172 if (global_scope_p || nested_name_specifier_p)
08173 return cp_parser_class_name (parser,
08174 true,
08175 template_p,
08176 none_type,
08177 true,
08178 false,
08179 true);
08180
08181 cp_parser_parse_tentatively (parser);
08182
08183 id = cp_parser_class_name (parser,
08184 true,
08185 false,
08186 none_type,
08187 true,
08188 false,
08189 true);
08190
08191 if (cp_parser_parse_definitely (parser))
08192 return id;
08193
08194 return cp_parser_identifier (parser);
08195 }
08196
08197
08198
08199
08200
08201
08202
08203
08204
08205
08206
08207 static tree
08208 cp_parser_operator_function_id (cp_parser* parser)
08209 {
08210
08211 if (!cp_parser_require_keyword (parser, RID_OPERATOR, "`operator'"))
08212 return error_mark_node;
08213
08214 return cp_parser_operator (parser);
08215 }
08216
08217
08218
08219
08220
08221
08222
08223
08224
08225
08226
08227
08228
08229
08230
08231
08232 static tree
08233 cp_parser_operator (cp_parser* parser)
08234 {
08235 tree id = NULL_TREE;
08236 cp_token *token;
08237
08238
08239 token = cp_lexer_peek_token (parser->lexer);
08240
08241 switch (token->type)
08242 {
08243 case CPP_KEYWORD:
08244 {
08245 enum tree_code op;
08246
08247
08248 if (token->keyword == RID_NEW)
08249 op = NEW_EXPR;
08250 else if (token->keyword == RID_DELETE)
08251 op = DELETE_EXPR;
08252 else
08253 break;
08254
08255
08256 cp_lexer_consume_token (parser->lexer);
08257
08258
08259 token = cp_lexer_peek_token (parser->lexer);
08260
08261
08262 if (token->type == CPP_OPEN_SQUARE)
08263 {
08264
08265 cp_lexer_consume_token (parser->lexer);
08266
08267 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
08268 id = ansi_opname (op == NEW_EXPR
08269 ? VEC_NEW_EXPR : VEC_DELETE_EXPR);
08270 }
08271
08272 else
08273 id = ansi_opname (op);
08274
08275 return id;
08276 }
08277
08278 case CPP_PLUS:
08279 id = ansi_opname (PLUS_EXPR);
08280 break;
08281
08282 case CPP_MINUS:
08283 id = ansi_opname (MINUS_EXPR);
08284 break;
08285
08286 case CPP_MULT:
08287 id = ansi_opname (MULT_EXPR);
08288 break;
08289
08290 case CPP_DIV:
08291 id = ansi_opname (TRUNC_DIV_EXPR);
08292 break;
08293
08294 case CPP_MOD:
08295 id = ansi_opname (TRUNC_MOD_EXPR);
08296 break;
08297
08298 case CPP_XOR:
08299 id = ansi_opname (BIT_XOR_EXPR);
08300 break;
08301
08302 case CPP_AND:
08303 id = ansi_opname (BIT_AND_EXPR);
08304 break;
08305
08306 case CPP_OR:
08307 id = ansi_opname (BIT_IOR_EXPR);
08308 break;
08309
08310 case CPP_COMPL:
08311 id = ansi_opname (BIT_NOT_EXPR);
08312 break;
08313
08314 case CPP_NOT:
08315 id = ansi_opname (TRUTH_NOT_EXPR);
08316 break;
08317
08318 case CPP_EQ:
08319 id = ansi_assopname (NOP_EXPR);
08320 break;
08321
08322 case CPP_LESS:
08323 id = ansi_opname (LT_EXPR);
08324 break;
08325
08326 case CPP_GREATER:
08327 id = ansi_opname (GT_EXPR);
08328 break;
08329
08330 case CPP_PLUS_EQ:
08331 id = ansi_assopname (PLUS_EXPR);
08332 break;
08333
08334 case CPP_MINUS_EQ:
08335 id = ansi_assopname (MINUS_EXPR);
08336 break;
08337
08338 case CPP_MULT_EQ:
08339 id = ansi_assopname (MULT_EXPR);
08340 break;
08341
08342 case CPP_DIV_EQ:
08343 id = ansi_assopname (TRUNC_DIV_EXPR);
08344 break;
08345
08346 case CPP_MOD_EQ:
08347 id = ansi_assopname (TRUNC_MOD_EXPR);
08348 break;
08349
08350 case CPP_XOR_EQ:
08351 id = ansi_assopname (BIT_XOR_EXPR);
08352 break;
08353
08354 case CPP_AND_EQ:
08355 id = ansi_assopname (BIT_AND_EXPR);
08356 break;
08357
08358 case CPP_OR_EQ:
08359 id = ansi_assopname (BIT_IOR_EXPR);
08360 break;
08361
08362 case CPP_LSHIFT:
08363 id = ansi_opname (LSHIFT_EXPR);
08364 break;
08365
08366 case CPP_RSHIFT:
08367 id = ansi_opname (RSHIFT_EXPR);
08368 break;
08369
08370 case CPP_LSHIFT_EQ:
08371 id = ansi_assopname (LSHIFT_EXPR);
08372 break;
08373
08374 case CPP_RSHIFT_EQ:
08375 id = ansi_assopname (RSHIFT_EXPR);
08376 break;
08377
08378 case CPP_EQ_EQ:
08379 id = ansi_opname (EQ_EXPR);
08380 break;
08381
08382 case CPP_NOT_EQ:
08383 id = ansi_opname (NE_EXPR);
08384 break;
08385
08386 case CPP_LESS_EQ:
08387 id = ansi_opname (LE_EXPR);
08388 break;
08389
08390 case CPP_GREATER_EQ:
08391 id = ansi_opname (GE_EXPR);
08392 break;
08393
08394 case CPP_AND_AND:
08395 id = ansi_opname (TRUTH_ANDIF_EXPR);
08396 break;
08397
08398 case CPP_OR_OR:
08399 id = ansi_opname (TRUTH_ORIF_EXPR);
08400 break;
08401
08402 case CPP_PLUS_PLUS:
08403 id = ansi_opname (POSTINCREMENT_EXPR);
08404 break;
08405
08406 case CPP_MINUS_MINUS:
08407 id = ansi_opname (PREDECREMENT_EXPR);
08408 break;
08409
08410 case CPP_COMMA:
08411 id = ansi_opname (COMPOUND_EXPR);
08412 break;
08413
08414 case CPP_DEREF_STAR:
08415 id = ansi_opname (MEMBER_REF);
08416 break;
08417
08418 case CPP_DEREF:
08419 id = ansi_opname (COMPONENT_REF);
08420 break;
08421
08422 case CPP_OPEN_PAREN:
08423
08424 cp_lexer_consume_token (parser->lexer);
08425
08426 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
08427 return ansi_opname (CALL_EXPR);
08428
08429 case CPP_OPEN_SQUARE:
08430
08431 cp_lexer_consume_token (parser->lexer);
08432
08433 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
08434 return ansi_opname (ARRAY_REF);
08435
08436 default:
08437
08438 break;
08439 }
08440
08441
08442
08443 if (id)
08444 cp_lexer_consume_token (parser->lexer);
08445
08446 else
08447 {
08448 cp_parser_error (parser, "expected operator");
08449 id = error_mark_node;
08450 }
08451
08452 return id;
08453 }
08454
08455
08456
08457
08458
08459
08460
08461
08462
08463
08464
08465
08466
08467
08468
08469
08470
08471
08472
08473
08474
08475
08476 static void
08477 cp_parser_template_declaration (cp_parser* parser, bool member_p)
08478 {
08479
08480 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_EXPORT))
08481 {
08482
08483 cp_lexer_consume_token (parser->lexer);
08484
08485 warning (0, "keyword %<export%> not implemented, and will be ignored");
08486 }
08487
08488 cp_parser_template_declaration_after_export (parser, member_p);
08489 }
08490
08491
08492
08493
08494
08495
08496
08497
08498
08499
08500 static tree
08501 cp_parser_template_parameter_list (cp_parser* parser)
08502 {
08503 tree parameter_list = NULL_TREE;
08504
08505 begin_template_parm_list ();
08506 while (true)
08507 {
08508 tree parameter;
08509 cp_token *token;
08510 bool is_non_type;
08511
08512
08513 parameter = cp_parser_template_parameter (parser, &is_non_type);
08514
08515 if (parameter != error_mark_node)
08516 parameter_list = process_template_parm (parameter_list,
08517 parameter,
08518 is_non_type);
08519 else
08520 {
08521 tree err_parm = build_tree_list (parameter, parameter);
08522 TREE_VALUE (err_parm) = error_mark_node;
08523 parameter_list = chainon (parameter_list, err_parm);
08524 }
08525
08526
08527 token = cp_lexer_peek_token (parser->lexer);
08528
08529 if (token->type != CPP_COMMA)
08530 break;
08531
08532 cp_lexer_consume_token (parser->lexer);
08533 }
08534
08535 return end_template_parm_list (parameter_list);
08536 }
08537
08538
08539
08540
08541
08542
08543
08544
08545
08546
08547
08548
08549 static tree
08550 cp_parser_template_parameter (cp_parser* parser, bool *is_non_type)
08551 {
08552 cp_token *token;
08553 cp_parameter_declarator *parameter_declarator;
08554 tree parm;
08555
08556
08557 *is_non_type = false;
08558
08559 token = cp_lexer_peek_token (parser->lexer);
08560
08561 if (token->keyword == RID_TEMPLATE)
08562 return cp_parser_type_parameter (parser);
08563
08564
08565
08566
08567
08568
08569
08570
08571
08572
08573
08574
08575
08576 if (token->keyword == RID_TYPENAME || token->keyword == RID_CLASS)
08577 {
08578
08579 token = cp_lexer_peek_nth_token (parser->lexer, 2);
08580
08581 if (token->type == CPP_NAME)
08582 token = cp_lexer_peek_nth_token (parser->lexer, 3);
08583
08584
08585 if (token->type == CPP_COMMA
08586 || token->type == CPP_EQ
08587 || token->type == CPP_GREATER)
08588 return cp_parser_type_parameter (parser);
08589 }
08590
08591
08592
08593
08594
08595
08596
08597
08598
08599 *is_non_type = true;
08600 parameter_declarator
08601 = cp_parser_parameter_declaration (parser, true,
08602 NULL);
08603 parm = grokdeclarator (parameter_declarator->declarator,
08604 ¶meter_declarator->decl_specifiers,
08605 PARM, 0,
08606 NULL);
08607 if (parm == error_mark_node)
08608 return error_mark_node;
08609 return build_tree_list (parameter_declarator->default_argument, parm);
08610 }
08611
08612
08613
08614
08615
08616
08617
08618
08619
08620
08621
08622
08623
08624
08625
08626
08627 static tree
08628 cp_parser_type_parameter (cp_parser* parser)
08629 {
08630 cp_token *token;
08631 tree parameter;
08632
08633
08634 token = cp_parser_require (parser, CPP_KEYWORD,
08635 "`class', `typename', or `template'");
08636 if (!token)
08637 return error_mark_node;
08638
08639 switch (token->keyword)
08640 {
08641 case RID_CLASS:
08642 case RID_TYPENAME:
08643 {
08644 tree identifier;
08645 tree default_argument;
08646
08647
08648
08649 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
08650 identifier = cp_parser_identifier (parser);
08651 else
08652 identifier = NULL_TREE;
08653
08654
08655 parameter = finish_template_type_parm (class_type_node, identifier);
08656
08657
08658 if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
08659 {
08660
08661 cp_lexer_consume_token (parser->lexer);
08662
08663 push_deferring_access_checks (dk_no_deferred);
08664 default_argument = cp_parser_type_id (parser);
08665 pop_deferring_access_checks ();
08666 }
08667 else
08668 default_argument = NULL_TREE;
08669
08670
08671
08672 parameter = build_tree_list (default_argument, parameter);
08673 }
08674 break;
08675
08676 case RID_TEMPLATE:
08677 {
08678 tree parameter_list;
08679 tree identifier;
08680 tree default_argument;
08681
08682
08683 cp_parser_require (parser, CPP_LESS, "`<'");
08684
08685 parameter_list = cp_parser_template_parameter_list (parser);
08686
08687 cp_parser_require (parser, CPP_GREATER, "`>'");
08688
08689 cp_parser_require_keyword (parser, RID_CLASS, "`class'");
08690
08691
08692
08693
08694 if (cp_lexer_next_token_is_not (parser->lexer, CPP_EQ)
08695 && cp_lexer_next_token_is_not (parser->lexer, CPP_GREATER)
08696 && cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
08697 {
08698 identifier = cp_parser_identifier (parser);
08699
08700 if (identifier == error_mark_node)
08701 identifier = NULL_TREE;
08702 }
08703 else
08704 identifier = NULL_TREE;
08705
08706
08707 parameter = finish_template_template_parm (class_type_node,
08708 identifier);
08709
08710
08711
08712 if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
08713 {
08714 bool is_template;
08715
08716
08717 cp_lexer_consume_token (parser->lexer);
08718
08719 push_deferring_access_checks (dk_no_deferred);
08720 default_argument
08721 = cp_parser_id_expression (parser,
08722 false,
08723 true,
08724 &is_template,
08725 false,
08726 false);
08727 if (TREE_CODE (default_argument) == TYPE_DECL)
08728
08729
08730
08731 ;
08732 else
08733
08734 default_argument
08735 = cp_parser_lookup_name (parser, default_argument,
08736 none_type,
08737 is_template,
08738 false,
08739 true,
08740 NULL);
08741
08742 default_argument
08743 = check_template_template_default_arg (default_argument);
08744 pop_deferring_access_checks ();
08745 }
08746 else
08747 default_argument = NULL_TREE;
08748
08749
08750
08751 parameter = build_tree_list (default_argument, parameter);
08752 }
08753 break;
08754
08755 default:
08756 gcc_unreachable ();
08757 break;
08758 }
08759
08760 return parameter;
08761 }
08762
08763
08764
08765
08766
08767
08768
08769
08770
08771
08772
08773
08774
08775
08776
08777 static tree
08778 cp_parser_template_id (cp_parser *parser,
08779 bool template_keyword_p,
08780 bool check_dependency_p,
08781 bool is_declaration)
08782 {
08783 int i;
08784 tree template;
08785 tree arguments;
08786 tree template_id;
08787 cp_token_position start_of_id = 0;
08788 deferred_access_check *chk;
08789 VEC (deferred_access_check,gc) *access_check;
08790 cp_token *next_token, *next_token_2;
08791 bool is_identifier;
08792
08793
08794
08795 next_token = cp_lexer_peek_token (parser->lexer);
08796 if (next_token->type == CPP_TEMPLATE_ID)
08797 {
08798 struct tree_check *check_value;
08799
08800
08801 check_value = cp_lexer_consume_token (parser->lexer)->u.tree_check_value;
08802
08803 access_check = check_value->checks;
08804 if (access_check)
08805 {
08806 for (i = 0 ;
08807 VEC_iterate (deferred_access_check, access_check, i, chk) ;
08808 ++i)
08809 {
08810 perform_or_defer_access_check (chk->binfo,
08811 chk->decl,
08812 chk->diag_decl);
08813 }
08814 }
08815
08816 return check_value->value;
08817 }
08818
08819
08820
08821 if ((next_token->type != CPP_NAME && next_token->keyword != RID_OPERATOR)
08822 || (next_token->type == CPP_NAME
08823 && !cp_parser_nth_token_starts_template_argument_list_p
08824 (parser, 2)))
08825 {
08826 cp_parser_error (parser, "expected template-id");
08827 return error_mark_node;
08828 }
08829
08830
08831 if (cp_parser_uncommitted_to_tentative_parse_p (parser))
08832 start_of_id = cp_lexer_token_position (parser->lexer, false);
08833
08834 push_deferring_access_checks (dk_deferred);
08835
08836
08837 is_identifier = false;
08838 template = cp_parser_template_name (parser, template_keyword_p,
08839 check_dependency_p,
08840 is_declaration,
08841 &is_identifier);
08842 if (template == error_mark_node || is_identifier)
08843 {
08844 pop_deferring_access_checks ();
08845 return template;
08846 }
08847
08848
08849
08850
08851 next_token = cp_lexer_peek_token (parser->lexer);
08852 next_token_2 = cp_lexer_peek_nth_token (parser->lexer, 2);
08853 if (next_token->type == CPP_OPEN_SQUARE
08854 && next_token->flags & DIGRAPH
08855 && next_token_2->type == CPP_COLON
08856 && !(next_token_2->flags & PREV_WHITE))
08857 {
08858 cp_parser_parse_tentatively (parser);
08859
08860 next_token_2->type = CPP_SCOPE;
08861
08862
08863 cp_lexer_consume_token (parser->lexer);
08864
08865 arguments = cp_parser_enclosed_template_argument_list (parser);
08866 if (!cp_parser_parse_definitely (parser))
08867 {
08868
08869
08870
08871 next_token_2->type = CPP_COLON;
08872 cp_parser_error (parser, "expected %<<%>");
08873 pop_deferring_access_checks ();
08874 return error_mark_node;
08875 }
08876
08877
08878 pedwarn ("%<<::%> cannot begin a template-argument list");
08879 inform ("%<<:%> is an alternate spelling for %<[%>. Insert whitespace "
08880 "between %<<%> and %<::%>");
08881 if (!flag_permissive)
08882 {
08883 static bool hint;
08884 if (!hint)
08885 {
08886 inform ("(if you use -fpermissive G++ will accept your code)");
08887 hint = true;
08888 }
08889 }
08890 }
08891 else
08892 {
08893
08894 if (!cp_parser_require (parser, CPP_LESS, "`<'"))
08895 {
08896 pop_deferring_access_checks ();
08897 return error_mark_node;
08898 }
08899
08900 arguments = cp_parser_enclosed_template_argument_list (parser);
08901 }
08902
08903
08904 if (TREE_CODE (template) == IDENTIFIER_NODE)
08905 template_id = build_min_nt (TEMPLATE_ID_EXPR, template, arguments);
08906 else if (DECL_CLASS_TEMPLATE_P (template)
08907 || DECL_TEMPLATE_TEMPLATE_PARM_P (template))
08908 {
08909 bool entering_scope;
08910
08911
08912
08913
08914
08915 entering_scope = (template_parm_scope_p ()
08916 && cp_lexer_next_token_is (parser->lexer,
08917 CPP_SCOPE));
08918 template_id
08919 = finish_template_type (template, arguments, entering_scope);
08920 }
08921 else
08922 {
08923
08924
08925 gcc_assert ((DECL_FUNCTION_TEMPLATE_P (template)
08926 || TREE_CODE (template) == OVERLOAD
08927 || BASELINK_P (template)));
08928
08929 template_id = lookup_template_function (template, arguments);
08930 }
08931
08932
08933
08934
08935
08936
08937
08938 if (start_of_id)
08939 {
08940 cp_token *token = cp_lexer_token_at (parser->lexer, start_of_id);
08941
08942
08943 token->type = CPP_TEMPLATE_ID;
08944
08945
08946 token->u.tree_check_value = GGC_CNEW (struct tree_check);
08947 token->u.tree_check_value->value = template_id;
08948 token->u.tree_check_value->checks = get_deferred_access_checks ();
08949 token->keyword = RID_MAX;
08950
08951
08952 cp_lexer_purge_tokens_after (parser->lexer, start_of_id);
08953
08954
08955
08956
08957
08958 if (cp_parser_error_occurred (parser) && template_id != error_mark_node)
08959 error ("parse error in template argument list");
08960 }
08961
08962 pop_deferring_access_checks ();
08963 return template_id;
08964 }
08965
08966
08967
08968
08969
08970
08971
08972
08973
08974
08975
08976
08977
08978
08979
08980
08981
08982
08983
08984
08985
08986
08987
08988
08989
08990
08991
08992
08993
08994
08995
08996
08997
08998
08999
09000
09001
09002
09003 static tree
09004 cp_parser_template_name (cp_parser* parser,
09005 bool template_keyword_p,
09006 bool check_dependency_p,
09007 bool is_declaration,
09008 bool *is_identifier)
09009 {
09010 tree identifier;
09011 tree decl;
09012 tree fns;
09013
09014
09015
09016 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_OPERATOR))
09017 {
09018
09019
09020 cp_parser_parse_tentatively (parser);
09021
09022 identifier = cp_parser_operator_function_id (parser);
09023
09024 if (!cp_parser_parse_definitely (parser))
09025 {
09026 cp_parser_error (parser, "expected template-name");
09027 return error_mark_node;
09028 }
09029 }
09030
09031 else
09032 identifier = cp_parser_identifier (parser);
09033
09034
09035 if (identifier == error_mark_node)
09036 return error_mark_node;
09037
09038
09039
09040
09041
09042
09043
09044
09045
09046
09047
09048
09049
09050 if (processing_template_decl
09051 && cp_parser_nth_token_starts_template_argument_list_p (parser, 1))
09052 {
09053
09054
09055
09056
09057
09058
09059
09060 if (is_declaration
09061 && !template_keyword_p
09062 && parser->scope && TYPE_P (parser->scope)
09063 && check_dependency_p
09064 && dependent_type_p (parser->scope)
09065
09066
09067 && !constructor_name_p (identifier, parser->scope))
09068 {
09069 cp_token_position start = 0;
09070
09071
09072 error ("non-template %qD used as template", identifier);
09073 inform ("use %<%T::template %D%> to indicate that it is a template",
09074 parser->scope, identifier);
09075
09076 if (cp_parser_simulate_error (parser))
09077 start = cp_lexer_token_position (parser->lexer, true);
09078
09079
09080 cp_lexer_consume_token (parser->lexer);
09081 cp_parser_enclosed_template_argument_list (parser);
09082
09083
09084 cp_parser_skip_to_closing_parenthesis (parser,
09085 true,
09086 true,
09087 false);
09088
09089
09090
09091
09092 if (start)
09093 cp_lexer_purge_tokens_after (parser->lexer, start);
09094 if (is_identifier)
09095 *is_identifier = true;
09096 return identifier;
09097 }
09098
09099
09100
09101
09102
09103 if (template_keyword_p
09104 && (!parser->scope
09105 || (TYPE_P (parser->scope)
09106 && dependent_type_p (parser->scope))))
09107 return identifier;
09108 }
09109
09110
09111 decl = cp_parser_lookup_name (parser, identifier,
09112 none_type,
09113 false,
09114 false,
09115 check_dependency_p,
09116 NULL);
09117 decl = maybe_get_template_decl_from_type_decl (decl);
09118
09119
09120 if (TREE_CODE (decl) == TEMPLATE_DECL)
09121 ;
09122 else
09123 {
09124 tree fn = NULL_TREE;
09125
09126
09127
09128
09129
09130
09131 fns = BASELINK_P (decl) ? BASELINK_FUNCTIONS (decl) : decl;
09132 if (TREE_CODE (fns) == OVERLOAD)
09133 for (fn = fns; fn; fn = OVL_NEXT (fn))
09134 if (TREE_CODE (OVL_CURRENT (fn)) == TEMPLATE_DECL)
09135 break;
09136
09137 if (!fn)
09138 {
09139
09140 cp_parser_error (parser, "expected template-name");
09141 return error_mark_node;
09142 }
09143 }
09144
09145
09146
09147 if (DECL_FUNCTION_TEMPLATE_P (decl) || !DECL_P (decl))
09148 {
09149 tree scope = CP_DECL_CONTEXT (get_first_fn (decl));
09150 if (TYPE_P (scope) && dependent_type_p (scope))
09151 return identifier;
09152 }
09153
09154 return decl;
09155 }
09156
09157
09158
09159
09160
09161
09162
09163
09164
09165 static tree
09166 cp_parser_template_argument_list (cp_parser* parser)
09167 {
09168 tree fixed_args[10];
09169 unsigned n_args = 0;
09170 unsigned alloced = 10;
09171 tree *arg_ary = fixed_args;
09172 tree vec;
09173 bool saved_in_template_argument_list_p;
09174 bool saved_ice_p;
09175 bool saved_non_ice_p;
09176
09177 saved_in_template_argument_list_p = parser->in_template_argument_list_p;
09178 parser->in_template_argument_list_p = true;
09179
09180
09181
09182 saved_ice_p = parser->integral_constant_expression_p;
09183 parser->integral_constant_expression_p = false;
09184 saved_non_ice_p = parser->non_integral_constant_expression_p;
09185 parser->non_integral_constant_expression_p = false;
09186
09187 do
09188 {
09189 tree argument;
09190
09191 if (n_args)
09192
09193 cp_lexer_consume_token (parser->lexer);
09194
09195
09196 argument = cp_parser_template_argument (parser);
09197 if (n_args == alloced)
09198 {
09199 alloced *= 2;
09200
09201 if (arg_ary == fixed_args)
09202 {
09203 arg_ary = XNEWVEC (tree, alloced);
09204 memcpy (arg_ary, fixed_args, sizeof (tree) * n_args);
09205 }
09206 else
09207 arg_ary = XRESIZEVEC (tree, arg_ary, alloced);
09208 }
09209 arg_ary[n_args++] = argument;
09210 }
09211 while (cp_lexer_next_token_is (parser->lexer, CPP_COMMA));
09212
09213 vec = make_tree_vec (n_args);
09214
09215 while (n_args--)
09216 TREE_VEC_ELT (vec, n_args) = arg_ary[n_args];
09217
09218 if (arg_ary != fixed_args)
09219 free (arg_ary);
09220 parser->non_integral_constant_expression_p = saved_non_ice_p;
09221 parser->integral_constant_expression_p = saved_ice_p;
09222 parser->in_template_argument_list_p = saved_in_template_argument_list_p;
09223 return vec;
09224 }
09225
09226
09227
09228
09229
09230
09231
09232
09233
09234
09235
09236
09237
09238
09239
09240
09241
09242 static tree
09243 cp_parser_template_argument (cp_parser* parser)
09244 {
09245 tree argument;
09246 bool template_p;
09247 bool address_p;
09248 bool maybe_type_id = false;
09249 cp_token *token;
09250 cp_id_kind idk;
09251
09252
09253
09254
09255
09256
09257
09258
09259
09260
09261
09262 cp_parser_parse_tentatively (parser);
09263 argument = cp_parser_type_id (parser);
09264
09265
09266
09267
09268
09269
09270
09271
09272
09273
09274
09275
09276 if (!cp_parser_error_occurred (parser)
09277 && cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT))
09278 {
09279 maybe_type_id = true;
09280 cp_parser_abort_tentative_parse (parser);
09281 }
09282 else
09283 {
09284
09285
09286
09287 if (!cp_parser_next_token_ends_template_argument_p (parser))
09288 cp_parser_error (parser, "expected template-argument");
09289
09290 if (cp_parser_parse_definitely (parser))
09291 return argument;
09292 }
09293
09294 cp_parser_parse_tentatively (parser);
09295
09296 argument = cp_parser_id_expression (parser,
09297 false,
09298 true,
09299 &template_p,
09300 false,
09301 false);
09302
09303
09304 if (!cp_parser_next_token_ends_template_argument_p (parser))
09305 cp_parser_error (parser, "expected template-argument");
09306 if (!cp_parser_error_occurred (parser))
09307 {
09308
09309
09310
09311
09312 if (TREE_CODE (argument) != TYPE_DECL)
09313 argument = cp_parser_lookup_name (parser, argument,
09314 none_type,
09315 template_p,
09316 false,
09317 true,
09318 NULL);
09319 if (TREE_CODE (argument) != TEMPLATE_DECL
09320 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
09321 cp_parser_error (parser, "expected template-name");
09322 }
09323 if (cp_parser_parse_definitely (parser))
09324 return argument;
09325
09326
09327
09328
09329
09330
09331
09332
09333
09334
09335
09336
09337
09338
09339 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
09340 {
09341 cp_parser_parse_tentatively (parser);
09342 argument = cp_parser_primary_expression (parser,
09343 false,
09344 false,
09345 true,
09346 &idk);
09347 if (TREE_CODE (argument) != TEMPLATE_PARM_INDEX
09348 || !cp_parser_next_token_ends_template_argument_p (parser))
09349 cp_parser_simulate_error (parser);
09350 if (cp_parser_parse_definitely (parser))
09351 return argument;
09352 }
09353
09354
09355
09356 address_p = cp_lexer_next_token_is (parser->lexer, CPP_AND);
09357 if (address_p)
09358 cp_lexer_consume_token (parser->lexer);
09359
09360 token = cp_lexer_peek_token (parser->lexer);
09361 if (token->type == CPP_NAME
09362 || token->keyword == RID_OPERATOR
09363 || token->type == CPP_SCOPE
09364 || token->type == CPP_TEMPLATE_ID
09365 || token->type == CPP_NESTED_NAME_SPECIFIER)
09366 {
09367 cp_parser_parse_tentatively (parser);
09368 argument = cp_parser_primary_expression (parser,
09369 address_p,
09370 false,
09371 true,
09372 &idk);
09373 if (cp_parser_error_occurred (parser)
09374 || !cp_parser_next_token_ends_template_argument_p (parser))
09375 cp_parser_abort_tentative_parse (parser);
09376 else
09377 {
09378 if (TREE_CODE (argument) == INDIRECT_REF)
09379 {
09380 gcc_assert (REFERENCE_REF_P (argument));
09381 argument = TREE_OPERAND (argument, 0);
09382 }
09383
09384 if (TREE_CODE (argument) == VAR_DECL)
09385 {
09386
09387
09388
09389 if (!address_p && !DECL_EXTERNAL_LINKAGE_P (argument))
09390 cp_parser_simulate_error (parser);
09391 }
09392 else if (is_overloaded_fn (argument))
09393
09394
09395
09396 ;
09397 else if (address_p
09398 && (TREE_CODE (argument) == OFFSET_REF
09399 || TREE_CODE (argument) == SCOPE_REF))
09400
09401 ;
09402 else if (TREE_CODE (argument) == TEMPLATE_PARM_INDEX)
09403 ;
09404 else
09405 cp_parser_simulate_error (parser);
09406
09407 if (cp_parser_parse_definitely (parser))
09408 {
09409 if (address_p)
09410 argument = build_x_unary_op (ADDR_EXPR, argument);
09411 return argument;
09412 }
09413 }
09414 }
09415
09416
09417 if (address_p)
09418 {
09419 cp_parser_error (parser, "invalid non-type template argument");
09420 return error_mark_node;
09421 }
09422
09423
09424
09425
09426
09427 if (maybe_type_id)
09428 cp_parser_parse_tentatively (parser);
09429 argument = cp_parser_constant_expression (parser,
09430 false,
09431 NULL);
09432 argument = fold_non_dependent_expr (argument);
09433 if (!maybe_type_id)
09434 return argument;
09435 if (!cp_parser_next_token_ends_template_argument_p (parser))
09436 cp_parser_error (parser, "expected template-argument");
09437 if (cp_parser_parse_definitely (parser))
09438 return argument;
09439
09440
09441
09442
09443 return cp_parser_type_id (parser);
09444 }
09445
09446
09447
09448
09449
09450
09451
09452
09453
09454
09455
09456
09457
09458
09459
09460
09461
09462
09463
09464
09465
09466
09467
09468 static void
09469 cp_parser_explicit_instantiation (cp_parser* parser)
09470 {
09471 int declares_class_or_enum;
09472 cp_decl_specifier_seq decl_specifiers;
09473 tree extension_specifier = NULL_TREE;
09474
09475
09476
09477 if (cp_parser_allow_gnu_extensions_p (parser))
09478 {
09479 extension_specifier
09480 = cp_parser_storage_class_specifier_opt (parser);
09481 if (!extension_specifier)
09482 extension_specifier
09483 = cp_parser_function_specifier_opt (parser,
09484 NULL);
09485 }
09486
09487
09488 cp_parser_require_keyword (parser, RID_TEMPLATE, "`template'");
09489
09490
09491 begin_explicit_instantiation ();
09492
09493
09494 push_deferring_access_checks (dk_no_check);
09495
09496 cp_parser_decl_specifier_seq (parser,
09497 CP_PARSER_FLAGS_OPTIONAL,
09498 &decl_specifiers,
09499 &declares_class_or_enum);
09500
09501
09502
09503 if (declares_class_or_enum && cp_parser_declares_only_class_p (parser))
09504 {
09505 tree type;
09506
09507 type = check_tag_decl (&decl_specifiers);
09508
09509
09510 pop_deferring_access_checks ();
09511 if (type)
09512 do_type_instantiation (type, extension_specifier,
09513 tf_error);
09514 }
09515 else
09516 {
09517 cp_declarator *declarator;
09518 tree decl;
09519
09520
09521 declarator
09522 = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
09523 NULL,
09524 NULL,
09525 false);
09526 if (declares_class_or_enum & 2)
09527 cp_parser_check_for_definition_in_return_type (declarator,
09528 decl_specifiers.type);
09529 if (declarator != cp_error_declarator)
09530 {
09531 decl = grokdeclarator (declarator, &decl_specifiers,
09532 NORMAL, 0, &decl_specifiers.attributes);
09533
09534
09535 pop_deferring_access_checks ();
09536
09537 do_decl_instantiation (decl, extension_specifier);
09538 }
09539 else
09540 {
09541 pop_deferring_access_checks ();
09542
09543 cp_parser_skip_to_end_of_statement (parser);
09544 }
09545 }
09546
09547 end_explicit_instantiation ();
09548
09549 cp_parser_consume_semicolon_at_end_of_statement (parser);
09550 }
09551
09552
09553
09554
09555
09556
09557
09558
09559
09560
09561
09562
09563
09564
09565 static void
09566 cp_parser_explicit_specialization (cp_parser* parser)
09567 {
09568 bool need_lang_pop;
09569
09570 cp_parser_require_keyword (parser, RID_TEMPLATE, "`template'");
09571
09572 cp_parser_require (parser, CPP_LESS, "`<'");
09573
09574 cp_parser_require (parser, CPP_GREATER, "`>'");
09575
09576 ++parser->num_template_parameter_lists;
09577
09578
09579
09580
09581 if (current_lang_name == lang_name_c)
09582 {
09583 error ("template specialization with C linkage");
09584
09585
09586 push_lang_context (lang_name_cplusplus);
09587 need_lang_pop = true;
09588 }
09589 else
09590 need_lang_pop = false;
09591
09592 if (!begin_specialization ())
09593 {
09594 end_specialization ();
09595 cp_parser_skip_to_end_of_block_or_statement (parser);
09596 return;
09597 }
09598
09599
09600
09601 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
09602 {
09603 if (cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_LESS
09604 && cp_lexer_peek_nth_token (parser->lexer, 3)->type != CPP_GREATER)
09605 cp_parser_template_declaration_after_export (parser,
09606 false);
09607 else
09608 cp_parser_explicit_specialization (parser);
09609 }
09610 else
09611
09612 cp_parser_single_declaration (parser,
09613 NULL,
09614 false,
09615 NULL);
09616
09617 end_specialization ();
09618
09619
09620 if (need_lang_pop)
09621 pop_lang_context ();
09622
09623 --parser->num_template_parameter_lists;
09624 }
09625
09626
09627
09628
09629
09630
09631
09632
09633
09634
09635
09636
09637
09638
09639
09640
09641
09642
09643
09644
09645
09646
09647
09648
09649
09650
09651
09652
09653
09654
09655
09656
09657
09658
09659 static tree
09660 cp_parser_type_specifier (cp_parser* parser,
09661 cp_parser_flags flags,
09662 cp_decl_specifier_seq *decl_specs,
09663 bool is_declaration,
09664 int* declares_class_or_enum,
09665 bool* is_cv_qualifier)
09666 {
09667 tree type_spec = NULL_TREE;
09668 cp_token *token;
09669 enum rid keyword;
09670 cp_decl_spec ds = ds_last;
09671
09672
09673 if (declares_class_or_enum)
09674 *declares_class_or_enum = 0;
09675
09676 if (is_cv_qualifier)
09677 *is_cv_qualifier = false;
09678
09679 token = cp_lexer_peek_token (parser->lexer);
09680
09681
09682
09683 keyword = token->keyword;
09684 switch (keyword)
09685 {
09686 case RID_ENUM:
09687
09688 type_spec = cp_parser_enum_specifier (parser);
09689
09690 if (type_spec)
09691 {
09692 if (declares_class_or_enum)
09693 *declares_class_or_enum = 2;
09694 if (decl_specs)
09695 cp_parser_set_decl_spec_type (decl_specs,
09696 type_spec,
09697 true);
09698 return type_spec;
09699 }
09700 else
09701 goto elaborated_type_specifier;
09702
09703
09704
09705 case RID_CLASS:
09706 case RID_STRUCT:
09707 case RID_UNION:
09708
09709
09710 cp_parser_parse_tentatively (parser);
09711
09712 type_spec = cp_parser_class_specifier (parser);
09713
09714 if (cp_parser_parse_definitely (parser))
09715 {
09716 if (declares_class_or_enum)
09717 *declares_class_or_enum = 2;
09718 if (decl_specs)
09719 cp_parser_set_decl_spec_type (decl_specs,
09720 type_spec,
09721 true);
09722 return type_spec;
09723 }
09724
09725
09726 elaborated_type_specifier:
09727
09728 if (declares_class_or_enum)
09729 *declares_class_or_enum = 1;
09730
09731
09732 case RID_TYPENAME:
09733
09734 type_spec
09735 = (cp_parser_elaborated_type_specifier
09736 (parser,
09737 decl_specs && decl_specs->specs[(int) ds_friend],
09738 is_declaration));
09739 if (decl_specs)
09740 cp_parser_set_decl_spec_type (decl_specs,
09741 type_spec,
09742 true);
09743 return type_spec;
09744
09745 case RID_CONST:
09746 ds = ds_const;
09747 if (is_cv_qualifier)
09748 *is_cv_qualifier = true;
09749 break;
09750
09751 case RID_VOLATILE:
09752 ds = ds_volatile;
09753 if (is_cv_qualifier)
09754 *is_cv_qualifier = true;
09755 break;
09756
09757 case RID_RESTRICT:
09758 ds = ds_restrict;
09759 if (is_cv_qualifier)
09760 *is_cv_qualifier = true;
09761 break;
09762
09763 case RID_COMPLEX:
09764
09765 ds = ds_complex;
09766 break;
09767
09768 default:
09769 break;
09770 }
09771
09772
09773 if (ds != ds_last)
09774 {
09775 if (decl_specs)
09776 {
09777 ++decl_specs->specs[(int)ds];
09778 decl_specs->any_specifiers_p = true;
09779 }
09780 return cp_lexer_consume_token (parser->lexer)->u.value;
09781 }
09782
09783
09784
09785 type_spec = cp_parser_simple_type_specifier (parser,
09786 decl_specs,
09787 flags);
09788
09789
09790
09791 if (!type_spec && !(flags & CP_PARSER_FLAGS_OPTIONAL))
09792 {
09793 cp_parser_error (parser, "expected type specifier");
09794 return error_mark_node;
09795 }
09796
09797 return type_spec;
09798 }
09799
09800
09801
09802
09803
09804
09805
09806
09807
09808
09809
09810
09811
09812
09813
09814
09815
09816
09817
09818
09819
09820
09821
09822
09823
09824
09825
09826 static tree
09827 cp_parser_simple_type_specifier (cp_parser* parser,
09828 cp_decl_specifier_seq *decl_specs,
09829 cp_parser_flags flags)
09830 {
09831 tree type = NULL_TREE;
09832 cp_token *token;
09833
09834
09835 token = cp_lexer_peek_token (parser->lexer);
09836
09837
09838 switch (token->keyword)
09839 {
09840 case RID_CHAR:
09841 if (decl_specs)
09842 decl_specs->explicit_char_p = true;
09843 type = char_type_node;
09844 break;
09845 case RID_WCHAR:
09846 type = wchar_type_node;
09847 break;
09848 case RID_BOOL:
09849 type = boolean_type_node;
09850 break;
09851 case RID_SHORT:
09852 if (decl_specs)
09853 ++decl_specs->specs[(int) ds_short];
09854 type = short_integer_type_node;
09855 break;
09856 case RID_INT:
09857 if (decl_specs)
09858 decl_specs->explicit_int_p = true;
09859 type = integer_type_node;
09860 break;
09861 case RID_LONG:
09862 if (decl_specs)
09863 ++decl_specs->specs[(int) ds_long];
09864 type = long_integer_type_node;
09865 break;
09866 case RID_SIGNED:
09867 if (decl_specs)
09868 ++decl_specs->specs[(int) ds_signed];
09869 type = integer_type_node;
09870 break;
09871 case RID_UNSIGNED:
09872 if (decl_specs)
09873 ++decl_specs->specs[(int) ds_unsigned];
09874 type = unsigned_type_node;
09875 break;
09876 case RID_FLOAT:
09877 type = float_type_node;
09878 break;
09879 case RID_DOUBLE:
09880 type = double_type_node;
09881 break;
09882 case RID_VOID:
09883 type = void_type_node;
09884 break;
09885
09886 case RID_TYPEOF:
09887
09888 cp_lexer_consume_token (parser->lexer);
09889
09890 type = cp_parser_sizeof_operand (parser, RID_TYPEOF);
09891
09892 if (!TYPE_P (type))
09893 type = finish_typeof (type);
09894
09895 if (decl_specs)
09896 cp_parser_set_decl_spec_type (decl_specs, type,
09897 true);
09898
09899 return type;
09900
09901 default:
09902 break;
09903 }
09904
09905
09906 if (type)
09907 {
09908 tree id;
09909
09910
09911 if (decl_specs
09912 && (token->keyword != RID_SIGNED
09913 && token->keyword != RID_UNSIGNED
09914 && token->keyword != RID_SHORT
09915 && token->keyword != RID_LONG))
09916 cp_parser_set_decl_spec_type (decl_specs,
09917 type,
09918 false);
09919 if (decl_specs)
09920 decl_specs->any_specifiers_p = true;
09921
09922
09923 id = cp_lexer_consume_token (parser->lexer)->u.value;
09924
09925
09926
09927
09928 cp_parser_check_for_invalid_template_id (parser, type);
09929
09930 return TYPE_NAME (type);
09931 }
09932
09933
09934 if (!(flags & CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES))
09935 {
09936 bool qualified_p;
09937 bool global_p;
09938
09939
09940
09941 if (flags & CP_PARSER_FLAGS_OPTIONAL)
09942 cp_parser_parse_tentatively (parser);
09943
09944
09945 global_p
09946 = (cp_parser_global_scope_opt (parser,
09947 false)
09948 != NULL_TREE);
09949
09950 qualified_p
09951 = (cp_parser_nested_name_specifier_opt (parser,
09952 false,
09953 true,
09954 false,
09955 false)
09956 != NULL_TREE);
09957
09958
09959 if (parser->scope
09960 && cp_parser_optional_template_keyword (parser))
09961 {
09962
09963 type = cp_parser_template_id (parser,
09964 true,
09965 true,
09966 false);
09967
09968
09969 if (TREE_CODE (type) != TYPE_DECL)
09970 {
09971 cp_parser_error (parser, "expected template-id for type");
09972 type = NULL_TREE;
09973 }
09974 }
09975
09976 else
09977 type = cp_parser_type_name (parser);
09978
09979 if (type
09980 && !global_p
09981 && !qualified_p
09982 && TREE_CODE (type) == TYPE_DECL
09983 && TREE_CODE (DECL_NAME (type)) == IDENTIFIER_NODE)
09984 maybe_note_name_used_in_class (DECL_NAME (type), type);
09985
09986 if ((flags & CP_PARSER_FLAGS_OPTIONAL)
09987 && !cp_parser_parse_definitely (parser))
09988 type = NULL_TREE;
09989 if (type && decl_specs)
09990 cp_parser_set_decl_spec_type (decl_specs, type,
09991 true);
09992 }
09993
09994
09995 if (!type && !(flags & CP_PARSER_FLAGS_OPTIONAL))
09996 {
09997 cp_parser_error (parser, "expected type-name");
09998 return error_mark_node;
09999 }
10000
10001
10002
10003
10004 if (type && type != error_mark_node)
10005 {
10006
10007
10008
10009 if (c_dialect_objc ()
10010 && (objc_is_id (type) || objc_is_class_name (type)))
10011 {
10012 tree protos = cp_parser_objc_protocol_refs_opt (parser);
10013 tree qual_type = objc_get_protocol_qualified_type (type, protos);
10014
10015
10016
10017 if (decl_specs)
10018 decl_specs->type = qual_type;
10019
10020 return qual_type;
10021 }
10022
10023 cp_parser_check_for_invalid_template_id (parser, TREE_TYPE (type));
10024 }
10025
10026 return type;
10027 }
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044 static tree
10045 cp_parser_type_name (cp_parser* parser)
10046 {
10047 tree type_decl;
10048 tree identifier;
10049
10050
10051 cp_parser_parse_tentatively (parser);
10052
10053 type_decl = cp_parser_class_name (parser,
10054 false,
10055 false,
10056 none_type,
10057 true,
10058 false,
10059 false);
10060
10061 if (!cp_parser_parse_definitely (parser))
10062 {
10063
10064 identifier = cp_parser_identifier (parser);
10065 if (identifier == error_mark_node)
10066 return error_mark_node;
10067
10068
10069 type_decl = cp_parser_lookup_name_simple (parser, identifier);
10070
10071 if (TREE_CODE (type_decl) != TYPE_DECL
10072 && (objc_is_id (identifier) || objc_is_class_name (identifier)))
10073 {
10074
10075 tree protos = cp_parser_objc_protocol_refs_opt (parser);
10076 tree type = objc_get_protocol_qualified_type (identifier, protos);
10077 if (type)
10078 type_decl = TYPE_NAME (type);
10079 }
10080
10081
10082 if (TREE_CODE (type_decl) != TYPE_DECL)
10083 {
10084 if (!cp_parser_simulate_error (parser))
10085 cp_parser_name_lookup_error (parser, identifier, type_decl,
10086 "is not a type");
10087 type_decl = error_mark_node;
10088 }
10089
10090
10091
10092
10093 else if (type_decl != error_mark_node
10094 && !parser->scope)
10095 maybe_note_name_used_in_class (identifier, type_decl);
10096 }
10097
10098 return type_decl;
10099 }
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128 static tree
10129 cp_parser_elaborated_type_specifier (cp_parser* parser,
10130 bool is_friend,
10131 bool is_declaration)
10132 {
10133 enum tag_types tag_type;
10134 tree identifier;
10135 tree type = NULL_TREE;
10136 tree attributes = NULL_TREE;
10137
10138
10139 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ENUM))
10140 {
10141
10142 cp_lexer_consume_token (parser->lexer);
10143
10144 tag_type = enum_type;
10145
10146 attributes = cp_parser_attributes_opt (parser);
10147 }
10148
10149 else if (cp_lexer_next_token_is_keyword (parser->lexer,
10150 RID_TYPENAME))
10151 {
10152
10153 cp_lexer_consume_token (parser->lexer);
10154
10155 tag_type = typename_type;
10156
10157 if (!processing_template_decl)
10158 pedwarn ("using %<typename%> outside of template");
10159 }
10160
10161 else
10162 {
10163 tag_type = cp_parser_class_key (parser);
10164 if (tag_type == none_type)
10165 return error_mark_node;
10166
10167 attributes = cp_parser_attributes_opt (parser);
10168 }
10169
10170
10171 cp_parser_global_scope_opt (parser,
10172 false);
10173
10174 if (tag_type == typename_type)
10175 {
10176 if (!cp_parser_nested_name_specifier (parser,
10177 true,
10178 true,
10179 true,
10180 is_declaration))
10181 return error_mark_node;
10182 }
10183 else
10184
10185
10186
10187 cp_parser_nested_name_specifier_opt (parser,
10188 true,
10189 true,
10190 true,
10191 is_declaration);
10192
10193
10194 if (tag_type != enum_type)
10195 {
10196 bool template_p = false;
10197 tree decl;
10198
10199
10200 template_p = cp_parser_optional_template_keyword (parser);
10201
10202
10203 if (!template_p)
10204 cp_parser_parse_tentatively (parser);
10205
10206 decl = cp_parser_template_id (parser, template_p,
10207 true,
10208 is_declaration);
10209
10210
10211 if (!template_p && !cp_parser_parse_definitely (parser))
10212 ;
10213
10214
10215
10216 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
10217 && tag_type == typename_type)
10218 type = make_typename_type (parser->scope, decl,
10219 typename_type,
10220 tf_error);
10221 else
10222 type = TREE_TYPE (decl);
10223 }
10224
10225 if (!type)
10226 {
10227 identifier = cp_parser_identifier (parser);
10228
10229 if (identifier == error_mark_node)
10230 {
10231 parser->scope = NULL_TREE;
10232 return error_mark_node;
10233 }
10234
10235
10236 if (tag_type == typename_type
10237 && TREE_CODE (parser->scope) != NAMESPACE_DECL)
10238 return cp_parser_make_typename_type (parser, parser->scope,
10239 identifier);
10240
10241 if (parser->scope)
10242 {
10243 tree decl;
10244
10245 decl = cp_parser_lookup_name (parser, identifier,
10246 tag_type,
10247 false,
10248 false,
10249 true,
10250 NULL);
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273 decl = (cp_parser_maybe_treat_template_as_class
10274 (decl, is_friend
10275 && parser->num_template_parameter_lists));
10276
10277 if (TREE_CODE (decl) != TYPE_DECL)
10278 {
10279 cp_parser_diagnose_invalid_type_name (parser,
10280 parser->scope,
10281 identifier);
10282 return error_mark_node;
10283 }
10284
10285 if (TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE)
10286 {
10287 bool allow_template = (parser->num_template_parameter_lists
10288 || DECL_SELF_REFERENCE_P (decl));
10289 type = check_elaborated_type_specifier (tag_type, decl,
10290 allow_template);
10291
10292 if (type == error_mark_node)
10293 return error_mark_node;
10294 }
10295
10296 type = TREE_TYPE (decl);
10297 }
10298 else
10299 {
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343 tag_scope ts;
10344 bool template_p;
10345
10346 if (is_friend)
10347
10348 ts = ts_within_enclosing_non_class;
10349 else if (is_declaration
10350 && cp_lexer_next_token_is (parser->lexer,
10351 CPP_SEMICOLON))
10352
10353 ts = ts_current;
10354 else
10355 ts = ts_global;
10356
10357 template_p =
10358 (parser->num_template_parameter_lists
10359 && (cp_parser_next_token_starts_class_definition_p (parser)
10360 || cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)));
10361
10362
10363 if (!cp_parser_check_template_parameters (parser,
10364 0))
10365 return error_mark_node;
10366 type = xref_tag (tag_type, identifier, ts, template_p);
10367 }
10368 }
10369
10370 if (type == error_mark_node)
10371 return error_mark_node;
10372
10373
10374 if (attributes)
10375 {
10376 if (TREE_CODE (type) == TYPENAME_TYPE)
10377 warning (OPT_Wattributes,
10378 "attributes ignored on uninstantiated type");
10379 else if (tag_type != enum_type && CLASSTYPE_TEMPLATE_INSTANTIATION (type)
10380 && ! processing_explicit_instantiation)
10381 warning (OPT_Wattributes,
10382 "attributes ignored on template instantiation");
10383 else if (is_declaration && cp_parser_declares_only_class_p (parser))
10384 cplus_decl_attributes (&type, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
10385 else
10386 warning (OPT_Wattributes,
10387 "attributes ignored on elaborated-type-specifier that is not a forward declaration");
10388 }
10389
10390 if (tag_type != enum_type)
10391 cp_parser_check_class_key (tag_type, type);
10392
10393
10394
10395 cp_parser_check_for_invalid_template_id (parser, type);
10396
10397 return type;
10398 }
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412 static tree
10413 cp_parser_enum_specifier (cp_parser* parser)
10414 {
10415 tree identifier;
10416 tree type;
10417 tree attributes;
10418
10419
10420
10421 cp_parser_parse_tentatively (parser);
10422
10423
10424
10425
10426
10427 cp_lexer_consume_token (parser->lexer);
10428
10429 attributes = cp_parser_attributes_opt (parser);
10430
10431 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
10432 identifier = cp_parser_identifier (parser);
10433 else
10434 identifier = make_anon_name ();
10435
10436
10437 if (!cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
10438 cp_parser_simulate_error (parser);
10439
10440 if (!cp_parser_parse_definitely (parser))
10441 return NULL_TREE;
10442
10443
10444 if (!cp_parser_check_type_definition (parser))
10445 type = error_mark_node;
10446 else
10447
10448
10449
10450 type = start_enum (identifier);
10451
10452
10453 cp_lexer_consume_token (parser->lexer);
10454
10455 if (type == error_mark_node)
10456 {
10457 cp_parser_skip_to_end_of_block_or_statement (parser);
10458 return error_mark_node;
10459 }
10460
10461
10462 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE))
10463 cp_parser_enumerator_list (parser, type);
10464
10465
10466 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
10467
10468
10469
10470 if (cp_parser_allow_gnu_extensions_p (parser))
10471 {
10472 tree trailing_attr = cp_parser_attributes_opt (parser);
10473 cplus_decl_attributes (&type,
10474 trailing_attr,
10475 (int) ATTR_FLAG_TYPE_IN_PLACE);
10476 }
10477
10478
10479 finish_enum (type);
10480
10481 return type;
10482 }
10483
10484
10485
10486
10487
10488
10489
10490
10491 static void
10492 cp_parser_enumerator_list (cp_parser* parser, tree type)
10493 {
10494 while (true)
10495 {
10496
10497 cp_parser_enumerator_definition (parser, type);
10498
10499
10500
10501 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
10502 break;
10503
10504 cp_lexer_consume_token (parser->lexer);
10505
10506 if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
10507 {
10508 if (pedantic && !in_system_header)
10509 pedwarn ("comma at end of enumerator list");
10510 break;
10511 }
10512 }
10513 }
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525 static void
10526 cp_parser_enumerator_definition (cp_parser* parser, tree type)
10527 {
10528 tree identifier;
10529 tree value;
10530
10531
10532 identifier = cp_parser_identifier (parser);
10533 if (identifier == error_mark_node)
10534 return;
10535
10536
10537 if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
10538 {
10539
10540 cp_lexer_consume_token (parser->lexer);
10541
10542 value = cp_parser_constant_expression (parser,
10543 false,
10544 NULL);
10545 }
10546 else
10547 value = NULL_TREE;
10548
10549
10550 build_enumerator (identifier, value, type);
10551 }
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561 static tree
10562 cp_parser_namespace_name (cp_parser* parser)
10563 {
10564 tree identifier;
10565 tree namespace_decl;
10566
10567
10568 identifier = cp_parser_identifier (parser);
10569 if (identifier == error_mark_node)
10570 return error_mark_node;
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590 namespace_decl = cp_parser_lookup_name (parser, identifier,
10591 none_type,
10592 false,
10593 true,
10594 true,
10595 NULL);
10596
10597 if (namespace_decl == error_mark_node
10598 || TREE_CODE (namespace_decl) != NAMESPACE_DECL)
10599 {
10600 if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
10601 error ("%qD is not a namespace-name", identifier);
10602 cp_parser_error (parser, "expected namespace-name");
10603 namespace_decl = error_mark_node;
10604 }
10605
10606 return namespace_decl;
10607 }
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628 static void
10629 cp_parser_namespace_definition (cp_parser* parser)
10630 {
10631 tree identifier, attribs;
10632
10633
10634 cp_parser_require_keyword (parser, RID_NAMESPACE, "`namespace'");
10635
10636
10637
10638
10639
10640 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
10641 identifier = cp_parser_identifier (parser);
10642 else
10643 identifier = NULL_TREE;
10644
10645
10646 attribs = cp_parser_attributes_opt (parser);
10647
10648
10649 cp_parser_require (parser, CPP_OPEN_BRACE, "`{'");
10650
10651 push_namespace_with_attribs (identifier, attribs);
10652
10653 cp_parser_namespace_body (parser);
10654
10655 pop_namespace ();
10656
10657 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
10658 }
10659
10660
10661
10662
10663
10664
10665 static void
10666 cp_parser_namespace_body (cp_parser* parser)
10667 {
10668 cp_parser_declaration_seq_opt (parser);
10669 }
10670
10671
10672
10673
10674
10675
10676 static void
10677 cp_parser_namespace_alias_definition (cp_parser* parser)
10678 {
10679 tree identifier;
10680 tree namespace_specifier;
10681
10682
10683 cp_parser_require_keyword (parser, RID_NAMESPACE, "`namespace'");
10684
10685 identifier = cp_parser_identifier (parser);
10686 if (identifier == error_mark_node)
10687 return;
10688
10689 cp_parser_require (parser, CPP_EQ, "`='");
10690
10691 namespace_specifier
10692 = cp_parser_qualified_namespace_specifier (parser);
10693
10694 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
10695
10696
10697 do_namespace_alias (identifier, namespace_specifier);
10698 }
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708 static tree
10709 cp_parser_qualified_namespace_specifier (cp_parser* parser)
10710 {
10711
10712 cp_parser_global_scope_opt (parser,
10713 false);
10714
10715
10716 cp_parser_nested_name_specifier_opt (parser,
10717 false,
10718 true,
10719 false,
10720 true);
10721
10722 return cp_parser_namespace_name (parser);
10723 }
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737 static bool
10738 cp_parser_using_declaration (cp_parser* parser,
10739 bool access_declaration_p)
10740 {
10741 cp_token *token;
10742 bool typename_p = false;
10743 bool global_scope_p;
10744 tree decl;
10745 tree identifier;
10746 tree qscope;
10747
10748 if (access_declaration_p)
10749 cp_parser_parse_tentatively (parser);
10750 else
10751 {
10752
10753 cp_parser_require_keyword (parser, RID_USING, "`using'");
10754
10755
10756 token = cp_lexer_peek_token (parser->lexer);
10757
10758 if (token->keyword == RID_TYPENAME)
10759 {
10760
10761 typename_p = true;
10762
10763 cp_lexer_consume_token (parser->lexer);
10764 }
10765 }
10766
10767
10768 global_scope_p
10769 = (cp_parser_global_scope_opt (parser,
10770 false)
10771 != NULL_TREE);
10772
10773
10774
10775 if (typename_p || !global_scope_p)
10776 qscope = cp_parser_nested_name_specifier (parser, typename_p,
10777 true,
10778 false,
10779 true);
10780
10781
10782 else
10783 qscope = cp_parser_nested_name_specifier_opt (parser,
10784 false,
10785 true,
10786 false,
10787 true);
10788 if (!qscope)
10789 qscope = global_namespace;
10790
10791 if (access_declaration_p && cp_parser_error_occurred (parser))
10792
10793
10794
10795 return cp_parser_parse_definitely (parser);
10796
10797
10798 identifier = cp_parser_unqualified_id (parser,
10799 false,
10800 true,
10801 true,
10802 false);
10803
10804 if (access_declaration_p)
10805 {
10806 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
10807 cp_parser_simulate_error (parser);
10808 if (!cp_parser_parse_definitely (parser))
10809 return false;
10810 }
10811
10812
10813
10814 if (qscope == error_mark_node || identifier == error_mark_node)
10815 ;
10816 else if (TREE_CODE (identifier) != IDENTIFIER_NODE
10817 && TREE_CODE (identifier) != BIT_NOT_EXPR)
10818
10819
10820
10821 error ("a template-id may not appear in a using-declaration");
10822 else
10823 {
10824 if (at_class_scope_p ())
10825 {
10826
10827 decl = do_class_using_decl (parser->scope, identifier);
10828
10829 finish_member_declaration (decl);
10830 }
10831 else
10832 {
10833 decl = cp_parser_lookup_name_simple (parser, identifier);
10834 if (decl == error_mark_node)
10835 cp_parser_name_lookup_error (parser, identifier, decl, NULL);
10836 else if (!at_namespace_scope_p ())
10837 do_local_using_decl (decl, qscope, identifier);
10838 else
10839 do_toplevel_using_decl (decl, qscope, identifier);
10840 }
10841 }
10842
10843
10844 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
10845
10846 return true;
10847 }
10848
10849
10850
10851
10852
10853
10854
10855 static void
10856 cp_parser_using_directive (cp_parser* parser)
10857 {
10858 tree namespace_decl;
10859 tree attribs;
10860
10861
10862 cp_parser_require_keyword (parser, RID_USING, "`using'");
10863
10864 cp_parser_require_keyword (parser, RID_NAMESPACE, "`namespace'");
10865
10866 cp_parser_global_scope_opt (parser, false);
10867
10868 cp_parser_nested_name_specifier_opt (parser,
10869 false,
10870 true,
10871 false,
10872 true);
10873
10874 namespace_decl = cp_parser_namespace_name (parser);
10875
10876 attribs = cp_parser_attributes_opt (parser);
10877
10878 parse_using_directive (namespace_decl, attribs);
10879
10880 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
10881 }
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899 static void
10900 cp_parser_asm_definition (cp_parser* parser)
10901 {
10902 tree string;
10903 tree outputs = NULL_TREE;
10904 tree inputs = NULL_TREE;
10905 tree clobbers = NULL_TREE;
10906 tree asm_stmt;
10907 bool volatile_p = false;
10908 bool extended_p = false;
10909
10910
10911 cp_parser_require_keyword (parser, RID_ASM, "`asm'");
10912
10913 if (cp_parser_allow_gnu_extensions_p (parser)
10914 && cp_lexer_next_token_is_keyword (parser->lexer, RID_VOLATILE))
10915 {
10916
10917 volatile_p = true;
10918
10919 cp_lexer_consume_token (parser->lexer);
10920 }
10921
10922 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
10923 return;
10924
10925 string = cp_parser_string_literal (parser, false, false);
10926 if (string == error_mark_node)
10927 {
10928 cp_parser_skip_to_closing_parenthesis (parser, true, false,
10929 true);
10930 return;
10931 }
10932
10933
10934
10935
10936
10937
10938 if (cp_parser_allow_gnu_extensions_p (parser)
10939 && parser->in_function_body
10940 && (cp_lexer_next_token_is (parser->lexer, CPP_COLON)
10941 || cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)))
10942 {
10943 bool inputs_p = false;
10944 bool clobbers_p = false;
10945
10946
10947 extended_p = true;
10948
10949
10950 if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
10951 {
10952
10953 cp_lexer_consume_token (parser->lexer);
10954
10955 if (cp_lexer_next_token_is_not (parser->lexer,
10956 CPP_COLON)
10957 && cp_lexer_next_token_is_not (parser->lexer,
10958 CPP_SCOPE)
10959 && cp_lexer_next_token_is_not (parser->lexer,
10960 CPP_CLOSE_PAREN))
10961 outputs = cp_parser_asm_operand_list (parser);
10962 }
10963
10964
10965 else if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
10966
10967 inputs_p = true;
10968
10969
10970 if (inputs_p
10971 || cp_lexer_next_token_is (parser->lexer, CPP_COLON))
10972 {
10973
10974 cp_lexer_consume_token (parser->lexer);
10975
10976 if (cp_lexer_next_token_is_not (parser->lexer,
10977 CPP_COLON)
10978 && cp_lexer_next_token_is_not (parser->lexer,
10979 CPP_CLOSE_PAREN))
10980 inputs = cp_parser_asm_operand_list (parser);
10981 }
10982 else if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
10983
10984 clobbers_p = true;
10985
10986
10987 if (clobbers_p
10988 || cp_lexer_next_token_is (parser->lexer, CPP_COLON))
10989 {
10990
10991 cp_lexer_consume_token (parser->lexer);
10992
10993 if (cp_lexer_next_token_is_not (parser->lexer,
10994 CPP_CLOSE_PAREN))
10995 clobbers = cp_parser_asm_clobber_list (parser);
10996 }
10997 }
10998
10999 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
11000 cp_parser_skip_to_closing_parenthesis (parser, true, false,
11001 true);
11002 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
11003
11004
11005 if (parser->in_function_body)
11006 {
11007 asm_stmt = finish_asm_stmt (volatile_p, string, outputs,
11008 inputs, clobbers);
11009
11010 if (!extended_p)
11011 {
11012 tree temp = asm_stmt;
11013 if (TREE_CODE (temp) == CLEANUP_POINT_EXPR)
11014 temp = TREE_OPERAND (temp, 0);
11015
11016 ASM_INPUT_P (temp) = 1;
11017 }
11018 }
11019 else
11020 cgraph_add_asm_node (string);
11021 }
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063 static tree
11064 cp_parser_init_declarator (cp_parser* parser,
11065 cp_decl_specifier_seq *decl_specifiers,
11066 VEC (deferred_access_check,gc)* checks,
11067 bool function_definition_allowed_p,
11068 bool member_p,
11069 int declares_class_or_enum,
11070 bool* function_definition_p)
11071 {
11072 cp_token *token;
11073 cp_declarator *declarator;
11074 tree prefix_attributes;
11075 tree attributes;
11076 tree asm_specification;
11077 tree initializer;
11078 tree decl = NULL_TREE;
11079 tree scope;
11080 bool is_initialized;
11081
11082
11083
11084 enum cpp_ttype initialization_kind;
11085 bool is_parenthesized_init = false;
11086 bool is_non_constant_init;
11087 int ctor_dtor_or_conv_p;
11088 bool friend_p;
11089 tree pushed_scope = NULL;
11090
11091
11092
11093 prefix_attributes = decl_specifiers->attributes;
11094
11095
11096
11097 if (function_definition_p)
11098 *function_definition_p = false;
11099
11100
11101
11102
11103 resume_deferring_access_checks ();
11104
11105
11106 declarator
11107 = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
11108 &ctor_dtor_or_conv_p,
11109 NULL,
11110 false);
11111
11112 stop_deferring_access_checks ();
11113
11114
11115
11116 if (declarator == cp_error_declarator)
11117 return error_mark_node;
11118
11119
11120 if (!cp_parser_check_declarator_template_parameters (parser, declarator))
11121 return error_mark_node;
11122
11123 if (declares_class_or_enum & 2)
11124 cp_parser_check_for_definition_in_return_type (declarator,
11125 decl_specifiers->type);
11126
11127
11128
11129
11130 scope = get_scope_of_declarator (declarator);
11131
11132
11133
11134 if (cp_parser_allow_gnu_extensions_p (parser))
11135 {
11136
11137 asm_specification = cp_parser_asm_specification_opt (parser);
11138
11139 attributes = cp_parser_attributes_opt (parser);
11140 }
11141 else
11142 {
11143 asm_specification = NULL_TREE;
11144 attributes = NULL_TREE;
11145 }
11146
11147
11148 token = cp_lexer_peek_token (parser->lexer);
11149
11150
11151 if (cp_parser_token_starts_function_definition_p (token))
11152 {
11153 if (!function_definition_allowed_p)
11154 {
11155
11156
11157 cp_parser_error (parser,
11158 "a function-definition is not allowed here");
11159 return error_mark_node;
11160 }
11161 else
11162 {
11163
11164
11165 if (asm_specification)
11166 error ("an asm-specification is not allowed on a function-definition");
11167 if (attributes)
11168 error ("attributes are not allowed on a function-definition");
11169
11170 *function_definition_p = true;
11171
11172
11173 if (member_p)
11174 decl = cp_parser_save_member_function_body (parser,
11175 decl_specifiers,
11176 declarator,
11177 prefix_attributes);
11178 else
11179 decl
11180 = (cp_parser_function_definition_from_specifiers_and_declarator
11181 (parser, decl_specifiers, prefix_attributes, declarator));
11182
11183 return decl;
11184 }
11185 }
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195 if (!decl_specifiers->any_specifiers_p && ctor_dtor_or_conv_p <= 0)
11196 {
11197 cp_parser_error (parser,
11198 "expected constructor, destructor, or type conversion");
11199 return error_mark_node;
11200 }
11201
11202
11203 if (token->type == CPP_EQ
11204 || token->type == CPP_OPEN_PAREN)
11205 {
11206 is_initialized = true;
11207 initialization_kind = token->type;
11208 }
11209 else
11210 {
11211
11212
11213 if (token->type != CPP_COMMA
11214 && token->type != CPP_SEMICOLON)
11215 {
11216 cp_parser_error (parser, "expected initializer");
11217 return error_mark_node;
11218 }
11219 is_initialized = false;
11220 initialization_kind = CPP_EOF;
11221 }
11222
11223
11224
11225
11226 cp_parser_commit_to_tentative_parse (parser);
11227
11228
11229
11230
11231
11232 if (decl_specifiers->any_specifiers_p
11233 && decl_specifiers->type == error_mark_node)
11234 {
11235 cp_parser_error (parser, "invalid type in declaration");
11236 decl_specifiers->type = integer_type_node;
11237 }
11238
11239
11240 friend_p = cp_parser_friend_p (decl_specifiers);
11241
11242
11243
11244
11245 if (!member_p)
11246 {
11247 if (parser->in_unbraced_linkage_specification_p)
11248 decl_specifiers->storage_class = sc_extern;
11249 decl = start_decl (declarator, decl_specifiers,
11250 is_initialized, attributes, prefix_attributes,
11251 &pushed_scope);
11252 }
11253 else if (scope)
11254
11255
11256 pushed_scope = push_scope (scope);
11257
11258
11259
11260 if (!member_p && decl)
11261 {
11262 tree saved_current_function_decl = NULL_TREE;
11263
11264
11265
11266
11267 if (TREE_CODE (decl) == FUNCTION_DECL)
11268 {
11269 saved_current_function_decl = current_function_decl;
11270 current_function_decl = decl;
11271 }
11272
11273
11274 cp_parser_perform_template_parameter_access_checks (checks);
11275
11276
11277
11278 perform_deferred_access_checks ();
11279
11280
11281 if (TREE_CODE (decl) == FUNCTION_DECL)
11282 current_function_decl = saved_current_function_decl;
11283 }
11284
11285
11286 initializer = NULL_TREE;
11287 is_parenthesized_init = false;
11288 is_non_constant_init = true;
11289 if (is_initialized)
11290 {
11291 if (function_declarator_p (declarator))
11292 {
11293 if (initialization_kind == CPP_EQ)
11294 initializer = cp_parser_pure_specifier (parser);
11295 else
11296 {
11297
11298
11299
11300 if (decl != error_mark_node)
11301 error ("initializer provided for function");
11302 cp_parser_skip_to_closing_parenthesis (parser,
11303 true,
11304 false,
11305 true);
11306 }
11307 }
11308 else
11309 initializer = cp_parser_initializer (parser,
11310 &is_parenthesized_init,
11311 &is_non_constant_init);
11312 }
11313
11314
11315
11316
11317
11318 if (cp_parser_allow_gnu_extensions_p (parser) && is_parenthesized_init)
11319 if (cp_parser_attributes_opt (parser))
11320 warning (OPT_Wattributes,
11321 "attributes after parenthesized initializer ignored");
11322
11323
11324
11325 if (member_p)
11326 {
11327 if (pushed_scope)
11328 {
11329 pop_scope (pushed_scope);
11330 pushed_scope = false;
11331 }
11332 decl = grokfield (declarator, decl_specifiers,
11333 initializer, !is_non_constant_init,
11334 NULL_TREE,
11335 prefix_attributes);
11336 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
11337 cp_parser_save_default_args (parser, decl);
11338 }
11339
11340
11341
11342 if (!friend_p && decl && decl != error_mark_node)
11343 {
11344 cp_finish_decl (decl,
11345 initializer, !is_non_constant_init,
11346 asm_specification,
11347
11348
11349
11350
11351 ((is_parenthesized_init || !is_initialized)
11352 ? 0 : LOOKUP_ONLYCONVERTING));
11353 }
11354 if (!friend_p && pushed_scope)
11355 pop_scope (pushed_scope);
11356
11357 return decl;
11358 }
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399 static cp_declarator *
11400 cp_parser_declarator (cp_parser* parser,
11401 cp_parser_declarator_kind dcl_kind,
11402 int* ctor_dtor_or_conv_p,
11403 bool* parenthesized_p,
11404 bool member_p)
11405 {
11406 cp_token *token;
11407 cp_declarator *declarator;
11408 enum tree_code code;
11409 cp_cv_quals cv_quals;
11410 tree class_type;
11411 tree attributes = NULL_TREE;
11412
11413
11414
11415 if (ctor_dtor_or_conv_p)
11416 *ctor_dtor_or_conv_p = 0;
11417
11418 if (cp_parser_allow_gnu_extensions_p (parser))
11419 attributes = cp_parser_attributes_opt (parser);
11420
11421
11422 token = cp_lexer_peek_token (parser->lexer);
11423
11424
11425 cp_parser_parse_tentatively (parser);
11426
11427 code = cp_parser_ptr_operator (parser,
11428 &class_type,
11429 &cv_quals);
11430
11431 if (cp_parser_parse_definitely (parser))
11432 {
11433
11434
11435 if (parenthesized_p)
11436 *parenthesized_p = true;
11437
11438
11439 if (dcl_kind != CP_PARSER_DECLARATOR_NAMED)
11440 cp_parser_parse_tentatively (parser);
11441
11442
11443 declarator = cp_parser_declarator (parser, dcl_kind,
11444 NULL,
11445 NULL,
11446 false);
11447
11448
11449
11450 if (dcl_kind != CP_PARSER_DECLARATOR_NAMED
11451 && !cp_parser_parse_definitely (parser))
11452 declarator = NULL;
11453
11454
11455 if (class_type)
11456 declarator = make_ptrmem_declarator (cv_quals,
11457 class_type,
11458 declarator);
11459 else if (code == INDIRECT_REF)
11460 declarator = make_pointer_declarator (cv_quals, declarator);
11461 else
11462 declarator = make_reference_declarator (cv_quals, declarator);
11463 }
11464
11465 else
11466 {
11467 if (parenthesized_p)
11468 *parenthesized_p = cp_lexer_next_token_is (parser->lexer,
11469 CPP_OPEN_PAREN);
11470 declarator = cp_parser_direct_declarator (parser, dcl_kind,
11471 ctor_dtor_or_conv_p,
11472 member_p);
11473 }
11474
11475 if (attributes && declarator && declarator != cp_error_declarator)
11476 declarator->attributes = attributes;
11477
11478 return declarator;
11479 }
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508 static cp_declarator *
11509 cp_parser_direct_declarator (cp_parser* parser,
11510 cp_parser_declarator_kind dcl_kind,
11511 int* ctor_dtor_or_conv_p,
11512 bool member_p)
11513 {
11514 cp_token *token;
11515 cp_declarator *declarator = NULL;
11516 tree scope = NULL_TREE;
11517 bool saved_default_arg_ok_p = parser->default_arg_ok_p;
11518 bool saved_in_declarator_p = parser->in_declarator_p;
11519 bool first = true;
11520 tree pushed_scope = NULL_TREE;
11521
11522 while (true)
11523 {
11524
11525 token = cp_lexer_peek_token (parser->lexer);
11526 if (token->type == CPP_OPEN_PAREN)
11527 {
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566 if (!first || dcl_kind != CP_PARSER_DECLARATOR_NAMED)
11567 {
11568 cp_parameter_declarator *params;
11569 unsigned saved_num_template_parameter_lists;
11570
11571
11572
11573
11574
11575
11576
11577 if (!member_p)
11578 cp_parser_parse_tentatively (parser);
11579
11580
11581 cp_lexer_consume_token (parser->lexer);
11582 if (first)
11583 {
11584
11585
11586 parser->default_arg_ok_p = false;
11587 parser->in_declarator_p = true;
11588 }
11589
11590
11591
11592 saved_num_template_parameter_lists
11593 = parser->num_template_parameter_lists;
11594 parser->num_template_parameter_lists = 0;
11595
11596
11597 params = cp_parser_parameter_declaration_clause (parser);
11598
11599 parser->num_template_parameter_lists
11600 = saved_num_template_parameter_lists;
11601
11602
11603
11604 if (member_p || cp_parser_parse_definitely (parser))
11605 {
11606 cp_cv_quals cv_quals;
11607 tree exception_specification;
11608
11609 if (ctor_dtor_or_conv_p)
11610 *ctor_dtor_or_conv_p = *ctor_dtor_or_conv_p < 0;
11611 first = false;
11612
11613 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
11614
11615
11616 cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
11617
11618 exception_specification
11619 = cp_parser_exception_specification_opt (parser);
11620
11621
11622 declarator = make_call_declarator (declarator,
11623 params,
11624 cv_quals,
11625 exception_specification);
11626
11627
11628
11629 parser->default_arg_ok_p = false;
11630
11631
11632 continue;
11633 }
11634 }
11635
11636
11637
11638 if (first)
11639 {
11640 bool saved_in_type_id_in_expr_p;
11641
11642 parser->default_arg_ok_p = saved_default_arg_ok_p;
11643 parser->in_declarator_p = saved_in_declarator_p;
11644
11645
11646 cp_lexer_consume_token (parser->lexer);
11647
11648 saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
11649 parser->in_type_id_in_expr_p = true;
11650 declarator
11651 = cp_parser_declarator (parser, dcl_kind, ctor_dtor_or_conv_p,
11652 NULL,
11653 member_p);
11654 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
11655 first = false;
11656
11657 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
11658 declarator = cp_error_declarator;
11659 if (declarator == cp_error_declarator)
11660 break;
11661
11662 goto handle_declarator;
11663 }
11664
11665 else
11666 break;
11667 }
11668 else if ((!first || dcl_kind != CP_PARSER_DECLARATOR_NAMED)
11669 && token->type == CPP_OPEN_SQUARE)
11670 {
11671
11672 tree bounds;
11673
11674 if (ctor_dtor_or_conv_p)
11675 *ctor_dtor_or_conv_p = 0;
11676
11677 first = false;
11678 parser->default_arg_ok_p = false;
11679 parser->in_declarator_p = true;
11680
11681 cp_lexer_consume_token (parser->lexer);
11682
11683 token = cp_lexer_peek_token (parser->lexer);
11684
11685
11686 if (token->type != CPP_CLOSE_SQUARE)
11687 {
11688 bool non_constant_p;
11689
11690 bounds
11691 = cp_parser_constant_expression (parser,
11692 true,
11693 &non_constant_p);
11694 if (!non_constant_p)
11695 bounds = fold_non_dependent_expr (bounds);
11696
11697
11698
11699 else if (!parser->in_function_body)
11700 {
11701 error ("array bound is not an integer constant");
11702 bounds = error_mark_node;
11703 }
11704 }
11705 else
11706 bounds = NULL_TREE;
11707
11708 if (!cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'"))
11709 {
11710 declarator = cp_error_declarator;
11711 break;
11712 }
11713
11714 declarator = make_array_declarator (declarator, bounds);
11715 }
11716 else if (first && dcl_kind != CP_PARSER_DECLARATOR_ABSTRACT)
11717 {
11718 tree qualifying_scope;
11719 tree unqualified_name;
11720 special_function_kind sfk;
11721 bool abstract_ok;
11722
11723
11724 abstract_ok = (dcl_kind == CP_PARSER_DECLARATOR_EITHER);
11725 if (abstract_ok)
11726 cp_parser_parse_tentatively (parser);
11727 unqualified_name
11728 = cp_parser_declarator_id (parser, abstract_ok);
11729 qualifying_scope = parser->scope;
11730 if (abstract_ok)
11731 {
11732 if (!cp_parser_parse_definitely (parser))
11733 unqualified_name = error_mark_node;
11734 else if (unqualified_name
11735 && (qualifying_scope
11736 || (TREE_CODE (unqualified_name)
11737 != IDENTIFIER_NODE)))
11738 {
11739 cp_parser_error (parser, "expected unqualified-id");
11740 unqualified_name = error_mark_node;
11741 }
11742 }
11743
11744 if (!unqualified_name)
11745 return NULL;
11746 if (unqualified_name == error_mark_node)
11747 {
11748 declarator = cp_error_declarator;
11749 break;
11750 }
11751
11752 if (qualifying_scope && at_namespace_scope_p ()
11753 && TREE_CODE (qualifying_scope) == TYPENAME_TYPE)
11754 {
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771 tree type;
11772
11773
11774 type = resolve_typename_type (qualifying_scope,
11775 false);
11776
11777 if (type == error_mark_node)
11778 error ("%<%T::%D%> is not a type",
11779 TYPE_CONTEXT (qualifying_scope),
11780 TYPE_IDENTIFIER (qualifying_scope));
11781 qualifying_scope = type;
11782 }
11783
11784 sfk = sfk_none;
11785 if (unqualified_name)
11786 {
11787 tree class_type;
11788
11789 if (qualifying_scope
11790 && CLASS_TYPE_P (qualifying_scope))
11791 class_type = qualifying_scope;
11792 else
11793 class_type = current_class_type;
11794
11795 if (TREE_CODE (unqualified_name) == TYPE_DECL)
11796 {
11797 tree name_type = TREE_TYPE (unqualified_name);
11798 if (class_type && same_type_p (name_type, class_type))
11799 {
11800 if (qualifying_scope
11801 && CLASSTYPE_USE_TEMPLATE (name_type))
11802 {
11803 error ("invalid use of constructor as a template");
11804 inform ("use %<%T::%D%> instead of %<%T::%D%> to "
11805 "name the constructor in a qualified name",
11806 class_type,
11807 DECL_NAME (TYPE_TI_TEMPLATE (class_type)),
11808 class_type, name_type);
11809 declarator = cp_error_declarator;
11810 break;
11811 }
11812 else
11813 unqualified_name = constructor_name (class_type);
11814 }
11815 else
11816 {
11817
11818
11819
11820
11821 cp_parser_error (parser, "invalid declarator");
11822 declarator = cp_error_declarator;
11823 break;
11824 }
11825 }
11826
11827 if (class_type)
11828 {
11829 if (TREE_CODE (unqualified_name) == BIT_NOT_EXPR)
11830 sfk = sfk_destructor;
11831 else if (IDENTIFIER_TYPENAME_P (unqualified_name))
11832 sfk = sfk_conversion;
11833 else if (
11834
11835
11836 !TYPE_WAS_ANONYMOUS (class_type)
11837 && constructor_name_p (unqualified_name,
11838 class_type))
11839 {
11840 unqualified_name = constructor_name (class_type);
11841 sfk = sfk_constructor;
11842 }
11843
11844 if (ctor_dtor_or_conv_p && sfk != sfk_none)
11845 *ctor_dtor_or_conv_p = -1;
11846 }
11847 }
11848 declarator = make_id_declarator (qualifying_scope,
11849 unqualified_name,
11850 sfk);
11851 declarator->id_loc = token->location;
11852
11853 handle_declarator:;
11854 scope = get_scope_of_declarator (declarator);
11855 if (scope)
11856
11857
11858 pushed_scope = push_scope (scope);
11859 parser->in_declarator_p = true;
11860 if ((ctor_dtor_or_conv_p && *ctor_dtor_or_conv_p)
11861 || (declarator && declarator->kind == cdk_id))
11862
11863
11864 parser->default_arg_ok_p = saved_default_arg_ok_p;
11865 else
11866 parser->default_arg_ok_p = false;
11867
11868 first = false;
11869 }
11870
11871 else
11872 break;
11873 }
11874
11875
11876
11877 if (!declarator)
11878 cp_parser_error (parser, "expected declarator");
11879
11880
11881 if (pushed_scope)
11882 pop_scope (pushed_scope);
11883
11884 parser->default_arg_ok_p = saved_default_arg_ok_p;
11885 parser->in_declarator_p = saved_in_declarator_p;
11886
11887 return declarator;
11888 }
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909 static enum tree_code
11910 cp_parser_ptr_operator (cp_parser* parser,
11911 tree* type,
11912 cp_cv_quals *cv_quals)
11913 {
11914 enum tree_code code = ERROR_MARK;
11915 cp_token *token;
11916
11917
11918 *type = NULL_TREE;
11919
11920 *cv_quals = TYPE_UNQUALIFIED;
11921
11922
11923 token = cp_lexer_peek_token (parser->lexer);
11924
11925 if (token->type == CPP_MULT || token->type == CPP_AND)
11926 {
11927
11928 code = (token->type == CPP_AND ? ADDR_EXPR : INDIRECT_REF);
11929
11930
11931 cp_lexer_consume_token (parser->lexer);
11932
11933
11934
11935
11936
11937 if (code == INDIRECT_REF
11938 || cp_parser_allow_gnu_extensions_p (parser))
11939 *cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
11940 }
11941 else
11942 {
11943
11944 cp_parser_parse_tentatively (parser);
11945
11946 cp_parser_global_scope_opt (parser,
11947 false);
11948
11949 cp_parser_nested_name_specifier (parser,
11950 false,
11951 true,
11952 false,
11953 false);
11954
11955
11956 if (!cp_parser_error_occurred (parser)
11957 && cp_parser_require (parser, CPP_MULT, "`*'"))
11958 {
11959
11960 code = INDIRECT_REF;
11961
11962 if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
11963 error ("%qD is a namespace", parser->scope);
11964 else
11965 {
11966
11967
11968 *type = parser->scope;
11969
11970 parser->scope = NULL_TREE;
11971 parser->qualifying_scope = NULL_TREE;
11972 parser->object_scope = NULL_TREE;
11973
11974 *cv_quals = cp_parser_cv_qualifier_seq_opt (parser);
11975 }
11976 }
11977
11978 if (!cp_parser_parse_definitely (parser))
11979 cp_parser_error (parser, "expected ptr-operator");
11980 }
11981
11982 return code;
11983 }
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001 static cp_cv_quals
12002 cp_parser_cv_qualifier_seq_opt (cp_parser* parser)
12003 {
12004 cp_cv_quals cv_quals = TYPE_UNQUALIFIED;
12005
12006 while (true)
12007 {
12008 cp_token *token;
12009 cp_cv_quals cv_qualifier;
12010
12011
12012 token = cp_lexer_peek_token (parser->lexer);
12013
12014 switch (token->keyword)
12015 {
12016 case RID_CONST:
12017 cv_qualifier = TYPE_QUAL_CONST;
12018 break;
12019
12020 case RID_VOLATILE:
12021 cv_qualifier = TYPE_QUAL_VOLATILE;
12022 break;
12023
12024 case RID_RESTRICT:
12025 cv_qualifier = TYPE_QUAL_RESTRICT;
12026 break;
12027
12028 default:
12029 cv_qualifier = TYPE_UNQUALIFIED;
12030 break;
12031 }
12032
12033 if (!cv_qualifier)
12034 break;
12035
12036 if (cv_quals & cv_qualifier)
12037 {
12038 error ("duplicate cv-qualifier");
12039 cp_lexer_purge_token (parser->lexer);
12040 }
12041 else
12042 {
12043 cp_lexer_consume_token (parser->lexer);
12044 cv_quals |= cv_qualifier;
12045 }
12046 }
12047
12048 return cv_quals;
12049 }
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064 static tree
12065 cp_parser_declarator_id (cp_parser* parser, bool optional_p)
12066 {
12067 tree id;
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082 id = cp_parser_id_expression (parser,
12083 false,
12084 false,
12085 NULL,
12086 true,
12087 optional_p);
12088 if (id && BASELINK_P (id))
12089 id = BASELINK_FUNCTIONS (id);
12090 return id;
12091 }
12092
12093
12094
12095
12096
12097
12098
12099
12100 static tree
12101 cp_parser_type_id (cp_parser* parser)
12102 {
12103 cp_decl_specifier_seq type_specifier_seq;
12104 cp_declarator *abstract_declarator;
12105
12106
12107 cp_parser_type_specifier_seq (parser, false,
12108 &type_specifier_seq);
12109 if (type_specifier_seq.type == error_mark_node)
12110 return error_mark_node;
12111
12112
12113 cp_parser_parse_tentatively (parser);
12114
12115 abstract_declarator
12116 = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_ABSTRACT, NULL,
12117 NULL,
12118 false);
12119
12120 if (!cp_parser_parse_definitely (parser))
12121 abstract_declarator = NULL;
12122
12123 return groktypename (&type_specifier_seq, abstract_declarator);
12124 }
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141 static void
12142 cp_parser_type_specifier_seq (cp_parser* parser,
12143 bool is_condition,
12144 cp_decl_specifier_seq *type_specifier_seq)
12145 {
12146 bool seen_type_specifier = false;
12147 cp_parser_flags flags = CP_PARSER_FLAGS_OPTIONAL;
12148
12149
12150 clear_decl_specs (type_specifier_seq);
12151
12152
12153 while (true)
12154 {
12155 tree type_specifier;
12156 bool is_cv_qualifier;
12157
12158
12159 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_ATTRIBUTE))
12160 {
12161 type_specifier_seq->attributes =
12162 chainon (type_specifier_seq->attributes,
12163 cp_parser_attributes_opt (parser));
12164 continue;
12165 }
12166
12167
12168 type_specifier = cp_parser_type_specifier (parser,
12169 flags,
12170 type_specifier_seq,
12171 false,
12172 NULL,
12173 &is_cv_qualifier);
12174 if (!type_specifier)
12175 {
12176
12177
12178 if (!seen_type_specifier)
12179 {
12180 cp_parser_error (parser, "expected type-specifier");
12181 type_specifier_seq->type = error_mark_node;
12182 return;
12183 }
12184
12185
12186 break;
12187 }
12188
12189 seen_type_specifier = true;
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206 if (is_condition && !is_cv_qualifier)
12207 flags |= CP_PARSER_FLAGS_NO_USER_DEFINED_TYPES;
12208 }
12209
12210 cp_parser_check_decl_spec (type_specifier_seq);
12211 }
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223 static cp_parameter_declarator *
12224 cp_parser_parameter_declaration_clause (cp_parser* parser)
12225 {
12226 cp_parameter_declarator *parameters;
12227 cp_token *token;
12228 bool ellipsis_p;
12229 bool is_error;
12230
12231
12232 token = cp_lexer_peek_token (parser->lexer);
12233
12234 if (token->type == CPP_ELLIPSIS)
12235 {
12236
12237 cp_lexer_consume_token (parser->lexer);
12238 return NULL;
12239 }
12240 else if (token->type == CPP_CLOSE_PAREN)
12241
12242 {
12243 #ifndef NO_IMPLICIT_EXTERN_C
12244 if (in_system_header && current_class_type == NULL
12245 && current_lang_name == lang_name_c)
12246 return NULL;
12247 else
12248 #endif
12249 return no_parameters;
12250 }
12251
12252 else if (token->keyword == RID_VOID
12253 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
12254 == CPP_CLOSE_PAREN))
12255 {
12256
12257 cp_lexer_consume_token (parser->lexer);
12258
12259 return no_parameters;
12260 }
12261
12262
12263 parameters = cp_parser_parameter_declaration_list (parser, &is_error);
12264
12265
12266
12267 if (is_error)
12268 return NULL;
12269
12270
12271 token = cp_lexer_peek_token (parser->lexer);
12272
12273 if (token->type == CPP_COMMA)
12274 {
12275
12276 cp_lexer_consume_token (parser->lexer);
12277
12278 ellipsis_p
12279 = (cp_parser_require (parser, CPP_ELLIPSIS, "`...'") != NULL);
12280 }
12281
12282
12283 else if (token->type == CPP_ELLIPSIS)
12284 {
12285
12286 cp_lexer_consume_token (parser->lexer);
12287
12288 ellipsis_p = true;
12289 }
12290 else
12291 ellipsis_p = false;
12292
12293
12294 if (parameters && ellipsis_p)
12295 parameters->ellipsis_p = true;
12296
12297 return parameters;
12298 }
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311 static cp_parameter_declarator *
12312 cp_parser_parameter_declaration_list (cp_parser* parser, bool *is_error)
12313 {
12314 cp_parameter_declarator *parameters = NULL;
12315 cp_parameter_declarator **tail = ¶meters;
12316 bool saved_in_unbraced_linkage_specification_p;
12317
12318
12319 *is_error = false;
12320
12321
12322
12323 saved_in_unbraced_linkage_specification_p
12324 = parser->in_unbraced_linkage_specification_p;
12325 parser->in_unbraced_linkage_specification_p = false;
12326
12327
12328 while (true)
12329 {
12330 cp_parameter_declarator *parameter;
12331 bool parenthesized_p;
12332
12333 parameter
12334 = cp_parser_parameter_declaration (parser,
12335 false,
12336 &parenthesized_p);
12337
12338
12339
12340 if (!parameter)
12341 {
12342 *is_error = true;
12343 parameters = NULL;
12344 break;
12345 }
12346
12347 *tail = parameter;
12348 tail = ¶meter->next;
12349
12350
12351 if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN)
12352 || cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)
12353
12354 || cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)
12355 || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
12356
12357 break;
12358 else if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
12359 {
12360 cp_token *token;
12361
12362
12363 token = cp_lexer_peek_nth_token (parser->lexer, 2);
12364
12365 if (token->type == CPP_ELLIPSIS)
12366 break;
12367
12368
12369 cp_lexer_consume_token (parser->lexer);
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382 if (!parser->in_template_argument_list_p
12383 && !parser->in_type_id_in_expr_p
12384 && cp_parser_uncommitted_to_tentative_parse_p (parser)
12385
12386
12387
12388
12389 && !parenthesized_p)
12390 cp_parser_commit_to_tentative_parse (parser);
12391 }
12392 else
12393 {
12394 cp_parser_error (parser, "expected %<,%> or %<...%>");
12395 if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
12396 cp_parser_skip_to_closing_parenthesis (parser,
12397 true,
12398 false,
12399 false);
12400 break;
12401 }
12402 }
12403
12404 parser->in_unbraced_linkage_specification_p
12405 = saved_in_unbraced_linkage_specification_p;
12406
12407 return parameters;
12408 }
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427 static cp_parameter_declarator *
12428 cp_parser_parameter_declaration (cp_parser *parser,
12429 bool template_parm_p,
12430 bool *parenthesized_p)
12431 {
12432 int declares_class_or_enum;
12433 bool greater_than_is_operator_p;
12434 cp_decl_specifier_seq decl_specifiers;
12435 cp_declarator *declarator;
12436 tree default_argument;
12437 cp_token *token;
12438 const char *saved_message;
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448 greater_than_is_operator_p = !template_parm_p;
12449
12450
12451 saved_message = parser->type_definition_forbidden_message;
12452 parser->type_definition_forbidden_message
12453 = "types may not be defined in parameter types";
12454
12455
12456 cp_parser_decl_specifier_seq (parser,
12457 CP_PARSER_FLAGS_NONE,
12458 &decl_specifiers,
12459 &declares_class_or_enum);
12460
12461
12462 if (cp_parser_error_occurred (parser))
12463 {
12464 parser->type_definition_forbidden_message = saved_message;
12465 return NULL;
12466 }
12467
12468
12469 token = cp_lexer_peek_token (parser->lexer);
12470
12471
12472 if (token->type == CPP_CLOSE_PAREN
12473 || token->type == CPP_COMMA
12474 || token->type == CPP_EQ
12475 || token->type == CPP_ELLIPSIS
12476 || token->type == CPP_GREATER)
12477 {
12478 declarator = NULL;
12479 if (parenthesized_p)
12480 *parenthesized_p = false;
12481 }
12482
12483 else
12484 {
12485 bool saved_default_arg_ok_p = parser->default_arg_ok_p;
12486 parser->default_arg_ok_p = false;
12487
12488
12489
12490
12491
12492 if (!parser->in_template_argument_list_p
12493
12494
12495
12496
12497
12498
12499
12500 && !parser->in_type_id_in_expr_p
12501 && cp_parser_uncommitted_to_tentative_parse_p (parser)
12502 && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
12503 cp_parser_commit_to_tentative_parse (parser);
12504
12505 declarator = cp_parser_declarator (parser,
12506 CP_PARSER_DECLARATOR_EITHER,
12507 NULL,
12508 parenthesized_p,
12509 false);
12510 parser->default_arg_ok_p = saved_default_arg_ok_p;
12511
12512 decl_specifiers.attributes
12513 = chainon (decl_specifiers.attributes,
12514 cp_parser_attributes_opt (parser));
12515 }
12516
12517
12518
12519 parser->type_definition_forbidden_message = saved_message;
12520
12521
12522 if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
12523 {
12524 bool saved_greater_than_is_operator_p;
12525
12526 cp_lexer_consume_token (parser->lexer);
12527
12528
12529
12530 if (!template_parm_p && at_class_scope_p ()
12531 && TYPE_BEING_DEFINED (current_class_type))
12532 {
12533 unsigned depth = 0;
12534 cp_token *first_token;
12535 cp_token *token;
12536
12537
12538
12539 first_token = cp_lexer_peek_token (parser->lexer);
12540 while (true)
12541 {
12542 bool done = false;
12543
12544
12545 token = cp_lexer_peek_token (parser->lexer);
12546
12547 switch (token->type)
12548 {
12549
12550
12551 case CPP_COMMA:
12552 case CPP_CLOSE_PAREN:
12553 case CPP_ELLIPSIS:
12554
12555
12556
12557 case CPP_SEMICOLON:
12558 case CPP_CLOSE_BRACE:
12559 case CPP_CLOSE_SQUARE:
12560 if (depth == 0)
12561 done = true;
12562
12563 else if (token->type == CPP_CLOSE_PAREN
12564 || token->type == CPP_CLOSE_BRACE
12565 || token->type == CPP_CLOSE_SQUARE)
12566 --depth;
12567 break;
12568
12569 case CPP_OPEN_PAREN:
12570 case CPP_OPEN_SQUARE:
12571 case CPP_OPEN_BRACE:
12572 ++depth;
12573 break;
12574
12575 case CPP_GREATER:
12576
12577
12578
12579 if (!depth && !greater_than_is_operator_p)
12580 done = true;
12581 break;
12582
12583
12584 case CPP_EOF:
12585 case CPP_PRAGMA_EOL:
12586 error ("file ends in default argument");
12587 done = true;
12588 break;
12589
12590 case CPP_NAME:
12591 case CPP_SCOPE:
12592
12593
12594
12595
12596
12597
12598
12599 break;
12600
12601 default:
12602 break;
12603 }
12604
12605
12606 if (done)
12607 break;
12608
12609
12610 token = cp_lexer_consume_token (parser->lexer);
12611 }
12612
12613
12614
12615 default_argument = make_node (DEFAULT_ARG);
12616 DEFARG_TOKENS (default_argument)
12617 = cp_token_cache_new (first_token, token);
12618 DEFARG_INSTANTIATIONS (default_argument) = NULL;
12619 }
12620
12621
12622 else
12623 {
12624 bool saved_local_variables_forbidden_p;
12625
12626
12627
12628 saved_greater_than_is_operator_p
12629 = parser->greater_than_is_operator_p;
12630 parser->greater_than_is_operator_p = greater_than_is_operator_p;
12631
12632
12633 saved_local_variables_forbidden_p
12634 = parser->local_variables_forbidden_p;
12635 parser->local_variables_forbidden_p = true;
12636
12637
12638
12639
12640
12641 ++function_depth;
12642
12643 if (template_parm_p)
12644 push_deferring_access_checks (dk_no_deferred);
12645 default_argument
12646 = cp_parser_assignment_expression (parser, false);
12647 if (template_parm_p)
12648 pop_deferring_access_checks ();
12649
12650 --function_depth;
12651 parser->greater_than_is_operator_p
12652 = saved_greater_than_is_operator_p;
12653 parser->local_variables_forbidden_p
12654 = saved_local_variables_forbidden_p;
12655 }
12656 if (!parser->default_arg_ok_p)
12657 {
12658 if (!flag_pedantic_errors)
12659 warning (0, "deprecated use of default argument for parameter of non-function");
12660 else
12661 {
12662 error ("default arguments are only permitted for function parameters");
12663 default_argument = NULL_TREE;
12664 }
12665 }
12666 }
12667 else
12668 default_argument = NULL_TREE;
12669
12670 return make_parameter_declarator (&decl_specifiers,
12671 declarator,
12672 default_argument);
12673 }
12674
12675
12676
12677
12678
12679
12680 static void
12681 cp_parser_function_body (cp_parser *parser)
12682 {
12683 cp_parser_compound_statement (parser, NULL, false);
12684 }
12685
12686
12687
12688
12689 static bool
12690 cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser)
12691 {
12692 tree body;
12693 bool ctor_initializer_p;
12694
12695
12696 body = begin_function_body ();
12697
12698 ctor_initializer_p = cp_parser_ctor_initializer_opt (parser);
12699
12700 cp_parser_function_body (parser);
12701
12702 finish_function_body (body);
12703
12704 return ctor_initializer_p;
12705 }
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722 static tree
12723 cp_parser_initializer (cp_parser* parser, bool* is_parenthesized_init,
12724 bool* non_constant_p)
12725 {
12726 cp_token *token;
12727 tree init;
12728
12729
12730 token = cp_lexer_peek_token (parser->lexer);
12731
12732
12733
12734 *is_parenthesized_init = (token->type == CPP_OPEN_PAREN);
12735
12736 *non_constant_p = false;
12737
12738 if (token->type == CPP_EQ)
12739 {
12740
12741 cp_lexer_consume_token (parser->lexer);
12742
12743 init = cp_parser_initializer_clause (parser, non_constant_p);
12744 }
12745 else if (token->type == CPP_OPEN_PAREN)
12746 init = cp_parser_parenthesized_expression_list (parser, false,
12747 false,
12748 non_constant_p);
12749 else
12750 {
12751
12752 cp_parser_error (parser, "expected initializer");
12753 init = error_mark_node;
12754 }
12755
12756 return init;
12757 }
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778 static tree
12779 cp_parser_initializer_clause (cp_parser* parser, bool* non_constant_p)
12780 {
12781 tree initializer;
12782
12783
12784 *non_constant_p = false;
12785
12786
12787
12788 if (cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
12789 {
12790 initializer
12791 = cp_parser_constant_expression (parser,
12792 true,
12793 non_constant_p);
12794 if (!*non_constant_p)
12795 initializer = fold_non_dependent_expr (initializer);
12796 }
12797 else
12798 {
12799
12800 cp_lexer_consume_token (parser->lexer);
12801
12802 initializer = make_node (CONSTRUCTOR);
12803
12804 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_BRACE))
12805 {
12806
12807 CONSTRUCTOR_ELTS (initializer)
12808 = cp_parser_initializer_list (parser, non_constant_p);
12809
12810 if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
12811 cp_lexer_consume_token (parser->lexer);
12812 }
12813
12814 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
12815 }
12816
12817 return initializer;
12818 }
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837 static VEC(constructor_elt,gc) *
12838 cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
12839 {
12840 VEC(constructor_elt,gc) *v = NULL;
12841
12842
12843 *non_constant_p = false;
12844
12845
12846 while (true)
12847 {
12848 cp_token *token;
12849 tree identifier;
12850 tree initializer;
12851 bool clause_non_constant_p;
12852
12853
12854
12855
12856 if (cp_parser_allow_gnu_extensions_p (parser)
12857 && cp_lexer_next_token_is (parser->lexer, CPP_NAME)
12858 && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_COLON)
12859 {
12860
12861 if (pedantic)
12862 pedwarn ("ISO C++ does not allow designated initializers");
12863
12864 identifier = cp_lexer_consume_token (parser->lexer)->u.value;
12865
12866 cp_lexer_consume_token (parser->lexer);
12867 }
12868 else
12869 identifier = NULL_TREE;
12870
12871
12872 initializer = cp_parser_initializer_clause (parser,
12873 &clause_non_constant_p);
12874
12875 if (clause_non_constant_p)
12876 *non_constant_p = true;
12877
12878
12879 CONSTRUCTOR_APPEND_ELT(v, identifier, initializer);
12880
12881
12882
12883 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
12884 break;
12885
12886
12887 token = cp_lexer_peek_nth_token (parser->lexer, 2);
12888
12889
12890
12891 if (token->type == CPP_CLOSE_BRACE)
12892 break;
12893
12894
12895 cp_lexer_consume_token (parser->lexer);
12896 }
12897
12898 return v;
12899 }
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920 static tree
12921 cp_parser_class_name (cp_parser *parser,
12922 bool typename_keyword_p,
12923 bool template_keyword_p,
12924 enum tag_types tag_type,
12925 bool check_dependency_p,
12926 bool class_head_p,
12927 bool is_declaration)
12928 {
12929 tree decl;
12930 tree scope;
12931 bool typename_p;
12932 cp_token *token;
12933
12934
12935 token = cp_lexer_peek_token (parser->lexer);
12936 if (token->type != CPP_NAME && token->type != CPP_TEMPLATE_ID)
12937 {
12938 cp_parser_error (parser, "expected class-name");
12939 return error_mark_node;
12940 }
12941
12942
12943
12944 scope = parser->scope;
12945 if (scope == error_mark_node)
12946 return error_mark_node;
12947
12948
12949
12950 typename_p = (typename_keyword_p && scope && TYPE_P (scope)
12951 && dependent_type_p (scope));
12952
12953
12954 if (token->type == CPP_NAME
12955 && !cp_parser_nth_token_starts_template_argument_list_p (parser, 2))
12956 {
12957 cp_token *identifier_token;
12958 tree identifier;
12959 bool ambiguous_p;
12960
12961
12962 identifier_token = cp_lexer_peek_token (parser->lexer);
12963 ambiguous_p = identifier_token->ambiguous_p;
12964 identifier = cp_parser_identifier (parser);
12965
12966
12967 if (identifier == error_mark_node)
12968 decl = error_mark_node;
12969
12970
12971 else if (typename_p)
12972 decl = identifier;
12973 else
12974 {
12975 tree ambiguous_decls;
12976
12977
12978
12979 if (ambiguous_p)
12980 {
12981 cp_parser_simulate_error (parser);
12982 return error_mark_node;
12983 }
12984
12985
12986
12987
12988
12989
12990
12991
12992 if (cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
12993 tag_type = typename_type;
12994
12995 decl = cp_parser_lookup_name (parser, identifier,
12996 tag_type,
12997 false,
12998 false,
12999 check_dependency_p,
13000 &ambiguous_decls);
13001 if (ambiguous_decls)
13002 {
13003 error ("reference to %qD is ambiguous", identifier);
13004 print_candidates (ambiguous_decls);
13005 if (cp_parser_parsing_tentatively (parser))
13006 {
13007 identifier_token->ambiguous_p = true;
13008 cp_parser_simulate_error (parser);
13009 }
13010 return error_mark_node;
13011 }
13012 }
13013 }
13014 else
13015 {
13016
13017 decl = cp_parser_template_id (parser, template_keyword_p,
13018 check_dependency_p,
13019 is_declaration);
13020 if (decl == error_mark_node)
13021 return error_mark_node;
13022 }
13023
13024 decl = cp_parser_maybe_treat_template_as_class (decl, class_head_p);
13025
13026
13027 if (typename_p && decl != error_mark_node)
13028 {
13029 decl = make_typename_type (scope, decl, typename_type,
13030 tf_error);
13031 if (decl != error_mark_node)
13032 decl = TYPE_NAME (decl);
13033 }
13034
13035
13036 if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
13037 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
13038 && cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049 {
13050 decl = make_typename_type (scope, decl, tag_type, tf_error);
13051 if (decl != error_mark_node)
13052 decl = TYPE_NAME (decl);
13053 }
13054 else if (TREE_CODE (decl) != TYPE_DECL
13055 || TREE_TYPE (decl) == error_mark_node
13056 || !IS_AGGR_TYPE (TREE_TYPE (decl)))
13057 decl = error_mark_node;
13058
13059 if (decl == error_mark_node)
13060 cp_parser_error (parser, "expected class-name");
13061
13062 return decl;
13063 }
13064
13065
13066
13067
13068
13069
13070
13071
13072 static tree
13073 cp_parser_class_specifier (cp_parser* parser)
13074 {
13075 cp_token *token;
13076 tree type;
13077 tree attributes = NULL_TREE;
13078 int has_trailing_semicolon;
13079 bool nested_name_specifier_p;
13080 unsigned saved_num_template_parameter_lists;
13081 bool saved_in_function_body;
13082 tree old_scope = NULL_TREE;
13083 tree scope = NULL_TREE;
13084 tree bases;
13085
13086 push_deferring_access_checks (dk_no_deferred);
13087
13088
13089 type = cp_parser_class_head (parser,
13090 &nested_name_specifier_p,
13091 &attributes,
13092 &bases);
13093
13094
13095 if (!type)
13096 {
13097 cp_parser_skip_to_end_of_block_or_statement (parser);
13098 pop_deferring_access_checks ();
13099 return error_mark_node;
13100 }
13101
13102
13103 if (!cp_parser_require (parser, CPP_OPEN_BRACE, "`{'"))
13104 {
13105 pop_deferring_access_checks ();
13106 return error_mark_node;
13107 }
13108
13109
13110
13111 if (!xref_basetypes (type, bases))
13112 {
13113 cp_parser_skip_to_closing_brace (parser);
13114
13115
13116
13117 cp_lexer_consume_token (parser->lexer);
13118 pop_deferring_access_checks ();
13119 return error_mark_node;
13120 }
13121
13122
13123 cp_parser_check_type_definition (parser);
13124
13125 ++parser->num_classes_being_defined;
13126
13127
13128 saved_num_template_parameter_lists
13129 = parser->num_template_parameter_lists;
13130 parser->num_template_parameter_lists = 0;
13131
13132 saved_in_function_body = parser->in_function_body;
13133 parser->in_function_body = false;
13134
13135
13136 if (nested_name_specifier_p)
13137 {
13138 scope = CP_DECL_CONTEXT (TYPE_MAIN_DECL (type));
13139 old_scope = push_inner_scope (scope);
13140 }
13141 type = begin_class_definition (type, attributes);
13142
13143 if (type == error_mark_node)
13144
13145 cp_parser_skip_to_closing_brace (parser);
13146 else
13147
13148 cp_parser_member_specification_opt (parser);
13149
13150
13151 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
13152
13153
13154 token = cp_lexer_peek_token (parser->lexer);
13155 has_trailing_semicolon = (token->type == CPP_SEMICOLON);
13156
13157 if (cp_parser_allow_gnu_extensions_p (parser))
13158 attributes = cp_parser_attributes_opt (parser);
13159 if (type != error_mark_node)
13160 type = finish_struct (type, attributes);
13161 if (nested_name_specifier_p)
13162 pop_inner_scope (old_scope, scope);
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183 if (--parser->num_classes_being_defined == 0)
13184 {
13185 tree queue_entry;
13186 tree fn;
13187 tree class_type = NULL_TREE;
13188 tree pushed_scope = NULL_TREE;
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200 for (TREE_PURPOSE (parser->unparsed_functions_queues)
13201 = nreverse (TREE_PURPOSE (parser->unparsed_functions_queues));
13202 (queue_entry = TREE_PURPOSE (parser->unparsed_functions_queues));
13203 TREE_PURPOSE (parser->unparsed_functions_queues)
13204 = TREE_CHAIN (TREE_PURPOSE (parser->unparsed_functions_queues)))
13205 {
13206 fn = TREE_VALUE (queue_entry);
13207
13208
13209 if (class_type != TREE_PURPOSE (queue_entry))
13210 {
13211 if (pushed_scope)
13212 pop_scope (pushed_scope);
13213 class_type = TREE_PURPOSE (queue_entry);
13214 pushed_scope = push_scope (class_type);
13215 }
13216
13217 maybe_begin_member_template_processing (fn);
13218
13219 cp_parser_late_parsing_default_args (parser, fn);
13220
13221 maybe_end_member_template_processing ();
13222 }
13223 if (pushed_scope)
13224 pop_scope (pushed_scope);
13225
13226 for (TREE_VALUE (parser->unparsed_functions_queues)
13227 = nreverse (TREE_VALUE (parser->unparsed_functions_queues));
13228 (queue_entry = TREE_VALUE (parser->unparsed_functions_queues));
13229 TREE_VALUE (parser->unparsed_functions_queues)
13230 = TREE_CHAIN (TREE_VALUE (parser->unparsed_functions_queues)))
13231 {
13232
13233 fn = TREE_VALUE (queue_entry);
13234
13235 cp_parser_late_parsing_for_member (parser, fn);
13236 }
13237 }
13238
13239
13240 pop_deferring_access_checks ();
13241
13242
13243 parser->in_function_body = saved_in_function_body;
13244 parser->num_template_parameter_lists
13245 = saved_num_template_parameter_lists;
13246
13247 return type;
13248 }
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274 static tree
13275 cp_parser_class_head (cp_parser* parser,
13276 bool* nested_name_specifier_p,
13277 tree *attributes_p,
13278 tree *bases)
13279 {
13280 tree nested_name_specifier;
13281 enum tag_types class_key;
13282 tree id = NULL_TREE;
13283 tree type = NULL_TREE;
13284 tree attributes;
13285 bool template_id_p = false;
13286 bool qualified_p = false;
13287 bool invalid_nested_name_p = false;
13288 bool invalid_explicit_specialization_p = false;
13289 tree pushed_scope = NULL_TREE;
13290 unsigned num_templates;
13291
13292
13293 *nested_name_specifier_p = false;
13294
13295
13296 num_templates = 0;
13297
13298
13299 class_key = cp_parser_class_key (parser);
13300 if (class_key == none_type)
13301 return error_mark_node;
13302
13303
13304 attributes = cp_parser_attributes_opt (parser);
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315 if (cp_parser_global_scope_opt (parser, false))
13316 qualified_p = true;
13317
13318 push_deferring_access_checks (dk_no_check);
13319
13320
13321
13322 nested_name_specifier
13323 = cp_parser_nested_name_specifier_opt (parser,
13324 false,
13325 false,
13326 false,
13327 false);
13328
13329
13330 if (nested_name_specifier)
13331 {
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349 cp_parser_parse_tentatively (parser);
13350 type = cp_parser_class_name (parser,
13351 false,
13352 false,
13353 class_type,
13354 false,
13355 true,
13356 false);
13357
13358 if (!cp_parser_parse_definitely (parser))
13359 {
13360 invalid_nested_name_p = true;
13361 id = cp_parser_identifier (parser);
13362 if (id == error_mark_node)
13363 id = NULL_TREE;
13364 }
13365
13366
13367 if (type == error_mark_node)
13368 nested_name_specifier = NULL_TREE;
13369
13370
13371 else
13372 {
13373 tree scope;
13374
13375 for (scope = TREE_TYPE (type);
13376 scope && TREE_CODE (scope) != NAMESPACE_DECL;
13377 scope = (TYPE_P (scope)
13378 ? TYPE_CONTEXT (scope)
13379 : DECL_CONTEXT (scope)))
13380 if (TYPE_P (scope)
13381 && CLASS_TYPE_P (scope)
13382 && CLASSTYPE_TEMPLATE_INFO (scope)
13383 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (scope))
13384 && !CLASSTYPE_TEMPLATE_SPECIALIZATION (scope))
13385 ++num_templates;
13386 }
13387 }
13388
13389 else
13390 {
13391
13392
13393 cp_parser_parse_tentatively (parser);
13394
13395 id = cp_parser_template_id (parser,
13396 false,
13397 true,
13398 true);
13399
13400 if (!cp_parser_parse_definitely (parser))
13401 {
13402 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
13403 id = cp_parser_identifier (parser);
13404 else
13405 id = NULL_TREE;
13406 }
13407 else
13408 {
13409 template_id_p = true;
13410 ++num_templates;
13411 }
13412 }
13413
13414 pop_deferring_access_checks ();
13415
13416 if (id)
13417 cp_parser_check_for_invalid_template_id (parser, id);
13418
13419
13420
13421
13422
13423 if (!cp_parser_next_token_starts_class_definition_p (parser))
13424 {
13425 cp_parser_error (parser, "expected %<{%> or %<:%>");
13426 return error_mark_node;
13427 }
13428
13429
13430
13431 cp_parser_commit_to_tentative_parse (parser);
13432
13433 if (qualified_p)
13434 cp_parser_error (parser,
13435 "global qualification of class name is invalid");
13436 else if (invalid_nested_name_p)
13437 cp_parser_error (parser,
13438 "qualified name does not name a class");
13439 else if (nested_name_specifier)
13440 {
13441 tree scope;
13442
13443
13444 if (!DECL_IMPLICIT_TYPEDEF_P (type))
13445 {
13446 error ("invalid class name in declaration of %qD", type);
13447 type = NULL_TREE;
13448 goto done;
13449 }
13450
13451
13452 scope = current_scope ();
13453
13454
13455 if (scope && !is_ancestor (scope, nested_name_specifier))
13456 {
13457 error ("declaration of %qD in %qD which does not enclose %qD",
13458 type, scope, nested_name_specifier);
13459 type = NULL_TREE;
13460 goto done;
13461 }
13462
13463
13464
13465
13466
13467
13468 if (scope == nested_name_specifier)
13469 {
13470 pedwarn ("extra qualification ignored");
13471 nested_name_specifier = NULL_TREE;
13472 num_templates = 0;
13473 }
13474 }
13475
13476
13477 if (at_namespace_scope_p ()
13478 && parser->num_template_parameter_lists == 0
13479 && template_id_p)
13480 {
13481 error ("an explicit specialization must be preceded by %<template <>%>");
13482 invalid_explicit_specialization_p = true;
13483
13484
13485 ++parser->num_template_parameter_lists;
13486 begin_specialization ();
13487 }
13488
13489
13490
13491
13492
13493 if (!cp_parser_check_template_parameters (parser, num_templates))
13494 {
13495
13496
13497 type = NULL_TREE;
13498 goto done;
13499 }
13500
13501
13502 if (template_id_p)
13503 {
13504 type = TREE_TYPE (id);
13505 type = maybe_process_partial_specialization (type);
13506 if (nested_name_specifier)
13507 pushed_scope = push_scope (nested_name_specifier);
13508 }
13509 else if (nested_name_specifier)
13510 {
13511 tree class_type;
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521 if (TREE_CODE (TREE_TYPE (type)) == TYPENAME_TYPE)
13522 {
13523 class_type = resolve_typename_type (TREE_TYPE (type),
13524 false);
13525 if (class_type != error_mark_node)
13526 type = TYPE_NAME (class_type);
13527 else
13528 {
13529 cp_parser_error (parser, "could not resolve typename type");
13530 type = error_mark_node;
13531 }
13532 }
13533
13534 maybe_process_partial_specialization (TREE_TYPE (type));
13535 class_type = current_class_type;
13536
13537 pushed_scope = push_scope (nested_name_specifier);
13538
13539 type = TYPE_MAIN_DECL (TREE_TYPE (type));
13540 if (PROCESSING_REAL_TEMPLATE_DECL_P ()
13541 && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (type)))
13542 {
13543 type = push_template_decl (type);
13544 if (type == error_mark_node)
13545 {
13546 type = NULL_TREE;
13547 goto done;
13548 }
13549 }
13550
13551 type = TREE_TYPE (type);
13552 *nested_name_specifier_p = true;
13553 }
13554 else
13555 {
13556
13557 if (!id)
13558 id = make_anon_name ();
13559 type = xref_tag (class_key, id, ts_current,
13560 parser->num_template_parameter_lists);
13561 }
13562
13563
13564
13565 if (TREE_CODE (type) == RECORD_TYPE)
13566 CLASSTYPE_DECLARED_CLASS (type) = (class_key == class_type);
13567 cp_parser_check_class_key (class_key, type);
13568
13569
13570
13571 if (type != error_mark_node && COMPLETE_TYPE_P (type))
13572 {
13573 error ("redefinition of %q#T", type);
13574 error ("previous definition of %q+#T", type);
13575 type = NULL_TREE;
13576 goto done;
13577 }
13578 else if (type == error_mark_node)
13579 type = NULL_TREE;
13580
13581
13582
13583
13584
13585
13586
13587
13588 *bases = NULL_TREE;
13589
13590
13591 if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
13592 *bases = cp_parser_base_clause (parser);
13593
13594 done:
13595
13596
13597 if (pushed_scope)
13598 pop_scope (pushed_scope);
13599
13600 if (invalid_explicit_specialization_p)
13601 {
13602 end_specialization ();
13603 --parser->num_template_parameter_lists;
13604 }
13605 *attributes_p = attributes;
13606 return type;
13607 }
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619 static enum tag_types
13620 cp_parser_class_key (cp_parser* parser)
13621 {
13622 cp_token *token;
13623 enum tag_types tag_type;
13624
13625
13626 token = cp_parser_require (parser, CPP_KEYWORD, "class-key");
13627 if (!token)
13628 return none_type;
13629
13630
13631 tag_type = cp_parser_token_is_class_key (token);
13632 if (!tag_type)
13633 cp_parser_error (parser, "expected class-key");
13634 return tag_type;
13635 }
13636
13637
13638
13639
13640
13641
13642
13643 static void
13644 cp_parser_member_specification_opt (cp_parser* parser)
13645 {
13646 while (true)
13647 {
13648 cp_token *token;
13649 enum rid keyword;
13650
13651
13652 token = cp_lexer_peek_token (parser->lexer);
13653
13654 if (token->type == CPP_CLOSE_BRACE
13655 || token->type == CPP_EOF
13656 || token->type == CPP_PRAGMA_EOL)
13657 break;
13658
13659
13660 keyword = token->keyword;
13661 switch (keyword)
13662 {
13663 case RID_PUBLIC:
13664 case RID_PROTECTED:
13665 case RID_PRIVATE:
13666
13667 cp_lexer_consume_token (parser->lexer);
13668
13669 current_access_specifier = token->u.value;
13670
13671 cp_parser_require (parser, CPP_COLON, "`:'");
13672 break;
13673
13674 default:
13675
13676 if (token->type == CPP_PRAGMA)
13677 {
13678 cp_parser_pragma (parser, pragma_external);
13679 break;
13680 }
13681
13682
13683
13684 cp_parser_member_declaration (parser);
13685 }
13686 }
13687 }
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717 static void
13718 cp_parser_member_declaration (cp_parser* parser)
13719 {
13720 cp_decl_specifier_seq decl_specifiers;
13721 tree prefix_attributes;
13722 tree decl;
13723 int declares_class_or_enum;
13724 bool friend_p;
13725 cp_token *token;
13726 int saved_pedantic;
13727
13728
13729 if (cp_parser_extension_opt (parser, &saved_pedantic))
13730 {
13731
13732 cp_parser_member_declaration (parser);
13733
13734 pedantic = saved_pedantic;
13735
13736 return;
13737 }
13738
13739
13740 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
13741 {
13742
13743
13744 if (cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_LESS
13745 && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_GREATER)
13746 cp_parser_explicit_specialization (parser);
13747 else
13748 cp_parser_template_declaration (parser, true);
13749
13750 return;
13751 }
13752
13753
13754 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_USING))
13755 {
13756
13757 cp_parser_using_declaration (parser,
13758 false);
13759 return;
13760 }
13761
13762
13763 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_DEFS))
13764 {
13765 tree ivar, member;
13766 tree ivar_chains = cp_parser_objc_defs_expression (parser);
13767 ivar = ivar_chains;
13768 while (ivar)
13769 {
13770 member = ivar;
13771 ivar = TREE_CHAIN (member);
13772 TREE_CHAIN (member) = NULL_TREE;
13773 finish_member_declaration (member);
13774 }
13775 return;
13776 }
13777
13778 if (cp_parser_using_declaration (parser, true))
13779 return;
13780
13781
13782 cp_parser_decl_specifier_seq (parser,
13783 CP_PARSER_FLAGS_OPTIONAL,
13784 &decl_specifiers,
13785 &declares_class_or_enum);
13786 prefix_attributes = decl_specifiers.attributes;
13787 decl_specifiers.attributes = NULL_TREE;
13788
13789 if (!decl_specifiers.type
13790 && cp_parser_parse_and_diagnose_invalid_type_name (parser))
13791 return;
13792
13793
13794 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
13795 {
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805 if (!decl_specifiers.any_specifiers_p)
13806 {
13807 cp_token *token = cp_lexer_peek_token (parser->lexer);
13808 if (pedantic && !token->in_system_header)
13809 pedwarn ("%Hextra %<;%>", &token->location);
13810 }
13811 else
13812 {
13813 tree type;
13814
13815
13816 friend_p = cp_parser_friend_p (&decl_specifiers);
13817
13818
13819 type = check_tag_decl (&decl_specifiers);
13820
13821
13822 if (friend_p)
13823 {
13824
13825
13826 if (!declares_class_or_enum)
13827 error ("a class-key must be used when declaring a friend");
13828
13829
13830
13831
13832
13833
13834
13835
13836 if (!type
13837 && decl_specifiers.type
13838 && TYPE_P (decl_specifiers.type))
13839 type = decl_specifiers.type;
13840 if (!type || !TYPE_P (type))
13841 error ("friend declaration does not name a class or "
13842 "function");
13843 else
13844 make_friend_class (current_class_type, type,
13845 true);
13846 }
13847
13848
13849 else if (!type || type == error_mark_node)
13850 ;
13851
13852
13853
13854 else if (ANON_AGGR_TYPE_P (type))
13855 {
13856
13857
13858 fixup_anonymous_aggr (type);
13859
13860 decl = build_decl (FIELD_DECL, NULL_TREE, type);
13861
13862 finish_member_declaration (decl);
13863 }
13864 else
13865 cp_parser_check_access_in_redeclaration (TYPE_NAME (type));
13866 }
13867 }
13868 else
13869 {
13870
13871 friend_p = cp_parser_friend_p (&decl_specifiers);
13872
13873
13874
13875 while (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
13876 {
13877 tree attributes = NULL_TREE;
13878 tree first_attribute;
13879
13880
13881 token = cp_lexer_peek_token (parser->lexer);
13882
13883
13884 if (token->type == CPP_COLON
13885 || (token->type == CPP_NAME
13886 && cp_lexer_peek_nth_token (parser->lexer, 2)->type
13887 == CPP_COLON))
13888 {
13889 tree identifier;
13890 tree width;
13891
13892
13893
13894
13895 if (cp_lexer_peek_token (parser->lexer)->type != CPP_COLON)
13896 identifier = cp_parser_identifier (parser);
13897 else
13898 identifier = NULL_TREE;
13899
13900
13901 cp_lexer_consume_token (parser->lexer);
13902
13903 width
13904 = cp_parser_constant_expression (parser,
13905 false,
13906 NULL);
13907
13908
13909 attributes = cp_parser_attributes_opt (parser);
13910
13911
13912 first_attribute = attributes;
13913
13914 attributes = chainon (prefix_attributes, attributes);
13915
13916
13917 decl = grokbitfield (identifier
13918 ? make_id_declarator (NULL_TREE,
13919 identifier,
13920 sfk_none)
13921 : NULL,
13922 &decl_specifiers,
13923 width);
13924
13925 cplus_decl_attributes (&decl, attributes, 0);
13926 }
13927 else
13928 {
13929 cp_declarator *declarator;
13930 tree initializer;
13931 tree asm_specification;
13932 int ctor_dtor_or_conv_p;
13933
13934
13935 declarator
13936 = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
13937 &ctor_dtor_or_conv_p,
13938 NULL,
13939 true);
13940
13941
13942
13943 if (declarator == cp_error_declarator)
13944 {
13945
13946 cp_parser_skip_to_end_of_statement (parser);
13947
13948
13949
13950
13951
13952 if (cp_lexer_next_token_is (parser->lexer,
13953 CPP_SEMICOLON))
13954 cp_lexer_consume_token (parser->lexer);
13955 return;
13956 }
13957
13958 if (declares_class_or_enum & 2)
13959 cp_parser_check_for_definition_in_return_type
13960 (declarator, decl_specifiers.type);
13961
13962
13963 asm_specification = cp_parser_asm_specification_opt (parser);
13964
13965 attributes = cp_parser_attributes_opt (parser);
13966
13967
13968 first_attribute = attributes;
13969
13970 attributes = chainon (prefix_attributes, attributes);
13971
13972
13973
13974
13975
13976
13977
13978
13979 if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
13980 {
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994 if (function_declarator_p (declarator))
13995 initializer = cp_parser_pure_specifier (parser);
13996 else
13997
13998 initializer = cp_parser_constant_initializer (parser);
13999 }
14000
14001 else
14002 initializer = NULL_TREE;
14003
14004
14005
14006
14007
14008
14009 if (cp_parser_token_starts_function_definition_p
14010 (cp_lexer_peek_token (parser->lexer)))
14011 {
14012
14013
14014
14015
14016
14017 if (initializer)
14018 error ("pure-specifier on function-definition");
14019 decl = cp_parser_save_member_function_body (parser,
14020 &decl_specifiers,
14021 declarator,
14022 attributes);
14023
14024 if (!friend_p)
14025 finish_member_declaration (decl);
14026
14027 token = cp_lexer_peek_token (parser->lexer);
14028
14029 if (token->type == CPP_SEMICOLON)
14030 cp_lexer_consume_token (parser->lexer);
14031 return;
14032 }
14033 else
14034
14035 decl = grokfield (declarator, &decl_specifiers,
14036 initializer, true,
14037 asm_specification,
14038 attributes);
14039 }
14040
14041
14042 while (attributes && TREE_CHAIN (attributes) != first_attribute)
14043 attributes = TREE_CHAIN (attributes);
14044 if (attributes)
14045 TREE_CHAIN (attributes) = NULL_TREE;
14046
14047
14048
14049 parser->scope = NULL_TREE;
14050 parser->qualifying_scope = NULL_TREE;
14051 parser->object_scope = NULL_TREE;
14052
14053 if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
14054 cp_lexer_consume_token (parser->lexer);
14055
14056 else if (cp_lexer_next_token_is_not (parser->lexer,
14057 CPP_SEMICOLON))
14058 {
14059 cp_parser_error (parser, "expected %<;%>");
14060
14061 cp_parser_skip_to_end_of_statement (parser);
14062
14063 break;
14064 }
14065
14066 if (decl)
14067 {
14068
14069 if (!friend_p)
14070 finish_member_declaration (decl);
14071
14072 if (TREE_CODE (decl) == FUNCTION_DECL)
14073 cp_parser_save_default_args (parser, decl);
14074 }
14075 }
14076 }
14077
14078 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
14079 }
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089 static tree
14090 cp_parser_pure_specifier (cp_parser* parser)
14091 {
14092 cp_token *token;
14093
14094
14095 if (!cp_parser_require (parser, CPP_EQ, "`='"))
14096 return error_mark_node;
14097
14098 token = cp_lexer_consume_token (parser->lexer);
14099
14100 if (token->type != CPP_NUMBER || !(token->flags & PURE_ZERO))
14101 {
14102 cp_parser_error (parser,
14103 "invalid pure specifier (only `= 0' is allowed)");
14104 cp_parser_skip_to_end_of_statement (parser);
14105 return error_mark_node;
14106 }
14107 if (PROCESSING_REAL_TEMPLATE_DECL_P ())
14108 {
14109 error ("templates may not be %<virtual%>");
14110 return error_mark_node;
14111 }
14112
14113 return integer_zero_node;
14114 }
14115
14116
14117
14118
14119
14120
14121
14122
14123 static tree
14124 cp_parser_constant_initializer (cp_parser* parser)
14125 {
14126
14127 if (!cp_parser_require (parser, CPP_EQ, "`='"))
14128 return error_mark_node;
14129
14130
14131
14132
14133
14134
14135 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
14136 {
14137 cp_parser_error (parser,
14138 "a brace-enclosed initializer is not allowed here");
14139
14140 cp_lexer_consume_token (parser->lexer);
14141
14142 cp_parser_skip_to_closing_brace (parser);
14143
14144 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
14145
14146 return error_mark_node;
14147 }
14148
14149 return cp_parser_constant_expression (parser,
14150 false,
14151 NULL);
14152 }
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172 static tree
14173 cp_parser_base_clause (cp_parser* parser)
14174 {
14175 tree bases = NULL_TREE;
14176
14177
14178 cp_parser_require (parser, CPP_COLON, "`:'");
14179
14180
14181 while (true)
14182 {
14183 cp_token *token;
14184 tree base;
14185
14186
14187 base = cp_parser_base_specifier (parser);
14188
14189 if (base != error_mark_node)
14190 {
14191 TREE_CHAIN (base) = bases;
14192 bases = base;
14193 }
14194
14195 token = cp_lexer_peek_token (parser->lexer);
14196
14197 if (token->type != CPP_COMMA)
14198 break;
14199
14200 cp_lexer_consume_token (parser->lexer);
14201 }
14202
14203
14204
14205
14206 parser->scope = NULL_TREE;
14207 parser->qualifying_scope = NULL_TREE;
14208 parser->object_scope = NULL_TREE;
14209
14210 return nreverse (bases);
14211 }
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227 static tree
14228 cp_parser_base_specifier (cp_parser* parser)
14229 {
14230 cp_token *token;
14231 bool done = false;
14232 bool virtual_p = false;
14233 bool duplicate_virtual_error_issued_p = false;
14234 bool duplicate_access_error_issued_p = false;
14235 bool class_scope_p, template_p;
14236 tree access = access_default_node;
14237 tree type;
14238
14239
14240 while (!done)
14241 {
14242
14243 token = cp_lexer_peek_token (parser->lexer);
14244
14245 switch (token->keyword)
14246 {
14247 case RID_VIRTUAL:
14248
14249 if (virtual_p && !duplicate_virtual_error_issued_p)
14250 {
14251 cp_parser_error (parser,
14252 "%<virtual%> specified more than once in base-specified");
14253 duplicate_virtual_error_issued_p = true;
14254 }
14255
14256 virtual_p = true;
14257
14258
14259 cp_lexer_consume_token (parser->lexer);
14260
14261 break;
14262
14263 case RID_PUBLIC:
14264 case RID_PROTECTED:
14265 case RID_PRIVATE:
14266
14267
14268 if (access != access_default_node
14269 && !duplicate_access_error_issued_p)
14270 {
14271 cp_parser_error (parser,
14272 "more than one access specifier in base-specified");
14273 duplicate_access_error_issued_p = true;
14274 }
14275
14276 access = ridpointers[(int) token->keyword];
14277
14278
14279 cp_lexer_consume_token (parser->lexer);
14280
14281 break;
14282
14283 default:
14284 done = true;
14285 break;
14286 }
14287 }
14288
14289
14290
14291 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME))
14292 {
14293 if (!processing_template_decl)
14294 error ("keyword %<typename%> not allowed outside of templates");
14295 else
14296 error ("keyword %<typename%> not allowed in this context "
14297 "(the base class is implicitly a type)");
14298 cp_lexer_consume_token (parser->lexer);
14299 }
14300
14301
14302 cp_parser_global_scope_opt (parser, false);
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315 cp_parser_nested_name_specifier_opt (parser,
14316 true,
14317 true,
14318 typename_type,
14319 true);
14320
14321
14322 class_scope_p = (parser->scope && TYPE_P (parser->scope));
14323 template_p = class_scope_p && cp_parser_optional_template_keyword (parser);
14324
14325
14326 type = cp_parser_class_name (parser,
14327 class_scope_p,
14328 template_p,
14329 typename_type,
14330 true,
14331 false,
14332 true);
14333
14334 if (type == error_mark_node)
14335 return error_mark_node;
14336
14337 return finish_base_specifier (TREE_TYPE (type), access, virtual_p);
14338 }
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350 static tree
14351 cp_parser_exception_specification_opt (cp_parser* parser)
14352 {
14353 cp_token *token;
14354 tree type_id_list;
14355
14356
14357 token = cp_lexer_peek_token (parser->lexer);
14358
14359 if (!cp_parser_is_keyword (token, RID_THROW))
14360 return NULL_TREE;
14361
14362
14363 cp_lexer_consume_token (parser->lexer);
14364
14365
14366 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
14367
14368
14369 token = cp_lexer_peek_token (parser->lexer);
14370
14371 if (token->type != CPP_CLOSE_PAREN)
14372 {
14373 const char *saved_message;
14374
14375
14376 saved_message = parser->type_definition_forbidden_message;
14377 parser->type_definition_forbidden_message
14378 = "types may not be defined in an exception-specification";
14379
14380 type_id_list = cp_parser_type_id_list (parser);
14381
14382 parser->type_definition_forbidden_message = saved_message;
14383 }
14384 else
14385 type_id_list = empty_except_spec;
14386
14387
14388 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
14389
14390 return type_id_list;
14391 }
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402 static tree
14403 cp_parser_type_id_list (cp_parser* parser)
14404 {
14405 tree types = NULL_TREE;
14406
14407 while (true)
14408 {
14409 cp_token *token;
14410 tree type;
14411
14412
14413 type = cp_parser_type_id (parser);
14414
14415 types = add_exception_specifier (types, type, 1);
14416
14417 token = cp_lexer_peek_token (parser->lexer);
14418
14419 if (token->type != CPP_COMMA)
14420 break;
14421
14422 cp_lexer_consume_token (parser->lexer);
14423 }
14424
14425 return nreverse (types);
14426 }
14427
14428
14429
14430
14431
14432
14433 static tree
14434 cp_parser_try_block (cp_parser* parser)
14435 {
14436 tree try_block;
14437
14438 cp_parser_require_keyword (parser, RID_TRY, "`try'");
14439 try_block = begin_try_block ();
14440 cp_parser_compound_statement (parser, NULL, true);
14441 finish_try_block (try_block);
14442 cp_parser_handler_seq (parser);
14443 finish_handler_sequence (try_block);
14444
14445 return try_block;
14446 }
14447
14448
14449
14450
14451
14452
14453 static bool
14454 cp_parser_function_try_block (cp_parser* parser)
14455 {
14456 tree compound_stmt;
14457 tree try_block;
14458 bool ctor_initializer_p;
14459
14460
14461 if (!cp_parser_require_keyword (parser, RID_TRY, "`try'"))
14462 return false;
14463
14464 try_block = begin_function_try_block (&compound_stmt);
14465
14466 ctor_initializer_p
14467 = cp_parser_ctor_initializer_opt_and_function_body (parser);
14468
14469 finish_function_try_block (try_block);
14470
14471 cp_parser_handler_seq (parser);
14472
14473 finish_function_handler_sequence (try_block, compound_stmt);
14474
14475 return ctor_initializer_p;
14476 }
14477
14478
14479
14480
14481
14482
14483 static void
14484 cp_parser_handler_seq (cp_parser* parser)
14485 {
14486 while (true)
14487 {
14488 cp_token *token;
14489
14490
14491 cp_parser_handler (parser);
14492
14493 token = cp_lexer_peek_token (parser->lexer);
14494
14495 if (!cp_parser_is_keyword (token, RID_CATCH))
14496 break;
14497 }
14498 }
14499
14500
14501
14502
14503
14504
14505 static void
14506 cp_parser_handler (cp_parser* parser)
14507 {
14508 tree handler;
14509 tree declaration;
14510
14511 cp_parser_require_keyword (parser, RID_CATCH, "`catch'");
14512 handler = begin_handler ();
14513 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
14514 declaration = cp_parser_exception_declaration (parser);
14515 finish_handler_parms (declaration, handler);
14516 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
14517 cp_parser_compound_statement (parser, NULL, false);
14518 finish_handler (handler);
14519 }
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532 static tree
14533 cp_parser_exception_declaration (cp_parser* parser)
14534 {
14535 cp_decl_specifier_seq type_specifiers;
14536 cp_declarator *declarator;
14537 const char *saved_message;
14538
14539
14540 if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
14541 {
14542
14543 cp_lexer_consume_token (parser->lexer);
14544 return NULL_TREE;
14545 }
14546
14547
14548 saved_message = parser->type_definition_forbidden_message;
14549 parser->type_definition_forbidden_message
14550 = "types may not be defined in exception-declarations";
14551
14552
14553 cp_parser_type_specifier_seq (parser, false,
14554 &type_specifiers);
14555
14556 if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
14557 declarator = NULL;
14558 else
14559 declarator = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_EITHER,
14560 NULL,
14561 NULL,
14562 false);
14563
14564
14565 parser->type_definition_forbidden_message = saved_message;
14566
14567 if (!type_specifiers.any_specifiers_p)
14568 return error_mark_node;
14569
14570 return grokdeclarator (declarator, &type_specifiers, CATCHPARM, 1, NULL);
14571 }
14572
14573
14574
14575
14576
14577
14578
14579
14580 static tree
14581 cp_parser_throw_expression (cp_parser* parser)
14582 {
14583 tree expression;
14584 cp_token* token;
14585
14586 cp_parser_require_keyword (parser, RID_THROW, "`throw'");
14587 token = cp_lexer_peek_token (parser->lexer);
14588
14589
14590 if (token->type == CPP_COMMA
14591 || token->type == CPP_SEMICOLON
14592 || token->type == CPP_CLOSE_PAREN
14593 || token->type == CPP_CLOSE_SQUARE
14594 || token->type == CPP_CLOSE_BRACE
14595 || token->type == CPP_COLON)
14596 expression = NULL_TREE;
14597 else
14598 expression = cp_parser_assignment_expression (parser,
14599 false);
14600
14601 return build_throw (expression);
14602 }
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615 static tree
14616 cp_parser_asm_specification_opt (cp_parser* parser)
14617 {
14618 cp_token *token;
14619 tree asm_specification;
14620
14621
14622 token = cp_lexer_peek_token (parser->lexer);
14623
14624
14625 if (!cp_parser_is_keyword (token, RID_ASM))
14626 return NULL_TREE;
14627
14628
14629 cp_lexer_consume_token (parser->lexer);
14630
14631 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
14632
14633
14634 asm_specification = cp_parser_string_literal (parser, false, false);
14635
14636
14637 cp_parser_require (parser, CPP_CLOSE_PAREN, "`('");
14638
14639 return asm_specification;
14640 }
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658 static tree
14659 cp_parser_asm_operand_list (cp_parser* parser)
14660 {
14661 tree asm_operands = NULL_TREE;
14662
14663 while (true)
14664 {
14665 tree string_literal;
14666 tree expression;
14667 tree name;
14668
14669 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
14670 {
14671
14672 cp_lexer_consume_token (parser->lexer);
14673
14674 name = cp_parser_identifier (parser);
14675 if (name != error_mark_node)
14676 name = build_string (IDENTIFIER_LENGTH (name),
14677 IDENTIFIER_POINTER (name));
14678
14679 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
14680 }
14681 else
14682 name = NULL_TREE;
14683
14684 string_literal = cp_parser_string_literal (parser, false, false);
14685
14686
14687 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
14688
14689 expression = cp_parser_expression (parser, false);
14690
14691 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
14692
14693
14694 asm_operands = tree_cons (build_tree_list (name, string_literal),
14695 expression,
14696 asm_operands);
14697
14698
14699 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
14700 break;
14701
14702 cp_lexer_consume_token (parser->lexer);
14703 }
14704
14705 return nreverse (asm_operands);
14706 }
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717 static tree
14718 cp_parser_asm_clobber_list (cp_parser* parser)
14719 {
14720 tree clobbers = NULL_TREE;
14721
14722 while (true)
14723 {
14724 tree string_literal;
14725
14726
14727 string_literal = cp_parser_string_literal (parser, false, false);
14728
14729 clobbers = tree_cons (NULL_TREE, string_literal, clobbers);
14730
14731
14732 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
14733 break;
14734
14735 cp_lexer_consume_token (parser->lexer);
14736 }
14737
14738 return clobbers;
14739 }
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751 static tree
14752 cp_parser_attributes_opt (cp_parser* parser)
14753 {
14754 tree attributes = NULL_TREE;
14755
14756 while (true)
14757 {
14758 cp_token *token;
14759 tree attribute_list;
14760
14761
14762 token = cp_lexer_peek_token (parser->lexer);
14763
14764 if (token->keyword != RID_ATTRIBUTE)
14765 break;
14766
14767
14768 cp_lexer_consume_token (parser->lexer);
14769
14770 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
14771 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
14772
14773
14774 token = cp_lexer_peek_token (parser->lexer);
14775 if (token->type != CPP_CLOSE_PAREN)
14776
14777 attribute_list = cp_parser_attribute_list (parser);
14778 else
14779
14780
14781 attribute_list = NULL;
14782
14783
14784 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
14785 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
14786
14787
14788 attributes = chainon (attributes, attribute_list);
14789 }
14790
14791 return attributes;
14792 }
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811 static tree
14812 cp_parser_attribute_list (cp_parser* parser)
14813 {
14814 tree attribute_list = NULL_TREE;
14815 bool save_translate_strings_p = parser->translate_strings_p;
14816
14817 parser->translate_strings_p = false;
14818 while (true)
14819 {
14820 cp_token *token;
14821 tree identifier;
14822 tree attribute;
14823
14824
14825
14826 token = cp_lexer_peek_token (parser->lexer);
14827 if (token->type == CPP_NAME
14828 || token->type == CPP_KEYWORD)
14829 {
14830 tree arguments = NULL_TREE;
14831
14832
14833 token = cp_lexer_consume_token (parser->lexer);
14834
14835
14836
14837 identifier = token->u.value;
14838 attribute = build_tree_list (identifier, NULL_TREE);
14839
14840
14841 token = cp_lexer_peek_token (parser->lexer);
14842
14843 if (token->type == CPP_OPEN_PAREN)
14844 {
14845 arguments = cp_parser_parenthesized_expression_list
14846 (parser, true, false,
14847 NULL);
14848
14849 TREE_VALUE (attribute) = arguments;
14850 }
14851
14852 if (arguments != error_mark_node)
14853 {
14854
14855 TREE_CHAIN (attribute) = attribute_list;
14856 attribute_list = attribute;
14857 }
14858
14859 token = cp_lexer_peek_token (parser->lexer);
14860 }
14861
14862
14863 if (token->type != CPP_COMMA)
14864 break;
14865
14866
14867 cp_lexer_consume_token (parser->lexer);
14868 }
14869 parser->translate_strings_p = save_translate_strings_p;
14870
14871
14872 return nreverse (attribute_list);
14873 }
14874
14875
14876
14877
14878
14879
14880
14881 static bool
14882 cp_parser_extension_opt (cp_parser* parser, int* saved_pedantic)
14883 {
14884
14885 *saved_pedantic = pedantic;
14886
14887 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_EXTENSION))
14888 {
14889
14890 cp_lexer_consume_token (parser->lexer);
14891
14892
14893 pedantic = 0;
14894
14895 return true;
14896 }
14897
14898 return false;
14899 }
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910 static void
14911 cp_parser_label_declaration (cp_parser* parser)
14912 {
14913
14914 cp_parser_require_keyword (parser, RID_LABEL, "`__label__'");
14915
14916 while (true)
14917 {
14918 tree identifier;
14919
14920
14921 identifier = cp_parser_identifier (parser);
14922
14923 if (identifier == error_mark_node)
14924 break;
14925
14926 finish_label_decl (identifier);
14927
14928 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
14929 break;
14930
14931 cp_parser_require (parser, CPP_COMMA, "`,'");
14932 }
14933
14934
14935 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
14936 }
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975 static tree
14976 cp_parser_lookup_name (cp_parser *parser, tree name,
14977 enum tag_types tag_type,
14978 bool is_template,
14979 bool is_namespace,
14980 bool check_dependency,
14981 tree *ambiguous_decls)
14982 {
14983 int flags = 0;
14984 tree decl;
14985 tree object_type = parser->context->object_type;
14986
14987 if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
14988 flags |= LOOKUP_COMPLAIN;
14989
14990
14991 if (ambiguous_decls)
14992 *ambiguous_decls = NULL_TREE;
14993
14994
14995
14996
14997 parser->context->object_type = NULL_TREE;
14998
14999 if (name == error_mark_node)
15000 return error_mark_node;
15001
15002
15003
15004 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
15005 return name;
15006 if (BASELINK_P (name))
15007 {
15008 gcc_assert (TREE_CODE (BASELINK_FUNCTIONS (name))
15009 == TEMPLATE_ID_EXPR);
15010 return name;
15011 }
15012
15013
15014
15015
15016 if (TREE_CODE (name) == BIT_NOT_EXPR)
15017 {
15018 tree type;
15019
15020
15021 if (parser->scope)
15022 type = parser->scope;
15023 else if (object_type)
15024 type = object_type;
15025 else
15026 type = current_class_type;
15027
15028 if (!type || !CLASS_TYPE_P (type))
15029 return error_mark_node;
15030 if (CLASSTYPE_LAZY_DESTRUCTOR (type))
15031 lazily_declare_fn (sfk_destructor, type);
15032 if (!CLASSTYPE_DESTRUCTORS (type))
15033 return error_mark_node;
15034
15035 return CLASSTYPE_DESTRUCTORS (type);
15036 }
15037
15038
15039
15040
15041 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
15042
15043
15044 if (parser->scope)
15045 {
15046 bool dependent_p;
15047
15048 if (parser->scope == error_mark_node)
15049 return error_mark_node;
15050
15051
15052
15053
15054
15055
15056 dependent_p = (TYPE_P (parser->scope)
15057 && !(parser->in_declarator_p
15058 && currently_open_class (parser->scope))
15059 && dependent_type_p (parser->scope));
15060 if ((check_dependency || !CLASS_TYPE_P (parser->scope))
15061 && dependent_p)
15062 {
15063 if (tag_type)
15064 {
15065 tree type;
15066
15067
15068
15069
15070 type = make_typename_type (parser->scope, name, tag_type,
15071 tf_error);
15072 decl = TYPE_NAME (type);
15073 }
15074 else if (is_template
15075 && (cp_parser_next_token_ends_template_argument_p (parser)
15076 || cp_lexer_next_token_is (parser->lexer,
15077 CPP_CLOSE_PAREN)))
15078 decl = make_unbound_class_template (parser->scope,
15079 name, NULL_TREE,
15080 tf_error);
15081 else
15082 decl = build_qualified_name (NULL_TREE,
15083 parser->scope, name,
15084 is_template);
15085 }
15086 else
15087 {
15088 tree pushed_scope = NULL_TREE;
15089
15090
15091
15092
15093
15094
15095 if (dependent_p)
15096 pushed_scope = push_scope (parser->scope);
15097
15098
15099
15100
15101 decl = lookup_qualified_name (parser->scope, name,
15102 tag_type != none_type,
15103 true);
15104 if (pushed_scope)
15105 pop_scope (pushed_scope);
15106 }
15107 parser->qualifying_scope = parser->scope;
15108 parser->object_scope = NULL_TREE;
15109 }
15110 else if (object_type)
15111 {
15112 tree object_decl = NULL_TREE;
15113
15114
15115 if (CLASS_TYPE_P (object_type))
15116
15117
15118
15119
15120 object_decl = lookup_member (object_type,
15121 name,
15122 0,
15123 tag_type != none_type);
15124
15125 decl = lookup_name_real (name, tag_type != none_type,
15126 0,
15127 true, is_namespace, flags);
15128 parser->object_scope = object_type;
15129 parser->qualifying_scope = NULL_TREE;
15130 if (object_decl)
15131 decl = object_decl;
15132 }
15133 else
15134 {
15135 decl = lookup_name_real (name, tag_type != none_type,
15136 0,
15137 true, is_namespace, flags);
15138 parser->qualifying_scope = NULL_TREE;
15139 parser->object_scope = NULL_TREE;
15140 }
15141
15142
15143 if (!decl || decl == error_mark_node)
15144 return error_mark_node;
15145
15146
15147 if (TREE_CODE (decl) == TREE_LIST)
15148 {
15149 if (ambiguous_decls)
15150 *ambiguous_decls = decl;
15151
15152
15153 if (!cp_parser_simulate_error (parser))
15154 {
15155 error ("reference to %qD is ambiguous", name);
15156 print_candidates (decl);
15157 }
15158 return error_mark_node;
15159 }
15160
15161 gcc_assert (DECL_P (decl)
15162 || TREE_CODE (decl) == OVERLOAD
15163 || TREE_CODE (decl) == SCOPE_REF
15164 || TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE
15165 || BASELINK_P (decl));
15166
15167
15168
15169
15170
15171
15172
15173
15174 if (DECL_P (decl))
15175 check_accessibility_of_qualified_id (decl, object_type, parser->scope);
15176
15177 return decl;
15178 }
15179
15180
15181
15182
15183
15184 static tree
15185 cp_parser_lookup_name_simple (cp_parser* parser, tree name)
15186 {
15187 return cp_parser_lookup_name (parser, name,
15188 none_type,
15189 false,
15190 false,
15191 true,
15192 NULL);
15193 }
15194
15195
15196
15197
15198
15199
15200
15201
15202 static tree
15203 cp_parser_maybe_treat_template_as_class (tree decl, bool tag_name_p)
15204 {
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233 if (DECL_CLASS_TEMPLATE_P (decl) && tag_name_p)
15234 return DECL_TEMPLATE_RESULT (decl);
15235
15236 return decl;
15237 }
15238
15239
15240
15241
15242
15243 static bool
15244 cp_parser_check_declarator_template_parameters (cp_parser* parser,
15245 cp_declarator *declarator)
15246 {
15247 unsigned num_templates;
15248
15249
15250 num_templates = 0;
15251
15252 switch (declarator->kind)
15253 {
15254 case cdk_id:
15255 if (declarator->u.id.qualifying_scope)
15256 {
15257 tree scope;
15258 tree member;
15259
15260 scope = declarator->u.id.qualifying_scope;
15261 member = declarator->u.id.unqualified_name;
15262
15263 while (scope && CLASS_TYPE_P (scope))
15264 {
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275 if (!CLASSTYPE_TEMPLATE_INFO (scope))
15276
15277
15278
15279 break;
15280 if (explicit_class_specialization_p (scope))
15281 break;
15282 if (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (scope)))
15283 ++num_templates;
15284
15285 scope = TYPE_CONTEXT (scope);
15286 }
15287 }
15288 else if (TREE_CODE (declarator->u.id.unqualified_name)
15289 == TEMPLATE_ID_EXPR)
15290
15291
15292 ++num_templates;
15293
15294 return cp_parser_check_template_parameters (parser,
15295 num_templates);
15296
15297 case cdk_function:
15298 case cdk_array:
15299 case cdk_pointer:
15300 case cdk_reference:
15301 case cdk_ptrmem:
15302 return (cp_parser_check_declarator_template_parameters
15303 (parser, declarator->declarator));
15304
15305 case cdk_error:
15306 return true;
15307
15308 default:
15309 gcc_unreachable ();
15310 }
15311 return false;
15312 }
15313
15314
15315
15316
15317
15318 static bool
15319 cp_parser_check_template_parameters (cp_parser* parser,
15320 unsigned num_templates)
15321 {
15322
15323
15324
15325
15326 if (parser->num_template_parameter_lists < num_templates)
15327 {
15328 error ("too few template-parameter-lists");
15329 return false;
15330 }
15331
15332
15333 if (parser->num_template_parameter_lists == num_templates)
15334 return true;
15335
15336
15337 if (parser->num_template_parameter_lists == num_templates + 1)
15338 return true;
15339
15340
15341
15342
15343 error ("too many template-parameter-lists");
15344 return false;
15345 }
15346
15347
15348
15349
15350
15351
15352
15353
15354 static tree
15355 cp_parser_global_scope_opt (cp_parser* parser, bool current_scope_valid_p)
15356 {
15357 cp_token *token;
15358
15359
15360 token = cp_lexer_peek_token (parser->lexer);
15361
15362
15363 if (token->type == CPP_SCOPE)
15364 {
15365
15366 cp_lexer_consume_token (parser->lexer);
15367
15368 parser->scope = global_namespace;
15369 parser->qualifying_scope = global_namespace;
15370 parser->object_scope = NULL_TREE;
15371
15372 return parser->scope;
15373 }
15374 else if (!current_scope_valid_p)
15375 {
15376 parser->scope = NULL_TREE;
15377 parser->qualifying_scope = NULL_TREE;
15378 parser->object_scope = NULL_TREE;
15379 }
15380
15381 return NULL_TREE;
15382 }
15383
15384
15385
15386
15387
15388 static bool
15389 cp_parser_constructor_declarator_p (cp_parser *parser, bool friend_p)
15390 {
15391 bool constructor_p;
15392 tree type_decl = NULL_TREE;
15393 bool nested_name_p;
15394 cp_token *next_token;
15395
15396
15397
15398
15399 if (parser->in_function_body)
15400 return false;
15401
15402 next_token = cp_lexer_peek_token (parser->lexer);
15403 if (next_token->type != CPP_NAME
15404 && next_token->type != CPP_SCOPE
15405 && next_token->type != CPP_NESTED_NAME_SPECIFIER
15406 && next_token->type != CPP_TEMPLATE_ID)
15407 return false;
15408
15409
15410
15411 cp_parser_parse_tentatively (parser);
15412
15413 constructor_p = true;
15414
15415
15416 cp_parser_global_scope_opt (parser,
15417 false);
15418
15419 nested_name_p
15420 = (cp_parser_nested_name_specifier_opt (parser,
15421 false,
15422 false,
15423 false,
15424 false)
15425 != NULL_TREE);
15426
15427
15428 if (!nested_name_p &&
15429 (!at_class_scope_p () || !TYPE_BEING_DEFINED (current_class_type)
15430 || friend_p))
15431 constructor_p = false;
15432
15433
15434 if (constructor_p)
15435 {
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447 type_decl = cp_parser_class_name (parser,
15448 false,
15449 false,
15450 none_type,
15451 false,
15452 false,
15453 false);
15454
15455 constructor_p = !cp_parser_error_occurred (parser);
15456 }
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468 if (constructor_p
15469 && cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
15470 {
15471 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)
15472 && cp_lexer_next_token_is_not (parser->lexer, CPP_ELLIPSIS)
15473
15474
15475
15476 && !cp_lexer_next_token_is_decl_specifier_keyword (parser->lexer))
15477 {
15478 tree type;
15479 tree pushed_scope = NULL_TREE;
15480 unsigned saved_num_template_parameter_lists;
15481
15482
15483
15484 if (current_class_type)
15485 type = NULL_TREE;
15486 else
15487 {
15488 type = TREE_TYPE (type_decl);
15489 if (TREE_CODE (type) == TYPENAME_TYPE)
15490 {
15491 type = resolve_typename_type (type,
15492 false);
15493 if (type == error_mark_node)
15494 {
15495 cp_parser_abort_tentative_parse (parser);
15496 return false;
15497 }
15498 }
15499 pushed_scope = push_scope (type);
15500 }
15501
15502
15503
15504 saved_num_template_parameter_lists
15505 = parser->num_template_parameter_lists;
15506 parser->num_template_parameter_lists = 0;
15507
15508
15509 cp_parser_type_specifier (parser,
15510 CP_PARSER_FLAGS_NONE,
15511 NULL,
15512 true,
15513 NULL,
15514 NULL);
15515
15516 parser->num_template_parameter_lists
15517 = saved_num_template_parameter_lists;
15518
15519
15520 if (pushed_scope)
15521 pop_scope (pushed_scope);
15522
15523 constructor_p = !cp_parser_error_occurred (parser);
15524 }
15525 }
15526 else
15527 constructor_p = false;
15528
15529 cp_parser_abort_tentative_parse (parser);
15530
15531 return constructor_p;
15532 }
15533
15534
15535
15536
15537
15538
15539
15540 static tree
15541 cp_parser_function_definition_from_specifiers_and_declarator
15542 (cp_parser* parser,
15543 cp_decl_specifier_seq *decl_specifiers,
15544 tree attributes,
15545 const cp_declarator *declarator)
15546 {
15547 tree fn;
15548 bool success_p;
15549
15550
15551 success_p = start_function (decl_specifiers, declarator, attributes);
15552
15553
15554
15555 reset_specialization ();
15556
15557
15558
15559
15560
15561 perform_deferred_access_checks ();
15562
15563 if (!success_p)
15564 {
15565
15566 cp_parser_skip_to_end_of_block_or_statement (parser);
15567 fn = error_mark_node;
15568 }
15569 else
15570 fn = cp_parser_function_definition_after_declarator (parser,
15571 false);
15572
15573 return fn;
15574 }
15575
15576
15577
15578
15579
15580
15581
15582 static tree
15583 cp_parser_function_definition_after_declarator (cp_parser* parser,
15584 bool inline_p)
15585 {
15586 tree fn;
15587 bool ctor_initializer_p = false;
15588 bool saved_in_unbraced_linkage_specification_p;
15589 bool saved_in_function_body;
15590 unsigned saved_num_template_parameter_lists;
15591
15592 saved_in_function_body = parser->in_function_body;
15593 parser->in_function_body = true;
15594
15595
15596
15597 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_RETURN))
15598 {
15599
15600 cp_lexer_consume_token (parser->lexer);
15601
15602
15603 cp_parser_identifier (parser);
15604
15605 error ("named return values are no longer supported");
15606
15607 while (true)
15608 {
15609 cp_token *token = cp_lexer_peek_token (parser->lexer);
15610 if (token->type == CPP_OPEN_BRACE
15611 || token->type == CPP_EOF
15612 || token->type == CPP_PRAGMA_EOL)
15613 break;
15614 cp_lexer_consume_token (parser->lexer);
15615 }
15616 }
15617
15618
15619 saved_in_unbraced_linkage_specification_p
15620 = parser->in_unbraced_linkage_specification_p;
15621 parser->in_unbraced_linkage_specification_p = false;
15622
15623
15624 saved_num_template_parameter_lists
15625 = parser->num_template_parameter_lists;
15626 parser->num_template_parameter_lists = 0;
15627
15628
15629 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY))
15630 ctor_initializer_p = cp_parser_function_try_block (parser);
15631
15632
15633 else
15634 ctor_initializer_p
15635 = cp_parser_ctor_initializer_opt_and_function_body (parser);
15636
15637
15638 fn = finish_function ((ctor_initializer_p ? 1 : 0) |
15639 (inline_p ? 2 : 0));
15640
15641 expand_or_defer_fn (fn);
15642
15643 parser->in_unbraced_linkage_specification_p
15644 = saved_in_unbraced_linkage_specification_p;
15645 parser->num_template_parameter_lists
15646 = saved_num_template_parameter_lists;
15647 parser->in_function_body = saved_in_function_body;
15648
15649 return fn;
15650 }
15651
15652
15653
15654
15655
15656 static void
15657 cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
15658 {
15659 tree decl = NULL_TREE;
15660 VEC (deferred_access_check,gc) *checks;
15661 tree parameter_list;
15662 bool friend_p = false;
15663 bool need_lang_pop;
15664
15665
15666 if (!cp_parser_require_keyword (parser, RID_TEMPLATE, "`template'"))
15667 return;
15668
15669
15670 if (!cp_parser_require (parser, CPP_LESS, "`<'"))
15671 return;
15672 if (at_class_scope_p () && current_function_decl)
15673 {
15674
15675
15676
15677 error ("invalid declaration of member template in local class");
15678 cp_parser_skip_to_end_of_block_or_statement (parser);
15679 return;
15680 }
15681
15682
15683
15684 if (current_lang_name == lang_name_c)
15685 {
15686 error ("template with C linkage");
15687
15688
15689 push_lang_context (lang_name_cplusplus);
15690 need_lang_pop = true;
15691 }
15692 else
15693 need_lang_pop = false;
15694
15695
15696
15697
15698 push_deferring_access_checks (dk_deferred);
15699
15700
15701
15702
15703 if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER))
15704 {
15705 cp_parser_error (parser, "invalid explicit specialization");
15706 begin_specialization ();
15707 parameter_list = NULL_TREE;
15708 }
15709 else
15710
15711 parameter_list = cp_parser_template_parameter_list (parser);
15712
15713
15714
15715
15716
15717 checks = get_deferred_access_checks ();
15718
15719
15720 cp_parser_skip_to_end_of_template_parameter_list (parser);
15721
15722 ++parser->num_template_parameter_lists;
15723
15724
15725 if (cp_lexer_next_token_is_keyword (parser->lexer,
15726 RID_TEMPLATE))
15727 cp_parser_template_declaration_after_export (parser, member_p);
15728 else
15729 {
15730
15731
15732 push_deferring_access_checks (dk_no_check);
15733 decl = cp_parser_single_declaration (parser,
15734 checks,
15735 member_p,
15736 &friend_p);
15737 pop_deferring_access_checks ();
15738
15739
15740
15741 if (member_p && !friend_p && decl)
15742 {
15743 if (TREE_CODE (decl) == TYPE_DECL)
15744 cp_parser_check_access_in_redeclaration (decl);
15745
15746 decl = finish_member_template_decl (decl);
15747 }
15748 else if (friend_p && decl && TREE_CODE (decl) == TYPE_DECL)
15749 make_friend_class (current_class_type, TREE_TYPE (decl),
15750 true);
15751 }
15752
15753 --parser->num_template_parameter_lists;
15754
15755 pop_deferring_access_checks ();
15756
15757
15758 finish_template_decl (parameter_list);
15759
15760
15761 if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
15762 finish_member_declaration (decl);
15763
15764
15765 if (need_lang_pop)
15766 pop_lang_context ();
15767
15768
15769
15770 if (member_p && decl
15771 && (TREE_CODE (decl) == FUNCTION_DECL
15772 || DECL_FUNCTION_TEMPLATE_P (decl)))
15773 TREE_VALUE (parser->unparsed_functions_queues)
15774 = tree_cons (NULL_TREE, decl,
15775 TREE_VALUE (parser->unparsed_functions_queues));
15776 }
15777
15778
15779
15780
15781
15782 static void
15783 cp_parser_perform_template_parameter_access_checks (VEC (deferred_access_check,gc)* checks)
15784 {
15785 ++processing_template_parmlist;
15786 perform_access_checks (checks);
15787 --processing_template_parmlist;
15788 }
15789
15790
15791
15792
15793
15794
15795
15796
15797 static tree
15798 cp_parser_single_declaration (cp_parser* parser,
15799 VEC (deferred_access_check,gc)* checks,
15800 bool member_p,
15801 bool* friend_p)
15802 {
15803 int declares_class_or_enum;
15804 tree decl = NULL_TREE;
15805 cp_decl_specifier_seq decl_specifiers;
15806 bool function_definition_p = false;
15807
15808
15809
15810 gcc_assert (innermost_scope_kind () == sk_template_parms
15811 || innermost_scope_kind () == sk_template_spec);
15812
15813
15814 push_deferring_access_checks (dk_deferred);
15815
15816
15817
15818 cp_parser_decl_specifier_seq (parser,
15819 CP_PARSER_FLAGS_OPTIONAL,
15820 &decl_specifiers,
15821 &declares_class_or_enum);
15822 if (friend_p)
15823 *friend_p = cp_parser_friend_p (&decl_specifiers);
15824
15825
15826 if (decl_specifiers.specs[(int) ds_typedef])
15827 {
15828 error ("template declaration of %qs", "typedef");
15829 decl = error_mark_node;
15830 }
15831
15832
15833
15834 stop_deferring_access_checks ();
15835
15836
15837 if (declares_class_or_enum)
15838 {
15839 if (cp_parser_declares_only_class_p (parser))
15840 {
15841 decl = shadow_tag (&decl_specifiers);
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851 if (friend_p && *friend_p
15852 && !decl
15853 && decl_specifiers.type
15854 && TYPE_P (decl_specifiers.type))
15855 decl = decl_specifiers.type;
15856
15857 if (decl && decl != error_mark_node)
15858 decl = TYPE_NAME (decl);
15859 else
15860 decl = error_mark_node;
15861
15862
15863 cp_parser_perform_template_parameter_access_checks (checks);
15864 }
15865 }
15866
15867
15868
15869
15870
15871 if (!decl
15872 && (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)
15873 || decl_specifiers.type != error_mark_node))
15874 decl = cp_parser_init_declarator (parser,
15875 &decl_specifiers,
15876 checks,
15877 true,
15878 member_p,
15879 declares_class_or_enum,
15880 &function_definition_p);
15881
15882 pop_deferring_access_checks ();
15883
15884
15885
15886 parser->scope = NULL_TREE;
15887 parser->qualifying_scope = NULL_TREE;
15888 parser->object_scope = NULL_TREE;
15889
15890 if (!function_definition_p
15891 && (decl == error_mark_node
15892 || !cp_parser_require (parser, CPP_SEMICOLON, "`;'")))
15893 cp_parser_skip_to_end_of_block_or_statement (parser);
15894
15895 return decl;
15896 }
15897
15898
15899
15900 static tree
15901 cp_parser_simple_cast_expression (cp_parser *parser)
15902 {
15903 return cp_parser_cast_expression (parser, false,
15904 false);
15905 }
15906
15907
15908
15909
15910 static tree
15911 cp_parser_functional_cast (cp_parser* parser, tree type)
15912 {
15913 tree expression_list;
15914 tree cast;
15915
15916 expression_list
15917 = cp_parser_parenthesized_expression_list (parser, false,
15918 true,
15919 NULL);
15920
15921 cast = build_functional_cast (type, expression_list);
15922
15923
15924 if (TREE_CODE (type) == TYPE_DECL)
15925 type = TREE_TYPE (type);
15926 if (cast != error_mark_node
15927 && !cast_valid_in_integral_constant_expression_p (type)
15928 && (cp_parser_non_integral_constant_expression
15929 (parser, "a call to a constructor")))
15930 return error_mark_node;
15931 return cast;
15932 }
15933
15934
15935
15936
15937
15938
15939
15940 static tree
15941 cp_parser_save_member_function_body (cp_parser* parser,
15942 cp_decl_specifier_seq *decl_specifiers,
15943 cp_declarator *declarator,
15944 tree attributes)
15945 {
15946 cp_token *first;
15947 cp_token *last;
15948 tree fn;
15949
15950
15951 fn = start_method (decl_specifiers, declarator, attributes);
15952
15953 if (fn == error_mark_node)
15954 {
15955
15956 if (cp_parser_token_starts_function_definition_p
15957 (cp_lexer_peek_token (parser->lexer)))
15958 cp_parser_skip_to_end_of_block_or_statement (parser);
15959 return error_mark_node;
15960 }
15961
15962
15963 cp_parser_save_default_args (parser, fn);
15964
15965
15966
15967 first = parser->lexer->next_token;
15968 cp_parser_cache_group (parser, CPP_CLOSE_BRACE, 0);
15969
15970 while (cp_lexer_next_token_is_keyword (parser->lexer, RID_CATCH))
15971 cp_parser_cache_group (parser, CPP_CLOSE_BRACE, 0);
15972 last = parser->lexer->next_token;
15973
15974
15975
15976 DECL_PENDING_INLINE_INFO (fn) = cp_token_cache_new (first, last);
15977 DECL_PENDING_INLINE_P (fn) = 1;
15978
15979
15980
15981 DECL_INITIALIZED_IN_CLASS_P (fn) = 1;
15982
15983
15984 finish_method (fn);
15985
15986
15987 TREE_VALUE (parser->unparsed_functions_queues)
15988 = tree_cons (NULL_TREE, fn,
15989 TREE_VALUE (parser->unparsed_functions_queues));
15990
15991 return fn;
15992 }
15993
15994
15995
15996
15997
15998 static tree
15999 cp_parser_enclosed_template_argument_list (cp_parser* parser)
16000 {
16001 tree arguments;
16002 tree saved_scope;
16003 tree saved_qualifying_scope;
16004 tree saved_object_scope;
16005 bool saved_greater_than_is_operator_p;
16006 bool saved_skip_evaluation;
16007
16008
16009
16010
16011
16012
16013 saved_greater_than_is_operator_p
16014 = parser->greater_than_is_operator_p;
16015 parser->greater_than_is_operator_p = false;
16016
16017
16018 saved_scope = parser->scope;
16019 saved_qualifying_scope = parser->qualifying_scope;
16020 saved_object_scope = parser->object_scope;
16021
16022
16023 saved_skip_evaluation = skip_evaluation;
16024 skip_evaluation = false;
16025
16026 if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER))
16027 arguments = NULL_TREE;
16028 else
16029 arguments = cp_parser_template_argument_list (parser);
16030
16031
16032 if (cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT))
16033 {
16034 if (!saved_greater_than_is_operator_p)
16035 {
16036
16037
16038
16039
16040
16041
16042 cp_token *token = cp_lexer_peek_token (parser->lexer);
16043 error ("%H%<>>%> should be %<> >%> "
16044 "within a nested template argument list",
16045 &token->location);
16046
16047
16048
16049 token->type = CPP_GREATER;
16050 }
16051 else
16052 {
16053
16054
16055
16056
16057 cp_lexer_consume_token (parser->lexer);
16058 error ("spurious %<>>%>, use %<>%> to terminate "
16059 "a template argument list");
16060 }
16061 }
16062 else
16063 cp_parser_skip_to_end_of_template_parameter_list (parser);
16064
16065 parser->greater_than_is_operator_p
16066 = saved_greater_than_is_operator_p;
16067
16068 parser->scope = saved_scope;
16069 parser->qualifying_scope = saved_qualifying_scope;
16070 parser->object_scope = saved_object_scope;
16071 skip_evaluation = saved_skip_evaluation;
16072
16073 return arguments;
16074 }
16075
16076
16077
16078
16079
16080 static void
16081 cp_parser_late_parsing_for_member (cp_parser* parser, tree member_function)
16082 {
16083
16084
16085 if (DECL_FUNCTION_TEMPLATE_P (member_function))
16086 member_function = DECL_TEMPLATE_RESULT (member_function);
16087
16088
16089
16090
16091 gcc_assert (parser->num_classes_being_defined == 0);
16092
16093
16094
16095
16096 parser->unparsed_functions_queues
16097 = tree_cons (NULL_TREE, NULL_TREE, parser->unparsed_functions_queues);
16098
16099
16100 maybe_begin_member_template_processing (member_function);
16101
16102
16103
16104 if (DECL_PENDING_INLINE_P (member_function))
16105 {
16106 tree function_scope;
16107 cp_token_cache *tokens;
16108
16109
16110 tokens = DECL_PENDING_INLINE_INFO (member_function);
16111 DECL_PENDING_INLINE_INFO (member_function) = NULL;
16112 DECL_PENDING_INLINE_P (member_function) = 0;
16113
16114
16115
16116 function_scope = current_function_decl;
16117 if (function_scope)
16118 push_function_context_to (function_scope);
16119
16120
16121
16122 cp_parser_push_lexer_for_tokens (parser, tokens);
16123
16124
16125
16126 start_preparsed_function (member_function, NULL_TREE,
16127 SF_PRE_PARSED | SF_INCLASS_INLINE);
16128
16129
16130 if (processing_template_decl)
16131 push_deferring_access_checks (dk_no_check);
16132
16133
16134 cp_parser_function_definition_after_declarator (parser,
16135 true);
16136
16137 if (processing_template_decl)
16138 pop_deferring_access_checks ();
16139
16140
16141 if (function_scope)
16142 pop_function_context_from (function_scope);
16143 cp_parser_pop_lexer (parser);
16144 }
16145
16146
16147 maybe_end_member_template_processing ();
16148
16149
16150 parser->unparsed_functions_queues
16151 = TREE_CHAIN (parser->unparsed_functions_queues);
16152 }
16153
16154
16155
16156
16157 static void
16158 cp_parser_save_default_args (cp_parser* parser, tree decl)
16159 {
16160 tree probe;
16161
16162 for (probe = TYPE_ARG_TYPES (TREE_TYPE (decl));
16163 probe;
16164 probe = TREE_CHAIN (probe))
16165 if (TREE_PURPOSE (probe))
16166 {
16167 TREE_PURPOSE (parser->unparsed_functions_queues)
16168 = tree_cons (current_class_type, decl,
16169 TREE_PURPOSE (parser->unparsed_functions_queues));
16170 break;
16171 }
16172 }
16173
16174
16175
16176
16177
16178
16179 static void
16180 cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
16181 {
16182 bool saved_local_variables_forbidden_p;
16183 tree parm;
16184
16185
16186
16187
16188
16189 parser->unparsed_functions_queues
16190 = tree_cons (NULL_TREE, NULL_TREE, parser->unparsed_functions_queues);
16191
16192
16193
16194 saved_local_variables_forbidden_p = parser->local_variables_forbidden_p;
16195 parser->local_variables_forbidden_p = true;
16196
16197 for (parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
16198 parm;
16199 parm = TREE_CHAIN (parm))
16200 {
16201 cp_token_cache *tokens;
16202 tree default_arg = TREE_PURPOSE (parm);
16203 tree parsed_arg;
16204 VEC(tree,gc) *insts;
16205 tree copy;
16206 unsigned ix;
16207
16208 if (!default_arg)
16209 continue;
16210
16211 if (TREE_CODE (default_arg) != DEFAULT_ARG)
16212
16213
16214 continue;
16215
16216
16217
16218 tokens = DEFARG_TOKENS (default_arg);
16219 cp_parser_push_lexer_for_tokens (parser, tokens);
16220
16221
16222 parsed_arg = cp_parser_assignment_expression (parser, false);
16223
16224 if (!processing_template_decl)
16225 parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg);
16226
16227 TREE_PURPOSE (parm) = parsed_arg;
16228
16229
16230 for (insts = DEFARG_INSTANTIATIONS (default_arg), ix = 0;
16231 VEC_iterate (tree, insts, ix, copy); ix++)
16232 TREE_PURPOSE (copy) = parsed_arg;
16233
16234
16235
16236
16237 if (!cp_lexer_next_token_is (parser->lexer, CPP_EOF))
16238 cp_parser_error (parser, "expected %<,%>");
16239
16240
16241 cp_parser_pop_lexer (parser);
16242 }
16243
16244
16245 check_default_args (fn);
16246
16247
16248 parser->local_variables_forbidden_p = saved_local_variables_forbidden_p;
16249
16250
16251 parser->unparsed_functions_queues
16252 = TREE_CHAIN (parser->unparsed_functions_queues);
16253 }
16254
16255
16256
16257
16258
16259
16260 static tree
16261 cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword)
16262 {
16263 static const char *format;
16264 tree expr = NULL_TREE;
16265 const char *saved_message;
16266 bool saved_integral_constant_expression_p;
16267 bool saved_non_integral_constant_expression_p;
16268
16269
16270 if (!format)
16271 format = "types may not be defined in '%s' expressions";
16272
16273
16274
16275 saved_message = parser->type_definition_forbidden_message;
16276
16277 parser->type_definition_forbidden_message
16278 = XNEWVEC (const char, strlen (format)
16279 + strlen (IDENTIFIER_POINTER (ridpointers[keyword]))
16280 + 1 );
16281 sprintf ((char *) parser->type_definition_forbidden_message,
16282 format, IDENTIFIER_POINTER (ridpointers[keyword]));
16283
16284
16285
16286 saved_integral_constant_expression_p
16287 = parser->integral_constant_expression_p;
16288 saved_non_integral_constant_expression_p
16289 = parser->non_integral_constant_expression_p;
16290 parser->integral_constant_expression_p = false;
16291
16292
16293 ++skip_evaluation;
16294
16295
16296 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
16297 {
16298 tree type;
16299 bool saved_in_type_id_in_expr_p;
16300
16301
16302
16303 cp_parser_parse_tentatively (parser);
16304
16305 cp_lexer_consume_token (parser->lexer);
16306
16307 saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
16308 parser->in_type_id_in_expr_p = true;
16309 type = cp_parser_type_id (parser);
16310 parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
16311
16312 cp_parser_require (parser, CPP_CLOSE_PAREN, "%<)%>");
16313
16314 if (cp_parser_parse_definitely (parser))
16315 {
16316 cp_decl_specifier_seq decl_specs;
16317
16318
16319 clear_decl_specs (&decl_specs);
16320 decl_specs.type = type;
16321
16322
16323 expr = grokdeclarator (NULL,
16324 &decl_specs,
16325 TYPENAME,
16326 0,
16327 NULL);
16328 }
16329 }
16330
16331
16332
16333 if (!expr)
16334 expr = cp_parser_unary_expression (parser, false,
16335 false);
16336
16337 --skip_evaluation;
16338
16339
16340 free ((char *) parser->type_definition_forbidden_message);
16341
16342 parser->type_definition_forbidden_message = saved_message;
16343 parser->integral_constant_expression_p
16344 = saved_integral_constant_expression_p;
16345 parser->non_integral_constant_expression_p
16346 = saved_non_integral_constant_expression_p;
16347
16348 return expr;
16349 }
16350
16351
16352
16353 static bool
16354 cp_parser_declares_only_class_p (cp_parser *parser)
16355 {
16356
16357
16358 return (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)
16359 || cp_lexer_next_token_is (parser->lexer, CPP_COMMA));
16360 }
16361
16362
16363
16364
16365 static void
16366 cp_parser_set_storage_class (cp_parser *parser,
16367 cp_decl_specifier_seq *decl_specs,
16368 enum rid keyword)
16369 {
16370 cp_storage_class storage_class;
16371
16372 if (parser->in_unbraced_linkage_specification_p)
16373 {
16374 error ("invalid use of %qD in linkage specification",
16375 ridpointers[keyword]);
16376 return;
16377 }
16378 else if (decl_specs->storage_class != sc_none)
16379 {
16380 decl_specs->conflicting_specifiers_p = true;
16381 return;
16382 }
16383
16384 if ((keyword == RID_EXTERN || keyword == RID_STATIC)
16385 && decl_specs->specs[(int) ds_thread])
16386 {
16387 error ("%<__thread%> before %qD", ridpointers[keyword]);
16388 decl_specs->specs[(int) ds_thread] = 0;
16389 }
16390
16391 switch (keyword)
16392 {
16393 case RID_AUTO:
16394 storage_class = sc_auto;
16395 break;
16396 case RID_REGISTER:
16397 storage_class = sc_register;
16398 break;
16399 case RID_STATIC:
16400 storage_class = sc_static;
16401 break;
16402 case RID_EXTERN:
16403 storage_class = sc_extern;
16404 break;
16405 case RID_MUTABLE:
16406 storage_class = sc_mutable;
16407 break;
16408 default:
16409 gcc_unreachable ();
16410 }
16411 decl_specs->storage_class = storage_class;
16412
16413
16414
16415
16416
16417 if (decl_specs->specs[(int)ds_typedef])
16418 decl_specs->conflicting_specifiers_p = true;
16419 }
16420
16421
16422
16423
16424
16425 static void
16426 cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs,
16427 tree type_spec,
16428 bool user_defined_p)
16429 {
16430 decl_specs->any_specifiers_p = true;
16431
16432
16433
16434
16435
16436 if (decl_specs->specs[(int) ds_typedef]
16437 && !user_defined_p
16438 && (type_spec == boolean_type_node
16439 || type_spec == wchar_type_node)
16440 && (decl_specs->type
16441 || decl_specs->specs[(int) ds_long]
16442 || decl_specs->specs[(int) ds_short]
16443 || decl_specs->specs[(int) ds_unsigned]
16444 || decl_specs->specs[(int) ds_signed]))
16445 {
16446 decl_specs->redefined_builtin_type = type_spec;
16447 if (!decl_specs->type)
16448 {
16449 decl_specs->type = type_spec;
16450 decl_specs->user_defined_type_p = false;
16451 }
16452 }
16453 else if (decl_specs->type)
16454 decl_specs->multiple_types_p = true;
16455 else
16456 {
16457 decl_specs->type = type_spec;
16458 decl_specs->user_defined_type_p = user_defined_p;
16459 decl_specs->redefined_builtin_type = NULL_TREE;
16460 }
16461 }
16462
16463
16464
16465
16466 static bool
16467 cp_parser_friend_p (const cp_decl_specifier_seq *decl_specifiers)
16468 {
16469 return decl_specifiers->specs[(int) ds_friend] != 0;
16470 }
16471
16472
16473
16474
16475
16476
16477
16478 static cp_token *
16479 cp_parser_require (cp_parser* parser,
16480 enum cpp_ttype type,
16481 const char* token_desc)
16482 {
16483 if (cp_lexer_next_token_is (parser->lexer, type))
16484 return cp_lexer_consume_token (parser->lexer);
16485 else
16486 {
16487
16488 if (!cp_parser_simulate_error (parser))
16489 {
16490 char *message = concat ("expected ", token_desc, NULL);
16491 cp_parser_error (parser, message);
16492 free (message);
16493 }
16494 return NULL;
16495 }
16496 }
16497
16498
16499
16500
16501
16502 static void
16503 cp_parser_skip_to_end_of_template_parameter_list (cp_parser* parser)
16504 {
16505
16506 unsigned level = 0;
16507
16508 unsigned nesting_depth = 0;
16509
16510
16511 if (cp_parser_require (parser, CPP_GREATER, "%<>%>"))
16512 return;
16513
16514
16515 while (true)
16516 {
16517
16518 switch (cp_lexer_peek_token (parser->lexer)->type)
16519 {
16520 case CPP_LESS:
16521 if (!nesting_depth)
16522 ++level;
16523 break;
16524
16525 case CPP_GREATER:
16526 if (!nesting_depth && level-- == 0)
16527 {
16528
16529 cp_lexer_consume_token (parser->lexer);
16530 return;
16531 }
16532 break;
16533
16534 case CPP_OPEN_PAREN:
16535 case CPP_OPEN_SQUARE:
16536 ++nesting_depth;
16537 break;
16538
16539 case CPP_CLOSE_PAREN:
16540 case CPP_CLOSE_SQUARE:
16541 if (nesting_depth-- == 0)
16542 return;
16543 break;
16544
16545 case CPP_EOF:
16546 case CPP_PRAGMA_EOL:
16547 case CPP_SEMICOLON:
16548 case CPP_OPEN_BRACE:
16549 case CPP_CLOSE_BRACE:
16550
16551 return;
16552
16553 default:
16554 break;
16555 }
16556
16557
16558 cp_lexer_consume_token (parser->lexer);
16559 }
16560 }
16561
16562
16563
16564
16565
16566
16567
16568 static cp_token *
16569 cp_parser_require_keyword (cp_parser* parser,
16570 enum rid keyword,
16571 const char* token_desc)
16572 {
16573 cp_token *token = cp_parser_require (parser, CPP_KEYWORD, token_desc);
16574
16575 if (token && token->keyword != keyword)
16576 {
16577 dyn_string_t error_msg;
16578
16579
16580 error_msg = dyn_string_new (0);
16581 dyn_string_append_cstr (error_msg, "expected ");
16582 dyn_string_append_cstr (error_msg, token_desc);
16583 cp_parser_error (parser, error_msg->s);
16584 dyn_string_delete (error_msg);
16585 return NULL;
16586 }
16587
16588 return token;
16589 }
16590
16591
16592
16593
16594 static bool
16595 cp_parser_token_starts_function_definition_p (cp_token* token)
16596 {
16597 return (
16598 token->type == CPP_OPEN_BRACE
16599
16600 || token->type == CPP_COLON
16601
16602 || token->keyword == RID_TRY
16603
16604 || token->keyword == RID_RETURN);
16605 }
16606
16607
16608
16609
16610 static bool
16611 cp_parser_next_token_starts_class_definition_p (cp_parser *parser)
16612 {
16613 cp_token *token;
16614
16615 token = cp_lexer_peek_token (parser->lexer);
16616 return (token->type == CPP_OPEN_BRACE || token->type == CPP_COLON);
16617 }
16618
16619
16620
16621
16622 static bool
16623 cp_parser_next_token_ends_template_argument_p (cp_parser *parser)
16624 {
16625 cp_token *token;
16626
16627 token = cp_lexer_peek_token (parser->lexer);
16628 return (token->type == CPP_COMMA || token->type == CPP_GREATER);
16629 }
16630
16631
16632
16633
16634 static bool
16635 cp_parser_nth_token_starts_template_argument_list_p (cp_parser * parser,
16636 size_t n)
16637 {
16638 cp_token *token;
16639
16640 token = cp_lexer_peek_nth_token (parser->lexer, n);
16641 if (token->type == CPP_LESS)
16642 return true;
16643
16644
16645
16646 if (token->type == CPP_OPEN_SQUARE && token->flags & DIGRAPH)
16647 {
16648 cp_token *token2;
16649 token2 = cp_lexer_peek_nth_token (parser->lexer, n+1);
16650 if (token2->type == CPP_COLON && !(token2->flags & PREV_WHITE))
16651 return true;
16652 }
16653 return false;
16654 }
16655
16656
16657
16658
16659 static enum tag_types
16660 cp_parser_token_is_class_key (cp_token* token)
16661 {
16662 switch (token->keyword)
16663 {
16664 case RID_CLASS:
16665 return class_type;
16666 case RID_STRUCT:
16667 return record_type;
16668 case RID_UNION:
16669 return union_type;
16670
16671 default:
16672 return none_type;
16673 }
16674 }
16675
16676
16677
16678 static void
16679 cp_parser_check_class_key (enum tag_types class_key, tree type)
16680 {
16681 if ((TREE_CODE (type) == UNION_TYPE) != (class_key == union_type))
16682 pedwarn ("%qs tag used in naming %q#T",
16683 class_key == union_type ? "union"
16684 : class_key == record_type ? "struct" : "class",
16685 type);
16686 }
16687
16688
16689
16690
16691
16692
16693 static void
16694 cp_parser_check_access_in_redeclaration (tree decl)
16695 {
16696 if (!CLASS_TYPE_P (TREE_TYPE (decl)))
16697 return;
16698
16699 if ((TREE_PRIVATE (decl)
16700 != (current_access_specifier == access_private_node))
16701 || (TREE_PROTECTED (decl)
16702 != (current_access_specifier == access_protected_node)))
16703 error ("%qD redeclared with different access", decl);
16704 }
16705
16706
16707
16708
16709
16710 static bool
16711 cp_parser_optional_template_keyword (cp_parser *parser)
16712 {
16713 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE))
16714 {
16715
16716
16717
16718 if (!processing_template_decl)
16719 {
16720 error ("%<template%> (as a disambiguator) is only allowed "
16721 "within templates");
16722
16723
16724
16725 cp_lexer_purge_token (parser->lexer);
16726 return false;
16727 }
16728 else
16729 {
16730
16731 cp_lexer_consume_token (parser->lexer);
16732 return true;
16733 }
16734 }
16735
16736 return false;
16737 }
16738
16739
16740
16741
16742 static void
16743 cp_parser_pre_parsed_nested_name_specifier (cp_parser *parser)
16744 {
16745 int i;
16746 struct tree_check *check_value;
16747 deferred_access_check *chk;
16748 VEC (deferred_access_check,gc) *checks;
16749
16750
16751 check_value = cp_lexer_consume_token (parser->lexer)->u.tree_check_value;
16752
16753 checks = check_value->checks;
16754 if (checks)
16755 {
16756 for (i = 0 ;
16757 VEC_iterate (deferred_access_check, checks, i, chk) ;
16758 ++i)
16759 {
16760 perform_or_defer_access_check (chk->binfo,
16761 chk->decl,
16762 chk->diag_decl);
16763 }
16764 }
16765
16766 parser->scope = check_value->value;
16767 parser->qualifying_scope = check_value->qualifying_scope;
16768 parser->object_scope = NULL_TREE;
16769 }
16770
16771
16772
16773 static void
16774 cp_parser_cache_group (cp_parser *parser,
16775 enum cpp_ttype end,
16776 unsigned depth)
16777 {
16778 while (true)
16779 {
16780 cp_token *token;
16781
16782
16783 if ((end == CPP_CLOSE_PAREN || depth == 0)
16784 && cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
16785 return;
16786
16787 if (cp_lexer_next_token_is (parser->lexer, CPP_EOF)
16788 || (end != CPP_PRAGMA_EOL
16789 && cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA_EOL)))
16790 return;
16791
16792 token = cp_lexer_consume_token (parser->lexer);
16793
16794 if (token->type == CPP_OPEN_BRACE)
16795 {
16796 cp_parser_cache_group (parser, CPP_CLOSE_BRACE, depth + 1);
16797 if (depth == 0)
16798 return;
16799 }
16800 else if (token->type == CPP_OPEN_PAREN)
16801 cp_parser_cache_group (parser, CPP_CLOSE_PAREN, depth + 1);
16802 else if (token->type == CPP_PRAGMA)
16803 cp_parser_cache_group (parser, CPP_PRAGMA_EOL, depth + 1);
16804 else if (token->type == end)
16805 return;
16806 }
16807 }
16808
16809
16810
16811
16812
16813 static void
16814 cp_parser_parse_tentatively (cp_parser* parser)
16815 {
16816
16817 parser->context = cp_parser_context_new (parser->context);
16818
16819 cp_lexer_save_tokens (parser->lexer);
16820
16821
16822
16823 push_deferring_access_checks (dk_deferred);
16824 }
16825
16826
16827
16828 static void
16829 cp_parser_commit_to_tentative_parse (cp_parser* parser)
16830 {
16831 cp_parser_context *context;
16832 cp_lexer *lexer;
16833
16834
16835 lexer = parser->lexer;
16836 for (context = parser->context; context->next; context = context->next)
16837 {
16838 if (context->status == CP_PARSER_STATUS_KIND_COMMITTED)
16839 break;
16840 context->status = CP_PARSER_STATUS_KIND_COMMITTED;
16841 while (!cp_lexer_saving_tokens (lexer))
16842 lexer = lexer->next;
16843 cp_lexer_commit_tokens (lexer);
16844 }
16845 }
16846
16847
16848
16849
16850 static void
16851 cp_parser_abort_tentative_parse (cp_parser* parser)
16852 {
16853 cp_parser_simulate_error (parser);
16854
16855
16856 cp_parser_parse_definitely (parser);
16857 }
16858
16859
16860
16861
16862
16863 static bool
16864 cp_parser_parse_definitely (cp_parser* parser)
16865 {
16866 bool error_occurred;
16867 cp_parser_context *context;
16868
16869
16870
16871 error_occurred = cp_parser_error_occurred (parser);
16872
16873 context = parser->context;
16874 parser->context = context->next;
16875
16876 if (!error_occurred)
16877 {
16878
16879
16880 if (context->status != CP_PARSER_STATUS_KIND_COMMITTED)
16881 cp_lexer_commit_tokens (parser->lexer);
16882
16883 pop_to_parent_deferring_access_checks ();
16884 }
16885
16886
16887 else
16888 {
16889 cp_lexer_rollback_tokens (parser->lexer);
16890 pop_deferring_access_checks ();
16891 }
16892
16893 context->next = cp_parser_context_free_list;
16894 cp_parser_context_free_list = context;
16895
16896 return !error_occurred;
16897 }
16898
16899
16900
16901
16902 static bool
16903 cp_parser_uncommitted_to_tentative_parse_p (cp_parser* parser)
16904 {
16905 return (cp_parser_parsing_tentatively (parser)
16906 && parser->context->status != CP_PARSER_STATUS_KIND_COMMITTED);
16907 }
16908
16909
16910
16911
16912 static bool
16913 cp_parser_error_occurred (cp_parser* parser)
16914 {
16915 return (cp_parser_parsing_tentatively (parser)
16916 && parser->context->status == CP_PARSER_STATUS_KIND_ERROR);
16917 }
16918
16919
16920
16921 static bool
16922 cp_parser_allow_gnu_extensions_p (cp_parser* parser)
16923 {
16924 return parser->allow_gnu_extensions_p;
16925 }
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942 static tree
16943 cp_parser_objc_expression (cp_parser* parser)
16944 {
16945
16946 cp_token *kwd = cp_lexer_peek_token (parser->lexer);
16947
16948 switch (kwd->type)
16949 {
16950 case CPP_OPEN_SQUARE:
16951 return cp_parser_objc_message_expression (parser);
16952
16953 case CPP_OBJC_STRING:
16954 kwd = cp_lexer_consume_token (parser->lexer);
16955 return objc_build_string_object (kwd->u.value);
16956
16957 case CPP_KEYWORD:
16958 switch (kwd->keyword)
16959 {
16960 case RID_AT_ENCODE:
16961 return cp_parser_objc_encode_expression (parser);
16962
16963 case RID_AT_PROTOCOL:
16964 return cp_parser_objc_protocol_expression (parser);
16965
16966 case RID_AT_SELECTOR:
16967 return cp_parser_objc_selector_expression (parser);
16968
16969 default:
16970 break;
16971 }
16972 default:
16973 error ("misplaced %<@%D%> Objective-C++ construct", kwd->u.value);
16974 cp_parser_skip_to_end_of_block_or_statement (parser);
16975 }
16976
16977 return error_mark_node;
16978 }
16979
16980
16981
16982
16983
16984
16985
16986
16987 static tree
16988 cp_parser_objc_message_expression (cp_parser* parser)
16989 {
16990 tree receiver, messageargs;
16991
16992 cp_lexer_consume_token (parser->lexer);
16993 receiver = cp_parser_objc_message_receiver (parser);
16994 messageargs = cp_parser_objc_message_args (parser);
16995 cp_parser_require (parser, CPP_CLOSE_SQUARE, "`]'");
16996
16997 return objc_build_message_expr (build_tree_list (receiver, messageargs));
16998 }
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008 static tree
17009 cp_parser_objc_message_receiver (cp_parser* parser)
17010 {
17011 tree rcv;
17012
17013
17014
17015 cp_parser_parse_tentatively (parser);
17016 rcv = cp_parser_expression (parser, false);
17017
17018 if (cp_parser_parse_definitely (parser))
17019 return rcv;
17020
17021 rcv = cp_parser_simple_type_specifier (parser,
17022 NULL,
17023 CP_PARSER_FLAGS_NONE);
17024
17025 return objc_get_class_reference (rcv);
17026 }
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047 static tree
17048 cp_parser_objc_message_args (cp_parser* parser)
17049 {
17050 tree sel_args = NULL_TREE, addl_args = NULL_TREE;
17051 bool maybe_unary_selector_p = true;
17052 cp_token *token = cp_lexer_peek_token (parser->lexer);
17053
17054 while (cp_parser_objc_selector_p (token->type) || token->type == CPP_COLON)
17055 {
17056 tree selector = NULL_TREE, arg;
17057
17058 if (token->type != CPP_COLON)
17059 selector = cp_parser_objc_selector (parser);
17060
17061
17062 if (maybe_unary_selector_p
17063 && cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
17064 return build_tree_list (selector, NULL_TREE);
17065
17066 maybe_unary_selector_p = false;
17067 cp_parser_require (parser, CPP_COLON, "`:'");
17068 arg = cp_parser_assignment_expression (parser, false);
17069
17070 sel_args
17071 = chainon (sel_args,
17072 build_tree_list (selector, arg));
17073
17074 token = cp_lexer_peek_token (parser->lexer);
17075 }
17076
17077
17078 while (token->type == CPP_COMMA)
17079 {
17080 tree arg;
17081
17082 cp_lexer_consume_token (parser->lexer);
17083 arg = cp_parser_assignment_expression (parser, false);
17084
17085 addl_args
17086 = chainon (addl_args,
17087 build_tree_list (NULL_TREE, arg));
17088
17089 token = cp_lexer_peek_token (parser->lexer);
17090 }
17091
17092 return build_tree_list (sel_args, addl_args);
17093 }
17094
17095
17096
17097
17098
17099
17100
17101
17102 static tree
17103 cp_parser_objc_encode_expression (cp_parser* parser)
17104 {
17105 tree type;
17106
17107 cp_lexer_consume_token (parser->lexer);
17108 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
17109 type = complete_type (cp_parser_type_id (parser));
17110 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17111
17112 if (!type)
17113 {
17114 error ("%<@encode%> must specify a type as an argument");
17115 return error_mark_node;
17116 }
17117
17118 return objc_build_encode_expr (type);
17119 }
17120
17121
17122
17123 static tree
17124 cp_parser_objc_defs_expression (cp_parser *parser)
17125 {
17126 tree name;
17127
17128 cp_lexer_consume_token (parser->lexer);
17129 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
17130 name = cp_parser_identifier (parser);
17131 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17132
17133 return objc_get_class_ivars (name);
17134 }
17135
17136
17137
17138
17139
17140
17141
17142
17143 static tree
17144 cp_parser_objc_protocol_expression (cp_parser* parser)
17145 {
17146 tree proto;
17147
17148 cp_lexer_consume_token (parser->lexer);
17149 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
17150 proto = cp_parser_identifier (parser);
17151 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17152
17153 return objc_build_protocol_expr (proto);
17154 }
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171 static tree
17172 cp_parser_objc_selector_expression (cp_parser* parser)
17173 {
17174 tree sel_seq = NULL_TREE;
17175 bool maybe_unary_selector_p = true;
17176 cp_token *token;
17177
17178 cp_lexer_consume_token (parser->lexer);
17179 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
17180 token = cp_lexer_peek_token (parser->lexer);
17181
17182 while (cp_parser_objc_selector_p (token->type) || token->type == CPP_COLON
17183 || token->type == CPP_SCOPE)
17184 {
17185 tree selector = NULL_TREE;
17186
17187 if (token->type != CPP_COLON
17188 || token->type == CPP_SCOPE)
17189 selector = cp_parser_objc_selector (parser);
17190
17191 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON)
17192 && cp_lexer_next_token_is_not (parser->lexer, CPP_SCOPE))
17193 {
17194
17195 if (maybe_unary_selector_p)
17196 {
17197 sel_seq = selector;
17198 goto finish_selector;
17199 }
17200 else
17201 {
17202 cp_parser_error (parser, "expected %<:%>");
17203 }
17204 }
17205 maybe_unary_selector_p = false;
17206 token = cp_lexer_consume_token (parser->lexer);
17207
17208 if (token->type == CPP_SCOPE)
17209 {
17210 sel_seq
17211 = chainon (sel_seq,
17212 build_tree_list (selector, NULL_TREE));
17213 sel_seq
17214 = chainon (sel_seq,
17215 build_tree_list (NULL_TREE, NULL_TREE));
17216 }
17217 else
17218 sel_seq
17219 = chainon (sel_seq,
17220 build_tree_list (selector, NULL_TREE));
17221
17222 token = cp_lexer_peek_token (parser->lexer);
17223 }
17224
17225 finish_selector:
17226 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17227
17228 return objc_build_selector_expr (sel_seq);
17229 }
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239 static tree
17240 cp_parser_objc_identifier_list (cp_parser* parser)
17241 {
17242 tree list = build_tree_list (NULL_TREE, cp_parser_identifier (parser));
17243 cp_token *sep = cp_lexer_peek_token (parser->lexer);
17244
17245 while (sep->type == CPP_COMMA)
17246 {
17247 cp_lexer_consume_token (parser->lexer);
17248 list = chainon (list,
17249 build_tree_list (NULL_TREE,
17250 cp_parser_identifier (parser)));
17251 sep = cp_lexer_peek_token (parser->lexer);
17252 }
17253
17254 return list;
17255 }
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265 static void
17266 cp_parser_objc_alias_declaration (cp_parser* parser)
17267 {
17268 tree alias, orig;
17269
17270 cp_lexer_consume_token (parser->lexer);
17271 alias = cp_parser_identifier (parser);
17272 orig = cp_parser_identifier (parser);
17273 objc_declare_alias (alias, orig);
17274 cp_parser_consume_semicolon_at_end_of_statement (parser);
17275 }
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285 static void
17286 cp_parser_objc_class_declaration (cp_parser* parser)
17287 {
17288 cp_lexer_consume_token (parser->lexer);
17289 objc_declare_class (cp_parser_objc_identifier_list (parser));
17290 cp_parser_consume_semicolon_at_end_of_statement (parser);
17291 }
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303 static tree
17304 cp_parser_objc_protocol_refs_opt (cp_parser* parser)
17305 {
17306 tree protorefs = NULL_TREE;
17307
17308 if(cp_lexer_next_token_is (parser->lexer, CPP_LESS))
17309 {
17310 cp_lexer_consume_token (parser->lexer);
17311 protorefs = cp_parser_objc_identifier_list (parser);
17312 cp_parser_require (parser, CPP_GREATER, "`>'");
17313 }
17314
17315 return protorefs;
17316 }
17317
17318
17319
17320 static void
17321 cp_parser_objc_visibility_spec (cp_parser* parser)
17322 {
17323 cp_token *vis = cp_lexer_peek_token (parser->lexer);
17324
17325 switch (vis->keyword)
17326 {
17327 case RID_AT_PRIVATE:
17328 objc_set_visibility (2);
17329 break;
17330 case RID_AT_PROTECTED:
17331 objc_set_visibility (0);
17332 break;
17333 case RID_AT_PUBLIC:
17334 objc_set_visibility (1);
17335 break;
17336 default:
17337 return;
17338 }
17339
17340
17341 cp_lexer_consume_token (parser->lexer);
17342 }
17343
17344
17345
17346 static void
17347 cp_parser_objc_method_type (cp_parser* parser)
17348 {
17349 objc_set_method_type
17350 (cp_lexer_consume_token (parser->lexer)->type == CPP_PLUS
17351 ? PLUS_EXPR
17352 : MINUS_EXPR);
17353 }
17354
17355
17356
17357 static tree
17358 cp_parser_objc_protocol_qualifiers (cp_parser* parser)
17359 {
17360 tree quals = NULL_TREE, node;
17361 cp_token *token = cp_lexer_peek_token (parser->lexer);
17362
17363 node = token->u.value;
17364
17365 while (node && TREE_CODE (node) == IDENTIFIER_NODE
17366 && (node == ridpointers [(int) RID_IN]
17367 || node == ridpointers [(int) RID_OUT]
17368 || node == ridpointers [(int) RID_INOUT]
17369 || node == ridpointers [(int) RID_BYCOPY]
17370 || node == ridpointers [(int) RID_BYREF]
17371 || node == ridpointers [(int) RID_ONEWAY]))
17372 {
17373 quals = tree_cons (NULL_TREE, node, quals);
17374 cp_lexer_consume_token (parser->lexer);
17375 token = cp_lexer_peek_token (parser->lexer);
17376 node = token->u.value;
17377 }
17378
17379 return quals;
17380 }
17381
17382
17383
17384 static tree
17385 cp_parser_objc_typename (cp_parser* parser)
17386 {
17387 tree typename = NULL_TREE;
17388
17389 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
17390 {
17391 tree proto_quals, cp_type = NULL_TREE;
17392
17393 cp_lexer_consume_token (parser->lexer);
17394 proto_quals = cp_parser_objc_protocol_qualifiers (parser);
17395
17396
17397
17398 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
17399 cp_type = cp_parser_type_id (parser);
17400
17401 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17402 typename = build_tree_list (proto_quals, cp_type);
17403 }
17404
17405 return typename;
17406 }
17407
17408
17409
17410 static bool
17411 cp_parser_objc_selector_p (enum cpp_ttype type)
17412 {
17413 return (type == CPP_NAME || type == CPP_KEYWORD
17414 || type == CPP_AND_AND || type == CPP_AND_EQ || type == CPP_AND
17415 || type == CPP_OR || type == CPP_COMPL || type == CPP_NOT
17416 || type == CPP_NOT_EQ || type == CPP_OR_OR || type == CPP_OR_EQ
17417 || type == CPP_XOR || type == CPP_XOR_EQ);
17418 }
17419
17420
17421
17422 static tree
17423 cp_parser_objc_selector (cp_parser* parser)
17424 {
17425 cp_token *token = cp_lexer_consume_token (parser->lexer);
17426
17427 if (!cp_parser_objc_selector_p (token->type))
17428 {
17429 error ("invalid Objective-C++ selector name");
17430 return error_mark_node;
17431 }
17432
17433
17434 switch (token->type)
17435 {
17436 case CPP_AND_AND: return get_identifier ("and");
17437 case CPP_AND_EQ: return get_identifier ("and_eq");
17438 case CPP_AND: return get_identifier ("bitand");
17439 case CPP_OR: return get_identifier ("bitor");
17440 case CPP_COMPL: return get_identifier ("compl");
17441 case CPP_NOT: return get_identifier ("not");
17442 case CPP_NOT_EQ: return get_identifier ("not_eq");
17443 case CPP_OR_OR: return get_identifier ("or");
17444 case CPP_OR_EQ: return get_identifier ("or_eq");
17445 case CPP_XOR: return get_identifier ("xor");
17446 case CPP_XOR_EQ: return get_identifier ("xor_eq");
17447 default: return token->u.value;
17448 }
17449 }
17450
17451
17452
17453 static tree
17454 cp_parser_objc_method_keyword_params (cp_parser* parser)
17455 {
17456 tree params = NULL_TREE;
17457 bool maybe_unary_selector_p = true;
17458 cp_token *token = cp_lexer_peek_token (parser->lexer);
17459
17460 while (cp_parser_objc_selector_p (token->type) || token->type == CPP_COLON)
17461 {
17462 tree selector = NULL_TREE, typename, identifier;
17463
17464 if (token->type != CPP_COLON)
17465 selector = cp_parser_objc_selector (parser);
17466
17467
17468 if (maybe_unary_selector_p
17469 && cp_lexer_next_token_is_not (parser->lexer, CPP_COLON))
17470 return selector;
17471
17472 maybe_unary_selector_p = false;
17473 cp_parser_require (parser, CPP_COLON, "`:'");
17474 typename = cp_parser_objc_typename (parser);
17475 identifier = cp_parser_identifier (parser);
17476
17477 params
17478 = chainon (params,
17479 objc_build_keyword_decl (selector,
17480 typename,
17481 identifier));
17482
17483 token = cp_lexer_peek_token (parser->lexer);
17484 }
17485
17486 return params;
17487 }
17488
17489
17490
17491 static tree
17492 cp_parser_objc_method_tail_params_opt (cp_parser* parser, bool *ellipsisp)
17493 {
17494 tree params = make_node (TREE_LIST);
17495 cp_token *token = cp_lexer_peek_token (parser->lexer);
17496 *ellipsisp = false;
17497
17498 while (token->type == CPP_COMMA)
17499 {
17500 cp_parameter_declarator *parmdecl;
17501 tree parm;
17502
17503 cp_lexer_consume_token (parser->lexer);
17504 token = cp_lexer_peek_token (parser->lexer);
17505
17506 if (token->type == CPP_ELLIPSIS)
17507 {
17508 cp_lexer_consume_token (parser->lexer);
17509 *ellipsisp = true;
17510 break;
17511 }
17512
17513 parmdecl = cp_parser_parameter_declaration (parser, false, NULL);
17514 parm = grokdeclarator (parmdecl->declarator,
17515 &parmdecl->decl_specifiers,
17516 PARM, 0,
17517 NULL);
17518
17519 chainon (params, build_tree_list (NULL_TREE, parm));
17520 token = cp_lexer_peek_token (parser->lexer);
17521 }
17522
17523 return params;
17524 }
17525
17526
17527
17528 static void
17529 cp_parser_objc_interstitial_code (cp_parser* parser)
17530 {
17531 cp_token *token = cp_lexer_peek_token (parser->lexer);
17532
17533
17534
17535 if (token->keyword == RID_EXTERN
17536 && cp_parser_is_string_literal (cp_lexer_peek_nth_token (parser->lexer, 2)))
17537 cp_parser_linkage_specification (parser);
17538
17539 else if (token->type == CPP_PRAGMA)
17540 cp_parser_pragma (parser, pragma_external);
17541
17542 else if (token->type == CPP_SEMICOLON)
17543 cp_lexer_consume_token (parser->lexer);
17544
17545 else
17546 cp_parser_block_declaration (parser, false);
17547 }
17548
17549
17550
17551 static tree
17552 cp_parser_objc_method_signature (cp_parser* parser)
17553 {
17554 tree rettype, kwdparms, optparms;
17555 bool ellipsis = false;
17556
17557 cp_parser_objc_method_type (parser);
17558 rettype = cp_parser_objc_typename (parser);
17559 kwdparms = cp_parser_objc_method_keyword_params (parser);
17560 optparms = cp_parser_objc_method_tail_params_opt (parser, &ellipsis);
17561
17562 return objc_build_method_signature (rettype, kwdparms, optparms, ellipsis);
17563 }
17564
17565
17566
17567 static void
17568 cp_parser_objc_method_prototype_list (cp_parser* parser)
17569 {
17570 cp_token *token = cp_lexer_peek_token (parser->lexer);
17571
17572 while (token->keyword != RID_AT_END)
17573 {
17574 if (token->type == CPP_PLUS || token->type == CPP_MINUS)
17575 {
17576 objc_add_method_declaration
17577 (cp_parser_objc_method_signature (parser));
17578 cp_parser_consume_semicolon_at_end_of_statement (parser);
17579 }
17580 else
17581
17582 cp_parser_objc_interstitial_code (parser);
17583
17584 token = cp_lexer_peek_token (parser->lexer);
17585 }
17586
17587 cp_lexer_consume_token (parser->lexer);
17588 objc_finish_interface ();
17589 }
17590
17591
17592
17593 static void
17594 cp_parser_objc_method_definition_list (cp_parser* parser)
17595 {
17596 cp_token *token = cp_lexer_peek_token (parser->lexer);
17597
17598 while (token->keyword != RID_AT_END)
17599 {
17600 tree meth;
17601
17602 if (token->type == CPP_PLUS || token->type == CPP_MINUS)
17603 {
17604 push_deferring_access_checks (dk_deferred);
17605 objc_start_method_definition
17606 (cp_parser_objc_method_signature (parser));
17607
17608
17609 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
17610 cp_lexer_consume_token (parser->lexer);
17611
17612 perform_deferred_access_checks ();
17613 stop_deferring_access_checks ();
17614 meth = cp_parser_function_definition_after_declarator (parser,
17615 false);
17616 pop_deferring_access_checks ();
17617 objc_finish_method_definition (meth);
17618 }
17619 else
17620
17621 cp_parser_objc_interstitial_code (parser);
17622
17623 token = cp_lexer_peek_token (parser->lexer);
17624 }
17625
17626 cp_lexer_consume_token (parser->lexer);
17627 objc_finish_implementation ();
17628 }
17629
17630
17631
17632 static void
17633 cp_parser_objc_class_ivars (cp_parser* parser)
17634 {
17635 cp_token *token = cp_lexer_peek_token (parser->lexer);
17636
17637 if (token->type != CPP_OPEN_BRACE)
17638 return;
17639
17640 cp_lexer_consume_token (parser->lexer);
17641 token = cp_lexer_peek_token (parser->lexer);
17642
17643 while (token->type != CPP_CLOSE_BRACE)
17644 {
17645 cp_decl_specifier_seq declspecs;
17646 int decl_class_or_enum_p;
17647 tree prefix_attributes;
17648
17649 cp_parser_objc_visibility_spec (parser);
17650
17651 if (cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_BRACE))
17652 break;
17653
17654 cp_parser_decl_specifier_seq (parser,
17655 CP_PARSER_FLAGS_OPTIONAL,
17656 &declspecs,
17657 &decl_class_or_enum_p);
17658 prefix_attributes = declspecs.attributes;
17659 declspecs.attributes = NULL_TREE;
17660
17661
17662
17663 while (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
17664 {
17665 tree width = NULL_TREE, attributes, first_attribute, decl;
17666 cp_declarator *declarator = NULL;
17667 int ctor_dtor_or_conv_p;
17668
17669
17670 token = cp_lexer_peek_token (parser->lexer);
17671 if (token->type == CPP_COLON)
17672 goto eat_colon;
17673
17674 if (token->type == CPP_NAME
17675 && (cp_lexer_peek_nth_token (parser->lexer, 2)->type
17676 == CPP_COLON))
17677 {
17678
17679 declarator = make_id_declarator (NULL_TREE,
17680 cp_parser_identifier (parser),
17681 sfk_none);
17682
17683 eat_colon:
17684 cp_lexer_consume_token (parser->lexer);
17685
17686 width
17687 = cp_parser_constant_expression (parser,
17688 false,
17689 NULL);
17690 }
17691 else
17692 {
17693
17694 declarator
17695 = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
17696 &ctor_dtor_or_conv_p,
17697 NULL,
17698 false);
17699 }
17700
17701
17702 attributes = cp_parser_attributes_opt (parser);
17703
17704
17705 first_attribute = attributes;
17706
17707 attributes = chainon (prefix_attributes, attributes);
17708
17709 if (width)
17710 {
17711
17712 decl = grokbitfield (declarator, &declspecs, width);
17713 cplus_decl_attributes (&decl, attributes, 0);
17714 }
17715 else
17716 decl = grokfield (declarator, &declspecs,
17717 NULL_TREE, false,
17718 NULL_TREE, attributes);
17719
17720
17721 objc_add_instance_variable (decl);
17722
17723
17724 while (attributes && TREE_CHAIN (attributes) != first_attribute)
17725 attributes = TREE_CHAIN (attributes);
17726 if (attributes)
17727 TREE_CHAIN (attributes) = NULL_TREE;
17728
17729 token = cp_lexer_peek_token (parser->lexer);
17730
17731 if (token->type == CPP_COMMA)
17732 {
17733 cp_lexer_consume_token (parser->lexer);
17734 continue;
17735 }
17736 break;
17737 }
17738
17739 cp_parser_consume_semicolon_at_end_of_statement (parser);
17740 token = cp_lexer_peek_token (parser->lexer);
17741 }
17742
17743 cp_lexer_consume_token (parser->lexer);
17744
17745 if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
17746 cp_lexer_consume_token (parser->lexer);
17747 }
17748
17749
17750
17751 static void
17752 cp_parser_objc_protocol_declaration (cp_parser* parser)
17753 {
17754 tree proto, protorefs;
17755 cp_token *tok;
17756
17757 cp_lexer_consume_token (parser->lexer);
17758 if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME))
17759 {
17760 error ("identifier expected after %<@protocol%>");
17761 goto finish;
17762 }
17763
17764
17765 tok = cp_lexer_peek_nth_token (parser->lexer, 2);
17766
17767
17768 if (tok->type == CPP_COMMA || tok->type == CPP_SEMICOLON)
17769 {
17770 objc_declare_protocols (cp_parser_objc_identifier_list (parser));
17771 finish:
17772 cp_parser_consume_semicolon_at_end_of_statement (parser);
17773 }
17774
17775
17776 else
17777 {
17778 proto = cp_parser_identifier (parser);
17779 protorefs = cp_parser_objc_protocol_refs_opt (parser);
17780 objc_start_protocol (proto, protorefs);
17781 cp_parser_objc_method_prototype_list (parser);
17782 }
17783 }
17784
17785
17786
17787 static void
17788 cp_parser_objc_superclass_or_category (cp_parser *parser, tree *super,
17789 tree *categ)
17790 {
17791 cp_token *next = cp_lexer_peek_token (parser->lexer);
17792
17793 *super = *categ = NULL_TREE;
17794 if (next->type == CPP_COLON)
17795 {
17796 cp_lexer_consume_token (parser->lexer);
17797 *super = cp_parser_identifier (parser);
17798 }
17799 else if (next->type == CPP_OPEN_PAREN)
17800 {
17801 cp_lexer_consume_token (parser->lexer);
17802 *categ = cp_parser_identifier (parser);
17803 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17804 }
17805 }
17806
17807
17808
17809 static void
17810 cp_parser_objc_class_interface (cp_parser* parser)
17811 {
17812 tree name, super, categ, protos;
17813
17814 cp_lexer_consume_token (parser->lexer);
17815 name = cp_parser_identifier (parser);
17816 cp_parser_objc_superclass_or_category (parser, &super, &categ);
17817 protos = cp_parser_objc_protocol_refs_opt (parser);
17818
17819
17820 if (categ)
17821 objc_start_category_interface (name, categ, protos);
17822 else
17823 {
17824 objc_start_class_interface (name, super, protos);
17825
17826 cp_parser_objc_class_ivars (parser);
17827 objc_continue_interface ();
17828 }
17829
17830 cp_parser_objc_method_prototype_list (parser);
17831 }
17832
17833
17834
17835 static void
17836 cp_parser_objc_class_implementation (cp_parser* parser)
17837 {
17838 tree name, super, categ;
17839
17840 cp_lexer_consume_token (parser->lexer);
17841 name = cp_parser_identifier (parser);
17842 cp_parser_objc_superclass_or_category (parser, &super, &categ);
17843
17844
17845 if (categ)
17846 objc_start_category_implementation (name, categ);
17847 else
17848 {
17849 objc_start_class_implementation (name, super);
17850
17851 cp_parser_objc_class_ivars (parser);
17852 objc_continue_implementation ();
17853 }
17854
17855 cp_parser_objc_method_definition_list (parser);
17856 }
17857
17858
17859
17860 static void
17861 cp_parser_objc_end_implementation (cp_parser* parser)
17862 {
17863 cp_lexer_consume_token (parser->lexer);
17864 objc_finish_implementation ();
17865 }
17866
17867
17868
17869 static void
17870 cp_parser_objc_declaration (cp_parser* parser)
17871 {
17872
17873 cp_token *kwd = cp_lexer_peek_token (parser->lexer);
17874
17875 switch (kwd->keyword)
17876 {
17877 case RID_AT_ALIAS:
17878 cp_parser_objc_alias_declaration (parser);
17879 break;
17880 case RID_AT_CLASS:
17881 cp_parser_objc_class_declaration (parser);
17882 break;
17883 case RID_AT_PROTOCOL:
17884 cp_parser_objc_protocol_declaration (parser);
17885 break;
17886 case RID_AT_INTERFACE:
17887 cp_parser_objc_class_interface (parser);
17888 break;
17889 case RID_AT_IMPLEMENTATION:
17890 cp_parser_objc_class_implementation (parser);
17891 break;
17892 case RID_AT_END:
17893 cp_parser_objc_end_implementation (parser);
17894 break;
17895 default:
17896 error ("misplaced %<@%D%> Objective-C++ construct", kwd->u.value);
17897 cp_parser_skip_to_end_of_block_or_statement (parser);
17898 }
17899 }
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918 static tree
17919 cp_parser_objc_try_catch_finally_statement (cp_parser *parser) {
17920 location_t location;
17921 tree stmt;
17922
17923 cp_parser_require_keyword (parser, RID_AT_TRY, "`@try'");
17924 location = cp_lexer_peek_token (parser->lexer)->location;
17925
17926
17927 stmt = push_stmt_list ();
17928 cp_parser_compound_statement (parser, NULL, false);
17929 objc_begin_try_stmt (location, pop_stmt_list (stmt));
17930
17931 while (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_CATCH))
17932 {
17933 cp_parameter_declarator *parmdecl;
17934 tree parm;
17935
17936 cp_lexer_consume_token (parser->lexer);
17937 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
17938 parmdecl = cp_parser_parameter_declaration (parser, false, NULL);
17939 parm = grokdeclarator (parmdecl->declarator,
17940 &parmdecl->decl_specifiers,
17941 PARM, 0,
17942 NULL);
17943 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17944 objc_begin_catch_clause (parm);
17945 cp_parser_compound_statement (parser, NULL, false);
17946 objc_finish_catch_clause ();
17947 }
17948
17949 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_AT_FINALLY))
17950 {
17951 cp_lexer_consume_token (parser->lexer);
17952 location = cp_lexer_peek_token (parser->lexer)->location;
17953
17954
17955 stmt = push_stmt_list ();
17956 cp_parser_compound_statement (parser, NULL, false);
17957 objc_build_finally_clause (location, pop_stmt_list (stmt));
17958 }
17959
17960 return objc_finish_try_stmt ();
17961 }
17962
17963
17964
17965
17966
17967
17968
17969
17970 static tree
17971 cp_parser_objc_synchronized_statement (cp_parser *parser) {
17972 location_t location;
17973 tree lock, stmt;
17974
17975 cp_parser_require_keyword (parser, RID_AT_SYNCHRONIZED, "`@synchronized'");
17976
17977 location = cp_lexer_peek_token (parser->lexer)->location;
17978 cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
17979 lock = cp_parser_expression (parser, false);
17980 cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
17981
17982
17983
17984 stmt = push_stmt_list ();
17985 cp_parser_compound_statement (parser, NULL, false);
17986
17987 return objc_build_synchronized (location, lock, pop_stmt_list (stmt));
17988 }
17989
17990
17991
17992
17993
17994
17995
17996
17997 static tree
17998 cp_parser_objc_throw_statement (cp_parser *parser) {
17999 tree expr = NULL_TREE;
18000
18001 cp_parser_require_keyword (parser, RID_AT_THROW, "`@throw'");
18002
18003 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
18004 expr = cp_parser_assignment_expression (parser, false);
18005
18006 cp_parser_consume_semicolon_at_end_of_statement (parser);
18007
18008 return objc_build_throw_stmt (expr);
18009 }
18010
18011
18012
18013 static tree
18014 cp_parser_objc_statement (cp_parser * parser) {
18015
18016 cp_token *kwd = cp_lexer_peek_token (parser->lexer);
18017
18018 switch (kwd->keyword)
18019 {
18020 case RID_AT_TRY:
18021 return cp_parser_objc_try_catch_finally_statement (parser);
18022 case RID_AT_SYNCHRONIZED:
18023 return cp_parser_objc_synchronized_statement (parser);
18024 case RID_AT_THROW:
18025 return cp_parser_objc_throw_statement (parser);
18026 default:
18027 error ("misplaced %<@%D%> Objective-C++ construct", kwd->u.value);
18028 cp_parser_skip_to_end_of_block_or_statement (parser);
18029 }
18030
18031 return error_mark_node;
18032 }
18033
18034
18035
18036
18037 typedef enum pragma_omp_clause {
18038 PRAGMA_OMP_CLAUSE_NONE = 0,
18039
18040 PRAGMA_OMP_CLAUSE_COPYIN,
18041 PRAGMA_OMP_CLAUSE_COPYPRIVATE,
18042 PRAGMA_OMP_CLAUSE_DEFAULT,
18043 PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
18044 PRAGMA_OMP_CLAUSE_IF,
18045 PRAGMA_OMP_CLAUSE_LASTPRIVATE,
18046 PRAGMA_OMP_CLAUSE_NOWAIT,
18047 PRAGMA_OMP_CLAUSE_NUM_THREADS,
18048 PRAGMA_OMP_CLAUSE_ORDERED,
18049 PRAGMA_OMP_CLAUSE_PRIVATE,
18050 PRAGMA_OMP_CLAUSE_REDUCTION,
18051 PRAGMA_OMP_CLAUSE_SCHEDULE,
18052 PRAGMA_OMP_CLAUSE_SHARED
18053 } pragma_omp_clause;
18054
18055
18056
18057
18058
18059
18060 static pragma_omp_clause
18061 cp_parser_omp_clause_name (cp_parser *parser)
18062 {
18063 pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE;
18064
18065 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_IF))
18066 result = PRAGMA_OMP_CLAUSE_IF;
18067 else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_DEFAULT))
18068 result = PRAGMA_OMP_CLAUSE_DEFAULT;
18069 else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_PRIVATE))
18070 result = PRAGMA_OMP_CLAUSE_PRIVATE;
18071 else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
18072 {
18073 tree id = cp_lexer_peek_token (parser->lexer)->u.value;
18074 const char *p = IDENTIFIER_POINTER (id);
18075
18076 switch (p[0])
18077 {
18078 case 'c':
18079 if (!strcmp ("copyin", p))
18080 result = PRAGMA_OMP_CLAUSE_COPYIN;
18081 else if (!strcmp ("copyprivate", p))
18082 result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
18083 break;
18084 case 'f':
18085 if (!strcmp ("firstprivate", p))
18086 result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
18087 break;
18088 case 'l':
18089 if (!strcmp ("lastprivate", p))
18090 result = PRAGMA_OMP_CLAUSE_LASTPRIVATE;
18091 break;
18092 case 'n':
18093 if (!strcmp ("nowait", p))
18094 result = PRAGMA_OMP_CLAUSE_NOWAIT;
18095 else if (!strcmp ("num_threads", p))
18096 result = PRAGMA_OMP_CLAUSE_NUM_THREADS;
18097 break;
18098 case 'o':
18099 if (!strcmp ("ordered", p))
18100 result = PRAGMA_OMP_CLAUSE_ORDERED;
18101 break;
18102 case 'r':
18103 if (!strcmp ("reduction", p))
18104 result = PRAGMA_OMP_CLAUSE_REDUCTION;
18105 break;
18106 case 's':
18107 if (!strcmp ("schedule", p))
18108 result = PRAGMA_OMP_CLAUSE_SCHEDULE;
18109 else if (!strcmp ("shared", p))
18110 result = PRAGMA_OMP_CLAUSE_SHARED;
18111 break;
18112 }
18113 }
18114
18115 if (result != PRAGMA_OMP_CLAUSE_NONE)
18116 cp_lexer_consume_token (parser->lexer);
18117
18118 return result;
18119 }
18120
18121
18122
18123 static void
18124 check_no_duplicate_clause (tree clauses, enum tree_code code, const char *name)
18125 {
18126 tree c;
18127
18128 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
18129 if (OMP_CLAUSE_CODE (c) == code)
18130 {
18131 error ("too many %qs clauses", name);
18132 break;
18133 }
18134 }
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150 static tree
18151 cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind,
18152 tree list)
18153 {
18154 while (1)
18155 {
18156 tree name, decl;
18157
18158 name = cp_parser_id_expression (parser, false,
18159 true,
18160 NULL,
18161 false,
18162 false);
18163 if (name == error_mark_node)
18164 goto skip_comma;
18165
18166 decl = cp_parser_lookup_name_simple (parser, name);
18167 if (decl == error_mark_node)
18168 cp_parser_name_lookup_error (parser, name, decl, NULL);
18169 else if (kind != 0)
18170 {
18171 tree u = build_omp_clause (kind);
18172 OMP_CLAUSE_DECL (u) = decl;
18173 OMP_CLAUSE_CHAIN (u) = list;
18174 list = u;
18175 }
18176 else
18177 list = tree_cons (decl, NULL_TREE, list);
18178
18179 get_comma:
18180 if (cp_lexer_next_token_is_not (parser->lexer, CPP_COMMA))
18181 break;
18182 cp_lexer_consume_token (parser->lexer);
18183 }
18184
18185 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18186 {
18187 int ending;
18188
18189
18190
18191 skip_comma:
18192 ending = cp_parser_skip_to_closing_parenthesis (parser,
18193 true,
18194 true,
18195 true);
18196 if (ending < 0)
18197 goto get_comma;
18198 }
18199
18200 return list;
18201 }
18202
18203
18204
18205
18206 static tree
18207 cp_parser_omp_var_list (cp_parser *parser, enum omp_clause_code kind, tree list)
18208 {
18209 if (cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
18210 return cp_parser_omp_var_list_no_open (parser, kind, list);
18211 return list;
18212 }
18213
18214
18215
18216
18217 static tree
18218 cp_parser_omp_clause_default (cp_parser *parser, tree list)
18219 {
18220 enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
18221 tree c;
18222
18223 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
18224 return list;
18225 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
18226 {
18227 tree id = cp_lexer_peek_token (parser->lexer)->u.value;
18228 const char *p = IDENTIFIER_POINTER (id);
18229
18230 switch (p[0])
18231 {
18232 case 'n':
18233 if (strcmp ("none", p) != 0)
18234 goto invalid_kind;
18235 kind = OMP_CLAUSE_DEFAULT_NONE;
18236 break;
18237
18238 case 's':
18239 if (strcmp ("shared", p) != 0)
18240 goto invalid_kind;
18241 kind = OMP_CLAUSE_DEFAULT_SHARED;
18242 break;
18243
18244 default:
18245 goto invalid_kind;
18246 }
18247
18248 cp_lexer_consume_token (parser->lexer);
18249 }
18250 else
18251 {
18252 invalid_kind:
18253 cp_parser_error (parser, "expected %<none%> or %<shared%>");
18254 }
18255
18256 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18257 cp_parser_skip_to_closing_parenthesis (parser, true,
18258 false,
18259 true);
18260
18261 if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
18262 return list;
18263
18264 check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default");
18265 c = build_omp_clause (OMP_CLAUSE_DEFAULT);
18266 OMP_CLAUSE_CHAIN (c) = list;
18267 OMP_CLAUSE_DEFAULT_KIND (c) = kind;
18268
18269 return c;
18270 }
18271
18272
18273
18274
18275 static tree
18276 cp_parser_omp_clause_if (cp_parser *parser, tree list)
18277 {
18278 tree t, c;
18279
18280 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
18281 return list;
18282
18283 t = cp_parser_condition (parser);
18284
18285 if (t == error_mark_node
18286 || !cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18287 cp_parser_skip_to_closing_parenthesis (parser, true,
18288 false,
18289 true);
18290
18291 check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if");
18292
18293 c = build_omp_clause (OMP_CLAUSE_IF);
18294 OMP_CLAUSE_IF_EXPR (c) = t;
18295 OMP_CLAUSE_CHAIN (c) = list;
18296
18297 return c;
18298 }
18299
18300
18301
18302
18303 static tree
18304 cp_parser_omp_clause_nowait (cp_parser *parser ATTRIBUTE_UNUSED, tree list)
18305 {
18306 tree c;
18307
18308 check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait");
18309
18310 c = build_omp_clause (OMP_CLAUSE_NOWAIT);
18311 OMP_CLAUSE_CHAIN (c) = list;
18312 return c;
18313 }
18314
18315
18316
18317
18318 static tree
18319 cp_parser_omp_clause_num_threads (cp_parser *parser, tree list)
18320 {
18321 tree t, c;
18322
18323 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
18324 return list;
18325
18326 t = cp_parser_expression (parser, false);
18327
18328 if (t == error_mark_node
18329 || !cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18330 cp_parser_skip_to_closing_parenthesis (parser, true,
18331 false,
18332 true);
18333
18334 check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads");
18335
18336 c = build_omp_clause (OMP_CLAUSE_NUM_THREADS);
18337 OMP_CLAUSE_NUM_THREADS_EXPR (c) = t;
18338 OMP_CLAUSE_CHAIN (c) = list;
18339
18340 return c;
18341 }
18342
18343
18344
18345
18346 static tree
18347 cp_parser_omp_clause_ordered (cp_parser *parser ATTRIBUTE_UNUSED, tree list)
18348 {
18349 tree c;
18350
18351 check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered");
18352
18353 c = build_omp_clause (OMP_CLAUSE_ORDERED);
18354 OMP_CLAUSE_CHAIN (c) = list;
18355 return c;
18356 }
18357
18358
18359
18360
18361
18362
18363
18364 static tree
18365 cp_parser_omp_clause_reduction (cp_parser *parser, tree list)
18366 {
18367 enum tree_code code;
18368 tree nlist, c;
18369
18370 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
18371 return list;
18372
18373 switch (cp_lexer_peek_token (parser->lexer)->type)
18374 {
18375 case CPP_PLUS:
18376 code = PLUS_EXPR;
18377 break;
18378 case CPP_MULT:
18379 code = MULT_EXPR;
18380 break;
18381 case CPP_MINUS:
18382 code = MINUS_EXPR;
18383 break;
18384 case CPP_AND:
18385 code = BIT_AND_EXPR;
18386 break;
18387 case CPP_XOR:
18388 code = BIT_XOR_EXPR;
18389 break;
18390 case CPP_OR:
18391 code = BIT_IOR_EXPR;
18392 break;
18393 case CPP_AND_AND:
18394 code = TRUTH_ANDIF_EXPR;
18395 break;
18396 case CPP_OR_OR:
18397 code = TRUTH_ORIF_EXPR;
18398 break;
18399 default:
18400 cp_parser_error (parser, "`+', `*', `-', `&', `^', `|', `&&', or `||'");
18401 resync_fail:
18402 cp_parser_skip_to_closing_parenthesis (parser, true,
18403 false,
18404 true);
18405 return list;
18406 }
18407 cp_lexer_consume_token (parser->lexer);
18408
18409 if (!cp_parser_require (parser, CPP_COLON, "`:'"))
18410 goto resync_fail;
18411
18412 nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_REDUCTION, list);
18413 for (c = nlist; c != list; c = OMP_CLAUSE_CHAIN (c))
18414 OMP_CLAUSE_REDUCTION_CODE (c) = code;
18415
18416 return nlist;
18417 }
18418
18419
18420
18421
18422
18423
18424
18425
18426 static tree
18427 cp_parser_omp_clause_schedule (cp_parser *parser, tree list)
18428 {
18429 tree c, t;
18430
18431 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
18432 return list;
18433
18434 c = build_omp_clause (OMP_CLAUSE_SCHEDULE);
18435
18436 if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
18437 {
18438 tree id = cp_lexer_peek_token (parser->lexer)->u.value;
18439 const char *p = IDENTIFIER_POINTER (id);
18440
18441 switch (p[0])
18442 {
18443 case 'd':
18444 if (strcmp ("dynamic", p) != 0)
18445 goto invalid_kind;
18446 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC;
18447 break;
18448
18449 case 'g':
18450 if (strcmp ("guided", p) != 0)
18451 goto invalid_kind;
18452 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED;
18453 break;
18454
18455 case 'r':
18456 if (strcmp ("runtime", p) != 0)
18457 goto invalid_kind;
18458 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME;
18459 break;
18460
18461 default:
18462 goto invalid_kind;
18463 }
18464 }
18465 else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_STATIC))
18466 OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
18467 else
18468 goto invalid_kind;
18469 cp_lexer_consume_token (parser->lexer);
18470
18471 if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
18472 {
18473 cp_lexer_consume_token (parser->lexer);
18474
18475 t = cp_parser_assignment_expression (parser, false);
18476
18477 if (t == error_mark_node)
18478 goto resync_fail;
18479 else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
18480 error ("schedule %<runtime%> does not take "
18481 "a %<chunk_size%> parameter");
18482 else
18483 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
18484
18485 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18486 goto resync_fail;
18487 }
18488 else if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`,' or `)'"))
18489 goto resync_fail;
18490
18491 check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule");
18492 OMP_CLAUSE_CHAIN (c) = list;
18493 return c;
18494
18495 invalid_kind:
18496 cp_parser_error (parser, "invalid schedule kind");
18497 resync_fail:
18498 cp_parser_skip_to_closing_parenthesis (parser, true,
18499 false,
18500 true);
18501 return list;
18502 }
18503
18504
18505
18506
18507
18508 static tree
18509 cp_parser_omp_all_clauses (cp_parser *parser, unsigned int mask,
18510 const char *where, cp_token *pragma_tok)
18511 {
18512 tree clauses = NULL;
18513
18514 while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
18515 {
18516 pragma_omp_clause c_kind = cp_parser_omp_clause_name (parser);
18517 const char *c_name;
18518 tree prev = clauses;
18519
18520 switch (c_kind)
18521 {
18522 case PRAGMA_OMP_CLAUSE_COPYIN:
18523 clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_COPYIN, clauses);
18524 c_name = "copyin";
18525 break;
18526 case PRAGMA_OMP_CLAUSE_COPYPRIVATE:
18527 clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_COPYPRIVATE,
18528 clauses);
18529 c_name = "copyprivate";
18530 break;
18531 case PRAGMA_OMP_CLAUSE_DEFAULT:
18532 clauses = cp_parser_omp_clause_default (parser, clauses);
18533 c_name = "default";
18534 break;
18535 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE:
18536 clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_FIRSTPRIVATE,
18537 clauses);
18538 c_name = "firstprivate";
18539 break;
18540 case PRAGMA_OMP_CLAUSE_IF:
18541 clauses = cp_parser_omp_clause_if (parser, clauses);
18542 c_name = "if";
18543 break;
18544 case PRAGMA_OMP_CLAUSE_LASTPRIVATE:
18545 clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_LASTPRIVATE,
18546 clauses);
18547 c_name = "lastprivate";
18548 break;
18549 case PRAGMA_OMP_CLAUSE_NOWAIT:
18550 clauses = cp_parser_omp_clause_nowait (parser, clauses);
18551 c_name = "nowait";
18552 break;
18553 case PRAGMA_OMP_CLAUSE_NUM_THREADS:
18554 clauses = cp_parser_omp_clause_num_threads (parser, clauses);
18555 c_name = "num_threads";
18556 break;
18557 case PRAGMA_OMP_CLAUSE_ORDERED:
18558 clauses = cp_parser_omp_clause_ordered (parser, clauses);
18559 c_name = "ordered";
18560 break;
18561 case PRAGMA_OMP_CLAUSE_PRIVATE:
18562 clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_PRIVATE,
18563 clauses);
18564 c_name = "private";
18565 break;
18566 case PRAGMA_OMP_CLAUSE_REDUCTION:
18567 clauses = cp_parser_omp_clause_reduction (parser, clauses);
18568 c_name = "reduction";
18569 break;
18570 case PRAGMA_OMP_CLAUSE_SCHEDULE:
18571 clauses = cp_parser_omp_clause_schedule (parser, clauses);
18572 c_name = "schedule";
18573 break;
18574 case PRAGMA_OMP_CLAUSE_SHARED:
18575 clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_SHARED,
18576 clauses);
18577 c_name = "shared";
18578 break;
18579 default:
18580 cp_parser_error (parser, "expected %<#pragma omp%> clause");
18581 goto saw_error;
18582 }
18583
18584 if (((mask >> c_kind) & 1) == 0)
18585 {
18586
18587
18588 clauses = prev;
18589 error ("%qs is not valid for %qs", c_name, where);
18590 }
18591 }
18592 saw_error:
18593 cp_parser_skip_to_pragma_eol (parser, pragma_tok);
18594 return finish_omp_clauses (clauses);
18595 }
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605 static unsigned
18606 cp_parser_begin_omp_structured_block (cp_parser *parser)
18607 {
18608 unsigned save = parser->in_statement;
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618 if (parser->in_statement)
18619 parser->in_statement = IN_OMP_BLOCK;
18620
18621 return save;
18622 }
18623
18624 static void
18625 cp_parser_end_omp_structured_block (cp_parser *parser, unsigned save)
18626 {
18627 parser->in_statement = save;
18628 }
18629
18630 static tree
18631 cp_parser_omp_structured_block (cp_parser *parser)
18632 {
18633 tree stmt = begin_omp_structured_block ();
18634 unsigned int save = cp_parser_begin_omp_structured_block (parser);
18635
18636 cp_parser_statement (parser, NULL_TREE, false);
18637
18638 cp_parser_end_omp_structured_block (parser, save);
18639 return finish_omp_structured_block (stmt);
18640 }
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653 static void
18654 cp_parser_omp_atomic (cp_parser *parser, cp_token *pragma_tok)
18655 {
18656 tree lhs, rhs;
18657 enum tree_code code;
18658
18659 cp_parser_require_pragma_eol (parser, pragma_tok);
18660
18661 lhs = cp_parser_unary_expression (parser, false,
18662 false);
18663 switch (TREE_CODE (lhs))
18664 {
18665 case ERROR_MARK:
18666 goto saw_error;
18667
18668 case PREINCREMENT_EXPR:
18669 case POSTINCREMENT_EXPR:
18670 lhs = TREE_OPERAND (lhs, 0);
18671 code = PLUS_EXPR;
18672 rhs = integer_one_node;
18673 break;
18674
18675 case PREDECREMENT_EXPR:
18676 case POSTDECREMENT_EXPR:
18677 lhs = TREE_OPERAND (lhs, 0);
18678 code = MINUS_EXPR;
18679 rhs = integer_one_node;
18680 break;
18681
18682 default:
18683 switch (cp_lexer_peek_token (parser->lexer)->type)
18684 {
18685 case CPP_MULT_EQ:
18686 code = MULT_EXPR;
18687 break;
18688 case CPP_DIV_EQ:
18689 code = TRUNC_DIV_EXPR;
18690 break;
18691 case CPP_PLUS_EQ:
18692 code = PLUS_EXPR;
18693 break;
18694 case CPP_MINUS_EQ:
18695 code = MINUS_EXPR;
18696 break;
18697 case CPP_LSHIFT_EQ:
18698 code = LSHIFT_EXPR;
18699 break;
18700 case CPP_RSHIFT_EQ:
18701 code = RSHIFT_EXPR;
18702 break;
18703 case CPP_AND_EQ:
18704 code = BIT_AND_EXPR;
18705 break;
18706 case CPP_OR_EQ:
18707 code = BIT_IOR_EXPR;
18708 break;
18709 case CPP_XOR_EQ:
18710 code = BIT_XOR_EXPR;
18711 break;
18712 default:
18713 cp_parser_error (parser,
18714 "invalid operator for %<#pragma omp atomic%>");
18715 goto saw_error;
18716 }
18717 cp_lexer_consume_token (parser->lexer);
18718
18719 rhs = cp_parser_expression (parser, false);
18720 if (rhs == error_mark_node)
18721 goto saw_error;
18722 break;
18723 }
18724 finish_omp_atomic (code, lhs, rhs);
18725 cp_parser_consume_semicolon_at_end_of_statement (parser);
18726 return;
18727
18728 saw_error:
18729 cp_parser_skip_to_end_of_block_or_statement (parser);
18730 }
18731
18732
18733
18734
18735
18736 static void
18737 cp_parser_omp_barrier (cp_parser *parser, cp_token *pragma_tok)
18738 {
18739 cp_parser_require_pragma_eol (parser, pragma_tok);
18740 finish_omp_barrier ();
18741 }
18742
18743
18744
18745
18746
18747 static tree
18748 cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok)
18749 {
18750 tree stmt, name = NULL;
18751
18752 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
18753 {
18754 cp_lexer_consume_token (parser->lexer);
18755
18756 name = cp_parser_identifier (parser);
18757
18758 if (name == error_mark_node
18759 || !cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18760 cp_parser_skip_to_closing_parenthesis (parser, true,
18761 false,
18762 true);
18763 if (name == error_mark_node)
18764 name = NULL;
18765 }
18766 cp_parser_require_pragma_eol (parser, pragma_tok);
18767
18768 stmt = cp_parser_omp_structured_block (parser);
18769 return c_finish_omp_critical (stmt, name);
18770 }
18771
18772
18773
18774
18775
18776
18777
18778 static void
18779 cp_parser_omp_flush (cp_parser *parser, cp_token *pragma_tok)
18780 {
18781 if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
18782 (void) cp_parser_omp_var_list (parser, 0, NULL);
18783 cp_parser_require_pragma_eol (parser, pragma_tok);
18784
18785 finish_omp_flush ();
18786 }
18787
18788
18789
18790 static tree
18791 cp_parser_omp_for_loop (cp_parser *parser)
18792 {
18793 tree init, cond, incr, body, decl, pre_body;
18794 location_t loc;
18795
18796 if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
18797 {
18798 cp_parser_error (parser, "for statement expected");
18799 return NULL;
18800 }
18801 loc = cp_lexer_consume_token (parser->lexer)->location;
18802 if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
18803 return NULL;
18804
18805 init = decl = NULL;
18806 pre_body = push_stmt_list ();
18807 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
18808 {
18809 cp_decl_specifier_seq type_specifiers;
18810
18811
18812
18813
18814 cp_parser_parse_tentatively (parser);
18815 cp_parser_type_specifier_seq (parser, false,
18816 &type_specifiers);
18817 if (!cp_parser_error_occurred (parser))
18818 {
18819 tree asm_specification, attributes;
18820 cp_declarator *declarator;
18821
18822 declarator = cp_parser_declarator (parser,
18823 CP_PARSER_DECLARATOR_NAMED,
18824 NULL,
18825 NULL,
18826 false);
18827 attributes = cp_parser_attributes_opt (parser);
18828 asm_specification = cp_parser_asm_specification_opt (parser);
18829
18830 cp_parser_require (parser, CPP_EQ, "`='");
18831 if (cp_parser_parse_definitely (parser))
18832 {
18833 tree pushed_scope;
18834
18835 decl = start_decl (declarator, &type_specifiers,
18836 false, attributes,
18837 NULL_TREE,
18838 &pushed_scope);
18839
18840 init = cp_parser_assignment_expression (parser, false);
18841
18842 cp_finish_decl (decl, NULL_TREE, false,
18843 asm_specification, LOOKUP_ONLYCONVERTING);
18844
18845 if (pushed_scope)
18846 pop_scope (pushed_scope);
18847 }
18848 }
18849 else
18850 cp_parser_abort_tentative_parse (parser);
18851
18852
18853
18854 if (decl == NULL)
18855 init = cp_parser_expression (parser, false);
18856 }
18857 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
18858 pre_body = pop_stmt_list (pre_body);
18859
18860 cond = NULL;
18861 if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
18862 cond = cp_parser_condition (parser);
18863 cp_parser_require (parser, CPP_SEMICOLON, "`;'");
18864
18865 incr = NULL;
18866 if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
18867 incr = cp_parser_expression (parser, false);
18868
18869 if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
18870 cp_parser_skip_to_closing_parenthesis (parser, true,
18871 false,
18872 true);
18873
18874
18875
18876 parser->in_statement = IN_OMP_FOR;
18877
18878
18879
18880 body = push_stmt_list ();
18881 cp_parser_statement (parser, NULL_TREE, false);
18882 body = pop_stmt_list (body);
18883
18884 return finish_omp_for (loc, decl, init, cond, incr, body, pre_body);
18885 }
18886
18887
18888
18889
18890
18891 #define OMP_FOR_CLAUSE_MASK \
18892 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
18893 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
18894 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
18895 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
18896 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
18897 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
18898 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
18899
18900 static tree
18901 cp_parser_omp_for (cp_parser *parser, cp_token *pragma_tok)
18902 {
18903 tree clauses, sb, ret;
18904 unsigned int save;
18905
18906 clauses = cp_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK,
18907 "#pragma omp for", pragma_tok);
18908
18909 sb = begin_omp_structured_block ();
18910 save = cp_parser_begin_omp_structured_block (parser);
18911
18912 ret = cp_parser_omp_for_loop (parser);
18913 if (ret)
18914 OMP_FOR_CLAUSES (ret) = clauses;
18915
18916 cp_parser_end_omp_structured_block (parser, save);
18917 add_stmt (finish_omp_structured_block (sb));
18918
18919 return ret;
18920 }
18921
18922
18923
18924
18925
18926 static tree
18927 cp_parser_omp_master (cp_parser *parser, cp_token *pragma_tok)
18928 {
18929 cp_parser_require_pragma_eol (parser, pragma_tok);
18930 return c_finish_omp_master (cp_parser_omp_structured_block (parser));
18931 }
18932
18933
18934
18935
18936
18937 static tree
18938 cp_parser_omp_ordered (cp_parser *parser, cp_token *pragma_tok)
18939 {
18940 cp_parser_require_pragma_eol (parser, pragma_tok);
18941 return c_finish_omp_ordered (cp_parser_omp_structured_block (parser));
18942 }
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953 static tree
18954 cp_parser_omp_sections_scope (cp_parser *parser)
18955 {
18956 tree stmt, substmt;
18957 bool error_suppress = false;
18958 cp_token *tok;
18959
18960 if (!cp_parser_require (parser, CPP_OPEN_BRACE, "`{'"))
18961 return NULL_TREE;
18962
18963 stmt = push_stmt_list ();
18964
18965 if (cp_lexer_peek_token (parser->lexer)->pragma_kind != PRAGMA_OMP_SECTION)
18966 {
18967 unsigned save;
18968
18969 substmt = begin_omp_structured_block ();
18970 save = cp_parser_begin_omp_structured_block (parser);
18971
18972 while (1)
18973 {
18974 cp_parser_statement (parser, NULL_TREE, false);
18975
18976 tok = cp_lexer_peek_token (parser->lexer);
18977 if (tok->pragma_kind == PRAGMA_OMP_SECTION)
18978 break;
18979 if (tok->type == CPP_CLOSE_BRACE)
18980 break;
18981 if (tok->type == CPP_EOF)
18982 break;
18983 }
18984
18985 cp_parser_end_omp_structured_block (parser, save);
18986 substmt = finish_omp_structured_block (substmt);
18987 substmt = build1 (OMP_SECTION, void_type_node, substmt);
18988 add_stmt (substmt);
18989 }
18990
18991 while (1)
18992 {
18993 tok = cp_lexer_peek_token (parser->lexer);
18994 if (tok->type == CPP_CLOSE_BRACE)
18995 break;
18996 if (tok->type == CPP_EOF)
18997 break;
18998
18999 if (tok->pragma_kind == PRAGMA_OMP_SECTION)
19000 {
19001 cp_lexer_consume_token (parser->lexer);
19002 cp_parser_require_pragma_eol (parser, tok);
19003 error_suppress = false;
19004 }
19005 else if (!error_suppress)
19006 {
19007 cp_parser_error (parser, "expected %<#pragma omp section%> or %<}%>");
19008 error_suppress = true;
19009 }
19010
19011 substmt = cp_parser_omp_structured_block (parser);
19012 substmt = build1 (OMP_SECTION, void_type_node, substmt);
19013 add_stmt (substmt);
19014 }
19015 cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
19016
19017 substmt = pop_stmt_list (stmt);
19018
19019 stmt = make_node (OMP_SECTIONS);
19020 TREE_TYPE (stmt) = void_type_node;
19021 OMP_SECTIONS_BODY (stmt) = substmt;
19022
19023 add_stmt (stmt);
19024 return stmt;
19025 }
19026
19027
19028
19029
19030
19031 #define OMP_SECTIONS_CLAUSE_MASK \
19032 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
19033 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
19034 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
19035 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
19036 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
19037
19038 static tree
19039 cp_parser_omp_sections (cp_parser *parser, cp_token *pragma_tok)
19040 {
19041 tree clauses, ret;
19042
19043 clauses = cp_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK,
19044 "#pragma omp sections", pragma_tok);
19045
19046 ret = cp_parser_omp_sections_scope (parser);
19047 if (ret)
19048 OMP_SECTIONS_CLAUSES (ret) = clauses;
19049
19050 return ret;
19051 }
19052
19053
19054
19055
19056
19057
19058 #define OMP_PARALLEL_CLAUSE_MASK \
19059 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
19060 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
19061 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
19062 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
19063 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
19064 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
19065 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
19066 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
19067
19068 static tree
19069 cp_parser_omp_parallel (cp_parser *parser, cp_token *pragma_tok)
19070 {
19071 enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL;
19072 const char *p_name = "#pragma omp parallel";
19073 tree stmt, clauses, par_clause, ws_clause, block;
19074 unsigned int mask = OMP_PARALLEL_CLAUSE_MASK;
19075 unsigned int save;
19076
19077 if (cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
19078 {
19079 cp_lexer_consume_token (parser->lexer);
19080 p_kind = PRAGMA_OMP_PARALLEL_FOR;
19081 p_name = "#pragma omp parallel for";
19082 mask |= OMP_FOR_CLAUSE_MASK;
19083 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
19084 }
19085 else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
19086 {
19087 tree id = cp_lexer_peek_token (parser->lexer)->u.value;
19088 const char *p = IDENTIFIER_POINTER (id);
19089 if (strcmp (p, "sections") == 0)
19090 {
19091 cp_lexer_consume_token (parser->lexer);
19092 p_kind = PRAGMA_OMP_PARALLEL_SECTIONS;
19093 p_name = "#pragma omp parallel sections";
19094 mask |= OMP_SECTIONS_CLAUSE_MASK;
19095 mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT);
19096 }
19097 }
19098
19099 clauses = cp_parser_omp_all_clauses (parser, mask, p_name, pragma_tok);
19100 block = begin_omp_parallel ();
19101 save = cp_parser_begin_omp_structured_block (parser);
19102
19103 switch (p_kind)
19104 {
19105 case PRAGMA_OMP_PARALLEL:
19106 cp_parser_already_scoped_statement (parser);
19107 par_clause = clauses;
19108 break;
19109
19110 case PRAGMA_OMP_PARALLEL_FOR:
19111 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
19112 stmt = cp_parser_omp_for_loop (parser);
19113 if (stmt)
19114 OMP_FOR_CLAUSES (stmt) = ws_clause;
19115 break;
19116
19117 case PRAGMA_OMP_PARALLEL_SECTIONS:
19118 c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
19119 stmt = cp_parser_omp_sections_scope (parser);
19120 if (stmt)
19121 OMP_SECTIONS_CLAUSES (stmt) = ws_clause;
19122 break;
19123
19124 default:
19125 gcc_unreachable ();
19126 }
19127
19128 cp_parser_end_omp_structured_block (parser, save);
19129 stmt = finish_omp_parallel (par_clause, block);
19130 if (p_kind != PRAGMA_OMP_PARALLEL)
19131 OMP_PARALLEL_COMBINED (stmt) = 1;
19132 return stmt;
19133 }
19134
19135
19136
19137
19138
19139 #define OMP_SINGLE_CLAUSE_MASK \
19140 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
19141 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
19142 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
19143 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
19144
19145 static tree
19146 cp_parser_omp_single (cp_parser *parser, cp_token *pragma_tok)
19147 {
19148 tree stmt = make_node (OMP_SINGLE);
19149 TREE_TYPE (stmt) = void_type_node;
19150
19151 OMP_SINGLE_CLAUSES (stmt)
19152 = cp_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK,
19153 "#pragma omp single", pragma_tok);
19154 OMP_SINGLE_BODY (stmt) = cp_parser_omp_structured_block (parser);
19155
19156 return add_stmt (stmt);
19157 }
19158
19159
19160
19161
19162 static void
19163 cp_parser_omp_threadprivate (cp_parser *parser, cp_token *pragma_tok)
19164 {
19165 tree vars;
19166
19167 vars = cp_parser_omp_var_list (parser, 0, NULL);
19168 cp_parser_require_pragma_eol (parser, pragma_tok);
19169
19170 if (!targetm.have_tls)
19171 sorry ("threadprivate variables not supported in this target");
19172
19173 finish_omp_threadprivate (vars);
19174 }
19175
19176
19177
19178 static void
19179 cp_parser_omp_construct (cp_parser *parser, cp_token *pragma_tok)
19180 {
19181 tree stmt;
19182
19183 switch (pragma_tok->pragma_kind)
19184 {
19185 case PRAGMA_OMP_ATOMIC:
19186 cp_parser_omp_atomic (parser, pragma_tok);
19187 return;
19188 case PRAGMA_OMP_CRITICAL:
19189 stmt = cp_parser_omp_critical (parser, pragma_tok);
19190 break;
19191 case PRAGMA_OMP_FOR:
19192 stmt = cp_parser_omp_for (parser, pragma_tok);
19193 break;
19194 case PRAGMA_OMP_MASTER:
19195 stmt = cp_parser_omp_master (parser, pragma_tok);
19196 break;
19197 case PRAGMA_OMP_ORDERED:
19198 stmt = cp_parser_omp_ordered (parser, pragma_tok);
19199 break;
19200 case PRAGMA_OMP_PARALLEL:
19201 stmt = cp_parser_omp_parallel (parser, pragma_tok);
19202 break;
19203 case PRAGMA_OMP_SECTIONS:
19204 stmt = cp_parser_omp_sections (parser, pragma_tok);
19205 break;
19206 case PRAGMA_OMP_SINGLE:
19207 stmt = cp_parser_omp_single (parser, pragma_tok);
19208 break;
19209 default:
19210 gcc_unreachable ();
19211 }
19212
19213 if (stmt)
19214 SET_EXPR_LOCATION (stmt, pragma_tok->location);
19215 }
19216
19217
19218
19219 static GTY (()) cp_parser *the_parser;
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231 static void
19232 cp_parser_initial_pragma (cp_token *first_token)
19233 {
19234 tree name = NULL;
19235
19236 cp_lexer_get_preprocessor_token (NULL, first_token);
19237 if (first_token->pragma_kind != PRAGMA_GCC_PCH_PREPROCESS)
19238 return;
19239
19240 cp_lexer_get_preprocessor_token (NULL, first_token);
19241 if (first_token->type == CPP_STRING)
19242 {
19243 name = first_token->u.value;
19244
19245 cp_lexer_get_preprocessor_token (NULL, first_token);
19246 if (first_token->type != CPP_PRAGMA_EOL)
19247 error ("junk at end of %<#pragma GCC pch_preprocess%>");
19248 }
19249 else
19250 error ("expected string literal");
19251
19252
19253 while (first_token->type != CPP_PRAGMA_EOL && first_token->type != CPP_EOF)
19254 cp_lexer_get_preprocessor_token (NULL, first_token);
19255
19256
19257 if (name)
19258 c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name));
19259
19260
19261
19262
19263 cp_lexer_get_preprocessor_token (NULL, first_token);
19264 }
19265
19266
19267
19268
19269 static bool
19270 cp_parser_pragma (cp_parser *parser, enum pragma_context context)
19271 {
19272 cp_token *pragma_tok;
19273 unsigned int id;
19274
19275 pragma_tok = cp_lexer_consume_token (parser->lexer);
19276 gcc_assert (pragma_tok->type == CPP_PRAGMA);
19277 parser->lexer->in_pragma = true;
19278
19279 id = pragma_tok->pragma_kind;
19280 switch (id)
19281 {
19282 case PRAGMA_GCC_PCH_PREPROCESS:
19283 error ("%<#pragma GCC pch_preprocess%> must be first");
19284 break;
19285
19286 case PRAGMA_OMP_BARRIER:
19287 switch (context)
19288 {
19289 case pragma_compound:
19290 cp_parser_omp_barrier (parser, pragma_tok);
19291 return false;
19292 case pragma_stmt:
19293 error ("%<#pragma omp barrier%> may only be "
19294 "used in compound statements");
19295 break;
19296 default:
19297 goto bad_stmt;
19298 }
19299 break;
19300
19301 case PRAGMA_OMP_FLUSH:
19302 switch (context)
19303 {
19304 case pragma_compound:
19305 cp_parser_omp_flush (parser, pragma_tok);
19306 return false;
19307 case pragma_stmt:
19308 error ("%<#pragma omp flush%> may only be "
19309 "used in compound statements");
19310 break;
19311 default:
19312 goto bad_stmt;
19313 }
19314 break;
19315
19316 case PRAGMA_OMP_THREADPRIVATE:
19317 cp_parser_omp_threadprivate (parser, pragma_tok);
19318 return false;
19319
19320 case PRAGMA_OMP_ATOMIC:
19321 case PRAGMA_OMP_CRITICAL:
19322 case PRAGMA_OMP_FOR:
19323 case PRAGMA_OMP_MASTER:
19324 case PRAGMA_OMP_ORDERED:
19325 case PRAGMA_OMP_PARALLEL:
19326 case PRAGMA_OMP_SECTIONS:
19327 case PRAGMA_OMP_SINGLE:
19328 if (context == pragma_external)
19329 goto bad_stmt;
19330 cp_parser_omp_construct (parser, pragma_tok);
19331 return true;
19332
19333 case PRAGMA_OMP_SECTION:
19334 error ("%<#pragma omp section%> may only be used in "
19335 "%<#pragma omp sections%> construct");
19336 break;
19337
19338 default:
19339 gcc_assert (id >= PRAGMA_FIRST_EXTERNAL);
19340 c_invoke_pragma_handler (id);
19341 break;
19342
19343 bad_stmt:
19344 cp_parser_error (parser, "expected declaration specifiers");
19345 break;
19346 }
19347
19348 cp_parser_skip_to_pragma_eol (parser, pragma_tok);
19349 return false;
19350 }
19351
19352
19353
19354 enum cpp_ttype
19355 pragma_lex (tree *value)
19356 {
19357 cp_token *tok;
19358 enum cpp_ttype ret;
19359
19360 tok = cp_lexer_peek_token (the_parser->lexer);
19361
19362 ret = tok->type;
19363 *value = tok->u.value;
19364
19365 if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF)
19366 ret = CPP_EOF;
19367 else if (ret == CPP_STRING)
19368 *value = cp_parser_string_literal (the_parser, false, false);
19369 else
19370 {
19371 cp_lexer_consume_token (the_parser->lexer);
19372 if (ret == CPP_KEYWORD)
19373 ret = CPP_NAME;
19374 }
19375
19376 return ret;
19377 }
19378
19379
19380
19381
19382
19383
19384 void
19385 c_parse_file (void)
19386 {
19387 bool error_occurred;
19388 static bool already_called = false;
19389
19390 if (already_called)
19391 {
19392 sorry ("inter-module optimizations not implemented for C++");
19393 return;
19394 }
19395 already_called = true;
19396
19397 the_parser = cp_parser_new ();
19398 push_deferring_access_checks (flag_access_control
19399 ? dk_no_deferred : dk_no_check);
19400 error_occurred = cp_parser_translation_unit (the_parser);
19401 the_parser = NULL;
19402 }
19403
19404
19405
19406 int yydebug;
19407
19408 #include "gt-cp-parser.h"