__run.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "__run.h"
  2. ResultType getBaseVarInfo(char **name, int *times, INTER_FUNCTIONSIG){
  3. LinkValue *value;
  4. *name = setStrVarName(st->u.base_var.name, false, inter, var_list);
  5. *times = 0;
  6. if (st->u.base_var.times == NULL){
  7. *times = 0;
  8. goto not_times;
  9. }
  10. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.base_var.times, var_list, result, father)))
  11. return result->type;
  12. if (!isType(result->value->value, number)){
  13. setResultErrorSt(result, inter, "TypeException", "Don't get a number value", st, father, true);
  14. return result->type;
  15. }
  16. *times = (int)result->value->value->data.num.num;
  17. freeResult(result);
  18. not_times:
  19. value = makeLinkValue(makeStringValue(st->u.base_var.name, inter), father, inter);
  20. setResultOperation(result, value);
  21. return result->type;
  22. }
  23. ResultType getBaseSVarInfo(char **name, int *times, INTER_FUNCTIONSIG){
  24. freeResult(result);
  25. if (st->u.base_svar.times == NULL){
  26. *times = 0;
  27. goto not_times;
  28. }
  29. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.base_svar.times, var_list, result, father)))
  30. return result->type;
  31. if (!isType(result->value->value, number)){
  32. setResultErrorSt(result, inter, "TypeException", "Don't get a number value", st, father, true);
  33. return result->type;
  34. }
  35. *times = (int)result->value->value->data.num.num;
  36. freeResult(result);
  37. not_times:
  38. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.base_svar.name, var_list, result, father)))
  39. return result->type;
  40. *name = getNameFromValue(result->value->value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  41. result->type = operation_return; // 执行 operationSafeInterStatement 的时候已经初始化 result
  42. return result->type;
  43. }
  44. ResultType getVarInfo(char **name, int *times, INTER_FUNCTIONSIG){
  45. if (st->type == base_var)
  46. getBaseVarInfo(name, times, CALL_INTER_FUNCTIONSIG(st, var_list, result, father));
  47. else if (st->type == base_svar)
  48. getBaseSVarInfo(name, times, CALL_INTER_FUNCTIONSIG(st, var_list, result, father));
  49. else{
  50. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st, var_list, result, father)))
  51. return result->type;
  52. *name = getNameFromValue(result->value->value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  53. *times = 0;
  54. }
  55. return result->type;
  56. }
  57. char *setStrVarName(char *old, bool free_old, INTER_FUNCTIONSIG_CORE) {
  58. return memStrcat(inter->data.var_str_prefix, old, false, free_old);
  59. }
  60. char *setNumVarName(NUMBER_TYPE num, INTER_FUNCTIONSIG_CORE) {
  61. char name[50];
  62. snprintf(name, 50, "%"NUMBER_FORMAT, num);
  63. return memStrcat(inter->data.var_num_prefix, name, false, false);
  64. }
  65. char *getNameFromValue(Value *value, INTER_FUNCTIONSIG_CORE) {
  66. switch (value->type){
  67. case string:
  68. return setStrVarName(value->data.str.str, false, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  69. case number:
  70. return setNumVarName(value->data.num.num, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  71. default:
  72. return memStrcpy(inter->data.var_defualt);
  73. }
  74. }