File: DojoExecutedFunction.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 (108 lines) | stat: -rw-r--r-- 3,370 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php

require_once('DojoFunctionDeclare.php');
require_once('DojoParameters.php');
require_once('Text.php');

class DojoExecutedFunction extends DojoFunctionDeclare
{
  private $object = 'DojoExecutedFunction';

  public function build(){
    if(!$this->start){
      die("DojoExecutedFunction->build() used before setting a start position");
    }
    if($this->end){
      return $this->end;
    }

    $lines = Text::chop($this->package->getCode(), $this->start[0], $this->start[1]);
    $line = $lines[$this->start[0]];
    
    $this->start = array($this->start[0], strpos($line, 'function'));

    $this->end = parent::build(); // Basically, the end array here will hold the position of the final } in the function declaration.

    $parameters = $this->getParameters();
    if (count($parameters) && ($pos = strpos($lines[$this->end[0]], '(')) !== false) {
      $arguments = new DojoParameters($this->package);
      $arguments->start = array($this->end[0], $pos);
      $arguments->build();
      $arguments = $arguments->getParameters();
      foreach ($parameters as $pos => $parameter) {
        if ($arguments[$pos]) {
          $argument = $arguments[$pos];
          if ($argument->isA(DojoVariable) && $parameter->isA(DojoVariable)) {
            if (preg_match('%(^|\|\|)([a-zA-Z0-9_.$]+)(\|\||$)%', $argument->getVariable(), $match)) {
              $this->body->addResolvedParameter($parameter->getVariable(), $match[2]);
            }
          }
        }
      }
    }
    $lines = Text::chop($this->package->getCode(), $this->end[0], $this->end[1], false, false, true);
    $closed = false;
    foreach($lines as $line_number => $line){
      $offset = 0;
      if($line_number == $this->end[0]){
        $offset = $this->end[1];
      }
      if(preg_match('%\S%', $line, $match, PREG_OFFSET_CAPTURE, $offset)){
        if(!$closed){
          if($match[0][0] != ')'){
            return false;
          }else{
            $closed = true;
            $offset = $match[0][1] + 1;
          }
        }
      }
      if(preg_match('%\S%', $line, $match, PREG_OFFSET_CAPTURE, $offset)){
        if($closed){
          if($match[0][0] != '('){
            return false;
          }else{
            $parameters = new DojoParameters($this->package, $line_number, $match[0][1]);
            $end = $parameters->build();
            break;
          }
        }
      }
    }
    return $end;
  }

  public function rollOut(&$output) {
    if ($this->getFunctionName()) {
      parent::rollOut($output);
    }

    $execution_variables = $this->getVariableNames($this->getFunctionName());
    foreach ($execution_variables as $execution_variable) {
      if (empty($output[$execution_variable])) {
        $output[$execution_variable] = array();
      }
    }

    $execution_declarations = $this->getFunctionDeclarations();
    foreach ($execution_declarations as $declaration) {
      $declaration->rollOut($output);
    }

    $execution_objects = $this->getObjects();
    foreach ($execution_objects as $object) {
      $object->rollOut($output);
    }
    unset($object);
    unset($execution_objects);

    if ($this->getFunctionName()) {
      $instance_declarations = $this->getInstanceFunctions($this->getFunctionName());
      foreach ($instance_declarations as $declaration) {
        $declaration->rollOut($output);
      }
    }
  }
}

?>