Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Praspel\Model\Declaration Class Reference
Inheritance diagram for Hoa\Praspel\Model\Declaration:

Public Member Functions

 offsetExists ($offset)
 
 offsetGet ($offset)
 
 getVariable ($name, $borrowing=false)
 
 addVariable ($name, Variable $variable)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 __get ($name)
 
 getIterator ()
 
 count ()
 
getLocalVariables ()
 
 getInScopeVariables ()
 
 predicate ($predicate)
 
 getPredicates ()
 
- Public Member Functions inherited from Hoa\Praspel\Model\Clause
 __construct (Clause $parent)
 
 getParent ()
 
 getRoot ()
 
 getName ()
 
 getId ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Protected Attributes

 $_variables = []
 
 $_predicates = []
 
 $_let = false
 
- Protected Attributes inherited from Hoa\Praspel\Model\Clause
 $_parent = null
 

Additional Inherited Members

- Protected Member Functions inherited from Hoa\Praspel\Model\Clause
 setParent (Clause $parent)
 
 _getId ()
 

Detailed Description

Class .

Represent a declaration.

Definition at line 51 of file Declaration.php.

Member Function Documentation

Hoa\Praspel\Model\Declaration::__get (   $name)

Allow to write $clause->let['var'] = … to define a local variable (if $name is not equal to "let", then it is a normal behavior).

Parameters
string$nameName.
Returns

Definition at line 188 of file Declaration.php.

189  {
190  if ('let' !== $name) {
191  return $this->$name;
192  }
193 
194  $this->_let = true;
195 
196  return $this;
197  }
Hoa\Praspel\Model\Declaration::addVariable (   $name,
Variable  $variable 
)

Add a variable.

Parameters
string$nameName.
\Hoa\Praspel\Model\Variable$variableVariable.
Returns

Definition at line 147 of file Declaration.php.

148  {
149  return $this->_variables[$name] = $variable;
150  }
Hoa\Praspel\Model\Declaration::count ( )

Count number of variables.

Returns
int

Definition at line 219 of file Declaration.php.

220  {
221  return count($this->_variables);
222  }
Hoa\Praspel\Model\Declaration::getInScopeVariables ( )

Get in-scope variables.

Returns
array

Definition at line 239 of file Declaration.php.

240  {
241  $out = [];
242  $clause = $this->getName();
243  $current = $this;
244 
245  while (null !== $current = $current->getParent()) {
246  if (false === $current->clauseExists($clause)) {
247  continue;
248  }
249 
250  $localVariables = &$current->getClause($clause)->getLocalVariables();
251 
252  foreach ($localVariables as $name => &$variables) {
253  $out[$name] = &$variables;
254  }
255  }
256 
257  return $out;
258  }

Here is the call graph for this function:

Hoa\Praspel\Model\Declaration::getIterator ( )

Iterator over local variables.

Returns

Definition at line 204 of file Declaration.php.

205  {
206  return new Iterator\CallbackFilter(
207  new Iterator\Map($this->getLocalVariables()),
208  function (Variable $variable) {
209  return false === $variable->isLocal();
210  }
211  );
212  }

Here is the call graph for this function:

& Hoa\Praspel\Model\Declaration::getLocalVariables ( )

Get local variables.

Returns
array

Definition at line 229 of file Declaration.php.

230  {
231  return $this->_variables;
232  }

Here is the caller graph for this function:

Hoa\Praspel\Model\Declaration::getPredicates ( )

Get all predicates.

Returns
array

Definition at line 278 of file Declaration.php.

279  {
280  return $this->_predicates;
281  }
Hoa\Praspel\Model\Declaration::getVariable (   $name,
  $borrowing = false 
)

Declare or get a new variable.

Parameters
string$nameVariable name.
bool$borrowingBorrowing variable or not.
Returns
mixed

Definition at line 109 of file Declaration.php.

110  {
111  if (true === $borrowing) {
112  $out = new Variable\Borrowing($name, $this->_let, $this);
113  $this->_let = false;
114 
115  return $out;
116  }
117 
118  if ('\old(' === substr($name, 0, 5)) {
119  $variable = $this->getVariable($name, true);
120 
121  return new Realdom\Crate\Constant(
122  $variable->getBorrowedVariable(),
123  function () use ($variable) {
124  return $variable->getName();
125  },
126  $this
127  );
128  }
129 
130  if (false === $this->offsetExists($name)) {
131  $variable = new Variable($name, $this->_let, $this);
132  $this->_let = false;
133 
134  return $this->_variables[$name] = $variable;
135  }
136 
137  return $this->_variables[$name];
138  }
getVariable($name, $borrowing=false)

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Praspel\Model\Declaration::offsetExists (   $offset)

Check if a variable exists.

Parameters
string$offsetVariable name.
Returns
bool

Definition at line 86 of file Declaration.php.

87  {
88  return isset($this->_variables[$offset]);
89  }

Here is the caller graph for this function:

Hoa\Praspel\Model\Declaration::offsetGet (   $offset)

Get or create a variable.

Parameters
string$offsetVariable name.
Returns

Definition at line 97 of file Declaration.php.

98  {
99  return $this->getVariable($offset);
100  }
getVariable($name, $borrowing=false)

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Praspel\Model\Declaration::offsetSet (   $offset,
  $value 
)

Set a value to a variable.

Parameters
string$offsetVariable name.
mixed$valueVariable value.
Returns
mixed

Definition at line 159 of file Declaration.php.

160  {
161  $variable = $this->offsetGet($offset);
162  $old = $variable->getValue();
163  $variable->setValue($value);
164 
165  return $old;
166  }

Here is the call graph for this function:

Hoa\Praspel\Model\Declaration::offsetUnset (   $offset)

Delete a variable.

Parameters
string$offsetVariable name.
Returns
void

Definition at line 174 of file Declaration.php.

175  {
176  unset($this->_variables[$offset]);
177 
178  return;
179  }
Hoa\Praspel\Model\Declaration::predicate (   $predicate)

Add a predicate.

Parameters
string$predicatePredicate.
Returns

Definition at line 266 of file Declaration.php.

267  {
268  $this->_predicates[] = $predicate;
269 
270  return $this;
271  }

Member Data Documentation

Hoa\Praspel\Model\Declaration::$_let = false
protected

Definition at line 76 of file Declaration.php.

Hoa\Praspel\Model\Declaration::$_predicates = []
protected

Definition at line 69 of file Declaration.php.

Hoa\Praspel\Model\Declaration::$_variables = []
protected

Definition at line 62 of file Declaration.php.


The documentation for this class was generated from the following file: