Skip to content

Commit

Permalink
ScriptSharp definition generator is using normal ASTWalker
Browse files Browse the repository at this point in the history
The ScriptSharp definitino generator with reflection is using the normal
ASTWalker, it must use the ScriptSharpDefinitionASTWalker instead.
Rewired.

Targets #41
  • Loading branch information
andry-tino committed May 17, 2017
1 parent d440732 commit e4a5e91
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Reflection.ScriptSharp/ProgramWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ namespace Rosetta.Reflection.ScriptSharp
using System;
using System.IO;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

using Rosetta.AST;
using Rosetta.Reflection.Proxies;
using Rosetta.ScriptSharp.Definition.AST;

/// <summary>
/// Initiates the translation.
Expand All @@ -25,5 +30,7 @@ public ProgramWrapper(string assemblyPath)
}

protected override IASTBuilder CreateASTBuilder(IAssemblyProxy assembly, Stream rawAssembly) => new ASTBuilder(assembly, rawAssembly);

protected override IASTWalker CreateASTWalker(CSharpSyntaxNode node, SemanticModel semanticModel) => ProgramDefinitionASTWalker.Create(node, null, semanticModel);
}
}
10 changes: 9 additions & 1 deletion src/Reflection.ScriptSharp/Reflection.ScriptSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Reflection.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Reference Include="System.Reflection.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reflection.Metadata.1.2.0\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
<Private>True</Private>
</Reference>
Expand All @@ -108,10 +108,18 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ASTWalker\ASTWalker.csproj">
<Project>{cb3ff60e-af76-471a-98a3-dfed31a10e94}</Project>
<Name>ASTWalker</Name>
</ProjectReference>
<ProjectReference Include="..\Reflection\Reflection.csproj">
<Project>{20c3aa07-7e56-4e13-a932-b8d69a94525a}</Project>
<Name>Reflection</Name>
</ProjectReference>
<ProjectReference Include="..\ScriptSharp.Definition\ScriptSharp.Definition.csproj">
<Project>{730970a0-58ad-4911-905d-126832243e82}</Project>
<Name>ScriptSharp.Definition</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
7 changes: 5 additions & 2 deletions src/Reflection/ProgramWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ProgramWrapper
private readonly string assemblyPath;

// Lazy loaded or cached quantities
private ProgramASTWalker walker;
private IASTWalker walker;
private CSharpSyntaxTree tree;
private SemanticModel semanticModel;
private string output;
Expand Down Expand Up @@ -64,6 +64,8 @@ public string Output

protected virtual IAssemblyLoader CreateAssemblyLoader(string assemblyPath) => new MonoFSAssemblyLoader(assemblyPath);

protected virtual IASTWalker CreateASTWalker(CSharpSyntaxNode node, SemanticModel semanticModel) => ProgramASTWalker.Create(node, null, semanticModel);

private void Initialize()
{
LoadedAssembly loadedAssembly = this.LoadAssembly();
Expand All @@ -84,10 +86,11 @@ private void Initialize()
var node = this.tree.GetRoot();

// Loading the semantic model
// TODO: Seems like the semantic model has a reference to the ScriptNamespace attribute, check why this happens
this.semanticModel = astInfo.CompilationUnit.GetSemanticModel(this.tree);

// Creating the walker
this.walker = ProgramASTWalker.Create(node, null, this.semanticModel);
this.walker = this.CreateASTWalker(node, this.semanticModel);

// Translating
this.output = this.walker.Walk().Translate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public ScriptNamespaceAttributeOnType(AttributeSemantics attribute)
/// <summary>
/// Gets the value of the overriden namespace in the attribute.
/// </summary>
public string OverridenName => this.attribute.ConstructorArguments.First().Value.ToString();
public string OverridenName
{
get
{
var ctorArgs = this.attribute.ConstructorArguments;
return ctorArgs.First().Value.ToString();
}
}
}
}

0 comments on commit e4a5e91

Please sign in to comment.