Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit definition files via DLL and without source code #41

Closed
andry-tino opened this issue Mar 22, 2017 · 3 comments
Closed

Emit definition files via DLL and without source code #41

andry-tino opened this issue Mar 22, 2017 · 3 comments

Comments

@andry-tino
Copy link
Owner

andry-tino commented Mar 22, 2017

Rosetta ScriptSharp Definition Generator can work on DLLs only instead of using source files.

Scenarios

Can be used in contexts where:

  • The source code is not available

Benefits

Can cut down dependencies on code.

Downsides

Comments and documentation not available for emitting.

Plan

It is necessary to decouple the ScriptSharp generation components from AST Walkers as not needed. Also more work needed:

  • Decouple AST
  • Generate components for enumerating types in DLL and get the tree from the SemanticModel.
  • Reuse helpers for extracting data from the SemanticModel, here we might get issues as helpers are depending on SyntaxNodes
  • Reuse TranslationUnits as they are

Important Evaluate the possibility to generate AST and then feed it to the regular stack.

@andry-tino andry-tino self-assigned this Mar 22, 2017
andry-tino added a commit that referenced this issue Apr 3, 2017
This pack introduced the ability to generate the signature AST from an
assembly to be used for generating definition files in future without
the need for code, just the assembly.

Targets #41
andry-tino added a commit that referenced this issue Apr 7, 2017
Adding tests too.

Targets #41
andry-tino added a commit that referenced this issue Apr 7, 2017
@andry-tino
Copy link
Owner Author

andry-tino commented Apr 9, 2017

A problem occurs in terms of API after this will be completed: 3 ways will be available for generating definition files:

  1. From source code: code driven (pure syntax)
  2. From source code and assembly: code driven (with semantic model)
  3. From assembly: assembly driven

Scenarios

Scenario-wise, we have conflicts as we need to serve the following ones:

  • Generate definitions when source is available.
  • Generate definitions when assembly is available.

When both assembly and source are available, we fall in the second scenario, thus the code is not really necessary. Only possible difference might be the code structure.

Deprecation required

Ideally, we need to deprecate API for possibility no. 2. This has to be considered in the future.

Current solution

The 3 different strategies will be triggered as follows:

  1. When source files are provided: use code driven pure syntax generation.
  2. When source code and assembly are provided: use code driven with semantic model.
  3. When no source code is provided but assembly is provided: use assembly driven (reflection).

andry-tino added a commit that referenced this issue Apr 9, 2017
Tests added by extending the build task example project.
Extended runner in ScriptSharp for keeping into account the assembly.

Attention: The runner does not work because the assembly is not loaded
into the inspection only context and all reference errors are surfacing.
This must be fixed in later pack.

Targets #41
andry-tino added a commit that referenced this issue Apr 10, 2017
Assebly now correctly loaded. Also added IAssemblyLoader for abstracting
loading capabilities.

Targets #41
@andry-tino
Copy link
Owner Author

andry-tino commented May 8, 2017

Problems encountered for loading assemblies and deps:

Mono.cecil

Because of all the issues encountered so far, it has been decided to take a dependency on Mono.cecil.

andry-tino referenced this issue May 11, 2017
This change modifies a little the architecture around Reflection.

- Using Mono.Cecil for reflecting assemblies
- Added assembly abstraction layer in order to limit the use of Cecil to
one single project only (avoiding dep spreading across the product and
tests)
- Added layer for assembly loading strategies

Verified that assemblies are correctly loaded without any need to load
external dependencies on that one. IL parsing executed fine and
attribute info available.

Unfortunately `System.Reflection` triggers many problems:
- If the assembly is loaded in reflection-only-context,
custom-attributes are not available.
- In order to have custom-attributes available, tried loading assembly
in normal exec context. Failure occurs as the assembly references other
assemblies (`mscorlib` and `Script.Import.dll`) which cannot be found.
andry-tino added a commit that referenced this issue May 16, 2017
Introduding support for object creation expressions with renderers and
tests targeting the most basic scenario: parameterless object
construction.

This is related to #41 as the generation of the AST in `ASTBuilder`
needs the creation of empty block codes where we emit `throw new
NotImplementedException()`. SO far the object creation expression was
not supported, thus leading to issues here.
andry-tino referenced this issue May 17, 2017
Added tests for class and methods (factories).
andry-tino added a commit that referenced this issue May 17, 2017
Helper method `BaseTypeReference.Name` was returning sometimes the type
full name. This was interfering with
`SeparateClassAndInterfacesBasedOnNames` as the routine expects pure
names, no namespaces. Applied namespace stripping.

Targets #41
andry-tino added a commit that referenced this issue May 17, 2017
The ScriptSharp definitino generator with reflection is using the normal
ASTWalker, it must use the ScriptSharpDefinitionASTWalker instead.
Rewired.

Targets #41
andry-tino added a commit that referenced this issue May 17, 2017
When generating the AST in Reflection, the System.Object base class
should be ignored.

Targets #41
andry-tino added a commit that referenced this issue May 18, 2017
The generation of AST from assembly was failing because the semantic
model was computed on the original assembly. Because of the
ScriptNamespace, the AST generator will change the AST from the original
one in the assembly, this was causing a misalignment in the semantic
model being used and, at AST walking time, the ScriptNamespace attribute
was detected wrongly.

Fixed the issue and also got rid of the raw assembly in reflcetion.

Targets #41
andry-tino added a commit that referenced this issue May 18, 2017
Reflection proxies were returning constructors among methods, thus
leading to the generartion of `.ctor` methods in the definition file.

Targets #41

Targets #41
andry-tino added a commit that referenced this issue May 18, 2017
Class AST node factory was ignoring constructors. Added support and
added tests too.

Targets #41
andry-tino added a commit that referenced this issue May 18, 2017
Interfaces in ScriptSharp definition generation are not emitted at full!
Only the interface name and base list.

Targets #41
andry-tino added a commit that referenced this issue May 18, 2017
Since Mono.Cecil parses IL, getters and setters are seen as methods.
Filter them out in factories and proxies.

Targets #41
andry-tino added a commit that referenced this issue May 18, 2017
Properties were not supported. Adding it with tests.

Targets #41
andry-tino added a commit that referenced this issue Jun 7, 2017
Commit 428b0c5 has wrong wiring up of
interface generation stack in ASTBuilder. Fixing that.

Targets #41
andry-tino added a commit that referenced this issue Jun 8, 2017
Reflection to support enums.
Added tests.

Targets #41
@andry-tino
Copy link
Owner Author

andry-tino commented Jun 8, 2017

Bug

The generated code correctly defines type in overridden namespaces but references to those types still use the old namespace.

Root cause

The issue is in factories. ASTBuilder correctly handles the type declaration by encapsulating it in a namespace, however factories generate type references without caring about the ScriptNamespace attribute.

andry-tino added a commit that referenced this issue Jun 12, 2017
The ScriptSharp definition reflector was not building the correst AST as
type references were not considering the ScriptNamespace override. Only
definition of types were, but references to types were using the
original full name,

Targets #41
@andry-tino andry-tino moved this from In progress to Completed in ScriptSharp definition generation Level-0 Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment