示例#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();
    }
}
示例#2
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, ">");
}