aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2018-08-17 23:18:11 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2018-08-17 23:18:11 +0000
commit800c0e9877f2adce864fd3e0c0ee5906bd32736f (patch)
treed259b37b7b95254179ac5634b71a84ce199430fe /gcc/c-family
parent6f0821f4468b774cefe0a00560ed4bd290835fe2 (diff)
downloadgcc-800c0e9877f2adce864fd3e0c0ee5906bd32736f.zip
gcc-800c0e9877f2adce864fd3e0c0ee5906bd32736f.tar.gz
gcc-800c0e9877f2adce864fd3e0c0ee5906bd32736f.tar.bz2
[PATCH] Adjust lazy macro definition
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01072.html libcpp/ * include/cpplib.h (struct cpp_callbacks): Replace user_builtin_macro with user_lazy_macro. (struct cpp_macro): add lazy field. (enum cpp_builtin_type): Remove BT_FIRST_USER, BT_LAST_USER. (cpp_define_lazily): Declare. * macro.c (enter_macro_context) Use _cpp_maybe_notify_macro_use. (warn_of_redefinition): Use cpp_builtin_macro_p, directly call user_lazy_macro hook. (_cpp_new_macro): Clear lazy field. (cpp_define_lazily): Define. (_cpp_notify_macro_use): Adjust lazy definition code. (cpp_macro_definition): No need to do lazy definition here. * pch.c (write_macdef, save_macros): Likewise. gcc/c-family/ * c-cppbuiltin.c (struct lazy_hex_fp_value_struct): Remove macro field. (laxy_hex_fp_value_count): Make unsigned. (lazy_hex_fp_value): Provided with macro & lazy number. Directly manipulate the macro. (builtin_defin_with_hex_fp_value): Adjust callback name, use cpp_define_lazily. From-SVN: r263640
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog10
-rw-r--r--gcc/c-family/c-cppbuiltin.c59
2 files changed, 36 insertions, 33 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 47221b4..6cdade5 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-17 Nathan Sidwell <nathan@acm.org>
+
+ * c-cppbuiltin.c (struct lazy_hex_fp_value_struct): Remove macro
+ field.
+ (laxy_hex_fp_value_count): Make unsigned.
+ (lazy_hex_fp_value): Provided with macro & lazy number. Directly
+ manipulate the macro.
+ (builtin_defin_with_hex_fp_value): Adjust callback name, use
+ cpp_define_lazily.
+
2018-08-17 David Malcolm <dmalcolm@redhat.com>
* c-format.c (enum format_type): Add gcc_dump_printf_format_type.
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 85d79dc..96a6b4d 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1570,7 +1570,6 @@ builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
struct GTY(()) lazy_hex_fp_value_struct
{
const char *hex_str;
- cpp_macro *macro;
machine_mode mode;
int digits;
const char *fp_suffix;
@@ -1583,36 +1582,35 @@ struct GTY(()) lazy_hex_fp_value_struct
#define LAZY_HEX_FP_VALUES_CNT (4 * (3 + NUM_FLOATN_NX_TYPES))
static GTY(()) struct lazy_hex_fp_value_struct
lazy_hex_fp_values[LAZY_HEX_FP_VALUES_CNT];
-static GTY(()) int lazy_hex_fp_value_count;
+static GTY(()) unsigned lazy_hex_fp_value_count;
-static bool
-lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
- cpp_hashnode *node)
+static void
+lazy_hex_fp_value (cpp_reader *, cpp_macro *macro, unsigned num)
{
REAL_VALUE_TYPE real;
char dec_str[64], buf1[256];
- unsigned int idx;
- if (node->value.builtin < BT_FIRST_USER
- || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
- return false;
- idx = node->value.builtin - BT_FIRST_USER;
- real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
+ gcc_checking_assert (num < lazy_hex_fp_value_count);
+
+ real_from_string (&real, lazy_hex_fp_values[num].hex_str);
real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
- lazy_hex_fp_values[idx].digits, 0,
- lazy_hex_fp_values[idx].mode);
-
- sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
- node->flags &= ~(NODE_BUILTIN | NODE_USED);
- node->value.macro = lazy_hex_fp_values[idx].macro;
- for (idx = 0; idx < node->value.macro->count; idx++)
- if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
- break;
- gcc_assert (idx < node->value.macro->count);
- node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
- node->value.macro->exp.tokens[idx].val.str.text
- = (const unsigned char *) ggc_strdup (buf1);
- return true;
+ lazy_hex_fp_values[num].digits, 0,
+ lazy_hex_fp_values[num].mode);
+
+ size_t len
+ = sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[num].fp_suffix);
+ gcc_assert (len < sizeof (buf1));
+ for (unsigned idx = 0; idx < macro->count; idx++)
+ if (macro->exp.tokens[idx].type == CPP_NUMBER)
+ {
+ macro->exp.tokens[idx].val.str.len = len;
+ macro->exp.tokens[idx].val.str.text
+ = (const unsigned char *) ggc_strdup (buf1);
+ return;
+ }
+
+ /* We must have replaced a token. */
+ gcc_unreachable ();
}
/* Pass an object-like macro a hexadecimal floating-point value. */
@@ -1631,23 +1629,18 @@ builtin_define_with_hex_fp_value (const char *macro,
&& flag_dump_macros == 0
&& !cpp_get_options (parse_in)->traditional)
{
- struct cpp_hashnode *node;
if (lazy_hex_fp_value_count == 0)
- cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
+ cpp_get_callbacks (parse_in)->user_lazy_macro = lazy_hex_fp_value;
sprintf (buf2, fp_cast, "1.1");
sprintf (buf1, "%s=%s", macro, buf2);
cpp_define (parse_in, buf1);
- node = C_CPP_HASHNODE (get_identifier (macro));
+ struct cpp_hashnode *node = C_CPP_HASHNODE (get_identifier (macro));
lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str
= ggc_strdup (hex_str);
lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
- lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
- node->flags |= NODE_BUILTIN;
- node->value.builtin
- = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count);
- lazy_hex_fp_value_count++;
+ cpp_define_lazily (parse_in, node, lazy_hex_fp_value_count++);
return;
}