summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2003-10-22 00:55:27 +0000
committerMark Spruiell <mes@zeroc.com>2003-10-22 00:55:27 +0000
commit8139c19d39ca2af95acd96558b88055e40c2a367 (patch)
tree1d228d238a08e9de82836c457d8c3293d86a6ec9 /cpp/src
parentadding dictionary/sequence element access to grammar (diff)
downloadice-8139c19d39ca2af95acd96558b88055e40c2a367.tar.bz2
ice-8139c19d39ca2af95acd96558b88055e40c2a367.tar.xz
ice-8139c19d39ca2af95acd96558b88055e40c2a367.zip
adding line number support
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IcePack/ApplicationBuilder.cpp21
-rw-r--r--cpp/src/IcePack/ComponentBuilder.cpp20
-rw-r--r--cpp/src/IcePack/ComponentBuilder.h6
-rw-r--r--cpp/src/IcePack/ServerBuilder.cpp12
-rw-r--r--cpp/src/IcePack/ServiceBuilder.cpp6
-rw-r--r--cpp/src/IceStorm/WeightedGraph.cpp20
-rw-r--r--cpp/src/IceXML/Parser.cpp86
7 files changed, 109 insertions, 62 deletions
diff --git a/cpp/src/IcePack/ApplicationBuilder.cpp b/cpp/src/IcePack/ApplicationBuilder.cpp
index f52ca661523..087158c779c 100644
--- a/cpp/src/IcePack/ApplicationBuilder.cpp
+++ b/cpp/src/IcePack/ApplicationBuilder.cpp
@@ -104,8 +104,8 @@ public:
ApplicationHandler(ApplicationBuilder&);
- virtual void startElement(const string&, const IceXML::Attributes&);
- virtual void endElement(const string&);
+ virtual void startElement(const string&, const IceXML::Attributes&, int, int);
+ virtual void endElement(const string&, int, int);
private:
@@ -124,9 +124,9 @@ IcePack::ApplicationHandler::ApplicationHandler(ApplicationBuilder& builder) :
}
void
-IcePack::ApplicationHandler::startElement(const string& name, const IceXML::Attributes& attrs)
+IcePack::ApplicationHandler::startElement(const string& name, const IceXML::Attributes& attrs, int line, int column)
{
- ComponentHandler::startElement(name, attrs);
+ ComponentHandler::startElement(name, attrs, line, column);
if(!isCurrentTargetDeployable())
{
return;
@@ -144,7 +144,9 @@ IcePack::ApplicationHandler::startElement(const string& name, const IceXML::Attr
{
if(!_currentNode.empty())
{
- throw IceXML::ParserException(__FILE__, __LINE__, "node element enclosed in a node element is not allowed");
+ ostringstream ostr;
+ ostr << "line " << line << ": node element enclosed in a node element is not allowed";
+ throw IceXML::ParserException(__FILE__, __LINE__, ostr.str());
}
_currentNode = getAttributeValue(attrs, "name");
@@ -163,8 +165,9 @@ IcePack::ApplicationHandler::startElement(const string& name, const IceXML::Attr
{
if(_currentNode.empty())
{
- throw IceXML::ParserException(__FILE__, __LINE__,
- "server element is not allowed outside the scope of a node element");
+ ostringstream ostr;
+ ostr << "line " << line << ": server element is not allowed outside the scope of a node element";
+ throw IceXML::ParserException(__FILE__, __LINE__, ostr.str());
}
string serverName = getAttributeValue(attrs, "name");
@@ -177,7 +180,7 @@ IcePack::ApplicationHandler::startElement(const string& name, const IceXML::Attr
}
void
-IcePack::ApplicationHandler::endElement(const string& name)
+IcePack::ApplicationHandler::endElement(const string& name, int line, int column)
{
if(isCurrentTargetDeployable())
{
@@ -188,7 +191,7 @@ IcePack::ApplicationHandler::endElement(const string& name)
}
}
- ComponentHandler::endElement(name);
+ ComponentHandler::endElement(name, line, column);
}
IcePack::ApplicationBuilder::ApplicationBuilder(const Ice::CommunicatorPtr& communicator,
diff --git a/cpp/src/IcePack/ComponentBuilder.cpp b/cpp/src/IcePack/ComponentBuilder.cpp
index 1dde83c33be..21671031c92 100644
--- a/cpp/src/IcePack/ComponentBuilder.cpp
+++ b/cpp/src/IcePack/ComponentBuilder.cpp
@@ -279,7 +279,7 @@ IcePack::ComponentHandler::ComponentHandler(ComponentBuilder& builder) :
}
void
-IcePack::ComponentHandler::startElement(const string& name, const IceXML::Attributes& attrs)
+IcePack::ComponentHandler::startElement(const string& name, const IceXML::Attributes& attrs, int line, int)
{
_elements.push("");
@@ -313,8 +313,9 @@ IcePack::ComponentHandler::startElement(const string& name, const IceXML::Attrib
{
if(!_currentAdapterId.empty())
{
- throw IceXML::ParserException(__FILE__, __LINE__,
- "Adapter element enclosed in an adapter element is not allowed");
+ ostringstream ostr;
+ ostr << "line " << line << ": Adapter element enclosed in an adapter element is not allowed";
+ throw IceXML::ParserException(__FILE__, __LINE__, ostr.str());
}
//
@@ -324,7 +325,9 @@ IcePack::ComponentHandler::startElement(const string& name, const IceXML::Attrib
string adapterName = getAttributeValue(attrs, "name");
if(adapterName.empty())
{
- throw IceXML::ParserException(__FILE__, __LINE__, "empty adapter name");
+ ostringstream ostr;
+ ostr << "line " << line << ": empty adapter name";
+ throw IceXML::ParserException(__FILE__, __LINE__, ostr.str());
}
_currentAdapterId = getAttributeValueWithDefault(attrs, "id", _builder.getDefaultAdapterId(adapterName));
}
@@ -338,15 +341,16 @@ IcePack::ComponentHandler::startElement(const string& name, const IceXML::Attrib
{
if(!_currentTarget.empty())
{
- throw IceXML::ParserException(__FILE__, __LINE__,
- "Target element enclosed in a target element is not allowed");
+ ostringstream ostr;
+ ostr << "line " << line << ": Target element enclosed in a target element is not allowed";
+ throw IceXML::ParserException(__FILE__, __LINE__, ostr.str());
}
_isCurrentTargetDeployable = _builder.isTargetDeployable(getAttributeValue(attrs, "name"));
}
}
void
-IcePack::ComponentHandler::endElement(const string& name)
+IcePack::ComponentHandler::endElement(const string& name, int, int)
{
_elements.pop();
@@ -366,7 +370,7 @@ IcePack::ComponentHandler::endElement(const string& name)
}
void
-IcePack::ComponentHandler::characters(const string& chars)
+IcePack::ComponentHandler::characters(const string& chars, int, int)
{
_elements.top().assign(chars);
}
diff --git a/cpp/src/IcePack/ComponentBuilder.h b/cpp/src/IcePack/ComponentBuilder.h
index bf4453bdf75..9e9bf442a80 100644
--- a/cpp/src/IcePack/ComponentBuilder.h
+++ b/cpp/src/IcePack/ComponentBuilder.h
@@ -49,9 +49,9 @@ public:
ComponentHandler(ComponentBuilder&);
- virtual void startElement(const std::string&, const IceXML::Attributes&);
- virtual void endElement(const std::string&);
- virtual void characters(const std::string&);
+ virtual void startElement(const std::string&, const IceXML::Attributes&, int, int);
+ virtual void endElement(const std::string&, int, int);
+ virtual void characters(const std::string&, int, int);
protected:
diff --git a/cpp/src/IcePack/ServerBuilder.cpp b/cpp/src/IcePack/ServerBuilder.cpp
index 2002d507e16..1b9827f04c3 100644
--- a/cpp/src/IcePack/ServerBuilder.cpp
+++ b/cpp/src/IcePack/ServerBuilder.cpp
@@ -192,8 +192,8 @@ public:
ServerHandler(ServerBuilder&);
- virtual void startElement(const string&, const IceXML::Attributes&);
- virtual void endElement(const string&);
+ virtual void startElement(const string&, const IceXML::Attributes&, int, int);
+ virtual void endElement(const string&, int, int);
private:
@@ -215,9 +215,9 @@ IcePack::ServerHandler::ServerHandler(ServerBuilder& builder) :
}
void
-IcePack::ServerHandler::startElement(const string& name, const IceXML::Attributes& attrs)
+IcePack::ServerHandler::startElement(const string& name, const IceXML::Attributes& attrs, int line, int column)
{
- ComponentHandler::startElement(name, attrs);
+ ComponentHandler::startElement(name, attrs, line, column);
if(!isCurrentTargetDeployable())
{
return;
@@ -289,7 +289,7 @@ IcePack::ServerHandler::startElement(const string& name, const IceXML::Attribute
}
void
-IcePack::ServerHandler::endElement(const string& name)
+IcePack::ServerHandler::endElement(const string& name, int line, int column)
{
if(isCurrentTargetDeployable())
{
@@ -315,7 +315,7 @@ IcePack::ServerHandler::endElement(const string& name)
}
}
- ComponentHandler::endElement(name);
+ ComponentHandler::endElement(name, line, column);
}
IcePack::ServerBuilder::ServerBuilder(const NodeInfoPtr& nodeInfo,
diff --git a/cpp/src/IcePack/ServiceBuilder.cpp b/cpp/src/IcePack/ServiceBuilder.cpp
index d84ad24f3a0..5617c02ccf6 100644
--- a/cpp/src/IcePack/ServiceBuilder.cpp
+++ b/cpp/src/IcePack/ServiceBuilder.cpp
@@ -28,7 +28,7 @@ public:
ServiceHandler(ServiceBuilder&);
- virtual void startElement(const string& name, const IceXML::Attributes& attrs);
+ virtual void startElement(const string&, const IceXML::Attributes&, int, int);
private:
@@ -44,9 +44,9 @@ IcePack::ServiceHandler::ServiceHandler(ServiceBuilder& builder) :
}
void
-IcePack::ServiceHandler::startElement(const string& name, const IceXML::Attributes& attrs)
+IcePack::ServiceHandler::startElement(const string& name, const IceXML::Attributes& attrs, int line, int column)
{
- ComponentHandler::startElement(name, attrs);
+ ComponentHandler::startElement(name, attrs, line, column);
if(!isCurrentTargetDeployable())
{
diff --git a/cpp/src/IceStorm/WeightedGraph.cpp b/cpp/src/IceStorm/WeightedGraph.cpp
index 4ecf3e9bd66..e9e69abd8cd 100644
--- a/cpp/src/IceStorm/WeightedGraph.cpp
+++ b/cpp/src/IceStorm/WeightedGraph.cpp
@@ -42,9 +42,9 @@ public:
{
}
- virtual void startElement(const string& name, const IceXML::Attributes& attrs);
- virtual void endElement(const string& name) { }
- virtual void characters(const string& chars) { }
+ virtual void startElement(const string&, const IceXML::Attributes&, int, int);
+ virtual void endElement(const string&, int, int) { }
+ virtual void characters(const string&, int, int) { }
private:
@@ -62,7 +62,7 @@ struct WeightedGraphParseException
} // End namespace IceStorm
void
-GraphHandler::startElement(const string& name, const IceXML::Attributes& attrs)
+GraphHandler::startElement(const string& name, const IceXML::Attributes& attrs, int line, int)
{
if(name == "vertex")
{
@@ -70,7 +70,9 @@ GraphHandler::startElement(const string& name, const IceXML::Attributes& attrs)
if(p == attrs.end())
{
WeightedGraphParseException ex;
- ex.reason = "<vertex> name attribute missing";
+ ostringstream ostr;
+ ostr << "line " << line << ": <vertex> name attribute missing";
+ ex.reason = ostr.str();
throw ex;
}
@@ -84,7 +86,9 @@ GraphHandler::startElement(const string& name, const IceXML::Attributes& attrs)
if(p == attrs.end())
{
WeightedGraphParseException ex;
- ex.reason = "<edge> source attribute missing";
+ ostringstream ostr;
+ ostr << "line " << line << ": <edge> source attribute missing";
+ ex.reason = ostr.str();
throw ex;
}
@@ -94,7 +98,9 @@ GraphHandler::startElement(const string& name, const IceXML::Attributes& attrs)
if(p == attrs.end())
{
WeightedGraphParseException ex;
- ex.reason = "<edge> target attribute missing";
+ ostringstream ostr;
+ ostr << "line " << line << ": <edge> target attribute missing";
+ ex.reason = ostr.str();
throw ex;
}
diff --git a/cpp/src/IceXML/Parser.cpp b/cpp/src/IceXML/Parser.cpp
index 24fe4c7d19d..f973ef03f27 100644
--- a/cpp/src/IceXML/Parser.cpp
+++ b/cpp/src/IceXML/Parser.cpp
@@ -65,11 +65,17 @@ IceXML::ParserException::ice_throw() const
throw *this;
}
+string
+IceXML::ParserException::reason() const
+{
+ return _reason;
+}
+
//
// Node
//
-IceXML::Node::Node(const NodePtr& parent, const string& name, const string& value) :
- _parent(parent), _name(name), _value(value)
+IceXML::Node::Node(const NodePtr& parent, const string& name, const string& value, int line, int column) :
+ _parent(parent), _name(name), _value(value), _line(line), _column(column)
{
}
@@ -108,22 +114,35 @@ IceXML::Node::getAttributes() const
}
string
-IceXML::Node::getAttribute(const string& name) const
+IceXML::Node::getAttribute(const string&) const
{
return string();
}
bool
-IceXML::Node::addChild(const NodePtr& child)
+IceXML::Node::addChild(const NodePtr&)
{
return false;
}
+int
+IceXML::Node::getLine() const
+{
+ return _line;
+}
+
+int
+IceXML::Node::getColumn() const
+{
+ return _column;
+}
+
//
// Element
//
-IceXML::Element::Element(const NodePtr& parent, const string& name, const Attributes& attributes) :
- Node(parent, name, ""), _attributes(attributes)
+IceXML::Element::Element(const NodePtr& parent, const string& name, const Attributes& attributes, int line,
+ int column) :
+ Node(parent, name, "", line, column), _attributes(attributes)
{
}
@@ -164,8 +183,8 @@ IceXML::Element::addChild(const NodePtr& child)
//
// Text
//
-IceXML::Text::Text(const NodePtr& parent, const string& value) :
- Node(parent, "", value)
+IceXML::Text::Text(const NodePtr& parent, const string& value, int line, int column) :
+ Node(parent, "", value, line, column)
{
}
@@ -177,7 +196,7 @@ IceXML::Text::~Text()
// Document
//
IceXML::Document::Document() :
- Node(0, "", "")
+ Node(0, "", "", 0, 0)
{
}
@@ -206,10 +225,10 @@ IceXML::Handler::~Handler()
}
void
-IceXML::Handler::error(const string& msg, int line, int col)
+IceXML::Handler::error(const string& msg, int line, int column)
{
ostringstream out;
- out << "XML error at input line " << line << ", column " << col << ":" << endl << msg;
+ out << "XML error at input line " << line << ", column " << column << ":" << endl << msg;
throw ParserException(__FILE__, __LINE__, out.str());
}
@@ -224,9 +243,9 @@ class DocumentBuilder : public Handler
public:
DocumentBuilder();
- virtual void startElement(const string&, const Attributes&);
- virtual void endElement(const string&);
- virtual void characters(const string&);
+ virtual void startElement(const string&, const Attributes&, int, int);
+ virtual void endElement(const string&, int, int);
+ virtual void characters(const string&, int, int);
DocumentPtr getDocument() const;
@@ -244,11 +263,11 @@ IceXML::DocumentBuilder::DocumentBuilder()
}
void
-IceXML::DocumentBuilder::startElement(const string& name, const Attributes& attributes)
+IceXML::DocumentBuilder::startElement(const string& name, const Attributes& attributes, int line, int column)
{
NodePtr parent = _nodeStack.front();
- Element* element = new Element(parent, name, attributes);
+ Element* element = new Element(parent, name, attributes, line, column);
bool b = parent->addChild(element);
assert(b);
@@ -256,17 +275,17 @@ IceXML::DocumentBuilder::startElement(const string& name, const Attributes& attr
}
void
-IceXML::DocumentBuilder::endElement(const string& name)
+IceXML::DocumentBuilder::endElement(const string& name, int, int)
{
assert(!_nodeStack.empty());
_nodeStack.pop_front();
}
void
-IceXML::DocumentBuilder::characters(const string& data)
+IceXML::DocumentBuilder::characters(const string& data, int line, int column)
{
NodePtr parent = _nodeStack.front();
- TextPtr text = new Text(parent, data);
+ TextPtr text = new Text(parent, data, line, column);
parent->addChild(text);
}
@@ -279,10 +298,16 @@ IceXML::DocumentBuilder::getDocument() const
//
// expat callbacks
//
+struct CallbackData
+{
+ XML_Parser parser;
+ Handler* handler;
+};
+
static void
startElementHandler(void* data, const XML_Char* name, const XML_Char** attr)
{
- Handler* handler = static_cast<Handler*>(data);
+ CallbackData* cb = static_cast<CallbackData*>(data);
Attributes attributes;
for(int i = 0; attr[i]; i += 2)
@@ -290,23 +315,29 @@ startElementHandler(void* data, const XML_Char* name, const XML_Char** attr)
attributes[attr[i]] = attr[i + 1];
}
- handler->startElement(name, attributes);
+ int line = XML_GetCurrentLineNumber(cb->parser);
+ int column = XML_GetCurrentColumnNumber(cb->parser);
+ cb->handler->startElement(name, attributes, line, column);
}
static void
endElementHandler(void* data, const XML_Char* name)
{
- Handler* handler = static_cast<Handler*>(data);
- handler->endElement(name);
+ CallbackData* cb = static_cast<CallbackData*>(data);
+ int line = XML_GetCurrentLineNumber(cb->parser);
+ int column = XML_GetCurrentColumnNumber(cb->parser);
+ cb->handler->endElement(name, line, column);
}
static void
characterDataHandler(void* data, const XML_Char* s, int len)
{
- Handler* handler = static_cast<Handler*>(data);
+ CallbackData* cb = static_cast<CallbackData*>(data);
string str(s, len);
- handler->characters(str);
+ int line = XML_GetCurrentLineNumber(cb->parser);
+ int column = XML_GetCurrentColumnNumber(cb->parser);
+ cb->handler->characters(str, line, column);
}
//
@@ -345,7 +376,10 @@ void
IceXML::Parser::parse(istream& in, Handler& handler)
{
XML_Parser parser = XML_ParserCreate(NULL);
- XML_SetUserData(parser, &handler);
+ CallbackData cb;
+ cb.parser = parser;
+ cb.handler = &handler;
+ XML_SetUserData(parser, &cb);
XML_SetElementHandler(parser, startElementHandler, endElementHandler);
XML_SetCharacterDataHandler(parser, characterDataHandler);