2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
|
#include "EnumVisitor.hh"
|
|
|
|
|
#include "EnumValues.hh"
|
|
|
|
|
#include "Utilities.hh"
|
2017-01-23 23:48:16 +00:00
|
|
|
|
#include "BraceMacro.hh"
|
2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
|
|
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 << "\n[34mEnum Decl = " << d->getDeclKindName() << "[00m" << std::endl ;
|
|
|
|
|
return true ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EnumVisitor::VisitType(clang::Type *t) {
|
|
|
|
|
//std::cout << "\n[34mEnum Type = " << t->getTypeClassName() << "[00m" << std::endl ;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) {
|
2017-01-23 23:48:16 +00:00
|
|
|
|
eval.setFileName(getFileName(ci , ed->RBRACELOC(), hsd)) ;
|
2015-02-26 15:02:31 +00:00
|
|
|
|
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("<anonymous")) != std::string::npos or
|
2022-04-25 21:02:17 +00:00
|
|
|
|
//(pos = enum_type_name.find("(anonymous")) != std::string::npos) {
|
|
|
|
|
(pos = enum_type_name.find("(anonymous")) != std::string::npos or
|
|
|
|
|
(pos = enum_type_name.find("(unnamed")) != std::string::npos) {
|
2015-02-26 15:02:31 +00:00
|
|
|
|
eval.setName("") ;
|
|
|
|
|
return false ;
|
|
|
|
|
}
|
|
|
|
|
if ((pos = enum_type_name.find("enum ")) != std::string::npos ) {
|
|
|
|
|
enum_type_name.erase(pos , 5) ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Strip off containing namespace/class names. They will be added back later.
|
|
|
|
|
if ((pos = enum_type_name.find_last_of(":")) != std::string::npos ) {
|
|
|
|
|
eval.setName(enum_type_name.substr(pos + 1)) ;
|
|
|
|
|
} else {
|
|
|
|
|
eval.setName(enum_type_name) ;
|
|
|
|
|
}
|
|
|
|
|
//std::cout << "\n[34mReplaced Enum name = " << eval->getName() << "[00m" << std::endl ;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 18:56:40 +00:00
|
|
|
|
eval.getNamespacesAndClasses(td->getDeclContext()) ;
|
2015-02-26 15:02:31 +00:00
|
|
|
|
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()) ;
|
2020-09-01 20:55:19 +00:00
|
|
|
|
eval.addFullyQualifiedEnum(ecd->getQualifiedNameAsString(), ecd->getInitVal().getSExtValue());
|
2015-02-26 15:02:31 +00:00
|
|
|
|
return true ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnumValues * EnumVisitor::get_enum_data() {
|
|
|
|
|
return &eval ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|