From fd7c2e6d3d2ff80c4a441a7d22c7b8926c951aec Mon Sep 17 00:00:00 2001 From: Alma Thaler Date: Tue, 19 Jul 2022 10:55:23 -0700 Subject: [PATCH] .module_use. 14057/14144 Summary: Added support for `.module_use` top-level identifier. Can now assemble 14057/14144 of tests in `hphp/test` and an example file that now passes is `hphp/test/slow/modules/reflection-3.php` Reviewed By: aorenste Differential Revision: D37945299 fbshipit-source-id: 7cbe5368a29b0b7df530e95fb67998c2d2a82b6e --- hphp/hack/src/hackc/hackc/assemble.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hphp/hack/src/hackc/hackc/assemble.rs b/hphp/hack/src/hackc/hackc/assemble.rs index 81caaab9833..d6ad4976e5a 100644 --- a/hphp/hack/src/hackc/hackc/assemble.rs +++ b/hphp/hack/src/hackc/hackc/assemble.rs @@ -140,6 +140,7 @@ fn assemble_from_toks<'arena>( let mut type_constants = Vec::new(); // Should be empty let mut fatal = None; let mut file_attributes = Vec::new(); + let mut module_use = Maybe::Nothing; // First non-comment token should be the filepath let fp = assemble_filepath(token_iter)?; while token_iter.peek().is_some() { @@ -204,6 +205,8 @@ fn assemble_from_toks<'arena>( } } else if token_iter.peek_if_str(Token::is_decl, ".file_attributes") { assemble_file_attributes(alloc, token_iter, &mut file_attributes)?; + } else if token_iter.peek_if_str(Token::is_decl, ".module_use") { + module_use = Maybe::Just(assemble_module_use(alloc, token_iter)?); } else { bail!( "Unknown top level identifier: {}", @@ -218,7 +221,7 @@ fn assemble_from_toks<'arena>( typedefs: Slice::fill_iter(alloc, typedefs.into_iter()), file_attributes: Slice::fill_iter(alloc, file_attributes.into_iter()), modules: Default::default(), - module_use: Maybe::Nothing, + module_use, symbol_refs: hhbc::hhas_symbol_refs::HhasSymbolRefs { functions: func_refs.unwrap_or_default(), classes: class_refs.unwrap_or_default(), @@ -231,6 +234,22 @@ fn assemble_from_toks<'arena>( Ok((hcu, fp)) } + +/// Ex: +/// .module_use "(module_use)"; +fn assemble_module_use<'arena>( + alloc: &'arena Bump, + token_iter: &mut Lexer<'_>, +) -> Result> { + token_iter.expect_is_str(Token::into_decl, ".module_use")?; + let st = Str::new_slice( + alloc, + escaper::unquote_slice(token_iter.expect(Token::into_str_literal)?), + ); + token_iter.expect(Token::into_semicolon)?; + Ok(st) +} + /// Ex: /// .file_attributes ["__EnableUnstableFeatures"("""v:1:{s:8:\"readonly\";}""")] ; fn assemble_file_attributes<'arena>( -- 2.11.4.GIT