#ifndef V8_INTERPRETER_BYTECODE_SOURCE_INFO_H_
#define V8_INTERPRETER_BYTECODE_SOURCE_INFO_H_
#include "src/common/globals.h"
namespace v8 {
namespace internal {
namespace interpreter {
class BytecodeSourceInfo final {
public:
static const int kUninitializedPosition = -1;
BytecodeSourceInfo()
: position_type_(PositionType::kNone),
source_position_(kUninitializedPosition),
is_breakable_(true) {}
BytecodeSourceInfo(int source_position, bool is_statement,
bool is_breakable = true)
: position_type_(is_statement ? PositionType::kStatement
: PositionType::kExpression),
source_position_(source_position),
is_breakable_(is_breakable) {
DCHECK_GE(source_position, 0);
}
void MakeStatementPosition(int source_position, bool is_breakable = true) {
position_type_ = PositionType::kStatement;
source_position_ = source_position;
is_breakable_ = is_breakable;
}
void MakeExpressionPosition(int source_position) {
DCHECK(!is_statement());
position_type_ = PositionType::kExpression;
source_position_ = source_position;
is_breakable_ = true;
}
void ForceExpressionPosition(int source_position) {
position_type_ = PositionType::kExpression;
source_position_ = source_position;
}
int source_position() const {
DCHECK(is_valid());
return source_position_;
}
bool is_statement() const {
return position_type_ == PositionType::kStatement;
}
bool is_expression() const {
return position_type_ == PositionType::kExpression;
}
bool is_valid() const { return position_type_ != PositionType::kNone; }
void set_invalid() {
position_type_ = PositionType::kNone;
source_position_ = kUninitializedPosition;
}
bool is_breakable() const { return is_breakable_; }
bool operator==(const BytecodeSourceInfo& other) const {
return position_type_ == other.position_type_ &&
source_position_ == other.source_position_;
}
bool operator!=(const BytecodeSourceInfo& other) const {
return position_type_ != other.position_type_ ||
source_position_ != other.source_position_;
}
private:
enum class PositionType : uint8_t { kNone, kExpression, kStatement };
PositionType position_type_;
int source_position_;
bool is_breakable_;
};
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
const BytecodeSourceInfo& info);
}
}
}
#endif