|
@@ -16,25 +16,29 @@ bool checkBool(Value *value){
|
|
Result ifBranch(INTER_FUNCTIONSIG) {
|
|
Result ifBranch(INTER_FUNCTIONSIG) {
|
|
Result result, else_tmp, finally_tmp;
|
|
Result result, else_tmp, finally_tmp;
|
|
StatementList *if_list = st->u.if_branch.if_list;
|
|
StatementList *if_list = st->u.if_branch.if_list;
|
|
- bool set_result = true;
|
|
|
|
|
|
+ bool set_result = true, is_rego = false;
|
|
|
|
|
|
var_list = pushVarList(var_list, inter);
|
|
var_list = pushVarList(var_list, inter);
|
|
while (if_list != NULL){
|
|
while (if_list != NULL){
|
|
if (if_list->type == if_b){
|
|
if (if_list->type == if_b){
|
|
Result tmp;
|
|
Result tmp;
|
|
- if (operationSafeInterStatement(&tmp, CALL_INTER_FUNCTIONSIG(if_list->condition, var_list))){
|
|
|
|
|
|
+ if (!is_rego && operationSafeInterStatement(&tmp, CALL_INTER_FUNCTIONSIG(if_list->condition, var_list))){
|
|
result = tmp;
|
|
result = tmp;
|
|
set_result = false;
|
|
set_result = false;
|
|
goto not_else;
|
|
goto not_else;
|
|
}
|
|
}
|
|
- if (checkBool(tmp.value->value)){
|
|
|
|
|
|
+ if (is_rego || checkBool(tmp.value->value)){
|
|
Result code_tmp;
|
|
Result code_tmp;
|
|
|
|
+ is_rego = false;
|
|
if (ifBranchSafeInterStatement(&code_tmp, CALL_INTER_FUNCTIONSIG(if_list->code, var_list))){
|
|
if (ifBranchSafeInterStatement(&code_tmp, CALL_INTER_FUNCTIONSIG(if_list->code, var_list))){
|
|
result = code_tmp;
|
|
result = code_tmp;
|
|
set_result = false;
|
|
set_result = false;
|
|
goto not_else;
|
|
goto not_else;
|
|
}
|
|
}
|
|
- goto not_else;
|
|
|
|
|
|
+ if (code_tmp.type == rego_return)
|
|
|
|
+ is_rego = true;
|
|
|
|
+ else
|
|
|
|
+ goto not_else;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
@@ -44,6 +48,8 @@ Result ifBranch(INTER_FUNCTIONSIG) {
|
|
set_result = false;
|
|
set_result = false;
|
|
goto not_else;
|
|
goto not_else;
|
|
}
|
|
}
|
|
|
|
+ if (code_tmp.type == rego_return)
|
|
|
|
+ is_rego = true;
|
|
}
|
|
}
|
|
if_list = if_list->next;
|
|
if_list = if_list->next;
|
|
}
|
|
}
|
|
@@ -67,10 +73,10 @@ Result ifBranch(INTER_FUNCTIONSIG) {
|
|
Result whileBranch(INTER_FUNCTIONSIG) {
|
|
Result whileBranch(INTER_FUNCTIONSIG) {
|
|
Result result, else_tmp, finally_tmp;
|
|
Result result, else_tmp, finally_tmp;
|
|
StatementList *while_list = st->u.while_branch.while_list;
|
|
StatementList *while_list = st->u.while_branch.while_list;
|
|
- bool set_result = true;
|
|
|
|
|
|
+ bool set_result = true, is_break = false;
|
|
|
|
|
|
var_list = pushVarList(var_list, inter);
|
|
var_list = pushVarList(var_list, inter);
|
|
- while (true){
|
|
|
|
|
|
+ while (!is_break){
|
|
Result tmp, do_tmp;
|
|
Result tmp, do_tmp;
|
|
if (operationSafeInterStatement(&tmp, CALL_INTER_FUNCTIONSIG(while_list->condition, var_list))){
|
|
if (operationSafeInterStatement(&tmp, CALL_INTER_FUNCTIONSIG(while_list->condition, var_list))){
|
|
result = tmp;
|
|
result = tmp;
|
|
@@ -85,7 +91,7 @@ Result whileBranch(INTER_FUNCTIONSIG) {
|
|
goto not_else;
|
|
goto not_else;
|
|
}
|
|
}
|
|
if (code_tmp.type == break_return)
|
|
if (code_tmp.type == break_return)
|
|
- goto not_else; // 不会执行else语句
|
|
|
|
|
|
+ is_break = true;
|
|
if (code_tmp.type == continue_return)
|
|
if (code_tmp.type == continue_return)
|
|
PASS;
|
|
PASS;
|
|
}
|
|
}
|
|
@@ -97,8 +103,12 @@ Result whileBranch(INTER_FUNCTIONSIG) {
|
|
set_result = false;
|
|
set_result = false;
|
|
goto not_else;
|
|
goto not_else;
|
|
}
|
|
}
|
|
|
|
+ if (do_tmp.type == break_return)
|
|
|
|
+ goto not_else; // 直接跳转到not_else
|
|
|
|
+ if (do_tmp.type == continue_return)
|
|
|
|
+ PASS;
|
|
}
|
|
}
|
|
- if (st->u.while_branch.else_list != NULL && cycleBranchSafeInterStatement(&else_tmp, CALL_INTER_FUNCTIONSIG(st->u.while_branch.else_list, var_list))){
|
|
|
|
|
|
+ if (!is_break && st->u.while_branch.else_list != NULL && cycleBranchSafeInterStatement(&else_tmp, CALL_INTER_FUNCTIONSIG(st->u.while_branch.else_list, var_list))){
|
|
set_result = false;
|
|
set_result = false;
|
|
result = else_tmp;
|
|
result = else_tmp;
|
|
}
|
|
}
|
|
@@ -120,14 +130,13 @@ Result breakCycle(INTER_FUNCTIONSIG){
|
|
int times_int = 0;
|
|
int times_int = 0;
|
|
if (st->u.break_cycle.times == NULL)
|
|
if (st->u.break_cycle.times == NULL)
|
|
goto not_times;
|
|
goto not_times;
|
|
- if (operationSafeInterStatement(×, CALL_INTER_FUNCTIONSIG(st->u.break_cycle.times, var_list))){
|
|
|
|
|
|
+ if (operationSafeInterStatement(×, CALL_INTER_FUNCTIONSIG(st->u.break_cycle.times, var_list)))
|
|
return times;
|
|
return times;
|
|
- }
|
|
|
|
|
|
+ // TODO-szh 类型检查处理
|
|
times_int = (int)times.value->value->data.num.num;
|
|
times_int = (int)times.value->value->data.num.num;
|
|
not_times:
|
|
not_times:
|
|
setResult(&result, true, inter);
|
|
setResult(&result, true, inter);
|
|
if (times_int >= 0) {
|
|
if (times_int >= 0) {
|
|
- // TODO-szh 类型检查处理
|
|
|
|
result.type = break_return;
|
|
result.type = break_return;
|
|
result.times = times_int;
|
|
result.times = times_int;
|
|
}
|
|
}
|
|
@@ -139,16 +148,45 @@ Result continueCycle(INTER_FUNCTIONSIG){
|
|
int times_int = 0;
|
|
int times_int = 0;
|
|
if (st->u.continue_cycle.times == NULL)
|
|
if (st->u.continue_cycle.times == NULL)
|
|
goto not_times;
|
|
goto not_times;
|
|
- if (operationSafeInterStatement(×, CALL_INTER_FUNCTIONSIG(st->u.continue_cycle.times, var_list))){
|
|
|
|
|
|
+ if (operationSafeInterStatement(×, CALL_INTER_FUNCTIONSIG(st->u.continue_cycle.times, var_list)))
|
|
return times;
|
|
return times;
|
|
- }
|
|
|
|
times_int = (int)times.value->value->data.num.num;
|
|
times_int = (int)times.value->value->data.num.num;
|
|
not_times:
|
|
not_times:
|
|
setResult(&result, true, inter);
|
|
setResult(&result, true, inter);
|
|
if (times_int >= 0) {
|
|
if (times_int >= 0) {
|
|
- // TODO-szh 类型检查处理
|
|
|
|
result.type = continue_return;
|
|
result.type = continue_return;
|
|
result.times = times_int;
|
|
result.times = times_int;
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+Result regoIf(INTER_FUNCTIONSIG){
|
|
|
|
+ Result result, times;
|
|
|
|
+ int times_int = 0;
|
|
|
|
+ if (st->u.rego_if.times == NULL)
|
|
|
|
+ goto not_times;
|
|
|
|
+ if (operationSafeInterStatement(×, CALL_INTER_FUNCTIONSIG(st->u.rego_if.times, var_list)))
|
|
|
|
+ return times;
|
|
|
|
+ times_int = (int)times.value->value->data.num.num;
|
|
|
|
+ not_times:
|
|
|
|
+ setResult(&result, true, inter);
|
|
|
|
+ if (times_int >= 0) {
|
|
|
|
+ result.type = rego_return;
|
|
|
|
+ result.times = times_int;
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Result returnCode(INTER_FUNCTIONSIG){
|
|
|
|
+ Result result;
|
|
|
|
+ if (st->u.return_code.value == NULL) {
|
|
|
|
+ setResult(&result, true, inter);
|
|
|
|
+ goto set_result;
|
|
|
|
+ }
|
|
|
|
+ if (operationSafeInterStatement(&result, CALL_INTER_FUNCTIONSIG(st->u.return_code.value, var_list)))
|
|
|
|
+ return result;
|
|
|
|
+
|
|
|
|
+ set_result:
|
|
|
|
+ result.type = function_return;
|
|
|
|
+ return result;
|
|
|
|
+}
|