Skip to content

Commit a483f1f

Browse files
committed
unified compilation order
1 parent 0457121 commit a483f1f

File tree

7 files changed

+72
-73
lines changed

7 files changed

+72
-73
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44
[*]
55
charset = utf-8
66
indent_style = tab
7-
indent_size = 3
7+
indent_size = 4
88
end_of_line = lf
99
insert_final_newline = true
1010
trim_trailing_whitespace = true

compiler/Compiler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ private function set_paths(Unit $unit, string $unit_path)
148148
array_unshift($dir_names, $dir_name);
149149
}
150150

151-
$this->unit_path = $unit_path;
152-
153151
if (self::is_framework_internal_namespaces($unit->ns)) {
154152
// 框架内部名称空间,其base_path应为往上一级
155153
$this->base_path = $checking_path . DS;
@@ -161,8 +159,10 @@ private function set_paths(Unit $unit, string $unit_path)
161159
$this->super_path = $checking_path . DS;
162160
}
163161

162+
$this->unit_path = $unit_path;
163+
164164
$unit_dir = join(DS, $dir_names);
165-
$this->unit_dist_path = $this->get_unit_dist_path($unit_dir, $this->base_path);
165+
$this->unit_dist_path = $this->get_unit_dist_path($unit_dir);
166166
$this->unit_dist_path_len = strlen($this->unit_dist_path);
167167
}
168168

@@ -476,6 +476,9 @@ private function glob_program_files()
476476
$files[] = $path;
477477
}
478478

479+
// 排序以保障在所有情况下顺序一致
480+
sort($files);
481+
479482
return $files;
480483
}
481484

@@ -534,9 +537,9 @@ private function parse_header(string $file_path, ASTFactory $ast_factory)
534537
return $program;
535538
}
536539

537-
private function get_unit_dist_path(string $unit_dir_name, string $base_path)
540+
private function get_unit_dist_path(string $unit_dir_name)
538541
{
539-
$dist_path = $base_path . 'dist';
542+
$dist_path = $this->base_path . 'dist';
540543
if (!is_dir($dist_path)) {
541544
throw new Exception("The dist dir '{$dist_path}' not found.");
542545
}

compiler/helper/TeaInitializer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ public function process()
1919
$unit_dir = $this->uri;
2020

2121
// create the unit dir
22-
if (!is_dir($unit_dir)) {
23-
FileHelper::mkdir($unit_dir);
24-
}
22+
is_dir($unit_dir) or FileHelper::mkdir($unit_dir);
2523

2624
// create the dist dir
2725
$dist_dir = $this->domain . '/dist';
28-
if (!is_dir($dist_dir)) {
29-
FileHelper::mkdir($dist_dir);
30-
}
26+
is_dir($dist_dir) or FileHelper::mkdir($dist_dir);
3127

3228
// the __unit.th
3329
$header_file = $unit_dir . '/__unit.th';

dist/tests/syntax/__public.th

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
public __CLASS__ String
66

7-
public xrange(start Int, stop Int, step UInt = 1)
7+
public get_class() Class
88

9-
#php range(start Int, end Int, step UInt = 1) Array
9+
public fn0(str Any)
1010

11-
#php var_dump(v Any)
11+
public xrange(start Int, stop Int, step UInt = 1)
1212

13-
public get_class() Class
13+
#php var_dump(v Any)
1414

15-
public fn0(str Any)
15+
#php range(start Int, end Int, step UInt = 1) Array
1616

1717
public DemoList: BaseView {
1818
ABC String = '12'

dist/tests/syntax/__unit.php

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,33 @@
1111
require_once $super_path . 'tea/dist/tests/xview/__unit.php';
1212
require_once $super_path . 'tea/tests/PHPDemoUnit/__unit.php';
1313

14-
/*internal*/ const PI = 3.1415926;
1514

15+
/*internal*/ const PI = 3.1415926;
1616

17-
function new_collector_demo(): CollectorDemo
17+
function get_class(): string
1818
{
19-
return new CollectorDemo();
19+
return Test1::class;
2020
}
2121

22-
function collector1(): array
22+
function fn0($str)
2323
{
24-
$__collects = [];
25-
$__collects[] = '<div>hei~</div>';
26-
27-
new CollectorDemo();
28-
29-
(new CollectorDemo())->subnode->text('red')->subnode = new_collector_demo();
30-
31-
$abc = new CollectorDemo();
32-
33-
$factory = new CollectorDemoFactory();
34-
35-
new_collector_demo();
36-
$factory->new_collector_demo();
24+
echo $str, NL;
25+
}
3726

38-
if (1) {
39-
(new CollectorDemo())->text('red')->subnode->text('hei~');
40-
}
27+
function fn1(callable $callee)
28+
{
29+
$unknow_type_value = $callee('hei');
30+
}
4131

42-
foreach ([1, 2, 3] as $item) {
43-
(new CollectorDemo())->subnode->text('hello');
44-
}
32+
function fn2(string $class)
33+
{
34+
$class();
35+
}
4536

46-
return $__collects;
37+
function fn3(\Exception $ex, string $num = null)
38+
{
39+
$num = 1;
40+
echo $ex->getMessage(), NL;
4741
}
4842

4943
function xrange(int $start, int $stop, int $step = 1)
@@ -71,42 +65,43 @@ function xrange(int $start, int $stop, int $step = 1)
7165
}
7266
}
7367

74-
function get_class(): string
68+
function new_collector_demo(): CollectorDemo
7569
{
76-
return Test1::class;
70+
return new CollectorDemo();
7771
}
7872

79-
function fn0($str)
73+
function collector1(): array
8074
{
81-
echo $str, NL;
82-
}
75+
$__collects = [];
76+
$__collects[] = '<div>hei~</div>';
8377

84-
function fn1(callable $callee)
85-
{
86-
$unknow_type_value = $callee('hei');
87-
}
78+
new CollectorDemo();
8879

89-
function fn2(string $class)
90-
{
91-
$class();
92-
}
80+
(new CollectorDemo())->subnode->text('red')->subnode = new_collector_demo();
9381

94-
function fn3(\Exception $ex, string $num = null)
95-
{
96-
$num = 1;
97-
echo $ex->getMessage(), NL;
82+
$abc = new CollectorDemo();
83+
84+
$factory = new CollectorDemoFactory();
85+
86+
new_collector_demo();
87+
$factory->new_collector_demo();
88+
89+
if (1) {
90+
(new CollectorDemo())->text('red')->subnode->text('hei~');
91+
}
92+
93+
foreach ([1, 2, 3] as $item) {
94+
(new CollectorDemo())->subnode->text('hello');
95+
}
96+
97+
return $__collects;
9898
}
9999

100100

101101
// program end
102102

103103
# --- generates ---
104104
const __AUTOLOADS = [
105-
'tea\tests\syntax\CollectorDemo' => 'type-collector.php',
106-
'tea\tests\syntax\CollectorDemoFactory' => 'type-collector.php',
107-
'tea\tests\syntax\TeaDemoClass' => 'main1.php',
108-
'tea\tests\syntax\Cell' => 'type-xview.php',
109-
'tea\tests\syntax\DemoList' => 'type-xview.php',
110105
'tea\tests\syntax\IDemo' => 'class.php',
111106
'tea\tests\syntax\IDemoTrait' => 'class.php',
112107
'tea\tests\syntax\BaseClass' => 'class.php',
@@ -115,7 +110,12 @@ function fn3(\Exception $ex, string $num = null)
115110
'tea\tests\syntax\ITest' => 'class.php',
116111
'tea\tests\syntax\Test3' => 'class.php',
117112
'tea\tests\syntax\Test4' => 'class.php',
118-
'tea\tests\syntax\Test5' => 'class.php'
113+
'tea\tests\syntax\Test5' => 'class.php',
114+
'tea\tests\syntax\TeaDemoClass' => 'main1.php',
115+
'tea\tests\syntax\CollectorDemo' => 'type-collector.php',
116+
'tea\tests\syntax\CollectorDemoFactory' => 'type-collector.php',
117+
'tea\tests\syntax\Cell' => 'type-xview.php',
118+
'tea\tests\syntax\DemoList' => 'type-xview.php'
119119
];
120120

121121
spl_autoload_register(function ($class) {

dist/tests/xview/__public.th

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
#unit tea/tests/xview
44

5-
public IViewDemo: IView {
6-
name String
7-
css_class String
8-
9-
set_css_class(names String) IViewDemo
10-
}
11-
125
public BaseView: IView {
136
name String
147

@@ -28,4 +21,11 @@ public BaseView: IView {
2821
to_string() String
2922
}
3023

24+
public IViewDemo: IView {
25+
name String
26+
css_class String
27+
28+
set_css_class(names String) IViewDemo
29+
}
30+
3131
// program end

dist/tests/xview/__unit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
# --- generates ---
99
const __AUTOLOADS = [
10+
'tea\tests\xview\BaseView' => 'BaseView.php',
1011
'tea\tests\xview\IViewDemo' => 'IViewDemo.php',
11-
'tea\tests\xview\IViewDemoTrait' => 'IViewDemo.php',
12-
'tea\tests\xview\BaseView' => 'BaseView.php'
12+
'tea\tests\xview\IViewDemoTrait' => 'IViewDemo.php'
1313
];
1414

1515
spl_autoload_register(function ($class) {

0 commit comments

Comments
 (0)