LLVM  16.0.0git
Classes | Public Member Functions | List of all members
llvm::Annotations Class Reference

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::pair< size_t, llvm::StringRefpointWithPayload (llvm::StringRef Name="") const
 Returns the position of the point with Name and its payload (if any). More...
 
std::vector< size_tpoints (llvm::StringRef Name="") const
 Returns the position of all points marked by ^ (or $name^) in the text. More...
 
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. More...
 
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. More...
 
Range range (llvm::StringRef Name="") const
 Returns the location of the range marked by [[ ]] (or $name[[ ]]). More...
 
std::pair< Range, llvm::StringRefrangeWithPayload (llvm::StringRef Name="") const
 Returns the location and payload of the range marked by [[ ]] (or $name(payload)[[ ]]). More...
 
std::vector< Rangeranges (llvm::StringRef Name="") const
 Returns the location of all ranges marked by [[ ]] (or $name[[ ]]). More...
 
std::vector< std::pair< Range, llvm::StringRef > > rangesWithPayload (llvm::StringRef Name="") const
 Returns the location of all ranges marked by [[ ]] (or $name(payload)[[ ]]). More...
 
llvm::StringMap< llvm::SmallVector< Range, 1 > > all_ranges () const
 Returns the mapping of all names of ranges marked in the text to their location. More...
 

Detailed Description

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" ^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:

  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 54 of file Annotations.h.

Constructor & Destructor Documentation

◆ Annotations()

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::AMDGPU::SendMsg::Msg, llvm::None, require(), llvm::StringRef::size(), and llvm::Optional< T >::value_or().

Member Function Documentation

◆ all_points()

llvm::StringMap<llvm::SmallVector<size_t, 1> > llvm::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)

◆ all_ranges()

llvm::StringMap<llvm::SmallVector<Range, 1> > llvm::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.

◆ code()

llvm::StringRef llvm::Annotations::code ( ) const
inline

The input text with all annotations stripped.

All points and ranges are relative to this stripped text.

Definition at line 73 of file Annotations.h.

◆ point()

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.

◆ points()

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.

◆ pointsWithPayload()

std::vector<std::pair<size_t, llvm::StringRef> > llvm::Annotations::pointsWithPayload ( llvm::StringRef  Name = "") const

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

◆ pointWithPayload()

std::pair<size_t, llvm::StringRef> llvm::Annotations::pointWithPayload ( llvm::StringRef  Name = "") const

Returns the position of the point with Name and its payload (if any).

◆ range()

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.

◆ ranges()

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.

◆ rangesWithPayload()

std::vector<std::pair<Range, llvm::StringRef> > llvm::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.

◆ rangeWithPayload()

std::pair<Range, llvm::StringRef> llvm::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.


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