Skip to content

Commit fd84def

Browse files
dirxircmaxell
authored andcommitted
fix context evaluation (#4)
* add test for issue #2 * fix context evaluation
1 parent 8dbb1e4 commit fd84def

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

lib/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function evaluate(?Token $expr): Token {
137137
switch ($expr->type) {
138138
case Token::IDENTIFIER:
139139
if ($this->isDefined($expr->value)) {
140-
return $this->evaluate(...$this->definitions[$expr->value]);
140+
return $this->evaluate($this->definitions[$expr->value]);
141141
}
142142
return new Token(Token::NUMBER, '0', 'computed');
143143
}

test/cases/c/issue_2.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test for issue #2
3+
--FILE--
4+
5+
#ifndef TEST
6+
#define TEST 1
7+
#endif
8+
9+
#if TEST
10+
int bar;
11+
#endif
12+
13+
--EXPECT--
14+
int bar;

test/generated/c/issue_2Test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
#ifndef TEST
3+
#define TEST 1
4+
#endif
5+
6+
#if TEST
7+
int bar;
8+
#endif
9+

test/generated/c/issue_2Test.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
namespace PHPCParser\Test\c;
3+
use PHPCParser\CParser;
4+
use PHPCParser\Printer;
5+
use PHPCParser\Printer\Dumper;
6+
use PHPCParser\Printer\C;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/**
10+
* Note: this is a generated file, do not edit this!!!
11+
*/
12+
class issue_2Test extends TestCase {
13+
14+
const EXPECTED = 'int bar;';
15+
16+
protected CParser $parser;
17+
protected Printer $printer;
18+
19+
public function setUp(): void {
20+
$this->parser = new CParser;
21+
$this->parser->addSearchPath(__DIR__);
22+
$this->parser->addSearchPath(__DIR__ . '/../../include');
23+
$this->printer = new C;
24+
}
25+
26+
/**
27+
* @textdox Test for issue #2
28+
*/
29+
public function testCode() {
30+
$translationUnit = $this->parser->parse(__DIR__ . '/issue_2Test.c');
31+
$actual = $this->printer->print($translationUnit);
32+
$this->assertEquals(self::EXPECTED, trim($actual));
33+
}
34+
}

0 commit comments

Comments
 (0)