diff options
author | Li Jin <dragon-fly@qq.com> | 2022-03-17 11:15:04 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-03-17 11:15:04 +0800 |
commit | 7be6c300256bfe411942a7ccc66f6bc3afa7390d (patch) | |
tree | 82b70608dc79eae1771d0868ceb628450d5556c9 | |
parent | 0055f2fdb169788a7796821d20c7fba2230ea9ae (diff) | |
download | yuescript-7be6c300256bfe411942a7ccc66f6bc3afa7390d.tar.gz yuescript-7be6c300256bfe411942a7ccc66f6bc3afa7390d.tar.bz2 yuescript-7be6c300256bfe411942a7ccc66f6bc3afa7390d.zip |
cleanup.
-rwxr-xr-x | src/yuescript/yue_ast.h | 1 | ||||
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 42 |
2 files changed, 18 insertions, 25 deletions
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index ecf5afc..b5ceac1 100755 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h | |||
@@ -334,7 +334,6 @@ AST_NODE(Try) | |||
334 | AST_END(Try) | 334 | AST_END(Try) |
335 | 335 | ||
336 | class CompInner_t; | 336 | class CompInner_t; |
337 | class Statement_t; | ||
338 | 337 | ||
339 | AST_NODE(Comprehension) | 338 | AST_NODE(Comprehension) |
340 | ast_sel<true, Exp_t, Statement_t> value; | 339 | ast_sel<true, Exp_t, Statement_t> value; |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 047b2ab..4e01c24 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -1069,20 +1069,26 @@ private: | |||
1069 | 1069 | ||
1070 | str_list getAssignVars(ExpListAssign_t* assignment) { | 1070 | str_list getAssignVars(ExpListAssign_t* assignment) { |
1071 | str_list vars; | 1071 | str_list vars; |
1072 | bool lintGlobal = _config.lintGlobalVariable; | ||
1073 | _config.lintGlobalVariable = false; | ||
1072 | if (!assignment->action.is<Assign_t>()) return vars; | 1074 | if (!assignment->action.is<Assign_t>()) return vars; |
1073 | for (auto exp : assignment->expList->exprs.objects()) { | 1075 | for (auto exp : assignment->expList->exprs.objects()) { |
1074 | auto var = singleVariableFrom(exp); | 1076 | auto var = singleVariableFrom(exp); |
1075 | vars.push_back(var.empty() ? Empty : var); | 1077 | vars.push_back(var.empty() ? Empty : var); |
1076 | } | 1078 | } |
1079 | _config.lintGlobalVariable = lintGlobal; | ||
1077 | return vars; | 1080 | return vars; |
1078 | } | 1081 | } |
1079 | 1082 | ||
1080 | str_list getAssignVars(With_t* with) { | 1083 | str_list getAssignVars(With_t* with) { |
1081 | str_list vars; | 1084 | str_list vars; |
1085 | bool lintGlobal = _config.lintGlobalVariable; | ||
1086 | _config.lintGlobalVariable = false; | ||
1082 | for (auto exp : with->valueList->exprs.objects()) { | 1087 | for (auto exp : with->valueList->exprs.objects()) { |
1083 | auto var = singleVariableFrom(exp); | 1088 | auto var = singleVariableFrom(exp); |
1084 | vars.push_back(var.empty() ? Empty : var); | 1089 | vars.push_back(var.empty() ? Empty : var); |
1085 | } | 1090 | } |
1091 | _config.lintGlobalVariable = lintGlobal; | ||
1086 | return vars; | 1092 | return vars; |
1087 | } | 1093 | } |
1088 | 1094 | ||
@@ -4804,13 +4810,13 @@ private: | |||
4804 | out.push_back('(' + join(temp, ", "sv) + ')'); | 4810 | out.push_back('(' + join(temp, ", "sv) + ')'); |
4805 | } | 4811 | } |
4806 | 4812 | ||
4807 | void transformForHead(For_t* forNode, str_list& out) { | 4813 | void transformForHead(Variable_t* var, Exp_t* startVal, Exp_t* stopVal, for_step_value_t* stepVal, str_list& out) { |
4808 | str_list temp; | 4814 | str_list temp; |
4809 | std::string varName = _parser.toString(forNode->varName); | 4815 | std::string varName = _parser.toString(var); |
4810 | transformExp(forNode->startValue, temp, ExpUsage::Closure); | 4816 | transformExp(startVal, temp, ExpUsage::Closure); |
4811 | transformExp(forNode->stopValue, temp, ExpUsage::Closure); | 4817 | transformExp(stopVal, temp, ExpUsage::Closure); |
4812 | if (forNode->stepValue) { | 4818 | if (stepVal) { |
4813 | transformExp(forNode->stepValue->value, temp, ExpUsage::Closure); | 4819 | transformExp(stepVal->value, temp, ExpUsage::Closure); |
4814 | } else { | 4820 | } else { |
4815 | temp.emplace_back(); | 4821 | temp.emplace_back(); |
4816 | } | 4822 | } |
@@ -4818,12 +4824,16 @@ private: | |||
4818 | const auto& start = *it; | 4824 | const auto& start = *it; |
4819 | const auto& stop = *(++it); | 4825 | const auto& stop = *(++it); |
4820 | const auto& step = *(++it); | 4826 | const auto& step = *(++it); |
4821 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : ", "s + step) << " do"sv << nll(forNode); | 4827 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : ", "s + step) << " do"sv << nll(var); |
4822 | pushScope(); | 4828 | pushScope(); |
4823 | forceAddToScope(varName); | 4829 | forceAddToScope(varName); |
4824 | out.push_back(clearBuf()); | 4830 | out.push_back(clearBuf()); |
4825 | } | 4831 | } |
4826 | 4832 | ||
4833 | void transformForHead(For_t* forNode, str_list& out) { | ||
4834 | transformForHead(forNode->varName, forNode->startValue, forNode->stopValue, forNode->stepValue, out); | ||
4835 | } | ||
4836 | |||
4827 | void transform_plain_body(ast_node* body, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { | 4837 | void transform_plain_body(ast_node* body, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { |
4828 | switch (body->getId()) { | 4838 | switch (body->getId()) { |
4829 | case id<Block_t>(): | 4839 | case id<Block_t>(): |
@@ -6041,23 +6051,7 @@ private: | |||
6041 | } | 6051 | } |
6042 | 6052 | ||
6043 | void transformCompFor(CompFor_t* comp, str_list& out) { | 6053 | void transformCompFor(CompFor_t* comp, str_list& out) { |
6044 | str_list temp; | 6054 | transformForHead(comp->varName, comp->startValue, comp->stopValue, comp->stepValue, out); |
6045 | std::string varName = _parser.toString(comp->varName); | ||
6046 | transformExp(comp->startValue, temp, ExpUsage::Closure); | ||
6047 | transformExp(comp->stopValue, temp, ExpUsage::Closure); | ||
6048 | if (comp->stepValue) { | ||
6049 | transformExp(comp->stepValue->value, temp, ExpUsage::Closure); | ||
6050 | } else { | ||
6051 | temp.emplace_back(); | ||
6052 | } | ||
6053 | auto it = temp.begin(); | ||
6054 | const auto& start = *it; | ||
6055 | const auto& stop = *(++it); | ||
6056 | const auto& step = *(++it); | ||
6057 | _buf << indent() << "for "sv << varName << " = "sv << start << ", "sv << stop << (step.empty() ? Empty : ", "s + step) << " do"sv << nll(comp); | ||
6058 | out.push_back(clearBuf()); | ||
6059 | pushScope(); | ||
6060 | forceAddToScope(varName); | ||
6061 | } | 6055 | } |
6062 | 6056 | ||
6063 | void transformTableBlockIndent(TableBlockIndent_t* table, str_list& out) { | 6057 | void transformTableBlockIndent(TableBlockIndent_t* table, str_list& out) { |