From eb98ab553e86854bb892465d826516a5246b6ba4 Mon Sep 17 00:00:00 2001 From: James Ide Date: Sat, 23 Jul 2011 16:48:21 -0700 Subject: [PATCH] Munge XHP class names when generating phutil dependency maps Summary: When phutil_analyzer builds the dependency graph I convert all class names w.r.t XHP's internal naming scheme. It actually wouldn't be a terrible idea to do this munging when phutil loads the symbols. I guess it doesn't really matter at the moment since only Arcanist generates phutil maps and only libphutil reads them, but it'd be nice to do this munging in as few places as possible in the future. The XHP grammar does not allow elements to be interfaces (https://github.com/facebook/xhp/blob/dafff2cc1844d1138c3388509c9560b87167a3bb/xhp/parser.y#L1688) so I've only applied this to classes. Test Plan: Created a sample project: ./__phutil_library_init__.php hopping/__init__.php /hophophop.php where that last file contains bunny goes hop hop hop

; } } Ran phutil_mapper.php and generated __phutil_library_map__.php: array( 'xhp_bunny__hop_hop_hop' => 'hopping', ), 'function' => array( ), 'requires_class' => array( 'xhp_bunny__hop_hop_hop' => 'xhp_x__element', ), 'requires_interface' => array( ), )); Reviewed By: epriestley Reviewers: epriestley Commenters: aran CC: aran, ide, epriestley Differential Revision: 715 --- src/parser/phutilmodule/PhutilModuleRequirements.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/parser/phutilmodule/PhutilModuleRequirements.php b/src/parser/phutilmodule/PhutilModuleRequirements.php index f6bbcbb7..779b0179 100644 --- a/src/parser/phutilmodule/PhutilModuleRequirements.php +++ b/src/parser/phutilmodule/PhutilModuleRequirements.php @@ -65,6 +65,7 @@ class PhutilModuleRequirements { } public function addClassDeclaration(XHPASTNode $where, $name) { + $name = self::mungeXHPClassName($name); return $this->addDeclaration('class', $where, $name); } @@ -98,8 +99,10 @@ class PhutilModuleRequirements { } public function addClassDependency($child, XHPASTNode $where, $name) { + $name = self::mungeXHPClassName($name); if ($child !== null) { if (empty($this->builtins['class'][$name])) { + $child = self::mungeXHPClassName($child); $this->chain['class'][$child] = $name; } } @@ -173,4 +176,13 @@ class PhutilModuleRequirements { 'messages' => $this->messages, ); } + + private static function mungeXHPClassName($name) { + if (strlen($name) && $name[0] == ':') { + // XHP's semantic actions munge element names without a preceding colon. + $name = substr($name, 1); + return 'xhp_'.str_replace(array(':', '-'), array('__', '_'), $name); + } + return $name; + } }