Skip to content

Commit 91daa1d

Browse files
Adding language flag (#90)
* Improved version output specific to `hyde`; fixes #83 * wip * bringing hyde up to llvm 18.1.8 * version bump
1 parent 8855838 commit 91daa1d

File tree

3 files changed

+59
-21
lines changed

3 files changed

+59
-21
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ message(STATUS "INFO: Setting up LLVM...")
3030
FetchContent_Declare(
3131
llvm
3232
GIT_REPOSITORY https://github.com/llvm/llvm-project.git
33-
GIT_TAG 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a # llvmorg-15.0.7
33+
GIT_TAG 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff # llvmorg-18.1.8
3434
GIT_SHALLOW TRUE
3535
GIT_PROGRESS TRUE
3636
SOURCE_SUBDIR llvm

matchers/utilities.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,12 @@ inline std::string_view to_string_view(StringRef string) {
351351

352352
/**************************************************************************************************/
353353

354-
inline std::string_view to_string_view(ParamCommandComment::PassDirection x) {
354+
inline std::string_view to_string_view(ParamCommandPassDirection x) {
355355
// clang-format off
356356
switch (x) {
357-
case ParamCommandComment::PassDirection::In: return "in";
358-
case ParamCommandComment::PassDirection::InOut: return "inout";
359-
case ParamCommandComment::PassDirection::Out: return "out";
357+
case ParamCommandPassDirection::In: return "in";
358+
case ParamCommandPassDirection::InOut: return "inout";
359+
case ParamCommandPassDirection::Out: return "out";
360360
}
361361
// clang-format on
362362
return "in"; // gcc on linux is asking for this.
@@ -435,9 +435,9 @@ hyde::optional_json ProcessComment(const ASTContext& n,
435435
};
436436

437437
switch (comment->getCommentKind()) {
438-
case Comment::NoCommentKind:
438+
case CommentKind::None:
439439
break;
440-
case Comment::BlockCommandCommentKind: {
440+
case CommentKind::BlockCommandComment: {
441441
const BlockCommandComment* block_command_comment =
442442
llvm::dyn_cast_or_null<BlockCommandComment>(comment);
443443
assert(block_command_comment);
@@ -457,7 +457,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
457457
// Do further post-processing if the comment is a hyde command.
458458
result = post_process_hyde_command(std::move(result));
459459
} break;
460-
case Comment::ParamCommandCommentKind: {
460+
case CommentKind::ParamCommandComment: {
461461
const ParamCommandComment* param_command_comment =
462462
llvm::dyn_cast_or_null<ParamCommandComment>(comment);
463463
assert(param_command_comment);
@@ -477,7 +477,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
477477

478478
result = roll_up_single_paragraph_child(std::move(result));
479479
} break;
480-
case Comment::TParamCommandCommentKind: {
480+
case CommentKind::TParamCommandComment: {
481481
const TParamCommandComment* tparam_command_comment =
482482
llvm::dyn_cast_or_null<TParamCommandComment>(comment);
483483
assert(tparam_command_comment);
@@ -488,7 +488,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
488488

489489
result = roll_up_single_paragraph_child(std::move(result));
490490
} break;
491-
case Comment::VerbatimBlockCommentKind: {
491+
case CommentKind::VerbatimBlockComment: {
492492
const VerbatimBlockComment* verbatim_block_comment =
493493
llvm::dyn_cast_or_null<VerbatimBlockComment>(comment);
494494
assert(verbatim_block_comment);
@@ -497,7 +497,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
497497
result["children"] = std::move(*children);
498498
}
499499
} break;
500-
case Comment::VerbatimLineCommentKind: {
500+
case CommentKind::VerbatimLineComment: {
501501
const VerbatimLineComment* verbatim_line_comment =
502502
llvm::dyn_cast_or_null<VerbatimLineComment>(comment);
503503
assert(verbatim_line_comment);
@@ -506,7 +506,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
506506
result["children"] = std::move(*children);
507507
}
508508
} break;
509-
case Comment::ParagraphCommentKind: {
509+
case CommentKind::ParagraphComment: {
510510
const ParagraphComment* paragraph_comment =
511511
llvm::dyn_cast_or_null<ParagraphComment>(comment);
512512
assert(paragraph_comment);
@@ -534,19 +534,19 @@ hyde::optional_json ProcessComment(const ASTContext& n,
534534
result["text"] = std::move(paragraph);
535535
}
536536
} break;
537-
case Comment::FullCommentKind: {
537+
case CommentKind::FullComment: {
538538
const FullComment* full_comment_inner = llvm::dyn_cast_or_null<FullComment>(comment);
539539
assert(full_comment_inner);
540540

541541
if (auto children = process_comment_children(*full_comment_inner)) {
542542
result["children"] = std::move(*children);
543543
}
544544
} break;
545-
case Comment::HTMLEndTagCommentKind:
545+
case CommentKind::HTMLEndTagComment:
546546
break;
547-
case Comment::HTMLStartTagCommentKind:
547+
case CommentKind::HTMLStartTagComment:
548548
break;
549-
case Comment::InlineCommandCommentKind: {
549+
case CommentKind::InlineCommandComment: {
550550
const InlineCommandComment* inline_command_comment =
551551
llvm::dyn_cast_or_null<InlineCommandComment>(comment);
552552
assert(inline_command_comment);
@@ -557,7 +557,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
557557
result["args"] = std::move(*args);
558558
}
559559
} break;
560-
case Comment::TextCommentKind: {
560+
case CommentKind::TextComment: {
561561
const TextComment* text_comment = llvm::dyn_cast_or_null<TextComment>(comment);
562562
assert(text_comment);
563563

@@ -567,7 +567,7 @@ hyde::optional_json ProcessComment(const ASTContext& n,
567567

568568
result["text"] = to_string_view(text_comment->getText());
569569
} break;
570-
case Comment::VerbatimBlockLineCommentKind:
570+
case CommentKind::VerbatimBlockLineComment:
571571
break;
572572
}
573573

sources/main.cpp

+41-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ std::vector<std::string> make_absolute(std::vector<std::string> paths) {
9494
enum ToolMode { ToolModeJSON, ToolModeYAMLValidate, ToolModeYAMLUpdate, ToolModeFixupSubfield };
9595
enum ToolDiagnostic { ToolDiagnosticQuiet, ToolDiagnosticVerbose, ToolDiagnosticVeryVerbose };
9696
static llvm::cl::OptionCategory MyToolCategory(
97-
"Hyde is a tool to scan library headers to ensure documentation is kept up to\n"
98-
"date");
97+
"Hyde is a tool to scan library headers to ensure documentation is kept up to date");
9998
static cl::opt<ToolMode> ToolMode(
10099
cl::desc("There are several modes under which the tool can run:"),
101100
cl::values(
@@ -193,6 +192,16 @@ static cl::list<std::string> NamespaceBlacklist(
193192
cl::cat(MyToolCategory),
194193
cl::CommaSeparated);
195194

195+
static cl::opt<std::string> DriverLanguage(
196+
"language",
197+
cl::desc("Override language used for compilation"),
198+
cl::cat(MyToolCategory));
199+
200+
static cl::alias DriverLanguageAlias(
201+
"x",
202+
cl::desc("Alias for `-language`"),
203+
cl::aliasopt(DriverLanguage));
204+
196205
static cl::opt<bool> ProcessClassMethods(
197206
"process-class-methods",
198207
cl::desc("Process Class Methods"),
@@ -417,6 +426,18 @@ bool fixup_have_file_subfield(const std::filesystem::path& path) {
417426

418427
/**************************************************************************************************/
419428

429+
constexpr auto hyde_version_major_k = 2;
430+
constexpr auto hyde_version_minor_k = 0;
431+
constexpr auto hyde_version_patch_k = 2;
432+
433+
auto hyde_version() {
434+
return std::to_string(hyde_version_major_k) +
435+
"." + std::to_string(hyde_version_minor_k) +
436+
"." + std::to_string(hyde_version_patch_k);
437+
}
438+
439+
/**************************************************************************************************/
440+
420441
} // namespace
421442

422443
/**************************************************************************************************/
@@ -428,7 +449,10 @@ std::vector<std::string> source_paths(int argc, const char** argv) {
428449
/**************************************************************************************************/
429450

430451
int main(int argc, const char** argv) try {
431-
auto sources = source_paths(argc, argv);
452+
llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
453+
OS << "hyde " << hyde_version() << "; llvm " << LLVM_VERSION_STRING << "\n";
454+
});
455+
432456
command_line_args args = integrate_hyde_config(argc, argv);
433457
int new_argc = static_cast<int>(args._hyde.size());
434458
std::vector<const char*> new_argv(args._hyde.size(), nullptr);
@@ -606,6 +630,20 @@ int main(int argc, const char** argv) try {
606630

607631
ClangTool Tool(OptionsParser.getCompilations(), sourcePaths);
608632

633+
// Clang usually permits the "-x" (aka "--language") flag to "treat subsequent input files as
634+
// having type <language>". (See https://clang.llvm.org/docs/ClangCommandLineReference.html).
635+
// As noted, the flag only works for _subsequent_ files, and since the input file is passed as
636+
// the last parameter before the flag termination token (`--`), we cannot pass the `--language`
637+
// flag thereafter and have it apply retroactively. Since the clang driver flags are all passed
638+
// after the flag termination token, we have to inject this specific flag early.
639+
if (!DriverLanguage.empty()) {
640+
std::vector<std::string> prefix_arguments;
641+
prefix_arguments.emplace_back("--language=" + DriverLanguage.getValue());
642+
643+
Tool.appendArgumentsAdjuster(
644+
getInsertArgumentAdjuster(prefix_arguments, clang::tooling::ArgumentInsertPosition::BEGIN));
645+
}
646+
609647
Tool.appendArgumentsAdjuster(OptionsParser.getArgumentsAdjuster());
610648

611649
Tool.appendArgumentsAdjuster(

0 commit comments

Comments
 (0)