How to preserve variable name in Cheerp (a C++ to JavaScript transpiler)

耗尽温柔 提交于 2020-06-25 21:48:58

问题


I'm using Cheerp (https://www.leaningtech.com/cheerp/) to transpile some C++ code into JavaScript. Is there any option to preserve variable names? Looks like the names get always mangled

Original C++ code:

void myClass::myMethod(int32_T myParam, boolean_T *rty_Result)
{

  switch (myParam) {
   case Mycase1:
   case Mycase2:
   case Mycase3:
   case Mycase4:
   case Mycase5:

    *rty_Result = true;
    break;

   case Mycase6:

    *rty_Result = (filter.field1.field2 == 1);
    break;

   default:
    *rty_Result = false;
    break;
  }
}

Output from Cheerp:

function __ZN8JsBridge12AvailabilityEP9bFilter_Ti(Lthis,filter,myParam){
    var tmp0=0;
    switch(myParam|0){
        case 5:
        {
            tmp0=filter.a3.i2|0;
            return (((tmp0|0)===1?1:0)?1:0)|0;
            break;
        }
        case 1:
        case 2:
        case 4:
        case 6:
        case 3:
        {
            return 1|0;
            break;
        }
        default:{
            return 0|0;
            break;
        }
    }
}

I don't find any options in the documentation: https://github.com/leaningtech/cheerp-meta/wiki


回答1:


You can try to pass the option:

-cheerp-pretty-code

Source: https://github.com/leaningtech/cheerp-meta/wiki/JavaScript-interoperability#clobbering-names

If that doesn't work, then I'm quite sure that this just unfortunately cannot be accomplished.



来源:https://stackoverflow.com/questions/56853261/how-to-preserve-variable-name-in-cheerp-a-c-to-javascript-transpiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!