1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Calculation\Token; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet. |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* |
24
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
25
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
26
|
|
|
*/ |
27
|
|
|
class Stack |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* The parser stack for formulae. |
31
|
|
|
* |
32
|
|
|
* @var mixed[] |
33
|
|
|
*/ |
34
|
|
|
private $stack = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Count of entries in the parser stack. |
38
|
|
|
* |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
private $count = 0; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Return the number of entries on the stack. |
45
|
|
|
* |
46
|
|
|
* @return int |
47
|
|
|
*/ |
48
|
95 |
|
public function count() |
49
|
|
|
{ |
50
|
95 |
|
return $this->count; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Push a new entry onto the stack. |
55
|
|
|
* |
56
|
|
|
* @param mixed $type |
57
|
|
|
* @param mixed $value |
58
|
|
|
* @param mixed $reference |
59
|
|
|
*/ |
60
|
95 |
|
public function push($type, $value, $reference = null) |
61
|
|
|
{ |
62
|
95 |
|
$this->stack[$this->count++] = [ |
63
|
95 |
|
'type' => $type, |
64
|
95 |
|
'value' => $value, |
65
|
95 |
|
'reference' => $reference, |
66
|
|
|
]; |
67
|
95 |
|
if ($type == 'Function') { |
68
|
25 |
|
$localeFunction = \PhpOffice\PhpSpreadsheet\Calculation::localeFunc($value); |
69
|
25 |
|
if ($localeFunction != $value) { |
70
|
1 |
|
$this->stack[($this->count - 1)]['localeValue'] = $localeFunction; |
71
|
|
|
} |
72
|
|
|
} |
73
|
95 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Pop the last entry from the stack. |
77
|
|
|
* |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
95 |
|
public function pop() |
81
|
|
|
{ |
82
|
95 |
|
if ($this->count > 0) { |
83
|
95 |
|
return $this->stack[--$this->count]; |
84
|
|
|
} |
85
|
|
|
|
86
|
95 |
|
return null; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Return an entry from the stack without removing it. |
91
|
|
|
* |
92
|
|
|
* @param int $n number indicating how far back in the stack we want to look |
93
|
|
|
* |
94
|
|
|
* @return mixed |
95
|
|
|
*/ |
96
|
95 |
|
public function last($n = 1) |
97
|
|
|
{ |
98
|
95 |
|
if ($this->count - $n < 0) { |
99
|
89 |
|
return null; |
100
|
|
|
} |
101
|
|
|
|
102
|
94 |
|
return $this->stack[$this->count - $n]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Clear the stack. |
107
|
|
|
*/ |
108
|
|
|
public function clear() |
109
|
|
|
{ |
110
|
|
|
$this->stack = []; |
111
|
|
|
$this->count = 0; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|