File: JavaScriptLiteral.php

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (56 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download | duplicates (7)
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
<?php

require_once('Destructable.php');

class JavaScriptLiteral extends Destructable {
  protected $value;

  public function __construct($value) {
    $this->value = $value;
  }

  public function __destruct() {
    $this->mem_flush('value');
  }

  public function value() {
    return $this->value;
  }

  public function type() {
    if (is_object($this->value)) {
      if ($this->value->arity == 'this') {
        return 'Object';
      }
      elseif (strlen($this->value->id) > 1 && in_array($this->value->id{0}, array('!', '=', '<', '>'))) {
        return 'bool';
      }
      elseif (in_array($this->value->id, array('!', '>', '<', '&', '|'))) {
        return 'bool';
      }
      elseif ($this->value->id == '+' && !is_numeric($this->value->second->value)) {
        return 'String';
      }
      elseif (in_array($this->value->id, array('++', '--', '+', '-', '*', '/', '%'))) {
        return 'Number';
      }
      elseif ($this->value->id == '&&' || $this->value->id == '||') {
        $first = $this->value->first;
        if (is_array($first)) {
          $first = $first[0];
        }
        return $first->type();
      }
    }
    elseif (is_null($this->value) || $this->value == 'null') {
      return 'Object';
    }
    elseif (is_bool($this->value)) {
      return 'bool';
    }
    elseif ($this->value == 'arguments') {
      return 'Array';
    }
    throw new Exception("Unstringed literal type: {$this->value}");
  }
}