cmake/Source/cmListFileCache.h

160 lines
4.0 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmListFileCache_h
#define cmListFileCache_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <string>
#include <vector>
2017-04-14 19:02:05 +02:00
#include "cmStateSnapshot.h"
2015-04-27 22:25:09 +02:00
/** \class cmListFileCache
* \brief A class to cache list file contents.
*
* cmListFileCache is a class used to cache the contents of parsed
* cmake list files.
*/
2016-10-30 18:24:19 +01:00
class cmMessenger;
2013-03-16 19:13:01 +02:00
2015-11-17 17:22:37 +01:00
struct cmCommandContext
{
std::string Name;
long Line;
2016-07-09 11:21:54 +02:00
cmCommandContext()
: Name()
, Line(0)
{
}
2015-11-17 17:22:37 +01:00
};
struct cmListFileArgument
{
2013-11-03 12:27:13 +02:00
enum Delimiter
2016-07-09 11:21:54 +02:00
{
2013-11-03 12:27:13 +02:00
Unquoted,
2014-08-03 19:52:23 +02:00
Quoted,
Bracket
2016-07-09 11:21:54 +02:00
};
cmListFileArgument()
: Value()
, Delim(Unquoted)
, Line(0)
{
}
2015-11-17 17:22:37 +01:00
cmListFileArgument(const std::string& v, Delimiter d, long line)
2016-07-09 11:21:54 +02:00
: Value(v)
, Delim(d)
, Line(line)
{
}
bool operator==(const cmListFileArgument& r) const
{
2013-11-03 12:27:13 +02:00
return (this->Value == r.Value) && (this->Delim == r.Delim);
2016-07-09 11:21:54 +02:00
}
bool operator!=(const cmListFileArgument& r) const { return !(*this == r); }
std::string Value;
2013-11-03 12:27:13 +02:00
Delimiter Delim;
long Line;
};
2016-07-09 11:21:54 +02:00
class cmListFileContext
{
2016-07-09 11:21:54 +02:00
public:
std::string Name;
std::string FilePath;
long Line;
2016-07-09 11:21:54 +02:00
cmListFileContext()
: Name()
, FilePath()
, Line(0)
{
}
2015-11-17 17:22:37 +01:00
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&);
2015-08-17 11:37:30 +02:00
bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs);
bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs);
bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs);
2016-07-09 11:21:54 +02:00
struct cmListFileFunction : public cmCommandContext
{
std::vector<cmListFileArgument> Arguments;
};
2016-07-09 11:21:54 +02:00
// Represent a backtrace (call stack). Provide value semantics
// but use efficient reference-counting underneath to avoid copies.
2015-11-17 17:22:37 +01:00
class cmListFileBacktrace
2015-04-27 22:25:09 +02:00
{
2016-07-09 11:21:54 +02:00
public:
// Default-constructed backtrace may not be used until after
// set via assignment from a backtrace constructed with a
// valid snapshot.
cmListFileBacktrace();
// Construct an empty backtrace whose bottom sits in the directory
// indicated by the given valid snapshot.
2017-07-20 19:35:53 +02:00
cmListFileBacktrace(cmStateSnapshot const& snapshot);
2016-07-09 11:21:54 +02:00
// Backtraces may be copied and assigned as values.
cmListFileBacktrace(cmListFileBacktrace const& r);
cmListFileBacktrace& operator=(cmListFileBacktrace const& r);
~cmListFileBacktrace();
2017-04-14 19:02:05 +02:00
cmStateSnapshot GetBottom() const { return this->Bottom; }
2016-07-09 11:21:54 +02:00
// Get a backtrace with the given file scope added to the top.
// May not be called until after construction with a valid snapshot.
cmListFileBacktrace Push(std::string const& file) const;
// Get a backtrace with the given call context added to the top.
// May not be called until after construction with a valid snapshot.
cmListFileBacktrace Push(cmListFileContext const& lfc) const;
// Get a backtrace with the top level removed.
// May not be called until after a matching Push.
cmListFileBacktrace Pop() const;
// Get the context at the top of the backtrace.
// Returns an empty context if the backtrace is empty.
cmListFileContext const& Top() const;
// Print the top of the backtrace.
void PrintTitle(std::ostream& out) const;
// Print the call stack below the top of the backtrace.
void PrintCallStack(std::ostream& out) const;
private:
struct Entry;
2016-10-30 18:24:19 +01:00
2017-04-14 19:02:05 +02:00
cmStateSnapshot Bottom;
2016-07-09 11:21:54 +02:00
Entry* Cur;
2017-07-20 19:35:53 +02:00
cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* up,
2016-07-09 11:21:54 +02:00
cmListFileContext const& lfc);
2017-07-20 19:35:53 +02:00
cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* cur);
2015-04-27 22:25:09 +02:00
};
struct cmListFile
{
2016-10-30 18:24:19 +01:00
bool ParseFile(const char* path, cmMessenger* messenger,
cmListFileBacktrace const& lfbt);
std::vector<cmListFileFunction> Functions;
};
#endif