Write nest levels in case of nested group calculations.
Change-Id: Ie2a94bf76ab28f792ff5684879365fda81c10e2b
This commit is contained in:
@@ -20,14 +20,17 @@ namespace sc {
|
|||||||
class FormulaLogger
|
class FormulaLogger
|
||||||
{
|
{
|
||||||
std::unique_ptr<osl::File> mpLogFile;
|
std::unique_ptr<osl::File> mpLogFile;
|
||||||
OUString maGroupPrefix;
|
|
||||||
std::vector<OUString> maMessages;
|
std::vector<OUString> maMessages;
|
||||||
|
|
||||||
|
sal_Int32 mnNestLevel = 0;
|
||||||
|
|
||||||
void writeAscii( const char* s );
|
void writeAscii( const char* s );
|
||||||
void writeAscii( const char* s, size_t n );
|
void writeAscii( const char* s, size_t n );
|
||||||
void write( const OUString& ou );
|
void write( const OUString& ou );
|
||||||
void write( sal_Int32 n );
|
void write( sal_Int32 n );
|
||||||
|
|
||||||
|
void writeNestLevel();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static FormulaLogger& get();
|
static FormulaLogger& get();
|
||||||
@@ -45,7 +48,8 @@ public:
|
|||||||
GroupScope( const GroupScope& ) = delete;
|
GroupScope( const GroupScope& ) = delete;
|
||||||
GroupScope& operator= ( 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( GroupScope&& r );
|
||||||
~GroupScope();
|
~GroupScope();
|
||||||
|
|
||||||
|
@@ -16,8 +16,6 @@
|
|||||||
#include <sfx2/docfile.hxx>
|
#include <sfx2/docfile.hxx>
|
||||||
#include <tools/urlobj.hxx>
|
#include <tools/urlobj.hxx>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace sc {
|
namespace sc {
|
||||||
|
|
||||||
FormulaLogger& FormulaLogger::get()
|
FormulaLogger& FormulaLogger::get()
|
||||||
@@ -35,28 +33,54 @@ struct FormulaLogger::GroupScope::Impl
|
|||||||
|
|
||||||
bool mbCalcComplete = false;
|
bool mbCalcComplete = false;
|
||||||
|
|
||||||
Impl( FormulaLogger& rLogger, const OUString& rPrefix ) :
|
Impl( FormulaLogger& rLogger, const OUString& rPrefix, const ScDocument& rDoc, const ScFormulaCell& rCell ) :
|
||||||
mrLogger(rLogger), maPrefix(rPrefix) {}
|
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()
|
~Impl()
|
||||||
{
|
{
|
||||||
for (const OUString& rMsg : maMessages)
|
for (const OUString& rMsg : maMessages)
|
||||||
{
|
{
|
||||||
mrLogger.write(maPrefix);
|
mrLogger.write(maPrefix);
|
||||||
mrLogger.writeAscii(" * ");
|
mrLogger.writeNestLevel();
|
||||||
|
mrLogger.writeAscii(" * ");
|
||||||
mrLogger.write(rMsg);
|
mrLogger.write(rMsg);
|
||||||
mrLogger.writeAscii("\n");
|
mrLogger.writeAscii("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
mrLogger.write(maPrefix);
|
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.mpLogFile->sync();
|
||||||
|
|
||||||
|
--mrLogger.mnNestLevel;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FormulaLogger::GroupScope::GroupScope( FormulaLogger& rLogger, const OUString& rPrefix ) :
|
FormulaLogger::GroupScope::GroupScope(
|
||||||
mpImpl(o3tl::make_unique<Impl>(rLogger, rPrefix)) {}
|
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)) {}
|
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()
|
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"))
|
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());
|
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(
|
FormulaLogger::GroupScope FormulaLogger::enterGroup(
|
||||||
const ScDocument& rDoc, const ScFormulaCell& rCell )
|
const ScDocument& rDoc, const ScFormulaCell& rCell )
|
||||||
{
|
{
|
||||||
maGroupPrefix = "formula-group: ";
|
|
||||||
|
|
||||||
// Get the file name if available.
|
// Get the file name if available.
|
||||||
const SfxObjectShell* pShell = rDoc.GetDocumentShell();
|
const SfxObjectShell* pShell = rDoc.GetDocumentShell();
|
||||||
const SfxMedium* pMedium = pShell->GetMedium();
|
const SfxMedium* pMedium = pShell->GetMedium();
|
||||||
@@ -154,22 +191,13 @@ FormulaLogger::GroupScope FormulaLogger::enterGroup(
|
|||||||
if (aName.isEmpty())
|
if (aName.isEmpty())
|
||||||
aName = "-"; // unsaved document.
|
aName = "-"; // unsaved document.
|
||||||
|
|
||||||
maGroupPrefix += aName;
|
OUString aGroupPrefix = aName;
|
||||||
maGroupPrefix += ": ";
|
|
||||||
maGroupPrefix += rCell.aPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc, rDoc.GetAddressConvention());
|
|
||||||
maGroupPrefix += ": ";
|
|
||||||
write(maGroupPrefix);
|
|
||||||
|
|
||||||
writeAscii("(formula='");
|
aGroupPrefix += ": formula-group: ";
|
||||||
|
aGroupPrefix += rCell.aPos.Format(ScRefFlags::VALID | ScRefFlags::TAB_3D, &rDoc, rDoc.GetAddressConvention());
|
||||||
|
aGroupPrefix += ": ";
|
||||||
|
|
||||||
sc::TokenStringContext aCxt(&rDoc, rDoc.GetGrammar());
|
return GroupScope(*this, aGroupPrefix, rDoc, rCell);
|
||||||
write(rCell.GetCode()->CreateString(aCxt, rCell.aPos));
|
|
||||||
|
|
||||||
writeAscii("', size=");
|
|
||||||
write(rCell.GetSharedLength());
|
|
||||||
writeAscii(")\n");
|
|
||||||
|
|
||||||
return GroupScope(*this, maGroupPrefix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user