Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

First try of removing failed decls, not working at all #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 32 additions & 4 deletions src/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -1106,8 +1114,16 @@ class ValidatingASTVisitor : public clang::DeclVisitor<ValidatingASTVisitor>,
}

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<clang::FunctionDecl>(D) || isa<clang::ObjCMethodDecl>(D) || isa<clang::BlockDecl>(D))
return;
Expand Down Expand Up @@ -1148,7 +1164,6 @@ class ValidatingASTVisitor : public clang::DeclVisitor<ValidatingASTVisitor>,

};


class JuliaCodeGenerator : public clang::ASTConsumer {
public:
JuliaCodeGenerator(C) : Cxx(*Cxx) {}
Expand All @@ -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;
}

Expand Down