port print utils + refactoring
Summary:
- Aast shapes are printed as darray, in Ocaml new darrays are created from shape key and values. However, creating aast nodes implies extra allocation cost and hurts perf. Darray printing logic are factored out into more abstract implementation, which can be applied to both darray and shape without creating aast node.
- Introduced `then_write(cond: bool, str: AsRef<str>) -> Result<(), Error>` to make printing logic more concise and improve readability. Not all `if ... { w.write(...) }` changed to `then_write`, I prefer doing this kind refactoring in a separate diff, which is easy to show no regression.
- ported `SSwitch` printing with new slice pattern, I like it very much!
Differential Revision:
D20690069
fbshipit-source-id:
0c5e82204c13916f9f0d8d15b1fb47ea0cd15caa