LLVM
15.0.0git
|
Annotations lets you mark points and ranges inside source code, for tests: More...
#include "llvm/Testing/Support/Annotations.h"
Classes | |
struct | Range |
Two offsets pointing to a continuous substring. More... | |
Public Member Functions | |
Annotations (llvm::StringRef Text) | |
Parses the annotations from Text. Crashes if it's malformed. More... | |
llvm::StringRef | code () const |
The input text with all annotations stripped. More... | |
size_t | point (llvm::StringRef Name="") const |
Returns the position of the point marked by ^ (or $name^) in the text. More... | |
std::vector< size_t > | points (llvm::StringRef Name="") const |
Returns the position of all points marked by ^ (or $name^) in the text. More... | |
Range | range (llvm::StringRef Name="") const |
Returns the location of the range marked by [[ ]] (or $name[[ ]]). More... | |
std::vector< Range > | ranges (llvm::StringRef Name="") const |
Returns the location of all ranges marked by [[ ]] (or $name[[ ]]). More... | |
Annotations lets you mark points and ranges inside source code, for tests:
Annotations Example(R"cpp( int complete() { x.pri^ } // ^ indicates a point void err() { [["hello" == 42]]; } // [[this is a range]] $definition^class Foo{}; // points can be named: "definition" $fail[[static_assert(false, "")]] // ranges can be named too: "fail" )cpp");
StringRef Code = Example.code(); // annotations stripped. std::vector<size_t> PP = Example.points(); // all unnamed points size_t P = Example.point(); // there must be exactly one llvm::Range R = Example.range("fail"); // find named ranges
Points/ranges are coordinated into code()
which is stripped of annotations.
Ranges may be nested (and points can be inside ranges), but there's no way to define general overlapping ranges.
FIXME: the choice of the marking syntax makes it impossible to represent some of the C++ and Objective C constructs (including common ones like C++ attributes). We can fix this by:
Definition at line 48 of file Annotations.h.
Annotations::Annotations | ( | llvm::StringRef | Text | ) |
Parses the annotations from Text. Crashes if it's malformed.
Definition at line 26 of file Annotations.cpp.
References llvm::StringRef::consume_front(), llvm::StringRef::drop_front(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::StringRef::empty(), llvm::StringRef::front(), llvm::AMDGPU::SendMsg::Msg, llvm::None, require(), llvm::StringRef::size(), and llvm::StringRef::take_while().
|
inline |
The input text with all annotations stripped.
All points and ranges are relative to this stripped text.
Definition at line 67 of file Annotations.h.
size_t llvm::Annotations::point | ( | llvm::StringRef | Name = "" | ) | const |
Returns the position of the point marked by ^ (or $name^) in the text.
Crashes if there isn't exactly one.
std::vector<size_t> llvm::Annotations::points | ( | llvm::StringRef | Name = "" | ) | const |
Returns the position of all points marked by ^ (or $name^) in the text.
Order matches the order within the text.
Range llvm::Annotations::range | ( | llvm::StringRef | Name = "" | ) | const |
Returns the location of the range marked by [[ ]] (or $name[[ ]]).
Crashes if there isn't exactly one.
std::vector<Range> llvm::Annotations::ranges | ( | llvm::StringRef | Name = "" | ) | const |
Returns the location of all ranges marked by [[ ]] (or $name[[ ]]).
They are ordered by start position within the text.