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