LLVM 20.0.0git
|
Annotations lets you mark points and ranges inside source code, for tests: More...
#include "llvm/Testing/Annotations/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. | |
llvm::StringRef | code () const |
The input text with all annotations stripped. | |
size_t | point (llvm::StringRef Name="") const |
Returns the position of the point marked by ^ (or $name^) in the text. | |
std::pair< size_t, llvm::StringRef > | pointWithPayload (llvm::StringRef Name="") const |
Returns the position of the point with Name and its payload (if any). | |
std::vector< size_t > | points (llvm::StringRef Name="") const |
Returns the position of all points marked by ^ (or $name^) in the text. | |
std::vector< std::pair< size_t, llvm::StringRef > > | pointsWithPayload (llvm::StringRef Name="") const |
Returns the positions and payloads (if any) of all points named Name . | |
llvm::StringMap< llvm::SmallVector< size_t, 1 > > | all_points () const |
Returns the mapping of all names of points marked in the text to their position. | |
Range | range (llvm::StringRef Name="") const |
Returns the location of the range marked by [[ ]] (or $name[[ ]]). | |
std::pair< Range, llvm::StringRef > | rangeWithPayload (llvm::StringRef Name="") const |
Returns the location and payload of the range marked by [[ ]] (or $name(payload)[[ ]]). | |
std::vector< Range > | ranges (llvm::StringRef Name="") const |
Returns the location of all ranges marked by [[ ]] (or $name[[ ]]). | |
std::vector< std::pair< Range, llvm::StringRef > > | rangesWithPayload (llvm::StringRef Name="") const |
Returns the location of all ranges marked by [[ ]] (or $name(payload)[[ ]]). | |
llvm::StringMap< llvm::SmallVector< Range, 1 > > | all_ranges () const |
Returns the mapping of all names of ranges marked in the text to their location. | |
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" $(foo)^class Foo{}; // ...or have a payload: "foo" $definition(foo)^class Foo{}; // ...or both $fail(runtime)[[assert(false)]] // ranges can have names/payloads too )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.
Names consist of only alphanumeric characters or '_'. Payloads can contain any character expect '(' and ')'.
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 53 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::SmallVectorTemplateCommon< T, typename >::back(), llvm::CallingConv::C, llvm::SmallVectorBase< Size_T >::empty(), Name, llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and require().
llvm::StringMap< llvm::SmallVector< size_t, 1 > > Annotations::all_points | ( | ) | const |
Returns the mapping of all names of points marked in the text to their position.
Unnamed points are mapped to the empty string. The positions are sorted. FIXME Remove this and expose All
directly (currently used out-of-tree)
Definition at line 119 of file Annotations.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::keys(), Name, and points().
llvm::StringMap< llvm::SmallVector< Annotations::Range, 1 > > Annotations::all_ranges | ( | ) | const |
Returns the mapping of all names of ranges marked in the text to their location.
Unnamed ranges are mapped to the empty string. The ranges are sorted by their start position.
Definition at line 166 of file Annotations.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::keys(), Name, and ranges().
|
inline |
The input text with all annotations stripped.
All points and ranges are relative to this stripped text.
Definition at line 72 of file Annotations.h.
size_t 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.
Definition at line 83 of file Annotations.cpp.
References Name, and pointWithPayload().
std::vector< size_t > 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.
Definition at line 96 of file Annotations.cpp.
References Name, and pointsWithPayload().
Referenced by all_points().
std::vector< std::pair< size_t, llvm::StringRef > > Annotations::pointsWithPayload | ( | llvm::StringRef | Name = "" | ) | const |
Returns the positions and payloads (if any) of all points named Name
.
Definition at line 106 of file Annotations.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringMap< ValueTy, AllocatorTy >::find(), I, and Name.
Referenced by points().
std::pair< size_t, llvm::StringRef > Annotations::pointWithPayload | ( | llvm::StringRef | Name = "" | ) | const |
Returns the position of the point with Name
and its payload (if any).
Definition at line 88 of file Annotations.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringMap< ValueTy, AllocatorTy >::find(), I, Name, P, and require().
Referenced by point().
Annotations::Range Annotations::range | ( | llvm::StringRef | Name = "" | ) | const |
Returns the location of the range marked by [[ ]] (or $name[[ ]]).
Crashes if there isn't exactly one.
Definition at line 128 of file Annotations.cpp.
References Name, and rangeWithPayload().
std::vector< Annotations::Range > 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.
Definition at line 142 of file Annotations.cpp.
References Name, and rangesWithPayload().
Referenced by all_ranges().
std::vector< std::pair< Annotations::Range, llvm::StringRef > > Annotations::rangesWithPayload | ( | llvm::StringRef | Name = "" | ) | const |
Returns the location of all ranges marked by [[ ]] (or $name(payload)[[ ]]).
They are ordered by start position within the text.
Definition at line 151 of file Annotations.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringMap< ValueTy, AllocatorTy >::find(), I, and Name.
Referenced by ranges().
std::pair< Annotations::Range, llvm::StringRef > Annotations::rangeWithPayload | ( | llvm::StringRef | Name = "" | ) | const |
Returns the location and payload of the range marked by [[ ]] (or $name(payload)[[ ]]).
Crashes if there isn't exactly one.
Definition at line 133 of file Annotations.cpp.
References llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringMap< ValueTy, AllocatorTy >::find(), I, Name, and require().
Referenced by range().