docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
attributes.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <nlohmann/json.hpp>
6#include <nlohmann/json_fwd.hpp>
7#include <string>
8#include <vector>
9
10using json = nlohmann::json;
11
12namespace docc {
13namespace analysis {
14
24
25struct Attributes {
26 std::vector<ArgumentAttributes> arguments;
27
28 static Attributes from_json(const json& j) {
29 Attributes attrs;
30 if (!j.is_null()) {
31 for (const auto& arg_attrs : j["arguments"]) {
32 ArgumentAttributes argument;
33 argument.copy_target = arg_attrs.value("copy_target", "");
34 argument.copy_buffer = arg_attrs.value("copy_buffer", "");
35 argument.copy_in = arg_attrs.value("copy_in", false);
36 argument.copy_out = arg_attrs.value("copy_out", false);
37 argument.alloc = arg_attrs.value("alloc", false);
38 argument.free = arg_attrs.value("free", false);
39 argument.copy_size = SymEngine::null;
40 if (arg_attrs["copy_size"].is_string() && !arg_attrs["copy_size"].get<std::string>().empty()) {
41 argument.copy_size = sdfg::symbolic::parse(arg_attrs["copy_size"].get<std::string>());
42 }
43 attrs.arguments.push_back(argument);
44 }
45 }
46 return attrs;
47 }
48
49 json to_json() const {
50 json j;
51 j["arguments"] = json::array();
52 for (const auto& arg_attrs : arguments) {
53 std::string copy_size_str;
54 if (!arg_attrs.copy_size.is_null()) {
56 copy_size_str = printer.apply(arg_attrs.copy_size);
57 }
58
59 nlohmann::json attr_json;
60 attr_json["copy_target"] = arg_attrs.copy_target;
61 attr_json["copy_buffer"] = arg_attrs.copy_buffer;
62 attr_json["copy_in"] = arg_attrs.copy_in;
63 attr_json["copy_out"] = arg_attrs.copy_out;
64 attr_json["alloc"] = arg_attrs.alloc;
65 attr_json["free"] = arg_attrs.free;
66 attr_json["copy_size"] = copy_size_str;
67
68 j["arguments"].push_back(attr_json);
69 }
70 return j;
71 }
72};
73
74} // namespace analysis
75} // namespace docc
Definition json_serializer.h:155
Expression parse(const std::string &expr_str)
Parses a string into a symbolic expression.
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
nlohmann::json json
Definition interstate_edge.h:14
Definition analysis.h:9
Definition targets.h:8
Definition attributes.h:15
bool copy_in
Definition attributes.h:19
bool copy_out
Definition attributes.h:20
bool free
Definition attributes.h:22
sdfg::symbolic::Expression copy_size
Definition attributes.h:18
bool alloc
Definition attributes.h:21
std::string copy_buffer
Definition attributes.h:17
std::string copy_target
Definition attributes.h:16
Definition attributes.h:25
std::vector< ArgumentAttributes > arguments
Definition attributes.h:26
static Attributes from_json(const json &j)
Definition attributes.h:28
json to_json() const
Definition attributes.h:49