Skip to content

Commit

Permalink
Sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Verbytskyi committed Apr 13, 2024
1 parent 008d334 commit 8bb5333
Showing 1 changed file with 0 additions and 159 deletions.
159 changes: 0 additions & 159 deletions source/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,167 +114,8 @@ bool IncludeSet::add_decl(clang::NamedDecl const *D, int level)
// remove all includes and clear up the stack
void IncludeSet::clear()
{
<<<<<<< HEAD
public:
explicit BinderVisitor(CompilerInstance *ci) : ast_context( &( ci->getASTContext() ) )
{
Config & config = Config::get();

config.root_module = O_root_module;
config.prefix = O_prefix;
config.maximum_file_length = O_max_file_size;

config.namespaces_to_bind = O_bind;
config.namespaces_to_skip = O_skip;

if( O_config.size() ) config.read(O_config);
if( O_suppress_errors ) {
clang::DiagnosticsEngine& di = ci->getDiagnostics();
#if (LLVM_VERSION_MAJOR < 10)
di.setSuppressAllDiagnostics();
#else
di.setSuppressAllDiagnostics(true);
#endif
}
}

virtual ~BinderVisitor() {}

bool shouldVisitTemplateInstantiations () const { return true; }

virtual bool VisitFunctionDecl(FunctionDecl *F)
{
if( F->isCXXInstanceMember() or isa<CXXMethodDecl>(F) ) return true;

if( binder::is_bindable(F) ) {
binder::BinderOP b = std::make_shared<binder::FunctionBinder>(F);
context.add(b);
} else if( F->isOverloadedOperator() and F->getNameAsString() == "operator<<" ) {
//outs() << "Adding insertion operator: " << binder::function_pointer_type(F) << "\n";
context.add_insertion_operator(F);
}

return true;
}

virtual bool VisitCXXRecordDecl(CXXRecordDecl *C) {
if( C->isCXXInstanceMember() or C->isCXXClassMember() ) return true;

if( binder::is_bindable(C) ) {
binder::BinderOP b = std::make_shared<binder::ClassBinder>(C);
context.add(b);
}

return true;
}

// virtual bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *C) {
// if( FullSourceLoc(C->getLocation(), ast_context->getSourceManager() ).isInSystemHeader() ) return true;
// errs() << "Visit ClassTemplateSpecializationDecl:" << C->getQualifiedNameAsString() << binder::template_specialization(C) << "\n";
// C->dump();
// return true;
// }

// virtual bool VisitTemplateDecl(TemplateDecl *record) {
// //if( FullSourceLoc(record->getLocation(), ast_context->getSourceManager() ).isInSystemHeader() ) return true;
// errs() << "Visit TemplateDecl: " << record->getQualifiedNameAsString() << "\n";
// //record->dump();
// return true;
// }

// virtual bool VisitClassTemplateDecl(ClassTemplateDecl *record) {
// //if( FullSourceLoc(record->getLocation(), ast_context->getSourceManager() ).isInSystemHeader() ) return true;
// errs() << "Visit ClassTemplateDecl: " << record->getQualifiedNameAsString() << binder::template_specialization( record->getTemplatedDecl() ) << "\n";
// //record->dump();
// return true;
// }

// virtual bool VisitTypedefDecl(TypedefDecl *T) {
// if( FullSourceLoc(T->getLocation(), ast_context->getSourceManager() ).isInSystemHeader() ) return true;
// //errs() << "Visit TypedefDecl: " << T->getQualifiedNameAsString() << " Type: " << T->getUnderlyingType()->getCanonicalTypeInternal()/*getCanonicalType()*/.getAsString() << "\n";
// // record->dump();
// return true;
// }

// virtual bool VisitNamedDecl(NamedDecl *record) {
// errs() << "Visit NamedRecord: " << record->getQualifiedNameAsString() << "\n";
// return true;
// }

// virtual bool VisitFieldDecl(FieldDecl *record) {
// errs() << "Visit FieldDecl: " << record->getQualifiedNameAsString() << "\n";
// record->dump();
// return true;
// }

virtual bool VisitEnumDecl(EnumDecl *E) {
if( E->isCXXInstanceMember() or E->isCXXClassMember() ) return true;

binder::BinderOP b = std::make_shared<binder::EnumBinder>( E/*->getCanonicalDecl()*/ );
context.add(b);

return true;
}
virtual bool VisitVarDecl(VarDecl *V) {
if( !V->getType().isConstQualified() ) return true;
if( !V->hasInit() ) return true;
if( V->getType().getTypePtr()->isArrayType()) return true;
if( V->isCXXInstanceMember() or V->isCXXClassMember() ) return true;
binder::BinderOP b = std::make_shared<binder::ConstBinder>( V );
context.add(b);
return true;
}

void generate(void) {
context.generate( Config::get() );
}

private:
ASTContext *ast_context;

binder::Context context;
};


class BinderASTConsumer : public ASTConsumer
{
private:
std::unique_ptr<BinderVisitor> visitor;

public:
// override the constructor in order to pass CI
explicit BinderASTConsumer(CompilerInstance *ci) : visitor(new BinderVisitor(ci)) {}

// override this to call our ExampleVisitor on the entire source file
virtual void HandleTranslationUnit(ASTContext &context)
{
visitor->TraverseDecl( context.getTranslationUnitDecl() );
visitor->generate();
}
};


class BinderFrontendAction : public ASTFrontendAction {
public:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(CompilerInstance &ci, StringRef file) {
return std::unique_ptr<ASTConsumer>( new BinderASTConsumer(&ci) );
}
};


int main(int argc, const char **argv)
{
CommonOptionsParser op(argc, argv, BinderToolCategory);

ClangTool tool(op.getCompilations(), op.getSourcePathList());
//outs() << "Root module: " << O_root_module << "\n";
//for(auto &s : O_bind) outs() << "Binding: '" << s << "'\n";

return tool.run(newFrontendActionFactory<BinderFrontendAction>().get());
=======
includes_.clear();
stack_.clear();
>>>>>>> origin/master
}

/// return true if object declared in system header
Expand Down

0 comments on commit 8bb5333

Please sign in to comment.