Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/libclang/Rewrite.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Rewrite.cpp --------------------------------------------------------===//
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
9
#include "clang-c/Rewrite.h"
10
#include "CXSourceLocation.h"
11
#include "CXTranslationUnit.h"
12
#include "clang/Basic/SourceManager.h"
13
#include "clang/Frontend/ASTUnit.h"
14
#include "clang/Rewrite/Core/Rewriter.h"
15
16
5
CXRewriter clang_CXRewriter_create(CXTranslationUnit TU) {
17
5
  if (clang::cxtu::isNotUsableTU(TU)) {
18
0
    LOG_BAD_TU(TU);
19
0
    return {};
20
0
  }
21
5
  clang::ASTUnit *AU = clang::cxtu::getASTUnit(TU);
22
5
  assert(AU);
23
0
  return reinterpret_cast<CXRewriter>(
24
5
      new clang::Rewriter(AU->getSourceManager(), AU->getLangOpts()));
25
5
}
26
27
void clang_CXRewriter_insertTextBefore(CXRewriter Rew, CXSourceLocation Loc,
28
1
                            const char *Insert) {
29
1
  assert(Rew);
30
0
  clang::Rewriter &R = *reinterpret_cast<clang::Rewriter *>(Rew);
31
1
  R.InsertTextBefore(clang::cxloc::translateSourceLocation(Loc), Insert);
32
1
}
33
34
void clang_CXRewriter_replaceText(CXRewriter Rew, CXSourceRange ToBeReplaced,
35
3
                       const char *Replacement) {
36
3
  assert(Rew);
37
0
  clang::Rewriter &R = *reinterpret_cast<clang::Rewriter *>(Rew);
38
3
  R.ReplaceText(clang::cxloc::translateCXRangeToCharRange(ToBeReplaced),
39
3
                Replacement);
40
3
}
41
42
1
void clang_CXRewriter_removeText(CXRewriter Rew, CXSourceRange ToBeRemoved) {
43
1
  assert(Rew);
44
0
  clang::Rewriter &R = *reinterpret_cast<clang::Rewriter *>(Rew);
45
1
  R.RemoveText(clang::cxloc::translateCXRangeToCharRange(ToBeRemoved));
46
1
}
47
48
5
int clang_CXRewriter_overwriteChangedFiles(CXRewriter Rew) {
49
5
  assert(Rew);
50
0
  clang::Rewriter &R = *reinterpret_cast<clang::Rewriter *>(Rew);
51
5
  return R.overwriteChangedFiles();
52
5
}
53
54
0
void clang_CXRewriter_writeMainFileToStdOut(CXRewriter Rew) {
55
0
  assert(Rew);
56
0
  clang::Rewriter &R = *reinterpret_cast<clang::Rewriter *>(Rew);
57
0
  R.getEditBuffer(R.getSourceMgr().getMainFileID()).write(llvm::outs());
58
0
}
59
60
5
void clang_CXRewriter_dispose(CXRewriter Rew) {
61
5
  if (Rew)
62
5
    delete reinterpret_cast<clang::Rewriter *>(Rew);
63
5
}