From a25ccc548d5c1d5a263e1d60437a14dc07c83edc Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Wed, 26 Oct 2016 11:33:43 +0800 Subject: [PATCH] CodeDoc/Parser/Method.php --- CodeDoc/Parser/Method.php | 210 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 CodeDoc/Parser/Method.php diff --git a/CodeDoc/Parser/Method.php b/CodeDoc/Parser/Method.php new file mode 100644 index 0000000..6f2b61c --- /dev/null +++ b/CodeDoc/Parser/Method.php @@ -0,0 +1,210 @@ +debug(__METHOD__,$c->name); + if ($inclass) { + + $c->rfilename = $this->rfilename; + $c->activeFile = $this->activeFile; + + $this->classes[$this->_active_class]->Operations[$c->name] = $c; + $this->classes[$this->_active_class]->Operations[$c->name]->class = $this->classes[$this->_active_class]->name; + + + // silly stuff :) + // merge method's author with class. + // hey this is a cool use of all those array functions! + + + if (@$a = $this->classes[$this->_active_class]->Operations[$c->name]->description->author) + $this->classes[$this->_active_class]->description->author + = array_reverse(array_values( array_unique (array_reverse(array_merge( + $this->classes[$this->_active_class]->description->author, $a))))); + + // echo $this->methods++; + } else { + $c->active_package = &$this->packages[$this->active_package->name]; + $c->rfilename = $this->rfilename; + $c->activeFile = $this->activeFile; + + $this->active_directory->functions[] = $c; + //$c->active_package->functions[$c->name] = $c; + } + $this->pos = $c->endpos; + } + } + + + var $_active_method; // return object (PHP_CodeDoc_MethodParser) + + function parse() { // really parse + + // before pos... 2 points... + /// probably need to look back for 'string'? + $flags= array($this->look_nws(-1,';'), $this->look_nws(-2,';'), $this->look_nws(-3,';'), $this->look_nws(-4,';')); + + + $startpos = $this->pos; + if ($npos = $this->find_token_pos($startpos,array(T_STRING),'(')) { + $n = @$this->tokens[$npos][1]; + } else { + return; + } + + $this->pos = $this->pos + 4; + $method = new PHP_CodeDoc_Data_Method; + $method->name = $n; + $method->type = "Public"; + $method->isPublic = 1; + $method->isStatic = in_array(T_STATIC, $flags) ? 1 : 0; + $method->isFinal = in_array(T_FINAL, $flags) ? 1 : 0; + $method->visibility = 1; + if (in_array(T_PRIVATE, $flags)) { + $method->type = "Private"; + $method ->isPublic = 0; + $method->visibility = 0; + } + if (in_array(T_PROTECTED, $flags)) { + $method->type = "Protected"; + $method ->isPublic = 0; + $method->visibility = 0; + } + + + $method->Param = PHP_CodeDoc_Parser_Method::_get_args($method); + + if ($v = PHP_CodeDoc_Parser_Comment::parse()) { + $method->description = $v; + } + + $this->pos = $startpos; + PHP_CodeDoc_Parser_Method::_store_method_tokens($method); + // store the array of objects so It can be printed out! + $this->pos = $startpos; + + $method->endpos = $this->endpos; + return $method; + + } + + + + + function _store_method_tokens(&$method) { //remember the tokens for a method.. (for printing later) + //return; + $tokens=array(); + $n=0; + $in_method =0; + $inbrak =0; + $level=0; + $pos = $this->pos; + $method->tokenStart = $this->pos; + $startpos = $this->pos; + while ($pos < $this->total) { + $v = $this->tokens[$pos]; + if (is_array($v)) { + if (!$inbrak && $v[0] == T_CURLY_OPEN) { + if ($level ==0) + $in_method=1; + $level++; + } + //if ($v[1] && $v[1]{0} == "(") + // $inbrak++; + //$v[0] = token_name($v[0]); + $v[2]= "{$level}:{$inbrak}"; + } else { + if (!$inbrak && trim($v) == "}") + $level--; + if (!$inbrak && trim($v) == "{") { + if ($level ==0) + $in_method=1; + $level++; + } + if (trim($v) == "(") $inbrak++; + if (trim($v) == ")") $inbrak--; + + } + + $tokens[$n] = $v; + if ($in_method && !$level) { + $this->endpos = $pos; + $method->tokenEnd = $pos; + + return; + } + $pos++; + $n++; + } + $this->endpos = $this->pos+1; + $method->tokenEnd = $this->pos+1; + } + + + + function _get_args (&$method) {// read arguments of a method call + $Param= array(); + $level =0; + $p = -1; + while ($this->pos < $this->total) { + $v = $this->tokens[$this->pos]; + if (is_array($v)) { + if ($v[0] == T_WHITESPACE) { + $this->pos++; + continue 1; + } + switch ($v[0]) { + case T_VARIABLE: + $p++; + $Param[$p] = new StdClass; + $Param[$p]->name = $v[1]; + break; + + case T_FILE: + case T_LINE: + case T_LNUMBER: + case T_CONSTANT_ENCAPSED_STRING: + if (!@$Param[$p]->Value) + $Param[$p]->Value = $v[1]; + break; + case T_ARRAY: + $Param[$p]->Value = "array()"; + break; + } + //echo "XXX:{$this->pos}:" .token_name($v[0]) . ":{$this->level}:". $v[1] .":\n"; + } else { + //if ($v == "(") $level++; + if ($v == "{") return $Param; + + //if ($v == ",") $current_var = ""; + //echo "XXX:{$this->pos}:RAW:{$v}\n"; + } + $this->pos++; + } + return $Param; // shouldnt really get here + } + + + +} \ No newline at end of file -- 2.39.2