summaryrefslogtreecommitdiffstats
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2016-10-22 21:03:30 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2016-10-25 18:07:27 -0400
commit12127e1eaf63fec008cba3fe705e23ba86a704f7 (patch)
tree3d97e87cf3c0b8dfac53032c379a2768c682d490 /sc
parentUse a singleton pattern here. (diff)
downloadcore-12127e1eaf63fec008cba3fe705e23ba86a704f7.tar.gz
core-12127e1eaf63fec008cba3fe705e23ba86a704f7.zip
Write nest levels in case of nested group calculations.
Change-Id: Ie2a94bf76ab28f792ff5684879365fda81c10e2b
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/formulalogger.hxx8
-rw-r--r--sc/source/core/tool/formulalogger.cxx78
2 files changed, 59 insertions, 27 deletions
diff --git a/sc/inc/formulalogger.hxx b/sc/inc/formulalogger.hxx
index bc547b97dc99..d8ce3a4fda2f 100644
--- a/sc/inc/formulalogger.hxx
+++ b/sc/inc/formulalogger.hxx
@@ -20,14 +20,17 @@ namespace sc {
class FormulaLogger
{
std::unique_ptr<osl::File> mpLogFile;
- OUString maGroupPrefix;
std::vector<OUString> maMessages;
+ sal_Int32 mnNestLevel = 0;
+
void writeAscii( const char* s );
void writeAscii( const char* s, size_t n );
void write( const OUString& ou );
void write( sal_Int32 n );
+ void writeNestLevel();
+
public:
static FormulaLogger& get();
@@ -45,7 +48,8 @@ public:
GroupScope( const GroupScope& ) = delete;
GroupScope& operator= ( const GroupScope& ) = delete;
- GroupScope( FormulaLogger& rLogger, const OUString& rPrefix );
+ GroupScope( FormulaLogger& rLogger, const OUString& rPrefix, const ScDocument& rDoc, const ScFormulaCell& rCell );
+
GroupScope( GroupScope&& r );
~GroupScope();
diff --git a/sc/source/core/tool/formulalogger.cxx b/sc/source/core/tool/formulalogger.cxx
index db51259e8dc2..69b1ef97c504 100644
--- a/sc/source/core/tool/formulalogger.cxx
+++ b/sc/source/core/tool/formulalogger.cxx
@@ -16,8 +16,6 @@
#include <sfx2/docfile.hxx>
#include <tools/urlobj.hxx>
-#include <iostream>
-
namespace sc {
FormulaLogger& FormulaLogger::get()
@@ -35,28 +33,54 @@ struct FormulaLogger::GroupScope::Impl
bool mbCalcComplete = false;
- Impl( FormulaLogger& rLogger, const OUString& rPrefix ) :
- mrLogger(rLogger), maPrefix(rPrefix) {}
+ Impl( FormulaLogger& rLogger, const OUString& rPrefix, const ScDocument& rDoc, const ScFormulaCell& rCell ) :
+ mrLogger(rLogger), maPrefix(rPrefix)
+ {
+ ++mrLogger.mnNestLevel;
+
+ sc::TokenStringContext aCxt(&rDoc, rDoc.GetGrammar());
+ OUString aFormula = rCell.GetCode()->CreateString(aCxt, rCell.aPos);
+
+ mrLogger.write(maPrefix);
+ mrLogger.writeNestLevel();
+
+ mrLogger.writeAscii("-- enter (formula='");
+ mrLogger.write(aFormula);
+ mrLogger.writeAscii("', size=");
+ mrLogger.write(rCell.GetSharedLength());
+ mrLogger.writeAscii(")\n");
+ }
~Impl()
{
for (const OUString& rMsg : maMessages)
{
mrLogger.write(maPrefix);
- mrLogger.writeAscii(" * ");
+ mrLogger.writeNestLevel();
+ mrLogger.writeAscii(" * ");
mrLogger.write(rMsg);
mrLogger.writeAscii("\n");
}
mrLogger.write(maPrefix);
- mrLogger.writeAscii(mbCalcComplete ? " * calculation complete\n" : " * exited without calculation\n");
+ mrLogger.writeNestLevel();
+ mrLogger.writeAscii("-- exit (");
+ if (mbCalcComplete)
+ mrLogger.writeAscii("calculation complete");
+ else
+ mrLogger.writeAscii("without calculation");
+
+ mrLogger.writeAscii(")\n");
mrLogger.mpLogFile->sync();
+
+ --mrLogger.mnNestLevel;
}
};
-FormulaLogger::GroupScope::GroupScope( FormulaLogger& rLogger, const OUString& rPrefix ) :
- mpImpl(o3tl::make_unique<Impl>(rLogger, rPrefix)) {}
+FormulaLogger::GroupScope::GroupScope(
+ FormulaLogger& rLogger, const OUString& rPrefix, const ScDocument& rDoc, const ScFormulaCell& rCell ) :
+ mpImpl(o3tl::make_unique<Impl>(rLogger, rPrefix, rDoc, rCell)) {}
FormulaLogger::GroupScope::GroupScope( GroupScope&& r ) : mpImpl(std::move(r.mpImpl)) {}
@@ -69,7 +93,8 @@ void FormulaLogger::GroupScope::addMessage( const OUString& rMsg )
void FormulaLogger::GroupScope::setCalcComplete()
{
- mpImpl->mbCalcComplete;
+ mpImpl->mbCalcComplete = true;
+ addMessage("calculation performed");
}
FormulaLogger::FormulaLogger() : mpLogFile(o3tl::make_unique<osl::File>("file:///home/kohei/tmp/formula.log"))
@@ -142,11 +167,23 @@ void FormulaLogger::write( sal_Int32 n )
writeAscii(s.getStr(), s.getLength());
}
+void FormulaLogger::writeNestLevel()
+{
+ // Write the nest level, but keep it only 1-character length to avoid
+ // messing up the spacing.
+ if (mnNestLevel < 10)
+ write(mnNestLevel);
+ else
+ writeAscii("!");
+
+ writeAscii(":");
+ for (sal_Int32 i = 0; i < mnNestLevel; ++i)
+ writeAscii(" ");
+}
+
FormulaLogger::GroupScope FormulaLogger::enterGroup(
const ScDocument& rDoc, const ScFormulaCell& rCell )
{
- maGroupPrefix = "formula-group: ";
-
// Get the file name if available.
const SfxObjectShell* pShell = rDoc.GetDocumentShell();
const SfxMedium* pMedium = pShell->GetMedium();
@@ -154,22 +191,13 @@ FormulaLogger::GroupScope FormulaLogger::enterGroup(
if (aName.isEmpty())
aName = "-"; // unsaved document.
- maGroupPrefix += aName;
- maGroupPrefix += ": ";
- maGroupPrefix += rCell.aPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc, rDoc.GetAddressConvention());
- maGroupPrefix += ": ";
- write(maGroupPrefix);
-
- writeAscii("(formula='");
-
- sc::TokenStringContext aCxt(&rDoc, rDoc.GetGrammar());
- write(rCell.GetCode()->CreateString(aCxt, rCell.aPos));
+ OUString aGroupPrefix = aName;
- writeAscii("', size=");
- write(rCell.GetSharedLength());
- writeAscii(")\n");
+ aGroupPrefix += ": formula-group: ";
+ aGroupPrefix += rCell.aPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc, rDoc.GetAddressConvention());
+ aGroupPrefix += ": ";
- return GroupScope(*this, maGroupPrefix);
+ return GroupScope(*this, aGroupPrefix, rDoc, rCell);
}
}