Press enter to see results or esc to cancel.

Processing New

This procedure processes both syntaxes for New as procedure or as function. It either allocates space in heap or calls constructor to create the object in heap.

Procedure TExpression.Process_NEW;
Var PointerBaseType, Saved_TypeDefPtr: PTypeDefinition;
begin
  Saved_TypeDefPtr := TypeDefPtr;
  PointerBaseType := PointerFromOffsets (PPointerTypeDefinition (TypeDefPtr)^.PointerBaseTypeOffset);
  If (PointerBaseType^.BaseType = btObject) and (CheckAndGetNextToken (Token_Comma)) then
    begin
      IntermediateCodeOffset := 0;
      UsedRegisters := [];
      FindAndProcessMethodCall (PointerBaseType, [pfConstructor], [mcNew], ConstructorIdentifierExpected);
      CallProcedure;
    end else begin
               GenerateCodeToPushWord (PointerBaseType^.Size);
               GenerateInstruction_CALL_FAR (SysProc_NewPtr);
               EndIntermediateCodeSubroutine;
             end;
  TypeDefPtr := Saved_TypeDefPtr;
  Location := elRegister;
  DataType := itLongInt;
  UsedRegisters := [urBX, urDX, urCX, urAX];
  LocationData.Register := rDX_AX;
end;