Example #1
0
void xml_short_constant(tree cst, FILE *out)
{
    size_t i;
    const char *p;
    char buf[100];
    REAL_VALUE_TYPE rt;

    switch (TREE_CODE(cst))
    {
    case REAL_CST:
        rt = TREE_REAL_CST(cst);

        if (REAL_VALUE_ISINF(rt))
            fprintf(out, "<float-literal special='%sInfinity' />",
                    REAL_VALUE_NEGATIVE(rt) ? "-" : "+");
        else if (REAL_VALUE_ISNAN(rt))
            fprintf(out, "<float-literal special='NaN' />");
        else
        {
            real_to_decimal(buf, &rt, sizeof(buf), 0, 1);
            fprintf(out, "<float-literal value='%s' />", buf);
        }
        break;

    case INTEGER_CST:
        fprintf(out, "<integer-literal value='%lld' />", double_int_to_ll(TREE_INT_CST(cst)));
        break;

    case STRING_CST:
        fprintf(out, "<string-literal>");
        p = TREE_STRING_POINTER(cst);

        for (i = 0; i < TREE_STRING_LENGTH(cst); i++)
        {
            if (p[i] == '\\')
                fputc('\\', out), fputc('\\', out);
            else if (p[i] == '&')
                fputs("&amp;", out);
            else if (p[i] == '<')
                fputs("&lt;", out);
            else if (p[i] == '>')
                fputs("&gt;", out);
            else if (ISPRINT(p[i]))
                fputc(p[i], out);
            else
                fprintf(out, "\\x%02x", p[i] & 0xFF);
        }

        fprintf(out, "</string-literal>");
        break;

    default:
        fprintf(stderr, "failing: unhandled cst tree type %s\n",
                tree_code_name[TREE_CODE(cst)]);
        abort();
    }
}
Example #2
0
static void
java_perform_atof (YYSTYPE *java_lval, char *literal_token, int fflag,
		   int number_beginning)
{
  REAL_VALUE_TYPE value;
  tree type = (fflag ? FLOAT_TYPE_NODE : DOUBLE_TYPE_NODE);

  SET_REAL_VALUE_ATOF (value,
		       REAL_VALUE_ATOF (literal_token, TYPE_MODE (type)));

  if (REAL_VALUE_ISINF (value) || REAL_VALUE_ISNAN (value))
    {
      JAVA_FLOAT_RANGE_ERROR (fflag ? "float" : "double");
      value = DCONST0;
    }
  else if (IS_ZERO (value))
    {
      /* We check to see if the value is really 0 or if we've found an
	 underflow.  We do this in the most primitive imaginable way.  */
      int really_zero = 1;
      char *p = literal_token;
      if (*p == '-')
	++p;
      while (*p && *p != 'e' && *p != 'E')
	{
	  if (*p != '0' && *p != '.')
	    {
	      really_zero = 0;
	      break;
	    }
	  ++p;
	}
      if (! really_zero)
	{
	  int save_col = ctxp->lexer->position.col;
	  ctxp->lexer->position.col = number_beginning;
	  java_lex_error ("Floating point literal underflow", 0);
	  ctxp->lexer->position.col = save_col;
	}
    }

  SET_LVAL_NODE (build_real (type, value));
}
Example #3
0
/* Interpret TOKEN, a floating point number with FLAGS as classified
   by cpplib.  */
static tree
interpret_float (const cpp_token *token, unsigned int flags)
{
  tree type;
  tree value;
  REAL_VALUE_TYPE real;
  char *copy;
  size_t copylen;
  const char *type_name;

  /* FIXME: make %T work in error/warning, then we don't need type_name.  */
  if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
    {
      type = long_double_type_node;
      type_name = "long double";
    }
  else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
	   || flag_single_precision_constant)
    {
      type = float_type_node;
      type_name = "float";
    }
  else
    {
      type = double_type_node;
      type_name = "double";
    }

  /* Copy the constant to a nul-terminated buffer.  If the constant
     has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
     can't handle them.  */
  copylen = token->val.str.len;
  if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
    /* Must be an F or L suffix.  */
    copylen--;
  if (flags & CPP_N_IMAGINARY)
    /* I or J suffix.  */
    copylen--;

  copy = (char *) alloca (copylen + 1);
  memcpy (copy, token->val.str.text, copylen);
  copy[copylen] = '\0';

  real_from_string (&real, copy);
  real_convert (&real, TYPE_MODE (type), &real);

  /* Both C and C++ require a diagnostic for a floating constant
     outside the range of representable values of its type.  Since we
     have __builtin_inf* to produce an infinity, it might now be
     appropriate for this to be a mandatory pedwarn rather than
     conditioned on -pedantic.  */
  if (REAL_VALUE_ISINF (real) && pedantic)
    pedwarn ("floating constant exceeds range of %<%s%>", type_name);

  /* Create a node with determined type and value.  */
  value = build_real (type, real);
  if (flags & CPP_N_IMAGINARY)
    value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);

  return value;
}
Example #4
0
void
print_node_brief (FILE *file, const char *prefix, const_tree node, int indent)
{
    enum tree_code_class tclass;

    if (node == 0)
        return;

    tclass = TREE_CODE_CLASS (TREE_CODE (node));

    /* Always print the slot this node is in, and its code, address and
       name if any.  */
    if (indent > 0)
        fprintf (file, " ");
    fprintf (file, "%s <%s", prefix, get_tree_code_name (TREE_CODE (node)));
    dump_addr (file, " ", node);

    if (tclass == tcc_declaration)
    {
        if (DECL_NAME (node))
            fprintf (file, " %s", IDENTIFIER_POINTER (DECL_NAME (node)));
        else if (TREE_CODE (node) == LABEL_DECL
                 && LABEL_DECL_UID (node) != -1)
        {
            if (dump_flags & TDF_NOUID)
                fprintf (file, " L.xxxx");
            else
                fprintf (file, " L.%d", (int) LABEL_DECL_UID (node));
        }
        else
        {
            if (dump_flags & TDF_NOUID)
                fprintf (file, " %c.xxxx",
                         TREE_CODE (node) == CONST_DECL ? 'C' : 'D');
            else
                fprintf (file, " %c.%u",
                         TREE_CODE (node) == CONST_DECL ? 'C' : 'D',
                         DECL_UID (node));
        }
    }
    else if (tclass == tcc_type)
    {
        if (TYPE_NAME (node))
        {
            if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
                fprintf (file, " %s", IDENTIFIER_POINTER (TYPE_NAME (node)));
            else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
                     && DECL_NAME (TYPE_NAME (node)))
                fprintf (file, " %s",
                         IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node))));
        }
        if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
            fprintf (file, " address-space-%d", TYPE_ADDR_SPACE (node));
    }
    if (TREE_CODE (node) == IDENTIFIER_NODE)
        fprintf (file, " %s", IDENTIFIER_POINTER (node));

    /* We might as well always print the value of an integer or real.  */
    if (TREE_CODE (node) == INTEGER_CST)
    {
        if (TREE_OVERFLOW (node))
            fprintf (file, " overflow");

        fprintf (file, " ");
        print_dec (node, file, TYPE_SIGN (TREE_TYPE (node)));
    }
    if (TREE_CODE (node) == REAL_CST)
    {
        REAL_VALUE_TYPE d;

        if (TREE_OVERFLOW (node))
            fprintf (file, " overflow");

        d = TREE_REAL_CST (node);
        if (REAL_VALUE_ISINF (d))
            fprintf (file,  REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
        else if (REAL_VALUE_ISNAN (d))
            fprintf (file, " Nan");
        else
        {
            char string[60];
            real_to_decimal (string, &d, sizeof (string), 0, 1);
            fprintf (file, " %s", string);
        }
    }
    if (TREE_CODE (node) == FIXED_CST)
    {
        FIXED_VALUE_TYPE f;
        char string[60];

        if (TREE_OVERFLOW (node))
            fprintf (file, " overflow");

        f = TREE_FIXED_CST (node);
        fixed_to_decimal (string, &f, sizeof (string));
        fprintf (file, " %s", string);
    }

    fprintf (file, ">");
}
Example #5
0
File: c-lex.c Project: 0mp/freebsd
/* Interpret TOKEN, a floating point number with FLAGS as classified
   by cpplib.  */
static tree
interpret_float (const cpp_token *token, unsigned int flags)
{
  tree type;
  tree value;
  REAL_VALUE_TYPE real;
  char *copy;
  size_t copylen;

  /* Default (no suffix) is double.  */
  if (flags & CPP_N_DEFAULT)
    {
      flags ^= CPP_N_DEFAULT;
      flags |= CPP_N_MEDIUM;
    }

  /* Decode type based on width and properties. */
  if (flags & CPP_N_DFLOAT)
    if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
      type = dfloat128_type_node;
    else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
      type = dfloat32_type_node;
    else
      type = dfloat64_type_node;
  else
    if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
      type = long_double_type_node;
    else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
	     || flag_single_precision_constant)
      type = float_type_node;
    else
      type = double_type_node;

  /* Copy the constant to a nul-terminated buffer.  If the constant
     has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
     can't handle them.  */
  copylen = token->val.str.len;
  if (flags & CPP_N_DFLOAT) 
    copylen -= 2;
  else 
    {
      if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
	/* Must be an F or L suffix.  */
	copylen--;
      if (flags & CPP_N_IMAGINARY)
	/* I or J suffix.  */
	copylen--;
    }

  copy = (char *) alloca (copylen + 1);
  memcpy (copy, token->val.str.text, copylen);
  copy[copylen] = '\0';

  real_from_string3 (&real, copy, TYPE_MODE (type));

  /* Both C and C++ require a diagnostic for a floating constant
     outside the range of representable values of its type.  Since we
     have __builtin_inf* to produce an infinity, it might now be
     appropriate for this to be a mandatory pedwarn rather than
     conditioned on -pedantic.  */
  if (REAL_VALUE_ISINF (real) && pedantic)
    pedwarn ("floating constant exceeds range of %qT", type);

  /* Create a node with determined type and value.  */
  value = build_real (type, real);
  if (flags & CPP_N_IMAGINARY)
    value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);

  return value;
}