1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef vm_BytecodeIterator_h
8 #define vm_BytecodeIterator_h
10 #include "vm/BytecodeLocation.h"
14 class BytecodeIterator
{
15 BytecodeLocation current_
;
18 inline explicit BytecodeIterator(const JSScript
* script
);
20 explicit BytecodeIterator(BytecodeLocation loc
) : current_(loc
) {}
22 BytecodeIterator
& operator=(const BytecodeIterator
&) = default;
24 bool operator==(const BytecodeIterator
& other
) const {
25 return other
.current_
== current_
;
28 bool operator!=(const BytecodeIterator
& other
) const {
29 return !(other
.current_
== current_
);
32 const BytecodeLocation
& operator*() const { return current_
; }
34 const BytecodeLocation
* operator->() const { return ¤t_
; }
37 BytecodeIterator
& operator++() {
38 current_
= current_
.next();
43 BytecodeIterator
operator++(int) {
44 BytecodeIterator
previous(*this);
45 current_
= current_
.next();
50 // Given a JSScript, allow the construction of a range based for-loop
51 // that will visit all script locations in that script.
52 class AllBytecodesIterable
{
53 const JSScript
* script_
;
56 explicit AllBytecodesIterable(const JSScript
* script
) : script_(script
) {}
58 BytecodeIterator
begin();
59 BytecodeIterator
end();
62 // Construct a range based iterator that will visit all bytecode locations
63 // between two given bytecode locations.
64 // `beginLoc_` is the bytecode location where the iterator will start, and
65 // `endLoc_` is the bytecode location where the iterator will end.
66 class BytecodeLocationRange
{
67 BytecodeLocation beginLoc_
;
68 BytecodeLocation endLoc_
;
71 explicit BytecodeLocationRange(BytecodeLocation beginLoc
,
72 BytecodeLocation endLoc
)
73 : beginLoc_(beginLoc
), endLoc_(endLoc
) {
75 MOZ_ASSERT(beginLoc
.hasSameScript(endLoc
));
79 BytecodeIterator
begin();
80 BytecodeIterator
end();