-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolver.cpp
More file actions
51 lines (43 loc) · 1.58 KB
/
Copy pathResolver.cpp
File metadata and controls
51 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// modules-v2-graph U4: the standalone module-resolution component (see Resolver.h).
// Behavior-neutral extraction of the resolution environment both qcc and blangd
// built inline.
#include "Resolver.h"
#include "Frontend.h" // createGlobalScope(), gScope
#include "Expression.h" // complete AST types for SmartPtr<Scope> instantiation
namespace QLang
{
Resolver::Resolver()
{
// Own the global builtin scope (createGlobalScope returns refcount 0; the
// SmartPtr takes the owning reference — Frontend.h's contract, so the first
// child's parent ref does not free it out from under us). Install it as the
// process `gScope` alias the parser/sema read, saving the previous alias so a
// nested Resolver (LSP server, unit tests) restores it on destruction.
mGlobalScope = createGlobalScope();
mGlobalRaw = (Scope *)mGlobalScope;
mPrevGScope = gScope;
gScope = mGlobalRaw;
}
Resolver::~Resolver()
{
// Restore whatever alias was in place before this Resolver (typically nullptr
// for the top-level driver, or an enclosing Resolver's scope). mGlobalScope's
// SmartPtr releases the global scope here.
gScope = mPrevGScope;
}
Scope *Resolver::newModuleScope( Scope *parent )
{
Scope *s = new Scope( Scope::kScope_Module );
s->setParent( parent != nullptr ? parent : (Scope *)mGlobalScope );
return s;
}
void Resolver::registerNamespace( const std::string &name, Scope *ns )
{
mNamespaces[name] = ns;
}
Scope *Resolver::resolveNamespace( const std::string &name ) const
{
auto it = mNamespaces.find( name );
return it != mNamespaces.end() ? it->second : nullptr;
}
} // namespace QLang