7 method parser - implements all the routines related to parsing a method
8 and returning a Method Data Object.
11 NOTE: these methods are called statically from the main parser, and hence
12 inherit $this from the parser!!!!!!!
20 class PHP_CodeDoc_Parser_Method {
23 static function read(PHP_CodeDoc_Parser $thiz, $inclass) {
25 if ($c = PHP_CodeDoc_Parser_Method::parse($thiz)) {
26 $thiz->debug(__METHOD__,$c->name);
29 $c->rfilename = $thiz->rfilename;
30 $c->activeFile = $thiz->activeFile;
32 $thiz->classes[$thiz->_active_class]->Operations[$c->name] = $c;
33 $thiz->classes[$thiz->_active_class]->Operations[$c->name]->class = $thiz->classes[$thiz->_active_class]->name;
37 // merge method's author with class.
38 // hey this is a cool use of all those array functions!
41 if (@$a = $thiz->classes[$thiz->_active_class]->Operations[$c->name]->description->author)
42 $thiz->classes[$thiz->_active_class]->description->author
43 = array_reverse(array_values( array_unique (array_reverse(array_merge(
44 $thiz->classes[$thiz->_active_class]->description->author, $a)))));
46 // echo $thiz->methods++;
48 $c->active_package = &$thiz->packages[$thiz->active_package->name];
49 $c->rfilename = $thiz->rfilename;
50 $c->activeFile = $thiz->activeFile;
52 $thiz->active_directory->functions[] = $c;
53 //$c->active_package->functions[$c->name] = $c;
55 $thiz->pos = $c->endpos;
60 var $_active_method; // return object (PHP_CodeDoc_MethodParser)
62 function parse(PHP_CodeDoc_Parser $thiz) { // really parse
64 // before pos... 2 points...
65 /// probably need to look back for 'string'?
66 $flags= array($thiz->look_nws(-1), $thiz->look_nws(-2), $thiz->look_nws(-3), $thiz->look_nws(-4));
69 $startpos = $thiz->pos;
70 if ($npos = $thiz->find_token_pos($startpos,array(T_STRING),'(')) {
71 $n = @$thiz->tokens[$npos][1];
76 $thiz->pos = $thiz->pos + 4;
77 $method = new PHP_CodeDoc_Data_Method;
79 $method->type = "Public";
80 $method->isPublic = 1;
81 $method->isStatic = in_array(T_STATIC, $flags) ? 1 : 0;
82 $method->isFinal = in_array(T_FINAL, $flags) ? 1 : 0;
83 $method->visibility = 1;
84 if (in_array(T_PRIVATE, $flags)) {
85 $method->type = "Private";
86 $method ->isPublic = 0;
87 $method->visibility = 0;
89 if (in_array(T_PROTECTED, $flags)) {
90 $method->type = "Protected";
91 $method ->isPublic = 0;
92 $method->visibility = 0;
96 $method->Param = PHP_CodeDoc_Parser_Method::_get_args($thiz,$method);
98 if ($v = PHP_CodeDoc_Parser_Comment::parse($thiz)) {
99 $method->description = $v;
102 $thiz->pos = $startpos;
103 PHP_CodeDoc_Parser_Method::_store_method_tokens($thiz,$method);
104 // store the array of objects so It can be printed out!
105 $thiz->pos = $startpos;
107 $method->endpos = $thiz->endpos;
115 function _store_method_tokens(PHP_CodeDoc_Parser $thiz, &$method) { //remember the tokens for a method.. (for printing later)
123 $method->tokenStart = $thiz->pos;
124 $startpos = $thiz->pos;
125 while ($pos < $thiz->total) {
126 $v = $thiz->tokens[$pos];
128 if (!$inbrak && $v[0] == T_CURLY_OPEN) {
133 //if ($v[1] && $v[1]{0} == "(")
135 //$v[0] = token_name($v[0]);
136 $v[2]= "{$level}:{$inbrak}";
138 if (!$inbrak && trim($v) == "}")
140 if (!$inbrak && trim($v) == "{") {
145 if (trim($v) == "(") $inbrak++;
146 if (trim($v) == ")") $inbrak--;
151 if ($in_method && !$level) {
152 $thiz->endpos = $pos;
153 $method->tokenEnd = $pos;
160 $thiz->endpos = $thiz->pos+1;
161 $method->tokenEnd = $thiz->pos+1;
166 function _get_args (PHP_CodeDoc_Parser $thiz, &$method) {// read arguments of a method call
170 while ($thiz->pos < $thiz->total) {
171 $v = $thiz->tokens[$thiz->pos];
173 if ($v[0] == T_WHITESPACE) {
180 $Param[$p] = new StdClass;
181 $Param[$p]->name = $v[1];
187 case T_CONSTANT_ENCAPSED_STRING:
188 if (!@$Param[$p]->Value)
189 $Param[$p]->Value = $v[1];
192 $Param[$p]->Value = "array()";
195 //echo "XXX:{$thiz->pos}:" .token_name($v[0]) . ":{$thiz->level}:". $v[1] .":\n";
197 //if ($v == "(") $level++;
198 if ($v == "{") return $Param;
200 //if ($v == ",") $current_var = "";
201 //echo "XXX:{$thiz->pos}:RAW:{$v}\n";
205 return $Param; // shouldnt really get here