Press enter to see results or esc to cancel.

System Function New

This procedure processes system function New. It uses a common procedure for New as function and procedure.

Procedure Func_New; Far;
Var TypeDefPtr: PTypeDefinition;
begin
  ExpectTokenAndGetNext (Token_LeftParenthesis);
  TypeDefPtr := ExpectTypeIdentifier;
  If TypeDefPtr^.BaseType <> btPointer then Error (PointerTypeIdentifierExpected);
  Expression^.Process_NEW;
  ExpectTokenAndGetNext (Token_RightParenthesis);
end;

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;