public:
// Construct a yaml Input object from a StringRef and optional user-data.
Input(StringRef InputContent, void *Ctxt=NULL);
-
+ ~Input();
+
// Check if there was an syntax or semantic error during parsing.
llvm::error_code error();
class HNode {
public:
HNode(Node *n) : _node(n) { }
+ virtual ~HNode() { }
static inline bool classof(const HNode *) { return true; }
Node *_node;
class EmptyHNode : public HNode {
public:
EmptyHNode(Node *n) : HNode(n) { }
+ virtual ~EmptyHNode() {}
static inline bool classof(const HNode *n) {
return NullNode::classof(n->_node);
}
class ScalarHNode : public HNode {
public:
ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
+ virtual ~ScalarHNode() { }
StringRef value() const { return _value; }
class MapHNode : public HNode {
public:
MapHNode(Node *n) : HNode(n) { }
+ virtual ~MapHNode();
static inline bool classof(const HNode *n) {
return MappingNode::classof(n->_node);
class SequenceHNode : public HNode {
public:
SequenceHNode(Node *n) : HNode(n) { }
+ virtual ~SequenceHNode();
static inline bool classof(const HNode *n) {
return SequenceNode::classof(n->_node);
void nextDocument();
private:
- llvm::yaml::Stream *Strm;
- llvm::SourceMgr SrcMgr;
+ llvm::SourceMgr SrcMgr; // must be before Strm
+ OwningPtr<llvm::yaml::Stream> Strm;
+ OwningPtr<HNode> TopNode;
llvm::error_code EC;
- llvm::BumpPtrAllocator Allocator;
+ llvm::BumpPtrAllocator StringAllocator;
llvm::yaml::document_iterator DocIterator;
std::vector<bool> BitValuesUsed;
HNode *CurrentNode;
// Input
//===----------------------------------------------------------------------===//
-Input::Input(StringRef InputContent, void *Ctxt) : IO(Ctxt), CurrentNode(NULL) {
- Strm = new Stream(InputContent, SrcMgr);
+Input::Input(StringRef InputContent, void *Ctxt)
+ : IO(Ctxt),
+ Strm(new Stream(InputContent, SrcMgr)),
+ CurrentNode(NULL) {
DocIterator = Strm->begin();
}
+Input::~Input() {
+
+}
+
error_code Input::error() {
return EC;
}
++DocIterator;
return setCurrentDocument();
}
- CurrentNode = this->createHNodes(N);
+ TopNode.reset(this->createHNodes(N));
+ CurrentNode = TopNode.get();
return true;
}
return false;
if (!StringStorage.empty()) {
// Copy string to permanent storage
unsigned Len = StringStorage.size();
- char *Buf = Allocator.Allocate<char>(Len);
+ char *Buf = StringAllocator.Allocate<char>(Len);
memcpy(Buf, &StringStorage[0], Len);
KeyStr = StringRef(Buf, Len);
}
- return new (Allocator) ScalarHNode(N, KeyStr);
+ return new ScalarHNode(N, KeyStr);
} else if (SequenceNode *SQ = dyn_cast<SequenceNode>(N)) {
- SequenceHNode *SQHNode = new (Allocator) SequenceHNode(N);
+ SequenceHNode *SQHNode = new SequenceHNode(N);
for (SequenceNode::iterator i = SQ->begin(), End = SQ->end(); i != End;
++i) {
HNode *Entry = this->createHNodes(i);
}
return SQHNode;
} else if (MappingNode *Map = dyn_cast<MappingNode>(N)) {
- MapHNode *mapHNode = new (Allocator) MapHNode(N);
+ MapHNode *mapHNode = new MapHNode(N);
for (MappingNode::iterator i = Map->begin(), End = Map->end(); i != End;
++i) {
ScalarNode *KeyScalar = dyn_cast<ScalarNode>(i->getKey());
if (!StringStorage.empty()) {
// Copy string to permanent storage
unsigned Len = StringStorage.size();
- char *Buf = Allocator.Allocate<char>(Len);
+ char *Buf = StringAllocator.Allocate<char>(Len);
memcpy(Buf, &StringStorage[0], Len);
KeyStr = StringRef(Buf, Len);
}
}
return mapHNode;
} else if (isa<NullNode>(N)) {
- return new (Allocator) EmptyHNode(N);
+ return new EmptyHNode(N);
} else {
setError(N, "unknown node kind");
return NULL;
this->setError(CurrentNode, Message);
}
+Input::MapHNode::~MapHNode() {
+ for (MapHNode::NameToNode::iterator i = Mapping.begin(), End = Mapping.end();
+ i != End; ++i) {
+ delete i->second;
+ }
+}
+
+Input::SequenceHNode::~SequenceHNode() {
+ for (std::vector<HNode*>::iterator i = Entries.begin(), End = Entries.end();
+ i != End; ++i) {
+ delete *i;
+ }
+}
+
+
+
//===----------------------------------------------------------------------===//
// Output
//===----------------------------------------------------------------------===//