cmListFileBacktrace: Hide the context-stack implementation detail.

The backtrace will soon not be implemented in terms of a stack of
cmListFileContext objects.  Keep the cmListFileContext in the API
for convenience for now.
This commit is contained in:
Stephen Kelly 2015-05-18 21:33:38 +02:00
parent a271f7f177
commit 61d52e6e77
5 changed files with 44 additions and 24 deletions

View File

@ -143,7 +143,7 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
cmListFileContext lfc;
lfc.FilePath = this->FileName;
lfc.Line = this->FileLine;
bt.push_back(lfc);
bt.Append(lfc);
msg << "uninitialized variable \'" << var << "\'";
this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
msg.str(), bt);

View File

@ -400,6 +400,11 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
}
}
void cmListFileBacktrace::Append(cmListFileContext const& context)
{
this->push_back(context);
}
//----------------------------------------------------------------------------
void cmListFileBacktrace::MakeRelative()
{
@ -416,6 +421,31 @@ void cmListFileBacktrace::MakeRelative()
this->Relative = true;
}
void cmListFileBacktrace::PrintTitle(std::ostream& out)
{
if (this->empty())
{
return;
}
out << (this->front().Line ? " at " : " in ") << this->front();
}
void cmListFileBacktrace::PrintCallStack(std::ostream& out)
{
if (size() <= 1)
{
return;
}
const_iterator i = this->begin() + 1;
out << "Call Stack (most recent call first):\n";
while(i != this->end())
{
cmListFileContext const& lfc = *i;
out << " " << lfc << "\n";
++i;
}
}
//----------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)

View File

@ -71,7 +71,7 @@ struct cmListFileFunction: public cmListFileContext
std::vector<cmListFileArgument> Arguments;
};
class cmListFileBacktrace: public std::vector<cmListFileContext>
class cmListFileBacktrace: private std::vector<cmListFileContext>
{
public:
cmListFileBacktrace(cmLocalGenerator* localGen)
@ -80,7 +80,12 @@ class cmListFileBacktrace: public std::vector<cmListFileContext>
{
}
void Append(cmListFileContext const& context);
void MakeRelative();
void PrintTitle(std::ostream& out);
void PrintCallStack(std::ostream& out);
private:
cmLocalGenerator* LocalGenerator;
bool Relative;

View File

@ -358,7 +358,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
lfc.FilePath = this->ListFileStack.back();
}
lfc.Line = 0;
backtrace.push_back(lfc);
backtrace.Append(lfc);
}
// Issue the message.
@ -372,7 +372,7 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
i != this->CallStack.rend(); ++i)
{
backtrace.push_back(*i->Context);
backtrace.Append(*i->Context);
}
return backtrace;
}
@ -1944,7 +1944,7 @@ void cmMakefile::CheckForUnused(const char* reason,
if (!this->CallStack.empty())
{
cmListFileContext file = this->GetExecutionContext();
bt.push_back(file);
bt.Append(file);
path = file.FilePath;
}
else
@ -1954,7 +1954,7 @@ void cmMakefile::CheckForUnused(const char* reason,
cmListFileContext lfc;
lfc.FilePath = path;
lfc.Line = 0;
bt.push_back(lfc);
bt.Append(lfc);
}
if (this->CheckSystemVars ||
cmSystemTools::IsSubDirectory(path,
@ -2884,7 +2884,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
cmListFileContext lfc;
lfc.FilePath = filename;
lfc.Line = line;
bt.push_back(lfc);
bt.Append(lfc);
msg << "uninitialized variable \'" << lookup << "\'";
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
msg.str(), bt);

View File

@ -2485,13 +2485,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
}
// Add the immediate context.
cmListFileBacktrace::const_iterator i = backtrace.begin();
if(i != backtrace.end())
{
cmListFileContext const& lfc = *i;
msg << (lfc.Line? " at ": " in ") << lfc;
++i;
}
backtrace.PrintTitle(msg);
// Add the message text.
{
@ -2502,16 +2496,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
}
// Add the rest of the context.
if(i != backtrace.end())
{
msg << "Call Stack (most recent call first):\n";
while(i != backtrace.end())
{
cmListFileContext const& lfc = *i;
msg << " " << lfc << "\n";
++i;
}
}
backtrace.PrintCallStack(msg);
// Add a note about warning suppression.
if(t == cmake::AUTHOR_WARNING)