13 std::vector<std::pair<std::string, std::string>> _attributes;
14 std::vector<Node> _children;
16 static std::string Escape(std::string s) {
18 for (
const auto c : s) {
19 if (!std::isprint(
c)) {
20 ss <<
"&#" <<
static_cast<int>(
c) <<
';';
53 explicit Node(std::string
tag, std::string
name) : _tag(std::move(
tag)), _name(std::move(
name)) {}
59 std::string &
tag() {
return _tag; }
65 std::string
tag()
const {
return _tag; }
71 std::string&
name() {
return _name; }
77 std::string
name()
const {
return _name; }
83 std::vector<std::pair<std::string, std::string>> &
attributes() {
return _attributes; }
89 const std::vector<std::pair<std::string, std::string>> &
attributes()
const {
return _attributes; }
95 std::vector<Node> &
children() {
return _children; }
101 const std::vector<Node> &
children()
const {
return _children; }
107 void print(llvm::raw_ostream &os)
const;
125 Node *
insert(std::deque<std::string> &path,
const std::string &
tag);
138 Tree() : _root(
"assembly",
"") {}
A node for symbol tree. It represents just simple XML serializer.
std::vector< std::pair< std::string, std::string > > & attributes()
Gets attributes of node.
void print(llvm::raw_ostream &os) const
Serialize subtree as XML to stream.
const std::vector< std::pair< std::string, std::string > > & attributes() const
Gets attributes of node as readonly.
Node * insert(std::deque< std::string > &path, const std::string &tag)
Inserts new node at given path (first element of path is id of this node)
std::string & name()
Gets a name of node.
const std::vector< Node > & children() const
Gets children of node as readonly.
std::string tag() const
Gets a tag of node as readonly.
std::string & tag()
Gets a tag of node.
std::vector< Node > & children()
Gets children of node.
Node(std::string tag, std::string name)
Creates new node.
std::string name() const
Gets a name of node as readonly.
Node * insert_inplace(std::deque< std::string > &path, const std::string &tag)
Inserts new node in-place at given path (first element of path is not id of this node)
Node & root()
Gets a root node of the tree.