From 90c48f008492f28c9092e67aa1a03ca4e686ce37 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Tue, 28 May 2024 01:32:36 -0400 Subject: [PATCH 1/5] add getCode method --- pgetinker/Compiler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pgetinker/Compiler.php b/pgetinker/Compiler.php index ed48e0a..8680fc8 100644 --- a/pgetinker/Compiler.php +++ b/pgetinker/Compiler.php @@ -83,6 +83,11 @@ public function deserialize(string $json) $this->workingDirectory = ""; } + public function getCode() + { + return implode("\n", $this->code); + } + public function setCode(string $code) { $this->code = explode("\n", $code); From e2207814c63dc9012b4bc1f14dc78c07b240c335 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Tue, 28 May 2024 01:32:57 -0400 Subject: [PATCH 2/5] public processCode method, so testing is possible --- pgetinker/Compiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgetinker/Compiler.php b/pgetinker/Compiler.php index 8680fc8..1dadd5e 100644 --- a/pgetinker/Compiler.php +++ b/pgetinker/Compiler.php @@ -346,7 +346,7 @@ private function processCodeRemoteInclude($index) } } - private function processCode() + public function processCode() { $this->logger->info("begin processing code"); $startTime = microtime(true); From c69c8fbcba521b3db53f39c6134e9d7568c441a9 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Tue, 28 May 2024 01:34:41 -0400 Subject: [PATCH 3/5] use regex to determine the validity of the implementation macro, if any --- pgetinker/Compiler.php | 61 +++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/pgetinker/Compiler.php b/pgetinker/Compiler.php index 1dadd5e..b858945 100644 --- a/pgetinker/Compiler.php +++ b/pgetinker/Compiler.php @@ -167,6 +167,10 @@ private function processCodeDetectGeometryUtility($index) private function processCodeDetectImplementationMacros($index) { + // broad phase, don't process if this line doesn't at least contain the word "define" + if(!str_contains($this->code[$index], "define")) + return false; + $libraryMap = [ 'OLC_PGE_APPLICATION' => 'olcPixelGameEngine.o', 'OLC_SOUNDWAVE_ENGINE' => 'olcSoundWaveEngine.o', @@ -181,35 +185,44 @@ private function processCodeDetectImplementationMacros($index) 'OLC_PGEX_WIREFRAME' => 'olcPGEX_Wireframe.o', ]; - // filter macros to detect implementation #define - if(str_contains($this->code[$index], "#define")) + $foundImplementationMacro = false; + + foreach($libraryMap as $macro => $objectFileName) { - $foundImplementationMacro = false; - foreach($libraryMap as $macro => $objectFileName) + preg_match( + '/(.*)\s*#\s*define?\s+' . $macro . '(.*)/', + $this->code[$index], + $match, + PREG_OFFSET_CAPTURE, + 0 + ); + + // no match, this time + if(count($match) == 0) + continue; + + if(!empty(trim($match[1][0])) || !empty(trim($match[2][0]))) + continue; + + // blank the line + $this->code[$index] = ""; + + if($macro == "OLC_PGE_APPLICATION" && $this->foundGeometryHeader) { - if(str_contains($this->code[$index], $macro)) - { - // blank the line - $this->code[$index] = ""; - - if($macro == "OLC_PGE_APPLICATION" && $this->foundGeometryHeader) - { - $objectFileName = "olcPixelGameEngine_withGeometry.o"; - $this->logger->info("Found the need for geometry utility support"); - } + $objectFileName = "olcPixelGameEngine_withGeometry.o"; + $this->logger->info("Found the need for geometry utility support"); + } - // indicate that we use this library - $this->linkerInputFiles[] = "./lib/{$objectFileName}"; + // indicate that we use this library + $this->linkerInputFiles[] = "./lib/{$objectFileName}"; - $this->logger->info("Found implementation macro: {$macro}"); - $foundImplementationMacro = true; - break; - } - } + $this->logger->info("Found implementation macro: {$macro}"); + $foundImplementationMacro = true; + break; + } - if($foundImplementationMacro) - return true; - } + if($foundImplementationMacro) + return true; return false; } From df0a4187859662dbac31ecf36f50dc743863a2e3 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Tue, 28 May 2024 01:35:13 -0400 Subject: [PATCH 4/5] money where the mouth is, make damn sure it works. --- tests/Feature/ProcessCodeTest.php | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/Feature/ProcessCodeTest.php diff --git a/tests/Feature/ProcessCodeTest.php b/tests/Feature/ProcessCodeTest.php new file mode 100644 index 0000000..3029c71 --- /dev/null +++ b/tests/Feature/ProcessCodeTest.php @@ -0,0 +1,69 @@ +setCode($code); + $compiler->processCode(); + $this->assertTrue($code == $compiler->getCode()); + + $code = "#define OLC_PGE_APPLICATIONYEAAAAAAA\n"; + $compiler->setCode($code); + $compiler->processCode(); + $this->assertTrue($code == $compiler->getCode()); + + $code = "I can write anything wheeeee!#define OLC_PGE_APPLICATIONYEAAAAAAA\n"; + $compiler->setCode($code); + $compiler->processCode(); + $this->assertTrue($code == $compiler->getCode()); + } + + public function test_valid_white_space_macros(): void + { + $compiler = new Compiler(); + + $code = "\t #define OLC_PGE_APPLICATION\n"; + $compiler->setCode($code); + $compiler->processCode(); + print_r($code); + print_r($compiler->getCode()); + $this->assertTrue($code != $compiler->getCode()); + + $code = "# define OLC_PGE_APPLICATION\n"; + $compiler->setCode($code); + $compiler->processCode(); + $this->assertTrue($code != $compiler->getCode()); + + $code = "#define OLC_PGE_APPLICATION\n"; + $compiler->setCode($code); + $compiler->processCode(); + $this->assertTrue($code != $compiler->getCode()); + + $code = "#define OLC_PGE_APPLICATION \n"; + $compiler->setCode($code); + $compiler->processCode(); + $this->assertTrue($code != $compiler->getCode()); + } + + // public function test_process_code_fails_on_bad_macro(): void + // { + // $compiler = new Compiler(); + + // $code = "I can write anything wheeeee!#define OLC_PGE_APPLICATIONYEAAAAAAA\n"; + // $compiler->setCode($code); + // $compiler->processCode(); + + // $this->assertTrue($code == $compiler->getCode()); + // } + +} From 07c22dc09588a3048d54f29fa322b6ea7c25961e Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Tue, 28 May 2024 01:38:39 -0400 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 026553c..28ba31f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Each batch It is a summary of changes that would be pertinent to the end user of the PGEtinker website. For a comprehensive history of changes made to the project, please refer to the repository's commit history. +## 2024-05-28 + +- Fixed [Issue #78](https://github.com/Moros1138/PGEtinker/issues/78) + ## 2024-05-27 - Changed complete revamp of the frontend code, much more organized