diff options
author | Philip Herron <herron.philip@googlemail.com> | 2020-05-17 16:38:03 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 21:13:13 +0000 |
commit | ae07b534e2e4da55734a4577b0176f623e5b1362 (patch) | |
tree | 55e338cb03e1262e3fa7a4d134e6362b38460460 /gcc/rust/analysis | |
parent | 837cc2b5c46844e897545112a8395f94b8a35758 (diff) | |
download | gcc-ae07b534e2e4da55734a4577b0176f623e5b1362.zip gcc-ae07b534e2e4da55734a4577b0176f623e5b1362.tar.gz gcc-ae07b534e2e4da55734a4577b0176f623e5b1362.tar.bz2 |
Template the scope class
Diffstat (limited to 'gcc/rust/analysis')
-rw-r--r-- | gcc/rust/analysis/rust-resolution.h | 4 | ||||
-rw-r--r-- | gcc/rust/analysis/scope.h | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/gcc/rust/analysis/rust-resolution.h b/gcc/rust/analysis/rust-resolution.h index 8a16b0d..cd8eb91 100644 --- a/gcc/rust/analysis/rust-resolution.h +++ b/gcc/rust/analysis/rust-resolution.h @@ -225,8 +225,8 @@ private: bool go (); - Scope scope; - Scope typeScope; + Scope<AST::Type *> scope; + Scope<AST::Type *> typeScope; AST::Crate &crate; std::vector<AST::IdentifierPattern> letPatternBuffer; diff --git a/gcc/rust/analysis/scope.h b/gcc/rust/analysis/scope.h index 0374251..231e667 100644 --- a/gcc/rust/analysis/scope.h +++ b/gcc/rust/analysis/scope.h @@ -6,14 +6,14 @@ namespace Rust { namespace Analysis { -class Scope +template <class T> class Scope { public: Scope () : scopeStack () {} ~Scope () {} - bool Insert (std::string key, AST::Type *val) + bool Insert (std::string key, T val) { if (scopeStack.back ().find (key) != scopeStack.back ().end ()) { @@ -24,7 +24,7 @@ public: return true; } - bool Lookup (std::string key, AST::Type **result) + bool Lookup (std::string key, T *result) { for (auto it = scopeStack.rbegin (); it != scopeStack.rend (); ++it) { @@ -40,7 +40,7 @@ public: void Push () { scopeStack.push_back ({}); } - std ::map<std::string, AST::Type *> Pop () + std ::map<std::string, T> Pop () { auto toplevel = scopeStack.back (); scopeStack.pop_back (); @@ -48,7 +48,7 @@ public: } private: - std::vector<std::map<std::string, AST::Type *> > scopeStack; + std::vector<std::map<std::string, T> > scopeStack; }; } // namespace Analysis |