diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-12-29 09:59:47 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-12-29 09:59:47 +0800 |
| commit | 603ecbc22bc37378ed3ea1a8abf74fb2dc2329af (patch) | |
| tree | ddb97404b94b81e87ab77833a6ec15b611c38751 /src | |
| parent | dba662758192b41648e6c1201083d83926f07783 (diff) | |
| download | yuescript-603ecbc22bc37378ed3ea1a8abf74fb2dc2329af.tar.gz yuescript-603ecbc22bc37378ed3ea1a8abf74fb2dc2329af.tar.bz2 yuescript-603ecbc22bc37378ed3ea1a8abf74fb2dc2329af.zip | |
prevent using declared global variables as temporary inline variables.
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 42310b2..db59c08 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -71,7 +71,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
| 71 | "close"s // Lua 5.4 | 71 | "close"s // Lua 5.4 |
| 72 | }; | 72 | }; |
| 73 | 73 | ||
| 74 | const std::string_view version = "0.15.19"sv; | 74 | const std::string_view version = "0.15.20"sv; |
| 75 | const std::string_view extension = "yue"sv; | 75 | const std::string_view extension = "yue"sv; |
| 76 | 76 | ||
| 77 | class YueCompilerImpl { | 77 | class YueCompilerImpl { |
| @@ -417,6 +417,19 @@ private: | |||
| 417 | return isDefined; | 417 | return isDefined; |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | bool isSolidDefined(const std::string& name) const { | ||
| 421 | bool defined = false; | ||
| 422 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { | ||
| 423 | auto vars = it->vars.get(); | ||
| 424 | auto vit = vars->find(name); | ||
| 425 | if (vit != vars->end()) { | ||
| 426 | defined = true; | ||
| 427 | break; | ||
| 428 | } | ||
| 429 | } | ||
| 430 | return defined; | ||
| 431 | } | ||
| 432 | |||
| 420 | bool isLocal(const std::string& name) const { | 433 | bool isLocal(const std::string& name) const { |
| 421 | bool local = false; | 434 | bool local = false; |
| 422 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { | 435 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { |
| @@ -526,7 +539,7 @@ private: | |||
| 526 | do { | 539 | do { |
| 527 | newName = nameStr + std::to_string(index); | 540 | newName = nameStr + std::to_string(index); |
| 528 | index++; | 541 | index++; |
| 529 | } while (isLocal(newName)); | 542 | } while (isSolidDefined(newName)); |
| 530 | return newName; | 543 | return newName; |
| 531 | } | 544 | } |
| 532 | 545 | ||
