Original address: http://clang.llvm.org/docs/ClangTools.html
Translator: Sninning (snsn1984) Introduction
The Clang tool is a separate command-line (latent graphical interface) tool designed for C + + developers who are already using clang and prefer to use clang as their compiler. These tools provide development-oriented functionality: syntax checking, automatic formatting, refactoring, and more.
Only a few of the most basic and fundamental tools were retained in Clang's SVN project. The rest of the tools are saved on the other side of the project, because some users don't want or need to build them. If you want to go into the additional Clang tool code base, simply download them to your Clang tool directory, and then use the usual build process to build with the associated Llvm/clang code:
With SUBVERSION:CD llvm/tools/clang/tools svn cohttp://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra Or With GIT:CD llvm/tools/clang/tools Git Clonehttp://llvm.org/git/clang-tools-extra.gitextra
This document describes the high-level organization of the clang tools within the project, along with a few of the more important of these tools. However, it should be noted that this document is intended only for developers of Clang and clang tools, not the end users of these tools.
Organization of the Clang tool
The Clang tool is a command line or graphical interface program that the C + + developer can use directly. They were not originally intended for use by clang developers, although hopefully they will be helpful to C + + developers who happen to be working in clang, and we are actively expanding their capabilities. They are developed as three parts: the infrastructure of a separate tool built on clang, the core shared logic used by many different tools, which occur in the form of refactoring and rewriting libraries;
The infrastructure of the Clang tool is the libtooling platform. You can see more details about how its architecture works from its documentation. The common aspect of refactoring and rewriting toolkit-style libraries is also part of the libtooling organization.
Almost no clang tools are developed with core clang libraries, like basic functionality and test cases. However, most tools are developed on the side of the code base (not the project's code base) to prove that they are simply separated from the core library. We're not going to support a lot of public libraries that are not in the project code base, we want to review and look at the interfaces of good libraries carefully, and then put them from those libraries into the core Clang Library series.
The development process and practice of all clang tools are clang itself, regardless of the code base in which the clang's tools are placed. They are all part of the Clang project, regardless of the version control system used.
Core Clang Tools
The core series of the Clang tool is within the main project, the completion level is already very high, and allows the use and conduct of clang specific functional testing.
Clang-check
Clangcheck combined the libtooling framework needed to run a clang tool and the Clang diagnostics for a quick syntax check on a particular file, using a command-line interface. It can also be used to drive the IDE or editor by accepting different flags to display different formats of output. In addition, it can use the repair prompt provided by clang directly in Repair mode. You can find out how to create and use Clang-check commands from the documentation how-to Setup clang tooling for LLVM.
Clang-format
Clang-format is both a library and a separate tool, and its goal is to automatically format the C + + source files according to the certification style guidelines. To achieve this goal, Clang-format uses Clang's lexer to convert an input file into a token stream and then change all the spaces around the token. The goal of Clang-format is to be both as a user tool (ideally with powerful IDE integrations) and as part of other refactoring tools, such as formatting all changed rows when renaming.
cpp11-migrate
Cpp11-migrate Migrate the C + + code to use the C++11 feature in the right place. At present it can:
Turn the loop into a range based for loop;
Converts null pointer constants (such as null or 0) to c++11 nullptr;
Replace the type description in the variable declaration with the auto type descriptor;
Add the override description on the appropriate member function;
Additional Clang Tools
Different kinds of clang tools are added to the additional code base, where they will be tracked and recorded. The focus of this document is on the tool scope characteristics for other tool developers, and each tool should provide its own focused user documentation.
the idea of new tools:
C + + cast conversion tool. The C-style casts (type) value can be converted to C + + cast (Static_cast,const_cast orreinterpret_cast).
The Begin () and end () transform tool without members. You will be able to convert foo.begin () to begin (foo), and End () is the same, where Foo is a standard container. We will also explore similar patterns of arrays.
Make_shared/make_unique conversion. Part of this converter can be combined with the auto converter. It will be able to convert:
Std::shared_ptr<foo> sp (new Foo);
Std::unique_ptr<foo> up (new Foo);
Func (std::shared_ptr<foo> (new Foo), bar ());
Into:
Auto SP = std::make_shared<foo> ();
Auto up = std::make_unique<foo> (); In c++14 mode.
This also affects correctness. For the cases where bar () throws,
//make_shared () are safe and the original code may leak.
Func (std::make_shared<foo> (), bar ());
TR1 Removal Tool. It will use the source code of the TR1 library to migrate to libraries using C++11. For example:
#include <tr1/unordered_map>
int main ()
{
std::tr1::unordered_map <int, int> ma;
Std::cout << ma.size () << Std::endl;
return 0;
}
Should be rewritten as:
#include <unordered_map>
int main ()
{
std::unordered_map <int, int> ma;
Std::cout << ma.size () << Std::endl;
return 0;
}
A removal auto tool. Converts auto to an explicit type or adds an inferred type to the annotation. The motivation for this tool is that developers do not want to use auto, and they are afraid of getting their code out of control.
C++14: Fewer redundant operations of function objects (N3421). For example:
Sort (V.begin (), V.end (), greater<valuetype> ());
Should be rewritten as:
Sort (V.begin (), V.end (), greater<> ());