Searching in Symbol Table
This function searches for current identifier in specified symbol table. The speed of this function and the design of symbol tables (hash function) have a significant impact on the speed of the compiler. Hash function splits identifiers into several linked lists so only one list is checked when searching for identifier. However, all the identifiers in a list must be checked against current identifier. This is the task of this function. If the identifier is marked as Private (as a member of an object) then it is visible only in current unit.
Function IsIdentifierInSymbolTable (List: PIdentifierList; Var Tok: TToken; Var IdentifierData: Pointer;
                                                                     Var IdentifierPointer: Word): Boolean;
Var TempIdentifier: PIdentifier;
    N: Byte;
    OffsetToNext: Word;
    Equal: Boolean;
  IsIdentifierInSymbolTable := False;
  OffsetToNext := List^.Offset [(CurrentIdentifierHash and List^.Mask) shr 1];
  While OffsetToNext <> 0 do
      TempIdentifier := Ptr (Seg (List^), OffsetToNext);
      OffsetToNext := TempIdentifier^.Next;
      If TempIdentifier^.Name.Len <> Length (CurrentIdentifier) then Continue;
      Equal := True;
      For N := 1 to TempIdentifier^.Name.Len do
        If (Byte (TempIdentifier^.Name.Chr [N]) xor Byte (CurrentIdentifier [N])) and $DF <> 0 then
            Equal := False;
      If not Equal then Continue;
      IdentifierPointer := Ofs (TempIdentifier^);
      IdentifierData := Ptr (Seg (List^), Ofs (TempIdentifier^) + TempIdentifier^.Name.Len + 4);
      IsIdentifierInSymbolTable := True;
      Tok := TempIdentifier^.Token;
      If Byte (TempIdentifier^.Token) and $80 = 0 then Exit;
      Tok := TToken (Byte (Tok) and $7F);
      If Seg (List^) = MainSymbolTable.Segment then Exit;
      IsIdentifierInSymbolTable := False;
© 2017 Turbo Pascal | Privacy Policy