|
9 | 9 | #include "metacg/metadata/MetaData.h" |
10 | 10 |
|
11 | 11 | namespace clang { |
12 | | - class FunctionDecl; |
| 12 | +class FunctionDecl; |
13 | 13 | } |
14 | 14 |
|
15 | | - |
16 | 15 | class CaGeDemoMD : public metacg::MetaData::Registrar<CaGeDemoMD> { |
17 | | -public: |
18 | | - static constexpr const char* key = "CaCeDemoMetadata"; |
| 16 | + public: |
| 17 | + static constexpr const char* key = "CaCeDemoMetadata"; |
19 | 18 |
|
20 | | - CaGeDemoMD() = default; |
21 | | - /** |
22 | | - * Specify how to create your Metadata from a json input |
23 | | - */ |
24 | | - explicit CaGeDemoMD(const nlohmann::json&, metacg::StrToNodeMapping&) { |
25 | | - assert(false && "This metadata should not be created via json"); |
26 | | - } |
| 19 | + CaGeDemoMD() = default; |
| 20 | + /** |
| 21 | + * Specify how to create your Metadata from a json input |
| 22 | + */ |
| 23 | + explicit CaGeDemoMD(const nlohmann::json&, metacg::StrToNodeMapping&) { |
| 24 | + assert(false && "This metadata should not be created via json"); |
| 25 | + } |
27 | 26 |
|
28 | | - explicit CaGeDemoMD(const void* const f) : address(reinterpret_cast<uintptr_t>(f)) {} |
29 | | - explicit CaGeDemoMD(const uintptr_t p) : address(p) {} |
| 27 | + explicit CaGeDemoMD(const void* const f) : address(reinterpret_cast<uintptr_t>(f)) {} |
| 28 | + explicit CaGeDemoMD(const uintptr_t p) : address(p) {} |
30 | 29 |
|
31 | | - /** |
32 | | - * Specify how to serialize your metadata into a json output |
33 | | - * Return an empty json object to signal that this metadata will not be serialized |
34 | | - * @return empty json object |
35 | | - */ |
36 | | - nlohmann::json toJson(metacg::NodeToStrMapping&) const final { |
37 | | - //We just store the address |
38 | | - return {{"Address", reinterpret_cast<uintptr_t>(address)}}; |
39 | | - } |
| 30 | + /** |
| 31 | + * Specify how to serialize your metadata into a json output |
| 32 | + * Return an empty json object to signal that this metadata will not be serialized |
| 33 | + * @return empty json object |
| 34 | + */ |
| 35 | + nlohmann::json toJson(metacg::NodeToStrMapping&) const final { |
| 36 | + // We just store the address |
| 37 | + return {{"Address", reinterpret_cast<uintptr_t>(address)}}; |
| 38 | + } |
40 | 39 |
|
41 | | - /** |
42 | | - * Allows to query the metadata-key from a baseclass-pointer via virtual dispatch |
43 | | - * @return your metadata key |
44 | | - */ |
45 | | - [[nodiscard]] const char* getKey() const final { return key; } |
| 40 | + /** |
| 41 | + * Allows to query the metadata-key from a baseclass-pointer via virtual dispatch |
| 42 | + * @return your metadata key |
| 43 | + */ |
| 44 | + [[nodiscard]] const char* getKey() const final { return key; } |
46 | 45 |
|
47 | | - /** |
48 | | - * If your metadata stores ids of other callgraph-nodes, they might be invalidated |
49 | | - * This can happen if the graph containing your metadata is merged with another graph. |
50 | | - * Your metadata might be copied into the new graph |
51 | | - * In this case you need to remap the stored node-ids to be valid in the new merged graph context |
52 | | - * |
53 | | - * @param g A map how to rename the old node-id to a new node-id, which is valid in the merged graph |
54 | | - */ |
55 | | - void applyMapping(const metacg::GraphMapping& g) final {} |
| 46 | + /** |
| 47 | + * If your metadata stores ids of other callgraph-nodes, they might be invalidated |
| 48 | + * This can happen if the graph containing your metadata is merged with another graph. |
| 49 | + * Your metadata might be copied into the new graph |
| 50 | + * In this case you need to remap the stored node-ids to be valid in the new merged graph context |
| 51 | + * |
| 52 | + * @param g A map how to rename the old node-id to a new node-id, which is valid in the merged graph |
| 53 | + */ |
| 54 | + void applyMapping(const metacg::GraphMapping& g) final {} |
56 | 55 |
|
57 | | - /** |
58 | | - * How to merge your metadata with itself |
59 | | - * This can happen if the graph containing your metadata is merged with another graph. |
60 | | - * Update the state of your this metadata object accordingly |
61 | | - * @param toMerge the other Metadata to merge with |
62 | | - * @param mergeAction contains whether the merge will replace the other metadata |
63 | | - * @param g A map how to rename the old node-id to a new node-id, which is valid in the merged graph |
64 | | - */ |
65 | | - void merge(const MetaData& toMerge, std::optional<metacg::MergeAction> mergeAction, |
66 | | - const metacg::GraphMapping& g) final { |
67 | | - if (std::strcmp(toMerge.getKey(), getKey()) != 0) { |
68 | | - metacg::MCGLogger::instance().getErrConsole()->error( |
69 | | - "The MetaData which was tried to merge with ASTNodeMetadata was of a different MetaData type"); |
70 | | - abort(); |
71 | | - } |
72 | | - assert(false && "This metadata can not be exported and therefore is not mergeable"); |
73 | | - // const ASTNodeMetadata* toMergeDerived = static_cast<const ASTNodeMetadata*>(&toMerge); |
| 56 | + /** |
| 57 | + * How to merge your metadata with itself |
| 58 | + * This can happen if the graph containing your metadata is merged with another graph. |
| 59 | + * Update the state of your this metadata object accordingly |
| 60 | + * @param toMerge the other Metadata to merge with |
| 61 | + * @param mergeAction contains whether the merge will replace the other metadata |
| 62 | + * @param g A map how to rename the old node-id to a new node-id, which is valid in the merged graph |
| 63 | + */ |
| 64 | + void merge(const MetaData& toMerge, std::optional<metacg::MergeAction> mergeAction, |
| 65 | + const metacg::GraphMapping& g) final { |
| 66 | + if (std::strcmp(toMerge.getKey(), getKey()) != 0) { |
| 67 | + metacg::MCGLogger::instance().getErrConsole()->error( |
| 68 | + "The MetaData which was tried to merge with ASTNodeMetadata was of a different MetaData type"); |
| 69 | + abort(); |
74 | 70 | } |
| 71 | + assert(false && "This metadata can not be exported and therefore is not mergeable"); |
| 72 | + // const ASTNodeMetadata* toMergeDerived = static_cast<const ASTNodeMetadata*>(&toMerge); |
| 73 | + } |
75 | 74 |
|
76 | | - /** |
77 | | - * Specify how to clone your metadat |
78 | | - * @return a cloned version of your metadata |
79 | | - */ |
80 | | - [[nodiscard]] std::unique_ptr<MetaData> clone() const final { |
81 | | - return std::make_unique<CaGeDemoMD>(); |
82 | | - } |
| 75 | + /** |
| 76 | + * Specify how to clone your metadat |
| 77 | + * @return a cloned version of your metadata |
| 78 | + */ |
| 79 | + [[nodiscard]] std::unique_ptr<MetaData> clone() const final { return std::make_unique<CaGeDemoMD>(); } |
83 | 80 |
|
84 | | - uintptr_t getAdressValue() { |
85 | | - return reinterpret_cast<uintptr_t>(address); |
86 | | - } |
| 81 | + uintptr_t getAdressValue() { return reinterpret_cast<uintptr_t>(address); } |
87 | 82 |
|
88 | | -private: |
89 | | - uintptr_t address = 0; |
| 83 | + private: |
| 84 | + uintptr_t address = 0; |
90 | 85 | }; |
91 | 86 | #endif |
0 commit comments