diff --git a/CMakeLists.txt b/CMakeLists.txt index 89cbd5f..766f1c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ message(STATUS "INFO: Setting up LLVM...") FetchContent_Declare( llvm GIT_REPOSITORY https://github.com/llvm/llvm-project.git - GIT_TAG 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a # llvmorg-15.0.7 + GIT_TAG 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff # llvmorg-18.1.8 GIT_SHALLOW TRUE GIT_PROGRESS TRUE SOURCE_SUBDIR llvm diff --git a/matchers/utilities.cpp b/matchers/utilities.cpp index c84ed93..75e9fbe 100644 --- a/matchers/utilities.cpp +++ b/matchers/utilities.cpp @@ -351,12 +351,12 @@ inline std::string_view to_string_view(StringRef string) { /**************************************************************************************************/ -inline std::string_view to_string_view(ParamCommandComment::PassDirection x) { +inline std::string_view to_string_view(ParamCommandPassDirection x) { // clang-format off switch (x) { - case ParamCommandComment::PassDirection::In: return "in"; - case ParamCommandComment::PassDirection::InOut: return "inout"; - case ParamCommandComment::PassDirection::Out: return "out"; + case ParamCommandPassDirection::In: return "in"; + case ParamCommandPassDirection::InOut: return "inout"; + case ParamCommandPassDirection::Out: return "out"; } // clang-format on return "in"; // gcc on linux is asking for this. @@ -435,9 +435,9 @@ hyde::optional_json ProcessComment(const ASTContext& n, }; switch (comment->getCommentKind()) { - case Comment::NoCommentKind: + case CommentKind::None: break; - case Comment::BlockCommandCommentKind: { + case CommentKind::BlockCommandComment: { const BlockCommandComment* block_command_comment = llvm::dyn_cast_or_null(comment); assert(block_command_comment); @@ -457,7 +457,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, // Do further post-processing if the comment is a hyde command. result = post_process_hyde_command(std::move(result)); } break; - case Comment::ParamCommandCommentKind: { + case CommentKind::ParamCommandComment: { const ParamCommandComment* param_command_comment = llvm::dyn_cast_or_null(comment); assert(param_command_comment); @@ -477,7 +477,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result = roll_up_single_paragraph_child(std::move(result)); } break; - case Comment::TParamCommandCommentKind: { + case CommentKind::TParamCommandComment: { const TParamCommandComment* tparam_command_comment = llvm::dyn_cast_or_null(comment); assert(tparam_command_comment); @@ -488,7 +488,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result = roll_up_single_paragraph_child(std::move(result)); } break; - case Comment::VerbatimBlockCommentKind: { + case CommentKind::VerbatimBlockComment: { const VerbatimBlockComment* verbatim_block_comment = llvm::dyn_cast_or_null(comment); assert(verbatim_block_comment); @@ -497,7 +497,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result["children"] = std::move(*children); } } break; - case Comment::VerbatimLineCommentKind: { + case CommentKind::VerbatimLineComment: { const VerbatimLineComment* verbatim_line_comment = llvm::dyn_cast_or_null(comment); assert(verbatim_line_comment); @@ -506,7 +506,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result["children"] = std::move(*children); } } break; - case Comment::ParagraphCommentKind: { + case CommentKind::ParagraphComment: { const ParagraphComment* paragraph_comment = llvm::dyn_cast_or_null(comment); assert(paragraph_comment); @@ -534,7 +534,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result["text"] = std::move(paragraph); } } break; - case Comment::FullCommentKind: { + case CommentKind::FullComment: { const FullComment* full_comment_inner = llvm::dyn_cast_or_null(comment); assert(full_comment_inner); @@ -542,11 +542,11 @@ hyde::optional_json ProcessComment(const ASTContext& n, result["children"] = std::move(*children); } } break; - case Comment::HTMLEndTagCommentKind: + case CommentKind::HTMLEndTagComment: break; - case Comment::HTMLStartTagCommentKind: + case CommentKind::HTMLStartTagComment: break; - case Comment::InlineCommandCommentKind: { + case CommentKind::InlineCommandComment: { const InlineCommandComment* inline_command_comment = llvm::dyn_cast_or_null(comment); assert(inline_command_comment); @@ -557,7 +557,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result["args"] = std::move(*args); } } break; - case Comment::TextCommentKind: { + case CommentKind::TextComment: { const TextComment* text_comment = llvm::dyn_cast_or_null(comment); assert(text_comment); @@ -567,7 +567,7 @@ hyde::optional_json ProcessComment(const ASTContext& n, result["text"] = to_string_view(text_comment->getText()); } break; - case Comment::VerbatimBlockLineCommentKind: + case CommentKind::VerbatimBlockLineComment: break; } diff --git a/sources/main.cpp b/sources/main.cpp index d8c3ecf..5413616 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -94,8 +94,7 @@ std::vector make_absolute(std::vector paths) { enum ToolMode { ToolModeJSON, ToolModeYAMLValidate, ToolModeYAMLUpdate, ToolModeFixupSubfield }; enum ToolDiagnostic { ToolDiagnosticQuiet, ToolDiagnosticVerbose, ToolDiagnosticVeryVerbose }; static llvm::cl::OptionCategory MyToolCategory( - "Hyde is a tool to scan library headers to ensure documentation is kept up to\n" - "date"); + "Hyde is a tool to scan library headers to ensure documentation is kept up to date"); static cl::opt ToolMode( cl::desc("There are several modes under which the tool can run:"), cl::values( @@ -193,6 +192,16 @@ static cl::list NamespaceBlacklist( cl::cat(MyToolCategory), cl::CommaSeparated); +static cl::opt DriverLanguage( + "language", + cl::desc("Override language used for compilation"), + cl::cat(MyToolCategory)); + +static cl::alias DriverLanguageAlias( + "x", + cl::desc("Alias for `-language`"), + cl::aliasopt(DriverLanguage)); + static cl::opt ProcessClassMethods( "process-class-methods", cl::desc("Process Class Methods"), @@ -417,6 +426,18 @@ bool fixup_have_file_subfield(const std::filesystem::path& path) { /**************************************************************************************************/ +constexpr auto hyde_version_major_k = 2; +constexpr auto hyde_version_minor_k = 0; +constexpr auto hyde_version_patch_k = 2; + +auto hyde_version() { + return std::to_string(hyde_version_major_k) + + "." + std::to_string(hyde_version_minor_k) + + "." + std::to_string(hyde_version_patch_k); +} + +/**************************************************************************************************/ + } // namespace /**************************************************************************************************/ @@ -428,7 +449,10 @@ std::vector source_paths(int argc, const char** argv) { /**************************************************************************************************/ int main(int argc, const char** argv) try { - auto sources = source_paths(argc, argv); + llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) { + OS << "hyde " << hyde_version() << "; llvm " << LLVM_VERSION_STRING << "\n"; + }); + command_line_args args = integrate_hyde_config(argc, argv); int new_argc = static_cast(args._hyde.size()); std::vector new_argv(args._hyde.size(), nullptr); @@ -606,6 +630,20 @@ int main(int argc, const char** argv) try { ClangTool Tool(OptionsParser.getCompilations(), sourcePaths); + // Clang usually permits the "-x" (aka "--language") flag to "treat subsequent input files as + // having type ". (See https://clang.llvm.org/docs/ClangCommandLineReference.html). + // As noted, the flag only works for _subsequent_ files, and since the input file is passed as + // the last parameter before the flag termination token (`--`), we cannot pass the `--language` + // flag thereafter and have it apply retroactively. Since the clang driver flags are all passed + // after the flag termination token, we have to inject this specific flag early. + if (!DriverLanguage.empty()) { + std::vector prefix_arguments; + prefix_arguments.emplace_back("--language=" + DriverLanguage.getValue()); + + Tool.appendArgumentsAdjuster( + getInsertArgumentAdjuster(prefix_arguments, clang::tooling::ArgumentInsertPosition::BEGIN)); + } + Tool.appendArgumentsAdjuster(OptionsParser.getArgumentsAdjuster()); Tool.appendArgumentsAdjuster(