Character Pointer Operations
This procedure checks if operation is PChar
± Integer or PChar
± PChar
. If so, it generates code and returns True
otherwise it returns False
.
Function CharacterPointerOperations: Boolean;
Function IsOperation_PChar_Integer (Var LeftExpression, RightExpression: TExpression): Boolean;
begin
IsOperation_PChar_Integer := False;
If LeftExpression.TypeDefPtr <> Ptr (SystemUnitSegment, PChar_TypeOffset) then Exit;
IsOperation_PChar_Integer := RightExpression.TypeDefPtr^.BaseType = btInteger;
end;
Procedure CharacterPointerOperation;
begin
CharacterPointerOperations := True;
If (RightExpression.Location = elConstant) and ((LeftExpression.Location = elConstant) or
(LeftExpression.Location = elPointerToMemory) and not (efSegment in LeftExpression.LocationData.Flags)) then
begin
Case Operation of
Calc_Add: Inc (LeftExpression.Value.Word, RightExpression.Value.Word);
Calc_Subtract: Dec (LeftExpression.Value.Word, RightExpression.Value.Word);
end;
Exit;
end;
LeftExpression.LoadPointerToMemoryTo_DX_AX;
RightExpression.LoadPointerToMemoryTo_DX_AX;
RightExpression.ExtendInteger ([it16Bit, itUnsigned]);
LoadBothExpressionsToRegisters (LeftExpression, RightExpression, [urDX, urAX]);
Case Operation of
Calc_Add: RightExpression.GenerateArithmeticInstructionWith_ACC (mod_ADD_rm);
Calc_Subtract: RightExpression.GenerateArithmeticInstructionWith_ACC (mod_SUB_rm);
end;
LeftExpression.EndIntermediateCodeSubroutine;
LeftExpression.UsedRegisters := LeftExpression.UsedRegisters + RightExpression.UsedRegisters;
end;
begin
CharacterPointerOperations := False;
LeftExpression.CheckForConversionOfZeroBasedCharacterArrayToPChar (RightExpression.TypeDefPtr);
RightExpression.CheckForConversionOfZeroBasedCharacterArrayToPChar (LeftExpression.TypeDefPtr);
Case Operation of
Calc_Subtract: If IsOperation_PChar_Integer (LeftExpression, RightExpression) then CharacterPointerOperation;
Calc_Add: begin
If IsOperation_PChar_Integer (RightExpression, LeftExpression) then ExchangeLeftAndRightExpression;
If IsOperation_PChar_Integer (LeftExpression, RightExpression) then CharacterPointerOperation;
end;
end;
end;