src/misc/dbg_helpers.cpp
author terom@frrb.lan
Fri, 19 Dec 2008 01:32:07 +0200
changeset 10438 51bff16a04c9
parent 9790 5d5c70e0334e
permissions -rw-r--r--
initial mini-map stuff
7122
444ddcad8909 (svn r10395) -Fix [YAPF]: missing include + some signed/unsigned comparison warnings
KUDr
parents: 7118
diff changeset
     1
/* $Id$ */
7118
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8123
diff changeset
     3
/** @file dbg_helpers.cpp Helpers for outputting debug information. */
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8123
diff changeset
     4
7118
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     5
#include "../stdafx.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8100
diff changeset
     6
#include "../openttd.h"
8100
6bc08f98ec16 (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 7122
diff changeset
     7
#include "../direction_type.h"
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
     8
#include "../strings_type.h"
7118
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     9
#include "../rail.h"
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    10
#include "../rail_map.h"
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    11
#include "dbg_helpers.h"
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    12
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    13
/** Trackdir & TrackdirBits short names. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    14
static const char* trackdir_names[] = {
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    15
	"NE", "SE", "UE", "LE", "LS", "RS", "rne", "rse",
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    16
	"SW", "NW", "UW", "LW", "LN", "RN", "rsw", "rnw",
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    17
};
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    18
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    19
/** Return name of given Trackdir. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    20
CStrA ValueStr(Trackdir td)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    21
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    22
	CStrA out;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    23
	out.Format("%d (%s)", td, ItemAtT(td, trackdir_names, "UNK", INVALID_TRACKDIR, "INV"));
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    24
	return out.Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    25
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    26
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    27
/** Return composed name of given TrackdirBits. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    28
CStrA ValueStr(TrackdirBits td_bits)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    29
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    30
	CStrA out;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    31
	out.Format("%d (%s)", td_bits, ComposeNameT(td_bits, trackdir_names, "UNK", INVALID_TRACKDIR_BIT, "INV").Data());
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    32
	return out.Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    33
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    34
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    35
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    36
/** DiagDirection short names. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    37
static const char* diagdir_names[] = {
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    38
	"NE", "SE", "SW", "NW",
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    39
};
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    40
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    41
/** Return name of given DiagDirection. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    42
CStrA ValueStr(DiagDirection dd)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    43
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    44
	CStrA out;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    45
	out.Format("%d (%s)", dd, ItemAtT(dd, diagdir_names, "UNK", INVALID_DIAGDIR, "INV"));
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    46
	return out.Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    47
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    48
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    49
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    50
/** SignalType short names. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    51
static const char* signal_type_names[] = {
9790
5d5c70e0334e (svn r13932) -Add [YAPP]: PBS signals added to the map array. The signals are drawn using the old Patch-like PBS sprites. (michi_cc)
rubidium
parents: 9154
diff changeset
    52
	"NORMAL", "ENTRY", "EXIT", "COMBO", "PBS", "NOENTRY",
7118
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    53
};
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    54
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    55
/** Return name of given SignalType. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    56
CStrA ValueStr(SignalType t)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    57
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    58
	CStrA out;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    59
	out.Format("%d (%s)", t, ItemAtT(t, signal_type_names, "UNK"));
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    60
	return out.Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    61
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    62
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    63
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    64
/** Translate TileIndex into string. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    65
CStrA TileStr(TileIndex tile)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    66
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    67
	CStrA out;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    68
	out.Format("0x%04X (%d, %d)", tile, TileX(tile), TileY(tile));
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    69
	return out.Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    70
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    71
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    72
/** Keep track of the last assigned type_id. Used for anti-recursion. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    73
/*static*/ size_t& DumpTarget::LastTypeId()
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    74
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    75
	static size_t last_type_id = 0;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    76
	return last_type_id;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    77
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    78
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    79
/** Return structured name of the current class/structure. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    80
CStrA DumpTarget::GetCurrentStructName()
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    81
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    82
	CStrA out;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    83
	if (!m_cur_struct.empty()) {
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    84
		// we are inside some named struct, return its name
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    85
		out = m_cur_struct.top();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    86
	}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    87
	return out.Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    88
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    89
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    90
/**
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    91
 * Find the given instance in our anti-recursion repository.
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    92
 * Return true and set name when object was found.
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    93
 */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    94
bool DumpTarget::FindKnownName(size_t type_id, const void *ptr, CStrA &name)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    95
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    96
	KNOWN_NAMES::const_iterator it = m_known_names.find(KnownStructKey(type_id, ptr));
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    97
	if (it != m_known_names.end()) {
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    98
		/* we have found it */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    99
		name = (*it).second;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   100
		return true;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   101
	}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   102
	return false;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   103
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   104
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   105
/** Write some leading spaces into the output. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   106
void DumpTarget::WriteIndent()
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   107
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   108
	int num_spaces = 2 * m_indent;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   109
	memset(m_out.GrowSizeNC(num_spaces), ' ', num_spaces);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   110
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   111
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   112
/** Write a line with indent at the beginning and <LF> at the end. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   113
void DumpTarget::WriteLine(const char *format, ...)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   114
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   115
	WriteIndent();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   116
	va_list args;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   117
	va_start(args, format);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   118
	m_out.AddFormatL(format, args);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   119
	va_end(args);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   120
	m_out.AppendStr("\n");
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   121
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   122
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   123
/** Write 'name = value' with indent and new-line. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   124
void DumpTarget::WriteValue(const char *name, const char *value_str)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   125
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   126
	WriteIndent();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   127
	m_out.AddFormat("%s = %s\n", name, value_str);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   128
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   129
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   130
/** Write name & TileIndex to the output. */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   131
void DumpTarget::WriteTile(const char *name, TileIndex tile)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   132
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   133
	WriteIndent();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   134
	m_out.AddFormat("%s = %s\n", name, TileStr(tile).Data());
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   135
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   136
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   137
/**
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   138
 * Open new structure (one level deeper than the current one) 'name = {<LF>'.
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   139
 */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   140
void DumpTarget::BeginStruct(size_t type_id, const char *name, const void *ptr)
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   141
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   142
	/* make composite name */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   143
	CStrA cur_name = GetCurrentStructName().Transfer();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   144
	if (cur_name.Size() > 0) {
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   145
		/* add name delimiter (we use structured names) */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   146
		cur_name.AppendStr(".");
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   147
	}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   148
	cur_name.AppendStr(name);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   149
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   150
	/* put the name onto stack (as current struct name) */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   151
	m_cur_struct.push(cur_name);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   152
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   153
	/* put it also to the map of known structures */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   154
	m_known_names.insert(KNOWN_NAMES::value_type(KnownStructKey(type_id, ptr), cur_name));
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   155
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   156
	WriteIndent();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   157
	m_out.AddFormat("%s = {\n", name);
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   158
	m_indent++;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   159
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   160
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   161
/**
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   162
 * Close structure '}<LF>'.
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   163
 */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   164
void DumpTarget::EndStruct()
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   165
{
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   166
	m_indent--;
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   167
	WriteIndent();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   168
	m_out.AddFormat("}\n");
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   169
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   170
	/* remove current struct name from the stack */
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   171
	m_cur_struct.pop();
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   172
}
78372bbb200b (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   173