Envision
A visual programming IDE for object-oriented languages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
CppImport::ClangAstVisitor Class Reference

This is the core visitor of the CppImport plugin it translates declarations and statements from clang's AST to Envision's AST. More...

Inheritance diagram for CppImport::ClangAstVisitor:

Public Member Functions

 ClangAstVisitor (OOModel::Project *project, const QString &projectPath, CppImportLogger *logger)
 
 ~ClangAstVisitor ()
 
void beforeTranslationUnit (clang::ASTContext &astContext)
 
void endEntireImport ()
 
void endTranslationUnit ()
 
Model::NodeooStackTop ()
 
Model::NodepopOOStack ()
 
void pushOOStack (Model::Node *node)
 
void setSourceManagerAndPreprocessor (const clang::SourceManager *sourceManager, const clang::Preprocessor *preprocessor)
 
bool shouldUseDataRecursionfor (clang::Stmt *S)
 A helper function called by RecursiveASTVisitor parent class. More...
 
bool TraverseBreakStmt (clang::BreakStmt *breakStmt)
 
bool TraverseCaseStmt (clang::CaseStmt *caseStmt)
 
bool TraverseClassTemplateDecl (clang::ClassTemplateDecl *classTemplate)
 
bool TraverseClassTemplateSpecializationDecl (clang::ClassTemplateSpecializationDecl *specializationDecl)
 
bool TraverseCompoundStmt (clang::CompoundStmt *compoundStmt)
 
bool TraverseContinueStmt (clang::ContinueStmt *continueStmt)
 
bool TraverseCXXCatchStmt (clang::CXXCatchStmt *catchStmt)
 
bool TraverseCXXConstructorDecl (clang::CXXConstructorDecl *constructorDecl)
 
bool TraverseCXXConversionDecl (clang::CXXConversionDecl *conversionDecl)
 
bool TraverseCXXDestructorDecl (clang::CXXDestructorDecl *destructorDecl)
 
bool TraverseCXXForRangeStmt (clang::CXXForRangeStmt *forRangeStmt)
 
bool TraverseCXXMethodDecl (clang::CXXMethodDecl *methodDecl)
 
bool TraverseCXXRecordDecl (clang::CXXRecordDecl *recordDecl)
 
bool TraverseCXXTryStmt (clang::CXXTryStmt *tryStmt)
 
bool TraverseDecl (clang::Decl *decl)
 
bool TraverseDeclStmt (clang::DeclStmt *declStmt)
 
bool TraverseDefaultStmt (clang::DefaultStmt *defaultStmt)
 
bool TraverseDoStmt (clang::DoStmt *doStmt)
 
bool TraverseEnumDecl (clang::EnumDecl *enumDecl)
 
bool TraverseFieldDecl (clang::FieldDecl *fieldDecl)
 
bool TraverseForStmt (clang::ForStmt *forStmt)
 
bool TraverseFunctionDecl (clang::FunctionDecl *functionDecl)
 
bool TraverseFunctionTemplateDecl (clang::FunctionTemplateDecl *functionDecl)
 
bool TraverseIfStmt (clang::IfStmt *ifStmt)
 
bool TraverseNamespaceAliasDecl (clang::NamespaceAliasDecl *namespaceAlias)
 
bool TraverseNamespaceDecl (clang::NamespaceDecl *namespaceDecl)
 
bool TraverseReturnStmt (clang::ReturnStmt *returnStmt)
 
bool TraverseStaticAssertDecl (clang::StaticAssertDecl *staticAssertDecl)
 
bool TraverseStmt (clang::Stmt *S)
 Traverses the stmt S and if it is an expression dispatches to the expression visitor. More...
 
bool TraverseSwitchStmt (clang::SwitchStmt *switchStmt)
 
bool TraverseTypeAliasTemplateDecl (clang::TypeAliasTemplateDecl *typeAliasTemplate)
 
bool TraverseUnresolvedUsingValueDecl (clang::UnresolvedUsingValueDecl *unresolvedUsing)
 
bool TraverseUsingDecl (clang::UsingDecl *usingDecl)
 
bool TraverseUsingDirectiveDecl (clang::UsingDirectiveDecl *usingDirectiveDecl)
 
bool TraverseVarDecl (clang::VarDecl *varDecl)
 
bool TraverseWhileStmt (clang::WhileStmt *whileStmt)
 
bool VisitDecl (clang::Decl *decl)
 
bool VisitStmt (clang::Stmt *S)
 
bool WalkUpFromTypedefNameDecl (clang::TypedefNameDecl *typedefDecl)
 

Private Types

using Base = clang::RecursiveASTVisitor< ClangAstVisitor >
 

Private Member Functions

void addFunctionModifiers (clang::FunctionDecl *functionDecl, OOModel::Method *method)
 
void insertFriendClass (clang::FriendDecl *friendDecl, OOModel::Class *ooClass)
 Inserts a friend class with the typeInfo in ooClass. More...
 
void insertFriendFunction (clang::FriendDecl *friendDecl, OOModel::Class *ooClass)
 Inserts the friend function friendFunction in ooClass. More...
 
void insertUsingDirectiveDeclarations ()
 
bool shouldImport (const clang::SourceLocation &location)
 Returns if it is intended to import the code at the location. More...
 
void TraverseClass (clang::CXXRecordDecl *recordDecl, OOModel::Class *ooClass)
 Insert the class in the tree and will visit the body and insert base classes. More...
 
void TraverseFunction (clang::FunctionDecl *functionDecl, OOModel::Method *ooFunction)
 Abstract function to handle common parts between FunctionDecl and its subclasses. More...
 
bool TraverseMethodDecl (clang::CXXMethodDecl *methodDecl, OOModel::Method::MethodKind kind)
 Abstract function to handle normal member functions, constructors, destructors and conversion functions. More...
 

Private Attributes

ClangHelpers clang_
 
const QString className_ {"ClangAstVisitor"}
 
CommentParsercommentParser_ {}
 
ExpressionVisitorexprVisitor_ {}
 
bool importSysHeader_ {false}
 
bool inBody_ {true}
 
CppImportLoggerlog_ {}
 
MacroImporter macroImporter_
 
QStack< OOModel::Expression * > ooExprStack_
 
QStack< Model::Node * > ooStack_
 
TemplateArgumentVisitortemplArgVisitor_ {}
 
TranslateManagertrMngr_ {}
 
QList< clang::UsingDirectiveDecl * > usingDirectiveDeclarations_
 
CppImportUtilitiesutils_ {}
 

Detailed Description

This is the core visitor of the CppImport plugin it translates declarations and statements from clang's AST to Envision's AST.

One can specify to also import system headers with the importSysHeader_ variable.

Member Typedef Documentation

◆ Base

using CppImport::ClangAstVisitor::Base = clang::RecursiveASTVisitor<ClangAstVisitor>
private

Constructor & Destructor Documentation

◆ ClangAstVisitor()

CppImport::ClangAstVisitor::ClangAstVisitor ( OOModel::Project project,
const QString &  projectPath,
CppImportLogger logger 
)

◆ ~ClangAstVisitor()

CppImport::ClangAstVisitor::~ClangAstVisitor ( )

Member Function Documentation

◆ addFunctionModifiers()

void CppImport::ClangAstVisitor::addFunctionModifiers ( clang::FunctionDecl *  functionDecl,
OOModel::Method method 
)
private

◆ beforeTranslationUnit()

void CppImport::ClangAstVisitor::beforeTranslationUnit ( clang::ASTContext &  astContext)

◆ endEntireImport()

void CppImport::ClangAstVisitor::endEntireImport ( )

◆ endTranslationUnit()

void CppImport::ClangAstVisitor::endTranslationUnit ( )

◆ insertFriendClass()

void CppImport::ClangAstVisitor::insertFriendClass ( clang::FriendDecl *  friendDecl,
OOModel::Class ooClass 
)
private

Inserts a friend class with the typeInfo in ooClass.

◆ insertFriendFunction()

void CppImport::ClangAstVisitor::insertFriendFunction ( clang::FriendDecl *  friendDecl,
OOModel::Class ooClass 
)
private

Inserts the friend function friendFunction in ooClass.

◆ insertUsingDirectiveDeclarations()

void CppImport::ClangAstVisitor::insertUsingDirectiveDeclarations ( )
private

◆ ooStackTop()

Model::Node * CppImport::ClangAstVisitor::ooStackTop ( )

◆ popOOStack()

Model::Node * CppImport::ClangAstVisitor::popOOStack ( )

◆ pushOOStack()

void CppImport::ClangAstVisitor::pushOOStack ( Model::Node node)

◆ setSourceManagerAndPreprocessor()

void CppImport::ClangAstVisitor::setSourceManagerAndPreprocessor ( const clang::SourceManager *  sourceManager,
const clang::Preprocessor *  preprocessor 
)

◆ shouldImport()

bool CppImport::ClangAstVisitor::shouldImport ( const clang::SourceLocation &  location)
private

Returns if it is intended to import the code at the location.

The decision is based on wheter the location is valid and on the value of importSysHeader_

◆ shouldUseDataRecursionfor()

bool CppImport::ClangAstVisitor::shouldUseDataRecursionfor ( clang::Stmt *  S)

A helper function called by RecursiveASTVisitor parent class.

In our case this function should return false because we use a custom traversal strategy.

◆ TraverseBreakStmt()

bool CppImport::ClangAstVisitor::TraverseBreakStmt ( clang::BreakStmt *  breakStmt)

◆ TraverseCaseStmt()

bool CppImport::ClangAstVisitor::TraverseCaseStmt ( clang::CaseStmt *  caseStmt)

◆ TraverseClass()

void CppImport::ClangAstVisitor::TraverseClass ( clang::CXXRecordDecl *  recordDecl,
OOModel::Class ooClass 
)
private

Insert the class in the tree and will visit the body and insert base classes.

It does not visit type arguments they should be handled on the caller site.

◆ TraverseClassTemplateDecl()

bool CppImport::ClangAstVisitor::TraverseClassTemplateDecl ( clang::ClassTemplateDecl *  classTemplate)

◆ TraverseClassTemplateSpecializationDecl()

bool CppImport::ClangAstVisitor::TraverseClassTemplateSpecializationDecl ( clang::ClassTemplateSpecializationDecl *  specializationDecl)

◆ TraverseCompoundStmt()

bool CppImport::ClangAstVisitor::TraverseCompoundStmt ( clang::CompoundStmt *  compoundStmt)

◆ TraverseContinueStmt()

bool CppImport::ClangAstVisitor::TraverseContinueStmt ( clang::ContinueStmt *  continueStmt)

◆ TraverseCXXCatchStmt()

bool CppImport::ClangAstVisitor::TraverseCXXCatchStmt ( clang::CXXCatchStmt *  catchStmt)

◆ TraverseCXXConstructorDecl()

bool CppImport::ClangAstVisitor::TraverseCXXConstructorDecl ( clang::CXXConstructorDecl *  constructorDecl)
inline

◆ TraverseCXXConversionDecl()

bool CppImport::ClangAstVisitor::TraverseCXXConversionDecl ( clang::CXXConversionDecl *  conversionDecl)
inline

◆ TraverseCXXDestructorDecl()

bool CppImport::ClangAstVisitor::TraverseCXXDestructorDecl ( clang::CXXDestructorDecl *  destructorDecl)
inline

◆ TraverseCXXForRangeStmt()

bool CppImport::ClangAstVisitor::TraverseCXXForRangeStmt ( clang::CXXForRangeStmt *  forRangeStmt)

◆ TraverseCXXMethodDecl()

bool CppImport::ClangAstVisitor::TraverseCXXMethodDecl ( clang::CXXMethodDecl *  methodDecl)
inline

◆ TraverseCXXRecordDecl()

bool CppImport::ClangAstVisitor::TraverseCXXRecordDecl ( clang::CXXRecordDecl *  recordDecl)

◆ TraverseCXXTryStmt()

bool CppImport::ClangAstVisitor::TraverseCXXTryStmt ( clang::CXXTryStmt *  tryStmt)

◆ TraverseDecl()

bool CppImport::ClangAstVisitor::TraverseDecl ( clang::Decl *  decl)

◆ TraverseDeclStmt()

bool CppImport::ClangAstVisitor::TraverseDeclStmt ( clang::DeclStmt *  declStmt)

◆ TraverseDefaultStmt()

bool CppImport::ClangAstVisitor::TraverseDefaultStmt ( clang::DefaultStmt *  defaultStmt)

◆ TraverseDoStmt()

bool CppImport::ClangAstVisitor::TraverseDoStmt ( clang::DoStmt *  doStmt)

◆ TraverseEnumDecl()

bool CppImport::ClangAstVisitor::TraverseEnumDecl ( clang::EnumDecl *  enumDecl)

◆ TraverseFieldDecl()

bool CppImport::ClangAstVisitor::TraverseFieldDecl ( clang::FieldDecl *  fieldDecl)

◆ TraverseForStmt()

bool CppImport::ClangAstVisitor::TraverseForStmt ( clang::ForStmt *  forStmt)

◆ TraverseFunction()

void CppImport::ClangAstVisitor::TraverseFunction ( clang::FunctionDecl *  functionDecl,
OOModel::Method ooFunction 
)
private

Abstract function to handle common parts between FunctionDecl and its subclasses.

This includes traversing the body.

◆ TraverseFunctionDecl()

bool CppImport::ClangAstVisitor::TraverseFunctionDecl ( clang::FunctionDecl *  functionDecl)

◆ TraverseFunctionTemplateDecl()

bool CppImport::ClangAstVisitor::TraverseFunctionTemplateDecl ( clang::FunctionTemplateDecl *  functionDecl)

◆ TraverseIfStmt()

bool CppImport::ClangAstVisitor::TraverseIfStmt ( clang::IfStmt *  ifStmt)

◆ TraverseMethodDecl()

bool CppImport::ClangAstVisitor::TraverseMethodDecl ( clang::CXXMethodDecl *  methodDecl,
OOModel::Method::MethodKind  kind 
)
private

Abstract function to handle normal member functions, constructors, destructors and conversion functions.

This method will translate the complete method if methodDecl is a definition

◆ TraverseNamespaceAliasDecl()

bool CppImport::ClangAstVisitor::TraverseNamespaceAliasDecl ( clang::NamespaceAliasDecl *  namespaceAlias)

◆ TraverseNamespaceDecl()

bool CppImport::ClangAstVisitor::TraverseNamespaceDecl ( clang::NamespaceDecl *  namespaceDecl)

◆ TraverseReturnStmt()

bool CppImport::ClangAstVisitor::TraverseReturnStmt ( clang::ReturnStmt *  returnStmt)

◆ TraverseStaticAssertDecl()

bool CppImport::ClangAstVisitor::TraverseStaticAssertDecl ( clang::StaticAssertDecl *  staticAssertDecl)

◆ TraverseStmt()

bool CppImport::ClangAstVisitor::TraverseStmt ( clang::Stmt *  S)

Traverses the stmt S and if it is an expression dispatches to the expression visitor.

◆ TraverseSwitchStmt()

bool CppImport::ClangAstVisitor::TraverseSwitchStmt ( clang::SwitchStmt *  switchStmt)

◆ TraverseTypeAliasTemplateDecl()

bool CppImport::ClangAstVisitor::TraverseTypeAliasTemplateDecl ( clang::TypeAliasTemplateDecl *  typeAliasTemplate)

◆ TraverseUnresolvedUsingValueDecl()

bool CppImport::ClangAstVisitor::TraverseUnresolvedUsingValueDecl ( clang::UnresolvedUsingValueDecl *  unresolvedUsing)

◆ TraverseUsingDecl()

bool CppImport::ClangAstVisitor::TraverseUsingDecl ( clang::UsingDecl *  usingDecl)

◆ TraverseUsingDirectiveDecl()

bool CppImport::ClangAstVisitor::TraverseUsingDirectiveDecl ( clang::UsingDirectiveDecl *  usingDirectiveDecl)

◆ TraverseVarDecl()

bool CppImport::ClangAstVisitor::TraverseVarDecl ( clang::VarDecl *  varDecl)

◆ TraverseWhileStmt()

bool CppImport::ClangAstVisitor::TraverseWhileStmt ( clang::WhileStmt *  whileStmt)

◆ VisitDecl()

bool CppImport::ClangAstVisitor::VisitDecl ( clang::Decl *  decl)

◆ VisitStmt()

bool CppImport::ClangAstVisitor::VisitStmt ( clang::Stmt *  S)

◆ WalkUpFromTypedefNameDecl()

bool CppImport::ClangAstVisitor::WalkUpFromTypedefNameDecl ( clang::TypedefNameDecl *  typedefDecl)

Member Data Documentation

◆ clang_

ClangHelpers CppImport::ClangAstVisitor::clang_
private

◆ className_

const QString CppImport::ClangAstVisitor::className_ {"ClangAstVisitor"}
private

◆ commentParser_

CommentParser* CppImport::ClangAstVisitor::commentParser_ {}
private

◆ exprVisitor_

ExpressionVisitor* CppImport::ClangAstVisitor::exprVisitor_ {}
private

◆ importSysHeader_

bool CppImport::ClangAstVisitor::importSysHeader_ {false}
private

◆ inBody_

bool CppImport::ClangAstVisitor::inBody_ {true}
private

◆ log_

CppImportLogger* CppImport::ClangAstVisitor::log_ {}
private

◆ macroImporter_

MacroImporter CppImport::ClangAstVisitor::macroImporter_
private

◆ ooExprStack_

QStack<OOModel::Expression*> CppImport::ClangAstVisitor::ooExprStack_
private

◆ ooStack_

QStack<Model::Node*> CppImport::ClangAstVisitor::ooStack_
private

◆ templArgVisitor_

TemplateArgumentVisitor* CppImport::ClangAstVisitor::templArgVisitor_ {}
private

◆ trMngr_

TranslateManager* CppImport::ClangAstVisitor::trMngr_ {}
private

◆ usingDirectiveDeclarations_

QList<clang::UsingDirectiveDecl*> CppImport::ClangAstVisitor::usingDirectiveDeclarations_
private

◆ utils_

CppImportUtilities* CppImport::ClangAstVisitor::utils_ {}
private