summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/xml/XmlParser.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp
index ef738d8..78d9df8 100644
--- a/src/plugins/xml/XmlParser.cpp
+++ b/src/plugins/xml/XmlParser.cpp
@@ -131,11 +131,12 @@ public:
!(defaultValue.isObject() && defaultValue.asObject() == nullptr);
Rooted<StructType> structType = scope().getLeaf().cast<StructType>();
- Rooted<Attribute> attribute = structType->createAttribute(
- name, defaultValue, optional, logger());
+ Rooted<Attribute> attribute =
+ structType->createAttribute(name, defaultValue, optional, logger());
// Try to resolve the type
- scope().resolve<Type>(type, logger(),
+ scope().resolve<Type>(
+ type, logger(),
[attribute](Handle<Type> type, Logger &logger) mutable {
attribute->setType(type, logger);
},
@@ -234,16 +235,23 @@ public:
/* Adapter Expat -> ParserStack */
+struct XMLParserUserData {
+ SourceId sourceId;
+};
+
static SourceLocation syncLoggerPosition(XML_Parser p)
{
+ // Fetch the parser stack and the associated user data
+ ParserStack *stack = static_cast<ParserStack *>(XML_GetUserData(p));
+ XMLParserUserData *ud =
+ static_cast<XMLParserUserData *>(stack->getUserData());
+
// Fetch the current location in the XML file
- int line = XML_GetCurrentLineNumber(p);
- int column = XML_GetCurrentColumnNumber(p);
size_t offs = XML_GetCurrentByteIndex(p);
- SourceLocation loc{line, column, offs};
- // Update the default location of the current logger instance
- ParserStack *stack = static_cast<ParserStack *>(XML_GetUserData(p));
+ // Build the source location and update the default location of the current
+ // logger instance
+ SourceLocation loc{ud->sourceId, offs};
stack->getContext().logger.setDefaultLocation(loc);
return loc;
}
@@ -270,9 +278,9 @@ static void xmlStartElementHandler(void *p, const XML_Char *name,
static void xmlEndElementHandler(void *p, const XML_Char *name)
{
XML_Parser parser = static_cast<XML_Parser>(p);
- syncLoggerPosition(parser);
-
ParserStack *stack = static_cast<ParserStack *>(XML_GetUserData(parser));
+
+ syncLoggerPosition(parser);
stack->end();
}
@@ -297,7 +305,10 @@ Rooted<Node> XmlParser::doParse(CharReader &reader, ParserContext &ctx)
// Create the parser stack instance and pass the reference to the state
// machine descriptor
- ParserStack stack{ctx, XML_HANDLERS};
+ XMLParserUserData data;
+ data.sourceId = reader.getSourceId();
+
+ ParserStack stack{ctx, XML_HANDLERS, &data};
XML_SetUserData(&p, &stack);
XML_UseParserAsHandlerArg(&p);
@@ -321,15 +332,14 @@ Rooted<Node> XmlParser::doParse(CharReader &reader, ParserContext &ctx)
// Parse the data and handle any XML error
if (!XML_ParseBuffer(&p, bytesRead, bytesRead == 0)) {
- // Fetch the current line number and column
- int line = XML_GetCurrentLineNumber(&p);
- int column = XML_GetCurrentColumnNumber(&p);
+ // Fetch the xml parser byte offset
size_t offs = XML_GetCurrentByteIndex(&p);
// Throw a corresponding exception
XML_Error code = XML_GetErrorCode(&p);
std::string msg = std::string{XML_ErrorString(code)};
- throw LoggableException{"XML: " + msg, line, column, offs};
+ throw LoggableException{"XML: " + msg,
+ SourceLocation{reader.getSourceId(), offs}};
}
// Abort once there are no more bytes in the stream