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

This class is to manage the whole translation process. More...

Public Member Functions

 TranslateManager (ClangHelpers &clang, OOModel::Project *root, ExpressionVisitor *visitor)
 
 ~TranslateManager ()
 
QList< OOModel::Class * > classesInFile (QString fileName)
 
bool containsClass (clang::CXXRecordDecl *recordDecl)
 
bool insertClass (clang::CXXRecordDecl *rDecl, OOModel::Class *&createdClass)
 Inserts the class ooClass to the managed class if it is not yet managed. More...
 
bool insertClassTemplate (clang::ClassTemplateDecl *classTemplate, OOModel::Class *&createdClass)
 Inserts the class ooClass to the managed class if it is not yet managed. More...
 
bool insertClassTemplateSpec (clang::ClassTemplateSpecializationDecl *classTemplate, OOModel::Class *&createdClass)
 Inserts the class ooClass to the managed class if it is not yet managed. More...
 
bool insertEnum (clang::EnumDecl *enumDecl, OOModel::Class *&createdEnum)
 Inserts the enum ooEnum to the managed class if it is not yet managed. More...
 
OOModel::ExplicitTemplateInstantiationinsertExplicitTemplateInstantiation (clang::ClassTemplateSpecializationDecl *explicitTemplateInst)
 
OOModel::FieldinsertField (clang::FieldDecl *fieldDecl)
 Inserts the field fieldDecl to the manager and into the correct class. More...
 
OOModel::MethodinsertFunctionDecl (clang::FunctionDecl *functionDecl)
 Inserts the method mDecl to the manager if not yet managed. More...
 
OOModel::MethodinsertMethodDecl (clang::CXXMethodDecl *mDecl, OOModel::Method::MethodKind kind)
 Inserts the method mDecl to the manager if not yet managed. More...
 
OOModel::ModuleinsertNamespace (clang::NamespaceDecl *namespaceDecl)
 
OOModel::TypeAliasinsertNamespaceAlias (clang::NamespaceAliasDecl *namespaceAlias)
 This function is to make sure that an using directive is used only once. More...
 
OOModel::FieldinsertNamespaceField (clang::VarDecl *varDecl, bool &wasDeclared)
 
OOModel::FieldinsertStaticField (clang::VarDecl *varDecl, bool &wasDeclared)
 Inserts the static field varDecl to the manager and into the correct class. More...
 
OOModel::TypeAliasinsertTypeAlias (clang::TypedefNameDecl *typeAlias)
 This function is to make sure that a TypeAlias (either using or typedef) is used only once. More...
 
OOModel::TypeAliasinsertTypeAliasTemplate (clang::TypeAliasTemplateDecl *typeAliasTemplate)
 This function is to make sure that a TypeAlias with template arguments is used only once. More...
 
OOModel::NameImportinsertUnresolvedUsing (clang::UnresolvedUsingValueDecl *unresolvedUsing)
 This function is to make sure that an unresolved using directive is used only once. More...
 
OOModel::NameImportinsertUsingDecl (clang::UsingDecl *usingDecl)
 This function is to make sure that an using declaration is used only once. More...
 
OOModel::NameImportinsertUsingDirective (clang::UsingDirectiveDecl *usingDirective)
 This function is to make sure that an using directive is used only once. More...
 
OOModel::ClasslookupClass (clang::CXXRecordDecl *rDecl)
 
void removeEmptyNamespaces ()
 Called at the end of each translation unit in order to remove empty namespaces that were added because of forward declarations. More...
 
void setUtils (CppImportUtilities *utils)
 

Private Member Functions

void addMethodArguments (clang::FunctionDecl *functionDecl, OOModel::Method *method)
 
void addMethodResult (clang::FunctionDecl *functionDecl, OOModel::Method *method)
 
OOModel::MethodaddNewFunction (clang::FunctionDecl *functionDecl)
 
OOModel::MethodaddNewMethod (clang::CXXMethodDecl *mDecl, OOModel::Method::MethodKind kind)
 
OOModel::ClasscreateClass (clang::CXXRecordDecl *recordDecl)
 Creates a class with the name as specified in recordDecl. More...
 
bool isNameSpaceEmpty (OOModel::Module *nameSpace)
 

Private Attributes

ClangHelpersclang_
 
QHash< QString, OOModel::Class * > classMap_
 
QHash< QString, OOModel::Class * > enumMap_
 
QHash< QString, OOModel::ExplicitTemplateInstantiation * > explicitTemplateInstMap_ {}
 
ExpressionVisitorexprVisitor_ {}
 
QHash< QString, OOModel::Method * > functionMap_
 
QHash< QString, OOModel::Method * > methodMap_
 
QHash< QString, OOModel::TypeAlias * > namespacAliasMap_
 
QHash< QString, OOModel::Field * > namespaceFieldMap_
 
QHash< QString, OOModel::Module * > nameSpaceMap_
 
NodeHashernh_ {}
 
OOModel::ProjectrootProject_ {}
 
QHash< QString, OOModel::Field * > staticFieldMap_
 
QHash< QString, OOModel::TypeAlias * > typeAliasMap_
 
QHash< QString, OOModel::NameImport * > usingDeclMap_
 
QHash< QString, OOModel::NameImport * > usingDirectiveMap_
 
CppImportUtilitiesutils_ {}
 

Detailed Description

This class is to manage the whole translation process.

It keeps track of nodes already translated and completes them if needed.

Constructor & Destructor Documentation

◆ TranslateManager()

CppImport::TranslateManager::TranslateManager ( ClangHelpers clang,
OOModel::Project root,
ExpressionVisitor visitor 
)

◆ ~TranslateManager()

CppImport::TranslateManager::~TranslateManager ( )

Member Function Documentation

◆ addMethodArguments()

void CppImport::TranslateManager::addMethodArguments ( clang::FunctionDecl *  functionDecl,
OOModel::Method method 
)
private

◆ addMethodResult()

void CppImport::TranslateManager::addMethodResult ( clang::FunctionDecl *  functionDecl,
OOModel::Method method 
)
private

◆ addNewFunction()

OOModel::Method * CppImport::TranslateManager::addNewFunction ( clang::FunctionDecl *  functionDecl)
private

◆ addNewMethod()

OOModel::Method * CppImport::TranslateManager::addNewMethod ( clang::CXXMethodDecl *  mDecl,
OOModel::Method::MethodKind  kind 
)
private

◆ classesInFile()

QList< OOModel::Class * > CppImport::TranslateManager::classesInFile ( QString  fileName)

◆ containsClass()

bool CppImport::TranslateManager::containsClass ( clang::CXXRecordDecl *  recordDecl)

◆ createClass()

OOModel::Class * CppImport::TranslateManager::createClass ( clang::CXXRecordDecl *  recordDecl)
private

Creates a class with the name as specified in recordDecl.

It also sets the correct Kind (class, struct or union) if the kind is none of this the method returns a nullptr

◆ insertClass()

bool CppImport::TranslateManager::insertClass ( clang::CXXRecordDecl *  rDecl,
OOModel::Class *&  createdClass 
)

Inserts the class ooClass to the managed class if it is not yet managed.

Returns true if the class is not yet managed (insert success) else false

◆ insertClassTemplate()

bool CppImport::TranslateManager::insertClassTemplate ( clang::ClassTemplateDecl *  classTemplate,
OOModel::Class *&  createdClass 
)

Inserts the class ooClass to the managed class if it is not yet managed.

Returns true if the class is not yet managed (insert success) else false

◆ insertClassTemplateSpec()

bool CppImport::TranslateManager::insertClassTemplateSpec ( clang::ClassTemplateSpecializationDecl *  classTemplate,
OOModel::Class *&  createdClass 
)

Inserts the class ooClass to the managed class if it is not yet managed.

Returns true if the class is not yet managed (insert success) else false

◆ insertEnum()

bool CppImport::TranslateManager::insertEnum ( clang::EnumDecl *  enumDecl,
OOModel::Class *&  createdEnum 
)

Inserts the enum ooEnum to the managed class if it is not yet managed.

Returns true if the enum is not yet managed (insert success) else false

◆ insertExplicitTemplateInstantiation()

OOModel::ExplicitTemplateInstantiation * CppImport::TranslateManager::insertExplicitTemplateInstantiation ( clang::ClassTemplateSpecializationDecl *  explicitTemplateInst)

◆ insertField()

OOModel::Field * CppImport::TranslateManager::insertField ( clang::FieldDecl *  fieldDecl)

Inserts the field fieldDecl to the manager and into the correct class.

If the parent is not yet visited this method returns a nullptr.

◆ insertFunctionDecl()

OOModel::Method * CppImport::TranslateManager::insertFunctionDecl ( clang::FunctionDecl *  functionDecl)

Inserts the method mDecl to the manager if not yet managed.

If the method is already managed the arguments may be completed. Returns either the new method created or the existing one.

◆ insertMethodDecl()

OOModel::Method * CppImport::TranslateManager::insertMethodDecl ( clang::CXXMethodDecl *  mDecl,
OOModel::Method::MethodKind  kind 
)

Inserts the method mDecl to the manager if not yet managed.

If the method is already managed the arguments may be completed. Returns either the new method created or the existing one.

◆ insertNamespace()

OOModel::Module * CppImport::TranslateManager::insertNamespace ( clang::NamespaceDecl *  namespaceDecl)

◆ insertNamespaceAlias()

OOModel::TypeAlias * CppImport::TranslateManager::insertNamespaceAlias ( clang::NamespaceAliasDecl *  namespaceAlias)

This function is to make sure that an using directive is used only once.

The function returns a new allocated NameImport object if this usingdecl is not yet there in this context. Else it returns a nullptr.

◆ insertNamespaceField()

OOModel::Field * CppImport::TranslateManager::insertNamespaceField ( clang::VarDecl *  varDecl,
bool &  wasDeclared 
)

◆ insertStaticField()

OOModel::Field * CppImport::TranslateManager::insertStaticField ( clang::VarDecl *  varDecl,
bool &  wasDeclared 
)

Inserts the static field varDecl to the manager and into the correct class.

The parameter wasDeclared will be set to true if the declaration of this field was visited (only need to visit initializer now). The caller has to make sure that this is a static field. If the parent is not yet visited this method returns a nullptr. Note that clang treats a static field as a VarDecl

◆ insertTypeAlias()

OOModel::TypeAlias * CppImport::TranslateManager::insertTypeAlias ( clang::TypedefNameDecl *  typeAlias)

This function is to make sure that a TypeAlias (either using or typedef) is used only once.

The function returns a new allocated TypeAlias object if this type alias is not yet there in this context. Else it returns a nullptr.

◆ insertTypeAliasTemplate()

OOModel::TypeAlias * CppImport::TranslateManager::insertTypeAliasTemplate ( clang::TypeAliasTemplateDecl *  typeAliasTemplate)

This function is to make sure that a TypeAlias with template arguments is used only once.

The function returns a new allocated TypeAlias object if this type alias is not yet there in this context. Else it returns a nullptr.

◆ insertUnresolvedUsing()

OOModel::NameImport * CppImport::TranslateManager::insertUnresolvedUsing ( clang::UnresolvedUsingValueDecl *  unresolvedUsing)

This function is to make sure that an unresolved using directive is used only once.

The function returns a new allocated NameImport object if this usingdecl is not yet there in this context. Else it returns a nullptr.

◆ insertUsingDecl()

OOModel::NameImport * CppImport::TranslateManager::insertUsingDecl ( clang::UsingDecl *  usingDecl)

This function is to make sure that an using declaration is used only once.

The function returns a new allocated NameImport object if this usingdecl is not yet there in this context. Else it returns a nullptr.

◆ insertUsingDirective()

OOModel::NameImport * CppImport::TranslateManager::insertUsingDirective ( clang::UsingDirectiveDecl *  usingDirective)

This function is to make sure that an using directive is used only once.

The function returns a new allocated NameImport object if this usingdecl is not yet there in this context. Else it returns a nullptr.

◆ isNameSpaceEmpty()

bool CppImport::TranslateManager::isNameSpaceEmpty ( OOModel::Module nameSpace)
private

◆ lookupClass()

OOModel::Class * CppImport::TranslateManager::lookupClass ( clang::CXXRecordDecl *  rDecl)

◆ removeEmptyNamespaces()

void CppImport::TranslateManager::removeEmptyNamespaces ( )

Called at the end of each translation unit in order to remove empty namespaces that were added because of forward declarations.

◆ setUtils()

void CppImport::TranslateManager::setUtils ( CppImportUtilities utils)

Member Data Documentation

◆ clang_

ClangHelpers& CppImport::TranslateManager::clang_
private

◆ classMap_

QHash<QString, OOModel::Class*> CppImport::TranslateManager::classMap_
private

◆ enumMap_

QHash<QString, OOModel::Class*> CppImport::TranslateManager::enumMap_
private

◆ explicitTemplateInstMap_

QHash<QString, OOModel::ExplicitTemplateInstantiation*> CppImport::TranslateManager::explicitTemplateInstMap_ {}
private

◆ exprVisitor_

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

◆ functionMap_

QHash<QString, OOModel::Method*> CppImport::TranslateManager::functionMap_
private

◆ methodMap_

QHash<QString, OOModel::Method*> CppImport::TranslateManager::methodMap_
private

◆ namespacAliasMap_

QHash<QString, OOModel::TypeAlias*> CppImport::TranslateManager::namespacAliasMap_
private

◆ namespaceFieldMap_

QHash<QString, OOModel::Field*> CppImport::TranslateManager::namespaceFieldMap_
private

◆ nameSpaceMap_

QHash<QString, OOModel::Module*> CppImport::TranslateManager::nameSpaceMap_
private

◆ nh_

NodeHasher* CppImport::TranslateManager::nh_ {}
private

◆ rootProject_

OOModel::Project* CppImport::TranslateManager::rootProject_ {}
private

◆ staticFieldMap_

QHash<QString, OOModel::Field*> CppImport::TranslateManager::staticFieldMap_
private

◆ typeAliasMap_

QHash<QString, OOModel::TypeAlias*> CppImport::TranslateManager::typeAliasMap_
private

◆ usingDeclMap_

QHash<QString, OOModel::NameImport*> CppImport::TranslateManager::usingDeclMap_
private

◆ usingDirectiveMap_

QHash<QString, OOModel::NameImport*> CppImport::TranslateManager::usingDirectiveMap_
private

◆ utils_

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