Tweak `HhasTypeConstant` C++: Replace Option with Maybe
[hiphop-php.git] / hphp / hack / src / hhbc / hhbc_by_ref / emit_fatal.rs
blobf1b690d764b23adffe542e364a03c1b36a77c243
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 use hhbc_by_ref_emit_pos::emit_pos;
7 use hhbc_by_ref_hhbc_ast::FatalOp;
8 use hhbc_by_ref_instruction_sequence::{instr, Error, InstrSeq};
9 use oxidized::pos::Pos;
11 pub fn raise_fatal_runtime(pos: &Pos, msg: impl Into<String>) -> Error {
12     Error::IncludeTimeFatalException(FatalOp::Runtime, pos.clone(), msg.into())
15 pub fn raise_fatal_parse(pos: &Pos, msg: impl Into<String>) -> Error {
16     Error::IncludeTimeFatalException(FatalOp::Parse, pos.clone(), msg.into())
19 pub fn emit_fatal<'arena>(
20     alloc: &'arena bumpalo::Bump,
21     op: FatalOp,
22     pos: &Pos,
23     msg: impl AsRef<str>,
24 ) -> InstrSeq<'arena> {
25     InstrSeq::gather(
26         alloc,
27         vec![
28             emit_pos(alloc, pos),
29             instr::string(alloc, msg.as_ref()),
30             instr::fatal(alloc, op),
31         ],
32     )
35 pub fn emit_fatal_runtime<'arena>(
36     alloc: &'arena bumpalo::Bump,
37     pos: &Pos,
38     msg: impl AsRef<str>,
39 ) -> InstrSeq<'arena> {
40     emit_fatal(alloc, FatalOp::Runtime, pos, msg)
43 pub fn emit_fatal_runtimeomitframe<'arena>(
44     alloc: &'arena bumpalo::Bump,
45     pos: &Pos,
46     msg: impl AsRef<str>,
47 ) -> InstrSeq<'arena> {
48     emit_fatal(alloc, FatalOp::RuntimeOmitFrame, pos, msg)
51 pub fn emit_fatal_for_break_continue<'arena>(
52     alloc: &'arena bumpalo::Bump,
53     pos: &Pos,
54     level: usize,
55 ) -> InstrSeq<'arena> {
56     let suffix = if level == 1 { "" } else { "s" };
57     let msg = format!("Cannot break/continue {} level{}", level, suffix);
58     emit_fatal_runtime(alloc, pos, msg)