forked from jimthunderbird/php-to-c-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add one level call_c_auto conversion support
- Loading branch information
1 parent
75ac7af
commit f71a6ca
Showing
3 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace PHPtoCExt\Converter; | ||
|
||
/** | ||
* Automatically convert c_function_auto api to corresponding c_function_call apis | ||
*/ | ||
class CFunctionAutoConverter extends \PHPtoCExt\Converter | ||
{ | ||
public function convert() | ||
{ | ||
//first, find out all call_c_auto calls and find out the corresponding class context this c function call belongs to | ||
$classMap = $this->getClassMap(); | ||
|
||
foreach($classMap as $className => $classInfo) { | ||
$originalClassCode = implode("\n",array_slice($this->codeLines, $classInfo->startLine - 1, $classInfo->endLine - $classInfo->startLine + 1)); | ||
foreach($classInfo->methodInfos as $methodPureName => $methodInfo) { | ||
for ($index = $methodInfo->startLine; $index <= $methodInfo->endLine; $index++) { | ||
if (preg_match("/call_c_auto\(.*\)/", $this->codeLines[$index], $matches)) { | ||
if(count($matches) == 1) { | ||
$codeLine = $this->codeLines[$index]; //store the original code line here | ||
$filteredCodeLine = str_replace(array("call_c_auto","(",")",";"),"",trim($codeLine)); | ||
$lineComps = explode("=",$filteredCodeLine); | ||
$lineCompsCount = count($lineComps); | ||
$className[0] = ""; | ||
$className = trim($className); | ||
$classNameComps = explode("\\", $className); | ||
//remove namespace | ||
array_shift($classNameComps); | ||
$className = implode("/",$classNameComps); | ||
if ($lineCompsCount == 1) { //this means we do not have return result variable | ||
$inputParamsStr = trim($lineComps[0]); | ||
if (strlen($inputParamsStr) == 0) { | ||
$this->searchAndReplace($filteredCodeLine,"call_c_function(\"$className.c\",\"$methodPureName\");"); | ||
} else { | ||
$this->searchAndReplace($codeLine,"call_c_function(\"$className.c\",\"$methodPureName\",$inputParamsStr);"); | ||
} | ||
} else if ($lineCompsCount == 2){ //this means we have input return result variable | ||
$returnVarStr = $lineComps[0]; | ||
$inputParamsStr = $lineComps[1]; | ||
if (strlen($inputParamsStr) == 0) { | ||
$this->searchAndReplace($filteredCodeLine,"$returnVarStr = call_c_function(\"$className.c\",\"$methodPureName\");"); | ||
} else { | ||
$this->searchAndReplace($codeLine,"$returnVarStr = call_c_function(\"$className.c\",\"$methodPureName\",$inputParamsStr);"); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters