4

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

Gianluca Ghettini
  • 11,129
  • 19
  • 93
  • 159
  • 1
    Hi, lead dev of Cheerp here. JS level "variables" are not intended to map to C++ level ones. JS variables are just temporary values which may be mapped to 0, 1 or multiple original variables in C++. Instead of using -cheerp-pretty-code for debugging you could try our SourceMaps support (documented here: https://github.com/leaningtech/cheerp-meta/wiki/In-browser-debugging-with-Source-Maps). With SourceMaps you can see the original C++ code in the browser debugger, but unfortunately variables are not supported by the source maps standard. We hope to provide C++ variables debugging at some point. – alexp Jul 04 '19 at 10:03
  • Note for readers: There is a relevant question [here](https://stackoverflow.com/questions/62378053/how-do-i-interface-with-extern-variables-from-cheerp-js). – Xunie Jun 15 '20 at 12:37

1 Answers1

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.

ruohola
  • 21,987
  • 6
  • 62
  • 97