From be3540e64db0a803dbf3a697804d297f7d5f0a2c Mon Sep 17 00:00:00 2001 From: Till Ehrengruber Date: Sat, 25 Jun 2016 15:17:32 +0200 Subject: [PATCH] First try of removing failed decls, not working at all --- src/bootstrap.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 7f8eb20e..d918e686 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -159,6 +159,14 @@ extern "C" { extern void jl_error(const char *str); +bool _debug_ast = false; + +// enable output of the ast +// usage `ccall((:enable_ast_debug, Cxx.libcxxffi),Void, ())` +JL_DLLEXPORT void enable_ast_debug() { + _debug_ast = true; +} + // For initialization.jl JL_DLLEXPORT void add_directory(C, int kind, int isFramework, const char *dirname) { @@ -1106,8 +1114,16 @@ class ValidatingASTVisitor : public clang::DeclVisitor, } void VisitDecl(clang::Decl *D) { - if (D->isInvalidDecl()) + if (_debug_ast) { + std::cout << "--------------------------" << std::endl; + D->dump(); + std::cout << "--------------------------" << std::endl; + } + + // check for semantic errors + if (D->isInvalidDecl()) { FoundInvalid = true; + } if (isa(D) || isa(D) || isa(D)) return; @@ -1148,7 +1164,6 @@ class ValidatingASTVisitor : public clang::DeclVisitor, }; - class JuliaCodeGenerator : public clang::ASTConsumer { public: JuliaCodeGenerator(C) : Cxx(*Cxx) {} @@ -1164,10 +1179,23 @@ class JuliaCodeGenerator : public clang::ASTConsumer { bool EmitTopLevelDecl(clang::Decl *D) { Visitor.Visit(D); - bool HadErrors = (bool)Visitor; - if (!HadErrors) + const clang::DiagnosticsEngine& Diags = Cxx.CI->getSema().getDiagnostics(); + bool HadErrors = ((bool) Visitor) || Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred(); + if (!HadErrors) { Cxx.CGM->EmitTopLevelDecl(D); + } else { + // remove declaration if an error occured + clang::DeclContext* decl_ctx = D->getLexicalDeclContext(); + if (decl_ctx->containsDecl(D)) { + decl_ctx->removeDecl(D); + std::cout << "removed decl " << D << " since an error occured" << std::endl; + } + + // nop? + Cxx.CI->getSema().getASTContext().Deallocate(D); + } Visitor.reset(); + return HadErrors; }