clang: include/clang/Tooling/Transformer/MatchConsumer.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_CLANG_TOOLING_TRANSFORMER_MATCHCONSUMER_H

16#define LLVM_CLANG_TOOLING_TRANSFORMER_MATCHCONSUMER_H

17

20#include "llvm/ADT/StringRef.h"

21#include "llvm/Support/Errc.h"

22#include "llvm/Support/Error.h"

23

25namespace transformer {

26

27

28

29

30

31

32

33template

36

37

38

40 return llvm::make_errorllvm::StringError(llvm::errc::invalid_argument,

41 "Id not bound: " + Id);

42}

43

44

45

46template

50 auto &Map = Result.Nodes.getMap();

51 return (Map.find(ID) != Map.end() ? TrueC : FalseC)(Result);

52 };

53}

54

55

56

57

58

59

60

61

62

63

65public:

67

68

69

70

71

74

75

76

78

79

80

81

82 virtual std::string toString() const = 0;

83

84protected:

86

87

88

91};

92

93template

96 T Output;

97 if (auto Err = eval(R, &Output))

98 return std::move(Err);

99 return Output;

100}

101}

102}

103#endif

A failable computation over nodes bound by AST matchers, with (limited) reflection via the toString m...

virtual ~MatchComputation()=default

virtual std::string toString() const =0

Constructs a string representation of the computation, for informational purposes.

MatchComputation & operator=(const MatchComputation &)=default

virtual llvm::Error eval(const ast_matchers::MatchFinder::MatchResult &Match, T *Result) const =0

Evaluates the computation and (potentially) updates the accumulator Result.

MatchComputation(const MatchComputation &)=default

MatchComputation()=default

MatchConsumer< T > ifBound(std::string ID, MatchConsumer< T > TrueC, MatchConsumer< T > FalseC)

Chooses between the two consumers, based on whether ID is bound in the match.

llvm::Error notBoundError(llvm::StringRef Id)

Creates an error that signals that a MatchConsumer expected a certain node to be bound by AST matcher...

std::function< Expected< T >(const ast_matchers::MatchFinder::MatchResult &)> MatchConsumer

A failable computation over nodes bound by AST matchers.

The JSON file list parser is used to communicate input to InstallAPI.

@ Result

The result type of a method or function.

const FunctionProtoType * T

Contains all information for a given match.