LLVM: llvm::Annotations Class Reference (original) (raw)

Annotations lets you mark points and ranges inside source code, for tests: More...

#include "[llvm/Testing/Annotations/Annotations.h](Annotations%5F8h%5Fsource.html)"

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]] definitionclassFoo;//pointscanbenamed:"definition"definition^class Foo{}; // points can be named: "definition" definitionclassFoo;//pointscanbenamed:"definition"(foo)^class Foo{}; // ...or have a payload: "foo" definition(foo)classFoo;//...orbothdefinition(foo)^class Foo{}; // ...or both definition(foo)classFoo;//...orbothfail(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:

  1. introducing an escaping mechanism for the special characters,
  2. making characters for marking points and ranges configurable,
  3. changing the syntax to something less commonly used,
  4. ...

Definition at line 53 of file Annotations.h.

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::SmallVectorTemplateCommon< T, typename >::empty(), llvm::isAlnum(), llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), require(), and llvm::SmallVectorImpl< T >::reserve().

all_points()

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 points().

all_ranges()

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 ranges().

code()

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.

point()

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 pointWithPayload().

points()

std::vector< size_t > Annotations::points ( llvm::StringRef Name = "" ) const

pointsWithPayload()

Returns the positions and payloads (if any) of all points named Name.

Definition at line 106 of file Annotations.cpp.

References I.

Referenced by points().

pointWithPayload()

range()

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 rangeWithPayload().

ranges()

rangesWithPayload()

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 I.

Referenced by ranges().

rangeWithPayload()

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 I, and require().

Referenced by range().


The documentation for this class was generated from the following files: