diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-06-09 20:45:19 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-06-09 20:45:19 -0700 |
commit | 11627049aec88e21b6a9cbdef10984868d4ca3fe (patch) | |
tree | 1d6a223214cc0425ea11d3e2314b68d4030c2db6 /preproc.c | |
parent | fcb8909749b2a159ba7f32fec7df8e465a974f77 (diff) | |
download | nasm-11627049aec88e21b6a9cbdef10984868d4ca3fe.tar.gz nasm-11627049aec88e21b6a9cbdef10984868d4ca3fe.tar.bz2 nasm-11627049aec88e21b6a9cbdef10984868d4ca3fe.zip |
Make strings a first-class token type; defer evaluation
Make strings a proper, first-class token type, instead of relying on
the "TOKEN_NUM with tv_charptr" hack. Only convert a string to a
number if requested in an expression context; this also makes it
possible to actually issue a warning when it overflows.
Diffstat (limited to 'preproc.c')
-rw-r--r-- | preproc.c | 27 |
1 files changed, 10 insertions, 17 deletions
@@ -1134,10 +1134,11 @@ static int ppscan(void *private_data, struct tokenval *tokval) if (tline->type == TOK_NUMBER) { bool rn_error; tokval->t_integer = readnum(tline->text, &rn_error); - if (rn_error) - return tokval->t_type = TOKEN_ERRNUM; /* some malformation occurred */ tokval->t_charptr = tline->text; - return tokval->t_type = TOKEN_NUM; + if (rn_error) + return tokval->t_type = TOKEN_ERRNUM; + else + return tokval->t_type = TOKEN_NUM; } if (tline->type == TOK_FLOAT) { @@ -1146,23 +1147,15 @@ static int ppscan(void *private_data, struct tokenval *tokval) if (tline->type == TOK_STRING) { char bq, *ep; - bool errquote; - bool rn_warn; - size_t l; bq = tline->text[0]; - l = nasm_unquote(tline->text, &ep); - if (ep[0] != bq || ep[1] != '\0') - errquote = true; + tokval->t_charptr = tline->text; + tokval->t_inttwo = nasm_unquote(tline->text, &ep); - if (errquote) - return tokval->t_type = TOKEN_ERRNUM; - - tokval->t_integer = readstrnum(tline->text, l, &rn_warn); - if (rn_warn) - error(ERR_WARNING | ERR_PASS1, "character constant too long"); - tokval->t_charptr = NULL; - return tokval->t_type = TOKEN_NUM; + if (ep[0] != bq || ep[1] != '\0') + return tokval->t_type = TOKEN_ERRSTR; + else + return tokval->t_type = TOKEN_STR; } if (tline->type == TOK_OTHER) { |