Commit 006fb5e1 authored by rmrf's avatar rmrf

Add FindTemplateParameters

parent b0fcd790
#include "FindTemplateParameters.h"
#include "FindTemplateTypes.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceManager.h"
using namespace scpar;
FindTemplateParameters::FindTemplateParameters(CXXRecordDecl *declaration, llvm::raw_ostream &os)
: declaration_{declaration}, os_{os}, template_parameters_{nullptr} {
if (declaration->hasDefinition() == true) {
TraverseDecl(declaration);
}
}
bool FindTemplateParameters::VisitCXXRecordDecl(CXXRecordDecl *declaration) {
if (IdentifierInfo *info = declaration_->getIdentifier()) {
auto module_name = info->getNameStart();
// Check if the class is a templated module class.
auto template_args{ declaration->getDescribedClassTemplate() };
if (template_args != nullptr) {
template_parameters_ = template_args->getTemplateParameters();
}
}
return false;
}
vector<string> FindTemplateParameters::getTemplateParameters() const {
vector<string> parm_list;
if ( (template_parameters_ == nullptr)
|| (template_parameters_->size() <= 0) ) {
return parm_list;
}
for (auto parm : template_parameters_->asArray() ) {
parm_list.push_back( parm->getName() );
// os_ << "Parm: " << parm->getName() << "\n";
}
return parm_list;
}
FindTemplateParameters::~FindTemplateParameters() { declaration_ = nullptr; }
void FindTemplateParameters::dump() {
}
#ifndef _FIND_TEMPLATE_PARAMETERS_H_
#define _FIND_TEMPLATE_PARAMETERS_H_
#include "clang/AST/DeclCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "llvm/Support/raw_ostream.h"
namespace scpar {
using namespace clang;
using namespace std;
class FindTemplateParameters : public RecursiveASTVisitor<FindTemplateParameters> {
public:
FindTemplateParameters(CXXRecordDecl *, llvm::raw_ostream &);
virtual bool VisitCXXRecordDecl(CXXRecordDecl *decl);
virtual ~FindTemplateParameters();
void dump();
vector<string> getTemplateParameters() const;
private:
CXXRecordDecl *declaration_;
llvm::raw_ostream &os_;
TemplateParameterList *template_parameters_;
};
} // namespace scpar
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment