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\Graph\Node; |
14
|
|
|
|
15
|
|
|
// TODO: Maybe this should not extend Entities |
16
|
|
|
class LanguageConstruct extends Entities { |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $construct_name; |
21
|
|
|
|
22
|
38 |
|
public function __construct($construct_name, $name = null) { |
23
|
38 |
|
parent::__construct($name); |
24
|
38 |
|
assert('is_string($construct_name)'); |
25
|
|
|
// TODO: Restrict the possible construct_names (like @, unset, echo, ...) |
|
|
|
|
26
|
38 |
|
$this->construct_name = $construct_name; |
27
|
38 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
35 |
|
public function construct_name() { |
33
|
35 |
|
return $this->construct_name; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
*/ |
39
|
33 |
|
public function meaning() { |
40
|
33 |
|
return $this->construct_name(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritdoc |
45
|
|
|
*/ |
46
|
1 |
|
public function id() { |
47
|
1 |
|
return Variable::LANGUAGE_CONSTRUCT_TYPE; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdocs |
52
|
|
|
*/ |
53
|
4 |
|
public function compile($negate = false) { |
54
|
4 |
|
if (!$negate) { |
55
|
|
|
return function(Node $n) { |
56
|
4 |
|
return $n->type() == Variable::LANGUAGE_CONSTRUCT_TYPE |
57
|
4 |
|
&& $n->property("name") == $this->construct_name(); |
58
|
4 |
|
}; |
59
|
|
|
} |
60
|
|
|
else { |
61
|
|
|
return function(Node $n) { |
62
|
|
|
return $n->type() != Variable::LANGUAGE_CONSTRUCT_TYPE |
63
|
|
|
|| $n->property("name") != $this->construct_name(); |
64
|
|
|
}; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.