Any function that can log things should be able to easily log them to a memory buffer...
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Nov 2012 03:16:47 +0000 (03:16 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Nov 2012 03:16:47 +0000 (03:16 +0000)
commitfa2d14fc6f455fd1cbb9c18089cb30644ef56332
treebca0da1c4b77bf07304659de69874fdcbdedaf1c
parent41ad40ead602d6a76993dc0ba9c3638259fbd9a6
Any function that can log things should be able to easily log them to a memory buffer as well
https://bugs.webkit.org/show_bug.cgi?id=103000

Reviewed by Sam Weinig.

Source/JavaScriptCore:

Change all users of WTF::dataFile() to expect a PrintStream& rather than a FILE*.

* bytecode/Operands.h:
(JSC::OperandValueTraits::dump):
(JSC::dumpOperands):
(JSC):
* dfg/DFGAbstractState.cpp:
(JSC::DFG::AbstractState::dump):
* dfg/DFGAbstractState.h:
(AbstractState):
* dfg/DFGAbstractValue.h:
(JSC::DFG::AbstractValue::dump):
* dfg/DFGCommon.h:
(JSC::DFG::NodeIndexTraits::dump):
* dfg/DFGStructureAbstractValue.h:
(JSC::DFG::StructureAbstractValue::dump):
* dfg/DFGVariableEvent.cpp:
(JSC::DFG::VariableEvent::dump):
(JSC::DFG::VariableEvent::dumpFillInfo):
(JSC::DFG::VariableEvent::dumpSpillInfo):
* dfg/DFGVariableEvent.h:
(VariableEvent):
* disassembler/Disassembler.h:
(JSC):
(JSC::tryToDisassemble):
* disassembler/UDis86Disassembler.cpp:
(JSC::tryToDisassemble):

Source/WTF:

We have a number of places where we pass around a FILE* as a target to which to print
some logging information. But the purpose of passing FILE* instead of always assuming
that we should dump to stderr is that it may be sometimes useful to send the logging
information elsewhere. Unfortunately, FILE* isn't quite powerful enough: it's combersome
to use it to send logging to a string, for example.

We could get around this by using <iostream> and <sstream>, but so far this aspect of
C++ has not been part of the WebKit coding conventions. Personally I find <iostream>
awkward due to its abuse of operator overloading.

So this patch introduces the PrintStream abstract class, which offers printf-like
functionality while completely abstracting the destination and mechanism of the printing
output. It would be trivial to implement a StringPrintStream, for example. This will feed
into work on https://bugs.webkit.org/show_bug.cgi?id=102999.

This also sets us up for creating templatized print() and println() methods that will
allow us to say things like out.print("count = ", count, "\n"), but that is the topic
of https://bugs.webkit.org/show_bug.cgi?id=103009.

This patch also changes dataLog() to use FilePrintStream internally, and WTF::dataFile()
now returns a FilePrintStream&. Any previous users of WTF::dataFile() have been changed
to expect a PrintStream&.

* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcproj/WTF.vcproj:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/DataLog.cpp:
(WTF):
(WTF::initializeLogFileOnce):
(WTF::initializeLogFile):
(WTF::dataFile):
(WTF::dataLogV):
(WTF::dataLogString):
* wtf/DataLog.h:
(WTF):
* wtf/FilePrintStream.cpp: Added.
(WTF):
(WTF::FilePrintStream::FilePrintStream):
(WTF::FilePrintStream::~FilePrintStream):
(WTF::FilePrintStream::vprintf):
(WTF::FilePrintStream::flush):
* wtf/FilePrintStream.h: Added.
(WTF):
(FilePrintStream):
(WTF::FilePrintStream::file):
* wtf/PrintStream.cpp: Added.
(WTF):
(WTF::PrintStream::PrintStream):
(WTF::PrintStream::~PrintStream):
(WTF::PrintStream::printf):
(WTF::PrintStream::print):
(WTF::PrintStream::println):
(WTF::PrintStream::flush):
(WTF::print):
* wtf/PrintStream.h: Added.
(WTF):
(PrintStream):
(WTF::print):
(WTF::println):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@135640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/Operands.h
Source/JavaScriptCore/dfg/DFGAbstractState.cpp
Source/JavaScriptCore/dfg/DFGAbstractState.h
Source/JavaScriptCore/dfg/DFGAbstractValue.h
Source/JavaScriptCore/dfg/DFGCommon.h
Source/JavaScriptCore/dfg/DFGStructureAbstractValue.h
Source/JavaScriptCore/dfg/DFGVariableEvent.cpp
Source/JavaScriptCore/dfg/DFGVariableEvent.h
Source/JavaScriptCore/disassembler/Disassembler.cpp
Source/JavaScriptCore/disassembler/Disassembler.h
Source/JavaScriptCore/disassembler/UDis86Disassembler.cpp
Source/WTF/ChangeLog
Source/WTF/GNUmakefile.list.am
Source/WTF/WTF.gypi
Source/WTF/WTF.pro
Source/WTF/WTF.vcproj/WTF.vcproj
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/DataLog.cpp
Source/WTF/wtf/DataLog.h
Source/WTF/wtf/FilePrintStream.cpp [new file with mode: 0644]
Source/WTF/wtf/FilePrintStream.h [new file with mode: 0644]
Source/WTF/wtf/PrintStream.cpp [new file with mode: 0644]
Source/WTF/wtf/PrintStream.h [new file with mode: 0644]