C-sparse
view release on metacpan or search on metacpan
src/sparse-0.4.4/expression.c view on Meta::CPAN
if (value & (~1ULL << bits))
goto Eoverflow;
if (!(value & (1ULL << bits)))
goto got_it;
if (!try_unsigned)
warning(sctx_ expr->pos->pos, "decimal constant %s is too big for long long",
show_token(sctx_ token));
want_unsigned = 1;
got_it:
if (do_warn)
warning(sctx_ expr->pos->pos, "constant %s is so big it is%s%s%s",
show_token(sctx_ token),
want_unsigned ? " unsigned":"",
size > 0 ? " long":"",
size > 1 ? " long":"");
if (do_warn & 2)
warning(sctx_ expr->pos->pos,
"decimal constant %s is between LONG_MAX and ULONG_MAX."
" For C99 that means long long, C90 compilers are very "
"likely to produce unsigned long (and a warning) here",
show_token(sctx_ token));
expr->type = EXPR_VALUE;
expr->flags = Int_const_expr;
expr->ctype = ctype_integer(sctx_ size, want_unsigned);
expr->value = value;
return;
Eoverflow:
error_die(sctx_ expr->pos->pos, "constant %s is too big even for unsigned long long",
show_token(sctx_ token));
return;
Float:
expr->fvalue = string_to_ld(sctx_ str, &end);
if (str == end)
goto Enoint;
if (*end && end[1])
goto Enoint;
if (*end == 'f' || *end == 'F')
expr->ctype = &sctxp float_ctype;
else if (*end == 'l' || *end == 'L')
expr->ctype = &sctxp ldouble_ctype;
else if (!*end)
expr->ctype = &sctxp double_ctype;
else
goto Enoint;
expr->flags = Float_literal;
expr->type = EXPR_FVALUE;
return;
Enoint:
error_die(sctx_ expr->pos->pos, "constant %s is not a valid number", show_token(sctx_ token));
}
struct token *primary_expression(SCTX_ struct token *token, struct expression **tree)
{
struct expression *expr = NULL;
switch (token_type(token)) {
case TOKEN_CHAR ... TOKEN_WIDE_CHAR_EMBEDDED_3:
expr = alloc_expression(sctx_ token, EXPR_VALUE);
expr->flags = Int_const_expr;
expr->ctype = token_type(token) < TOKEN_WIDE_CHAR ? &sctxp int_ctype : &sctxp long_ctype;
get_char_constant(sctx_ token, &expr->value);
token = token->next;
break;
case TOKEN_NUMBER:
expr = alloc_expression(sctx_ token, EXPR_VALUE);
get_number_value(sctx_ expr, token); /* will see if it's an integer */
token = token->next;
break;
case TOKEN_ZERO_IDENT: {
expr = alloc_expression(sctx_ token, EXPR_SYMBOL);
expr->flags = Int_const_expr;
expr->ctype = &sctxp int_ctype;
expr->symbol = &sctxp zero_int;
expr->symbol_name = token->ident;
token = token->next;
break;
}
case TOKEN_IDENT: {
struct symbol *sym = lookup_symbol(sctx_ token->ident, NS_SYMBOL | NS_TYPEDEF);
struct token *next = token->next;
if (!sym) {
sym = handle_func(sctx_ token);
if (token->ident == (struct ident *)&sctxp __builtin_types_compatible_p_ident) {
token = builtin_types_compatible_p_expr(sctx_ token, &expr);
break;
}
if (token->ident == (struct ident *)&sctxp __builtin_offsetof_ident) {
token = builtin_offsetof_expr(sctx_ token, &expr);
break;
}
} else if (sym->enum_member) {
expr = alloc_expression(sctx_ token, EXPR_VALUE);
*expr = *sym->initializer;
/* we want the right position reported, thus the copy */
expr->pos = token;
expr->flags = Int_const_expr;
token = next;
break;
}
expr = alloc_expression(sctx_ token, EXPR_SYMBOL);
/*
* We support types as real first-class citizens, with type
* comparisons etc:
*
* if (typeof(a) == int) ..
*/
if (sym && sym->namespace == NS_TYPEDEF) {
sparse_error(sctx_ token->pos, "typename in expression");
sym = NULL;
}
expr->symbol_name = token->ident;
( run in 1.219 second using v1.01-cache-2.11-cpan-71847e10f99 )