本文整理汇总了C++中TYPE_NFIELDS函数的典型用法代码示例。如果您正苦于以下问题:C++ TYPE_NFIELDS函数的具体用法?C++ TYPE_NFIELDS怎么用?C++ TYPE_NFIELDS使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TYPE_NFIELDS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_range
static void
print_range(struct type *the_type, struct ui_file *stream)
{
struct type *target_type;
target_type = TYPE_TARGET_TYPE(the_type);
if (target_type == NULL)
target_type = the_type;
switch (TYPE_CODE(target_type))
{
case TYPE_CODE_RANGE:
case TYPE_CODE_INT:
case TYPE_CODE_BOOL:
case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
break;
default:
target_type = builtin_type_int;
break;
}
if (TYPE_NFIELDS(the_type) < 2)
{
/* A range needs at least 2 bounds to be printed. If there are less
than 2, just print the type name instead of the range itself.
This check handles cases such as characters, for example.
Note that if the name is not defined, then we don't print anything.
*/
fprintf_filtered(stream, "%.*s",
ada_name_prefix_len(TYPE_NAME(the_type)),
TYPE_NAME(the_type));
}
else
{
/* We extract the range type bounds respectively from the first element
and the last element of the type->fields array */
const LONGEST lower_bound = (LONGEST)TYPE_LOW_BOUND(the_type);
const LONGEST upper_bound =
(LONGEST)TYPE_FIELD_BITPOS(the_type, TYPE_NFIELDS(the_type) - 1);
ada_print_scalar(target_type, lower_bound, stream);
fprintf_filtered(stream, " .. ");
ada_print_scalar(target_type, upper_bound, stream);
}
}
示例2: get_regs_type
static struct type *
get_regs_type (struct objfile *objfile)
{
struct symbol *func_sym;
struct type *func_type, *regsp_type, *regs_type;
func_sym = lookup_global_symbol_from_objfile (objfile,
GCC_FE_WRAPPER_FUNCTION,
VAR_DOMAIN);
if (func_sym == NULL)
error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
func_type = SYMBOL_TYPE (func_sym);
if (TYPE_CODE (func_type) != TYPE_CODE_FUNC)
error (_("Invalid type code %d of function \"%s\" in compiled "
"module \"%s\"."),
TYPE_CODE (func_type), GCC_FE_WRAPPER_FUNCTION,
objfile_name (objfile));
/* No register parameter present. */
if (TYPE_NFIELDS (func_type) == 0)
return NULL;
if (TYPE_NFIELDS (func_type) != 1)
error (_("Invalid %d parameters of function \"%s\" in compiled "
"module \"%s\"."),
TYPE_NFIELDS (func_type), GCC_FE_WRAPPER_FUNCTION,
objfile_name (objfile));
regsp_type = check_typedef (TYPE_FIELD_TYPE (func_type, 0));
if (TYPE_CODE (regsp_type) != TYPE_CODE_PTR)
error (_("Invalid type code %d of first parameter of function \"%s\" "
"in compiled module \"%s\"."),
TYPE_CODE (regsp_type), GCC_FE_WRAPPER_FUNCTION,
objfile_name (objfile));
regs_type = check_typedef (TYPE_TARGET_TYPE (regsp_type));
if (TYPE_CODE (regs_type) != TYPE_CODE_STRUCT)
error (_("Invalid type code %d of dereferenced first parameter "
"of function \"%s\" in compiled module \"%s\"."),
TYPE_CODE (regs_type), GCC_FE_WRAPPER_FUNCTION,
objfile_name (objfile));
return regs_type;
}
示例3: print_record_field_types
static int
print_record_field_types (struct type *type, struct type *outer_type,
struct ui_file *stream, int show, int level,
const struct type_print_options *flags)
{
return print_selected_record_field_types (type, outer_type,
0, TYPE_NFIELDS (type) - 1,
stream, show, level, flags);
}
示例4: m2_long_set
static int
m2_long_set (struct type *type, struct ui_file *stream, int show, int level)
{
struct type *index_type;
struct type *range_type;
struct type *of_type;
int i;
int len = TYPE_NFIELDS (type);
LONGEST low;
LONGEST high;
if (m2_is_long_set (type))
{
if (TYPE_TAG_NAME (type) != NULL)
{
fputs_filtered (TYPE_TAG_NAME (type), stream);
if (show == 0)
return 1;
}
else if (TYPE_NAME (type) != NULL)
{
fputs_filtered (TYPE_NAME (type), stream);
if (show == 0)
return 1;
}
if (TYPE_TAG_NAME (type) != NULL || TYPE_NAME (type) != NULL)
fputs_filtered (" = ", stream);
if (get_long_set_bounds (type, &low, &high))
{
fprintf_filtered(stream, "SET OF ");
i = TYPE_N_BASECLASSES (type);
if (m2_is_long_set_of_type (type, &of_type))
m2_print_type (of_type, "", stream, show - 1, level);
else
{
fprintf_filtered(stream, "[");
m2_print_bounds (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, i)),
stream, show - 1, level, 0);
fprintf_filtered(stream, "..");
m2_print_bounds (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, len-1)),
stream, show - 1, level, 1);
fprintf_filtered(stream, "]");
}
}
else
/* i18n: Do not translate the "SET OF" part! */
fprintf_filtered(stream, _("SET OF <unknown>"));
return 1;
}
return 0;
}
示例5: sixg_string_p
static int
sixg_string_p (struct type *type)
{
if (TYPE_NFIELDS (type) == 2
&& TYPE_TAG_NAME (type) != NULL
&& strcmp (TYPE_TAG_NAME (type), "string") == 0)
return 1;
return 0;
}
示例6: c_type_print_args
static void
c_type_print_args (struct type *type, struct ui_file *stream)
{
int i;
struct field *args;
fprintf_filtered (stream, "(");
args = TYPE_FIELDS (type);
if (args != NULL)
{
int i;
/* FIXME drow/2002-05-31: Always skips the first argument,
should we be checking for static members? */
for (i = 1; i < TYPE_NFIELDS (type); i++)
{
c_print_type (args[i].type, "", stream, -1, 0);
if (i != TYPE_NFIELDS (type))
{
fprintf_filtered (stream, ",");
wrap_here (" ");
}
}
if (TYPE_VARARGS (type))
fprintf_filtered (stream, "...");
else if (i == 1
/* APPLE LOCAL begin Objective-C++ */
&& (current_language->la_language == language_cplus
|| current_language->la_language == language_objcplus))
/* APPLE LOCAL end Objective-C++ */
fprintf_filtered (stream, "void");
}
/* APPLE LOCAL begin Objective-C++ */
else if (current_language->la_language == language_cplus
|| current_language->la_language == language_objcplus)
/* APPLE LOCAL end Objective-C++ */
{
fprintf_filtered (stream, "void");
}
fprintf_filtered (stream, ")");
}
示例7: c_type_print_args
static void
c_type_print_args (struct type *type, struct ui_file *stream)
{
int i, len;
struct field *args;
int printed_any = 0;
fprintf_filtered (stream, "(");
args = TYPE_FIELDS (type);
len = TYPE_NFIELDS (type);
for (i = 0; i < TYPE_NFIELDS (type); i++)
{
if (printed_any)
{
fprintf_filtered (stream, ", ");
wrap_here (" ");
}
c_print_type (TYPE_FIELD_TYPE (type, i), "", stream, -1, 0);
printed_any = 1;
}
if (printed_any && TYPE_VARARGS (type))
{
/* Print out a trailing ellipsis for varargs functions. Ignore
TYPE_VARARGS if the function has no named arguments; that
represents unprototyped (K&R style) C functions. */
if (printed_any && TYPE_VARARGS (type))
{
fprintf_filtered (stream, ", ");
wrap_here (" ");
fprintf_filtered (stream, "...");
}
}
else if (!printed_any
&& (TYPE_PROTOTYPED (type)
|| current_language->la_language == language_cplus))
fprintf_filtered (stream, "void");
fprintf_filtered (stream, ")");
}
示例8: ada_varobj_get_struct_number_of_children
static int
ada_varobj_get_struct_number_of_children (struct value *parent_value,
struct type *parent_type)
{
int n_children = 0;
int i;
gdb_assert (TYPE_CODE (parent_type) == TYPE_CODE_STRUCT
|| TYPE_CODE (parent_type) == TYPE_CODE_UNION);
for (i = 0; i < TYPE_NFIELDS (parent_type); i++)
{
if (ada_is_ignored_field (parent_type, i))
continue;
if (ada_is_wrapper_field (parent_type, i))
{
struct value *elt_value;
struct type *elt_type;
ada_varobj_struct_elt (parent_value, parent_type, i,
&elt_value, &elt_type);
if (ada_is_tagged_type (elt_type, 0))
{
/* We must not use ada_varobj_get_number_of_children
to determine is element's number of children, because
this function first calls ada_varobj_decode_var,
which "fixes" the element. For tagged types, this
includes reading the object's tag to determine its
real type, which happens to be the parent_type, and
leads to an infinite loop (because the element gets
fixed back into the parent). */
n_children += ada_varobj_get_struct_number_of_children
(elt_value, elt_type);
}
else
n_children += ada_varobj_get_number_of_children (elt_value, elt_type);
}
else if (ada_is_variant_part (parent_type, i))
{
/* In normal situations, the variant part of the record should
have been "fixed". Or, in other words, it should have been
replaced by the branch of the variant part that is relevant
for our value. But there are still situations where this
can happen, however (Eg. when our parent is a NULL pointer).
We do not support showing this part of the record for now,
so just pretend this field does not exist. */
}
else
n_children++;
}
return n_children;
}
示例9: cp_type_print_method_args
static void
cp_type_print_method_args (struct type *mtype, const char *prefix,
const char *varstring, int staticp,
struct ui_file *stream)
{
struct field *args = TYPE_FIELDS (mtype);
int nargs = TYPE_NFIELDS (mtype);
int varargs = TYPE_VARARGS (mtype);
int i;
fprintf_symbol_filtered (stream, prefix,
language_cplus, DMGL_ANSI);
fprintf_symbol_filtered (stream, varstring,
language_cplus, DMGL_ANSI);
fputs_filtered ("(", stream);
/* Skip the class variable. */
i = staticp ? 0 : 1;
if (nargs > i)
{
while (i < nargs)
{
type_print (args[i++].type, "", stream, 0);
if (i == nargs && varargs)
fprintf_filtered (stream, ", ...");
else if (i < nargs)
fprintf_filtered (stream, ", ");
}
}
else if (varargs)
fprintf_filtered (stream, "...");
else if (current_language->la_language == language_cplus)
fprintf_filtered (stream, "void");
fprintf_filtered (stream, ")");
/* For non-static methods, read qualifiers from the type of
THIS. */
if (!staticp)
{
struct type *domain;
gdb_assert (nargs > 0);
gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
domain = TYPE_TARGET_TYPE (args[0].type);
if (TYPE_CONST (domain))
fprintf_filtered (stream, " const");
if (TYPE_VOLATILE (domain))
fprintf_filtered (stream, " volatile");
}
}
示例10: m68k_svr4_return_value
static enum return_value_convention
m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = TYPE_CODE (type);
if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
|| code == TYPE_CODE_COMPLEX)
&& !m68k_reg_struct_return_p (gdbarch, type))
{
/* The System V ABI says that:
"A function returning a structure or union also sets %a0 to
the value it finds in %a0. Thus when the caller receives
control again, the address of the returned object resides in
register %a0."
So the ABI guarantees that we can always find the return
value just after the function has returned. */
if (readbuf)
{
ULONGEST addr;
regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr);
read_memory (addr, readbuf, TYPE_LENGTH (type));
}
return RETURN_VALUE_ABI_RETURNS_ADDRESS;
}
/* This special case is for structures consisting of a single
`float' or `double' member. These structures are returned in
%fp0. For these structures, we call ourselves recursively,
changing TYPE into the type of the first member of the structure.
Since that should work for all structures that have only one
member, we don't bother to check the member's type here. */
if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
{
type = check_typedef (TYPE_FIELD_TYPE (type, 0));
return m68k_svr4_return_value (gdbarch, function, type, regcache,
readbuf, writebuf);
}
if (readbuf)
m68k_svr4_extract_return_value (type, regcache, readbuf);
if (writebuf)
m68k_svr4_store_return_value (type, regcache, writebuf);
return RETURN_VALUE_REGISTER_CONVENTION;
}
示例11: m2_print_bounds
static void
m2_print_bounds (struct type *type,
struct ui_file *stream, int show, int level,
int print_high)
{
struct type *target = TYPE_TARGET_TYPE (type);
if (TYPE_NFIELDS(type) == 0)
return;
if (print_high)
print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
else
print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
}
示例12: store_regs
static void
store_regs (struct type *regs_type, CORE_ADDR regs_base)
{
struct gdbarch *gdbarch = target_gdbarch ();
struct regcache *regcache = get_thread_regcache (inferior_ptid);
int fieldno;
for (fieldno = 0; fieldno < TYPE_NFIELDS (regs_type); fieldno++)
{
const char *reg_name = TYPE_FIELD_NAME (regs_type, fieldno);
ULONGEST reg_bitpos = TYPE_FIELD_BITPOS (regs_type, fieldno);
ULONGEST reg_bitsize = TYPE_FIELD_BITSIZE (regs_type, fieldno);
ULONGEST reg_offset;
struct type *reg_type = check_typedef (TYPE_FIELD_TYPE (regs_type,
fieldno));
ULONGEST reg_size = TYPE_LENGTH (reg_type);
int regnum;
struct value *regval;
CORE_ADDR inferior_addr;
if (strcmp (reg_name, COMPILE_I_SIMPLE_REGISTER_DUMMY) == 0)
continue;
if ((reg_bitpos % 8) != 0 || reg_bitsize != 0)
error (_("Invalid register \"%s\" position %s bits or size %s bits"),
reg_name, pulongest (reg_bitpos), pulongest (reg_bitsize));
reg_offset = reg_bitpos / 8;
if (TYPE_CODE (reg_type) != TYPE_CODE_INT
&& TYPE_CODE (reg_type) != TYPE_CODE_PTR)
error (_("Invalid register \"%s\" type code %d"), reg_name,
TYPE_CODE (reg_type));
regnum = compile_register_name_demangle (gdbarch, reg_name);
regval = value_from_register (reg_type, regnum, get_current_frame ());
if (value_optimized_out (regval))
error (_("Register \"%s\" is optimized out."), reg_name);
if (!value_entirely_available (regval))
error (_("Register \"%s\" is not available."), reg_name);
inferior_addr = regs_base + reg_offset;
if (0 != target_write_memory (inferior_addr, value_contents (regval),
reg_size))
error (_("Cannot write register \"%s\" to inferior memory at %s."),
reg_name, paddress (gdbarch, inferior_addr));
}
}
示例13: mn10300_type_align
static int
mn10300_type_align (struct type *type)
{
int i, align = 1;
switch (TYPE_CODE (type))
{
case TYPE_CODE_INT:
case TYPE_CODE_ENUM:
case TYPE_CODE_SET:
case TYPE_CODE_RANGE:
case TYPE_CODE_CHAR:
case TYPE_CODE_BOOL:
case TYPE_CODE_FLT:
case TYPE_CODE_PTR:
case TYPE_CODE_REF:
return TYPE_LENGTH (type);
case TYPE_CODE_COMPLEX:
return TYPE_LENGTH (type) / 2;
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
for (i = 0; i < TYPE_NFIELDS (type); i++)
{
int falign = mn10300_type_align (TYPE_FIELD_TYPE (type, i));
while (align < falign)
align <<= 1;
}
return align;
case TYPE_CODE_ARRAY:
/* HACK! Structures containing arrays, even small ones, are not
elligible for returning in registers. */
return 256;
case TYPE_CODE_TYPEDEF:
return mn10300_type_align (check_typedef (type));
default:
internal_error (__FILE__, __LINE__, _("bad switch"));
}
}
示例14: dynamic_array_type
static int
dynamic_array_type (struct type *type, const gdb_byte *valaddr,
int embedded_offset, CORE_ADDR address,
struct ui_file *stream, int recurse,
const struct value *val,
const struct value_print_options *options)
{
if (TYPE_NFIELDS (type) == 2
&& TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
&& strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
&& strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
&& !value_bits_any_optimized_out (val,
TARGET_CHAR_BIT * embedded_offset,
TARGET_CHAR_BIT * TYPE_LENGTH (type)))
{
CORE_ADDR addr;
struct type *elttype;
struct type *true_type;
struct type *ptr_type;
struct value *ival;
int length;
length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
ptr_type = TYPE_FIELD_TYPE (type, 1);
elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
addr = unpack_pointer (ptr_type,
valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
+ embedded_offset);
true_type = check_typedef (elttype);
true_type = lookup_array_range_type (true_type, 0, length - 1);
ival = value_at (true_type, addr);
true_type = value_type (ival);
d_val_print (true_type,
value_contents_for_printing (ival),
value_embedded_offset (ival), addr,
stream, recurse + 1, ival, options);
return 0;
}
return 1;
}
示例15: get_long_set_bounds
int
get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high)
{
int len, i;
if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
{
len = TYPE_NFIELDS (type);
i = TYPE_N_BASECLASSES (type);
if (len == 0)
return 0;
*low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, i)));
*high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type,
len-1)));
return 1;
}
error (_("expecting long_set"));
return 0;
}