cmake/Source/cmListFileCache.h

181 lines
4.7 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>
2018-10-28 12:09:07 +01:00
#include <memory> // IWYU pragma: keep
2018-04-23 21:13:27 +02:00
#include <stddef.h>
2016-10-30 18:24:19 +01:00
#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
{
2018-08-09 18:06:22 +02:00
struct cmCommandName
{
std::string Lower;
std::string Original;
cmCommandName() {}
cmCommandName(std::string const& name) { *this = name; }
cmCommandName& operator=(std::string const& name);
} Name;
2015-11-17 17:22:37 +01:00
long Line;
2016-07-09 11:21:54 +02:00
cmCommandContext()
2018-08-09 18:06:22 +02:00
: Line(0)
{
}
cmCommandContext(const char* name, int line)
: Name(name)
, Line(line)
2016-07-09 11:21:54 +02:00
{
}
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;
2018-08-09 18:06:22 +02:00
lfc.Name = lfcc.Name.Original;
2015-11-17 17:22:37 +01:00
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.
2018-10-28 12:09:07 +01:00
cmListFileBacktrace() = default;
2016-07-09 11:21:54 +02:00
// 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
2018-10-28 12:09:07 +01:00
// Backtraces may be copied, moved, and assigned as values.
cmListFileBacktrace(cmListFileBacktrace const&) = default;
cmListFileBacktrace(cmListFileBacktrace&&) // NOLINT(clang-tidy)
noexcept = default;
cmListFileBacktrace& operator=(cmListFileBacktrace const&) = default;
cmListFileBacktrace& operator=(cmListFileBacktrace&&) // NOLINT(clang-tidy)
noexcept = default;
~cmListFileBacktrace() = default;
2016-07-09 11:21:54 +02:00
2018-10-28 12:09:07 +01:00
cmStateSnapshot GetBottom() const;
2017-04-14 19:02:05 +02:00
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.
2018-10-28 12:09:07 +01:00
// This may be called only if Empty() would return false.
2016-07-09 11:21:54 +02:00
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;
2018-04-23 21:13:27 +02:00
// Get the number of 'frames' in this backtrace
size_t Depth() const;
2018-10-28 12:09:07 +01:00
// Return true if this backtrace is empty.
bool Empty() const;
2016-07-09 11:21:54 +02:00
private:
struct Entry;
2018-10-28 12:09:07 +01:00
std::shared_ptr<Entry const> TopEntry;
cmListFileBacktrace(std::shared_ptr<Entry const> parent,
2016-07-09 11:21:54 +02:00
cmListFileContext const& lfc);
2018-10-28 12:09:07 +01:00
cmListFileBacktrace(std::shared_ptr<Entry const> top);
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