Beispiel #1
0
 public function generateTargetCode(TokenPool $aTokenPool, Token $aToken)
 {
     if (!$aToken instanceof FunctionDefine) {
         return;
     }
     if (!($aBodyToken = $aToken->bodyToken())) {
         return;
     }
     // 函数开始
     $aBodyToken->setTargetCode($aBodyToken->targetCode() . "\r\n\t// ---------------------------------------------------------------------------------" . "\r\n\t// ALERT: 此文件由 JeCat Class Compiler 自动生成和维护,请不要**直接编辑**此文件!" . "\r\n\t//   对此文件的任何改动,都会在下次生成时被新生成的文件覆盖。" . "\r\n");
     // 函数结束
     $aBodyEndToken = $aBodyToken->theOther();
     if (!$aBodyEndToken) {
         throw new ClassCompileException(null, $aBodyToken, "函数 %s 的函数体没有闭合", $aToken->name());
     }
     $aBodyEndToken->setTargetCode("\r\n\t// ALERT: 此文件由 JeCat Class Compiler 自动生成和维护,请不要**直接编辑**此文件!" . "\r\n\t//   对此文件的任何改动,都会在下次生成时被新生成的文件覆盖。" . "\r\n\t// ---------------------------------------------------------------------------------" . "\r\n\t" . $aBodyEndToken->targetCode());
 }
 public function matchExecutionPoint(Token $aToken)
 {
     $bIsPattern = $this->weaveMethodIsPattern();
     // 模糊匹配每个方法
     if ($bIsPattern and $aToken instanceof FunctionDefine) {
         // 必须是一个类方法
         if (!($aClass = $aToken->belongsClass())) {
             return false;
         }
         if (!$this->matchClass($aClass->fullName())) {
             return false;
         }
         return preg_match($this->weaveMethodNameRegexp(), $aToken->name()) ? true : false;
     } else {
         if (!$bIsPattern and $aToken instanceof ClosureToken) {
             // 必须是一个 "}"
             if ($aToken->tokenType() != Token::T_BRACE_CLOSE) {
                 return false;
             }
             // 必须成对
             if (!$aToken->theOther()) {
                 return false;
             }
             $aClass = $aToken->theOther()->belongsClass();
             if (null === $aClass) {
                 return false;
             }
             // 必须做为 class 的结束边界
             if ($aToken->theOther() !== $aClass->bodyToken()) {
                 return false;
             }
             if (!$this->matchClass($aClass->fullName())) {
                 return false;
             }
             return true;
         }
     }
 }