Search code examples
javascriptc++transpilercheerp

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


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


Solution

  • 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.