Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Remove support for for extension methods at runtime
Browse files Browse the repository at this point in the history
They no longer exist in XP7 as per xp-framework/rfc#298
  • Loading branch information
thekid committed Jan 23, 2016
1 parent 4aa4aba commit bd3ad7c
Show file tree
Hide file tree
Showing 49 changed files with 77 additions and 258 deletions.
9 changes: 9 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ XP Compiler ChangeLog

## ?.?.? / ????-??-??

## 6.0.0 / ????-??-??

* **Heads up**: Removed support for extension methods at runtime. They no
longer exist in XP7 as per xp-framework/rfc#298
(@thekid)
* Fix code to use `nameof()` instead of the deprecated `getClassName()`
method from lang.Generic. See xp-framework/core#120
(@thekid)

## 5.0.1 / 2015-12-20

* Replaced deprecated ensure() with a finally statement, creating forward
Expand Down
12 changes: 6 additions & 6 deletions src/main/php/xp/compiler/CompilationProfile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CompilationProfile extends \lang\Object {
* @return xp.compiler.checks.Check the added check
*/
public function addWarning(Check $check) {
$this->warnings[$check->getClassName()]= $check;
$this->warnings[nameof($check)]= $check;
return $check;
}

Expand All @@ -32,7 +32,7 @@ public function addWarning(Check $check) {
* @return xp.compiler.profiles.CompilationProfile this
*/
public function withWarning(Check $check) {
$this->warnings[$check->getClassName()]= $check;
$this->warnings[nameof($check)]= $check;
return $this;
}

Expand All @@ -43,7 +43,7 @@ public function withWarning(Check $check) {
* @return xp.compiler.checks.Check the added check
*/
public function addError(Check $check) {
$this->errors[$check->getClassName()]= $check;
$this->errors[nameof($check)]= $check;
return $check;
}

Expand All @@ -54,7 +54,7 @@ public function addError(Check $check) {
* @return xp.compiler.profiles.CompilationProfile this
*/
public function withError(Check $check) {
$this->errors[$check->getClassName()]= $check;
$this->errors[nameof($check)]= $check;
return $this;
}

Expand All @@ -65,7 +65,7 @@ public function withError(Check $check) {
* @return xp.compiler.optimize.Optimization the added optimization
*/
public function addOptimization(Optimization $optimization) {
$this->optimizations[$optimization->getClassName()]= $optimization;
$this->optimizations[nameof($optimization)]= $optimization;
return $optimization;
}

Expand All @@ -76,7 +76,7 @@ public function addOptimization(Optimization $optimization) {
* @return xp.compiler.profiles.CompilationProfile this
*/
public function withOptimization(Optimization $optimization) {
$this->optimizations[$optimization->getClassName()]= $optimization;
$this->optimizations[nameof($optimization)]= $optimization;
return $this;
}
}
4 changes: 2 additions & 2 deletions src/main/php/xp/compiler/JitClassLoader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function loadClass0($class) {
// Define type
$this->debug && fputs(STDERR, $r->type()->toString()."\n");
$r->executeWith([]);
\xp::$cl[$class]= $this->getClassName().'://'.$this->instanceId();
\xp::$cl[$class]= nameof($this).'://'.$this->instanceId();
return $r->type()->literal();
}

Expand Down Expand Up @@ -254,6 +254,6 @@ public static function instanceFor($path, $debug= false) {
* @return string
*/
public function toString() {
return $this->getClassName().'<'.implode(', ', $this->files->getSourcePaths()).'>';
return nameof($this).'<'.implode(', ', $this->files->getSourcePaths()).'>';
}
}
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/Syntax.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function parse(InputStream $in, $source= null, $messages= null) {
* @return string
*/
public function toString() {
return $this->getClassName().'('.$this->hashCode().')';
return nameof($this).'('.$this->hashCode().')';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/ast/Node.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function equals($cmp) {
* @return string
*/
public function toString() {
$s= $this->getClassName().'(line '.$this->position[0].', offset '.$this->position[1].")@{\n";
$s= nameof($this).'(line '.$this->position[0].', offset '.$this->position[1].")@{\n";
foreach (get_object_vars($this) as $name => $value) {
'__id' !== $name && 'position' !== $name && 'holder' !== $name && $s.= sprintf(
" [%-20s] %s\n",
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/ast/ParseTree.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function toString() {
" imports : %s\n".
" declaration : %s\n".
"}",
$this->getClassName(),
nameof($this),
$this->package ? $this->package->name : '<main>',
str_replace("\n", "\n ", \xp::stringOf($this->imports)),
str_replace("\n", "\n ", $this->declaration->toString())
Expand Down
1 change: 1 addition & 0 deletions src/main/php/xp/compiler/ast/TypeMemberNode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstract class TypeMemberNode extends Node {
public $name= '';
public $modifiers= 0;
public $annotations= [];
public $comment= null;

/**
* Returns this routine's name
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/ast/Visitor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ protected function visitBracedExpression(BracedExpressionNode $node) {
public function visitOne(Node $node) {
$target= 'visit'.substr(get_class($node), strlen('xp\\compiler\\ast\\'), -strlen('Node'));
if (!method_exists($this, $target)) {
throw new \lang\IllegalArgumentException('Don\'t know how to visit '.$node->getClassName().'s');
throw new \lang\IllegalArgumentException('Don\'t know how to visit '.nameof($node).'s');
}
return call_user_func([$this, $target], $node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/checks/IsAssignable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function isWriteable($node) {
public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope) {
$a= \cast($node, 'xp.compiler.ast.AssignmentNode');
if (!$this->isWriteable($a->variable)) {
return ['A403', 'Cannot assign to '.($a->variable instanceof \lang\Generic ? $a->variable->getClassName() : \xp::stringOf($a->variable)).'s'];
return ['A403', 'Cannot assign to '.($a->variable instanceof \lang\Generic ? nameof($a->variable) : \xp::stringOf($a->variable)).'s'];
}
}
}
4 changes: 2 additions & 2 deletions src/main/php/xp/compiler/emit/Emitter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ protected function emitOne($b, $in) {
$this->cat && $this->cat->debugf(
'@%-3d Emit %s: %s',
$node->position[0],
$node->getClassName(),
nameof($node),
$node->hashCode()
);

Expand All @@ -722,7 +722,7 @@ protected function emitOne($b, $in) {
$node
);
} catch (\lang\Error $e) {
$this->error('0422', 'Cannot emit '.$node->getClassName().': '.$e->getMessage(), $node);
$this->error('0422', 'Cannot emit '.nameof($node).': '.$e->getMessage(), $node);
} catch (\lang\Throwable $e) {
$this->error('0500', $e->toString(), $node);
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/php/xp/compiler/emit/php/Emitter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ protected function emitUnaryOp($b, $un) {
$this->emitOne($b, $un->expression);
return;
} else if (!$this->isWriteable($un->expression)) {
$this->error('U400', 'Cannot perform unary '.$un->op.' on '.$un->expression->getClassName(), $un);
$this->error('U400', 'Cannot perform unary '.$un->op.' on '.nameof($un->expression), $un);
return;
}

Expand Down Expand Up @@ -926,7 +926,7 @@ protected function emitForeach($b, $loop) {
} else {
$ptr= $this->resolveType($t);
if (!$ptr->isEnumerable()) {
$this->warn('T300', 'Type '.$ptr->name().' is not enumerable in loop expression '.$loop->expression->getClassName().'['.$loop->expression->hashCode().']', $loop);
$this->warn('T300', 'Type '.$ptr->name().' is not enumerable in loop expression '.nameof($loop->expression).'['.$loop->expression->hashCode().']', $loop);
$vt= TypeName::$VAR;
$kt= new TypeName('int');
} else {
Expand Down Expand Up @@ -2326,7 +2326,7 @@ protected function emitSilenceOperator($b, $silenced) {
* @param xp.compiler.ast.YieldNode yield
*/
protected function emitYield($b, $yield) {
$this->error('V505', 'Yield not supported in '.$this->getClassName());
$this->error('V505', 'Yield not supported in '.nameof($this));
}

/**
Expand Down Expand Up @@ -2395,6 +2395,8 @@ public function emit(ParseTree $tree, Scope $scope) {
'unset' => true,
'empty' => true,
'eval' => true,
'typeof' => true,
'nameof' => true,
'include' => true,
'require' => true,
'include_once'=> true,
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/xp/compiler/io/CommandLineSource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getURI() {
* @return string
*/
public function toString() {
return $this->getClassName().'(syntax= '.$this->syntax->name().', fragment= `'.$this->fragment.'`)';
return nameof($this).'(syntax= '.$this->syntax->name().', fragment= `'.$this->fragment.'`)';
}

/**
Expand All @@ -91,6 +91,6 @@ public function toString() {
* @return string
*/
public function hashCode() {
return 'C:'.$this->offset;
return 'CLI:'.md5($this->fragment);
}
}
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/io/FileSource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getURI() {
* @return string
*/
public function toString() {
return $this->getClassName().'<'.str_replace(
return nameof($this).'<'.str_replace(
realpath(getcwd()),
'.',
$this->file->getURI()
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/io/StringSource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getURI() {
* @return string
*/
public function toString() {
return $this->getClassName().'<'.$this->name.'>';
return nameof($this).'<'.$this->name.'>';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function isLocal($scope, $type) {
*/
public function inline($call, $scope, $optimizations) {
if (isset($call->inlined)) {
// DEBUG Console::writeLine('**Recursion** Not inlining ', $call->name, ' from inside ', $scope->getClassName().'::'.$scope->name);
// DEBUG Console::writeLine('**Recursion** Not inlining ', $call->name, ' from inside ', nameof($scope).'::'.$scope->name);
return $call;
}

Expand All @@ -86,7 +86,7 @@ public function inline($call, $scope, $optimizations) {
$replacements[$parameter['name']]= $call->arguments[$i];
}

// DEBUG Console::writeLine('Inlining ', $call->name, ' from inside ', $scope->getClassName().'::'.$scope->name);
// DEBUG Console::writeLine('Inlining ', $call->name, ' from inside ', nameof($scope).'::'.$scope->name);
$call= $optimizations->optimize(
self::$rewriter->newInstance($replacements, $call->name)->visitOne(clone $member->body[0]->expression),
$scope
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/xp/compiler/optimize/Optimizations.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function optimize(\xp\compiler\ast\Node $in, \xp\compiler\types\Scope $sc
* @return string
*/
public function toString() {
$s= $this->getClassName().'('.$this->impl->size().")@{\n";
$s= nameof($this).'('.$this->impl->size().")@{\n";
foreach ($this->impl->keys() as $key) {
$s.= sprintf(" [%-20s] %s\n", $key->getSimpleName(), $this->impl->get($key)->getClassName());
$s.= sprintf(" [%-20s] %s\n", $key->getSimpleName(), nameof($this->impl->get($key)));
}
return $s.'}';
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/xp/compiler/task/CompilationTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public function run() {
* @return string
*/
public function toString() {
$s= $this->getClassName().'(source: '.$this->source->toString().")@{\n";
$s= nameof($this).'(source: '.$this->source->toString().")@{\n";
foreach ($this->done->keys() as $key) {
$s.= ' ['.$key->toString().'] '.$this->done[$key]->getClassName().'('.$this->done[$key]->name().")\n";
$s.= ' ['.$key->toString().'] '.nameof($this->done[$key]).'('.$this->done[$key]->name().")\n";
}
return $s.'}';
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/ArrayTypeOf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function genericPlaceholders() {
public function toString() {
return sprintf(
'%s@(%s[]>)',
$this->getClassName(),
nameof($this),
$this->component->name()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* abstract class Command implements Runnable {
*
* public function toString() {
* return $this.getClassName();
* return nameof($this);
* }
* }
* ```
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/CompiledType.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function genericPlaceholders() {
* @return string
*/
public function toString() {
$s= $this->getClassName().'<'.$this->name.">@{\n";
$s= nameof($this).'<'.$this->name.">@{\n";
if ($this->constructor) {
$s.= ' '.$this->constructor->toString()."\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Constant.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function name() {
public function toString() {
return sprintf(
'%s<const %s %s= %s>',
$this->getClassName(),
nameof($this),
$this->type->compoundName(),
$this->name,
\xp::stringOf($this->value)
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Constructor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function toString() {
}
return sprintf(
'%s<%s __construct(%s)>',
$this->getClassName(),
nameof($this),
implode(' ', \lang\reflect\Modifiers::namesOf($this->modifiers)),
substr($signature, 2)
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function name() {
public function toString() {
return sprintf(
'%s<%s %s $%s>',
$this->getClassName(),
nameof($this),
implode(' ', \lang\reflect\Modifiers::namesOf($this->modifiers)),
$this->type->compoundName(),
$this->name
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/FunctionTypeOf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function genericPlaceholders() {
public function toString() {
return sprintf(
'%s@(%s)',
$this->getClassName(),
nameof($this),
$this->name()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/GenericType.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function genericPlaceholders() {
public function toString() {
return sprintf(
'%s@(%s<%s>)',
$this->getClassName(),
nameof($this),
$this->definition->toString(),
implode(', ', array_map(['xp', 'stringOf'], $this->components))
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Indexer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Indexer extends \lang\Object {
public function toString() {
return sprintf(
'%s<%s this[%s]>',
$this->getClassName(),
nameof($this),
$this->type->compoundName(),
$this->parameter->compoundName()
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/MapTypeOf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function genericPlaceholders() {
public function toString() {
return sprintf(
'%s@([:%s]>)',
$this->getClassName(),
nameof($this),
$this->component->name()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Method.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function toString() {
}
return sprintf(
'%s<%s %s %s(%s)>',
$this->getClassName(),
nameof($this),
implode(' ', \lang\reflect\Modifiers::namesOf($this->modifiers)),
$this->returns->compoundName(),
$this->name,
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Operator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function toString() {
}
return sprintf(
'%s<%s %s %s(%s)>',
$this->getClassName(),
nameof($this),
implode(' ', \lang\reflect\Modifiers::namesOf($this->modifiers)),
$this->returns->compoundName(),
$this->symbol,
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/Parameter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function equals($cmp) {
public function toString() {
return sprintf(
'%s<%s %s%s>',
$this->getClassName(),
nameof($this),
$this->type->compoundName(),
$this->name,
$this->default ? '= '.$this->default->hashCode() : ''
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/xp/compiler/types/PrimitiveTypeOf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function genericPlaceholders() {
public function toString() {
return sprintf(
'%s@(%s>)',
$this->getClassName(),
nameof($this),
$this->name
);
}
Expand Down
Loading

0 comments on commit bd3ad7c

Please sign in to comment.