\r
template<typename T>\r
using opt = std::optional<T>;\r
+template<typename ... Ts>\r
+using tup = std::tuple<Ts ...>;\r
\r
+// find an item in a vector by predicate\r
template<typename T>\r
opt<T> find(const std::vector<T> & ts, std::function<bool(T)> f)\r
{\r
return nullopt;\r
}\r
\r
+// same as above but return pointer into raw array held by vector\r
template<typename T>\r
opt<T *> findPtr(const std::vector<T> & ts, std::function<bool(T)> f)\r
{\r
return nullopt;\r
}\r
\r
-std::optional<\r
- std::tuple<\r
- std::shared_ptr<Context>,\r
- std::vector<std::string>>>\r
+opt<tup<\r
+ std::shared_ptr<Context>,\r
+ std::vector<std::string>>>\r
getContext(std::shared_ptr<Context> ctx, const std::vector<std::string> & namespacePrefix)\r
{\r
+ // try finding a continuos series of namespaces in a given context\r
auto result = ctx;\r
\r
for (auto name : namespacePrefix)\r
}\r
}\r
\r
+ // if the found context is the end of a series of namespaces, also return\r
+ // a vector of namespace names\r
std::vector<std::string> namespaces;\r
for (auto it = result; it != nullptr; it = it->parent)\r
{\r
return std::make_tuple(result, namespaces);\r
}\r
\r
+// all of the following functions work the same way,\r
+// walking up the context hierarchy until the global context.\r
+// return the first found instance that matches provided criteria\r
+// theres also a variant to get a pointer instead for functions and\r
+// structs used for generic instantiation\r
\r
-\r
-opt<std::tuple<Function, std::vector<std::string>>> findFunction(\r
+opt<tup<Function, std::vector<std::string>>> findFunction(\r
const std::string & name,\r
const std::vector<std::string> & namespacePrefix,\r
std::shared_ptr<Context> ctx)\r
return nullopt;\r
}\r
\r
-opt<std::tuple<Function *, std::vector<std::string>>> findFunctionPtr(\r
+opt<tup<Function *, std::vector<std::string>>> findFunctionPtr(\r
const std::string & name,\r
const std::vector<std::string> & namespacePrefix,\r
std::shared_ptr<Context> ctx)\r
\r
\r
\r
-opt<std::tuple<Struct, std::vector<std::string>>> findStruct(\r
+opt<tup<Struct, std::vector<std::string>>> findStruct(\r
const std::string & name,\r
const std::vector<std::string> & namespacePrefix,\r
std::shared_ptr<Context> ctx)\r
return nullopt;\r
}\r
\r
-opt<std::tuple<Struct *, std::vector<std::string>>> findStructPtr(\r
+opt<tup<Struct *, std::vector<std::string>>> findStructPtr(\r
const std::string & name,\r
const std::vector<std::string> & namespacePrefix,\r
std::shared_ptr<Context> ctx)\r
\r
\r
\r
-opt<std::tuple<Variable, std::vector<std::string>>> findVariable(\r
+opt<tup<Variable, std::vector<std::string>>> findVariable(\r
const std::string & name,\r
const std::vector<std::string> & namespacePrefix,\r
std::shared_ptr<Context> ctx)\r
\r
\r
\r
+// find struct members and pointer variants\r
+\r
opt<StructMember<Function>> findStructMethod(\r
const std::string & name,\r
const Struct & s)\r