15 #include <experimental/filesystem>
19 #include <TClassTable.h>
20 #include <TDataMember.h>
21 #include <TInterpreter.h>
28 namespace fs = std::experimental::filesystem;
34 bool cn_has_scope = class_name.find(
"::") != std::string::npos;
35 std::string cn_with_scope_prefix = std::string(
"::") + class_name;
38 std::vector<TClass*> tclasses;
39 while ((current = TClassTable::At(idx++)) !=
nullptr) {
40 std::string scurrent(current);
41 if (scurrent.find(
"::") == std::string::npos) {
43 if (std::string(current).compare(class_name) == 0) {
44 tclasses.push_back(TClassTable::GetDict(current)());
48 if (
EndsWith(scurrent, class_name)) {
49 tclasses.push_back(TClassTable::GetDict(current)());
52 if (
EndsWith(scurrent, cn_with_scope_prefix)) {
53 tclasses.push_back(TClassTable::GetDict(current)());
63 const std::string& data_member) {
64 std::vector<TDataMember*> ret_val;
66 bool dm_has_scope = data_member.find(
"::") != std::string::npos;
67 std::string class_name =
"";
68 std::string dm_only_name = data_member;
70 auto idx = data_member.find_last_of(
"::");
71 class_name = data_member.substr(0, idx - 1);
72 dm_only_name = data_member.substr(idx + 1, data_member.size());
75 std::stack<TClass*> tc_stack;
76 tc_stack.push(tclass);
78 while (tc_stack.size() != 0) {
79 auto* current_tc = tc_stack.top();
81 for (
const auto&& base : *current_tc->GetListOfBases()) {
82 auto get_dict_functor = TClassTable::GetDict(base->GetName());
83 if (get_dict_functor !=
nullptr) {
84 tc_stack.push(get_dict_functor());
88 for (
int i = 0; i < current_tc->GetListOfDataMembers()->GetSize(); ++i) {
90 static_cast<TDataMember*
>(current_tc->GetListOfDataMembers()->At(i));
92 if (dm_only_name.compare(dm->GetName()) == 0 &&
93 EndsWith(std::string(current_tc->GetName()), class_name)) {
94 ret_val.push_back(dm);
97 if (data_member.compare(dm->GetName()) == 0) {
98 ret_val.push_back(dm);
109 TClass* tclass,
const std::vector<std::string>& dm_names,
110 const std::string& functor_name,
111 const std::function<std::string(
112 const std::string&,
const std::vector<TDataMember*>&)>& code_generator)
113 : functor_name_(
Concat(functor_name, counter_++)),
114 code_generator_(code_generator) {
116 for (
auto& dm : dm_names) {
118 if (candidates.size() == 1) {
120 }
else if (candidates.size() == 0) {
121 Log::Fatal(
"JitForEachDataMemberFunctor::JitForEachDataMemberFunctor",
122 "Could not find data member ", dm);
124 Log::Fatal(
"JitForEachDataMemberFunctor::JitForEachDataMemberFunctor",
125 "Data member name (", dm,
") is ambigous");
140 return reinterpret_cast<void*
>(gInterpreter->Calc(cmd.c_str()));
154 bool ExistsInIncludePath(
const std::string& header) {
156 std::string inc_dir_flags = gInterpreter->GetIncludePath();
159 Split(inc_dir_flags.substr(3, inc_dir_flags.length() - 4),
"\" -I\"");
161 std::string slash_header =
Concat(
"/", header);
162 for (
auto& dir : include_dirs) {
163 fs::path hpath = dir;
164 hpath += slash_header;
165 if (fs::exists(hpath)) {
172 std::string GetIncludePaths() {
173 std::string inc_dir_flags = gInterpreter->GetIncludePath();
175 Split(inc_dir_flags.substr(3, inc_dir_flags.length() - 4),
"\" -I\"");
176 std::stringstream sstr;
177 for (
auto& dir : dirs) {
178 sstr << dir << std::endl;
188 fs::path hpath = header;
189 if (hpath.is_absolute()) {
190 if (fs::exists(hpath)) {
191 gInterpreter->Declare(
Concat(
"#include \"", header,
"\"").c_str());
194 Concat(
"Header file ", header,
" does not exist."));
197 if (ExistsInIncludePath(header)) {
198 gInterpreter->Declare(
Concat(
"#include \"", header,
"\"").c_str());
201 Concat(
"Header file ", header,
202 " does not exist in any of the following include "