Port hhbc:label_writer in Emitter
[hiphop-php.git] / hphp / hack / src / hhbc / hhas_param.rs
blob72ea9c2e1c4171172a577c338a4a5abc9de50257
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.
5 #![feature(rustc_private)]
6 use hhas_attribute_rust::HhasAttribute;
7 use hhas_type::{constraint, Info};
8 use label_rust::Label;
9 use tast_rust::TastExpr;
10 extern crate bitflags;
12 #[derive(Clone)]
13 pub struct HhasParam {
14     pub name: String,
15     pub is_reference: bool,
16     pub is_variadic: bool,
17     pub is_inout: bool,
18     pub user_attributes: Vec<HhasAttribute>,
19     pub type_info: Option<Info>,
20     pub default_value: Option<(Label, TastExpr)>,
23 impl HhasParam {
24     pub fn replace_default_value_label(&mut self, new_label: Label) {
25         let old_default_value = std::mem::replace(&mut self.default_value, None);
26         if let Some((_, e)) = old_default_value {
27             self.default_value = Some((new_label, e));
28         }
29     }
31     pub fn without_type(&mut self) {
32         self.type_info.as_mut().map(|ti| {
33             ti.type_constraint = constraint::Type::default();
34         });
35     }
37     pub fn with_name(&mut self, name: String) {
38         self.name = name;
39     }
41     pub fn switch_inout_to_reference(&mut self) {
42         if self.is_inout {
43             self.is_inout = false;
44             self.is_reference = true;
45         }
46     }
48     pub fn switch_reference_to_inout(&mut self) {
49         if self.is_reference {
50             self.is_inout = true;
51             self.is_reference = false;
52         }
53     }