From 99d76f6c33c34fd1fd2ec017a4b5f2167a3dff20 Mon Sep 17 00:00:00 2001 From: Chenhao Date: Tue, 4 Jun 2024 10:49:05 +0000 Subject: [PATCH 1/5] Adding the getActionType method to allow the clang plugin to automatically load plugins during the compilation process. --- README.md | 15 +++++++++++++++ lib/CodeStyleChecker.cpp | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 5d45906..25ed72c 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,21 @@ the warnings with correct source code information. `-fcolor-diagnostics` above instructs Clang to generate color output (unfortunately Markdown doesn't render the colors here). +The **CodeStyleChecker** plugin could be used during the compilation process to +detect errors in the code, and get the output file, for example: +```bash +$Clang_DIR/bin/clang -fplugin=libCodeStyleChecker.dylib -o file.o -c file.cpp +file.cpp:2:7: warning: Type and variable names should start with upper-case letter +class clangTutor_BadName; + ^~~~~~~~~~~~~~~~~~~ + ClangTutor_BadName +file.cpp:2:17: warning: `_` in names is not allowed +class clangTutor_BadName; + ~~~~~~~~~~^~~~~~~~~ + clangTutorBadName +2 warnings generated. +``` + ### Run the plugin through `ct-code-style-checker` **ct-code-style-checker** is a standalone tool that will run the **CodeStyleChecker** plugin, but without the need of using `clang` and loading the plugin: diff --git a/lib/CodeStyleChecker.cpp b/lib/CodeStyleChecker.cpp index f368d15..2e97026 100644 --- a/lib/CodeStyleChecker.cpp +++ b/lib/CodeStyleChecker.cpp @@ -193,6 +193,10 @@ class CSCASTAction : public PluginASTAction { ros << "Help for CodeStyleChecker plugin goes here\n"; } + PluginASTAction::ActionType getActionType() override { + return AddAfterMainAction; + } + private: bool MainTuOnly = true; }; From cd932994ea9f16d1812e0a0b8f35a243f38f1c42 Mon Sep 17 00:00:00 2001 From: Chenhao Date: Wed, 5 Jun 2024 10:34:59 +0000 Subject: [PATCH 2/5] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25ed72c..53f0688 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ $Clang_DIR/bin/clang -cc1 -load /lib/libLACommenter.dylib -plugin LAC ``` ### Run the plugin through `ct-la-commenter` -**locommenter** is a standalone tool that will run the **LACommenter** plugin, +**lacommenter** is a standalone tool that will run the **LACommenter** plugin, but without the need of using `clang` and loading the plugin: ```bash From aac5d7eb3543817823d9b0d4fe1646f0513bf496 Mon Sep 17 00:00:00 2001 From: Chenhao Date: Wed, 5 Jun 2024 10:45:56 +0000 Subject: [PATCH 3/5] Make ClangPlugin **CodeStyleChecker** can be load automatically. --- README.md | 13 +++++++++++-- lib/CodeStyleChecker.cpp | 6 +++++- test/CodeStyleCheckerAnonymous.cpp | 4 +++- test/CodeStyleCheckerConversionOp.cpp | 4 +++- test/CodeStyleCheckerFunction.cpp | 4 +++- test/CodeStyleCheckerMacro.cpp | 4 +++- test/CodeStyleCheckerTypesAndVars.cpp | 4 +++- test/CodeStyleCheckerUnderscore.cpp | 4 +++- test/CodeStyleCheckerVector.cpp | 6 +++--- tools/CMakeLists.txt | 5 +++++ 10 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 53f0688..96fdc24 100644 --- a/README.md +++ b/README.md @@ -358,8 +358,17 @@ the warnings with correct source code information. `-fcolor-diagnostics` above instructs Clang to generate color output (unfortunately Markdown doesn't render the colors here). -The **CodeStyleChecker** plugin could be used during the compilation process to -detect errors in the code, and get the output file, for example: +According to [Clang Plugins](https://clang.llvm.org/docs/ClangPlugins.html#using-the-clang-command-line) +> If the plugin class implements the `getActionType` method then the plugin is run automatically. +```c +// Automatically run the plugin after the main AST action +PluginASTAction::ActionType getActionType() override { + return AddAfterMainAction; +} +``` + +The **CodeStyleChecker** plugin could be automatically load and be used during the normal compilation +process to detect errors in the code, and get the output file, for example: ```bash $Clang_DIR/bin/clang -fplugin=libCodeStyleChecker.dylib -o file.o -c file.cpp file.cpp:2:7: warning: Type and variable names should start with upper-case letter diff --git a/lib/CodeStyleChecker.cpp b/lib/CodeStyleChecker.cpp index 2e97026..17aea69 100644 --- a/lib/CodeStyleChecker.cpp +++ b/lib/CodeStyleChecker.cpp @@ -194,7 +194,11 @@ class CSCASTAction : public PluginASTAction { } PluginASTAction::ActionType getActionType() override { - return AddAfterMainAction; +#ifndef TARGET_CLANG_TOOL + return AddBeforeMainAction; +#else + return CmdlineAfterMainAction; +#endif } private: diff --git a/test/CodeStyleCheckerAnonymous.cpp b/test/CodeStyleCheckerAnonymous.cpp index 9f816ed..340221f 100644 --- a/test/CodeStyleCheckerAnonymous.cpp +++ b/test/CodeStyleCheckerAnonymous.cpp @@ -1,4 +1,6 @@ -// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -plugin CSC %s 2>&1 +// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 // 1. Verify that anonymous unions are not flagged as invalid (no name -> // nothing to check). However, the member variables _are_ verified. diff --git a/test/CodeStyleCheckerConversionOp.cpp b/test/CodeStyleCheckerConversionOp.cpp index bfbcbc5..4e31631 100644 --- a/test/CodeStyleCheckerConversionOp.cpp +++ b/test/CodeStyleCheckerConversionOp.cpp @@ -1,4 +1,6 @@ -// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -plugin CSC %s 2>&1 +// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 // Verify that conversion operators are not checked diff --git a/test/CodeStyleCheckerFunction.cpp b/test/CodeStyleCheckerFunction.cpp index 68a56f6..5872802 100644 --- a/test/CodeStyleCheckerFunction.cpp +++ b/test/CodeStyleCheckerFunction.cpp @@ -1,4 +1,6 @@ -// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -plugin CSC %s 2>&1 +// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 // Verify that function names starting with upper case are reported as invalid diff --git a/test/CodeStyleCheckerMacro.cpp b/test/CodeStyleCheckerMacro.cpp index 6966fd0..70cf12c 100644 --- a/test/CodeStyleCheckerMacro.cpp +++ b/test/CodeStyleCheckerMacro.cpp @@ -1,4 +1,6 @@ -// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -plugin CSC %s 2>&1 +// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 #define clang_tutor_class_ok(class_name) class ClangTutor##class_name #define clang_tutor_class_underscore(class_name) class Clang_TutorClass##class_name diff --git a/test/CodeStyleCheckerTypesAndVars.cpp b/test/CodeStyleCheckerTypesAndVars.cpp index b997d4f..8db3a9c 100644 --- a/test/CodeStyleCheckerTypesAndVars.cpp +++ b/test/CodeStyleCheckerTypesAndVars.cpp @@ -1,4 +1,6 @@ -// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -plugin CSC %s 2>&1 +// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 // Verify that type and variable names starting with lower case are reported as // invalid diff --git a/test/CodeStyleCheckerUnderscore.cpp b/test/CodeStyleCheckerUnderscore.cpp index 437107a..dbfa971 100644 --- a/test/CodeStyleCheckerUnderscore.cpp +++ b/test/CodeStyleCheckerUnderscore.cpp @@ -1,4 +1,6 @@ -// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -plugin CSC %s 2>&1 +// RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 // Verify that underscare in types, variables and function names are reported // as invalid diff --git a/test/CodeStyleCheckerVector.cpp b/test/CodeStyleCheckerVector.cpp index b297a9d..4590833 100644 --- a/test/CodeStyleCheckerVector.cpp +++ b/test/CodeStyleCheckerVector.cpp @@ -1,6 +1,6 @@ -// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -plugin -Xclang CSC -c %s -// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=true -c %s -// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=false -c %s +// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s +// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=true -c %s +// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=false -c %s #include diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e33eed5..e1deeaa 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -40,4 +40,9 @@ foreach( tool ${CLANG_TUTOR_TOOLS} ) ${tool} "clangTooling" ) + + # ct action type should be CmdlineAfterMainAction + if(${tool} STREQUAL "ct-code-style-checker") + target_compile_definitions(${tool} PRIVATE TARGET_CLANG_TOOL=1) + endif() endforeach() From fca3809ec631d952edcae7866f51830603181ff2 Mon Sep 17 00:00:00 2001 From: Chenhao Date: Mon, 14 Jul 2025 02:06:00 +0000 Subject: [PATCH 4/5] Fixed an issue where Clang Tools were used in actual compilation processes; modified the invocation method of the CodeStyleChecker plugin for lit test cases and adjusted the corresponding lit tests. --- test/CodeStyleCheckerAnonymous.cpp | 10 ++++++++-- test/CodeStyleCheckerConversionOp.cpp | 27 ++++++++++++++++++--------- test/CodeStyleCheckerFunction.cpp | 10 ++++++++-- test/CodeStyleCheckerMacro.cpp | 10 ++++++++-- test/CodeStyleCheckerTypesAndVars.cpp | 10 ++++++++-- test/CodeStyleCheckerUnderscore.cpp | 10 ++++++++-- test/CodeStyleCheckerVector.cpp | 15 ++++++++++++--- 7 files changed, 70 insertions(+), 22 deletions(-) diff --git a/test/CodeStyleCheckerAnonymous.cpp b/test/CodeStyleCheckerAnonymous.cpp index 340221f..ea263b9 100644 --- a/test/CodeStyleCheckerAnonymous.cpp +++ b/test/CodeStyleCheckerAnonymous.cpp @@ -1,6 +1,12 @@ // RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 -// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 -// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 + +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o + +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o // 1. Verify that anonymous unions are not flagged as invalid (no name -> // nothing to check). However, the member variables _are_ verified. diff --git a/test/CodeStyleCheckerConversionOp.cpp b/test/CodeStyleCheckerConversionOp.cpp index 4e31631..246f092 100644 --- a/test/CodeStyleCheckerConversionOp.cpp +++ b/test/CodeStyleCheckerConversionOp.cpp @@ -1,13 +1,22 @@ // RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 -// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 -// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 -// Verify that conversion operators are not checked +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o -// expected-no-diagnostics -class SomeClass { -public: - operator bool(); - operator int(); - operator char(); +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o + +// Verify that function names starting with upper case are reported as invalid + +// expected-warning@+1 {{Function names should start with lower-case letter}} +void ClangTutorFuncBad(); + +void clangTutorFuncOK(); + +struct ClangTutorStruct { + // expected-warning@+1 {{Function names should start with lower-case letter}} + void ClangTutorMemberMethodBad(); + void clangTutorMemberMethodOK(); }; diff --git a/test/CodeStyleCheckerFunction.cpp b/test/CodeStyleCheckerFunction.cpp index 5872802..246f092 100644 --- a/test/CodeStyleCheckerFunction.cpp +++ b/test/CodeStyleCheckerFunction.cpp @@ -1,6 +1,12 @@ // RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 -// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 -// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 + +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o + +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o // Verify that function names starting with upper case are reported as invalid diff --git a/test/CodeStyleCheckerMacro.cpp b/test/CodeStyleCheckerMacro.cpp index 70cf12c..2e6dc00 100644 --- a/test/CodeStyleCheckerMacro.cpp +++ b/test/CodeStyleCheckerMacro.cpp @@ -1,6 +1,12 @@ // RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 -// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 -// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 + +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o + +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o #define clang_tutor_class_ok(class_name) class ClangTutor##class_name #define clang_tutor_class_underscore(class_name) class Clang_TutorClass##class_name diff --git a/test/CodeStyleCheckerTypesAndVars.cpp b/test/CodeStyleCheckerTypesAndVars.cpp index 8db3a9c..3ed9a7a 100644 --- a/test/CodeStyleCheckerTypesAndVars.cpp +++ b/test/CodeStyleCheckerTypesAndVars.cpp @@ -1,6 +1,12 @@ // RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 -// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 -// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 + +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o + +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o // Verify that type and variable names starting with lower case are reported as // invalid diff --git a/test/CodeStyleCheckerUnderscore.cpp b/test/CodeStyleCheckerUnderscore.cpp index dbfa971..1b11725 100644 --- a/test/CodeStyleCheckerUnderscore.cpp +++ b/test/CodeStyleCheckerUnderscore.cpp @@ -1,6 +1,12 @@ // RUN: clang -cc1 -verify -load %shlibdir/libCodeStyleChecker%shlibext -add-plugin CSC %s 2>&1 -// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s 2>&1 -// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s 2>&1 + +// RUN: clang -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o + +// RUN: clang -fplugin=%shlibdir/libCodeStyleChecker%shlibext -c %s -o %t.o +// RUN: test -f %t.o +// RUN: rm %t.o // Verify that underscare in types, variables and function names are reported // as invalid diff --git a/test/CodeStyleCheckerVector.cpp b/test/CodeStyleCheckerVector.cpp index 4590833..9faa02a 100644 --- a/test/CodeStyleCheckerVector.cpp +++ b/test/CodeStyleCheckerVector.cpp @@ -1,6 +1,15 @@ -// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=true -c %s -// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=false -c %s +// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -c %s -o %t1.o 2>&1 +// RUN: test -f %t1.o +// RUN: rm %t1.o + +// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=true -c %s -o %t2.o 2>&1 +// RUN: test -f %t2.o +// RUN: rm %t2.o + +// RUN: clang++ -Xclang -load -Xclang %shlibdir/libCodeStyleChecker%shlibext -Xclang -add-plugin -Xclang CSC -Xclang -plugin-arg-CSC -Xclang -main-tu-only=false -c %s -o %t3.o 2>&1 +// RUN: test -f %t3.o +// RUN: rm %t3.o + #include From f38ce3585daf2201986695ffc6f1bb440c7edde5 Mon Sep 17 00:00:00 2001 From: Chenhao Date: Tue, 15 Jul 2025 17:39:27 +0800 Subject: [PATCH 5/5] About README.md, Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimized the description of run&compile in the documentation. Co-authored-by: Andrzej WarzyƄski --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ccdbef4..6793360 100644 --- a/README.md +++ b/README.md @@ -358,7 +358,9 @@ the warnings with correct source code information. `-fcolor-diagnostics` above instructs Clang to generate color output (unfortunately Markdown doesn't render the colors here). -According to [Clang Plugins](https://clang.llvm.org/docs/ClangPlugins.html#using-the-clang-command-line) +### Run the plugin and compile the input + +In the invocation from the previous section, Clang runs only one action - the plugin itself. This means that no output files are generated. In order to run a plugin action _and_ e.g. a compilation action, you need implement `getActionType` method (from [Clang Plugins](https://clang.llvm.org/docs/ClangPlugins.html#using-the-clang-command-line)): > If the plugin class implements the `getActionType` method then the plugin is run automatically. ```c // Automatically run the plugin after the main AST action @@ -367,7 +369,7 @@ PluginASTAction::ActionType getActionType() override { } ``` -The **CodeStyleChecker** plugin could be automatically load and be used during the normal compilation +The **CodeStyleChecker** plugin does implement `getActionType` and hence can be run automatically and used during the normal compilation process to detect errors in the code, and get the output file, for example: ```bash $Clang_DIR/bin/clang -fplugin=libCodeStyleChecker.dylib -o file.o -c file.cpp