clang: lib/Tooling/Syntax/Mutations.cpp Source File (original) (raw)

1

2

3

4

5

6

7

17#include "llvm/ADT/ArrayRef.h"

18#include "llvm/ADT/STLExtras.h"

19#include "llvm/Support/Casting.h"

20#include

21#include

22

23using namespace clang;

24

25

26

28public:

29

31 assert(Anchor != nullptr);

32 assert(Anchor->Parent != nullptr);

33 assert(New->Parent == nullptr);

34 assert(New->NextSibling == nullptr);

35 assert(New->PreviousSibling == nullptr);

38

39 New->setRole(Role);

40 auto *P = Anchor->getParent();

41 P->replaceChildRangeLowLevel(Anchor->getNextSibling(),

42 Anchor->getNextSibling(), New);

43

44 P->assertInvariants();

45 }

46

47

49 assert(Old != nullptr);

50 assert(Old->Parent != nullptr);

52 assert(New->Parent == nullptr);

53 assert(New->NextSibling == nullptr);

54 assert(New->PreviousSibling == nullptr);

56

57 New->Role = Old->Role;

59 P->replaceChildRangeLowLevel(Old, Old->getNextSibling(), New);

60

61 P->assertInvariants();

62 }

63

64

66 assert(N != nullptr);

67 assert(N->Parent != nullptr);

69

72 nullptr);

73

74 P->assertInvariants();

76 }

77};

78

81 assert(S);

82 assert(S->canModify());

83

84 if (isa(S->getParent())) {

85

86 MutationsImpl::remove(S);

87 return;

88 }

89

90 if (isa(S))

91 return;

92

94}

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

Defines the clang::SourceLocation class and associated facilities.

A memory arena for syntax trees.

void assertInvariants() const

Asserts invariants on this node of the tree and its immediate children.

bool canModify() const

If this function return false, the tree cannot be modified because there is no reasonable way to prod...

const Node * getNextSibling() const

const Tree * getParent() const

bool isDetached() const

Whether the node is detached from a tree, i.e. does not have a parent.

An abstract node for C++ statements, e.g.

A TokenBuffer-powered token manager.

static void addAfter(syntax::Node *Anchor, syntax::Node *New, NodeRole Role)

Add a new node with a specified role.

static void remove(syntax::Node *N)

Completely remove the node from its parent.

static void replace(syntax::Node *Old, syntax::Node *New)

Replace the node, keeping the role.

NodeRole

A relation between a parent and child node, e.g.

@ Detached

A node without a parent.

syntax::EmptyStatement * createEmptyStatement(syntax::Arena &A, TokenBufferTokenManager &TBTM)

void removeStatement(syntax::Arena &A, TokenBufferTokenManager &TBTM, syntax::Statement *S)

Removes a statement or replaces it with an empty statement where one is required syntactically.

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