Press enter to see results or esc to cancel.

System Functions Low and High

This procedure processes system function Low and High.

Procedure Func_Low_High; Far;
Var TypeDefinition: PTypeDefinition;
begin
  ExpectTokenAndGetNext (Token_LeftParenthesis);
  If IsTypeIdentifier (Expression^.TypeDefPtr) or not OpenArrayOrOpenString (Expression^.TypeDefPtr) then
    begin
      If (Expression^.TypeDefPtr^.BaseType = btArray) or (Expression^.TypeDefPtr^.BaseType = btString) then
        TypeDefinition := PointerFromOffsets (PArrayTypeDefinition (Expression^.TypeDefPtr)^.IndexTypeOffset) else
          TypeDefinition := Expression^.TypeDefPtr;
      If TypeDefinition^.BaseType < btInteger then Error (OrdinalTypeExpected);
      With Expression^ do
        begin
          TypeDefPtr := TypeDefinition;
          IntermediateCodeOffset := 0;
          Location := elConstant;
          Expression^.CheckOrdinalOverflowAndStore (PInteger (Pchar (TypeDefPtr) + FuncParameter)^, False);
          UsedRegisters := [];
        end;
      ExpectTokenAndGetNext (Token_RightParenthesis);
      Exit;
    end;
  Expression^.TypeDefPtr := Ptr (SystemUnitSegment, LongInt_TypeOffset);
  With Expression^ do
    begin
      If FuncParameter = 12 then begin
                        Expression^.PositionToOpenParameterHighestIndex;
                        Expression^.EndIntermediateCodeSubroutine;
                        Include (LocationData.Flags, efSegment);
                      end else begin
                                 IntermediateCodeOffset := 0;
                                 Location := elConstant;
                                 Expression^.CheckOrdinalOverflowAndStore (0, False);
                               end;
      UsedRegisters := [];
    end;
  ExpectTokenAndGetNext (Token_RightParenthesis);
end;

This function returns identifier type and True if next identifier is type identifier or False if identifier is variable.

Function IsTypeIdentifier (Var TypeDefPtr: PTypeDefinition): Boolean;
begin
  CheckForDeclaredIdentifier;
  IsTypeIdentifier := True;
  Case Token of
    Token_TypeIdentifier,
    Token_STRING,
    Token_FILE: TypeDefPtr := ExpectTypeIdentifier;
    else begin
           Expression^.ExpectVariableReferenceExceptProcedureOrFunction;
           TypeDefPtr := Expression^.TypeDefPtr;
           IsTypeIdentifier := False;
         end;
  end;
end;

This function returns True if array or string has size 0.

Function OpenArrayOrOpenString (TypeDef: PTypeDefinition): Boolean;
begin
  OpenArrayOrOpenString := False;
  Case TypeDef^.BaseType of
    btArray,
    btString: OpenArrayOrOpenString := TypeDef^.Size = 0;
  end;
end;