Do not turn errors into warnings by default

Not required anymore since the resource dir is specified
correctly.
This commit is contained in:
Martchus 2018-02-03 15:47:25 +01:00
parent 21e7f83995
commit 8587d62583
5 changed files with 41 additions and 15 deletions

View File

@ -36,6 +36,7 @@ CodeFactory::CodeFactory(
, m_clangOptions(clangOptions)
, m_os(os)
, m_compilerInstance(nullptr)
, m_errorResilient(true)
{
}

View File

@ -40,6 +40,8 @@ public:
bool run();
clang::CompilerInstance *compilerInstance();
void setCompilerInstance(clang::CompilerInstance *compilerInstance);
bool isErrorResilient() const;
void setErrorResilient(bool errorResilient);
private:
struct ToolInvocation;
@ -55,6 +57,7 @@ private:
std::vector<std::unique_ptr<CodeGenerator>> m_generators;
std::unique_ptr<ToolInvocation> m_toolInvocation;
clang::CompilerInstance *m_compilerInstance;
bool m_errorResilient;
};
/*!
@ -129,6 +132,22 @@ inline void CodeFactory::setCompilerInstance(clang::CompilerInstance *compilerIn
m_compilerInstance = compilerInstance;
}
/*!
* \brief Returns whether most errors will be turned into warnings (by default false).
*/
inline bool CodeFactory::isErrorResilient() const
{
return m_errorResilient;
}
/*!
* \brief Sets whether most errors will be turned into warnings (by default false).
*/
inline void CodeFactory::setErrorResilient(bool errorResilient)
{
m_errorResilient = errorResilient;
}
} // namespace ReflectiveRapidJSON
#endif // REFLECTIVE_RAPIDJSON_CODE_FACTORY_H

View File

@ -61,18 +61,20 @@ void DiagConsumer::finish()
*/
void DiagConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level diagLevel, const clang::Diagnostic &info)
{
const auto diagId = info.getID();
const auto category = info.getDiags()->getDiagnosticIDs()->getCategoryNumberForDiag(diagId);
bool shouldReset = false;
if (diagLevel >= clang::DiagnosticsEngine::Error) {
if (category == 2 /* 2 means "Semantic Issue" */) {
if (!m_realErrorCount) {
shouldReset = true;
if (m_errorResilient) {
const auto diagId = info.getID();
const auto category = info.getDiags()->getDiagnosticIDs()->getCategoryNumberForDiag(diagId);
if (diagLevel >= clang::DiagnosticsEngine::Error) {
if (category == 2 /* 2 means "Semantic Issue" */) {
if (!m_realErrorCount) {
shouldReset = true;
}
diagLevel = clang::DiagnosticsEngine::Warning;
} else {
++m_realErrorCount;
}
diagLevel = clang::DiagnosticsEngine::Warning;
} else {
++m_realErrorCount;
}
}

View File

@ -50,7 +50,7 @@ inline Consumer::Consumer(CodeFactory &factory, clang::CompilerInstance &compile
*/
class DiagConsumer : public clang::DiagnosticConsumer {
public:
DiagConsumer(std::unique_ptr<DiagnosticConsumer> Previous);
DiagConsumer(std::unique_ptr<DiagnosticConsumer> previous, bool errorResilient);
unsigned int realErrorCount() const;
void BeginSourceFile(const clang::LangOptions &langOpts, const clang::Preprocessor *pp = nullptr) override;
@ -62,11 +62,13 @@ public:
private:
std::unique_ptr<DiagnosticConsumer> m_proxy;
unsigned int m_realErrorCount;
bool m_errorResilient;
};
inline DiagConsumer::DiagConsumer(std::unique_ptr<clang::DiagnosticConsumer> Previous)
: m_proxy(std::move(Previous))
inline DiagConsumer::DiagConsumer(std::unique_ptr<clang::DiagnosticConsumer> previous, bool errorResilient)
: m_proxy(std::move(previous))
, m_realErrorCount(0)
, m_errorResilient(errorResilient)
{
}

View File

@ -42,9 +42,10 @@ int main(int argc, char *argv[])
generatorsArg.setCombinable(true);
ConfigValueArgument clangOptionsArg("clang-opt", '\0', "specifies arguments/options to be passed to Clang", { "option" });
clangOptionsArg.setRequiredValueCount(Argument::varValueCount);
ConfigValueArgument errorResilientArg("error-resilient", '\0', "turns most errors into warnings");
HelpArgument helpArg(parser);
NoColorArgument noColorArg;
generateArg.setSubArguments({ &inputFileArg, &outputFileArg, &generatorsArg, &clangOptionsArg });
generateArg.setSubArguments({ &inputFileArg, &outputFileArg, &generatorsArg, &clangOptionsArg, &errorResilientArg });
JsonSerializationCodeGenerator::Options jsonOptions;
jsonOptions.appendTo(&generateArg);
parser.setMainArguments({ &generateArg, &noColorArg, &helpArg });
@ -83,9 +84,10 @@ int main(int argc, char *argv[])
// instantiate the code factory and add generators to it
CodeFactory factory(parser.executable(), inputFileArg.values(0), clangOptions, *os);
factory.setErrorResilient(errorResilientArg.isPresent());
// add specified generators if the --generator argument is present; otherwise add default generators
if (generatorsArg.isPresent()) {
// define mapping of generator names to generator constructions (add new generators here!)
// define mapping of generator names to generator constructors (add new generators here!)
// clang-format off
const std::unordered_map<std::string, std::function<void()>> generatorsByName{
{ "json", factory.bindGenerator<JsonSerializationCodeGenerator, const JsonSerializationCodeGenerator::Options &>(jsonOptions) }