llvm.org GIT mirror llvm / 6c304f2
Make formatted_raw_ostream restore the buffer settings of the underlying stream when it is finished, so that clients don't have to do this manually. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78952 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
2 changed file(s) with 19 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
100100
101101 ~formatted_raw_ostream() {
102102 flush();
103 if (DeleteStream)
104 delete TheStream;
103 releaseStream();
105104 }
106
105
107106 void setStream(raw_ostream &Stream, bool Delete = false) {
108 if (DeleteStream)
109 delete TheStream;
107 releaseStream();
110108
111109 TheStream = &Stream;
112110 DeleteStream = Delete;
117115 // had been using, and tell TheStream not to do its own buffering.
118116 if (size_t BufferSize = TheStream->GetBufferSize())
119117 SetBufferSize(BufferSize);
118 else
119 SetUnbuffered();
120120 TheStream->SetUnbuffered();
121121
122122 Scanned = begin();
129129 /// recent I/O, even if the current column + minpad > newcol.
130130 ///
131131 void PadToColumn(unsigned NewCol, unsigned MinPad = 0);
132
133 private:
134 void releaseStream() {
135 // Delete the stream if needed. Otherwise, transfer the buffer
136 // settings from this raw_ostream back to the underlying stream.
137 if (!TheStream)
138 return;
139 if (DeleteStream)
140 delete TheStream;
141 else if (size_t BufferSize = GetBufferSize())
142 TheStream->SetBufferSize(BufferSize);
143 else
144 TheStream->SetUnbuffered();
145 }
132146 };
133147
134148 /// fouts() - This returns a reference to a formatted_raw_ostream for
20042004 }
20052005 void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
20062006 SlotTracker SlotTable(this);
2007 size_t OldBufferSize = ROS.GetBufferSize();
20082007 formatted_raw_ostream OS(ROS);
20092008 AssemblyWriter W(OS, SlotTable, this, AAW);
20102009 W.write(this);
2011 // formatted_raw_ostream forces the underlying raw_ostream to be
2012 // unbuffered. Reset it to its original buffer size.
2013 if (OldBufferSize != 0)
2014 ROS.SetBufferSize(OldBufferSize);
20152010 }
20162011
20172012 void Type::print(std::ostream &o) const {
20322027 ROS << "printing a value\n";
20332028 return;
20342029 }
2035 size_t OldBufferSize = ROS.GetBufferSize();
20362030 formatted_raw_ostream OS(ROS);
20372031 if (const Instruction *I = dyn_cast(this)) {
20382032 const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
20882082 } else {
20892083 llvm_unreachable("Unknown value to print out!");
20902084 }
2091 // formatted_raw_ostream forces the underlying raw_ostream to be
2092 // unbuffered. Reset it to its original buffer size.
2093 if (OldBufferSize != 0)
2094 ROS.SetBufferSize(OldBufferSize);
20952085 }
20962086
20972087 void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const {