0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
clanguml::common::visitor::ast_id_mapper Class Reference

Mapping between Clang AST identifier and clang-uml unique ids. More...

Detailed Description

Mapping between Clang AST identifier and clang-uml unique ids.

Since identifiers provided by Clang AST are not transferable between translation units (i.e. the same class can have a different id when visited from different translation units), we need global identifiers which are the same among all translation units.

Currently they are calculated as hashes from the fully qualified string representation of the type.

This class allows to store mappings between Clang local identifiers in current translation unit and the global identifiers for the element.

Definition at line 43 of file ast_id_mapper.h.

#include <ast_id_mapper.h>

Public Member Functions

 ast_id_mapper ()=default
 
void add (int64_t ast_id, eid_t global_id)
 
std::optional< eid_tget_global_id (eid_t ast_id)
 
eid_t resolve_or (eid_t id)
 

Private Attributes

std::map< int64_t, eid_tid_map_
 

Constructor & Destructor Documentation

◆ ast_id_mapper()

clanguml::common::visitor::ast_id_mapper::ast_id_mapper ( )
default

Member Function Documentation

◆ add()

void clanguml::common::visitor::ast_id_mapper::add ( int64_t  ast_id,
eid_t  global_id 
)

Add id mapping.

Parameters
ast_idClang's local AST id.
global_idGlobal element id.

Definition at line 23 of file ast_id_mapper.cc.

24{
25 id_map_[ast_id] = global_id;
26}

◆ get_global_id()

std::optional< eid_t > clanguml::common::visitor::ast_id_mapper::get_global_id ( eid_t  ast_id)

Get global element id based on it's local Clang AST id, if exists.

Parameters
ast_idClang's local AST id.
Returns
Global id, if exists.

Definition at line 28 of file ast_id_mapper.cc.

29{
30 if (ast_id.is_global())
31 return {};
32
33 if (id_map_.count(ast_id.ast_local_value()) == 0)
34 return {};
35
36 return id_map_.at(ast_id.ast_local_value());
37}

◆ resolve_or()

eid_t clanguml::common::visitor::ast_id_mapper::resolve_or ( eid_t  id)

Definition at line 39 of file ast_id_mapper.cc.

40{
41 if (id.is_global())
42 return id;
43
44 if (id_map_.count(id.ast_local_value()) == 0)
45 return id;
46
47 return id_map_.at(id.ast_local_value());
48}

Member Data Documentation

◆ id_map_

std::map< int64_t, eid_t> clanguml::common::visitor::ast_id_mapper::id_map_
private

Definition at line 68 of file ast_id_mapper.h.


The documentation for this class was generated from the following files: