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.
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;

                                                                                                                             {
 
 
 
© 2017 Turbo Pascal | Privacy Policy