Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{{else}}
|`{{>symbol/name . nolink=true}}`
{{/if}}
|{{~doc.brief}}
|{{{~doc.brief}}}
{{/each}}
|===

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
enum {{>symbol/name .~}}
enum {{#if isScoped}}class {{/if}}{{>symbol/name .~}}
{{#if type}} : {{>type/declarator type}}{{/if}};
4 changes: 4 additions & 0 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,10 @@ populate(
default_arg)
{
param.Default = getSourceCode(default_arg->getSourceRange());
if (param.Default.starts_with("= "))
{
param.Default.erase(0, 2);
}
}
}

Expand Down
49 changes: 44 additions & 5 deletions src/lib/Lib/MrDocsCompilationDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ isCXXSrcFile(
{
StringRef ext = llvm::sys::path::extension(filename).drop_front();
driver::types::ID extensionId = driver::types::lookupTypeForExtension(ext);
return driver::types::isCXX(extensionId) || ext == "c";
return driver::types::isCXX(extensionId);
}

static
bool
isCSrcFile(
std::string_view filename)
{
StringRef ext = llvm::sys::path::extension(filename).drop_front();
return ext == "c";
}

template<typename... Opts>
Expand Down Expand Up @@ -247,7 +256,8 @@ adjustCommandLine(
StringRef const workingDir,
std::vector<std::string> const& cmdline,
std::shared_ptr<Config const> const& config,
std::unordered_map<std::string, std::vector<std::string>> const& implicitIncludeDirectories)
std::unordered_map<std::string, std::vector<std::string>> const& implicitIncludeDirectories,
std::string_view filename)
{
if (cmdline.empty())
{
Expand Down Expand Up @@ -359,12 +369,40 @@ adjustCommandLine(
// ------------------------------------------------------
// Language standard
// ------------------------------------------------------
// If cmdline contains `-x c` or `-x c++`, then the
// language is explicitly set.
bool isExplicitCppCompileCommand = false;
bool isExplicitCCompileCommand = false;
constexpr auto is_x_option = [](std::string_view const opt) {
return opt == "-x" || opt == "--language";
};
if (auto const it = std::ranges::find_if(cmdline, is_x_option);
it != cmdline.end())
{
if (auto const next = std::next(it);
next != cmdline.end())
{
isExplicitCppCompileCommand = *next == "c++";
isExplicitCCompileCommand = *next == "c";
}
}
bool const isImplicitCSourceFile = isCSrcFile(filename);
bool const isCCompileCommand =
isExplicitCCompileCommand || (!isExplicitCppCompileCommand && isImplicitCSourceFile);

constexpr auto is_std_option = [](std::string_view const opt) {
return opt.starts_with("-std=") || opt.starts_with("--std=") || opt.starts_with("/std:");
};
if (std::ranges::find_if(cmdline, is_std_option) == cmdline.end())
{
new_cmdline.emplace_back("-std=c++23");
if (!isCCompileCommand)
{
new_cmdline.emplace_back("-std=c++23");
}
else
{
new_cmdline.emplace_back("-std=c23");
}
}

// ------------------------------------------------------
Expand Down Expand Up @@ -510,10 +548,11 @@ MrDocsCompilationDatabase(
workingDir,
cmd0.CommandLine,
config,
implicitIncludeDirectories);
implicitIncludeDirectories,
cmd0.Filename);
cmd.Directory = makeAbsoluteAndNative(workingDir, cmd0.Directory);
cmd.Filename = makeAbsoluteAndNative(workingDir, cmd0.Filename);
if (isCXXSrcFile(cmd.Filename))
if (isCXXSrcFile(cmd.Filename) || isCSrcFile(cmd.Filename))
{
const bool emplaced = IndexByFile_.try_emplace(cmd.Filename, AllCommands_.size()).second;
if (emplaced)
Expand Down
12 changes: 6 additions & 6 deletions test-files/golden-tests/metadata/enum.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ enum E0;
|===
|Name |Description
|`e0`
|e0 brief&amp;period&semi;
|e0 brief&period;


|`e1`
|e1 brief&amp;period&semi;
|e1 brief&period;


|===
Expand Down Expand Up @@ -111,7 +111,7 @@ Declared in `&lt;enum&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
enum E2 : int;
enum class E2 : int;
----

=== Members
Expand All @@ -121,11 +121,11 @@ enum E2 : int;
|===
|Name |Description
|`e4`
|e4 brief&amp;period&semi;
|e4 brief&period;


|`e5`
|e5 brief&amp;period&semi;
|e5 brief&period;


|===
Expand All @@ -148,7 +148,7 @@ Declared in `&lt;enum&period;cpp&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
enum E3 : char;
enum class E3 : char;
----

=== Members
Expand Down
4 changes: 2 additions & 2 deletions test-files/golden-tests/metadata/enum.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ <h3>Synopsis</h3>
Declared in <code>&lt;enum.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
enum E2 : int;
enum class E2 : int;
</code>
</pre>
</div>
Expand Down Expand Up @@ -175,7 +175,7 @@ <h3>Synopsis</h3>
Declared in <code>&lt;enum.cpp&gt;</code></div>
<pre>
<code class="source-code cpp">
enum E3 : char;
enum class E3 : char;
</code>
</pre>
</div>
Expand Down
Loading