maekitalo / tntnet

GNU Lesser General Public License v2.1
74 stars 35 forks source link

Generated code for application-wide variables has unused typedef #48

Closed jplatte closed 4 years ago

jplatte commented 9 years ago

This bit of ECPP

<%application scope="shared">
    GlobalConf a_conf;
</%application>

results is this generated C++

  typedef GlobalConf a_conf_type;
  TNT_APPLICATION_SHARED_VAR(GlobalConf, a_conf, ());   // <%application> GlobalConf a_conf

where the typedef isn't actually used. I suppose it's meant to be used as the first argument for TNT_APPLICATION_SHARED_VAR?

maekitalo commented 9 years ago

Good point. The idea is, that you have the actual type of your variable as a typedef by appending _type to the variable name. It is undocumented and I feel, that it is not too useful. Nowadays there are better C++11 features like the auto type for that.

maekitalo commented 9 years ago

I looked at it again and I've once changed that, so that the typedef is only used when needed. It is really needed when the type itself contains a comma like "std::map<int, int>". Then the macro do not work as needed. As I remember there was a problem when the typedef is used but I don't remember what the problem really was.

jplatte commented 9 years ago

I checked what eccpc would do when I added a variable std::basic_string<char, std::char_traits<char>> (which is equivalent to std::string). It used the typedef as the first argument for TNT_APPLICATION_SHARED_VAR and compilation worked.

I think the typedef should just be used independently of whether the type has commas in it or not.

maekitalo commented 9 years ago

As I wrote ecpp uses the typedef when needed. An if the type itself has a comma, the typedef is used. Look at your generated cpp in your example. I'm sure you can see, that the typedef is used here.

See the code in tntnet at sdk/tools/ecppc/scopevar.cpp line 83. There ecppc checks whether a comma is found in the type.

jplatte commented 9 years ago

Yeah of course I can see that. But it doesn't make any sense to generate the typedef unconditionally, and then only use it when needed. Either use it in every case, or only generate it when it's actually used.