Skip to content

Commit

Permalink
Merge pull request #1184 from joakim-brannstrom/mutate-set-default-co…
Browse files Browse the repository at this point in the history
…mpiledb

mutate: fix default config and value for compile_commands.json
  • Loading branch information
joakim-brannstrom committed Sep 1, 2020
2 parents 0319390 + 51f68d3 commit 2afb57f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
Expand Up @@ -15,66 +15,59 @@ import clang.TranslationUnit : TranslationUnit;
*
* Returns: True if errors where found.
*/
bool hasParseErrors(ref TranslationUnit tu) @safe {
bool hasParseErrors(ref TranslationUnit tu) @trusted {
import clang.c.Index : CXDiagnosticSeverity;

if (!tu.isValid)
return true;

auto dia = tu.diagnostics;

auto rval = () @trusted {
foreach (diag; dia) {
auto severity = diag.severity;
foreach (diag; dia) {
auto severity = diag.severity;

final switch (severity) with (CXDiagnosticSeverity) {
case ignored:
case note:
case warning:
break;
case error:
case fatal:
return true;
}
final switch (severity) with (CXDiagnosticSeverity) {
case ignored:
case note:
case warning:
break;
case error:
case fatal:
return true;
}
return false;
}();

return rval;
}
return false;
}

/** Log diagnostic error messages to std.logger.
*
* TODO Change to a template with a sink as parameter.
*/
void logDiagnostic(ref TranslationUnit tu) @safe {
void logDiagnostic(ref TranslationUnit tu) @trusted {
import logger = std.experimental.logger;

import clang.c.Index : CXDiagnosticSeverity;

auto dia = tu.diagnostics;

() @trusted {
foreach (diag; dia) {
auto severity = diag.severity;
foreach (diag; dia) {
auto severity = diag.severity;

final switch (severity) with (CXDiagnosticSeverity) {
case ignored:
logger.info(diag.format);
break;
case note:
logger.info(diag.format);
break;
case warning:
logger.warning(diag.format);
break;
case error:
logger.error(diag.format);
break;
case fatal:
logger.error(diag.format);
break;
}
final switch (severity) with (CXDiagnosticSeverity) {
case ignored:
logger.info(diag.format);
break;
case note:
logger.info(diag.format);
break;
case warning:
logger.warning(diag.format);
break;
case error:
logger.error(diag.format);
break;
case fatal:
logger.error(diag.format);
break;
}
}();
}
}
Expand Up @@ -135,7 +135,7 @@ struct ArgParser {
app.put(null);
app.put("# files and/or directories to look for compile_commands.json.");
if (compileDb.dbs.length == 0)
app.put(`# search_paths = ["./compile_commands.json"]`);
app.put(`search_paths = ["./compile_commands.json"]`);
else
app.put(format("search_paths = %s", compileDb.rawDbs));
app.put(null);
Expand Down Expand Up @@ -527,10 +527,11 @@ struct ArgParser {
}
}

/// Update the config from the users input.
/// Replace the config from the users input.
void updateCompileDb(ref ConfigCompileDb db, string[] compile_dbs) {
if (compile_dbs.length != 0)
db.rawDbs = compile_dbs;

db.dbs = db.rawDbs
.filter!(a => a.length != 0)
.map!(a => Path(a).AbsolutePath)
Expand Down

0 comments on commit 2afb57f

Please sign in to comment.