[PATCH] Add a level parameter to ClangTidyCheck::diag.
Alp Toker
alp at nuanti.com
Mon Mar 3 07:26:06 PST 2014
On 03/03/2014 15:02, Alp Toker wrote:
>
> On 03/03/2014 12:53, Alexander Kornienko wrote:
>
>>
>> What do you think about this?
>
> Keen to go ahead with it so long as we're treating the work as
> much-needed cleanup, with clang-tools-extra getting the functionality
> when it's ready. It is a non-trivial but the reduction in cruft and
> will surely pay off.
And to get a feel for things, I've attached is a testbed patch for
clang-tools-extra that generates diagnostics with tablegen (concept
only, not for review).
The generated diagnostics aren't usable yet but it does build. Playing
with this code gives an idea where we might want to go and what remains
to be done to make tablegenned diagnostics usable cleanly by external
modules.
Alp.
--
http://www.nuanti.com
the browser experts
-------------- next part --------------
diff --git a/clang-tidy/CMakeLists.txt b/clang-tidy/CMakeLists.txt
index c3226dd..08e8d54 100644
--- a/clang-tidy/CMakeLists.txt
+++ b/clang-tidy/CMakeLists.txt
@@ -20,6 +20,8 @@ add_clang_library(clangTidy
clangTooling
)
+clang_diag_gen(Tidy)
+
add_subdirectory(tool)
add_subdirectory(llvm)
add_subdirectory(google)
diff --git a/clang-tidy/ClangTidy.cpp b/clang-tidy/ClangTidy.cpp
index da7c4f0..0e1a291 100644
--- a/clang-tidy/ClangTidy.cpp
+++ b/clang-tidy/ClangTidy.cpp
@@ -17,6 +17,7 @@
#include "ClangTidy.h"
#include "ClangTidyDiagnosticConsumer.h"
+#include "TidyDiagnostic.h"
#include "ClangTidyModuleRegistry.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
diff --git a/clang-tidy/Diagnostic.td b/clang-tidy/Diagnostic.td
new file mode 100644
index 0000000..664fddb
--- /dev/null
+++ b/clang-tidy/Diagnostic.td
@@ -0,0 +1,121 @@
+//===--- Diagnostic.td - C Language Family Diagnostic Handling ------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the TableGen core definitions for the diagnostics
+// and diagnostic control.
+//
+//===----------------------------------------------------------------------===//
+
+// Define the diagnostic mappings.
+class DiagMapping;
+def MAP_IGNORE : DiagMapping;
+def MAP_REMARK : DiagMapping;
+def MAP_WARNING : DiagMapping;
+def MAP_ERROR : DiagMapping;
+def MAP_FATAL : DiagMapping;
+
+// Define the diagnostic classes.
+class DiagClass;
+def CLASS_NOTE : DiagClass;
+def CLASS_REMARK : DiagClass;
+def CLASS_WARNING : DiagClass;
+def CLASS_EXTENSION : DiagClass;
+def CLASS_ERROR : DiagClass;
+
+// Responses to a diagnostic in a SFINAE context.
+class SFINAEResponse;
+def SFINAE_SubstitutionFailure : SFINAEResponse;
+def SFINAE_Suppress : SFINAEResponse;
+def SFINAE_Report : SFINAEResponse;
+def SFINAE_AccessControl : SFINAEResponse;
+
+// Diagnostic Categories. These can be applied to groups or individual
+// diagnostics to specify a category.
+class DiagCategory<string Name> {
+ string CategoryName = Name;
+}
+
+// Diagnostic Groups.
+class DiagGroup<string Name, list<DiagGroup> subgroups = []> {
+ string GroupName = Name;
+ list<DiagGroup> SubGroups = subgroups;
+ string CategoryName = "";
+}
+class InGroup<DiagGroup G> { DiagGroup Group = G; }
+//class IsGroup<string Name> { DiagGroup Group = DiagGroup<Name>; }
+
+/*
+// This defines all of the named diagnostic categories.
+include "DiagnosticCategories.td"
+
+// This defines all of the named diagnostic groups.
+include "DiagnosticGroups.td"
+*/
+
+// All diagnostics emitted by the compiler are an indirect subclass of this.
+class Diagnostic<string text, DiagClass DC, DiagMapping defaultmapping> {
+ /// Component is specified by the file with a big let directive.
+ string Component = ?;
+ string Text = text;
+ DiagClass Class = DC;
+ SFINAEResponse SFINAE = SFINAE_Suppress;
+ bit AccessControl = 0;
+ bit WarningNoWerror = 0;
+ bit WarningShowInSystemHeader = 0;
+ DiagMapping DefaultMapping = defaultmapping;
+ DiagGroup Group;
+ string CategoryName = "";
+}
+
+class SFINAEFailure {
+ SFINAEResponse SFINAE = SFINAE_SubstitutionFailure;
+}
+class NoSFINAE {
+ SFINAEResponse SFINAE = SFINAE_Report;
+}
+class AccessControl {
+ SFINAEResponse SFINAE = SFINAE_AccessControl;
+}
+
+// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
+class Error<string str> : Diagnostic<str, CLASS_ERROR, MAP_ERROR>, SFINAEFailure;
+class Warning<string str> : Diagnostic<str, CLASS_WARNING, MAP_WARNING>;
+class Remark<string str> : Diagnostic<str, CLASS_REMARK, MAP_IGNORE>;
+class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_IGNORE>;
+class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_WARNING>;
+class Note<string str> : Diagnostic<str, CLASS_NOTE, MAP_FATAL/*ignored*/>;
+
+
+class DefaultIgnore { DiagMapping DefaultMapping = MAP_IGNORE; }
+class DefaultWarn { DiagMapping DefaultMapping = MAP_WARNING; }
+class DefaultError { DiagMapping DefaultMapping = MAP_ERROR; }
+class DefaultFatal { DiagMapping DefaultMapping = MAP_FATAL; }
+class DefaultWarnNoWerror {
+ bit WarningNoWerror = 1;
+}
+class DefaultWarnShowInSystemHeader {
+ bit WarningShowInSystemHeader = 1;
+}
+
+// Definitions for Diagnostics.
+include "DiagnosticTidyKinds.td"
+
+/*
+include "DiagnosticASTKinds.td"
+include "DiagnosticAnalysisKinds.td"
+include "DiagnosticCommentKinds.td"
+include "DiagnosticCommonKinds.td"
+include "DiagnosticDriverKinds.td"
+include "DiagnosticFrontendKinds.td"
+include "DiagnosticLexKinds.td"
+include "DiagnosticParseKinds.td"
+include "DiagnosticSemaKinds.td"
+include "DiagnosticSerializationKinds.td"
+*/
+
diff --git a/clang-tidy/DiagnosticTidyKinds.td b/clang-tidy/DiagnosticTidyKinds.td
new file mode 100644
index 0000000..0fafe01
--- /dev/null
+++ b/clang-tidy/DiagnosticTidyKinds.td
@@ -0,0 +1,18 @@
+//==--------- DiagnosticTidyKinds.td - diagnostics -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// Diagnostics
+//===----------------------------------------------------------------------===//
+
+let Component = "Tidy" in {
+
+def warn_external_foo : Warning<"diag from clang-tools-extra">;
+
+}
diff --git a/clang-tidy/TidyDiagnostic.h b/clang-tidy/TidyDiagnostic.h
new file mode 100644
index 0000000..4393001
--- /dev/null
+++ b/clang-tidy/TidyDiagnostic.h
@@ -0,0 +1,40 @@
+//===--- DiagnosticSema.h - Diagnostics for libsema -------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_DIAGNOSTICSEMA_H
+#define LLVM_CLANG_DIAGNOSTICSEMA_H
+
+//#include "clang/Basic/Diagnostic.h"
+namespace clang {
+ class DiagnosticsEngine;
+ class SourceLocation;
+
+ // Import the diagnostic enums themselves.
+ namespace diag {
+ // Start position for diagnostics.
+ enum {
+ DIAG_START_TIDY = 1,
+ };
+ }
+}
+
+namespace clang {
+ namespace diag {
+ enum {
+#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\
+ SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM,
+#define TIDYSTART
+#include "DiagnosticTidyKinds.inc"
+#undef DIAG
+ NUM_BUILTIN_TIDY_DIAGNOSTICS
+ };
+ } // end namespace diag
+} // end namespace clang
+
+#endif
More information about the cfe-commits
mailing list