public function cloneOf(self $aOther) { $this->nType = $aOther->nType; $this->setSourceCode($aOther->sourceCode()); $this->setTargetCode($aOther->targetCode()); $this->setPosition($aOther->position()); $this->setBelongsClass($aOther->belongsClass()); $this->setBelongsFunction($aOther->belongsFunction()); $this->setBelongsNamespace($aOther->belongsNamespace()); $this->setLine($aOther->line()); $this->sType = $this->tokenTypeName(); }
public function generateTargetCode(TokenPool $aTokenPool, Token $aObject) { switch( $aObject->tokenType() ) { case T_OBJECT_OPERATOR : // -> to . $aObject->setTargetCode('.') ; break ; case Token::T_CONCAT : // . to + $aObject->setTargetCode('+') ; break ; case T_CONCAT_EQUAL : // .= to += $aObject->setTargetCode('+=') ; break ; case T_VARIABLE : // 变量名前的 $ $aObject->setTargetCode( str_replace('$','',$aObject->sourceCode()) ) ; break ; case T_OPEN_TAG : // < ?php $aObject->setTargetCode( '' ) ; break ; case T_OPEN_TAG_WITH_ECHO : // < ?= $aObject->setTargetCode( 'echo ' ) ; break ; case T_CLOSE_TAG : // ? > $aObject->setTargetCode( '' ) ; break ; // 字符串压缩到一行 case T_CONSTANT_ENCAPSED_STRING : case T_ENCAPSED_AND_WHITESPACE: $sTarget = str_replace("\r","\\r", $aObject->targetCode()) ; $sTarget = str_replace("\n","\\n", $sTarget) ; $aObject->setTargetCode($sTarget) ; break ; // 转换 foreach (js 中没有foreach) case T_FOREACH: $this->transForeach($aTokenPool,$aObject) ; break ; case T_ENDFOREACH: // @todo break; } }