| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <cstdint> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | #include <util/DeferredLogic.h> | ||
| 9 | |||
| 10 | namespace spice::compiler { | ||
| 11 | |||
| 12 | // Forward declarations | ||
| 13 | class CompilerPass; | ||
| 14 | class IRGenerator; | ||
| 15 | class Scope; | ||
| 16 | enum class ScopeType : uint8_t; | ||
| 17 | class ASTNode; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * This class is used to change the current scope to a child scope and change it back to the parent scope when the handle object | ||
| 21 | * is destroyed. This can be used in visit functions to automatically leave the scope when the function returns. | ||
| 22 | */ | ||
| 23 | class ScopeHandle : DeferredLogic { | ||
| 24 | public: | ||
| 25 | // Constructors | ||
| 26 | ScopeHandle(CompilerPass *pass, Scope *childScope, const ScopeType &scopeType); | ||
| 27 | ScopeHandle(CompilerPass *pass, const std::string &childScopeId, const ScopeType &scopeType); | ||
| 28 | ScopeHandle(IRGenerator *generator, Scope *childScope, const ScopeType &scopeType, const ASTNode *node); | ||
| 29 | ScopeHandle(IRGenerator *generator, const std::string &childScopeId, const ScopeType &scopeType, const ASTNode *node); | ||
| 30 | |||
| 31 | // Public methods | ||
| 32 | 8320 | void leaveScopeEarly() { execute(); } | |
| 33 | }; | ||
| 34 | |||
| 35 | } // namespace spice::compiler | ||
| 36 |