cmListFileCache.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmListFileCache_h
  11. #define cmListFileCache_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmState.h"
  14. /** \class cmListFileCache
  15. * \brief A class to cache list file contents.
  16. *
  17. * cmListFileCache is a class used to cache the contents of parsed
  18. * cmake list files.
  19. */
  20. class cmMessenger;
  21. struct cmCommandContext
  22. {
  23. std::string Name;
  24. long Line;
  25. cmCommandContext()
  26. : Name()
  27. , Line(0)
  28. {
  29. }
  30. };
  31. struct cmListFileArgument
  32. {
  33. enum Delimiter
  34. {
  35. Unquoted,
  36. Quoted,
  37. Bracket
  38. };
  39. cmListFileArgument()
  40. : Value()
  41. , Delim(Unquoted)
  42. , Line(0)
  43. {
  44. }
  45. cmListFileArgument(const cmListFileArgument& r)
  46. : Value(r.Value)
  47. , Delim(r.Delim)
  48. , Line(r.Line)
  49. {
  50. }
  51. cmListFileArgument(const std::string& v, Delimiter d, long line)
  52. : Value(v)
  53. , Delim(d)
  54. , Line(line)
  55. {
  56. }
  57. bool operator==(const cmListFileArgument& r) const
  58. {
  59. return (this->Value == r.Value) && (this->Delim == r.Delim);
  60. }
  61. bool operator!=(const cmListFileArgument& r) const { return !(*this == r); }
  62. std::string Value;
  63. Delimiter Delim;
  64. long Line;
  65. };
  66. class cmListFileContext
  67. {
  68. public:
  69. std::string Name;
  70. std::string FilePath;
  71. long Line;
  72. cmListFileContext()
  73. : Name()
  74. , FilePath()
  75. , Line(0)
  76. {
  77. }
  78. static cmListFileContext FromCommandContext(cmCommandContext const& lfcc,
  79. std::string const& fileName)
  80. {
  81. cmListFileContext lfc;
  82. lfc.FilePath = fileName;
  83. lfc.Line = lfcc.Line;
  84. lfc.Name = lfcc.Name;
  85. return lfc;
  86. }
  87. };
  88. std::ostream& operator<<(std::ostream&, cmListFileContext const&);
  89. bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs);
  90. bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs);
  91. bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs);
  92. struct cmListFileFunction : public cmCommandContext
  93. {
  94. std::vector<cmListFileArgument> Arguments;
  95. };
  96. // Represent a backtrace (call stack). Provide value semantics
  97. // but use efficient reference-counting underneath to avoid copies.
  98. class cmListFileBacktrace
  99. {
  100. public:
  101. // Default-constructed backtrace may not be used until after
  102. // set via assignment from a backtrace constructed with a
  103. // valid snapshot.
  104. cmListFileBacktrace();
  105. // Construct an empty backtrace whose bottom sits in the directory
  106. // indicated by the given valid snapshot.
  107. cmListFileBacktrace(cmState::Snapshot snapshot);
  108. // Backtraces may be copied and assigned as values.
  109. cmListFileBacktrace(cmListFileBacktrace const& r);
  110. cmListFileBacktrace& operator=(cmListFileBacktrace const& r);
  111. ~cmListFileBacktrace();
  112. // Get a backtrace with the given file scope added to the top.
  113. // May not be called until after construction with a valid snapshot.
  114. cmListFileBacktrace Push(std::string const& file) const;
  115. // Get a backtrace with the given call context added to the top.
  116. // May not be called until after construction with a valid snapshot.
  117. cmListFileBacktrace Push(cmListFileContext const& lfc) const;
  118. // Get a backtrace with the top level removed.
  119. // May not be called until after a matching Push.
  120. cmListFileBacktrace Pop() const;
  121. // Get the context at the top of the backtrace.
  122. // Returns an empty context if the backtrace is empty.
  123. cmListFileContext const& Top() const;
  124. // Print the top of the backtrace.
  125. void PrintTitle(std::ostream& out) const;
  126. // Print the call stack below the top of the backtrace.
  127. void PrintCallStack(std::ostream& out) const;
  128. private:
  129. struct Entry;
  130. cmState::Snapshot Bottom;
  131. Entry* Cur;
  132. cmListFileBacktrace(cmState::Snapshot bottom, Entry* up,
  133. cmListFileContext const& lfc);
  134. cmListFileBacktrace(cmState::Snapshot bottom, Entry* cur);
  135. };
  136. struct cmListFile
  137. {
  138. bool ParseFile(const char* path, cmMessenger* messenger,
  139. cmListFileBacktrace const& lfbt);
  140. std::vector<cmListFileFunction> Functions;
  141. };
  142. #endif