CMake/Source/cmListFileCache.h

113 lines
3.0 KiB
C
Raw Normal View History

/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef cmListFileCache_h
#define cmListFileCache_h
#include "cmStandardIncludes.h"
#include "cmState.h"
/** \class cmListFileCache
* \brief A class to cache list file contents.
*
* cmListFileCache is a class used to cache the contents of parsed
* cmake list files.
*/
class cmMakefile;
struct cmCommandContext
{
std::string Name;
long Line;
cmCommandContext(): Name(), Line(0) {}
};
struct cmListFileArgument
{
enum Delimiter
{
Unquoted,
Quoted,
Bracket
};
cmListFileArgument(): Value(), Delim(Unquoted), Line(0) {}
cmListFileArgument(const cmListFileArgument& r)
: Value(r.Value), Delim(r.Delim), Line(r.Line) {}
cmListFileArgument(const std::string& v, Delimiter d, long line)
: Value(v), Delim(d), Line(line) {}
bool operator == (const cmListFileArgument& r) const
{
return (this->Value == r.Value) && (this->Delim == r.Delim);
}
2002-12-17 22:55:31 +03:00
bool operator != (const cmListFileArgument& r) const
{
return !(*this == r);
}
std::string Value;
Delimiter Delim;
long Line;
};
class cmListFileContext
{
public:
2006-03-15 19:02:08 +03:00
std::string Name;
std::string FilePath;
2006-03-15 19:02:08 +03:00
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&);
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 cmCommandContext
{
std::vector<cmListFileArgument> Arguments;
};
cmState: Avoid accumulating snapshot storage for backtraces Changes during post-3.3/pre-3.4 development refactored storage of most configure-time information, including variable bindings and function scopes. All scopes (even short-lived) were kept persistently for possible future debugging features, causing huge accumulated memory usage. This was mostly addressed by commit v3.4.1~4^2 (cmState: Avoid accumulating snapshot storage for short-lived scopes, 2015-11-24). Since then we still keep short-lived scopes when they are needed for a backtrace. This is because since commit v3.4.0-rc1~378^2 (cmListFileBacktrace: Implement in terms of cmState::Snapshot, 2015-05-29) backtraces have been lightweight objects that simply point into the snapshot tree. While the intention of this approach was to avoid duplicating the call stack file path strings, the cost turned out to be holding on to the entire call stack worth of scope snapshots, which is much worse. Furthermore, since commit v3.4.0-rc2~1^2 (cmIfCommand: Issue CMP0054 warning with appropriate context, 2015-10-20) all conditions used in `if()` commands hold a backtrace for use in diagnostic messages. Even though the backtrace is short-lived it still causes the scope snapshot to be kept. This means that code like function(foo) if(0) endif() endfunction() foreach(i RANGE 1000000) foo() endforeach() accumulates storage for the function call scope snapshots. Fix this by partially reverting commit v3.4.0-rc1~378^2 and saving the entire call stack during cmListFileBacktrace construction. This way we can avoid keeping short-lived scope snapshot storage in all cases.
2016-04-13 00:07:08 +03:00
class cmListFileBacktrace: private std::vector<cmListFileContext>
{
public:
cmListFileBacktrace(cmState::Snapshot snapshot = cmState::Snapshot(),
cmCommandContext const& cc = cmCommandContext());
~cmListFileBacktrace();
2015-07-09 23:26:51 +03:00
void PrintTitle(std::ostream& out) const;
void PrintCallStack(std::ostream& out) const;
private:
cmState::Snapshot Snapshot;
};
struct cmListFile
{
bool ParseFile(const char* path,
bool topLevel,
cmMakefile *mf);
2006-03-15 19:02:08 +03:00
std::vector<cmListFileFunction> Functions;
};
#endif