public AbstractDatum inner_step(ExpressionNode nd, VMState vms) { // Find the object Object xd = vms.top().at(nd.child_exp(0)); Assert.check(xd instanceof AbstractPointerDatum); AbstractPointerDatum xpd = (AbstractPointerDatum) xd; AbstractDatum rd = (AbstractDatum) xpd.deref(); Assert.check(rd instanceof AbstractObjectDatum); AbstractObjectDatum object = (AbstractObjectDatum) rd; // Find the field AbstractDatum field = object.getFieldByName(((OpMember) nd).path, ((OpMember) nd).member); // New datum on scratch Clc_ASTUtilities util = (Clc_ASTUtilities) vms.getProperty("ASTUtilities"); AbstractRefDatum d = (AbstractRefDatum) util.scratchDatum(nd.get_type(), vms); // Give it a value d.putValue(field); String name = xpd.getValueString() + ((OpMember) nd).operator_image + ((OpMember) nd).member_name; d.putValueString(name); return d; }
public void step(ExpressionNode nd, VMState vms) { ExpNew nd1 = (ExpNew) nd; // The node shouldn't already be mapped. Assert.check(vms.top().at(nd) == null); // Clear the selection vms.top().setSelected(null); if (vms.top().at(nd1.stateDummy) == null) { // Step 0. Allocate the datum and start initialization. Clc_ASTUtilities util = (Clc_ASTUtilities) vms.getProperty("ASTUtilities"); // Get the types Assert.check(nd1.get_type() instanceof TyAbstractPointer); TyAbstractPointer ptr_type = (TyAbstractPointer) nd1.get_type(); TypeNode new_object_type = ptr_type.getPointeeType(); // Find some space int space = new_object_type.getNumBytes(); Store store = vms.getStore(); MemRegion heapRegion = store.getHeap(); int address = 0; // TODO The following line could throw an exception. // Ideally we should do a garbage collection and // retry. address = heapRegion.findSpace(space); // Make the heap datum. AbstractDatum new_object = new_object_type.makeMemberDatum(vms, address, null, ""); new_object.defaultInitialize(); store.addDatum(new_object); // Make a scratch pointer AbstractPointerDatum ptr = (AbstractPointerDatum) util.scratchDatum(ptr_type, vms); ptr.putValue(address); // Initialization // Map the state dummy so that next time we are in at step 1. // We use the stateDummy also to pass the actual pointer // value of the new expression on to step 1. vms.top().map(nd1.stateDummy, ptr); // Put a reference to the new data // in the vms as argument 0. AbstractRefDatum new_object_ref = util.scratchRef(vms, new_object_type); new_object_ref.putValue(address); vms.pushNewArgumentList(); vms.addArgument(new_object_ref); // Push an evalautation for the initialization. ExpressionEvaluation ee = new ExpressionEvaluation(vms, nd1.initialization); vms.push(ee); } else { // Step 1 vms.popArgumentList(); Object ptr = vms.top().at(nd1.stateDummy); // Map this node to the pointer. vms.top().map(nd1, ptr); } }