class Annotations

Declaration

class Annotations { /* full declaration omitted */ };

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

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:46

Method Overview

  • public Annotations(llvm::StringRef Text)
  • public llvm::StringRef code() const
  • public size_t point(llvm::StringRef Name = "") const
  • public std::vector<size_t> points(llvm::StringRef Name = "") const
  • public llvm::Annotations::Range range(llvm::StringRef Name = "") const
  • public std::vector<Range> ranges(llvm::StringRef Name = "") const

Methods

Annotations(llvm::StringRef Text)

Description

Parses the annotations from Text. Crashes if it's malformed.

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:61

Parameters

llvm::StringRef Text

llvm::StringRef code() const

Description

The input text with all annotations stripped. All points and ranges are relative to this stripped text.

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:65

size_t point(llvm::StringRef Name = "") const

Description

Returns the position of the point marked by ^ (or $name^) in the text. Crashes if there isn't exactly one.

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:69

Parameters

llvm::StringRef Name = ""

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

Description

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

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:71

Parameters

llvm::StringRef Name = ""

llvm::Annotations::Range range(
    llvm::StringRef Name = "") const

Description

Returns the location of the range marked by [[ ]] (or $name[[ ]]). Crashes if there isn't exactly one.

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:75

Parameters

llvm::StringRef Name = ""

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

Description

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

Declared at: llvm/include/llvm/Testing/Support/Annotations.h:77

Parameters

llvm::StringRef Name = ""