Skip to content

Commit dccd7a0

Browse files
committed
Work on parser
1 parent 95ecddb commit dccd7a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+275
-146
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
protected $_notes = array();
66
protected $_dependencies = array();
77
protected $_authors = array();
8+
protected $_processed = 0;
89

910
public $config = array(
1011
"mapping"=>array(
@@ -31,8 +32,11 @@ public function PHPJS_DocBlock($docBlock) {
3132
}
3233

3334
public function parseDocBlock() {
35+
if ($this->_processed > 0) {
36+
return $this->_processed;
37+
}
38+
3439
$mapping = $this->config["mapping"];
35-
$info = array();
3640

3741
// Match all meaningful comment lines
3842
preg_match_all('/^[\s]*\/\/[\s]*(['.preg_quote(implode('', array_keys($mapping))).'])[\s]*(.+)/m',
@@ -66,7 +70,8 @@ public function parseDocBlock() {
6670
}
6771
}
6872

69-
return $info;
73+
$this->_processed++;
74+
return $this->_processed;
7075
}
7176
}
7277
?>
File renamed without changes.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getDependencies($recurse=true) {
179179
foreach($list as $functionName) {
180180
$Function = &$this->PHPJS_Library->getFunction($functionName);
181181

182-
if (!is_object($functionName)) {
182+
if (!is_object($Function)) {
183183
throw new PHPJS_Exception("No Function object for '".$functionName."' in relation to: '".$this->getFunctionName()."'.");
184184
//$dbg = debug_backtrace();
185185
//print_r($dbg);
@@ -193,6 +193,10 @@ public function getDependencies($recurse=true) {
193193
return $list;
194194
}
195195

196+
public function log($str, $level=PHPJS_Library::LOG_INFO) {
197+
return PHPJS_Library::log($str, $level);
198+
}
199+
196200
public function getDocBlock() {
197201
return $this->_tokDocBlock;
198202
}

_helpers/PHPJS_Library/PHPJS/Function/Tester.php renamed to _tools/PHPJS_Library/PHPJS/Function/Tester.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public function PHPJS_Function_Tester($file, &$PHPJS_Library){
1313
protected function _parseTestOutput($testOutput) {
1414
$testResults = array();
1515

16+
if (is_array($testOutput)) {
17+
$testOutput = implode("\n", $testOutput);
18+
}
19+
1620
$sets = explode("## SETS ##", $testOutput);
1721
$i = 0;
1822
foreach ($sets as $set) {
@@ -27,15 +31,20 @@ protected function _parseTestOutput($testOutput) {
2731
$x = $this->PHPJS_Library->strShift(" ", $result);
2832
$type = $this->PHPJS_Library->strShift(" ", $result);
2933
$success = $this->PHPJS_Library->strShift(" ", $result);
30-
$testResults[$type][$success] = $result;
34+
$testResults[$type][][$success] = $result;
3135
}
3236
$i++;
3337
}
3438

35-
$testResults = array(1,2,3,4,5);
3639
return $testResults;
3740
}
3841

42+
public function testFunction($outputRaw=false) {
43+
$testCode = $this->testCode();
44+
$results = $this->runTestCode($testCode, $outputRaw);
45+
return $this->showResults($results);
46+
}
47+
3948
public function addInclude($path, $name="") {
4049
$this->_includes[$path] = $name;
4150
}
@@ -75,15 +84,18 @@ public function testCode() {
7584
$n = $this->_n;
7685
$testCode = "";
7786

78-
7987
// Add dependencies to Includes
8088
// DONT RECURSE DEPENDENCIES WITH THE CONSTRUCTOR.
8189
// ALSO DON'T SAVE TESTCODE WITH THE CONSTRUCTOR,
8290
// BECAUSE NOT ALL FUNCTIONS ARE LOADED YET
8391
$depsRec = $this->getDependencies(true);
8492
$depsSng = $this->getDependencies(false);
8593
foreach ($depsRec as $funcName) {
86-
$path = $this->PHPJS_Library->Functions[$funcName]->getPath();
94+
if (($FunctionDep = $this->PHPJS_Library->getFunction($funcName)) === false) {
95+
$this->log("Function $funcName not found", PHPJS_Library::LOG_CRIT);
96+
return false;
97+
}
98+
$path = $FunctionDep->getPath();
8799
$depType = (!in_array($funcName, $depsSng) ? "direct" : "recursive");
88100
$this->addInclude($path, "Dependency (".$depType."): ".$funcName);
89101
}

_helpers/PHPJS_Library/PHPJS/Function/Tester/Shell.php renamed to _tools/PHPJS_Library/PHPJS/Function/Tester/Shell.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public function PHPJS_Function_Tester_Shell($file, &$PHPJS_Library){
66
parent::PHPJS_Function_Tester($file, $PHPJS_Library);
77

88
// Add shell specific Includes
9-
$this->addInclude($PHPJS_Library->getDirRealRoot()."/_helpers/env.js", "Shell Requirement");
10-
$this->addInclude($PHPJS_Library->getDirRealRoot()."/_helpers/tester.js", "Shell Requirement");
9+
$this->addInclude($PHPJS_Library->getDirRealRoot()."/_tools/env.js", "Shell Requirement");
10+
$this->addInclude($PHPJS_Library->getDirRealRoot()."/_tools/tester.js", "Shell Requirement");
1111
}
1212

1313
public function getPath() {
@@ -27,7 +27,7 @@ protected function _testCodePrepend() {
2727
$testCode .= "// Main source we want to test".$n;
2828
$testCode .= "load('".$this->getRealPath()."');".$n;
2929
$testCode .= "".$n;
30-
$testCode .= "window.location = '".$this->PHPJS_Library->getDirRealRoot()."/_helpers/tester.htm"."';".$n;
30+
$testCode .= "window.location = '".$this->PHPJS_Library->getDirRealRoot()."/_tools/tester.htm"."';".$n;
3131
$testCode .= "window.onload = function(){".$n;
3232

3333
return $testCode;
@@ -42,7 +42,49 @@ protected function _testCodeAppend() {
4242
return $testCode;
4343
}
4444

45+
public function showResults($results, $breakOnError=true) {
46+
// @todo: Parser can be better. Does it work with result-values?
47+
// @todo: Outputting needs cleanup
48+
$examples = $this->DocBlock->getExamples();
49+
50+
print_r($results);
51+
52+
foreach ($results as $type=>$typeSet) {
53+
foreach ($typeSet as $typeSetNr=>$typeSetNrRes) {
54+
foreach ($typeSetNrRes as $succeeded=>$returnValue) {
55+
56+
if ($succeeded) {
57+
echo "OKAY ";
58+
} else {
59+
echo "FAIL ";
60+
}
61+
$exampleNr = $typeSetNr+1;
62+
63+
64+
$example = $examples[$exampleNr]["example"];
65+
66+
echo str_pad($this->_functionName.":".$exampleNr, 20, " ", STR_PAD_RIGHT). " ";
67+
68+
69+
70+
echo str_pad($example[0], 20, " ", STR_PAD_RIGHT). " ";
71+
72+
echo str_pad($returnValue, 20, " ", STR_PAD_RIGHT). " ";
73+
74+
echo "\n";
75+
76+
if ($succeeded == false && $breakOnError==true) {
77+
return false;
78+
}
79+
}
80+
}
81+
}
82+
83+
return true;
84+
}
85+
4586
protected function _saveTestCode($file, $testCode) {
87+
$this->log("Saved testcode in ".$file, PHPJS_Library::LOG_DEBUG);
4688
return @file_put_contents($file, $testCode);
4789
}
4890

@@ -68,18 +110,20 @@ public function runTestCode($testCode, $outputRaw=false) {
68110
return false;
69111
}
70112

71-
$testOutput = implode("\n", $output);
113+
$testOutput = $output;
72114
$testResults = $this->_parseTestOutput($testOutput);
73115

74116
if ($outputRaw) {
75117
return $testOutput;
76118
}
77-
119+
78120
return $testResults;
79121
}
80122

81123
protected function _execute($cmd) {
124+
mark();
82125
exec($cmd, $o, $r);
126+
mark();
83127
if ($r) {
84128
return array(false, $o);
85129
}
File renamed without changes.
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
<?php
2+
function printFunc($what, $dif) {
3+
$r = realpath(dirname(__FILE__)."/..");
4+
5+
echo pad(str_replace($r, "", $what["file"]), 25);
6+
echo pad($what["line"]);
7+
echo pad($what["function"]."(".implode(", ", $what["args"]).") ");
8+
echo pad(round($dif, 3)."s", 5);
9+
echo "\n";
10+
}
11+
12+
function pad($str, $spaces=25) {
13+
return str_pad($str, $spaces, " ", STR_PAD_RIGHT)." ";
14+
}
15+
16+
function mark() {
17+
return null;
18+
global $lastMarkAt;
19+
20+
21+
22+
if (!$lastMarkAt) $lastMarkAt = microtime(true);
23+
$dif = microtime(true) - $lastMarkAt;
24+
25+
$x = debug_backtrace();
26+
$one = array_shift($x);
27+
$two = array_shift($x);
28+
$three = array_shift($x);
29+
30+
printFunc($two, $dif);
31+
32+
$lastMarkAt = microtime(true);
33+
}
234

335
// Autoloader borrowed from PHP_CodeSniffer, see function for credits
436
spl_autoload_register(array("PHPJS_Library", "autoload"));
@@ -78,7 +110,7 @@ public function addFunction($path) {
78110
$obj = new $className($path, &$this);
79111

80112
//$obj->reload();
81-
$funcName = &$obj->getFunctionName();
113+
$funcName = $obj->getFunctionName();
82114
$this->Functions[$funcName] = &$obj;
83115
}
84116

@@ -94,7 +126,8 @@ public function functionExists($funcName) {
94126
* @return Object
95127
*/
96128
public function getFunction($function) {
97-
if (!isset($this->Functions[$function])) {
129+
if (!$this->functionExists($function)) {
130+
$this->Function = false;
98131
return false;
99132
}
100133

@@ -122,7 +155,7 @@ public function PHPJS_Library($dirRealFunctions="") {
122155
$this->_dirRealRoot = realpath($this->_dirRealFunc."/..");
123156
}
124157
if (!$this->_dirRealTemp) {
125-
$this->_dirRealTemp = $this->_dirRealRoot."/_helpers/_temp";
158+
$this->_dirRealTemp = $this->_dirRealRoot."/_tools/_temp";
126159
}
127160

128161
foreach (array($this->_dirRealFunc, $this->_dirRealRoot, $this->_dirRealTemp) as $dir) {
@@ -191,7 +224,7 @@ public function reload() {
191224
* @param string $str
192225
* @param integer $level
193226
*/
194-
private function _log($str, $level=PHPJS_Library::LOG_INFO) {
227+
public function log($str, $level=PHPJS_Library::LOG_INFO) {
195228
echo $str."\n";
196229
if ($level <= self::LOG_CRIT) {
197230
die();

_helpers/PHPJS_Library/PHPJS/Library/Tester.php renamed to _tools/PHPJS_Library/PHPJS/Library/Tester.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
protected $_fleRealRhino = "/usr/bin/rhino";
55

6-
public function report($str) {
7-
echo $str;
8-
}
9-
106
public function getFleRealRhino() {
117
return $this->_fleRealRhino;
128
}
@@ -31,12 +27,6 @@ public function testFrom($fromFunctionName) {
3127
return $this->_testSelection($selectedFunctions);
3228
}
3329

34-
public function testOne($oneFunctionName) {
35-
$selectedFunctions = array();
36-
$selectedFunctions[$oneFunctionName] = &$this->Functions[$oneFunctionName];
37-
return $this->_testSelection($selectedFunctions);
38-
}
39-
4030
protected function _testSelection($selectedFunctions) {
4131
$testResults = array();
4232
foreach ($selectedFunctions as $funcName=>$Function) {
@@ -46,14 +36,13 @@ protected function _testSelection($selectedFunctions) {
4636
}
4737

4838
public function testFunction($funcName, $outputRaw=false) {
49-
if (!$this->functionExists($funcName)) {
39+
if (($Function = $this->getFunction($funcName)) === false) {
5040
throw new PHPJS_Exception("Function $funcName does not exst");
5141
return false;
5242
}
5343

54-
$Function = $this->getFunction($funcName);
55-
$testCode = $Function->testCode();
56-
$results = $Function->runTestCode($testCode, $outputRaw);
44+
// Forward to Function Object
45+
$results = $Function->testFunction($outputRaw);
5746

5847
return $results;
5948
}

_helpers/PHPJS_Library/PHPJS/Library/Tester/Shell.php renamed to _tools/PHPJS_Library/PHPJS/Library/Tester/Shell.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<?php
22
Class PHPJS_Library_Tester_Shell extends PHPJS_Library_Tester {
3-
4-
public function testFunction($funcName, $outputRaw=false) {
5-
// Proceed with parent
6-
parent::testFunction($funcName, $outputRaw);
7-
}
8-
93
public function getAllowedCmdArgs() {
104
$posArgs = array();
115
$posArgs["func"] = "--func";
File renamed without changes.

0 commit comments

Comments
 (0)