summaryrefslogtreecommitdiff
path: root/cpp/src/FreezeScript/Error.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-01-16 22:22:44 +0000
committerMark Spruiell <mes@zeroc.com>2004-01-16 22:22:44 +0000
commit00081d77200a08baac2e62cc2797c7530caacea3 (patch)
tree69a638dc86939389e9c810946a7d0fef20a31cd4 /cpp/src/FreezeScript/Error.cpp
parentadding ClassDef::isA (diff)
downloadice-00081d77200a08baac2e62cc2797c7530caacea3.tar.bz2
ice-00081d77200a08baac2e62cc2797c7530caacea3.tar.xz
ice-00081d77200a08baac2e62cc2797c7530caacea3.zip
initial check-in
Diffstat (limited to 'cpp/src/FreezeScript/Error.cpp')
-rw-r--r--cpp/src/FreezeScript/Error.cpp193
1 files changed, 193 insertions, 0 deletions
diff --git a/cpp/src/FreezeScript/Error.cpp b/cpp/src/FreezeScript/Error.cpp
new file mode 100644
index 00000000000..7262827c1d6
--- /dev/null
+++ b/cpp/src/FreezeScript/Error.cpp
@@ -0,0 +1,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 Exception(__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);
+}