1 // Copyright (c) Facebook, Inc. and its affiliates.
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 crate::{special_class_resolver::SpecialClassResolver, write::newline};
7 use env::emitter::Emitter;
8 use oxidized::relative_path::RelativePath;
9 use std::collections::BTreeMap;
10 use std::io::{Result, Write};
12 /// Indent is an abstraction of indentation. Configurable indentation
13 /// and perf tweaking will be easier.
30 fn write(&self, w: &mut dyn Write) -> Result<()> {
39 pub struct Context<'a> {
40 pub(crate) special_class_resolver: &'a dyn SpecialClassResolver,
41 pub(crate) path: Option<&'a RelativePath>,
43 dump_symbol_refs: bool,
44 pub(crate) dump_lambdas: bool,
48 pub(crate) include_roots: &'a BTreeMap<String, String>,
49 pub(crate) include_search_paths: &'a [String],
50 pub(crate) doc_root: &'a str,
51 pub(crate) array_provenance: bool,
54 impl<'a> Context<'a> {
55 pub fn new<'arena, 'decl>(
56 emitter: &'a Emitter<'arena, 'decl>,
57 path: Option<&'a RelativePath>,
58 dump_symbol_refs: bool,
61 let include_roots = emitter.options().hhvm.include_roots.get();
62 let include_search_paths = emitter.options().server.include_search_paths.get();
63 let doc_root = emitter.options().doc_root.get();
64 let array_provenance = emitter.options().array_provenance();
67 special_class_resolver: emitter,
71 indent: Indent::new(),
81 pub(crate) fn dump_symbol_refs(&self) -> bool {
85 /// Insert a newline with indentation
86 pub(crate) fn newline(&self, w: &mut dyn Write) -> Result<()> {
91 /// Start a new indented block
92 pub(crate) fn block<F>(&self, w: &mut dyn Write, f: F) -> Result<()>
94 F: FnOnce(&Self, &mut dyn Write) -> Result<()>,
96 let mut ctx = self.clone();
101 pub(crate) fn unblock<F>(&self, w: &mut dyn Write, f: F) -> Result<()>
103 F: FnOnce(&Self, &mut dyn Write) -> Result<()>,
105 let mut ctx = self.clone();
110 /// Printing instruction list requies manually control indentation,
111 /// where indent_inc/indent_dec are called
112 pub(crate) fn indent_inc(&mut self) {
116 pub(crate) fn indent_dec(&mut self) {
120 pub(crate) fn is_system_lib(&self) -> bool {