From 4050f38746420e44e5c590374807d19774972ebe Mon Sep 17 00:00:00 2001 From: James Wu Date: Fri, 1 Sep 2017 13:10:04 -0700 Subject: [PATCH] Use namingGlobal to check for types Summary: This lets us actually check if types are toplevel entities, allowing us to actually create dependencies. Reviewed By: dabek Differential Revision: D5654912 fbshipit-source-id: d1184d39e6517ef70127cbc0e7fb6321451ed7dc --- hphp/hack/src/gen_deps/dependency_visitors.ml | 39 +++++++++++++++++---------- hphp/hack/test/gen_deps/test_class.php.exp | 20 +++++--------- hphp/hack/test/gen_deps/test_tconst.php | 11 ++++++++ hphp/hack/test/gen_deps/test_tconst.php.exp | 2 ++ 4 files changed, 45 insertions(+), 27 deletions(-) rewrite hphp/hack/test/gen_deps/test_class.php.exp (97%) create mode 100644 hphp/hack/test/gen_deps/test_tconst.php create mode 100644 hphp/hack/test/gen_deps/test_tconst.php.exp diff --git a/hphp/hack/src/gen_deps/dependency_visitors.ml b/hphp/hack/src/gen_deps/dependency_visitors.ml index ca7d583f99a..8ad0495df04 100644 --- a/hphp/hack/src/gen_deps/dependency_visitors.ml +++ b/hphp/hack/src/gen_deps/dependency_visitors.ml @@ -8,11 +8,10 @@ * *) - (* This file defines a visitor on the AST which calculates dependencies - * between toplevel entities in Hack. It grabs toplevel entities from the - * global naming table and adds the corresponding dependencies. - *) -open Utils +(* This file defines a visitor on the AST which calculates dependencies + * between toplevel entities in Hack. It grabs toplevel entities from the + * global naming table and adds the corresponding dependencies. + *) open Ast @@ -37,12 +36,28 @@ let default_env popt = { } let toplevel_to_string = function -| Class s -> "class "^(strip_ns s) -| Function f -> "function "^(strip_ns f) -| Typedef t -> "typedef "^(strip_ns t) -| Const c -> "const "^(strip_ns c) +| Class s -> "class "^s +| Function f -> "function "^f +| Typedef t -> "typedef "^t +| Const c -> "const "^c | Other -> "*UNKNOWN*" +let add_dep popt toplevel ty_name = + (* XXX: Need to elaborate namespaces here *) + let ty_name = "\\"^ty_name in + match NamingGlobal.GEnv.type_info popt ty_name with + | Some (_, `Class) -> + let name = Class ty_name in + Printf.printf "%s -> %s\n" + (toplevel_to_string toplevel) + (toplevel_to_string name) + | Some (_, `Typedef) -> + let name = Typedef ty_name in + Printf.printf "%s -> %s\n" + (toplevel_to_string toplevel) + (toplevel_to_string name) + | None -> () + class dependency_visitor = object inherit [_] Ast_visitors_iter.iter as super @@ -81,11 +96,7 @@ class dependency_visitor = object | Happly ((_, ty_name), _) (* Only care about the base class's name *) | Haccess ((_, ty_name), _, _) -> - (* For now, just print out any types we find. We'll add deps later *) - let top_ent = toplevel_to_string dep_env.top in - let pos = Pos.string (Pos.to_absolute (fst hint)) in - Printf.printf "In %s, %s \n" top_ent pos; - Printf.printf "Found type: %s\n" ty_name + add_dep dep_env.popt dep_env.top ty_name (* No need to recurse here, since the parent class does it for us *) | Hshape _ | Hoption _ diff --git a/hphp/hack/test/gen_deps/test_class.php.exp b/hphp/hack/test/gen_deps/test_class.php.exp dissimilarity index 97% index 992a3bd5239..81507eb9c43 100644 --- a/hphp/hack/test/gen_deps/test_class.php.exp +++ b/hphp/hack/test/gen_deps/test_class.php.exp @@ -1,13 +1,7 @@ -test_class.php -In class A, File "test_class.php", line 10, characters 34-34: -Found type: B -In function hint_on_shape, File "test_class.php", line 17, characters 40-40: -Found type: B -In function optional_hint, File "test_class.php", line 21, characters 28-28: -Found type: B -In function function_hint, File "test_class.php", line 25, characters 37-37: -Found type: B -In function function_hint, File "test_class.php", line 25, characters 39-39: -Found type: A -In function function_hint, File "test_class.php", line 25, characters 42-42: -Found type: C +test_class.php +class \A -> class \B +function \hint_on_shape -> class \B +function \optional_hint -> class \B +function \function_hint -> class \B +function \function_hint -> class \A +function \function_hint -> class \C diff --git a/hphp/hack/test/gen_deps/test_tconst.php b/hphp/hack/test/gen_deps/test_tconst.php new file mode 100644 index 00000000000..0f754ec3121 --- /dev/null +++ b/hphp/hack/test/gen_deps/test_tconst.php @@ -0,0 +1,11 @@ + class \B -- 2.11.4.GIT