0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
ast_id_mapper.h
Go to the documentation of this file.
1/**
2 * @file src/common/visitor/ast_id_mapper.h
3 *
4 * Copyright (c) 2021-2024 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#pragma once
19
21
22#include <cstdint>
23#include <map>
24
26
28
29/**
30 * @brief Mapping between Clang AST identifier and `clang-uml` unique ids
31 *
32 * Since identifiers provided by Clang AST are not transferable between
33 * translation units (i.e. the same class can have a different id when visited
34 * from different translation units), we need global identifiers which are
35 * the same among all translation units.
36 *
37 * Currently they are calculated as hashes from the fully qualified string
38 * representation of the type.
39 *
40 * This class allows to store mappings between Clang local identifiers
41 * in current translation unit and the global identifiers for the element.
42 */
44public:
45 ast_id_mapper() = default;
46
47 /**
48 * Add id mapping.
49 *
50 * @param ast_id Clang's local AST id.
51 * @param global_id Global element id.
52 */
53 void add(int64_t ast_id, eid_t global_id);
54
55 /**
56 * Get global element id based on it's local Clang AST id, if exists.
57 *
58 * @param ast_id Clang's local AST id.
59 * @return Global id, if exists.
60 */
61 std::optional<eid_t> get_global_id(eid_t ast_id);
62
64
65private:
66 std::map</* Clang AST translation unit local id */ int64_t,
67 /* clang-uml global id */ eid_t>
69};
70
71} // namespace clanguml::common::visitor