| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2024, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/RefCounted.h>
 | 
					
						
							|  |  |  | #include <LibJS/Bytecode/Operand.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-19 10:41:08 -07:00
										 |  |  | class ScopedOperandImpl : public RefCounted<ScopedOperandImpl> { | 
					
						
							| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     ScopedOperandImpl(Generator& generator, Operand operand) | 
					
						
							|  |  |  |         : m_generator(generator) | 
					
						
							|  |  |  |         , m_operand(operand) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~ScopedOperandImpl(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 10:19:28 +02:00
										 |  |  |     [[nodiscard]] Operand const& operand() const { return m_operand; } | 
					
						
							|  |  |  |     [[nodiscard]] Operand& operand() { return m_operand; } | 
					
						
							| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     Generator& m_generator; | 
					
						
							|  |  |  |     Operand m_operand; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-19 10:41:08 -07:00
										 |  |  | class ScopedOperand { | 
					
						
							| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     explicit ScopedOperand(Generator& generator, Operand operand) | 
					
						
							|  |  |  |         : m_impl(adopt_ref(*new ScopedOperandImpl(generator, operand))) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-01 10:19:28 +02:00
										 |  |  |     [[nodiscard]] Operand const& operand() const { return m_impl->operand(); } | 
					
						
							|  |  |  |     [[nodiscard]] Operand& operand() { return m_impl->operand(); } | 
					
						
							| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  |     operator Operand() const { return operand(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] bool operator==(ScopedOperand const& other) const { return operand() == other.operand(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-09 15:13:31 +02:00
										 |  |  |     [[nodiscard]] size_t ref_count() const { return m_impl->ref_count(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-07 21:36:56 +02:00
										 |  |  | private: | 
					
						
							|  |  |  |     NonnullRefPtr<ScopedOperandImpl> m_impl; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |