aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-12-29 09:59:47 +0800
committerLi Jin <dragon-fly@qq.com>2022-12-29 09:59:47 +0800
commit603ecbc22bc37378ed3ea1a8abf74fb2dc2329af (patch)
treeddb97404b94b81e87ab77833a6ec15b611c38751
parentdba662758192b41648e6c1201083d83926f07783 (diff)
downloadyuescript-603ecbc22bc37378ed3ea1a8abf74fb2dc2329af.tar.gz
yuescript-603ecbc22bc37378ed3ea1a8abf74fb2dc2329af.tar.bz2
yuescript-603ecbc22bc37378ed3ea1a8abf74fb2dc2329af.zip
prevent using declared global variables as temporary inline variables.
-rw-r--r--src/yuescript/yue_compiler.cpp17
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
74const std::string_view version = "0.15.19"sv; 74const std::string_view version = "0.15.20"sv;
75const std::string_view extension = "yue"sv; 75const std::string_view extension = "yue"sv;
76 76
77class YueCompilerImpl { 77class 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