cmListFile: Remove FilePath member from cmListFileContext.

There is no need to store the FilePath for every function, as it is
known by other means.
This commit is contained in:
Stephen Kelly 2015-07-04 13:12:50 +02:00 committed by Brad King
parent 329098a9a0
commit 238aac2351
7 changed files with 46 additions and 20 deletions

View File

@ -115,7 +115,10 @@ IsFunctionBlocked(const cmListFileFunction& lff,
{ {
std::string err = cmIfCommandError(expandedArguments); std::string err = cmIfCommandError(expandedArguments);
err += errorString; err += errorString;
cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]); cmListFileContext lfc =
cmListFileContext::FromCommandContext(
this->Functions[c], this->GetStartingContext().FilePath);
cmListFileBacktrace bt = mf.GetBacktrace(lfc);
mf.GetCMakeInstance()->IssueMessage(messType, err, bt); mf.GetCMakeInstance()->IssueMessage(messType, err, bt);
if (messType == cmake::FATAL_ERROR) if (messType == cmake::FATAL_ERROR)
{ {

View File

@ -251,7 +251,6 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
{ {
// Inintialize a new function call. // Inintialize a new function call.
this->Function = cmListFileFunction(); this->Function = cmListFileFunction();
this->Function.FilePath = this->FileName;
this->Function.Name = name; this->Function.Name = name;
this->Function.Line = line; this->Function.Line = line;

View File

@ -25,6 +25,13 @@
class cmMakefile; class cmMakefile;
struct cmCommandContext
{
std::string Name;
long Line;
cmCommandContext(): Name(), Line(0) {}
};
struct cmListFileArgument struct cmListFileArgument
{ {
enum Delimiter enum Delimiter
@ -57,6 +64,16 @@ struct cmListFileContext
std::string FilePath; std::string FilePath;
long Line; long Line;
cmListFileContext(): Name(), FilePath(), Line(0) {} cmListFileContext(): Name(), FilePath(), Line(0) {}
static cmListFileContext FromCommandContext(cmCommandContext const& lfcc,
std::string const& fileName)
{
cmListFileContext lfc;
lfc.FilePath = fileName;
lfc.Line = lfcc.Line;
lfc.Name = lfcc.Name;
return lfc;
}
}; };
std::ostream& operator<<(std::ostream&, cmListFileContext const&); std::ostream& operator<<(std::ostream&, cmListFileContext const&);
@ -64,7 +81,7 @@ bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs);
bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs); bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs);
bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs); bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs);
struct cmListFileFunction: public cmListFileContext struct cmListFileFunction: public cmCommandContext
{ {
std::vector<cmListFileArgument> Arguments; std::vector<cmListFileArgument> Arguments;
}; };

View File

@ -132,7 +132,6 @@ bool cmMacroHelperCommand::InvokeInitialPass
newLFF.Arguments.clear(); newLFF.Arguments.clear();
newLFF.Arguments.reserve(this->Functions[c].Arguments.size()); newLFF.Arguments.reserve(this->Functions[c].Arguments.size());
newLFF.Name = this->Functions[c].Name; newLFF.Name = this->Functions[c].Name;
newLFF.FilePath = this->Functions[c].FilePath;
newLFF.Line = this->Functions[c].Line; newLFF.Line = this->Functions[c].Line;
// for each argument of the current function // for each argument of the current function

View File

@ -277,12 +277,15 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
{ {
cmListFileBacktrace backtrace(this->StateSnapshot); cmListFileBacktrace backtrace(this->StateSnapshot);
cmState::Snapshot snp = this->StateSnapshot; cmState::Snapshot snp = this->StateSnapshot;
for(std::vector<cmListFileContext const*>::const_reverse_iterator for(std::vector<cmCommandContext const*>::const_reverse_iterator
i = this->ContextStack.rbegin(); i = this->ContextStack.rbegin();
i != this->ContextStack.rend(); ++i, snp = snp.GetCallStackParent()) i != this->ContextStack.rend();
++i, snp = snp.GetCallStackParent())
{ {
cmListFileContext frame = *(*i); assert(snp.IsValid());
frame.FilePath = snp.GetExecutionListFile(); cmListFileContext frame =
cmListFileContext::FromCommandContext(*(*i),
snp.GetExecutionListFile());
backtrace.Append(frame); backtrace.Append(frame);
} }
return backtrace; return backtrace;
@ -297,12 +300,15 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const
cmState::Snapshot snp = this->StateSnapshot; cmState::Snapshot snp = this->StateSnapshot;
assert(snp.GetExecutionListFile() == lfc.FilePath); assert(snp.GetExecutionListFile() == lfc.FilePath);
snp = snp.GetCallStackParent(); snp = snp.GetCallStackParent();
for(std::vector<cmListFileContext const*>::const_reverse_iterator for(std::vector<cmCommandContext const*>::const_reverse_iterator
i = this->ContextStack.rbegin(); i = this->ContextStack.rbegin();
i != this->ContextStack.rend(); ++i, snp = snp.GetCallStackParent()) i != this->ContextStack.rend();
++i, snp = snp.GetCallStackParent())
{ {
cmListFileContext frame = *(*i); assert(snp.IsValid());
frame.FilePath = snp.GetExecutionListFile(); cmListFileContext frame =
cmListFileContext::FromCommandContext(*(*i),
snp.GetExecutionListFile());
backtrace.Append(frame); backtrace.Append(frame);
} }
return backtrace; return backtrace;
@ -311,7 +317,9 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmListFileContext cmMakefile::GetExecutionContext() const cmListFileContext cmMakefile::GetExecutionContext() const
{ {
return *this->ContextStack.back(); return cmListFileContext::FromCommandContext(
*this->ContextStack.back(),
this->StateSnapshot.GetExecutionListFile());
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -561,7 +569,6 @@ public:
cmParseFileScope(cmMakefile* mf) cmParseFileScope(cmMakefile* mf)
: Makefile(mf) : Makefile(mf)
{ {
this->Context.FilePath = this->Makefile->GetExecutionFilePath();
this->Makefile->ContextStack.push_back(&this->Context); this->Makefile->ContextStack.push_back(&this->Context);
} }
@ -572,7 +579,7 @@ public:
private: private:
cmMakefile* Makefile; cmMakefile* Makefile;
cmListFileContext Context; cmCommandContext Context;
}; };
bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope) bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope)
@ -3581,11 +3588,13 @@ cmMakefile::RemoveFunctionBlocker(cmFunctionBlocker* fb,
if(!(*pos)->ShouldRemove(lff, *this)) if(!(*pos)->ShouldRemove(lff, *this))
{ {
cmListFileContext const& lfc = fb->GetStartingContext(); cmListFileContext const& lfc = fb->GetStartingContext();
cmListFileContext closingContext =
cmListFileContext::FromCommandContext(lff, lfc.FilePath);
std::ostringstream e; std::ostringstream e;
e << "A logical block opening on the line\n" e << "A logical block opening on the line\n"
<< " " << lfc << "\n" << " " << lfc << "\n"
<< "closes on the line\n" << "closes on the line\n"
<< " " << lff << "\n" << " " << closingContext << "\n"
<< "with mis-matching arguments."; << "with mis-matching arguments.";
this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
} }
@ -5595,7 +5604,7 @@ cmMakefile::MacroPushPop::~MacroPushPop()
this->Makefile->PopMacroScope(this->ReportError); this->Makefile->PopMacroScope(this->ReportError);
} }
cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmListFileContext& lfc, cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmCommandContext& lfc,
cmExecutionStatus& status): Makefile(mf) cmExecutionStatus& status): Makefile(mf)
{ {
this->Makefile->ContextStack.push_back(&lfc); this->Makefile->ContextStack.push_back(&lfc);

View File

@ -937,7 +937,7 @@ private:
// stack of list files being read // stack of list files being read
std::vector<std::string> ListFileStack; std::vector<std::string> ListFileStack;
std::vector<cmListFileContext const*> ContextStack; std::vector<cmCommandContext const*> ContextStack;
std::vector<cmExecutionStatus*> ExecutionStatusStack; std::vector<cmExecutionStatus*> ExecutionStatusStack;
friend class cmMakefileCall; friend class cmMakefileCall;
friend class cmParseFileScope; friend class cmParseFileScope;
@ -1055,7 +1055,7 @@ class cmMakefileCall
{ {
public: public:
cmMakefileCall(cmMakefile* mf, cmMakefileCall(cmMakefile* mf,
cmListFileContext const& lfc, cmCommandContext const& lfc,
cmExecutionStatus& status); cmExecutionStatus& status);
~cmMakefileCall(); ~cmMakefileCall();
private: private:

View File

@ -63,7 +63,6 @@ static void cmVariableWatchCommandVariableAccessed(
cmListFileArgument(stack, cmListFileArgument::Quoted, cmListFileArgument(stack, cmListFileArgument::Quoted,
9999)); 9999));
newLFF.Name = data->Command; newLFF.Name = data->Command;
newLFF.FilePath = "unknown";
newLFF.Line = 9999; newLFF.Line = 9999;
cmExecutionStatus status; cmExecutionStatus status;
if(!makefile->ExecuteCommand(newLFF,status)) if(!makefile->ExecuteCommand(newLFF,status))