public override void VisitBoxInstruction(BoxInstruction instruction) { var cilType = instruction.TypeSpec.GetCilType(_program); ControlState.EvaluationStack.PopValue(_program, cilType, out var val); CilObject obj = null; if (cilType.IsValueType(_program) && !cilType.IsNullable) { obj = val.Box(); } var objRef = ManagedMemory.Store(obj); ControlState.EvaluationStack.PushValue(objRef); ControlState.MoveToNextInstruction(); }
public override CILInstructionType BuildNode(ParseTreeNode node) { var instrTypeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_TYPE); CILInstructionType result = null; var boxParseTreeNode = instrTypeParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_box); if (boxParseTreeNode != null) { result = new BoxInstruction(); } var newarrParseTreeNode = instrTypeParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_newarr); if (newarrParseTreeNode != null) { result = new NewArrayInstruction(); } var unboxanyParseTreeNode = instrTypeParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_unboxany); if (unboxanyParseTreeNode != null) { result = new UnboxAnyInstruction(); } if (result != null) { var typeSpecParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.typeSpec); result.TypeSpecification = TypeSpecParseTreeNodeHelper.GetValue(typeSpecParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction type."); }
public abstract void VisitBoxInstruction(BoxInstruction instruction);