src/misc/dbg_helpers.cpp
author rubidium
Sun, 01 Jun 2008 16:45:32 +0000
branch0.6
changeset 10801 3ad9dfb5430d
parent 8619 c2434269c3eb
child 10429 1b99254f9607
permissions -rw-r--r--
(svn r13352) [0.6] -Backport from trunk (r13348, r13222, r13221, r13217):
- Fix: Industry tiles would sometimes tell they need a 'level' slope when they do not want the slope (r13348)
- Fix: Attempts to make the old AI perform better (r13217, r13221, r13222)
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
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     3
/** @file dbg_helpers.cpp */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     4
#include "../stdafx.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8596
diff changeset
     5
#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
     6
#include "../direction_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
     7
#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
     8
#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
     9
#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
    10
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    11
/** 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
    12
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
    13
	"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
    14
	"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
    15
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    16
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    17
/** 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
    18
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
    19
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    20
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    21
	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
    22
	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
    23
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    24
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    25
/** 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
    26
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
    27
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    28
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    29
	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
    30
	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
    31
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    32
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
/** 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
    35
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
    36
	"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
    37
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    38
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    39
/** 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
    40
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
    41
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    42
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    43
	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
    44
	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
    45
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    46
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
/** 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
    49
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
    50
	"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
    51
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    52
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    53
/** 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
    54
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
    55
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    56
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    57
	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
    58
	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
    59
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    60
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
/** 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
    63
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
    64
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    65
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    66
	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
    67
	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
    68
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    69
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    70
/** 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
    71
/*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
    72
{
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 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
    74
	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
    75
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    76
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    77
/** 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
    78
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
    79
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    80
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    81
	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
    82
		// 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
    83
		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
    84
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    85
	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
    86
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    87
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
 * 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
    90
 * 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
    91
 */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    92
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
    93
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    94
	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
    95
	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
    96
		/* 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
    97
		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
    98
		return true;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    99
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   100
	return false;
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
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   103
/** 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
   104
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
   105
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   106
	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
   107
	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
   108
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   109
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   110
/** 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
   111
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
   112
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   113
	WriteIndent();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   114
	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
   115
	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
   116
	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
   117
	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
   118
	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
   119
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   120
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   121
/** 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
   122
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
   123
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   124
	WriteIndent();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   125
	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
   126
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   127
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   128
/** 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
   129
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
   130
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   131
	WriteIndent();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   132
	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
   133
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   134
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
 * 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
   137
 */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   138
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
   139
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   140
	/* 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
   141
	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
   142
	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
   143
		/* 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
   144
		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
   145
	}
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(name);
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
	/* 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
   149
	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
   150
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   151
	/* 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
   152
	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
   153
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   154
	WriteIndent();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   155
	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
   156
	m_indent++;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   157
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   158
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
 * 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
   161
 */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   162
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
   163
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   164
	m_indent--;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   165
	WriteIndent();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   166
	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
   167
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   168
	/* 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
   169
	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
   170
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   171