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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
// **********************************************************************
//
// Copyright (c) 2004
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice 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.
//
// **********************************************************************
#include <FreezeScript/Error.h>
#include <FreezeScript/Exception.h>
#include <FreezeScript/Util.h>
using namespace std;
//
// ErrorReporter
//
FreezeScript::ErrorReporter::ErrorReporter(ostream& out, bool suppress) :
_out(out), _suppress(suppress)
{
}
ostream&
FreezeScript::ErrorReporter::stream() const
{
return _out;
}
void
FreezeScript::ErrorReporter::warning(const string& msg)
{
ostringstream ostr;
if(!_descName.empty())
{
ostr << "warning in <" << _descName << "> descriptor, line " << _descLine << ": " << msg << endl;
}
else
{
ostr << "warning: " << msg << endl;
}
string warn = ostr.str();
if(_suppress)
{
map<string, bool>::iterator p = _warningHistory.find(warn);
if(p != _warningHistory.end())
{
return;
}
_warningHistory.insert(map<string, bool>::value_type(warn, true));
}
_out << warn;
}
void
FreezeScript::ErrorReporter::error(const string& msg)
{
ostringstream ostr;
if(!_descName.empty())
{
ostr << "error in <" << _descName << "> descriptor, line " << _descLine << ": " << msg << endl;
}
else
{
ostr << "error: " << msg << endl;
}
throw FailureException(__FILE__, __LINE__, ostr.str());
}
void
FreezeScript::ErrorReporter::typeMismatchError(const Slice::TypePtr& expected, const Slice::TypePtr& received,
bool fatal)
{
ostringstream ostr;
ostr << "type mismatch: expected " << typeToString(expected) << " but received " << typeToString(received);
if(fatal)
{
error(ostr.str());
}
else
{
warning(ostr.str());
}
}
void
FreezeScript::ErrorReporter::conversionError(const string& value, const Slice::TypePtr& type, bool fatal)
{
ostringstream ostr;
ostr << "unable to convert `" << value << "' to " << typeToString(type);
if(fatal)
{
error(ostr.str());
}
else
{
warning(ostr.str());
}
}
void
FreezeScript::ErrorReporter::rangeError(const string& value, const Slice::TypePtr& type, bool fatal)
{
ostringstream ostr;
ostr << "value `" << value << "' is out of range for type " << typeToString(type);
if(fatal)
{
error(ostr.str());
}
else
{
warning(ostr.str());
}
}
void
FreezeScript::ErrorReporter::expressionSyntaxError(const string& msg)
{
assert(!_expression.empty());
ostringstream ostr;
ostr << "syntax error in expression `" << _expression << "': " << msg;
error(ostr.str());
}
void
FreezeScript::ErrorReporter::descriptorError(const string& msg, int line)
{
ostringstream ostr;
ostr << "XML error on line " << line << ":" << endl << msg;
error(ostr.str());
}
void
FreezeScript::ErrorReporter::setDescriptor(const string& name, int line)
{
_descName = name;
_descLine = line;
}
void
FreezeScript::ErrorReporter::getDescriptor(string& name, int& line)
{
name = _descName;
line = _descLine;
}
void
FreezeScript::ErrorReporter::clearDescriptor()
{
_descName.clear();
}
void
FreezeScript::ErrorReporter::setExpression(const string& expr)
{
_expression = expr;
}
void
FreezeScript::ErrorReporter::clearExpression()
{
_expression.clear();
}
//
// DescriptorErrorContext
//
FreezeScript::DescriptorErrorContext::DescriptorErrorContext(const ErrorReporterPtr& errorReporter, const string& name,
int line) :
_errorReporter(errorReporter)
{
//
// Save the existing descriptor information before changing it.
//
_errorReporter->getDescriptor(_name, _line);
_errorReporter->setDescriptor(name, line);
}
FreezeScript::DescriptorErrorContext::~DescriptorErrorContext()
{
//
// Restore the original descriptor information.
//
_errorReporter->setDescriptor(_name, _line);
}
|