Skip to content

Commit

Permalink
Output is now syntactically correct so far
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Apr 21, 2024
1 parent 6e9ff7f commit f37e95d
Show file tree
Hide file tree
Showing 5 changed files with 8,542 additions and 5,491 deletions.
12 changes: 8 additions & 4 deletions tools/ArduinoCsCompiler/IlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ public void Write(string sourceFile, string outFile)
// arduinoMethod can still be null, e.g. for implicit ctors.
}

var methodWrapped = new MethodWrapper(cls, member, arduinoMethod, _executionSet);
decl.AddChild(new Comment($"<summary>{member.Name}, Token {member.Token:X8}</summary>", CommentType.Documentation), Roles.Comment);
EntityDeclaration method = typeSystemAstBuilder.ConvertEntity(methodWrapped);
decl.AddChild(method, Roles.TypeMemberRole);
// Assume we don't need to generated implicit methods
if (arduinoMethod != null)
{
var methodWrapped = new MethodWrapper(cls, member, arduinoMethod, _executionSet);
decl.AddChild(new Comment($"<summary>{member.Name}, Token {member.Token:X8}</summary>", CommentType.Documentation), Roles.Comment);
EntityDeclaration method = typeSystemAstBuilder.ConvertEntity(methodWrapped);
decl.AddChild(method, Roles.TypeMemberRole);
}
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions tools/ArduinoCsCompiler/NanoGenerator/MethodWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal class MethodWrapper : IEntity, IMethod
{
private readonly ClassMember _memberField;
private readonly ExecutionSet _executionSet;
private readonly ArduinoMethodDeclaration? _arduinoMethod;
private readonly ArduinoMethodDeclaration _arduinoMethod;
private string _name;
private IType _declaringType;

public MethodWrapper(ClassDeclaration owner, ClassMember memberField, ArduinoMethodDeclaration? methodDeclaration, ExecutionSet executionSet)
public MethodWrapper(ClassDeclaration owner, ClassMember memberField, ArduinoMethodDeclaration methodDeclaration, ExecutionSet executionSet)
{
_memberField = memberField;
_executionSet = executionSet;
Expand Down Expand Up @@ -97,7 +97,7 @@ public IMethod Specialize(TypeParameterSubstitution substitution)
public IReadOnlyList<IType> TypeArguments => new List<IType>();
public bool IsExtensionMethod { get; }
public bool IsLocalFunction { get; }
public bool IsConstructor => _memberField.Method.IsConstructor;
public bool IsConstructor => _arduinoMethod.Flags.HasFlag(MethodFlags.Ctor);
public bool IsDestructor { get; }
public bool IsOperator { get; }
public bool HasBody => _arduinoMethod != null && _arduinoMethod.HasBody;
Expand Down Expand Up @@ -131,7 +131,7 @@ public IType ReturnType

if (returnType == typeof(void))
{
return new VoidTypeWrapper(SymbolKind.ReturnType, false);
return new VoidTypeWrapper(SymbolKind.ReturnType);
}

return new ClassWrapper(_executionSet.GetClass(returnType), _executionSet);
Expand All @@ -141,8 +141,20 @@ public IType ReturnType
IType? IEntity.DeclaringType => _declaringType;

public IModule? ParentModule { get; }
public Accessibility Accessibility { get; }
public bool IsStatic { get; }
public Accessibility Accessibility => Accessibility.Public;
public bool IsStatic
{
get
{
if (_arduinoMethod == null)
{
return false;
}

return _arduinoMethod.Flags.HasFlag(MethodFlags.Static);
}
}

public bool IsAbstract { get; }
public bool IsSealed { get; }
public string FullName { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;

namespace ArduinoCsCompiler.NanoGenerator
{
Expand All @@ -21,7 +22,7 @@ internal class VoidParameterWrapper : IParameter
public VoidParameterWrapper(string name)
{
_name = name;
_voidType = new VoidTypeWrapper(SymbolKind.Parameter, true);
_voidType = new PointerType(new VoidTypeWrapper(SymbolKind.Parameter));
}

public SymbolKind SymbolKind => SymbolKind.Parameter;
Expand Down
14 changes: 1 addition & 13 deletions tools/ArduinoCsCompiler/NanoGenerator/VoidTypeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ namespace ArduinoCsCompiler.NanoGenerator
internal class VoidTypeWrapper : IEntity, ITypeDefinition
{
private readonly string _name = "void";
private readonly bool _isPointer;

public VoidTypeWrapper(SymbolKind symbolKind, bool isPointer)
public VoidTypeWrapper(SymbolKind symbolKind)
{
SymbolKind = symbolKind;
_isPointer = isPointer;
}

public SymbolKind SymbolKind { get; }
Expand Down Expand Up @@ -115,11 +113,6 @@ public TypeKind Kind
{
get
{
if (_isPointer)
{
return TypeKind.Pointer;
}

return TypeKind.Void;
}
}
Expand Down Expand Up @@ -187,11 +180,6 @@ public FullTypeName FullTypeName
{
get
{
if (_isPointer)
{
return new FullTypeName("System.Void*");
}

return new FullTypeName("System.Void");
}
}
Expand Down
Loading

0 comments on commit f37e95d

Please sign in to comment.