move make_enum_declaration ShallowClassConst construction into make_enumerator
commit0b4b1c2cb082dbbdf3a58c3fe4ef1719434bb034
authorLucian Wischik <ljw@fb.com>
Thu, 22 Apr 2021 01:13:25 +0000 (21 18:13 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 22 Apr 2021 01:15:41 +0000 (21 18:15 -0700)
tree740372c6b17fb29ead0b17f25fd224fe18abc585
parenta15bbccffa1cabb3723c64b8e64fd430a5acc272
move make_enum_declaration ShallowClassConst construction into make_enumerator

Summary:
My grand unified plan for consts:
1. For legacy enums `make_enum_declaration` "enum E {X=1}" which is build out of `make_enumerator` "X=1", we shall construct a Node::Const(ShallowClassConst) in make_enumerator, and make_enum_declaration will have a ready-made list of ShallowClassConst children.
   * That's what this diff does. Previously, make_enumerator just returned a ListItem leaving make_enum_declaration to do all the conversion
2. For enum-classes `make_enum_class_declaration` "enum class E {int X=1}" which is built out of `make_enum_class_enumerator` "int X=1", we shall construct a Node::Const(ShallowClassConst) in make_enum_class_enumerator, and make_enum_class_declaration will have a ready-made list of ShallowClassConst children
   * it already does. No work needed.
3. For top-level and member consts `make_const_declaration` "const int X=1" which is built out of `make_constant_declarator` "X=1", we shall construct a Node::ConstInitializer(X,1) in make_constant_declarator, and make_const_declaration will either turn it into a ShallowClassConst or a top-level-const depending on the context.
   * it already does. No work needed.

What this diff does: for regular enums, it shifts the work of constructing a ShallowClassConst out of make_enum_declaration into each individual make_enumeration.

Why am I doing this? Because I want to use the "accumulator" trick (next but one diff in the stack) for constants to gather all their references, and this means that make_enumerator and make_enum_class_enumerator and make_constant_declarator must all have a place to stick the references that they gathered. That place will be either Node::Const(ShallowClassConst) or Node::ConstInitializer. The reason I'm writing this diff is because Node::ListItem has no place to store references.

Differential Revision: D27807442

fbshipit-source-id: 38b5c788ad8ae5659f0348871b8e8eebe36e378b
hphp/hack/src/decl/direct_decl_smart_constructors.rs