src/misc/dbg_helpers.cpp
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 23:20:33 +0300
changeset 11184 88c967f1422b
parent 10473 ad730880e443
permissions -rw-r--r--
add an empty bin/cache dir
7618
99822745fcfd (svn r10395) -Fix [YAPF]: missing include + some signed/unsigned comparison warnings
KUDr
parents: 7614
diff changeset
     1
/* $Id$ */
7614
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     2
10429
1b99254f9607 (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: 8619
diff changeset
     3
/** @file dbg_helpers.cpp Helpers for outputting debug information. */
1b99254f9607 (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: 8619
diff changeset
     4
7614
a70f01c9eb57 (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"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8596
diff changeset
     6
#include "../openttd.h"
8596
27646407e0bc (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: 7618
diff changeset
     7
#include "../direction_type.h"
10473
ad730880e443 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 10429
diff changeset
     8
#include "../strings_type.h"
7614
a70f01c9eb57 (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"
a70f01c9eb57 (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"
a70f01c9eb57 (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"
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    12
a70f01c9eb57 (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. */
a70f01c9eb57 (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[] = {
a70f01c9eb57 (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",
a70f01c9eb57 (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",
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    17
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    18
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    21
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    22
	CStrA out;
a70f01c9eb57 (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"));
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    25
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    26
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    29
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    30
	CStrA out;
a70f01c9eb57 (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());
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    33
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    34
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    35
a70f01c9eb57 (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. */
a70f01c9eb57 (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[] = {
a70f01c9eb57 (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",
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    39
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    40
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    43
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    44
	CStrA out;
a70f01c9eb57 (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"));
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    47
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    48
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    49
a70f01c9eb57 (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. */
a70f01c9eb57 (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[] = {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    52
	"NORMAL", "ENTRY", "EXIT", "COMBO",
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    53
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    54
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    57
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    58
	CStrA out;
a70f01c9eb57 (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"));
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    61
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    62
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    63
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    66
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    67
	CStrA out;
a70f01c9eb57 (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));
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    70
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    71
a70f01c9eb57 (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. */
a70f01c9eb57 (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()
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    74
{
a70f01c9eb57 (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;
a70f01c9eb57 (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;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    77
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    78
a70f01c9eb57 (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. */
a70f01c9eb57 (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()
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    81
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    82
	CStrA out;
a70f01c9eb57 (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()) {
a70f01c9eb57 (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
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    86
	}
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    88
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    89
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    90
/**
a70f01c9eb57 (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.
a70f01c9eb57 (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.
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    93
 */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    95
{
a70f01c9eb57 (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));
a70f01c9eb57 (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()) {
a70f01c9eb57 (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 */
a70f01c9eb57 (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;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   100
		return true;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   101
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   102
	return false;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   103
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   104
a70f01c9eb57 (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. */
a70f01c9eb57 (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()
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   107
{
a70f01c9eb57 (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;
a70f01c9eb57 (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);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   110
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   111
a70f01c9eb57 (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. */
a70f01c9eb57 (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, ...)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   114
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   115
	WriteIndent();
a70f01c9eb57 (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;
a70f01c9eb57 (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);
a70f01c9eb57 (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);
a70f01c9eb57 (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);
a70f01c9eb57 (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");
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   121
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   122
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   125
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   126
	WriteIndent();
a70f01c9eb57 (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);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   128
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   129
a70f01c9eb57 (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. */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   132
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   133
	WriteIndent();
a70f01c9eb57 (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());
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   135
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   136
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   137
/**
a70f01c9eb57 (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>'.
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   139
 */
a70f01c9eb57 (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)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   141
{
a70f01c9eb57 (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 */
a70f01c9eb57 (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();
a70f01c9eb57 (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) {
a70f01c9eb57 (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) */
a70f01c9eb57 (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(".");
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   147
	}
a70f01c9eb57 (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);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   149
a70f01c9eb57 (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) */
a70f01c9eb57 (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);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   152
a70f01c9eb57 (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 */
a70f01c9eb57 (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));
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   155
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   156
	WriteIndent();
a70f01c9eb57 (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);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   158
	m_indent++;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   159
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   160
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   161
/**
a70f01c9eb57 (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>'.
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   163
 */
a70f01c9eb57 (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()
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   165
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   166
	m_indent--;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   167
	WriteIndent();
a70f01c9eb57 (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");
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   169
a70f01c9eb57 (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 */
a70f01c9eb57 (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();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   172
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   173