Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / vm / BytecodeIterator.h
blobafc84e0451c024cba0cf8e21067eb9e5a77518c4
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"
12 namespace js {
14 class BytecodeIterator {
15 BytecodeLocation current_;
17 public:
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 &current_; }
36 // Pre-increment
37 BytecodeIterator& operator++() {
38 current_ = current_.next();
39 return *this;
42 // Post-increment
43 BytecodeIterator operator++(int) {
44 BytecodeIterator previous(*this);
45 current_ = current_.next();
46 return previous;
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_;
55 public:
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_;
70 public:
71 explicit BytecodeLocationRange(BytecodeLocation beginLoc,
72 BytecodeLocation endLoc)
73 : beginLoc_(beginLoc), endLoc_(endLoc) {
74 #ifdef DEBUG
75 MOZ_ASSERT(beginLoc.hasSameScript(endLoc));
76 #endif
79 BytecodeIterator begin();
80 BytecodeIterator end();
83 } // namespace js
85 #endif