9
9
#ifndef XEUS_CPP_INSPECT_HPP
10
10
#define XEUS_CPP_INSPECT_HPP
11
11
12
+ #include < filesystem>
12
13
#include < fstream>
13
14
#include < string>
14
15
15
-
16
16
#include < pugixml.hpp>
17
17
18
18
#include < xtl/xsystem.hpp>
23
23
#include " xdemangle.hpp"
24
24
#include " xparser.hpp"
25
25
26
- #include " llvm/Support/FileSystem.h"
27
- #include " llvm/Support/Path.h"
26
+ // #include "llvm/Support/FileSystem.h"
27
+ // #include "llvm/Support/Path.h"
28
+
29
+ // #include "clang/Interpreter/CppInterOp.h"
30
+
28
31
29
32
namespace xcpp
30
33
{
@@ -81,27 +84,57 @@ namespace xcpp
81
84
}
82
85
};
83
86
84
- std::string find_type (const std::string& expression, clang::Interpreter& interpreter)
87
+
88
+ std::string find_type_slow (const std::string& expression) {
89
+ static unsigned long long var_count = 0 ;
90
+
91
+ if (auto type = Cpp::GetType (expression))
92
+ return Cpp::GetQualifiedName (type);
93
+
94
+ // Here we might need to deal with integral types such as 3.14.
95
+
96
+ std::string id = " __Xeus_GetType_" + std::to_string (var_count++);
97
+ std::string using_clause = " using " + id + " = __typeof__(" + expression + " );\n " ;
98
+
99
+ if (!Cpp::Declare (using_clause.c_str (), /* silent=*/ false )) {
100
+ Cpp::TCppScope_t lookup = Cpp::GetNamed (id, 0 );
101
+ Cpp::TCppType_t lookup_ty = Cpp::GetTypeFromScope (lookup);
102
+ return Cpp::GetQualifiedCompleteName (Cpp::GetCanonicalType (lookup_ty));
103
+ }
104
+ return " " ;
105
+ }
106
+ /*
107
+ std::string find_type(const std::string& expression)
85
108
{
86
109
auto PTU = interpreter.Parse(expression + ";");
87
110
if (llvm::Error Err = PTU.takeError()) {
88
111
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
89
112
return "";
90
113
}
91
114
92
- clang::Decl *D = *PTU->TUPart ->decls_begin ();
93
- if (!llvm::isa<clang::TopLevelStmtDecl>(D))
94
- return " " ;
115
+ clang::Decl *D = *PTU->TUPart->decls_begin();
116
+ if (!llvm::isa<clang::TopLevelStmtDecl>(D))
117
+ return "";
95
118
96
- clang::Expr *E = llvm::cast<clang::Expr>(llvm::cast<clang::TopLevelStmtDecl>(D)->getStmt ());
119
+ clang::Expr *E = llvm::cast<clang::Expr>(llvm::cast<clang::TopLevelStmtDecl>(D)->getStmt());
97
120
98
- clang::QualType QT = E->getType ();
121
+ clang::QualType QT = E->getType();
99
122
return QT.getAsString();
100
123
}
101
-
124
+ */
102
125
static nl::json read_tagconfs (const char * path)
103
126
{
104
127
nl::json result = nl::json::array ();
128
+ for (auto &entry: std::filesystem::directory_iterator (path)) {
129
+ if (entry.path ().extension () != " .json" )
130
+ continue ;
131
+ std::ifstream i (entry.path ());
132
+ nl::json json_entry;
133
+ i >> json_entry;
134
+ result.emplace_back (std::move (json_entry));
135
+ }
136
+ return result;
137
+ /*
105
138
std::error_code EC;
106
139
for (llvm::sys::fs::directory_iterator File(path, EC), FileEnd;
107
140
File != FileEnd && !EC; File.increment(EC)) {
@@ -115,19 +148,19 @@ namespace xcpp
115
148
result.emplace_back(std::move(entry));
116
149
}
117
150
return result;
151
+ */
118
152
}
119
153
120
- std::pair<bool , std::smatch> is_inspect_request (const std::string code, std::regex re)
154
+ std::pair<bool , std::smatch> is_inspect_request (const std::string code, std::regex re)
121
155
{
122
156
std::smatch inspect;
123
157
if (std::regex_search (code, inspect, re)){
124
158
return std::make_pair (true , inspect);
125
159
}
126
160
return std::make_pair (false , inspect);
127
-
128
161
}
129
162
130
- void inspect (const std::string& code, nl::json& kernel_res, clang::Interpreter& interpreter )
163
+ void inspect (const std::string& code, nl::json& kernel_res)
131
164
{
132
165
std::string tagconf_dir = XCPP_TAGCONFS_DIR;
133
166
std::string tagfiles_dir = XCPP_TAGFILES_DIR;
@@ -150,7 +183,7 @@ namespace xcpp
150
183
// Method or variable of class found (xxxx.yyyy)
151
184
if (std::regex_search (to_inspect, method, std::regex (R"( (.*)\.(\w*)$)" )))
152
185
{
153
- std::string typename_ = find_type (method[1 ], interpreter );
186
+ std::string typename_ = find_type_slow (method[1 ]);
154
187
155
188
if (!typename_.empty ())
156
189
{
@@ -184,7 +217,7 @@ namespace xcpp
184
217
}
185
218
else
186
219
{
187
- std::string typename_ = find_type (to_inspect, interpreter );
220
+ std::string typename_ = find_type_slow (to_inspect);
188
221
find_string = (typename_.empty ()) ? to_inspect : typename_;
189
222
}
190
223
0 commit comments