parent
d947191450
commit
b7d649c34e
95
epp/cppexp.c
95
epp/cppexp.c
|
@ -138,10 +138,10 @@ struct operation
|
||||||
|
|
||||||
/* maybe needs to actually deal with floating point numbers */
|
/* maybe needs to actually deal with floating point numbers */
|
||||||
|
|
||||||
static struct operation
|
static void
|
||||||
parse_number(cpp_reader * pfile, const char *start, int olen)
|
parse_number(struct operation *op, cpp_reader * pfile, const char *start,
|
||||||
|
int olen)
|
||||||
{
|
{
|
||||||
struct operation op;
|
|
||||||
const char *p = start;
|
const char *p = start;
|
||||||
int c;
|
int c;
|
||||||
unsigned long n = 0, nd, ULONG_MAX_over_base;
|
unsigned long n = 0, nd, ULONG_MAX_over_base;
|
||||||
|
@ -151,7 +151,7 @@ parse_number(cpp_reader * pfile, const char *start, int olen)
|
||||||
int digit, largest_digit = 0;
|
int digit, largest_digit = 0;
|
||||||
int spec_long = 0;
|
int spec_long = 0;
|
||||||
|
|
||||||
op.unsignedp = 0;
|
op->unsignedp = 0;
|
||||||
|
|
||||||
for (c = 0; c < len; c++)
|
for (c = 0; c < len; c++)
|
||||||
if (p[c] == '.')
|
if (p[c] == '.')
|
||||||
|
@ -159,8 +159,8 @@ parse_number(cpp_reader * pfile, const char *start, int olen)
|
||||||
/* It's a float since it contains a point. */
|
/* It's a float since it contains a point. */
|
||||||
cpp_error(pfile,
|
cpp_error(pfile,
|
||||||
"floating point numbers not allowed in #if expressions");
|
"floating point numbers not allowed in #if expressions");
|
||||||
op.op = ERROR;
|
op->op = ERROR;
|
||||||
return op;
|
return;
|
||||||
}
|
}
|
||||||
if (len >= 3 && (!strncmp(p, "0x", 2) || !strncmp(p, "0X", 2)))
|
if (len >= 3 && (!strncmp(p, "0x", 2) || !strncmp(p, "0X", 2)))
|
||||||
{
|
{
|
||||||
|
@ -197,9 +197,9 @@ parse_number(cpp_reader * pfile, const char *start, int olen)
|
||||||
}
|
}
|
||||||
else if (c == 'u' || c == 'U')
|
else if (c == 'u' || c == 'U')
|
||||||
{
|
{
|
||||||
if (op.unsignedp)
|
if (op->unsignedp)
|
||||||
cpp_error(pfile, "two `u's in integer constant");
|
cpp_error(pfile, "two `u's in integer constant");
|
||||||
op.unsignedp = 1;
|
op->unsignedp = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
@ -221,8 +221,8 @@ parse_number(cpp_reader * pfile, const char *start, int olen)
|
||||||
if (len != 0)
|
if (len != 0)
|
||||||
{
|
{
|
||||||
cpp_error(pfile, "Invalid number in #if expression");
|
cpp_error(pfile, "Invalid number in #if expression");
|
||||||
op.op = ERROR;
|
op->op = ERROR;
|
||||||
return op;
|
return;
|
||||||
}
|
}
|
||||||
if (base <= largest_digit)
|
if (base <= largest_digit)
|
||||||
cpp_warning(pfile, "integer constant contains digits beyond the radix");
|
cpp_warning(pfile, "integer constant contains digits beyond the radix");
|
||||||
|
@ -231,16 +231,15 @@ parse_number(cpp_reader * pfile, const char *start, int olen)
|
||||||
cpp_warning(pfile, "integer constant out of range");
|
cpp_warning(pfile, "integer constant out of range");
|
||||||
|
|
||||||
/* If too big to be signed, consider it unsigned. */
|
/* If too big to be signed, consider it unsigned. */
|
||||||
if ((long)n < 0 && !op.unsignedp)
|
if ((long)n < 0 && !op->unsignedp)
|
||||||
{
|
{
|
||||||
if (base == 10)
|
if (base == 10)
|
||||||
cpp_warning(pfile,
|
cpp_warning(pfile,
|
||||||
"integer constant is so large that it is unsigned");
|
"integer constant is so large that it is unsigned");
|
||||||
op.unsignedp = 1;
|
op->unsignedp = 1;
|
||||||
}
|
}
|
||||||
op.value = n;
|
op->value = n;
|
||||||
op.op = INT;
|
op->op = INT;
|
||||||
return op;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct token
|
struct token
|
||||||
|
@ -265,18 +264,17 @@ static struct token tokentab2[] = {
|
||||||
|
|
||||||
/* Read one token. */
|
/* Read one token. */
|
||||||
|
|
||||||
static struct operation
|
static void
|
||||||
cpp_lex(cpp_reader * pfile)
|
cpp_lex(struct operation *op, cpp_reader * pfile)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
struct token *toktab;
|
struct token *toktab;
|
||||||
enum cpp_token token;
|
enum cpp_token token;
|
||||||
struct operation op;
|
|
||||||
unsigned char *tok_start, *tok_end;
|
unsigned char *tok_start, *tok_end;
|
||||||
int old_written;
|
int old_written;
|
||||||
|
|
||||||
op.value = 0;
|
op->value = 0;
|
||||||
op.unsignedp = 0;
|
op->unsignedp = 0;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
|
|
||||||
|
@ -284,13 +282,15 @@ cpp_lex(cpp_reader * pfile)
|
||||||
cpp_skip_hspace(pfile);
|
cpp_skip_hspace(pfile);
|
||||||
c = CPP_BUF_PEEK(CPP_BUFFER(pfile));
|
c = CPP_BUF_PEEK(CPP_BUFFER(pfile));
|
||||||
if (c == '#')
|
if (c == '#')
|
||||||
return parse_number(pfile,
|
{
|
||||||
cpp_read_check_assertion(pfile) ? "1" : "0", 1);
|
parse_number(op, pfile, cpp_read_check_assertion(pfile) ? "1" : "0", 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
{
|
{
|
||||||
op.op = 0;
|
op->op = 0;
|
||||||
return op;
|
return;
|
||||||
}
|
}
|
||||||
token = cpp_get_token(pfile);
|
token = cpp_get_token(pfile);
|
||||||
tok_start = pfile->token_buffer + old_written;
|
tok_start = pfile->token_buffer + old_written;
|
||||||
|
@ -299,25 +299,31 @@ cpp_lex(cpp_reader * pfile)
|
||||||
switch (token)
|
switch (token)
|
||||||
{
|
{
|
||||||
case CPP_EOF: /* Should not happen ... */
|
case CPP_EOF: /* Should not happen ... */
|
||||||
op.op = 0;
|
op->op = 0;
|
||||||
return op;
|
break;
|
||||||
|
|
||||||
case CPP_VSPACE:
|
case CPP_VSPACE:
|
||||||
case CPP_POP:
|
case CPP_POP:
|
||||||
if (CPP_BUFFER(pfile)->fname != NULL)
|
if (CPP_BUFFER(pfile)->fname != NULL)
|
||||||
{
|
{
|
||||||
op.op = 0;
|
op->op = 0;
|
||||||
return op;
|
break;
|
||||||
}
|
}
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
||||||
case CPP_HSPACE:
|
case CPP_HSPACE:
|
||||||
case CPP_COMMENT:
|
case CPP_COMMENT:
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
||||||
case CPP_NUMBER:
|
case CPP_NUMBER:
|
||||||
return parse_number(pfile, (char *)tok_start, tok_end - tok_start);
|
parse_number(op, pfile, (char *)tok_start, tok_end - tok_start);
|
||||||
|
break;
|
||||||
|
|
||||||
case CPP_STRING:
|
case CPP_STRING:
|
||||||
cpp_error(pfile, "string constants not allowed in #if expressions");
|
cpp_error(pfile, "string constants not allowed in #if expressions");
|
||||||
op.op = ERROR;
|
op->op = ERROR;
|
||||||
return op;
|
break;
|
||||||
|
|
||||||
case CPP_CHAR:
|
case CPP_CHAR:
|
||||||
/* This code for reading a character constant
|
/* This code for reading a character constant
|
||||||
* handles multicharacter constants and wide characters.
|
* handles multicharacter constants and wide characters.
|
||||||
|
@ -402,12 +408,11 @@ cpp_lex(cpp_reader * pfile)
|
||||||
if (cpp_lookup("__CHAR_UNSIGNED__",
|
if (cpp_lookup("__CHAR_UNSIGNED__",
|
||||||
sizeof("__CHAR_UNSIGNED__") - 1, -1)
|
sizeof("__CHAR_UNSIGNED__") - 1, -1)
|
||||||
|| ((result >> (num_bits - 1)) & 1) == 0)
|
|| ((result >> (num_bits - 1)) & 1) == 0)
|
||||||
op.value
|
op->value =
|
||||||
=
|
|
||||||
result & ((unsigned long)~0 >>
|
result & ((unsigned long)~0 >>
|
||||||
(HOST_BITS_PER_LONG - num_bits));
|
(HOST_BITS_PER_LONG - num_bits));
|
||||||
else
|
else
|
||||||
op.value =
|
op->value =
|
||||||
result | ~((unsigned long)~0 >>
|
result | ~((unsigned long)~0 >>
|
||||||
(HOST_BITS_PER_LONG - num_bits));
|
(HOST_BITS_PER_LONG - num_bits));
|
||||||
}
|
}
|
||||||
|
@ -431,18 +436,18 @@ cpp_lex(cpp_reader * pfile)
|
||||||
"Ignoring invalid multibyte character");
|
"Ignoring invalid multibyte character");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
op.value = result;
|
op->value = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is always a signed type. */
|
/* This is always a signed type. */
|
||||||
op.unsignedp = 0;
|
op->unsignedp = 0;
|
||||||
op.op = CHAR;
|
op->op = CHAR;
|
||||||
|
break;
|
||||||
return op;
|
|
||||||
|
|
||||||
case CPP_NAME:
|
case CPP_NAME:
|
||||||
return parse_number(pfile, "0", 0);
|
parse_number(op, pfile, "0", 0);
|
||||||
|
break;
|
||||||
|
|
||||||
case CPP_OTHER:
|
case CPP_OTHER:
|
||||||
/* See if it is a special token of length 2. */
|
/* See if it is a special token of length 2. */
|
||||||
|
@ -463,13 +468,13 @@ cpp_lex(cpp_reader * pfile)
|
||||||
cpp_error(pfile, buf);
|
cpp_error(pfile, buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
op.op = toktab->token;
|
op->op = toktab->token;
|
||||||
return op;
|
break;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
default:
|
default:
|
||||||
op.op = *tok_start;
|
op->op = *tok_start;
|
||||||
return op;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +691,7 @@ cpp_parse_expr(cpp_reader * pfile)
|
||||||
char flags = 0;
|
char flags = 0;
|
||||||
|
|
||||||
/* Read a token */
|
/* Read a token */
|
||||||
op = cpp_lex(pfile);
|
cpp_lex(&op, pfile);
|
||||||
|
|
||||||
/* See if the token is an operand, in which case go to set_value.
|
/* See if the token is an operand, in which case go to set_value.
|
||||||
* If the token is an operator, figure out its left and right
|
* If the token is an operator, figure out its left and right
|
||||||
|
|
26
epp/cpplib.c
26
epp/cpplib.c
|
@ -1510,9 +1510,9 @@ static char rest_extension[] = "...";
|
||||||
|
|
||||||
/* Create a DEFINITION node from a #define directive. Arguments are
|
/* Create a DEFINITION node from a #define directive. Arguments are
|
||||||
* as for do_define. */
|
* as for do_define. */
|
||||||
static MACRODEF
|
static void
|
||||||
create_definition(unsigned char *buf, unsigned char *limit, cpp_reader * pfile,
|
create_definition(MACRODEF * mdef, unsigned char *buf, unsigned char *limit,
|
||||||
int predefinition)
|
cpp_reader * pfile, int predefinition)
|
||||||
{
|
{
|
||||||
unsigned char *bp; /* temp ptr into input buffer */
|
unsigned char *bp; /* temp ptr into input buffer */
|
||||||
unsigned char *symname; /* remember where symbol name starts */
|
unsigned char *symname; /* remember where symbol name starts */
|
||||||
|
@ -1524,7 +1524,6 @@ create_definition(unsigned char *buf, unsigned char *limit, cpp_reader * pfile,
|
||||||
DEFINITION *defn;
|
DEFINITION *defn;
|
||||||
int arglengths = 0; /* Accumulate lengths of arg names
|
int arglengths = 0; /* Accumulate lengths of arg names
|
||||||
* plus number of args. */
|
* plus number of args. */
|
||||||
MACRODEF mdef;
|
|
||||||
|
|
||||||
cpp_buf_line_and_col(CPP_BUFFER(pfile), &line, &col);
|
cpp_buf_line_and_col(CPP_BUFFER(pfile), &line, &col);
|
||||||
|
|
||||||
|
@ -1718,15 +1717,14 @@ create_definition(unsigned char *buf, unsigned char *limit, cpp_reader * pfile,
|
||||||
|
|
||||||
/* OP is null if this is a predefinition */
|
/* OP is null if this is a predefinition */
|
||||||
defn->predefined = predefinition;
|
defn->predefined = predefinition;
|
||||||
mdef.defn = defn;
|
mdef->defn = defn;
|
||||||
mdef.symnam = (char *)symname;
|
mdef->symnam = (char *)symname;
|
||||||
mdef.symlen = sym_length;
|
mdef->symlen = sym_length;
|
||||||
|
|
||||||
return mdef;
|
return;
|
||||||
|
|
||||||
nope:
|
nope:
|
||||||
mdef.defn = 0;
|
mdef->defn = 0;
|
||||||
return mdef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check a purported macro name SYMNAME, and yield its length.
|
/* Check a purported macro name SYMNAME, and yield its length.
|
||||||
|
@ -1863,9 +1861,9 @@ do_define(cpp_reader * pfile, struct directive *keyword,
|
||||||
MACRODEF mdef;
|
MACRODEF mdef;
|
||||||
HASHNODE *hp;
|
HASHNODE *hp;
|
||||||
|
|
||||||
mdef = create_definition(buf, limit, pfile, keyword == NULL);
|
create_definition(&mdef, buf, limit, pfile, keyword == NULL);
|
||||||
if (mdef.defn == 0)
|
if (mdef.defn == 0)
|
||||||
goto nope;
|
return 1;
|
||||||
|
|
||||||
hashcode = hashf(mdef.symnam, mdef.symlen, HASHSIZE);
|
hashcode = hashf(mdef.symnam, mdef.symlen, HASHSIZE);
|
||||||
|
|
||||||
|
@ -1918,10 +1916,6 @@ do_define(cpp_reader * pfile, struct directive *keyword,
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
nope:
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This structure represents one parsed argument in a macro call.
|
/* This structure represents one parsed argument in a macro call.
|
||||||
|
|
Loading…
Reference in New Issue