-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolver.h
More file actions
67 lines (55 loc) · 2.71 KB
/
Copy pathResolver.h
File metadata and controls
67 lines (55 loc) · 2.71 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef BLANG_RESOLVER_H_
#define BLANG_RESOLVER_H_
// modules-v2-graph U4: the standalone module-resolution component.
//
// Resolution used to be built INLINE in qcc.cpp main() (and, separately, in
// lsp/Compile.cpp). U4 extracts the resolution ENVIRONMENT into one named class
// that BOTH the compiler (qcc) and the editor (blangd) construct — the single
// shared seam Epic C (cross-module LSP) consumes without re-plumbing.
//
// U4 is BEHAVIOR-NEUTRAL: it owns the global builtin scope and hands out module
// scopes exactly as the inline code did. The up-front .bmod flat-merge injection
// and the combine routing POLICY stay in the driver this unit (their removal /
// generalization is done-condition 6 / U6). The module-graph methods
// (registerNamespace/resolveNamespace) are used by qcc's combine path and are
// present-but-dormant for blangd (which stays single-file this epic — Epic C wires
// it through them).
#include <map>
#include <string>
#include <vector>
#include "Type.h" // QLang::Scope
#include "RefCount.h"
namespace QLang
{
class Resolver
{
public:
// Builds and OWNS the global builtin scope (createGlobalScope()) and installs
// it as the process `gScope` alias, saving the previous alias so nested
// constructions (the LSP server, unit tests) restore cleanly on destruction.
Resolver();
~Resolver();
Resolver( const Resolver & ) = delete;
Resolver &operator=( const Resolver & ) = delete;
// The shared global builtin scope. Same object `gScope` aliases.
Scope *globalScope() const { return mGlobalRaw; }
// A fresh module-level scope parented into the resolution environment (default
// parent = the global scope). Replicates EXACTLY what the drivers built inline
// (`new Scope(kScope_Module); setParent(parent)`) and returns the raw pointer —
// lifetime is held by the returned scope's children / the caller / the parent
// chain, precisely as before. The Resolver does NOT retain module scopes (doing
// so would leak one per LSP reparse); it owns only the global scope.
Scope *newModuleScope( Scope *parent = nullptr );
// --- Module graph (behavior-neutral bookkeeping) ------------------------
// The import/namespace registry the combine path keeps. Present for both
// drivers; blangd does not yet resolve through it (Epic C).
void registerNamespace( const std::string &name, Scope *ns );
Scope *resolveNamespace( const std::string &name ) const;
private:
SmartPtr<Scope> mGlobalScope; // owns the builtin scope
Scope *mGlobalRaw = nullptr; // raw alias (const-friendly getter)
Scope *mPrevGScope = nullptr; // saved gScope alias (restored on ~)
std::map<std::string, Scope *> mNamespaces;
};
} // namespace QLang
#endif // BLANG_RESOLVER_H_