This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[patch] ui-out - change stack elements to structs
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [patch] ui-out - change stack elements to structs
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Tue, 08 May 2001 20:17:32 -0400
FYI,
The attatched patch was extracted from my earlier MI jumbo patch. In
essence, it is replacing:
/* if on, a list is being generated. The value is the level of nesting */
int list_flag;
/* we count each field; the first element is for non-list fields */
int field_count[5];
with:
/* Sub structure tracking the table depth. */
int level;
struct ui_out_level levels[MAX_UI_OUT_LEVELS];
Andrew
2001-05-07 Andrew Cagney <ac131313@redhat.com>
* ui-out.h (list_begin_ftype, list_end_ftype): Rename argument
``list_flag'' to ``depth''.
* ui-out.c (default_list_begin, default_list_end): Update.
(uo_list_begin, uo_list_end): Update.
(MAX_UI_OUT_LEVELS): Define.
(struct ui_out_level): Define.
(top-level): Include "gdb_assert.h".
(struct ui_out): Add fields ``level'' and ``levels''. Delete
fields ``list_flag'' and ``field_count''.
(ui_out_new): Update.
(verify_field_proper_position): Update.
(current_level, push_level, pop_level): New functions.
(ui_out_list_begin): Use push_level.
(ui_out_list_end): Use pop_level.
(ui_out_field_int): Use current_level.
(ui_out_field_skip): Ditto.
(ui_out_field_fmt): Ditto.
Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.8
diff -p -r1.8 ui-out.c
*** ui-out.c 2001/02/08 06:03:54 1.8
--- ui-out.c 2001/05/09 00:08:12
***************
*** 25,30 ****
--- 25,31 ----
#include "expression.h" /* For language.h */
#include "language.h"
#include "ui-out.h"
+ #include "gdb_assert.h"
/* Convenience macro for allocting typesafe memory. */
*************** struct ui_out_hdr
*** 42,47 ****
--- 43,60 ----
struct ui_out_hdr *next;
};
+ /* Maintain a stack so that the info applicable to the inner most list
+ is always available. Stack/nested level 0 is reserved for the
+ top-level result. */
+
+ enum { MAX_UI_OUT_LEVELS = 5 };
+
+ struct ui_out_level
+ {
+ /* Count each field; the first element is for non-list fields */
+ int field_count;
+ };
+
/* The ui_out structure */
/* Any change here requires a corresponding one in the initialization
of the default uiout, which is statically initialized */
*************** struct ui_out
*** 64,75 ****
/* strinf identifying the table (as specified in the table_begin call) */
char *table_id;
-
- /* if on, a list is being generated. The value is the level of nesting */
- int list_flag;
! /* we count each field; the first element is for non-list fields */
! int field_count[5];
/* points to the first header (if any) */
struct ui_out_hdr *headerfirst;
--- 77,86 ----
/* strinf identifying the table (as specified in the table_begin call) */
char *table_id;
! /* Sub structure tracking the table depth. */
! int level;
! struct ui_out_level levels[MAX_UI_OUT_LEVELS];
/* points to the first header (if any) */
struct ui_out_hdr *headerfirst;
*************** struct ui_out
*** 82,87 ****
--- 93,131 ----
};
+ /* The current (inner most) level. */
+ static struct ui_out_level *
+ current_level (struct ui_out *uiout)
+ {
+ return &uiout->levels[uiout->level];
+ }
+
+ /* Create a new level, of TYPE. Return the new level's index. */
+ static int
+ push_level (struct ui_out *uiout,
+ const char *id)
+ {
+ struct ui_out_level *current;
+ /* We had better not overflow the buffer. */
+ uiout->level++;
+ gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
+ current = current_level (uiout);
+ current->field_count = 0;
+ return uiout->level;
+ }
+
+ /* Discard the current level, return the discarded level's index.
+ TYPE is the type of the level being discarded. */
+ static int
+ pop_level (struct ui_out *uiout)
+ {
+ /* We had better not underflow the buffer. */
+ gdb_assert (uiout->level > 0 && uiout->level < MAX_UI_OUT_LEVELS);
+ uiout->level--;
+ return uiout->level + 1;
+ }
+
+
/* These are the default implementation functions */
static void default_table_begin (struct ui_out *uiout, int nbrofcols,
*************** static void default_table_body (struct u
*** 90,98 ****
static void default_table_end (struct ui_out *uiout);
static void default_table_header (struct ui_out *uiout, int width,
enum ui_align alig, char *colhdr);
! static void default_list_begin (struct ui_out *uiout, int list_flag,
char *lstid);
! static void default_list_end (struct ui_out *uiout, int list_flag);
static void default_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align alig, char *fldname, int value);
static void default_field_skip (struct ui_out *uiout, int fldno, int width,
--- 134,142 ----
static void default_table_end (struct ui_out *uiout);
static void default_table_header (struct ui_out *uiout, int width,
enum ui_align alig, char *colhdr);
! static void default_list_begin (struct ui_out *uiout, int level,
char *lstid);
! static void default_list_end (struct ui_out *uiout, int level);
static void default_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align alig, char *fldname, int value);
static void default_field_skip (struct ui_out *uiout, int fldno, int width,
*************** static void uo_table_body (struct ui_out
*** 152,159 ****
static void uo_table_end (struct ui_out *uiout);
static void uo_table_header (struct ui_out *uiout, int width,
enum ui_align align, char *colhdr);
! static void uo_list_begin (struct ui_out *uiout, int list_flag, char *lstid);
! static void uo_list_end (struct ui_out *uiout, int list_flag);
static void uo_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align align, char *fldname, int value);
static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
--- 196,203 ----
static void uo_table_end (struct ui_out *uiout);
static void uo_table_header (struct ui_out *uiout, int width,
enum ui_align align, char *colhdr);
! static void uo_list_begin (struct ui_out *uiout, int level, char *lstid);
! static void uo_list_end (struct ui_out *uiout, int level);
static void uo_field_int (struct ui_out *uiout, int fldno, int width,
enum ui_align align, char *fldname, int value);
static void uo_field_skip (struct ui_out *uiout, int fldno, int width,
*************** and before table_body.");
*** 261,293 ****
void
ui_out_list_begin (struct ui_out *uiout, char *lstid)
{
if (uiout->table_flag && !uiout->body_flag)
internal_error (__FILE__, __LINE__,
"table header or table_body expected; lists must be \
specified after table_body.");
! if (uiout->list_flag >= 4)
! internal_error (__FILE__, __LINE__,
! "list depth exceeded; only 4 levels of lists can be \
! nested.");
!
! uiout->list_flag++;
! uiout->field_count[uiout->list_flag] = 0;
! if (uiout->table_flag && (uiout->list_flag == 1))
uiout->headercurr = uiout->headerfirst;
!
! uo_list_begin (uiout, uiout->list_flag, lstid);
}
void
ui_out_list_end (struct ui_out *uiout)
{
! if (!uiout->list_flag)
! internal_error (__FILE__, __LINE__,
! "misplaced list_end; there is no list to be closed.");
!
! uo_list_end (uiout, uiout->list_flag);
!
! uiout->list_flag--;
}
static void
--- 305,326 ----
void
ui_out_list_begin (struct ui_out *uiout, char *lstid)
{
+ int new_level;
if (uiout->table_flag && !uiout->body_flag)
internal_error (__FILE__, __LINE__,
"table header or table_body expected; lists must be \
specified after table_body.");
! new_level = push_level (uiout, lstid);
! if (uiout->table_flag && (new_level == 1))
uiout->headercurr = uiout->headerfirst;
! uo_list_begin (uiout, new_level, lstid);
}
void
ui_out_list_end (struct ui_out *uiout)
{
! int old_level = pop_level (uiout);
! uo_list_end (uiout, old_level);
}
static void
*************** ui_out_field_int (struct ui_out *uiout,
*** 308,318 ****
int fldno;
int width;
int align;
verify_field_proper_position (uiout);
! uiout->field_count[uiout->list_flag] += 1;
! fldno = uiout->field_count[uiout->list_flag];
verify_field_alignment (uiout, fldno, &width, &align);
--- 341,352 ----
int fldno;
int width;
int align;
+ struct ui_out_level *current = current_level (uiout);
verify_field_proper_position (uiout);
! current->field_count += 1;
! fldno = current->field_count;
verify_field_alignment (uiout, fldno, &width, &align);
*************** ui_out_field_skip (struct ui_out *uiout,
*** 353,363 ****
int fldno;
int width;
int align;
verify_field_proper_position (uiout);
! uiout->field_count[uiout->list_flag] += 1;
! fldno = uiout->field_count[uiout->list_flag];
verify_field_alignment (uiout, fldno, &width, &align);
--- 387,398 ----
int fldno;
int width;
int align;
+ struct ui_out_level *current = current_level (uiout);
verify_field_proper_position (uiout);
! current->field_count += 1;
! fldno = current->field_count;
verify_field_alignment (uiout, fldno, &width, &align);
*************** ui_out_field_string (struct ui_out *uiou
*** 372,382 ****
int fldno;
int width;
int align;
verify_field_proper_position (uiout);
! uiout->field_count[uiout->list_flag] += 1;
! fldno = uiout->field_count[uiout->list_flag];
verify_field_alignment (uiout, fldno, &width, &align);
--- 407,418 ----
int fldno;
int width;
int align;
+ struct ui_out_level *current = current_level (uiout);
verify_field_proper_position (uiout);
! current->field_count += 1;
! fldno = current->field_count;
verify_field_alignment (uiout, fldno, &width, &align);
*************** ui_out_field_fmt (struct ui_out *uiout,
*** 391,401 ****
int fldno;
int width;
int align;
verify_field_proper_position (uiout);
! uiout->field_count[uiout->list_flag] += 1;
! fldno = uiout->field_count[uiout->list_flag];
/* will not align, but has to call anyway */
verify_field_alignment (uiout, fldno, &width, &align);
--- 427,438 ----
int fldno;
int width;
int align;
+ struct ui_out_level *current = current_level (uiout);
verify_field_proper_position (uiout);
! current->field_count += 1;
! fldno = current->field_count;
/* will not align, but has to call anyway */
verify_field_alignment (uiout, fldno, &width, &align);
*************** default_table_header (struct ui_out *uio
*** 592,603 ****
}
static void
! default_list_begin (struct ui_out *uiout, int list_flag, char *lstid)
{
}
static void
! default_list_end (struct ui_out *uiout, int list_flag)
{
}
--- 629,640 ----
}
static void
! default_list_begin (struct ui_out *uiout, int level, char *lstid)
{
}
static void
! default_list_end (struct ui_out *uiout, int level)
{
}
*************** uo_table_header (struct ui_out *uiout, i
*** 691,709 ****
}
void
! uo_list_begin (struct ui_out *uiout, int list_flag, char *lstid)
{
if (!uiout->impl->list_begin)
return;
! uiout->impl->list_begin (uiout, list_flag, lstid);
}
void
! uo_list_end (struct ui_out *uiout, int list_flag)
{
if (!uiout->impl->list_end)
return;
! uiout->impl->list_end (uiout, list_flag);
}
void
--- 728,746 ----
}
void
! uo_list_begin (struct ui_out *uiout, int level, char *lstid)
{
if (!uiout->impl->list_begin)
return;
! uiout->impl->list_begin (uiout, level, lstid);
}
void
! uo_list_end (struct ui_out *uiout, int level)
{
if (!uiout->impl->list_end)
return;
! uiout->impl->list_end (uiout, level);
}
void
*************** verify_field_proper_position (struct ui_
*** 862,868 ****
internal_error (__FILE__, __LINE__,
"table_body missing; table fields must be \
specified after table_body and inside a list.");
! if (!uiout->list_flag)
internal_error (__FILE__, __LINE__,
"list_begin missing; table fields must be \
specified after table_body and inside a list.");
--- 899,905 ----
internal_error (__FILE__, __LINE__,
"table_body missing; table fields must be \
specified after table_body and inside a list.");
! if (uiout->level == 0)
internal_error (__FILE__, __LINE__,
"list_begin missing; table fields must be \
specified after table_body and inside a list.");
*************** ui_out_new (struct ui_out_impl *impl,
*** 922,929 ****
uiout->flags = flags;
uiout->table_flag = 0;
uiout->body_flag = 0;
! uiout->list_flag = 0;
! uiout->field_count[0] = 0;
uiout->headerfirst = NULL;
uiout->headerlast = NULL;
uiout->headercurr = NULL;
--- 959,966 ----
uiout->flags = flags;
uiout->table_flag = 0;
uiout->body_flag = 0;
! uiout->level = 0;
! memset (uiout->levels, 0, sizeof (uiout->levels));
uiout->headerfirst = NULL;
uiout->headerlast = NULL;
uiout->headercurr = NULL;
Index: ui-out.h
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.h,v
retrieving revision 1.5
diff -p -r1.5 ui-out.h
*** ui-out.h 2001/03/14 16:42:30 1.5
--- ui-out.h 2001/05/09 00:08:12
*************** typedef void (table_body_ftype) (struct
*** 162,170 ****
typedef void (table_end_ftype) (struct ui_out * uiout);
typedef void (table_header_ftype) (struct ui_out * uiout, int width,
enum ui_align align, char *colhdr);
typedef void (list_begin_ftype) (struct ui_out * uiout,
! int list_flag, char *lstid);
! typedef void (list_end_ftype) (struct ui_out * uiout, int list_flag);
typedef void (field_int_ftype) (struct ui_out * uiout, int fldno, int width,
enum ui_align align, char *fldname, int value);
typedef void (field_skip_ftype) (struct ui_out * uiout, int fldno, int width,
--- 162,172 ----
typedef void (table_end_ftype) (struct ui_out * uiout);
typedef void (table_header_ftype) (struct ui_out * uiout, int width,
enum ui_align align, char *colhdr);
+ /* Note: level 0 is the top-level so LEVEL is always greater than
+ zero. */
typedef void (list_begin_ftype) (struct ui_out * uiout,
! int level, char *lstid);
! typedef void (list_end_ftype) (struct ui_out * uiout, int level);
typedef void (field_int_ftype) (struct ui_out * uiout, int fldno, int width,
enum ui_align align, char *fldname, int value);
typedef void (field_skip_ftype) (struct ui_out * uiout, int fldno, int width,