X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FYAMLTraits.cpp;h=1e42b63e8d540063e43e6c60d751db6dec3e8b29;hb=fe532525cc4912ec0d1b4e91fa0396122dd087b3;hp=a31c31915a170eda5e8112190a092c8fc94efe45;hpb=ae3ce26f995f4747516a756f73d152c7188ff43b;p=oota-llvm.git diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp index a31c31915a1..1e42b63e8d5 100644 --- a/lib/Support/YAMLTraits.cpp +++ b/lib/Support/YAMLTraits.cpp @@ -40,11 +40,17 @@ void IO::setContext(void *Context) { // 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; } @@ -65,7 +71,8 @@ bool Input::setCurrentDocument() { ++DocIterator; return setCurrentDocument(); } - CurrentNode = this->createHNodes(N); + TopNode.reset(this->createHNodes(N)); + CurrentNode = TopNode.get(); return true; } return false; @@ -271,13 +278,13 @@ Input::HNode *Input::createHNodes(Node *N) { if (!StringStorage.empty()) { // Copy string to permanent storage unsigned Len = StringStorage.size(); - char *Buf = Allocator.Allocate(Len); + char *Buf = StringAllocator.Allocate(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(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); @@ -287,7 +294,7 @@ Input::HNode *Input::createHNodes(Node *N) { } return SQHNode; } else if (MappingNode *Map = dyn_cast(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(i->getKey()); @@ -296,7 +303,7 @@ Input::HNode *Input::createHNodes(Node *N) { if (!StringStorage.empty()) { // Copy string to permanent storage unsigned Len = StringStorage.size(); - char *Buf = Allocator.Allocate(Len); + char *Buf = StringAllocator.Allocate(Len); memcpy(Buf, &StringStorage[0], Len); KeyStr = StringRef(Buf, Len); } @@ -307,7 +314,7 @@ Input::HNode *Input::createHNodes(Node *N) { } return mapHNode; } else if (isa(N)) { - return new (Allocator) EmptyHNode(N); + return new EmptyHNode(N); } else { setError(N, "unknown node kind"); return NULL; @@ -315,7 +322,7 @@ Input::HNode *Input::createHNodes(Node *N) { } bool Input::MapHNode::isValidKey(StringRef Key) { - for (SmallVector::iterator i = ValidKeys.begin(), + for (SmallVectorImpl::iterator i = ValidKeys.begin(), End = ValidKeys.end(); i != End; ++i) { if (Key.equals(*i)) return true; @@ -327,6 +334,22 @@ void Input::setError(const Twine &Message) { 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::iterator i = Entries.begin(), End = Entries.end(); + i != End; ++i) { + delete *i; + } +} + + + //===----------------------------------------------------------------------===// // Output //===----------------------------------------------------------------------===// @@ -411,8 +434,8 @@ void Output::postflightElement(void *) { } unsigned Output::beginFlowSequence() { - this->newLineCheck(); StateStack.push_back(inFlowSeq); + this->newLineCheck(); ColumnAtFlowStart = Column; output("[ "); NeedFlowSequenceComma = false; @@ -516,7 +539,7 @@ void Output::output(StringRef s) { void Output::outputUpToEndOfLine(StringRef s) { this->output(s); - if (StateStack.back() != inFlowSeq) + if (StateStack.empty() || StateStack.back() != inFlowSeq) NeedsNewLine = true; }