Frege / frege-native-gen

Frege code generator for Java classes
17 stars 9 forks source link

Name collisions #6

Closed trilogysci closed 9 years ago

trilogysci commented 9 years ago

While running on a large set of classes I can across a number of name issues and generation issues.

Additionally would it be possible to have a whitelist of allowable classes and exclude generating code which references classes not in the list?

mmhelloworld commented 9 years ago

1) I also found out this issue few days ago. For abstract classes, we shouldn't generate any constructors. 2) & 3) need to be fixed as well.

would it be possible to have a whitelist of allowable classes and exclude generating code which references classes not in the list?

This is actually a good idea. Rather than assuming the missing classes as pure, we could as well not generate any code for those that reference them.

Ingo60 commented 9 years ago

While we are at it, ...

I noted that for pure native types the constructor gets generated as ST action. See this commit 2823f52091ccf13c4550fb16e06905f0e4098ce7 for an example.

While it is possible that we can get at a pure value only through impure actions, it will not be so in most cases. So this is not an error but just ultra-conservative.

I feel we could safely generate pure native new in many cases, unless other mutable data, exceptions etc. are involved, of course.

The follwoing rule most likely gives the correct results: When a ST phantom type s (and, of course, RealWorld) is not needed anywhere in the signature, then we can as well make it pure. Because, when the tool generates:

new :: String -> ST s Locale    -- for example     

one can always write a helper function:

purenew s = ST.run (new s)

to re-establish purity.

Honestly, if we know that some Java constructor uses global, observable mutable state, we must even make the constructor an IO action. Because ST s deals only with temporary, local (so to speak) state.

mmhelloworld commented 9 years ago

I feel we could safely generate pure native new in many cases, unless other mutable data, exceptions etc. are involved, of course.

Thanks Ingo! It definitely makes sense. I have created a new issue for this: https://github.com/Frege/native-gen/issues/7.

mmhelloworld commented 9 years ago

This issue is now partially fixed.

  1. Constructors for abstract classes are now not generated
  2. Frege keywords are now handled. If a Java class member results in a Frege keyword, it is now prefixed with j and suffixed with '

The only outstanding issue is to handle collision between static and instance methods (item# 2 in the original issue description).