Skip to content

Commit

Permalink
Adding language flag (#90)
Browse files Browse the repository at this point in the history
* Improved version output specific to `hyde`; fixes #83

* wip

* bringing hyde up to llvm 18.1.8

* version bump
  • Loading branch information
fosterbrereton authored Sep 12, 2024
1 parent 8855838 commit 91daa1d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions matchers/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<BlockCommandComment>(comment);
assert(block_command_comment);
Expand All @@ -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<ParamCommandComment>(comment);
assert(param_command_comment);
Expand All @@ -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<TParamCommandComment>(comment);
assert(tparam_command_comment);
Expand All @@ -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<VerbatimBlockComment>(comment);
assert(verbatim_block_comment);
Expand All @@ -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<VerbatimLineComment>(comment);
assert(verbatim_line_comment);
Expand All @@ -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<ParagraphComment>(comment);
assert(paragraph_comment);
Expand Down Expand Up @@ -534,19 +534,19 @@ 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<FullComment>(comment);
assert(full_comment_inner);

if (auto children = process_comment_children(*full_comment_inner)) {
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<InlineCommandComment>(comment);
assert(inline_command_comment);
Expand All @@ -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<TextComment>(comment);
assert(text_comment);

Expand All @@ -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;
}

Expand Down
44 changes: 41 additions & 3 deletions sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ std::vector<std::string> make_absolute(std::vector<std::string> 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> ToolMode(
cl::desc("There are several modes under which the tool can run:"),
cl::values(
Expand Down Expand Up @@ -193,6 +192,16 @@ static cl::list<std::string> NamespaceBlacklist(
cl::cat(MyToolCategory),
cl::CommaSeparated);

static cl::opt<std::string> 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<bool> ProcessClassMethods(
"process-class-methods",
cl::desc("Process Class Methods"),
Expand Down Expand Up @@ -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

/**************************************************************************************************/
Expand All @@ -428,7 +449,10 @@ std::vector<std::string> 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<int>(args._hyde.size());
std::vector<const char*> new_argv(args._hyde.size(), nullptr);
Expand Down Expand Up @@ -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 <language>". (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<std::string> prefix_arguments;
prefix_arguments.emplace_back("--language=" + DriverLanguage.getValue());

Tool.appendArgumentsAdjuster(
getInsertArgumentAdjuster(prefix_arguments, clang::tooling::ArgumentInsertPosition::BEGIN));
}

Tool.appendArgumentsAdjuster(OptionsParser.getArgumentsAdjuster());

Tool.appendArgumentsAdjuster(
Expand Down

0 comments on commit 91daa1d

Please sign in to comment.