#include #include #include #include "llvm/Support/CommandLine.h" #include "EnumVisitor.hh" #include "EnumValues.hh" #include "Utilities.hh" #include "BraceMacro.hh" extern llvm::cl::opt< int > debug_level ; EnumVisitor::EnumVisitor( clang::CompilerInstance & in_ci , HeaderSearchDirs & in_hsd ) : ci(in_ci) , hsd(in_hsd) { //eval = new EnumValues() ; } bool EnumVisitor::VisitDecl(clang::Decl *d) { //std::cout << "\nEnum Decl = " << d->getDeclKindName() << "" << std::endl ; return true ; } bool EnumVisitor::VisitType(clang::Type *t) { //std::cout << "\nEnum Type = " << t->getTypeClassName() << "" << std::endl ; return true; } bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) { eval.setFileName(getFileName(ci , ed->RBRACELOC(), hsd)) ; return true; } bool EnumVisitor::VisitEnumType(clang::EnumType *et) { clang::TagDecl * td = et->getDecl() ; eval.setName(td->getName().str()) ; if ( debug_level >= 3 ) { std::cout << "EnumVisitor VisitEnumType " << std::endl ; std::cout << "eval.getName() = " << eval.getName() << std::endl ; std::cout << "td->getName() = " << td->getName().str() << std::endl ; } if ( eval.getName().empty() ) { std::string enum_type_name = et->desugar().getAsString() ; size_t pos ; // If this enumeration is anonymous return an error condition if ((pos = enum_type_name.find("getDeclContext()) ; return true ; } bool EnumVisitor::VisitEnumConstantDecl(clang::EnumConstantDecl *ecd) { //std::cout << ecd->getName().str() << " = " << ecd->getInitVal().getSExtValue() << std::endl ; eval.addEnum(ecd->getName().str() , ecd->getInitVal().getSExtValue()) ; eval.addFullyQualifiedEnum(ecd->getQualifiedNameAsString(), ecd->getInitVal().getSExtValue()); return true ; } EnumValues * EnumVisitor::get_enum_data() { return &eval ; }