diff options
| author | Patrick Schönberger | 2021-08-04 17:46:48 +0200 |
|---|---|---|
| committer | Patrick Schönberger | 2021-08-04 17:46:48 +0200 |
| commit | c2ba7425955ae538e220cec79d9124756d1b4c8b (patch) | |
| tree | 95ae57095eaf15a8914edf0eda6a7d842ec2f10d /src/find.h | |
| parent | 7f83e1b208e87e3808b268303bb633a8fda203f5 (diff) | |
| download | toc-c2ba7425955ae538e220cec79d9124756d1b4c8b.tar.gz toc-c2ba7425955ae538e220cec79d9124756d1b4c8b.zip | |
function resolution, pre generics
Diffstat (limited to 'src/find.h')
| -rw-r--r-- | src/find.h | 40 |
1 files changed, 20 insertions, 20 deletions
@@ -33,15 +33,26 @@ opt<Function> findFunction( if (!n.has_value())
return nullopt;
+ std::vector<Namespace> namespaces = { n.value() };
+
for (int i = 1; i < namespacePrefixes.size(); i++)
{
n = find<Namespace>(n.value().namespaces, [&](Namespace n) { return n.name == namespacePrefixes[i]; });
if (!n.has_value())
return nullopt;
+
+ namespaces.push_back(n.value());
+ }
+
+ for (int i = namespaces.size()-1; i >= 0; i--)
+ {
+ auto f = find<Function>(namespaces[i].functions, [&](Function f) { return f.name == name; });
+ if (f.has_value())
+ return f.value();
}
- return find<Function>(n.value().functions, [&](Function f) { return f.name == name; });
+ return find<Function>(p.functions, [&](Function f) { return f.name == name; });
}
opt<Struct> findStruct(
@@ -72,28 +83,17 @@ opt<Struct> findStruct( opt<Variable> findVariable(
const Program & p,
const std::string & name,
- const std::vector<std::string> & namespacePrefixes)
+ std::shared_ptr<Context> ctx)
{
- for (auto n : namespacePrefixes)
- std::cout << n << std::endl;
- if (namespacePrefixes.empty())
- {
- return find<Variable>(p.ctx->variables, [&](Variable v) { return v.name == name; });
- }
-
- auto n = find<Namespace>(p.namespaces, [&](Namespace n) { return n.name == namespacePrefixes[0]; });
-
- if (!n.has_value())
- return nullopt;
-
- for (int i = 1; i < namespacePrefixes.size(); i++)
+ auto it = ctx;
+ while (it != nullptr)
{
- n = find<Namespace>(n.value().namespaces, [&](Namespace n) { return n.name == namespacePrefixes[i]; });
-
- if (!n.has_value())
- return nullopt;
+ auto v = find<Variable>(it->variables, [&](Variable v) { return v.name == name; });
+ if (v.has_value())
+ return v;
+ it = it->parent;
}
- return find<Variable>(n.value().ctx->variables, [&](Variable v) { return v.name == name; });
+ return nullopt;
}
opt<Function> findStructMethod(
|
