Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Syntax/Synthesis.cpp
Line
Count
Source
1
//===- Synthesis.cpp ------------------------------------------*- C++ -*-=====//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
#include "clang/Tooling/Syntax/BuildTree.h"
9
10
using namespace clang;
11
12
/// Exposes private syntax tree APIs required to implement node synthesis.
13
/// Should not be used for anything else.
14
class syntax::FactoryImpl {
15
public:
16
5
  static void setCanModify(syntax::Node *N) { N->CanModify = true; }
17
18
  static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child,
19
2
                                   syntax::NodeRole R) {
20
2
    T->prependChildLowLevel(Child, R);
21
2
  }
22
};
23
24
clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
25
3
                                               clang::tok::TokenKind K) {
26
3
  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
27
3
                                clang::tok::getPunctuatorSpelling(K)))
28
3
                    .second;
29
3
  assert(Tokens.size() == 1);
30
3
  assert(Tokens.front().kind() == K);
31
3
  auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
32
3
  FactoryImpl::setCanModify(L);
33
3
  L->assertInvariants();
34
3
  return L;
35
3
}
36
37
clang::syntax::EmptyStatement *
38
2
syntax::createEmptyStatement(clang::syntax::Arena &A) {
39
2
  auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
40
2
  FactoryImpl::setCanModify(S);
41
2
  FactoryImpl::prependChildLowLevel(S, createPunctuation(A, clang::tok::semi),
42
2
                                    NodeRole::Unknown);
43
2
  S->assertInvariants();
44
2
  return S;
45
2
}