|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Richard Klees <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This software is licensed under The MIT License. You should have received |
|
8
|
|
|
* a copy of the license along with the code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\Variables; |
|
12
|
|
|
|
|
13
|
|
|
use Lechimp\Dicto\Definition as Def; |
|
14
|
|
|
use Lechimp\Dicto\Graph\Predicate; |
|
15
|
|
|
use Lechimp\Dicto\Graph\PredicateFactory; |
|
16
|
|
|
|
|
17
|
|
|
abstract class Variable extends Def\Definition { |
|
18
|
|
|
// TODO: Use these in Graph/IndexDB. |
|
19
|
|
|
const CLASS_TYPE = "class"; |
|
20
|
|
|
const INTERFACE_TYPE = "interface"; |
|
21
|
|
|
const FILE_TYPE = "file"; |
|
22
|
|
|
const GLOBAL_TYPE = "global"; |
|
23
|
|
|
const FUNCTION_TYPE = "function"; |
|
24
|
|
|
const METHOD_TYPE = "method"; |
|
25
|
|
|
const LANGUAGE_CONSTRUCT_TYPE = "language construct"; |
|
26
|
|
|
|
|
27
|
43 |
|
static public function is_type($t) { |
|
|
|
|
|
|
28
|
|
|
static $types = array |
|
29
|
|
|
( "class" |
|
30
|
|
|
, "interface" |
|
31
|
|
|
, "file" |
|
32
|
|
|
, "global" |
|
33
|
|
|
, "function" |
|
34
|
|
|
, "method" |
|
35
|
|
|
, "language construct" |
|
36
|
43 |
|
); |
|
37
|
43 |
|
return in_array($t, $types); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string|null |
|
42
|
|
|
*/ |
|
43
|
|
|
private $name; |
|
44
|
|
|
|
|
45
|
94 |
|
public function __construct($name = null) { |
|
46
|
94 |
|
assert('is_string($name) || ($name === null)'); |
|
47
|
94 |
|
$this->name = $name; |
|
48
|
94 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return string|null |
|
52
|
|
|
*/ |
|
53
|
301 |
|
public function name() { |
|
54
|
301 |
|
return $this->name; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $name |
|
59
|
|
|
* @return self |
|
60
|
|
|
*/ |
|
61
|
37 |
|
public function withName($name) { |
|
62
|
37 |
|
assert('is_string($name)'); |
|
63
|
37 |
|
$clone = clone $this; |
|
64
|
37 |
|
$clone->name = $name; |
|
65
|
37 |
|
return $clone; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the meaning of the variable. |
|
70
|
|
|
* |
|
71
|
|
|
* In opposite to name, this gives insight in the structure of this variable. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
abstract public function meaning(); |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Compile the variable to a predicate on a graph node. |
|
79
|
|
|
* |
|
80
|
|
|
* @return PredicateFactory $f |
|
81
|
|
|
* @return Predicate |
|
82
|
|
|
*/ |
|
83
|
|
|
abstract public function compile(PredicateFactory $f); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|