Questions tagged [libtooling]

LibTooling is a library to support writing standalone tools based on Clang.

152 questions
0
votes
0 answers

rewriting C/C++ code with clang LibTooling

I am new to clang and need some help to rewrite c and c++ code for a custom coverage tool I am developing. As I understand it, I think I need to link to clang's libTooling to make a stand alone executable to make something like a code…
johnco3
  • 2,401
  • 4
  • 35
  • 67
0
votes
1 answer

clang libtooling: Get Preprocessor object in clang libtool

I want to get macro names from my source files. Going through a couple of answers I found that clang::Preprocessor::getPredefines() does the job. Question is how to get preprocessor object in ClangTool?
Bhushan
  • 354
  • 9
  • 25
0
votes
0 answers

Match multiple `FieldDecl` inside a `CXXRecordDecl`

I am trying to capture all structs that look like: struct Obj1 { int field1; double field2; template void serialize(Ar& ar) { ::serializer(ar, field1, field2); } }; I would like to match all structs with a template…
xis
  • 24,330
  • 9
  • 43
  • 59
0
votes
1 answer

How can I get main source file path from MatchCallback::onStartOfTranslationUnit()?

For now I can get it only in MatchCallback::run(const MatchResult& r): r.SourceManager.getFileEntryForID(r.SourceManager.getMainFileID())->getName().str() and cache for future use. But I might need it in my MatchCallback subclass even if no matches…
dimgel
  • 61
  • 1
  • 7
0
votes
0 answers

Is it possible to compile Clang LibTooling into standalone library?

I`m trying to find best solution for parsing C++ code for my refactor support tool. I decided to use clang frontend because it is meant to be frontend of C++ compiler. I found the documentation page that describes parsing of C++ code using clang…
0
votes
0 answers

clang LibTooling: weird include paths in Clang Invocation ---> clang's headers not found

I'm trying to make simple working tool with SyntaxOnlyAction and custom CompilationDatabase subclass which returns single file and command: clang++ -c -v -o target/test-object.cpp.o test-object.cpp. But unless I add -I/usr/lib/clang/14.0.6/include…
dimgel
  • 61
  • 1
  • 7
0
votes
0 answers

Replacement error calculating replacement in clang

I'm trying to refactor if-else branches and am unable to generate accurate Replacements for it. I try to fetch nodes using: clang::IfStmt *ifstmt = const_cast( …
gPats
  • 315
  • 2
  • 17
0
votes
1 answer

How to find method declarations in LibTooling?

I'm writing a program in LibTooling to print information of all functions, including methods in classes. But it seems VisitFunctionDecl() only detects functions outside a class. I also tried VisiCXXMethodDecl(), bool VisiCXXMethodDecl(CXXMethodDecl…
潇洒张
  • 273
  • 2
  • 9
0
votes
0 answers

How to invoke the clang compiler from my clang tool

I have an existing and working source-to-source code modification tool using libtooling (written in C++). Now I want to integrate this tool into clang, so users can compile the modified source code without actually saving it somewhere. The…
D_D
  • 1
  • 1
0
votes
1 answer

How to run LLVM's Pass with new Pass Builder on IR by calling the LLVM API in program?

By using opt, we can run a custom pass, or run a -O1 -O2 -O3 pass pipeline on a foo.ll file, but it all happens on the command line, and the IR is a file form.This is not conducive to some optimization of IR in the form of memory (each IR file is a…
0
votes
0 answers

Incomplete TranslationUnit with libclang CXTranslationUnit_SingleFileParse

I'm trying to parse a single C++ file that looks as follows: #include #include #include "foo.h" std::unique_ptr FooBar::baz(std::wstring const& text) { auto result = std::make_unique(text.length() + 1); …
DEls
  • 241
  • 3
  • 14
0
votes
1 answer

`clang::PluginASTAction` with `clang::tooling::runToolOnCode` produce string output (for tests)?

With clang::tooling::runToolOnCode I can provide std::string input but I only get a bool output. static const char *const from = "#include \n" "int main(void) {\n" " for(int i=0; i
Samuel Marks
  • 1,611
  • 1
  • 20
  • 25
0
votes
0 answers

C++ Source-to-Source Transformation with Clang

I am working on a project for which I need to "combine" code distributed over multiple C++ files into one file. Due to the nature of the project, I only need one entry function (the function that will be defined as the top function in the Xilinx…
Sam
  • 207
  • 1
  • 4
  • 12
0
votes
1 answer

How to link to Libtooling with cmake

According to docs, I have following cmake project cmake_minimum_required(VERSION 3.5) project(teeest LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(LLVM REQUIRED) find_package(Clang…
너를 속였다
  • 899
  • 11
  • 26
0
votes
2 answers

Processing standalone source files in a complex CMake structure with clang LibTooling

I wrote my own clang tool following https://clang.llvm.org/docs/LibASTMatchersTutorial.html The purpose of the tool is to generate diagrams based on specific source files. Until now as a prototype I worked with some basic cpp code which didn't have…
Rngaddict
  • 3
  • 2