Skip to content

Commit

Permalink
removes code duplication and moves method declaration for better orga…
Browse files Browse the repository at this point in the history
…nization (part of #243)
  • Loading branch information
adrianoc committed Aug 3, 2023
1 parent 4d9819b commit 6e32506
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Cecilifier.Core/AST/ValueTypeNoArgCtorInvocationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ internal ValueTypeNoArgCtorInvocationVisitor(IVisitorContext ctx, string ilVar,
this.ilVar = ilVar;
}

public bool TargetOfAssignmentIsValueType { get; private set; } = true;

public override void VisitUsingStatement(UsingStatementSyntax node)
{
// our direct parent is a using statement, which means we have something like:
Expand All @@ -35,9 +33,7 @@ public override void VisitEqualsValueClause(EqualsValueClauseSyntax node)
var varName = firstAncestorOrSelf?.Variables[0].Identifier.ValueText;

var operand = Context.DefinitionVariables.GetVariable(varName, VariableMemberKind.LocalVariable).VariableName;
Context.EmitCilInstruction(ilVar, OpCodes.Ldloca_S, operand);
var type = Context.TypeResolver.Resolve(ctorInfo.Symbol.ContainingType);
Context.EmitCilInstruction(ilVar, OpCodes.Initobj, type);
InitValueTypeLocalVariable(operand);
}

public override void VisitReturnStatement(ReturnStatementSyntax node)
Expand Down Expand Up @@ -84,6 +80,8 @@ public override void VisitArgument(ArgumentSyntax node)
Context.EmitCilInstruction(ilVar, loadOpCode, valueTypeLocalVariable.VariableName);
}

public bool TargetOfAssignmentIsValueType { get; private set; } = true;

private DefinitionVariable DeclareAndInitializeValueTypeLocalVariable()
{
var resolvedVarType = ResolvedStructType();
Expand Down

0 comments on commit 6e32506

Please sign in to comment.