diff options
author | Li Jin <dragon-fly@qq.com> | 2024-09-28 09:33:54 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2024-09-28 09:33:54 +0800 |
commit | d6d29a4288b96d42c7cabf424beb286bfbd24456 (patch) | |
tree | 6e29d7111725ca97077bb58d42b993200e13cea8 /src | |
parent | 7575fe00aad91e0ba943e877ddcd838f76e095c0 (diff) | |
download | yuescript-d6d29a4288b96d42c7cabf424beb286bfbd24456.tar.gz yuescript-d6d29a4288b96d42c7cabf424beb286bfbd24456.tar.bz2 yuescript-d6d29a4288b96d42c7cabf424beb286bfbd24456.zip |
Removed useless `do` block in `with`.
Diffstat (limited to 'src')
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index c346891..b44b697 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
76 | }; | 76 | }; |
77 | 77 | ||
78 | const std::string_view version = "0.25.2"sv; | 78 | const std::string_view version = "0.25.3"sv; |
79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
80 | 80 | ||
81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
@@ -9154,33 +9154,35 @@ private: | |||
9154 | transformIf(ifNode, temp, ExpUsage::Common); | 9154 | transformIf(ifNode, temp, ExpUsage::Common); |
9155 | } else { | 9155 | } else { |
9156 | bool transformed = false; | 9156 | bool transformed = false; |
9157 | if (auto block = with->body.as<Block_t>()) { | 9157 | if (assignList || returnValue) { |
9158 | if (!block->statements.empty()) { | 9158 | if (auto block = with->body.as<Block_t>()) { |
9159 | Statement_t* stmt = static_cast<Statement_t*>(block->statements.back()); | 9159 | if (!block->statements.empty()) { |
9160 | Statement_t* stmt = static_cast<Statement_t*>(block->statements.back()); | ||
9161 | if (stmt->content.is<Return_t>()) { | ||
9162 | auto newBlock = with->body->new_ptr<Block_t>(); | ||
9163 | newBlock->statements.dup(block->statements); | ||
9164 | newBlock->statements.pop_back(); | ||
9165 | transform_plain_body(newBlock, temp, ExpUsage::Common); | ||
9166 | auto newBody = stmt->new_ptr<Body_t>(); | ||
9167 | newBody->content.set(stmt); | ||
9168 | auto doNode = stmt->new_ptr<Do_t>(); | ||
9169 | doNode->body.set(newBody); | ||
9170 | transformDo(doNode, temp, ExpUsage::Common); | ||
9171 | transformed = true; | ||
9172 | } | ||
9173 | } | ||
9174 | } else { | ||
9175 | auto stmt = with->body.to<Statement_t>(); | ||
9160 | if (stmt->content.is<Return_t>()) { | 9176 | if (stmt->content.is<Return_t>()) { |
9161 | auto newBlock = with->body->new_ptr<Block_t>(); | ||
9162 | newBlock->statements.dup(block->statements); | ||
9163 | newBlock->statements.pop_back(); | ||
9164 | transform_plain_body(newBlock, temp, ExpUsage::Common); | ||
9165 | auto newBody = stmt->new_ptr<Body_t>(); | 9177 | auto newBody = stmt->new_ptr<Body_t>(); |
9166 | newBody->content.set(stmt); | 9178 | newBody->content.set(stmt); |
9167 | auto doNode = stmt->new_ptr<Do_t>(); | 9179 | auto doNode = stmt->new_ptr<Do_t>(); |
9168 | doNode->body.set(newBody); | 9180 | doNode->body.set(newBody); |
9169 | transformDo(doNode, temp, ExpUsage::Common); | 9181 | transformDo(doNode, temp, ExpUsage::Common); |
9182 | temp.back().insert(0, indent()); | ||
9170 | transformed = true; | 9183 | transformed = true; |
9171 | } | 9184 | } |
9172 | } | 9185 | } |
9173 | } else { | ||
9174 | auto stmt = with->body.to<Statement_t>(); | ||
9175 | if (stmt->content.is<Return_t>()) { | ||
9176 | auto newBody = stmt->new_ptr<Body_t>(); | ||
9177 | newBody->content.set(stmt); | ||
9178 | auto doNode = stmt->new_ptr<Do_t>(); | ||
9179 | doNode->body.set(newBody); | ||
9180 | transformDo(doNode, temp, ExpUsage::Common); | ||
9181 | temp.back().insert(0, indent()); | ||
9182 | transformed = true; | ||
9183 | } | ||
9184 | } | 9186 | } |
9185 | if (!transformed) { | 9187 | if (!transformed) { |
9186 | transform_plain_body(with->body, temp, ExpUsage::Common); | 9188 | transform_plain_body(with->body, temp, ExpUsage::Common); |