Skip to content

Commit 4fbfdc8

Browse files
committed
Add 'enum_select' diagnostic selection to clang.
This causes us to generate an enum to go along with the select diagnostic, which allows for clearer diagnostic error emit lines. The syntax for this is: %enum_select<EnumerationName>{%OptionalEnumeratorName{Text}|{Text2}}0 Where the curley brackets around the select-text are only required if an Enumerator name is provided. The TableGen here emits this as a normal 'select' to the frontend, which permits us to reuse all of the existing 'select' infrastructure. Documentation is the same as well.
1 parent 9c85cde commit 4fbfdc8

20 files changed

+417
-17
lines changed

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ macro(clang_diag_gen component)
33
-gen-clang-diags-defs -clang-component=${component}
44
SOURCE Diagnostic.td
55
TARGET ClangDiagnostic${component})
6+
7+
clang_tablegen(Diagnostic${component}Enums.inc
8+
-gen-clang-diags-enums -clang-component=${component}
9+
SOURCE Diagnostic.td
10+
TARGET ClangDiagnostic${component}Enums)
611
endmacro(clang_diag_gen)
712

813
clang_diag_gen(Analysis)

clang/include/clang/Basic/DiagnosticAST.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_AST_DIAGNOSTICS
2424
};
25+
26+
#define DIAG_ENUM(ENUM_NAME) \
27+
namespace ENUM_NAME { \
28+
enum {
29+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30+
#define DIAG_ENUM_END() \
31+
} \
32+
; \
33+
}
34+
#include "clang/Basic/DiagnosticASTEnums.inc"
35+
#undef DIAG_ENUM_END
36+
#undef DIAG_ENUM_ITEM
37+
#undef DIAG_ENUM
2538
} // end namespace diag
2639
} // end namespace clang
2740

clang/include/clang/Basic/DiagnosticAnalysis.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_ANALYSIS_DIAGNOSTICS
2424
};
25+
#define DIAG_ENUM(ENUM_NAME) \
26+
namespace ENUM_NAME { \
27+
enum {
28+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
29+
#define DIAG_ENUM_END() \
30+
} \
31+
; \
32+
}
33+
#include "clang/Basic/DiagnosticAnalysisEnums.inc"
34+
#undef DIAG_ENUM_END
35+
#undef DIAG_ENUM_ITEM
36+
#undef DIAG_ENUM
2537
} // end namespace diag
2638
} // end namespace clang
2739

clang/include/clang/Basic/DiagnosticComment.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_COMMENT_DIAGNOSTICS
2424
};
25+
26+
#define DIAG_ENUM(ENUM_NAME) \
27+
namespace ENUM_NAME { \
28+
enum {
29+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30+
#define DIAG_ENUM_END() \
31+
} \
32+
; \
33+
}
34+
#include "clang/Basic/DiagnosticCommentEnums.inc"
35+
#undef DIAG_ENUM_END
36+
#undef DIAG_ENUM_ITEM
37+
#undef DIAG_ENUM
2538
} // end namespace diag
2639
} // end namespace clang
2740

clang/include/clang/Basic/DiagnosticCrossTU.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_CROSSTU_DIAGNOSTICS
2424
};
25+
26+
#define DIAG_ENUM(ENUM_NAME) \
27+
namespace ENUM_NAME { \
28+
enum {
29+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30+
#define DIAG_ENUM_END() \
31+
} \
32+
; \
33+
}
34+
#include "clang/Basic/DiagnosticCrossTUEnums.inc"
35+
#undef DIAG_ENUM_END
36+
#undef DIAG_ENUM_ITEM
37+
#undef DIAG_ENUM
2538
} // end namespace diag
2639
} // end namespace clang
2740

clang/include/clang/Basic/DiagnosticDriver.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_DRIVER_DIAGNOSTICS
2424
};
25+
26+
#define DIAG_ENUM(ENUM_NAME) \
27+
namespace ENUM_NAME { \
28+
enum {
29+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30+
#define DIAG_ENUM_END() \
31+
} \
32+
; \
33+
}
34+
#include "clang/Basic/DiagnosticDriverEnums.inc"
35+
#undef DIAG_ENUM_END
36+
#undef DIAG_ENUM_ITEM
37+
#undef DIAG_ENUM
2538
} // end namespace diag
2639
} // end namespace clang
2740

clang/include/clang/Basic/DiagnosticFrontend.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_FRONTEND_DIAGNOSTICS
2424
};
25+
26+
#define DIAG_ENUM(ENUM_NAME) \
27+
namespace ENUM_NAME { \
28+
enum {
29+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30+
#define DIAG_ENUM_END() \
31+
} \
32+
; \
33+
}
34+
#include "clang/Basic/DiagnosticFrontendEnums.inc"
35+
#undef DIAG_ENUM_END
36+
#undef DIAG_ENUM_ITEM
37+
#undef DIAG_ENUM
2538
} // end namespace diag
2639
} // end namespace clang
2740

clang/include/clang/Basic/DiagnosticInstallAPI.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ enum {
2121
#undef DIAG
2222
NUM_BUILTIN_INSTALLAPI_DIAGNOSTICS
2323
};
24+
25+
#define DIAG_ENUM(ENUM_NAME) \
26+
namespace ENUM_NAME { \
27+
enum {
28+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
29+
#define DIAG_ENUM_END() \
30+
} \
31+
; \
32+
}
33+
#include "clang/Basic/DiagnosticInstallAPIEnums.inc"
34+
#undef DIAG_ENUM_END
35+
#undef DIAG_ENUM_ITEM
36+
#undef DIAG_ENUM
2437
} // namespace diag
2538
} // namespace clang
2639
#endif // LLVM_CLANG_BASIC_DIAGNOSTICINSTALLAPI_H

clang/include/clang/Basic/DiagnosticLex.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_LEX_DIAGNOSTICS
2424
};
25+
#define DIAG_ENUM(ENUM_NAME) \
26+
namespace ENUM_NAME { \
27+
enum {
28+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
29+
#define DIAG_ENUM_END() \
30+
} \
31+
; \
32+
}
33+
#include "clang/Basic/DiagnosticLexEnums.inc"
34+
#undef DIAG_ENUM_END
35+
#undef DIAG_ENUM_ITEM
36+
#undef DIAG_ENUM
2537
} // end namespace diag
2638
} // end namespace clang
2739

clang/include/clang/Basic/DiagnosticParse.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum {
2222
#undef DIAG
2323
NUM_BUILTIN_PARSE_DIAGNOSTICS
2424
};
25+
26+
#define DIAG_ENUM(ENUM_NAME) \
27+
namespace ENUM_NAME { \
28+
enum {
29+
#define DIAG_ENUM_ITEM(IDX, NAME) NAME = IDX,
30+
#define DIAG_ENUM_END() \
31+
} \
32+
; \
33+
}
34+
#include "clang/Basic/DiagnosticParseEnums.inc"
35+
#undef DIAG_ENUM_END
36+
#undef DIAG_ENUM_ITEM
37+
#undef DIAG_ENUM
2538
} // end namespace diag
2639
} // end namespace clang
2740

0 commit comments

Comments
 (0)