forked from MoSync/MoSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstabs_builtins.cpp
148 lines (115 loc) · 5.21 KB
/
stabs_builtins.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* Copyright (C) 2009 Mobile Sorcery AB
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, version 2, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
//todo: cleanup
#define LOGGING_ENABLED
#define CONFIG_H
#include "helpers/helpers.h"
#include "stabs_builtins.h"
#define DECLARE_BUILTIN_BASE(name, id, size, attrib) static class id : public Builtin {\
public:\
id() : Builtin(#name, size, e##id) {}\
void printMI(printfPtr, const void*, TypeBase::PrintFormat) const attrib;\
} s##id;
#if defined(_MSC_VER) || defined(__SYMBIAN32__)
#define BROKEN_BASE_ATTRIB
#elif defined(__GNUC__)
#define BROKEN_BASE_ATTRIB __attribute((noreturn))
#else
#error Unsupported platform!
#endif
#define DECLARE_BUILTIN(name, id) DECLARE_BUILTIN_BASE(name, id, sizeof(name),)
#define DECLARE_BROKEN_BUILTIN(name, id) DECLARE_BUILTIN_BASE(name, id, 0, BROKEN_BASE_ATTRIB)
BUILTINS(DECLARE_BUILTIN, DECLARE_BUILTIN);
BROKEN_BUILTINS(DECLARE_BROKEN_BUILTIN);
static class Bool : public Builtin {
public:
Bool() : Builtin("bool", 0, eBool) {}
void printMI(printfPtr, const void*, TypeBase::PrintFormat) const;
} sBool;
static class VTablePtr : public Builtin {
public:
VTablePtr() : Builtin("__vtbl_ptr_type", 4, eVTablePtr) {}
void printMI(printfPtr, const void*, TypeBase::PrintFormat) const;
} sVTablePtr;
#define ARR_BUILTIN(name, id) {#name, &s##id}
#define COMMA_ARR_BUILTIN(name, id) ,ARR_BUILTIN(name, id)
BUILTINdecl sBuiltins[] = {
BUILTINS(ARR_BUILTIN, COMMA_ARR_BUILTIN)
BROKEN_BUILTINS(COMMA_ARR_BUILTIN),
{"_Bool", &sBool},
{"bool", &sBool},
{"__vtbl_ptr_type", &sVTablePtr}
};
const int snBuiltins = sizeof(sBuiltins) / sizeof(BUILTINdecl);
void Int::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<int>(pf, data, "%i", fmt, TypeBase::eDecimal);
}
void Char::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
if(fmt==eNatural) {
printPrimitiveByFormat<char>(pf, data, "%i", eDecimal, eDecimal);
char c = *(char*)data;
if(c>=0 && c<=32) pf(" \'\\\\%o\'", c);
else pf(" \'%c\'", c);
} else {
printPrimitiveByFormat<char>(pf, data, "%i", fmt, fmt);
}
}
void LongInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<int>(pf, data, "%i", fmt, TypeBase::eDecimal);
}
void UnsignedInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<int>(pf, data, "%u", fmt, TypeBase::eDecimal);
}
void LongUnsignedInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<unsigned int>(pf, data, "%u", fmt, TypeBase::eDecimal);
}
void LongLongInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<s64>(pf, data, "%"INT64PREFIX"i", fmt, TypeBase::eDecimal);
}
void LongLongUnsignedInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<u64>(pf, data, "%"INT64PREFIX"u", fmt, TypeBase::eDecimal);
}
void ShortInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<short>(pf, data, "%i", fmt, TypeBase::eDecimal);
}
void ShortUnsignedInt::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<unsigned short>(pf, data, "%u", fmt, TypeBase::eDecimal);
}
void SignedChar::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<char>(pf, data, "%c", fmt, TypeBase::eDecimal);
}
void UnsignedChar::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<unsigned char>(pf, data, "%u", fmt, TypeBase::eDecimal);
}
void Float::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
if(fmt == TypeBase::eDecimal || fmt == TypeBase::eNatural) pf("%f", *(float*)data);
else pf("0");
}
void Double::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
if(fmt == TypeBase::eDecimal || fmt == TypeBase::eNatural) pf("%f", *(double*)data);
else pf("0");
}
#define BROKEN_BUILTIN_FUNCTIONS(name, id) \
void id::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const { \
DEBIG_PHAT_ERROR; }
BROKEN_BUILTINS(BROKEN_BUILTIN_FUNCTIONS);
void Bool::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<bool>(pf, data, "%i", fmt, TypeBase::eDecimal);
}
void VTablePtr::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<const void*>(pf, data, "%p", fmt, TypeBase::eDecimal);
}
void Wchar::printMI(printfPtr pf, const void* data, TypeBase::PrintFormat fmt) const {
printPrimitiveByFormat<wchar_t>(pf, data, "%C", fmt, TypeBase::eDecimal);
}