andry-tino / Rosetta

Toolset for migrating your codebase from C# to TypeScript
http://antino-enlad.cloudapp.net:8080/job/Rosetta/
GNU General Public License v3.0
24 stars 9 forks source link

Semantic-safe AST transformation for ScriptNamespace handling #22

Closed andry-tino closed 7 years ago

andry-tino commented 7 years ago

Change 86060aa has purposely broken the transformer which had to be deactivate in that same change. Issue #19 has been tracking the feature. This issue arises as a continuation of that and aims to fix the transformer in order to fix the ScriptNamespace attribute handling which is, currently, broken.

Problem

A problem arises concerning syntax transformation.

What Issue is that after transforming, the syntax tree is different and does not correspond anymore to the semantic model.

Solution

A mixture of the mapping approach and the semantic model update.

Available types in AST At transformation time, we transform the AST and then generate an updated model. This will deal with the types available in the local AST (a small part represented in the semantic model). See:

Referenced unavailable types We still have a problem concerning types referenced by the local AST but not available. The semantic model will refer to them using the not overriden namespace, while we should actually use the overridden one.

To accommodate this, helpers (when provided with semantic model), when providing the full name or every namespace-related quantity, will check the presence of the ScriptNamespace attribute and override the name accordingly. This will impact ONLY helpers in the ScriptSharp Definition area.

Challenge: semantic misalignment

After transforming and updating the semantic model reports a lot of errors relating to missing assemblies.

Solution Collect all using directives and copy in the root level of the new node or in the single namespaces created for each moved type. It is also important to include the namespace of the moved entities in order to have proper semantic alignment for them.

andry-tino commented 7 years ago

This is both an enhancement, in order to deal with overridden names in referenced types (unavailable in AST but available in semantic model, when latter is provided), and a bug (regression) since the transformation is now not taking place anymore.

andry-tino commented 7 years ago

The semantic misalignment problem should have been solved by placing using directives in the new AST. But that is not working for some reason. Need to move on with a temporary solution:

  1. Make AST transformation in order to have proper output in code.
  2. DO update SemanticModel. Keep using original one.
  3. For referenced types, same solution as before, check in semantic model the presence of ScriptNamespace and emit an overridden FullName.
  4. For defined/declared types in the local AST, the updating of the SemanticModel in 2 will fix these nodes which should be emitted fine.

Important Regarding point 4: A cache is not needed for defined symbols in local AST. If we add usings for namespaces of entities that have been placed in different namespace, then we are all right.

andry-tino commented 7 years ago

Current state is good. Semantic alignment still need a little more tuning but the fundamental structure is in place now.