Skip to content

Commit

Permalink
Some first step
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Apr 14, 2024
1 parent ce861b7 commit d56ef6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tools/ArduinoCsCompiler/IlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace ArduinoCsCompiler
{
public class IlWriter
{
public const string GENERATED_NAMESPACE = "NanoInput";
private readonly ExecutionSet _executionSet;
private readonly IlCapabilities _ilCapabilities;

Expand Down Expand Up @@ -81,14 +82,16 @@ public void Write(string sourceFile, string outFile)

using TextWriter tw = new StreamWriter("C:\\projects\\iot4\\tools\\ArduinoCsCompiler\\samples\\BlinkingLedNano\\generated.cs");
SyntaxTree tree = new SyntaxTree();
var node = new NamespaceDeclaration("Decompiled");
var node = new NamespaceDeclaration(GENERATED_NAMESPACE);
tree.AddChild(node, SyntaxTree.MemberRole);

foreach (var cls in _executionSet.Classes)
{
var typeSystemAstBuilder = new TypeSystemAstBuilder();
var wrapped = new ClassWrapper(cls, _executionSet);
EntityDeclaration decl = typeSystemAstBuilder.ConvertEntity(wrapped);

node.AddChild(new Comment($"<summary>{cls.Name}</summary>", CommentType.Documentation), Roles.Comment);
node.AddChild(decl, SyntaxTree.MemberRole);
foreach (var member in cls.Members)
{
Expand Down
6 changes: 3 additions & 3 deletions tools/ArduinoCsCompiler/NanoGenerator/ClassWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ClassWrapper(ClassDeclaration cls, ExecutionSet executionSet)

public SymbolKind SymbolKind => SymbolKind.TypeDefinition;

public string FullName => _cls.Name;
public string FullName => $"Class_{_cls.NewToken:X8}";

public IEnumerable<IAttribute> GetAttributes()
{
Expand All @@ -57,7 +57,7 @@ public bool HasAttribute(KnownAttribute attribute)

public EntityHandle MetadataToken => throw new NotImplementedException();

public string Name => _cls.SimpleName;
public string Name => $"Class_{_cls.NewToken:X8}";

public ITypeDefinition? DeclaringTypeDefinition => null;

Expand Down Expand Up @@ -235,7 +235,7 @@ public IEnumerable<IType> DirectBaseTypes

public string ReflectionName => _cls.TheType.Name;

public string Namespace => _cls.TheType.Namespace ?? string.Empty;
public string Namespace => IlWriter.GENERATED_NAMESPACE;

public ICompilation Compilation => throw new NotImplementedException();
public bool Equals(IType? other)
Expand Down
9 changes: 8 additions & 1 deletion tools/ArduinoCsCompiler/NanoGenerator/FieldWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public bool HasAttribute(KnownAttribute attribute)
return _memberField.Field.GetValue(null); // Expect a constant here
}

public string Name => _memberField.FieldName;
public string Name
{
get
{
// memberfied.FieldName
return $"Field_{_memberField.Token:X8}";
}
}
public bool IsReadOnly => _memberField.Field.IsInitOnly;
public bool ReturnTypeIsRefReadOnly { get; }
public bool IsVolatile { get; }
Expand Down

0 comments on commit d56ef6a

Please sign in to comment.