diff --git a/include/scope.hpp b/include/scope.hpp index e803d8e2..536e9a32 100644 --- a/include/scope.hpp +++ b/include/scope.hpp @@ -113,9 +113,10 @@ class ScopeStack { /// @param table The class member pointer to the table to add the entry. /// @return The added entry if the `id` of the `entry` isn't already in such /// scope; otherwise, the original entry. - template - std::shared_ptr AddEntry_(std::unique_ptr entry, ScopeKind kind, - std::unique_ptr Scope::*table); + template + std::shared_ptr AddEntry_( + std::unique_ptr entry, ScopeKind kind, + std::unique_ptr> Scope::*table); /// @brief Looks up the `id` from through all scopes. /// @tparam Table The type of the table to look up from the scope. @@ -124,9 +125,10 @@ class ScopeStack { /// scope. /// @return The entry with the `id` if it exists; otherwise, `nullptr`. /// @throws `NotInScopeError` - template + template std::shared_ptr LookUpEntry_( - const std::string& id, std::unique_ptr
Scope::*table) const; + const std::string& id, + std::unique_ptr> Scope::*table) const; /// @brief Probes the `id` from the top-most scope. /// @tparam Table The type of the table to probe from the scope. @@ -135,9 +137,10 @@ class ScopeStack { /// scope. /// @return The entry with the `id` if it exists; otherwise, `nullptr`. /// @throws `NotInScopeError` - template + template std::shared_ptr ProbeEntry_( - const std::string& id, std::unique_ptr
Scope::*table) const; + const std::string& id, + std::unique_ptr> Scope::*table) const; }; #endif // SCOPE_HPP_ diff --git a/src/scope.cpp b/src/scope.cpp index 2e83cf8d..a9404e08 100644 --- a/src/scope.cpp +++ b/src/scope.cpp @@ -31,10 +31,10 @@ void ScopeStack::MergeWithNextScope() { should_merge_with_next_scope_ = true; } -template +template std::shared_ptr ScopeStack::AddEntry_( std::unique_ptr entry, ScopeKind kind, - std::unique_ptr
Scope::*table) { + std::unique_ptr> Scope::*table) { ThrowIfNotInScope_(); for (auto it = scopes_.rbegin(); it != scopes_.rend(); ++it) { if (it->kind == kind) { @@ -44,9 +44,10 @@ std::shared_ptr ScopeStack::AddEntry_( throw NotInSuchKindOfScopeError{""}; } -template +template std::shared_ptr ScopeStack::LookUpEntry_( - const std::string& id, std::unique_ptr
Scope::*table) const { + const std::string& id, + std::unique_ptr> Scope::*table) const { ThrowIfNotInScope_(); // Iterates backward since we're using the container as a stack. for (auto it = scopes_.crbegin(); it != scopes_.crend(); ++it) { @@ -57,63 +58,38 @@ std::shared_ptr ScopeStack::LookUpEntry_( return nullptr; } -template +template std::shared_ptr ScopeStack::ProbeEntry_( - const std::string& id, std::unique_ptr
Scope::*table) const { + const std::string& id, + std::unique_ptr> Scope::*table) const { ThrowIfNotInScope_(); return (scopes_.back().*table)->Probe(id); } std::shared_ptr ScopeStack::AddSymbol( std::unique_ptr entry, ScopeKind kind) { - return AddEntry_(std::move(entry), kind, - &Scope::symbol_table); + return AddEntry_(std::move(entry), kind, &Scope::symbol_table); } std::shared_ptr ScopeStack::LookUpSymbol( const std::string& id) const { - return LookUpEntry_(id, &Scope::symbol_table); + return LookUpEntry_(id, &Scope::symbol_table); } std::shared_ptr ScopeStack::ProbeSymbol( const std::string& id) const { - return ProbeEntry_(id, &Scope::symbol_table); + return ProbeEntry_(id, &Scope::symbol_table); } std::shared_ptr ScopeStack::AddType(std::unique_ptr entry, ScopeKind kind) { - return AddEntry_(std::move(entry), kind, - &Scope::type_table); + return AddEntry_(std::move(entry), kind, &Scope::type_table); } std::shared_ptr ScopeStack::LookUpType(const std::string& id) const { - return LookUpEntry_(id, &Scope::type_table); + return LookUpEntry_(id, &Scope::type_table); } std::shared_ptr ScopeStack::ProbeType(const std::string& id) const { - return ProbeEntry_(id, &Scope::type_table); + return ProbeEntry_(id, &Scope::type_table); } - -// Explicit template instantiation for the member functions used by ScopeStack -template std::shared_ptr ScopeStack::AddEntry_< - SymbolTable, SymbolEntry>(std::unique_ptr, ScopeKind, - std::unique_ptr Scope::*); - -template std::shared_ptr ScopeStack::AddEntry_( - std::unique_ptr, ScopeKind, std::unique_ptr Scope::*); - -template std::shared_ptr -ScopeStack::LookUpEntry_( - const std::string&, std::unique_ptr Scope::*) const; - -template std::shared_ptr -ScopeStack::LookUpEntry_( - const std::string&, std::unique_ptr Scope::*) const; - -template std::shared_ptr -ScopeStack::ProbeEntry_( - const std::string&, std::unique_ptr Scope::*) const; - -template std::shared_ptr -ScopeStack::ProbeEntry_( - const std::string&, std::unique_ptr Scope::*) const;