⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctree.cc

📁 c到DHL的转换工具
💻 CC
📖 第 1 页 / 共 5 页
字号:
        if (num_matches > N())          {            error_line(1, NULL,                       "format for `%s' generic op requires %d operands, but "                       "it is used with %d", leafval.s, num_matches, N());          }        int match_num = 0;        for (follow = format_string; *follow != 0; ++follow)          {            if (*follow == '%')              {                ++follow;                switch (*follow)                  {                    case '%':                        out->io_putc('%');                        break;                    case 'a':                        child(match_num)->print_as_c(out, nindent);                        ++match_num;                        break;                    case 'n':                      {                        ++follow;                        char *begin_sep = follow;                        for (; *follow != 0; ++follow)                          {                            if (*follow == '%')                              {                                ++follow;                                if (*follow != '%')                                    break;                              }                          }                        if (*follow != 'm')                          {                            error_line(1, NULL,                                       "badly formed ``%%n'' directive in "                                       "format for generic op `%s'",                                       leafval.s);                          }                        int max_child = N() - (num_matches - match_num);                        while (match_num < max_child)                          {                            child(match_num)->print_as_c(out, nindent);                            ++match_num;                            if (match_num < max_child)                              {                                for (char *sep = begin_sep; sep < follow - 1;                                     ++sep)                                  {                                    out->io_putc(*sep);                                    if (*sep == '%')                                        ++sep;                                  }                              }                          }                        break;                      }                    default:                        error_line(1, NULL,                                   "illegal escape sequence `%%%c' in format"                                   " string for `%s'", *follow, leafval.s);                  }              }            else              {                out->io_putc(*follow);              }          }        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;      }    case ctree_funcdecl:      {        proc_sym *psym = (proc_sym *)leafval.y;        out->printf("%s", make_c_proc_prototype(psym));        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;      }    case ctree_vardecl:      {        var_sym *the_var = (var_sym *)leafval.y;        assert(the_var->is_global() && (!the_var->is_private()));        out->printf("extern ");        out->printf("%s", make_c_sym_type(the_var));        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;      }    case ctree_vardef:      {        var_sym *the_var = (var_sym *)leafval.y;        if (((!the_var->is_global()) && (!the_var->is_auto())) ||            (the_var->is_global() && the_var->is_private()))          {            out->printf("static ");          }        out->printf("%s", make_c_sym_type(the_var));        if (N()) {            assert(N() == 1);            out->printf(" =");            if (child(0)->op != ctree_block)                out->printf(" ");            child(0)->print_as_c(out, nindent);        }        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;      }    case ctree_typedecl: {        type_node *t = leafval.t;        if (t->op() == TYPE_ENUM) {            enum_type *et = (enum_type *) t;            out->printf("enum %s { ", et->name());            for (unsigned value_num=0; value_num<et->num_values();                 value_num++) {                if (value_num > 0)                    out->printf(", ");                out->printf("%s", et->member(value_num));                if (((value_num > 0) &&                     (et->value(value_num) !=                      (et->value(value_num - 1) + 1))) ||                    ((value_num == 0) && (et->value(value_num) != 0)))                  {                    out->printf(" = %d", et->value(value_num));                  }            }            out->printf(" }");        } else if ((t->op() == TYPE_GROUP) || (t->op() == TYPE_STRUCT) ||                   (t->op() == TYPE_UNION)) {            struct_type *st = (struct_type *) t;            print_struct_with_fields(st, out, nindent);        }        if (comments != NULL)            in_line_output_comments(out, 1, 1);        break;    }    case ctree_typeforward: {        type_node *t = leafval.t;        assert((t->op() == TYPE_GROUP) || (t->op() == TYPE_STRUCT) ||               (t->op() == TYPE_UNION));        struct_type *st = (struct_type *) t;        print_struct_short(st, out);        if (comments != NULL)            in_line_output_comments(out, 1, 1);        break;    }    case ctree_goto:        out->printf("goto %s", leafval.y->name());        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;    case ctree_break:        out->printf("break");        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;    case ctree_continue:        out->printf("continue");        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;    case ctree_return:        out->printf("return");        if (N()) {            out->printf(" ");            child(0)->print_as_c(out, nindent);        }        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;    case ctree_label:        out->printf("%s:", leafval.y->name());        if (comments != NULL)            in_line_output_comments(out, 1, 0);        return;    case ctree_case:        out->printf("case ");        out->print_ii(integer_val());        out->printf(":");        if (comments != NULL)            in_line_output_comments(out, 1, 0);        return;    case ctree_default:        out->printf("default:");        if (comments != NULL)            in_line_output_comments(out, 1, 0);        return;    case ctree_semi:        for (i=0; i<N(); i++) {            ctree_op cop = child(i)->op;            int indent_amount = nindent;            if ((cop == ctree_label) || (cop == ctree_case) ||                (cop == ctree_default))              {                indent_amount = indent_amount + c_style.label_indent;                indent_amount = ((indent_amount > 0) ? indent_amount : 0);              }            if ((cop != ctree_block) && (cop != ctree_blank_line) &&                (cop != ctree_pound_line))              {                ctree_indent(out, indent_amount);              }            child(i)->print_as_c(out, nindent);            if ((((cop != ctree_if) && (cop != ctree_for) &&                  (cop != ctree_switch)) ||                 (child(i)->child(child(i)->N() - 1)->op != ctree_block)) &&                (cop != ctree_funcdef) && (cop != ctree_block) &&                (cop != ctree_blank_line) && (cop != ctree_pound_line) &&                (((cop != ctree_label) && (cop != ctree_case) &&                  (cop != ctree_default)) || remainder_is_blanks(i + 1))) {                out->printf("%s\n", ctree_oper_attr[op].sym);            } else if ((cop != ctree_blank_line) &&                       (cop != ctree_pound_line)) {                out->printf("\n");            }            if ((i == 0) && (comments != NULL))                full_line_output_comments(out, nindent);            if ((cop == ctree_vardecl || cop == ctree_vardef ||                 cop == ctree_funcdecl || cop == ctree_funcdef ||                 cop == ctree_typedecl || cop == ctree_typeforward ||                 cop == ctree_block) &&                i < N()-1 && child(i+1)->op != cop &&                child(i+1)->op != ctree_block)              {                out->printf("\n");              }        }        return;        /* Nested scope */    case ctree_block:      {        if (c_style.new_line_for_open_brace)          {            out->printf("\n");            ctree_indent(out, nindent + c_style.brace_indent);          }        else          {            out->printf(" ");          }        out->printf("{");        int new_indent = nindent + c_style.statement_indent;        if (comments != NULL)            in_line_output_comments(out, 2, 0);        if (child(0)->getop() == ctree_comma)          {            boolean contains_block = FALSE;            for (i=0; i<child(0)->N(); i++)              {                if (child(0)->child(i)->op == ctree_block)                  {                    contains_block = TRUE;                    break;                  }              }            int mod = 0;            for (i=0; i<child(0)->N(); i++)              {                if (!contains_block)                  {                    if (i == 0)                      {                        out->printf("\n");                        ctree_indent(out, new_indent);                      }                    else if (mod == c_style.max_comma_items_per_line)                      {                        out->printf("\n");                        ctree_indent(out, new_indent);                        mod = 0;                      }                    else                      {                        out->printf(" ");                      }                  }                else if (child(0)->child(i)->op != ctree_block)                  {                    out->printf("\n");                    ctree_indent(out, new_indent);                  }                child(0)->child(i)->print_as_c(out, new_indent);                if (i < child(0)->N() - 1)                    out->printf("%s", ctree_oper_attr[ctree_comma].sym);                ++mod;              }            out->printf("\n");          }        else          {            if (child(0)->op != ctree_block)                out->printf("\n");            child(0)->print_as_c(out, new_indent);            if (child(0)->op == ctree_block)                out->printf("\n");          }        ctree_indent(out, nindent + c_style.brace_indent);        out->printf("}");        return;      }        /* FOR statement */    case ctree_for: {        assert(N() == 4);        out->printf("for (");        child(0)->print_as_c(out, nindent);        out->printf("; ");        child(1)->print_as_c(out, nindent);        out->printf("; ");        child(2)->print_as_c(out, nindent);        out->printf(")");        if (comments != NULL)            in_line_output_comments(out, 1, 0);        child(3)->print_as_body(out, nindent);        return;    }        /* IF statement */    case ctree_if: {        assert(N() == 2 || N() == 3);        out->printf("if (");        child(0)->print_as_c(out, nindent);        out->printf(")");        if (comments != NULL)            in_line_output_comments(out, 1, 0);        child(1)->print_as_body(out, nindent);        if (N() == 3)          {            if (c_style.new_line_for_else)              {                out->printf("\n");                ctree_indent(out, nindent);              }            else              {                out->printf(" ");              }            out->printf("else");            child(2)->print_as_body(out, nindent);          }        return;    }        /* DO...WHILE statement */    case ctree_do:        assert(N() == 2);        out->printf("do");        if (comments != NULL)            in_line_output_comments(out, 1, 0);        child(0)->print_as_body(out, nindent);        out->printf(" ");        out->printf("while (");        child(1)->print_as_c(out, nindent);        out->printf(")");        return;        /* SWITCH statement */    case ctree_switch:        assert(N() == 2);        out->printf("switch (");        child(0)->print_as_c(out, nindent);        out->printf(")");        if (comments != NULL)            in_line_output_comments(out, 1, 0);        child(1)->print_as_body(out, nindent);        return;        /* Function call */    case ctree_funcall:        child(0)->print_with_prec(out, nindent, op, TRUE);        out->printf("(");        for (i=1; i<N(); i++) {            child(i)->print_as_c(out, nindent);            if (i != N()-1)                out->printf(", ");        }        out->printf(")");        if (comments != NULL)            in_line_output_comments(out, 1, 1);        return;        /* Various constants */    case ctree_intconst:      {        assert(type->op() == TYPE_INT);        base_type *the_base = (base_type *)type;        enum C_types the_c_type = c_int_type(the_base);        assert((integer_val() >= 0) || always_intnum);        out->print_ii(integer_val());        if ((the_c_type == C_int) || always_intnum)          {            if (!the_base->is_signed())                out->printf("u");          }        else if (the_c_type == C_long)          {            if (the_base->is_signed())                out->printf("l");            else                out->printf("ul");          }        else if (the_c_type == C_longlong)          {            assert(ll_suffix);            if (the_base->is_signed())                out->printf("ll");            else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -