Class ASymbolFromSource

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ASymbolFromSource = class(ASymbol)

Description

This class represents a symbol that is parsed from a source file and which will be handled at once or written to an intermediate code file.

Instances of ASymbolFromSource contain a reference to their parent symbol, if any, which can be accessed by calling ASymbolFromSource.ParentSymbol. This is useful when a symbol represents a variable or some other source item that derives from a pre-defined type. Although instances of ASymbolFromSource make use of the Parent property inherited from ANode, symbols are not normally collected into hierarchical lists but are instead kept in either a tree or vector to make symbol lookup as fast as possible.

When ASymbolFromSource.writeSelfTo is called, the symbol will write an absolute reference to its parent, if any, to the destination stream. This reference is an instance of TSymbolReference and so is independent of any pointer value, which may change between the time the parent symbol is written and the time the symbol is recalled from a stream. Although it is possible to read instances of ASymbolFromSource from a binary stream, the base implementation of this class does not know how to read the parent reference. You should use an instance of ASymbolRecalled instead.

Hierarchy

Overview

Fields

Protected mySourceName: string;
Protected mySourceLine: TIndexAbsolute;

Methods

Public constructor named(const thisKey: string; const ThisParentType: ASymbol); reintroduce; virtual;
Public function init: boolean; override;
Public function shallowCopyFrom(const Other: AnObject): boolean; override;
Public function selfStreamingLength: TStreamIOSize; override;
Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;
Public function ParentSymbol: ASymbol; virtual;
Public function sourceName: string; virtual;
Public function setSourceName(const thisName: string): string; virtual;
Public function setSource(const ThisSource: AStream): string; virtual;
Public function sourceLine: TIndexAbsolute; virtual;
Public function setSourceLine(const thisLine: TIndexAbsolute): TIndexAbsolute; virtual;

Description

Fields

Protected mySourceName: string;

Stores the name of the source in which the symbol was declared

Protected mySourceLine: TIndexAbsolute;

Stores the line number of the source on which the symbol was declared

Methods

Public constructor named(const thisKey: string; const ThisParentType: ASymbol); reintroduce; virtual;

Construct a new symbol with the given name and type.

This method overrides the behavior inherited from AStringLeaf. It calls the inherited constructor, then associates the new symbol with the given ParentType.

ThisParentType refers to an instance of ASymbol to which the new symbol belongs. If the new symbol is a structured type that is not a class, then ParentType will likely be Nil.

Public function init: boolean; override;

Initializer

Public function shallowCopyFrom(const Other: AnObject): boolean; override;

Construct a shallow copy of the other object.

This method builds upon the behavior inherited from ASymbol.shallowCopyFrom. It calls that method, then checks to see whether Other is an instance of ASymbolFromSource. If so, it copies the value of ASymbolFromSource.ParentSymbol from Other to Self, overwriting the value in Self.

Note that this method does NOT copy the left and right subtree of Other and so does not place Self inside the same symbol table as Other, if any.

Public function selfStreamingLength: TStreamIOSize; override;

Calculate the number of bytes required to stream the symbol.

This method builds upon the behavior inherited from ASymbol.selfStreamingLength: it calls that method, then adds the number of bytes required to write a reference to its parent, if any.

Public function writeSelfTo(const Dest: AStream): TStreamIOSize; override;

Write the symbol, and just the symbol, to the specified stream.

This method builds upon the behavior inherited from ASymbol.writeSelfTo. It calls that method, then calls ASymbol.reference on its parent, if any, and writes those values, too. This behavior is designed to make it easy to recall a symbol from an intermediate code stream.

Returns

The total number of bytes written to the stream.

Public function ParentSymbol: ASymbol; virtual;

Retrieve a reference to the parent symbol of the symbol, if any. If the symbol has no parent (it is, itself, representative of a base type), then the return value from this routine will be Nil.

The caller should NOT free the reference returned by this routine.

Public function sourceName: string; virtual;

Retrieve the name of the source in which the symbol was defined. This function is useful in case a message (hint, warning, or error) must be displayed to the user while parsing.

Public function setSourceName(const thisName: string): string; virtual;

Set the name of the source in which the symbol is defined.

Returns

The previous value of ASymbolFromSource.sourceName.

Public function setSource(const ThisSource: AStream): string; virtual;

Set the source from which the symbol is defined.

This method calls AStream.name on ThisSource and stores the result as the value of ASymbolFromSource.sourceName. If ThisSource represents an instance of AFileStream, this will result in the name of the file being stored.

Returns

The previous value of ASymbolFromSource.sourceName.

Public function sourceLine: TIndexAbsolute; virtual;

Retrieve the line number in the source on which the symbol is defined. This function is useful in case a message (hint, warning, or error) must be displayed to the user while parsing.

Public function setSourceLine(const thisLine: TIndexAbsolute): TIndexAbsolute; virtual;

Set the line number in the source on which the symbol is defined.

Returns

The previous value of ASymbolFromSource.sourceLine.


Generated by PasDoc 0.13.0 on 2015-06-25 11:12:03