decompiler  1.0.0
Classes | Typedefs | Functions
xml.hh File Reference

Lightweight (and incomplete) XML parser for marshaling data to and from the decompiler. More...

#include "types.h"
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>

Classes

class  Attributes
 The attributes for a single XML element. More...
 
class  ContentHandler
 The SAX interface for parsing XML documents. More...
 
class  Element
 An XML element. A node in the DOM tree. More...
 
class  Document
 A complete in-memory XML document. More...
 
class  TreeHandler
 A SAX interface implementation for constructing an in-memory DOM model. More...
 
class  DocumentStorage
 A container for parsed XML documents. More...
 
struct  XmlError
 An exception thrown by the XML parser. More...
 

Typedefs

typedef void * Locator
 Placeholder for a document locator object.
 
typedef vector< Element * > List
 A list of XML elements.
 

Functions

int4 xml_parse (istream &i, ContentHandler *hand, int4 dbg=0)
 Start-up the XML parser given a stream and a handler. More...
 
Documentxml_tree (istream &i)
 Parse the given XML stream into an in-memory document. More...
 
void xml_escape (ostream &s, const char *str)
 Send the given character array to a stream, escaping characters with special XML meaning. More...
 
void a_v (ostream &s, const string &attr, const string &val)
 Output an XML attribute name/value pair to stream. More...
 
void a_v_i (ostream &s, const string &attr, intb val)
 Output the given signed integer as an XML attribute value. More...
 
void a_v_u (ostream &s, const string &attr, uintb val)
 Output the given unsigned integer as an XML attribute value. More...
 
void a_v_b (ostream &s, const string &attr, bool val)
 Output the given boolean value as an XML attribute. More...
 
bool xml_readbool (const string &attr)
 Read an XML attribute value as a boolean. More...
 

Detailed Description

Lightweight (and incomplete) XML parser for marshaling data to and from the decompiler.

Function Documentation

void a_v ( ostream &  s,
const string &  attr,
const string &  val 
)
inline
void a_v_b ( ostream &  s,
const string &  attr,
bool  val 
)
inline
void a_v_i ( ostream &  s,
const string &  attr,
intb  val 
)
inline
void a_v_u ( ostream &  s,
const string &  attr,
uintb  val 
)
inline
void xml_escape ( ostream &  s,
const char *  str 
)

Send the given character array to a stream, escaping characters with special XML meaning.

This makes the following character substitutions:

  • '<' => "&lt;"
  • '>' => "&gt;"
  • '&' => "&amp;"
  • '"' => "&quot;"
  • '\'' => "&apos;"
Parameters
sis the stream to write to
stris the given character array to escape

Referenced by a_v(), Comment::saveXml(), CPoolRecord::saveXml(), and XmlError::XmlError().

int4 xml_parse ( istream &  i,
ContentHandler hand,
int4  dbg = 0 
)

Start-up the XML parser given a stream and a handler.

This runs the low-level XML parser.

Parameters
iis the given stream to get character data from
handis the ContentHandler that stores or processes the XML content events
dbgis non-zero if the parser should output debug information during its parse
Returns
0 if there is no error during parsing or a (non-zero) error condition

Referenced by XmlError::XmlError().

bool xml_readbool ( const string &  attr)
inline
Document* xml_tree ( istream &  i)

Parse the given XML stream into an in-memory document.

The stream is parsed using the standard ContentHandler for producing an in-memory DOM representation of the XML document.

Parameters
iis the given stream
Returns
the in-memory XML document

Referenced by SleighArchitecture::loadLanguageDescription(), ArchitectureGhidra::readXMLStream(), and XmlError::XmlError().