1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
<?php
require_once('JavaScriptStatements.php');
require_once('JavaScriptArray.php');
require_once('Destructable.php');
class JavaScriptFunctionCall extends Destructable {
protected $call;
protected $args;
protected $assignment;
protected $resolved_args;
protected $name;
protected $global_scope;
public function __construct($call, $args, $instantiated = FALSE) {
$this->call = $call;
$this->args = $args;
}
public function __destruct() {
$this->mem_flush('call', 'args', 'assignment', 'resolved_args', 'name', 'global_scope');
}
private function resolve() {
if (!$this->call->is_lookup()) {
$this->global_scope = FALSE;
$this->name = NULL;
}
else {
list ($this->global_scope, $this->name) = $this->call->resolve();
}
}
public function name() {
if (!isset($this->name)) {
$this->resolve();
}
return $this->name;
}
public function setAssignment($assignment) {
$this->assignment = $assignment;
}
public function assignment() {
if ($this->assignment) {
if ($this->assignment->is_lookup()) {
list(, $assignment) = $this->assignment->resolve();
return $assignment;
}
}
return NULL;
}
public function is_global () {
if (!isset($this->global_scope)) {
$this->resolve();
}
return !!$this->global_scope;
}
public function type() {
// TODO: Try to resolve return type
return 'Object';
}
public function arguments() {
if (isset($this->resolved_args)) {
return $this->resolved_args;
}
return ($this->resolved_args = new JavaScriptArray($this->args));
}
}
|