📄 error.c
字号:
OB_PUTCP (input_filename); OB_PUTC (')');}static voiddump_decl (t, v) tree t; int v; /* verbosity */{ if (t == NULL_TREE) return; switch (TREE_CODE (t)) { case ERROR_MARK: OB_PUTS (" /* decl error */ "); break; case TYPE_DECL: { /* Don't say 'typedef class A' */ if (DECL_ARTIFICIAL (t)) { dump_type (TREE_TYPE (t), v); break; } } if (v > 0) OB_PUTS ("typedef "); goto general; break; case VAR_DECL: if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t))) { OB_PUTS ("vtable for "); dump_type (DECL_CONTEXT (t), v); break; } /* else fall through */ case FIELD_DECL: case PARM_DECL: general: if (v > 0) { dump_type_prefix (TREE_TYPE (t), v); OB_PUTC (' '); dump_readonly_or_volatile (t, after); } /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */ if (DECL_CONTEXT (t) && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't') { dump_type (DECL_CONTEXT (t), 0); OB_PUTC2 (':', ':'); } if (DECL_NAME (t)) dump_decl (DECL_NAME (t), v); else OB_PUTS ("{anon}"); if (v > 0) dump_type_suffix (TREE_TYPE (t), v); break; case NAMESPACE_DECL: OB_PUTID (DECL_NAME (t)); break; case ARRAY_REF: dump_decl (TREE_OPERAND (t, 0), v); OB_PUTC ('['); dump_decl (TREE_OPERAND (t, 1), v); OB_PUTC (']'); break; /* So that we can do dump_decl in dump_aggr_type and have it work for both class and function scope. */ case RECORD_TYPE: case UNION_TYPE: case ENUMERAL_TYPE: dump_type (t, v); break; case TYPE_EXPR: my_friendly_abort (69); break; /* These special cases are duplicated here so that other functions can feed identifiers to cp_error and get them demangled properly. */ case IDENTIFIER_NODE: { tree f; if (DESTRUCTOR_NAME_P (t) && (f = ident_fndecl (t)) && DECL_LANGUAGE (f) == lang_cplusplus) { OB_PUTC ('~'); dump_decl (DECL_NAME (f), 0); } else if (IDENTIFIER_TYPENAME_P (t)) { OB_PUTS ("operator "); /* Not exactly IDENTIFIER_TYPE_VALUE. */ dump_type (TREE_TYPE (t), 0); break; } else if (IDENTIFIER_OPNAME_P (t)) { char *name_string = operator_name_string (t); OB_PUTS ("operator "); OB_PUTCP (name_string); } else OB_PUTID (t); } break; case FUNCTION_DECL: if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t))) dump_global_iord (DECL_ASSEMBLER_NAME (t)); else if (! DECL_LANG_SPECIFIC (t)) OB_PUTS ("{internal}"); else dump_function_decl (t, v); break; case TEMPLATE_DECL: { tree orig_args = DECL_TEMPLATE_PARMS (t); tree args; int i; for (args = orig_args = nreverse (orig_args); args; args = TREE_CHAIN (args)) { int len = TREE_VEC_LENGTH (TREE_VALUE (args)); OB_PUTS ("template <"); for (i = 0; i < len; i++) { tree arg = TREE_VEC_ELT (TREE_VALUE (args), i); tree defval = TREE_PURPOSE (arg); arg = TREE_VALUE (arg); if (TREE_CODE (arg) == TYPE_DECL) { OB_PUTS ("class "); OB_PUTID (DECL_NAME (arg)); } else dump_decl (arg, 1); if (defval) { OB_PUTS (" = "); dump_decl (defval, 1); } OB_PUTC2 (',', ' '); } if (len != 0) OB_UNPUT (2); OB_PUTC2 ('>', ' '); } nreverse(orig_args); if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL) dump_type (TREE_TYPE (t), v); else if (TREE_TYPE (t) == NULL_TREE) my_friendly_abort (353); else switch (NEXT_CODE (t)) { case METHOD_TYPE: case FUNCTION_TYPE: dump_function_decl (t, v); break; default: my_friendly_abort (353); } } break; case LABEL_DECL: OB_PUTID (DECL_NAME (t)); break; case CONST_DECL: if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE) || (DECL_INITIAL (t) && TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM)) goto general; else if (DECL_INITIAL (t)) dump_expr (DECL_INITIAL (t), 0); else OB_PUTS ("enumerator"); break; case USING_DECL: OB_PUTS ("using "); dump_type (DECL_INITIAL (t), 0); OB_PUTS ("::"); OB_PUTID (DECL_NAME (t)); break; default: sorry ("`%s' not supported by dump_decl", tree_code_name[(int) TREE_CODE (t)]); }}/* Pretty printing for announce_function. T is the declaration of the function we are interested in seeing. V is non-zero if we should print the type that this function returns. */static voiddump_function_decl (t, v) tree t; int v;{ tree name; tree fntype; tree parmtypes; tree cname = NULL_TREE; if (TREE_CODE (t) == TEMPLATE_DECL) t = DECL_TEMPLATE_RESULT (t); name = DECL_ASSEMBLER_NAME (t); fntype = TREE_TYPE (t); parmtypes = TYPE_ARG_TYPES (fntype); /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */ if (DECL_CONTEXT (t)) cname = DECL_CLASS_CONTEXT (t); /* this is for partially instantiated template methods */ else if (TREE_CODE (fntype) == METHOD_TYPE) cname = TREE_TYPE (TREE_VALUE (parmtypes)); v = (v > 0); if (v) { if (DECL_STATIC_FUNCTION_P (t)) OB_PUTS ("static "); if (! IDENTIFIER_TYPENAME_P (name) && ! DECL_CONSTRUCTOR_P (t) && ! DESTRUCTOR_NAME_P (name)) { dump_type_prefix (TREE_TYPE (fntype), 1); OB_PUTC (' '); } } if (cname) { dump_type (cname, 0); OB_PUTC2 (':', ':'); if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes) parmtypes = TREE_CHAIN (parmtypes); if (DECL_CONSTRUCTOR_FOR_VBASE_P (t)) /* Skip past "in_charge" identifier. */ parmtypes = TREE_CHAIN (parmtypes); } if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus) parmtypes = TREE_CHAIN (parmtypes); dump_function_name (t); OB_PUTC ('('); if (parmtypes) dump_type (parmtypes, v); else OB_PUTS ("..."); OB_PUTC (')'); if (v && ! IDENTIFIER_TYPENAME_P (name)) dump_type_suffix (TREE_TYPE (fntype), 1); if (TREE_CODE (fntype) == METHOD_TYPE) { if (IS_SIGNATURE (cname)) /* We look at the type pointed to by the `optr' field of `this.' */ dump_readonly_or_volatile (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before); else dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before); }}/* Handle the function name for a FUNCTION_DECL node, grokking operators and destructors properly. */static voiddump_function_name (t) tree t;{ tree name = DECL_NAME (t); /* There ought to be a better way to find out whether or not something is a destructor. */ if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t)) && DECL_LANGUAGE (t) == lang_cplusplus) { OB_PUTC ('~'); dump_decl (name, 0); } else if (IDENTIFIER_TYPENAME_P (name)) { /* This cannot use the hack that the operator's return type is stashed off of its name because it may be used for error reporting. In the case of conflicting declarations, both will have the same name, yet the types will be different, hence the TREE_TYPE field of the first name will be clobbered by the second. */ OB_PUTS ("operator "); dump_type (TREE_TYPE (TREE_TYPE (t)), 0); } else if (IDENTIFIER_OPNAME_P (name)) { char *name_string = operator_name_string (name); OB_PUTS ("operator "); OB_PUTCP (name_string); } else dump_decl (name, 0); if ((DECL_TEMPLATE_SPECIALIZATION (t) || DECL_IMPLICIT_INSTANTIATION (t)) && (DECL_CLASS_CONTEXT (t) == NULL_TREE || is_member_template (t))) { tree args = DECL_TEMPLATE_INFO (t) ? DECL_TI_ARGS (t) : NULL_TREE; OB_PUTC ('<'); /* Be careful only to print things when we have them, so as not to crash producing error messages. */ if (args) { if (TREE_CODE (args) == TREE_LIST) { tree arg; int need_comma = 0; for (arg = args; arg; arg = TREE_CHAIN (arg)) { tree a = TREE_VALUE (arg); if (need_comma) OB_PUTS (", "); if (a) { if (TREE_CODE_CLASS (TREE_CODE (a)) == 't') dump_type (a, 0); else dump_expr (a, 0); } need_comma = 1; } } else if (TREE_CODE (args) == TREE_VEC) { int i; int need_comma = 0; if (TREE_VEC_LENGTH (args) > 0 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC) args = TREE_VEC_ELT (args, 0); for (i = 0; i < TREE_VEC_LENGTH (args); i++) { tree a = TREE_VEC_ELT (args, i); if (need_comma) OB_PUTS (", "); if (a) { if (TREE_CODE_CLASS (TREE_CODE (a)) == 't') dump_type (a, 0); else dump_expr (a, 0); } need_comma = 1; } } } OB_PUTC ('>'); }}static voiddump_char (c) int c;{ switch (c) { case TARGET_NEWLINE: OB_PUTS ("\\n"); break; case TARGET_TAB: OB_PUTS ("\\t"); break; case TARGET_VT: OB_PUTS ("\\v"); break; case TARGET_BS: OB_PUTS ("\\b"); break; case TARGET_CR: OB_PUTS ("\\r"); break; case TARGET_FF: OB_PUTS ("\\f"); break; case TARGET_BELL: OB_PUTS ("\\a"); break; case '\\': OB_PUTS ("\\\\"); break; case '\'': OB_PUTS ("\\'"); break; case '\"': OB_PUTS ("\\\""); break; default: if (isprint (c)) OB_PUTC (c); else { sprintf (digit_buffer, "\\%03o", (int) c); OB_PUTCP (digit_buffer); } }}/* Print out a list of initializers (subr of dump_expr) */static voiddump_expr_list (l) tree l;{ while (l) { dump_expr (TREE_VALUE (l), 0); if (TREE_CHAIN (l)) OB_PUTC2 (',', ' '); l = TREE_CHAIN (l); }}/* Print out an expression */static voiddump_expr (t, nop) tree t; int nop; /* suppress parens */{ switch (TREE_CODE (t)) { case VAR_DECL: case PARM_DECL: case FIELD_DECL: case CONST_DECL: case FUNCTION_DECL: case TEMPLATE_DECL: dump_decl (t, -1); break; case INTEGER_CST: { tree type = TREE_TYPE (t); my_friendly_assert (type != 0, 81); /* If it's an enum, output its tag, rather than its value. */ if (TREE_CODE (type) == ENUMERAL_TYPE) { char *p = enum_name_string (t, type); OB_PUTCP (p); } else if (type == boolean_type_node) { if (t == boolean_false_node || (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)) OB_PUTS ("false"); else if (t == boolean_true_node) OB_PUTS ("true"); } else if (type == char_type_node) { OB_PUTC ('\''); dump_char (TREE_INT_CST_LOW (t)); OB_PUTC ('\''); } else if (TREE_INT_CST_HIGH (t) != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1))) { tree val = t; if (TREE_INT_CST_HIGH (val) < 0) { OB_PUTC ('-'); val = build_int_2 (~TREE_INT_CST_LOW (val), -TREE_INT_CST_HIGH (val)); } /* Would "%x%0*x" or "%x%*0x" get zero-padding on all systems? */ { static char format[10]; /* "%x%09999x\0" */ if (!format[0]) sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4); sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val), TREE_INT_CST_LOW (val)); OB_PUTCP (digit_buffer); } } else OB_PUTI (TREE_INT_CST_LOW (t)); } break; case REAL_CST:#ifndef REAL_IS_NOT_DOUBLE sprintf (digit_buffer, "%g", TREE_REAL_CST (t));#else { unsigned char *p = (unsigned char *) &TREE_REAL_CST (t); int i; strcpy (digit_buffer, "0x"); for (i = 0; i < sizeof TREE_REAL_CST (t); i++) sprintf (digit_buffer + 2 + 2*i, "%02x", *p++); }#endif OB_PUTCP (digit_buffer); break; case STRING_CST: { char *p = TREE_STRING_POINTER (t); int len = TREE_STRING_LENGTH (t) - 1; int i; OB_PUTC ('\"'); for (i = 0; i < len; i++) dump_char (p[i]); OB_PUTC ('\"'); } break; case COMPOUND_EXPR: dump_binary_op (",", t); break; case COND_EXPR: OB_PUTC ('('); dump_expr (TREE_OPERAND (t, 0), 0); OB_PUTS (" ? "); dump_expr (TREE_OPERAND (t, 1), 0); OB_PUTS (" : "); dump_expr (TREE_OPERAND (t, 2), 0); OB_PUTC (')'); break; case SAVE_EXPR: if (TREE_HAS_CONSTRUCTOR (t)) { OB_PUTS ("new "); dump_type (TREE_TYPE (TREE_TYPE (t)), 0); PARM_DECL_EXPR (t) = 1; } else { dump_expr (TREE_OPERAND (t, 0), 0); } break; case NEW_EXPR: OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t))); OB_PUTC ('('); if (TREE_OPERAND (t, 1)) dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1))); OB_PUTC (')'); break; case CALL_EXPR: { tree fn = TREE_OPERAND (t, 0); tree args = TREE_OPERAND (t, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -