Merge topic 'minor-cleanups'

61d52e6e cmListFileBacktrace: Hide the context-stack implementation detail.
a271f7f1 cmTarget: Simplify CMP0023 message loop.
f4300cd4 cmTarget: Simplify output computation.
65a42849 cmTarget: Store context in stack only if different.
9645cba3 cmListFileContext: Implement EqualityComparable.
52a8d19c cmTarget: Store only cmListFileContext for CMP0023 handling.
59ba1215 cmTarget: Remove needless iteration.
18f810a8 cmListFileContext: Sort by line before file.
e96b5d14 cmListFileContext: Implement LessThanComparable.
7eb0dfa0 cmMakefile: Use std::set::insert API to simplify CMP0054 handling.
f9785e0c cmMakefile: Simplify CMP0054 handling.
e17b5e42 cmMakefile: Add access to the top-level execution context.
1ec1bf9f if(): Test the effect of cmMakefileCall use in elseif() handling.
9b4aefad cmMakefile: Replace deques with vectors.
This commit is contained in:
Brad King 2015-05-19 11:09:36 -04:00 committed by CMake Topic Stage
commit 0cbc69b9ea
13 changed files with 113 additions and 105 deletions

View File

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

View File

@ -112,10 +112,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN) if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN)
{ {
bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported( if(!this->Makefile.HasCMP0054AlreadyBeenReported())
this->Makefile.GetBacktrace()[0]);
if(!hasBeenReported)
{ {
std::ostringstream e; std::ostringstream e;
e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)) << "\n"; e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)) << "\n";
@ -161,10 +158,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword,
if(isKeyword && argument.WasQuoted() && if(isKeyword && argument.WasQuoted() &&
this->Policy54Status == cmPolicies::WARN) this->Policy54Status == cmPolicies::WARN)
{ {
bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported( if(!this->Makefile.HasCMP0054AlreadyBeenReported())
this->Makefile.GetBacktrace()[0]);
if(!hasBeenReported)
{ {
std::ostringstream e; std::ostringstream e;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054) << "\n"; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054) << "\n";

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() void cmListFileBacktrace::MakeRelative()
{ {
@ -416,6 +421,31 @@ void cmListFileBacktrace::MakeRelative()
this->Relative = true; 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) std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
@ -431,3 +461,22 @@ std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
} }
return os; return os;
} }
bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
if(lhs.Line != rhs.Line)
{
return lhs.Line < rhs.Line;
}
return lhs.FilePath < rhs.FilePath;
}
bool operator==(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
return lhs.Line == rhs.Line && lhs.FilePath == rhs.FilePath;
}
bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
return !(lhs == rhs);
}

View File

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

View File

@ -350,7 +350,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
lfc.FilePath = this->ListFileStack.back(); lfc.FilePath = this->ListFileStack.back();
} }
lfc.Line = 0; lfc.Line = 0;
backtrace.push_back(lfc); backtrace.Append(lfc);
} }
// Issue the message. // Issue the message.
@ -364,11 +364,17 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin(); for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
i != this->CallStack.rend(); ++i) i != this->CallStack.rend(); ++i)
{ {
backtrace.push_back(*i->Context); backtrace.Append(*i->Context);
} }
return backtrace; return backtrace;
} }
//----------------------------------------------------------------------------
cmListFileContext cmMakefile::GetExecutionContext() const
{
return *this->CallStack.back().Context;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
{ {
@ -1929,9 +1935,9 @@ void cmMakefile::CheckForUnused(const char* reason,
cmListFileBacktrace bt(this->GetLocalGenerator()); cmListFileBacktrace bt(this->GetLocalGenerator());
if (!this->CallStack.empty()) if (!this->CallStack.empty())
{ {
const cmListFileContext* file = this->CallStack.back().Context; cmListFileContext file = this->GetExecutionContext();
bt.push_back(*file); bt.Append(file);
path = file->FilePath.c_str(); path = file.FilePath;
} }
else else
{ {
@ -1940,7 +1946,7 @@ void cmMakefile::CheckForUnused(const char* reason,
cmListFileContext lfc; cmListFileContext lfc;
lfc.FilePath = path; lfc.FilePath = path;
lfc.Line = 0; lfc.Line = 0;
bt.push_back(lfc); bt.Append(lfc);
} }
if (this->CheckSystemVars || if (this->CheckSystemVars ||
cmSystemTools::IsSubDirectory(path, cmSystemTools::IsSubDirectory(path,
@ -2870,7 +2876,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
cmListFileContext lfc; cmListFileContext lfc;
lfc.FilePath = filename; lfc.FilePath = filename;
lfc.Line = line; lfc.Line = line;
bt.push_back(lfc); bt.Append(lfc);
msg << "uninitialized variable \'" << lookup << "\'"; msg << "uninitialized variable \'" << lookup << "\'";
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
msg.str(), bt); msg.str(), bt);
@ -3403,7 +3409,7 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
if(!this->CallStack.empty()) if(!this->CallStack.empty())
{ {
// Record the context in which the blocker is created. // Record the context in which the blocker is created.
fb->SetStartingContext(*(this->CallStack.back().Context)); fb->SetStartingContext(this->GetExecutionContext());
} }
this->FunctionBlockers.push_back(fb); this->FunctionBlockers.push_back(fb);
@ -4364,7 +4370,7 @@ std::string cmMakefile::GetListFileStack() const
size_t depth = this->ListFileStack.size(); size_t depth = this->ListFileStack.size();
if (depth > 0) if (depth > 0)
{ {
std::deque<std::string>::const_iterator it = this->ListFileStack.end(); std::vector<std::string>::const_iterator it = this->ListFileStack.end();
do do
{ {
if (depth != this->ListFileStack.size()) if (depth != this->ListFileStack.size())
@ -4928,20 +4934,9 @@ bool cmMakefile::SetPolicyVersion(const char *version)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmMakefile::HasCMP0054AlreadyBeenReported( bool cmMakefile::HasCMP0054AlreadyBeenReported() const
cmListFileContext context) const
{ {
cmCMP0054Id id(context); return !this->CMP0054ReportedIds.insert(this->GetExecutionContext()).second;
bool alreadyReported =
this->CMP0054ReportedIds.find(id) != this->CMP0054ReportedIds.end();
if(!alreadyReported)
{
this->CMP0054ReportedIds.insert(id);
}
return alreadyReported;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -35,7 +35,6 @@
#endif #endif
#include <stack> #include <stack>
#include <deque>
class cmFunctionBlocker; class cmFunctionBlocker;
class cmCommand; class cmCommand;
@ -387,33 +386,13 @@ public:
*/ */
cmPolicies *GetPolicies() const; cmPolicies *GetPolicies() const;
struct cmCMP0054Id mutable std::set<cmListFileContext> CMP0054ReportedIds;
{
cmCMP0054Id(cmListFileContext const& context):
Context(context)
{
}
bool operator< (cmCMP0054Id const& id) const
{
if(this->Context.FilePath != id.Context.FilePath)
return this->Context.FilePath < id.Context.FilePath;
return this->Context.Line < id.Context.Line;
}
cmListFileContext Context;
};
mutable std::set<cmCMP0054Id> CMP0054ReportedIds;
/** /**
* Determine if the given context, name pair has already been reported * Determine if the given context, name pair has already been reported
* in context of CMP0054. * in context of CMP0054.
*/ */
bool HasCMP0054AlreadyBeenReported( bool HasCMP0054AlreadyBeenReported() const;
cmListFileContext context) const;
bool IgnoreErrorsCMP0061() const; bool IgnoreErrorsCMP0061() const;
@ -611,6 +590,7 @@ public:
* Get the current context backtrace. * Get the current context backtrace.
*/ */
cmListFileBacktrace GetBacktrace() const; cmListFileBacktrace GetBacktrace() const;
cmListFileContext GetExecutionContext() const;
/** /**
* Get the vector of files created by this makefile * Get the vector of files created by this makefile
@ -963,7 +943,7 @@ private:
bool CheckSystemVars; bool CheckSystemVars;
// stack of list files being read // stack of list files being read
std::deque<std::string> ListFileStack; std::vector<std::string> ListFileStack;
// stack of commands being invoked. // stack of commands being invoked.
struct CallStackEntry struct CallStackEntry
@ -971,7 +951,7 @@ private:
cmListFileContext const* Context; cmListFileContext const* Context;
cmExecutionStatus* Status; cmExecutionStatus* Status;
}; };
typedef std::deque<CallStackEntry> CallStackType; typedef std::vector<CallStackEntry> CallStackType;
CallStackType CallStack; CallStackType CallStack;
friend class cmMakefileCall; friend class cmMakefileCall;

View File

@ -1239,8 +1239,11 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
ret = false; ret = false;
} }
} }
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); cmListFileContext lfc = this->Makefile->GetExecutionContext();
this->TLLCommands.push_back(std::make_pair(signature, lfbt)); if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
{
this->TLLCommands.push_back(std::make_pair(signature, lfc));
}
return ret; return ret;
} }
@ -1248,39 +1251,19 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
void cmTarget::GetTllSignatureTraces(std::ostringstream &s, void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
TLLSignature sig) const TLLSignature sig) const
{ {
std::vector<cmListFileBacktrace> sigs; const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container; : "plain");
s << "The uses of the " << sigString << " signature are here:\n";
typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
cmLocalGenerator* lg = this->GetMakefile()->GetLocalGenerator();
for(Container::const_iterator it = this->TLLCommands.begin(); for(Container::const_iterator it = this->TLLCommands.begin();
it != this->TLLCommands.end(); ++it) it != this->TLLCommands.end(); ++it)
{ {
if (it->first == sig) if (it->first == sig)
{ {
sigs.push_back(it->second); cmListFileContext lfc = it->second;
} lfc.FilePath = lg->Convert(lfc.FilePath, cmLocalGenerator::HOME);
} s << " * " << lfc << std::endl;
if (!sigs.empty())
{
const char *sigString
= (sig == cmTarget::KeywordTLLSignature ? "keyword"
: "plain");
s << "The uses of the " << sigString << " signature are here:\n";
UNORDERED_SET<std::string> emitted;
for(std::vector<cmListFileBacktrace>::iterator it = sigs.begin();
it != sigs.end(); ++it)
{
it->MakeRelative();
cmListFileBacktrace::const_iterator i = it->begin();
if(i != it->end())
{
cmListFileContext const& lfc = *i;
std::ostringstream line;
line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
if (emitted.insert(line.str()).second)
{
s << line.str();
}
++i;
}
} }
} }
} }

View File

@ -641,7 +641,7 @@ private:
// directories. // directories.
std::set<std::string> SystemIncludeDirectories; std::set<std::string> SystemIncludeDirectories;
std::vector<std::pair<TLLSignature, cmListFileBacktrace> > TLLCommands; std::vector<std::pair<TLLSignature, cmListFileContext> > TLLCommands;
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
/** /**

View File

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

View File

@ -2,3 +2,4 @@ include(RunCMake)
run_cmake(IsDirectory) run_cmake(IsDirectory)
run_cmake(IsDirectoryLong) run_cmake(IsDirectoryLong)
run_cmake(elseif-message)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,8 @@
CMake Error at elseif-message.cmake:[0-9]+ \(elseif\):
given arguments:
"Unknown" "arguments"
Unknown arguments specified
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,4 @@
if (0)
elseif(Unknown arguments)
endif()