DPrint.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * C++ Insights, copyright (C) by Andreas Fertig
4 * Distributed under an MIT license. See LICENSE for details
5 *
6 ****************************************************************************/
7
8#include "DPrint.h"
10#include "OutputFormatHelper.h"
11
12#include "clang/AST/AST.h"
13#include "clang/AST/ASTContext.h"
14#include "llvm/Support/Path.h"
15//-----------------------------------------------------------------------------
16
17namespace clang::insights {
18
19static void ToDo(std::string_view name, OutputFormatHelper& outputFormatHelper, std::source_location loc)
20{
21 const auto fileName = [&]() -> std::string_view {
22 if(llvm::sys::path::is_separator(loc.file_name()[0])) {
23 return llvm::sys::path::filename(loc.file_name());
24 }
25
26 return loc.file_name();
27 }();
28
29 outputFormatHelper.Append(
30 "/* INSIGHTS-TODO: "sv, fileName, ":"sv, loc.line(), " stmt: "sv, name, kwSpaceCCommentEnd);
31}
32//-----------------------------------------------------------------------------
33
34void ToDo(const Stmt* stmt, OutputFormatHelper& outputFormatHelper, std::source_location loc)
35{
36 const std::string_view name = [&]() {
37 if(stmt and stmt->getStmtClassName()) {
38 Dump(stmt);
39
40 return stmt->getStmtClassName();
41 }
42
43 Error("arg urg: class name is empty\n");
44
45 return "";
46 }();
47
48 ToDo(name, outputFormatHelper, loc);
49}
50//-----------------------------------------------------------------------------
51
52void ToDo(const Decl* stmt, OutputFormatHelper& outputFormatHelper, std::source_location loc)
53{
54 const std::string_view name = [&]() {
55 if(stmt and stmt->getDeclKindName()) {
56 Dump(stmt);
57 return stmt->getDeclKindName();
58 }
59
60 Error("decl urg: class name is empty\n");
61
62 return "";
63 }();
64
65 ToDo(name, outputFormatHelper, loc);
66}
67//-----------------------------------------------------------------------------
68
69void ToDo(const class TemplateArgument& stmt, class OutputFormatHelper& outputFormatHelper, std::source_location loc)
70{
71 const std::string_view name{StrCat("tmplArgKind: ", stmt.getKind())};
72
73 ToDo(name, outputFormatHelper, loc);
74}
75//-----------------------------------------------------------------------------
76
77} // namespace clang::insights
constexpr std::string_view kwSpaceCCommentEnd
void Append(const char c)
Append a single character.
static void ToDo(std::string_view name, OutputFormatHelper &outputFormatHelper, std::source_location loc)
Definition DPrint.cpp:19
void Error(const char *fmt, const auto &... args)
Log an error.
Definition DPrint.h:80
void Dump(const auto *stmt)
Definition DPrint.h:86
std::string StrCat(const auto &... args)