mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
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
(dafff2cc18/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
<?php
class :bunny:hop-hop-hop extends ❌element {
protected function render() {
return <p>bunny goes hop hop hop</p>;
}
}
Ran phutil_mapper.php and generated __phutil_library_map__.php:
<?php
/**
* This file is automatically generated. Use 'phutil_mapper.php' to rebuild i\
t.
* @generated
*/
phutil_register_library_map(array(
'class' =>
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
This commit is contained in:
parent
b3a9ee3d84
commit
eb98ab553e
1 changed files with 12 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue