From 27ff19a96a7d12f2ed6d9683ef733eff6378472a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 8 Jun 2015 20:09:55 +0200 Subject: cmLinkedTree: Add operator* to the iterator. --- Source/cmLinkedTree.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h index d2339c4..df00b30 100644 --- a/Source/cmLinkedTree.h +++ b/Source/cmLinkedTree.h @@ -87,6 +87,24 @@ public: return this->Tree->GetPointer(this->Position - 1); } + ReferenceType operator*() const + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + assert(this->Position <= this->Tree->Data.size()); + assert(this->Position > 0); + return this->Tree->GetReference(this->Position - 1); + } + + ReferenceType operator*() + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + assert(this->Position <= this->Tree->Data.size()); + assert(this->Position > 0); + return this->Tree->GetReference(this->Position - 1); + } + bool operator==(iterator other) const { assert(this->Tree); -- cgit v0.12 From dbafb01580a0d35e33e6577ad07002f4dd345236 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 31 May 2015 19:37:08 +0200 Subject: cmMakefile: Split CallStack into two pieces. --- Source/cmMakefile.cxx | 35 +++++++++++++++++++---------------- Source/cmMakefile.h | 10 ++-------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index cdcf88c..678c1b3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -247,11 +247,11 @@ void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text) const { // Collect context information. - if(!this->CallStack.empty()) + if(!this->ExecutionStatusStack.empty()) { if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR)) { - this->CallStack.back().Status->SetNestedError(true); + this->ExecutionStatusStack.back()->SetNestedError(true); } this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace()); } @@ -276,10 +276,11 @@ void cmMakefile::IssueMessage(cmake::MessageType t, cmListFileBacktrace cmMakefile::GetBacktrace() const { cmListFileBacktrace backtrace(this->StateSnapshot); - for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin(); - i != this->CallStack.rend(); ++i) + for(std::vector::const_reverse_iterator + i = this->ContextStack.rbegin(); + i != this->ContextStack.rend(); ++i) { - backtrace.Append(*i->Context); + backtrace.Append(*(*i)); } return backtrace; } @@ -290,10 +291,11 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const { cmListFileBacktrace backtrace(this->StateSnapshot); backtrace.Append(lfc); - for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin(); - i != this->CallStack.rend(); ++i) + for(std::vector::const_reverse_iterator + i = this->ContextStack.rbegin(); + i != this->ContextStack.rend(); ++i) { - backtrace.Append(*i->Context); + backtrace.Append(*(*i)); } return backtrace; } @@ -301,7 +303,7 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const //---------------------------------------------------------------------------- cmListFileContext cmMakefile::GetExecutionContext() const { - return *this->CallStack.back().Context; + return *this->ContextStack.back(); } //---------------------------------------------------------------------------- @@ -1996,7 +1998,7 @@ void cmMakefile::LogUnused(const char* reason, { std::string path; cmListFileContext lfc; - if (!this->CallStack.empty()) + if (!this->ExecutionStatusStack.empty()) { lfc = this->GetExecutionContext(); path = lfc.FilePath; @@ -3360,11 +3362,11 @@ bool cmMakefile::IsLoopBlock() const std::string cmMakefile::GetExecutionFilePath() const { - if (this->CallStack.empty()) + if (this->ContextStack.empty()) { return std::string(); } - return this->CallStack.back().Context->FilePath; + return this->ContextStack.back()->FilePath; } //---------------------------------------------------------------------------- @@ -3455,7 +3457,7 @@ bool cmMakefile::ExpandArguments( //---------------------------------------------------------------------------- void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb) { - if(!this->CallStack.empty()) + if(!this->ExecutionStatusStack.empty()) { // Record the context in which the blocker is created. fb->SetStartingContext(this->GetExecutionContext()); @@ -5503,11 +5505,12 @@ cmMakefile::MacroPushPop::~MacroPushPop() cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmListFileContext& lfc, cmExecutionStatus& status): Makefile(mf) { - cmMakefile::CallStackEntry entry = {&lfc, &status}; - this->Makefile->CallStack.push_back(entry); + this->Makefile->ContextStack.push_back(&lfc); + this->Makefile->ExecutionStatusStack.push_back(&status); } cmMakefileCall::~cmMakefileCall() { - this->Makefile->CallStack.pop_back(); + this->Makefile->ExecutionStatusStack.pop_back(); + this->Makefile->ContextStack.pop_back(); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index aa70c72..0ade8e1 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -935,14 +935,8 @@ private: // stack of list files being read std::vector ListFileStack; - // stack of commands being invoked. - struct CallStackEntry - { - cmListFileContext const* Context; - cmExecutionStatus* Status; - }; - typedef std::vector CallStackType; - CallStackType CallStack; + std::vector ContextStack; + std::vector ExecutionStatusStack; friend class cmMakefileCall; std::vector ImportedTargetsOwned; -- cgit v0.12 From a8e54460243b0650145c8684f3d8deb8a712376a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 21 Jun 2015 21:26:36 +0200 Subject: cmState: Store snapshots for more different types. Adjust cmMakefile implementation to create the snapshots. --- Source/cmMakefile.cxx | 33 +++++++++++++++++++++++++++++++ Source/cmState.cxx | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ Source/cmState.h | 14 +++++++++++-- 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 678c1b3..a176cda 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -463,11 +463,19 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, this->Makefile->PushPolicyBarrier(); this->Makefile->ListFileStack.push_back(filenametoread); this->Makefile->PushFunctionBlockerBarrier(); + + this->Makefile->StateSnapshot = + this->Makefile->GetState()->CreateCallStackSnapshot( + this->Makefile->StateSnapshot); } //---------------------------------------------------------------------------- cmMakefile::IncludeScope::~IncludeScope() { + this->Makefile->StateSnapshot = + this->Makefile->GetState()->Pop(this->Makefile->StateSnapshot); + assert(this->Makefile->StateSnapshot.IsValid()); + this->Makefile->PopFunctionBlockerBarrier(this->ReportError); // Enforce matching policy scopes inside the included file. this->Makefile->PopPolicyBarrier(this->ReportError); @@ -567,11 +575,20 @@ public: { this->Makefile->ListFileStack.push_back(filenametoread); this->Makefile->PushPolicyBarrier(); + + this->Makefile->StateSnapshot = + this->Makefile->GetState()->CreateInlineListFileSnapshot( + this->Makefile->StateSnapshot); + assert(this->Makefile->StateSnapshot.IsValid()); this->Makefile->PushFunctionBlockerBarrier(); } ~ListFileScope() { + this->Makefile->StateSnapshot = + this->Makefile->GetState()->Pop(this->Makefile->StateSnapshot); + assert(this->Makefile->StateSnapshot.IsValid()); + this->Makefile->PopFunctionBlockerBarrier(this->ReportError); this->Makefile->PopPolicyBarrier(this->ReportError); this->Makefile->ListFileStack.pop_back(); @@ -1575,6 +1592,11 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) void cmMakefile::PushFunctionScope(const cmPolicies::PolicyMap& pm) { + this->StateSnapshot = + this->GetState()->CreateFunctionCallSnapshot( + this->StateSnapshot); + assert(this->StateSnapshot.IsValid()); + this->Internal->PushDefinitions(); this->PushLoopBlockBarrier(); @@ -1594,6 +1616,9 @@ void cmMakefile::PopFunctionScope(bool reportError) this->PopPolicyBarrier(reportError); this->PopPolicy(); + this->StateSnapshot = this->GetState()->Pop(this->StateSnapshot); + assert(this->StateSnapshot.IsValid()); + this->PopFunctionBlockerBarrier(reportError); #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -1609,6 +1634,11 @@ void cmMakefile::PopFunctionScope(bool reportError) void cmMakefile::PushMacroScope(const cmPolicies::PolicyMap& pm) { + this->StateSnapshot = + this->GetState()->CreateMacroCallSnapshot( + this->StateSnapshot); + assert(this->StateSnapshot.IsValid()); + this->PushFunctionBlockerBarrier(); this->PushPolicy(true, pm); @@ -1620,6 +1650,9 @@ void cmMakefile::PopMacroScope(bool reportError) this->PopPolicyBarrier(reportError); this->PopPolicy(); + this->StateSnapshot = this->GetState()->Pop(this->StateSnapshot); + assert(this->StateSnapshot.IsValid()); + this->PopFunctionBlockerBarrier(reportError); } diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 58500cc..ef55e09 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -20,6 +20,7 @@ struct cmState::SnapshotDataType { + cmState::PositionType CallStackParent; cmState::PositionType DirectoryParent; cmState::SnapshotType SnapshotType; cmLinkedTree::iterator @@ -690,6 +691,7 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) { assert(originSnapshot.IsValid()); PositionType pos = this->SnapshotData.Extend(originSnapshot.Position); + pos->CallStackParent = originSnapshot.Position; pos->DirectoryParent = originSnapshot.Position; pos->SnapshotType = BuildsystemDirectoryType; pos->BuildSystemDirectory = @@ -698,6 +700,59 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) return cmState::Snapshot(this, pos); } +cmState::Snapshot +cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot) +{ + PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, + *originSnapshot.Position); + pos->CallStackParent = originSnapshot.Position; + pos->SnapshotType = FunctionCallType; + return cmState::Snapshot(this, pos); +} + + +cmState::Snapshot +cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot) +{ + PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, + *originSnapshot.Position); + pos->CallStackParent = originSnapshot.Position; + pos->SnapshotType = MacroCallType; + return cmState::Snapshot(this, pos); +} + +cmState::Snapshot +cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot) +{ + PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, + *originSnapshot.Position); + pos->CallStackParent = originSnapshot.Position; + pos->SnapshotType = CallStackType; + return cmState::Snapshot(this, pos); +} + +cmState::Snapshot +cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot) +{ + PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, + *originSnapshot.Position); + pos->CallStackParent = originSnapshot.Position; + pos->SnapshotType = InlineListFileType; + return cmState::Snapshot(this, pos); +} + +cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot) +{ + PositionType pos = originSnapshot.Position; + PositionType prevPos = pos; + ++prevPos; + if (prevPos == this->SnapshotData.Root()) + { + return Snapshot(this, prevPos); + } + return Snapshot(this, originSnapshot.Position->CallStackParent); +} + cmState::Snapshot::Snapshot(cmState* state, PositionType position) : State(state), Position(position) diff --git a/Source/cmState.h b/Source/cmState.h index 9c7574f..9a1f764 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -31,7 +31,11 @@ public: enum SnapshotType { - BuildsystemDirectoryType + BuildsystemDirectoryType, + FunctionCallType, + MacroCallType, + CallStackType, + InlineListFileType }; class Snapshot { @@ -69,7 +73,13 @@ public: }; Snapshot CreateBaseSnapshot(); - Snapshot CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot); + Snapshot + CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot); + Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot); + Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot); + Snapshot CreateCallStackSnapshot(Snapshot originSnapshot); + Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot); + Snapshot Pop(Snapshot originSnapshot); enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC, UNINITIALIZED }; -- cgit v0.12 From 94704d759cc8939f3573122d36d52c4598fd04ba Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 4 Jul 2015 06:56:13 +0200 Subject: cmState: Add GetCallStackParent method. --- Source/cmState.cxx | 22 ++++++++++++++++++++++ Source/cmState.h | 1 + 2 files changed, 23 insertions(+) diff --git a/Source/cmState.cxx b/Source/cmState.cxx index ef55e09..5ca1cce 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -854,6 +854,28 @@ cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const return snapshot; } +cmState::Snapshot cmState::Snapshot::GetCallStackParent() const +{ + assert(this->State); + assert(this->Position != this->State->SnapshotData.Root()); + + Snapshot snapshot; + if (this->Position->SnapshotType == cmState::BuildsystemDirectoryType) + { + return snapshot; + } + + PositionType parentPos = this->Position; + ++parentPos; + if (parentPos == this->State->SnapshotData.Root()) + { + return snapshot; + } + + snapshot = Snapshot(this->State, parentPos); + return snapshot; +} + cmState* cmState::Snapshot::GetState() const { return this->State; diff --git a/Source/cmState.h b/Source/cmState.h index 9a1f764..e35b843 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -59,6 +59,7 @@ public: bool IsValid() const; Snapshot GetBuildsystemDirectoryParent() const; + Snapshot GetCallStackParent() const; cmState* GetState() const; -- cgit v0.12 From 6361f680568c81e0391fa56cf9a7f4637bd745dc Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 31 May 2015 19:37:08 +0200 Subject: cmState: Store execution context. Extend snapshot creation API to store the file being executed and the entry point to get to that context. --- Source/cmFunctionCommand.cxx | 1 + Source/cmMacroCommand.cxx | 1 + Source/cmMakefile.cxx | 41 ++++++++++++++++++------- Source/cmMakefile.h | 12 ++++---- Source/cmState.cxx | 71 ++++++++++++++++++++++++++++++++++++++++---- Source/cmState.h | 32 ++++++++++++++++---- 6 files changed, 133 insertions(+), 25 deletions(-) diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index b3576c3..78853ce 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -95,6 +95,7 @@ bool cmFunctionHelperCommand::InvokeInitialPass } cmMakefile::FunctionPushPop functionScope(this->Makefile, + this->FilePath, this->Policies); // set the value of argc diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 0b945b2..3c2117b 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -97,6 +97,7 @@ bool cmMacroHelperCommand::InvokeInitialPass } cmMakefile::MacroPushPop macroScope(this->Makefile, + this->FilePath, this->Policies); // set the value of argc diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a176cda..eb26474 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -465,8 +465,11 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, this->Makefile->PushFunctionBlockerBarrier(); this->Makefile->StateSnapshot = - this->Makefile->GetState()->CreateCallStackSnapshot( - this->Makefile->StateSnapshot); + this->Makefile->GetState()->CreateCallStackSnapshot( + this->Makefile->StateSnapshot, + this->Makefile->ContextStack.back()->Name, + this->Makefile->ContextStack.back()->Line, + filenametoread); } //---------------------------------------------------------------------------- @@ -576,9 +579,16 @@ public: this->Makefile->ListFileStack.push_back(filenametoread); this->Makefile->PushPolicyBarrier(); + long line = 0; + std::string name; + if (!this->Makefile->ContextStack.empty()) + { + line = this->Makefile->ContextStack.back()->Line; + name = this->Makefile->ContextStack.back()->Name; + } this->Makefile->StateSnapshot = this->Makefile->GetState()->CreateInlineListFileSnapshot( - this->Makefile->StateSnapshot); + this->Makefile->StateSnapshot, name, line, filenametoread); assert(this->Makefile->StateSnapshot.IsValid()); this->Makefile->PushFunctionBlockerBarrier(); } @@ -1590,11 +1600,14 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent) this->ImportedTargets = parent->ImportedTargets; } -void cmMakefile::PushFunctionScope(const cmPolicies::PolicyMap& pm) +void cmMakefile::PushFunctionScope(std::string const& fileName, + const cmPolicies::PolicyMap& pm) { this->StateSnapshot = this->GetState()->CreateFunctionCallSnapshot( - this->StateSnapshot); + this->StateSnapshot, + this->ContextStack.back()->Name, this->ContextStack.back()->Line, + fileName); assert(this->StateSnapshot.IsValid()); this->Internal->PushDefinitions(); @@ -1632,11 +1645,14 @@ void cmMakefile::PopFunctionScope(bool reportError) this->Internal->PopDefinitions(); } -void cmMakefile::PushMacroScope(const cmPolicies::PolicyMap& pm) +void cmMakefile::PushMacroScope(std::string const& fileName, + const cmPolicies::PolicyMap& pm) { this->StateSnapshot = this->GetState()->CreateMacroCallSnapshot( - this->StateSnapshot); + this->StateSnapshot, + this->ContextStack.back()->Name, this->ContextStack.back()->Line, + fileName); assert(this->StateSnapshot.IsValid()); this->PushFunctionBlockerBarrier(); @@ -1670,6 +1686,7 @@ public: std::string currentStart = this->Makefile->StateSnapshot.GetCurrentSourceDirectory(); currentStart += "/CMakeLists.txt"; + this->Makefile->StateSnapshot.SetListFile(currentStart); this->Makefile->ListFileStack.push_back(currentStart); this->Makefile->PushPolicyBarrier(); this->Makefile->PushFunctionBlockerBarrier(); @@ -1813,7 +1830,9 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, } cmState::Snapshot newSnapshot = this->GetState() - ->CreateBuildsystemDirectorySnapshot(this->StateSnapshot); + ->CreateBuildsystemDirectorySnapshot(this->StateSnapshot, + this->ContextStack.back()->Name, + this->ContextStack.back()->Line); // create a new local generator and set its parent cmLocalGenerator *lg2 = this->GetGlobalGenerator() @@ -5511,10 +5530,11 @@ AddRequiredTargetCFeature(cmTarget *target, const std::string& feature) const cmMakefile::FunctionPushPop::FunctionPushPop(cmMakefile* mf, + const std::string& fileName, cmPolicies::PolicyMap const& pm) : Makefile(mf), ReportError(true) { - this->Makefile->PushFunctionScope(pm); + this->Makefile->PushFunctionScope(fileName, pm); } cmMakefile::FunctionPushPop::~FunctionPushPop() @@ -5524,10 +5544,11 @@ cmMakefile::FunctionPushPop::~FunctionPushPop() cmMakefile::MacroPushPop::MacroPushPop(cmMakefile* mf, + const std::string& fileName, const cmPolicies::PolicyMap& pm) : Makefile(mf), ReportError(true) { - this->Makefile->PushMacroScope(pm); + this->Makefile->PushMacroScope(fileName, pm); } cmMakefile::MacroPushPop::~MacroPushPop() diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 0ade8e1..01c9e8c 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -720,7 +720,7 @@ public: class FunctionPushPop { public: - FunctionPushPop(cmMakefile* mf, + FunctionPushPop(cmMakefile* mf, std::string const& fileName, cmPolicies::PolicyMap const& pm); ~FunctionPushPop(); @@ -733,8 +733,8 @@ public: class MacroPushPop { public: - MacroPushPop(cmMakefile* mf, - cmPolicies::PolicyMap const& pm); + MacroPushPop(cmMakefile* mf, std::string const& fileName, + cmPolicies::PolicyMap const& pm); ~MacroPushPop(); void Quiet() { this->ReportError = false; } @@ -743,9 +743,11 @@ public: bool ReportError; }; - void PushFunctionScope(cmPolicies::PolicyMap const& pm); + void PushFunctionScope(std::string const& fileName, + cmPolicies::PolicyMap const& pm); void PopFunctionScope(bool reportError); - void PushMacroScope(cmPolicies::PolicyMap const& pm); + void PushMacroScope(std::string const& fileName, + cmPolicies::PolicyMap const& pm); void PopMacroScope(bool reportError); void PushScope(); void PopScope(); diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 5ca1cce..d918f65 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -23,8 +23,11 @@ struct cmState::SnapshotDataType cmState::PositionType CallStackParent; cmState::PositionType DirectoryParent; cmState::SnapshotType SnapshotType; + cmLinkedTree::iterator ExecutionListFile; cmLinkedTree::iterator BuildSystemDirectory; + std::string EntryPointCommand; + long EntryPointLine; }; struct cmState::BuildsystemDirectoryStateType @@ -227,6 +230,7 @@ cmState::Snapshot cmState::Reset() this->BuildsystemDirectory.Truncate(); PositionType pos = this->SnapshotData.Truncate(); + this->ExecutionListFiles.Truncate(); this->DefineProperty ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, @@ -683,61 +687,98 @@ cmState::Snapshot cmState::CreateBaseSnapshot() pos->SnapshotType = BuildsystemDirectoryType; pos->BuildSystemDirectory = this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root()); + pos->ExecutionListFile = + this->ExecutionListFiles.Extend(this->ExecutionListFiles.Root()); return cmState::Snapshot(this, pos); } cmState::Snapshot -cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) +cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine) { assert(originSnapshot.IsValid()); PositionType pos = this->SnapshotData.Extend(originSnapshot.Position); pos->CallStackParent = originSnapshot.Position; + pos->EntryPointLine = entryPointLine; + pos->EntryPointCommand = entryPointCommand; pos->DirectoryParent = originSnapshot.Position; pos->SnapshotType = BuildsystemDirectoryType; pos->BuildSystemDirectory = this->BuildsystemDirectory.Extend( originSnapshot.Position->BuildSystemDirectory); + pos->ExecutionListFile = + this->ExecutionListFiles.Extend( + originSnapshot.Position->ExecutionListFile); return cmState::Snapshot(this, pos); } cmState::Snapshot -cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot) +cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine, + std::string const& fileName) { PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, *originSnapshot.Position); pos->CallStackParent = originSnapshot.Position; + pos->EntryPointLine = entryPointLine; + pos->EntryPointCommand = entryPointCommand; pos->SnapshotType = FunctionCallType; + pos->ExecutionListFile = this->ExecutionListFiles.Extend( + originSnapshot.Position->ExecutionListFile, fileName); return cmState::Snapshot(this, pos); } cmState::Snapshot -cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot) +cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine, + std::string const& fileName) { PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, *originSnapshot.Position); pos->CallStackParent = originSnapshot.Position; + pos->EntryPointLine = entryPointLine; + pos->EntryPointCommand = entryPointCommand; pos->SnapshotType = MacroCallType; + pos->ExecutionListFile = this->ExecutionListFiles.Extend( + originSnapshot.Position->ExecutionListFile, fileName); return cmState::Snapshot(this, pos); } cmState::Snapshot -cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot) +cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot, + const std::string& entryPointCommand, + long entryPointLine, + const std::string& fileName) { PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, *originSnapshot.Position); pos->CallStackParent = originSnapshot.Position; + pos->EntryPointLine = entryPointLine; + pos->EntryPointCommand = entryPointCommand; pos->SnapshotType = CallStackType; + pos->ExecutionListFile = this->ExecutionListFiles.Extend( + originSnapshot.Position->ExecutionListFile, fileName); return cmState::Snapshot(this, pos); } cmState::Snapshot -cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot) +cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot, + const std::string& entryPointCommand, + long entryPointLine, + const std::string& fileName) { PositionType pos = this->SnapshotData.Extend(originSnapshot.Position, *originSnapshot.Position); pos->CallStackParent = originSnapshot.Position; + pos->EntryPointLine = entryPointLine; + pos->EntryPointCommand = entryPointCommand; pos->SnapshotType = InlineListFileType; + pos->ExecutionListFile = this->ExecutionListFiles.Extend( + originSnapshot.Position->ExecutionListFile, fileName); return cmState::Snapshot(this, pos); } @@ -797,6 +838,11 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) this->ComputeRelativePathTopBinary(); } +void cmState::Snapshot::SetListFile(const std::string& listfile) +{ + *this->Position->ExecutionListFile = listfile; +} + std::vector const& cmState::Snapshot::GetCurrentSourceDirectoryComponents() const { @@ -831,6 +877,21 @@ void cmState::Snapshot::SetRelativePathTopBinary(const char* dir) this->Position->BuildSystemDirectory->RelativePathTopBinary = dir; } +std::string cmState::Snapshot::GetExecutionListFile() const +{ + return *this->Position->ExecutionListFile; +} + +std::string cmState::Snapshot::GetEntryPointCommand() const +{ + return this->Position->EntryPointCommand; +} + +long cmState::Snapshot::GetEntryPointLine() const +{ + return this->Position->EntryPointLine; +} + bool cmState::Snapshot::IsValid() const { return this->State && this->Position.IsValid() diff --git a/Source/cmState.h b/Source/cmState.h index e35b843..473a194 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -47,6 +47,8 @@ public: const char* GetCurrentBinaryDirectory() const; void SetCurrentBinaryDirectory(std::string const& dir); + void SetListFile(std::string const& listfile); + std::vector const& GetCurrentSourceDirectoryComponents() const; std::vector const& @@ -57,6 +59,10 @@ public: void SetRelativePathTopSource(const char* dir); void SetRelativePathTopBinary(const char* dir); + std::string GetExecutionListFile() const; + std::string GetEntryPointCommand() const; + long GetEntryPointLine() const; + bool IsValid() const; Snapshot GetBuildsystemDirectoryParent() const; Snapshot GetCallStackParent() const; @@ -75,11 +81,25 @@ public: Snapshot CreateBaseSnapshot(); Snapshot - CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot); - Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot); - Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot); - Snapshot CreateCallStackSnapshot(Snapshot originSnapshot); - Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot); + CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine); + Snapshot CreateFunctionCallSnapshot(Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine, + std::string const& fileName); + Snapshot CreateMacroCallSnapshot(Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine, + std::string const& fileName); + Snapshot CreateCallStackSnapshot(Snapshot originSnapshot, + std::string const& entryPointCommand, + long entryPointLine, + std::string const& fileName); + Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot, + const std::string& entryPointCommand, + long entryPointLine, + std::string const& fileName); Snapshot Pop(Snapshot originSnapshot); enum CacheEntryType{ BOOL=0, PATH, FILEPATH, STRING, INTERNAL,STATIC, @@ -186,6 +206,8 @@ private: struct BuildsystemDirectoryStateType; cmLinkedTree BuildsystemDirectory; + cmLinkedTree ExecutionListFiles; + cmLinkedTree SnapshotData; std::vector SourceDirectoryComponents; -- cgit v0.12 From 30d44efaf86194271c70f90a8fafa94a7d56f92c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 4 Jul 2015 12:20:47 +0200 Subject: cmMakefile: Access the execution list file from the cmState. --- Source/cmMakefile.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index eb26474..08df655 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -3418,7 +3418,8 @@ std::string cmMakefile::GetExecutionFilePath() const { return std::string(); } - return this->ContextStack.back()->FilePath; + assert(this->StateSnapshot.IsValid()); + return this->StateSnapshot.GetExecutionListFile(); } //---------------------------------------------------------------------------- -- cgit v0.12 From 821f91d6ab668bbfcfc645a872acf91f71f76ff1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 5 Jul 2015 19:28:45 +0200 Subject: cmMakefile: Create a scoped context for parsing listfiles. Update the Syntax tests to check for updated/improved backtraces. --- Source/cmMakefile.cxx | 30 ++++++++++++++++++++++++ Source/cmMakefile.h | 1 + Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt | 4 +++- Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt | 4 +++- Tests/RunCMake/Syntax/ParenInENV-stderr.txt | 4 +++- Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt | 12 +++++++--- Tests/RunCMake/Syntax/StringNoSpace-stderr.txt | 8 +++++-- 15 files changed, 79 insertions(+), 16 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 08df655..0d48cbc 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -547,6 +547,26 @@ void cmMakefile::IncludeScope::EnforceCMP0011() } } +class cmParseFileScope +{ +public: + cmParseFileScope(cmMakefile* mf) + : Makefile(mf) + { + this->Context.FilePath = this->Makefile->GetExecutionFilePath(); + this->Makefile->ContextStack.push_back(&this->Context); + } + + ~cmParseFileScope() + { + this->Makefile->ContextStack.pop_back(); + } + +private: + cmMakefile* Makefile; + cmListFileContext Context; +}; + bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope) { this->AddDefinition("CMAKE_PARENT_LIST_FILE", @@ -558,10 +578,14 @@ bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope) IncludeScope incScope(this, filenametoread, noPolicyScope); cmListFile listFile; + { + cmParseFileScope pfs(this); if (!listFile.ParseFile(filenametoread.c_str(), false, this)) { return false; } + } + this->ReadListFile(listFile, filenametoread); if(cmSystemTools::GetFatalErrorOccured()) { @@ -619,10 +643,13 @@ bool cmMakefile::ReadListFile(const char* filename) ListFileScope scope(this, filenametoread); cmListFile listFile; + { + cmParseFileScope pfs(this); if (!listFile.ParseFile(filenametoread.c_str(), false, this)) { return false; } + } this->ReadListFile(listFile, filenametoread); if(cmSystemTools::GetFatalErrorOccured()) @@ -1738,11 +1765,14 @@ void cmMakefile::Configure() this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str()); cmListFile listFile; + { + cmParseFileScope pfs(this); if (!listFile.ParseFile(currentStart.c_str(), this->IsRootMakefile(), this)) { this->SetConfigured(); return; } + } this->ReadListFile(listFile, currentStart); if(cmSystemTools::GetFatalErrorOccured()) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 01c9e8c..03b9c04 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -940,6 +940,7 @@ private: std::vector ContextStack; std::vector ExecutionStatusStack; friend class cmMakefileCall; + friend class cmParseFileScope; std::vector ImportedTargetsOwned; TargetMap ImportedTargets; diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt index b3f1e47..a845ffb 100644 --- a/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt +++ b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BOM-UTF-16-BE.cmake: File .*/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake starts with a Byte-Order-Mark that is not UTF-8. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt index c08c902..cc4244b 100644 --- a/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt +++ b/Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BOM-UTF-16-LE.cmake: File .*/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake starts with a Byte-Order-Mark that is not UTF-8. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt index 5dde4e3..5f851bf 100644 --- a/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt +++ b/Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BOM-UTF-32-BE.cmake: File .*/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake starts with a Byte-Order-Mark that is not UTF-8. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt index eb054ec..d8fafd0 100644 --- a/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt +++ b/Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BOM-UTF-32-LE.cmake: File .*/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake starts with a Byte-Order-Mark that is not UTF-8. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt index afd91f9..a288280 100644 --- a/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt +++ b/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BracketNoSpace0.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/BracketNoSpace0.cmake:1:27 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt index 826e511..391e11b 100644 --- a/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt +++ b/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BracketNoSpace1.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/BracketNoSpace1.cmake:1:24 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt index 23ecdcd..acaf7fe 100644 --- a/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt +++ b/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BracketNoSpace2.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/BracketNoSpace2.cmake:1:44 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt index 906d6fc..f12b2e5 100644 --- a/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt +++ b/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BracketNoSpace3.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/BracketNoSpace3.cmake:1:45 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt index a461e93..7157763 100644 --- a/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt +++ b/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BracketNoSpace4.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/BracketNoSpace4.cmake:1:44 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt index ff8bf1c..c13969d 100644 --- a/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt +++ b/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt @@ -1,6 +1,8 @@ -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in BracketNoSpace5.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/BracketNoSpace5.cmake:1:45 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/ParenInENV-stderr.txt b/Tests/RunCMake/Syntax/ParenInENV-stderr.txt index 7ecfe11..37c5d6e 100644 --- a/Tests/RunCMake/Syntax/ParenInENV-stderr.txt +++ b/Tests/RunCMake/Syntax/ParenInENV-stderr.txt @@ -1,9 +1,11 @@ -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): +CMake Warning \(dev\) in ParenInENV.cmake: Syntax Warning in cmake code at .*/Tests/RunCMake/Syntax/ParenInENV.cmake:2:21 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) This warning is for project developers. Use -Wno-dev to suppress it. CMake Error at ParenInENV.cmake:2 \(message\): diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt b/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt index 64ef8b1..45b2e6a 100644 --- a/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt +++ b/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt @@ -1,22 +1,28 @@ -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): +CMake Warning \(dev\) in ParenNoSpace1.cmake: Syntax Warning in cmake code at .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:1:26 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) This warning is for project developers. Use -Wno-dev to suppress it. -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): +CMake Warning \(dev\) in ParenNoSpace1.cmake: Syntax Warning in cmake code at .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:2:26 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) This warning is for project developers. Use -Wno-dev to suppress it. -CMake Error at CMakeLists.txt:3 \(include\): +CMake Error in ParenNoSpace1.cmake: Syntax Error in cmake code at .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:3:29 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt b/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt index 89c2d2a..a4ec6e7 100644 --- a/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt +++ b/Tests/RunCMake/Syntax/StringNoSpace-stderr.txt @@ -1,17 +1,21 @@ -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): +CMake Warning \(dev\) in StringNoSpace.cmake: Syntax Warning in cmake code at .*/Tests/RunCMake/Syntax/StringNoSpace.cmake:2:28 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) This warning is for project developers. Use -Wno-dev to suppress it. -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): +CMake Warning \(dev\) in StringNoSpace.cmake: Syntax Warning in cmake code at .*/Tests/RunCMake/Syntax/StringNoSpace.cmake:2:31 Argument not separated from preceding token by whitespace. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) This warning is for project developers. Use -Wno-dev to suppress it. \[1 \${var} \\n 4\] -- cgit v0.12 From 91158a3369e0f06600a9ada93222535d53361035 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 4 Jul 2015 12:14:58 +0200 Subject: cmMakefile: Create intermediate variables for snapshot frames. --- Source/cmMakefile.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0d48cbc..8d02092 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -280,7 +280,8 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const i = this->ContextStack.rbegin(); i != this->ContextStack.rend(); ++i) { - backtrace.Append(*(*i)); + cmListFileContext frame = *(*i); + backtrace.Append(frame); } return backtrace; } @@ -295,7 +296,8 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const i = this->ContextStack.rbegin(); i != this->ContextStack.rend(); ++i) { - backtrace.Append(*(*i)); + cmListFileContext frame = *(*i); + backtrace.Append(frame); } return backtrace; } -- cgit v0.12 From 329098a9a0e81e67bd760f53811cce582a3ebdcd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 4 Jul 2015 12:16:39 +0200 Subject: cmMakefile: Set the FilePath on the frame from the cmState. To verify unit tests pass and for future bisecting. --- Source/cmMakefile.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 8d02092..a65f6ba 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -276,11 +276,13 @@ void cmMakefile::IssueMessage(cmake::MessageType t, cmListFileBacktrace cmMakefile::GetBacktrace() const { cmListFileBacktrace backtrace(this->StateSnapshot); + cmState::Snapshot snp = this->StateSnapshot; for(std::vector::const_reverse_iterator i = this->ContextStack.rbegin(); - i != this->ContextStack.rend(); ++i) + i != this->ContextStack.rend(); ++i, snp = snp.GetCallStackParent()) { cmListFileContext frame = *(*i); + frame.FilePath = snp.GetExecutionListFile(); backtrace.Append(frame); } return backtrace; @@ -292,11 +294,15 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const { cmListFileBacktrace backtrace(this->StateSnapshot); backtrace.Append(lfc); + cmState::Snapshot snp = this->StateSnapshot; + assert(snp.GetExecutionListFile() == lfc.FilePath); + snp = snp.GetCallStackParent(); for(std::vector::const_reverse_iterator i = this->ContextStack.rbegin(); - i != this->ContextStack.rend(); ++i) + i != this->ContextStack.rend(); ++i, snp = snp.GetCallStackParent()) { cmListFileContext frame = *(*i); + frame.FilePath = snp.GetExecutionListFile(); backtrace.Append(frame); } return backtrace; -- cgit v0.12 From 238aac23514ecdae0d4edb71033e443f30e94158 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 4 Jul 2015 13:12:50 +0200 Subject: cmListFile: Remove FilePath member from cmListFileContext. There is no need to store the FilePath for every function, as it is known by other means. --- Source/cmIfCommand.cxx | 5 ++++- Source/cmListFileCache.cxx | 1 - Source/cmListFileCache.h | 19 ++++++++++++++++++- Source/cmMacroCommand.cxx | 1 - Source/cmMakefile.cxx | 35 ++++++++++++++++++++++------------- Source/cmMakefile.h | 4 ++-- Source/cmVariableWatchCommand.cxx | 1 - 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 20448c1..cdf278c 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -115,7 +115,10 @@ IsFunctionBlocked(const cmListFileFunction& lff, { std::string err = cmIfCommandError(expandedArguments); 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); if (messType == cmake::FATAL_ERROR) { diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 006ca4c..9141d88 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -251,7 +251,6 @@ bool cmListFileParser::ParseFunction(const char* name, long line) { // Inintialize a new function call. this->Function = cmListFileFunction(); - this->Function.FilePath = this->FileName; this->Function.Name = name; this->Function.Line = line; diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index f5859ec..57bf253 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -25,6 +25,13 @@ class cmMakefile; +struct cmCommandContext +{ + std::string Name; + long Line; + cmCommandContext(): Name(), Line(0) {} +}; + struct cmListFileArgument { enum Delimiter @@ -57,6 +64,16 @@ struct cmListFileContext std::string FilePath; long Line; 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&); @@ -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); -struct cmListFileFunction: public cmListFileContext +struct cmListFileFunction: public cmCommandContext { std::vector Arguments; }; diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 3c2117b..6d3054a 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -132,7 +132,6 @@ bool cmMacroHelperCommand::InvokeInitialPass newLFF.Arguments.clear(); newLFF.Arguments.reserve(this->Functions[c].Arguments.size()); newLFF.Name = this->Functions[c].Name; - newLFF.FilePath = this->Functions[c].FilePath; newLFF.Line = this->Functions[c].Line; // for each argument of the current function diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a65f6ba..9f2abff 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -277,12 +277,15 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const { cmListFileBacktrace backtrace(this->StateSnapshot); cmState::Snapshot snp = this->StateSnapshot; - for(std::vector::const_reverse_iterator + for(std::vector::const_reverse_iterator i = this->ContextStack.rbegin(); - i != this->ContextStack.rend(); ++i, snp = snp.GetCallStackParent()) + i != this->ContextStack.rend(); + ++i, snp = snp.GetCallStackParent()) { - cmListFileContext frame = *(*i); - frame.FilePath = snp.GetExecutionListFile(); + assert(snp.IsValid()); + cmListFileContext frame = + cmListFileContext::FromCommandContext(*(*i), + snp.GetExecutionListFile()); backtrace.Append(frame); } return backtrace; @@ -297,12 +300,15 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) const cmState::Snapshot snp = this->StateSnapshot; assert(snp.GetExecutionListFile() == lfc.FilePath); snp = snp.GetCallStackParent(); - for(std::vector::const_reverse_iterator + for(std::vector::const_reverse_iterator i = this->ContextStack.rbegin(); - i != this->ContextStack.rend(); ++i, snp = snp.GetCallStackParent()) + i != this->ContextStack.rend(); + ++i, snp = snp.GetCallStackParent()) { - cmListFileContext frame = *(*i); - frame.FilePath = snp.GetExecutionListFile(); + assert(snp.IsValid()); + cmListFileContext frame = + cmListFileContext::FromCommandContext(*(*i), + snp.GetExecutionListFile()); backtrace.Append(frame); } return backtrace; @@ -311,7 +317,9 @@ cmMakefile::GetBacktrace(cmListFileContext const& lfc) 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) : Makefile(mf) { - this->Context.FilePath = this->Makefile->GetExecutionFilePath(); this->Makefile->ContextStack.push_back(&this->Context); } @@ -572,7 +579,7 @@ public: private: cmMakefile* Makefile; - cmListFileContext Context; + cmCommandContext Context; }; bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope) @@ -3581,11 +3588,13 @@ cmMakefile::RemoveFunctionBlocker(cmFunctionBlocker* fb, if(!(*pos)->ShouldRemove(lff, *this)) { cmListFileContext const& lfc = fb->GetStartingContext(); + cmListFileContext closingContext = + cmListFileContext::FromCommandContext(lff, lfc.FilePath); std::ostringstream e; e << "A logical block opening on the line\n" << " " << lfc << "\n" << "closes on the line\n" - << " " << lff << "\n" + << " " << closingContext << "\n" << "with mis-matching arguments."; this->IssueMessage(cmake::AUTHOR_WARNING, e.str()); } @@ -5595,7 +5604,7 @@ cmMakefile::MacroPushPop::~MacroPushPop() this->Makefile->PopMacroScope(this->ReportError); } -cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmListFileContext& lfc, +cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmCommandContext& lfc, cmExecutionStatus& status): Makefile(mf) { this->Makefile->ContextStack.push_back(&lfc); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 03b9c04..d3cf02e 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -937,7 +937,7 @@ private: // stack of list files being read std::vector ListFileStack; - std::vector ContextStack; + std::vector ContextStack; std::vector ExecutionStatusStack; friend class cmMakefileCall; friend class cmParseFileScope; @@ -1055,7 +1055,7 @@ class cmMakefileCall { public: cmMakefileCall(cmMakefile* mf, - cmListFileContext const& lfc, + cmCommandContext const& lfc, cmExecutionStatus& status); ~cmMakefileCall(); private: diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index 6521c04..98a397c 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -63,7 +63,6 @@ static void cmVariableWatchCommandVariableAccessed( cmListFileArgument(stack, cmListFileArgument::Quoted, 9999)); newLFF.Name = data->Command; - newLFF.FilePath = "unknown"; newLFF.Line = 9999; cmExecutionStatus status; if(!makefile->ExecuteCommand(newLFF,status)) -- cgit v0.12 From d2475bb5c4488a0ef6015f13ee46ddc7a2e4455b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 29 May 2015 22:37:59 +0200 Subject: cmListFileBacktrace: Implement in terms of cmState::Snapshot. Avoid copying many strings into each backtrace object. --- Source/cmIfCommand.cxx | 5 +---- Source/cmListFileCache.cxx | 38 ++++++++++++++++++++++++-------------- Source/cmListFileCache.h | 10 +++++----- Source/cmMakefile.cxx | 34 ++++++---------------------------- Source/cmMakefile.h | 2 +- 5 files changed, 37 insertions(+), 52 deletions(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index cdf278c..20448c1 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -115,10 +115,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, { std::string err = cmIfCommandError(expandedArguments); err += errorString; - cmListFileContext lfc = - cmListFileContext::FromCommandContext( - this->Functions[c], this->GetStartingContext().FilePath); - cmListFileBacktrace bt = mf.GetBacktrace(lfc); + cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]); mf.GetCMakeInstance()->IssueMessage(messType, err, bt); if (messType == cmake::FATAL_ERROR) { diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 9141d88..1097dc2 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -398,40 +398,50 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, } } -void cmListFileBacktrace::Append(cmListFileContext const& context) -{ - this->push_back(context); -} - void cmListFileBacktrace::PrintTitle(std::ostream& out) { - if (this->empty()) + if (!this->Snapshot.IsValid()) { return; } - cmOutputConverter converter(this->Snapshot); - cmListFileContext lfc = this->front(); + cmListFileContext lfc = + cmListFileContext::FromCommandContext( + this->Context, this->Snapshot.GetExecutionListFile()); lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); out << (lfc.Line ? " at " : " in ") << lfc; } void cmListFileBacktrace::PrintCallStack(std::ostream& out) { - if (size() <= 1) + if (!this->Snapshot.IsValid()) + { + return; + } + cmState::Snapshot parent = this->Snapshot.GetCallStackParent(); + if (!parent.IsValid() || parent.GetExecutionListFile().empty()) { return; } cmOutputConverter converter(this->Snapshot); - const_iterator i = this->begin() + 1; + std::string commandName = this->Snapshot.GetEntryPointCommand(); + long commandLine = this->Snapshot.GetEntryPointLine(); + out << "Call Stack (most recent call first):\n"; - while(i != this->end()) + while(parent.IsValid()) { - cmListFileContext lfc = *i; - lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); + cmListFileContext lfc; + lfc.Name = commandName; + lfc.Line = commandLine; + + lfc.FilePath = converter.Convert(parent.GetExecutionListFile(), + cmOutputConverter::HOME); out << " " << lfc << "\n"; - ++i; + + commandName = parent.GetEntryPointCommand(); + commandLine = parent.GetEntryPointLine(); + parent = parent.GetCallStackParent(); } } diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 57bf253..aa8a34c 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -86,19 +86,19 @@ struct cmListFileFunction: public cmCommandContext std::vector Arguments; }; -class cmListFileBacktrace: private std::vector +class cmListFileBacktrace { public: - cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot()) - : Snapshot(snapshot) + cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot(), + cmCommandContext const& cc = cmCommandContext()) + : Context(cc), Snapshot(snapshot) { } - void Append(cmListFileContext const& context); - void PrintTitle(std::ostream& out); void PrintCallStack(std::ostream& out); private: + cmCommandContext Context; cmState::Snapshot Snapshot; }; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 9f2abff..94c77e1 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -275,43 +275,21 @@ void cmMakefile::IssueMessage(cmake::MessageType t, //---------------------------------------------------------------------------- cmListFileBacktrace cmMakefile::GetBacktrace() const { - cmListFileBacktrace backtrace(this->StateSnapshot); - cmState::Snapshot snp = this->StateSnapshot; - for(std::vector::const_reverse_iterator - i = this->ContextStack.rbegin(); - i != this->ContextStack.rend(); - ++i, snp = snp.GetCallStackParent()) + cmListFileBacktrace backtrace; + if (!this->ContextStack.empty()) { - assert(snp.IsValid()); - cmListFileContext frame = - cmListFileContext::FromCommandContext(*(*i), - snp.GetExecutionListFile()); - backtrace.Append(frame); + backtrace = cmListFileBacktrace(this->StateSnapshot, + *this->ContextStack.back()); } return backtrace; } //---------------------------------------------------------------------------- cmListFileBacktrace -cmMakefile::GetBacktrace(cmListFileContext const& lfc) const +cmMakefile::GetBacktrace(cmCommandContext const& cc) const { - cmListFileBacktrace backtrace(this->StateSnapshot); - backtrace.Append(lfc); cmState::Snapshot snp = this->StateSnapshot; - assert(snp.GetExecutionListFile() == lfc.FilePath); - snp = snp.GetCallStackParent(); - for(std::vector::const_reverse_iterator - i = this->ContextStack.rbegin(); - i != this->ContextStack.rend(); - ++i, snp = snp.GetCallStackParent()) - { - assert(snp.IsValid()); - cmListFileContext frame = - cmListFileContext::FromCommandContext(*(*i), - snp.GetExecutionListFile()); - backtrace.Append(frame); - } - return backtrace; + return cmListFileBacktrace(snp, cc); } //---------------------------------------------------------------------------- diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d3cf02e..82a2279 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -547,7 +547,7 @@ public: * Get the current context backtrace. */ cmListFileBacktrace GetBacktrace() const; - cmListFileBacktrace GetBacktrace(cmListFileContext const& lfc) const; + cmListFileBacktrace GetBacktrace(cmCommandContext const& lfc) const; cmListFileContext GetExecutionContext() const; /** -- cgit v0.12