comparison gcc/cp/cxx-pretty-print.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Implementation of subroutines for the GNU C++ pretty-printer. 1 /* Implementation of subroutines for the GNU C++ pretty-printer.
2 Copyright (C) 2003-2017 Free Software Foundation, Inc. 2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> 3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
292 } 292 }
293 break; 293 break;
294 } 294 }
295 } 295 }
296 296
297 /* Given a value e of ENUMERAL_TYPE:
298 Print out the first ENUMERATOR id with value e, if one is found,
299 (including nested names but excluding the enum name if unscoped)
300 else print out the value as a C-style cast (type-id)value. */
301
302 static void
303 pp_cxx_enumeration_constant (cxx_pretty_printer *pp, tree e)
304 {
305 tree type = TREE_TYPE (e);
306 tree value;
307
308 /* Find the name of this constant. */
309 for (value = TYPE_VALUES (type);
310 value != NULL_TREE
311 && !tree_int_cst_equal (DECL_INITIAL (TREE_VALUE (value)), e);
312 value = TREE_CHAIN (value))
313 ;
314
315 if (value != NULL_TREE)
316 {
317 if (!ENUM_IS_SCOPED (type))
318 type = get_containing_scope (type);
319 pp_cxx_nested_name_specifier (pp, type);
320 pp->id_expression (TREE_PURPOSE (value));
321 }
322 else
323 {
324 /* Value must have been cast. */
325 pp_c_type_cast (pp, type);
326 pp_c_integer_constant (pp, e);
327 }
328 }
329
297 330
298 void 331 void
299 cxx_pretty_printer::constant (tree t) 332 cxx_pretty_printer::constant (tree t)
300 { 333 {
301 switch (TREE_CODE (t)) 334 switch (TREE_CODE (t))
313 346
314 case INTEGER_CST: 347 case INTEGER_CST:
315 if (NULLPTR_TYPE_P (TREE_TYPE (t))) 348 if (NULLPTR_TYPE_P (TREE_TYPE (t)))
316 { 349 {
317 pp_string (this, "nullptr"); 350 pp_string (this, "nullptr");
351 break;
352 }
353 else if (TREE_CODE (TREE_TYPE (t)) == ENUMERAL_TYPE)
354 {
355 pp_cxx_enumeration_constant (this, t);
318 break; 356 break;
319 } 357 }
320 /* fall through. */ 358 /* fall through. */
321 359
322 default: 360 default:
897 switch (code) 935 switch (code)
898 { 936 {
899 case MULT_EXPR: 937 case MULT_EXPR:
900 case TRUNC_DIV_EXPR: 938 case TRUNC_DIV_EXPR:
901 case TRUNC_MOD_EXPR: 939 case TRUNC_MOD_EXPR:
940 case EXACT_DIV_EXPR:
941 case RDIV_EXPR:
902 multiplicative_expression (TREE_OPERAND (e, 0)); 942 multiplicative_expression (TREE_OPERAND (e, 0));
903 pp_space (this); 943 pp_space (this);
904 if (code == MULT_EXPR) 944 if (code == MULT_EXPR)
905 pp_star (this); 945 pp_star (this);
906 else if (code == TRUNC_DIV_EXPR) 946 else if (code != TRUNC_MOD_EXPR)
907 pp_slash (this); 947 pp_slash (this);
908 else 948 else
909 pp_modulo (this); 949 pp_modulo (this);
910 pp_space (this); 950 pp_space (this);
911 pp_cxx_pm_expression (this, TREE_OPERAND (e, 1)); 951 pp_cxx_pm_expression (this, TREE_OPERAND (e, 1));
1111 break; 1151 break;
1112 1152
1113 case MULT_EXPR: 1153 case MULT_EXPR:
1114 case TRUNC_DIV_EXPR: 1154 case TRUNC_DIV_EXPR:
1115 case TRUNC_MOD_EXPR: 1155 case TRUNC_MOD_EXPR:
1156 case EXACT_DIV_EXPR:
1157 case RDIV_EXPR:
1116 multiplicative_expression (t); 1158 multiplicative_expression (t);
1117 break; 1159 break;
1118 1160
1119 case COND_EXPR: 1161 case COND_EXPR:
1120 conditional_expression (t); 1162 conditional_expression (t);
1696 void 1738 void
1697 cxx_pretty_printer::abstract_declarator (tree t) 1739 cxx_pretty_printer::abstract_declarator (tree t)
1698 { 1740 {
1699 if (TYPE_PTRMEM_P (t)) 1741 if (TYPE_PTRMEM_P (t))
1700 pp_cxx_right_paren (this); 1742 pp_cxx_right_paren (this);
1701 else if (POINTER_TYPE_P (t)) 1743 else if (INDIRECT_TYPE_P (t))
1702 { 1744 {
1703 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE 1745 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
1704 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) 1746 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
1705 pp_cxx_right_paren (this); 1747 pp_cxx_right_paren (this);
1706 t = TREE_TYPE (t); 1748 t = TREE_TYPE (t);
2015 2057
2016 case RANGE_FOR_STMT: 2058 case RANGE_FOR_STMT:
2017 pp_cxx_ws_string (this, "for"); 2059 pp_cxx_ws_string (this, "for");
2018 pp_space (this); 2060 pp_space (this);
2019 pp_cxx_left_paren (this); 2061 pp_cxx_left_paren (this);
2062 if (RANGE_FOR_INIT_STMT (t))
2063 {
2064 statement (RANGE_FOR_INIT_STMT (t));
2065 pp_needs_newline (this) = false;
2066 pp_cxx_whitespace (this);
2067 }
2020 statement (RANGE_FOR_DECL (t)); 2068 statement (RANGE_FOR_DECL (t));
2021 pp_space (this); 2069 pp_space (this);
2022 pp_needs_newline (this) = false; 2070 pp_needs_newline (this) = false;
2023 pp_colon (this); 2071 pp_colon (this);
2024 pp_space (this); 2072 pp_space (this);
2389 { 2437 {
2390 switch (TREE_CODE (t)) 2438 switch (TREE_CODE (t))
2391 { 2439 {
2392 case ARROW_EXPR: 2440 case ARROW_EXPR:
2393 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR 2441 if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
2394 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0)))) 2442 && INDIRECT_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
2395 { 2443 {
2396 pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)))); 2444 pp->type_id (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
2397 pp_cxx_separate_with (pp, ','); 2445 pp_cxx_separate_with (pp, ',');
2398 return true; 2446 return true;
2399 } 2447 }