LLVM  9.0.0svn
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::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< Rangeranges (llvm::StringRef Name="") const
 Returns the location of all ranges marked by [[ ]] (or $name[[ ]]). 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" $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:

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

Constructor & Destructor Documentation

◆ Annotations()

Annotations::Annotations ( llvm::StringRef  Text)

Member Function Documentation

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

References Name, llvm::RISCVFenceField::O, llvm::operator<<(), point(), points(), range(), and ranges().

◆ point()

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 67 of file Annotations.cpp.

References llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::StringMap< ValueTy, AllocatorTy >::find(), I, and require().

Referenced by code().

◆ points()

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

Returns the position of all points marked by ^ (or $name^) in the text.

Definition at line 74 of file Annotations.cpp.

References llvm::StringMap< ValueTy, AllocatorTy >::lookup(), and P.

Referenced by code().

◆ range()

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 79 of file Annotations.cpp.

References I, and require().

Referenced by code().

◆ ranges()

std::vector< Annotations::Range > Annotations::ranges ( llvm::StringRef  Name = "") const

Returns the location of all ranges marked by [[ ]] (or $name[[ ]]).

Definition at line 87 of file Annotations.cpp.

Referenced by code().


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