Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::Symbol Class Referenceabstract

Base class for named entities that participate in symbol lookup. More...

#include <bond/compiler/parsenodes.h>

Inheritance diagram for Bond::Symbol:
Bond::ListParseNode Bond::ParseNode Bond::CompoundStatement Bond::EnumDeclaration Bond::Enumerator Bond::ForStatement Bond::FunctionDefinition Bond::NamedInitializer Bond::NamespaceDefinition Bond::Parameter Bond::StructDeclaration Bond::SwitchSection Bond::UsingDeclaration

Public Types

enum  SymbolType {
  TYPE_NAMESPACE , TYPE_STRUCT , TYPE_ENUM , TYPE_LOCALSCOPE ,
  TYPE_VALUE , TYPE_FUNCTION
}
 Identifies the concrete symbol category. More...

Public Member Functions

virtual ~Symbol ()
 Destroys a Symbol object.
virtual const Token * GetContextToken () const override
 Returns the token used as source context for diagnostics.
virtual SymbolType GetSymbolType () const =0
 Returns the concrete symbol type.
virtual const Token * GetName () const
 Returns the symbol name token.
virtual TypeAndValue * GetTypeAndValue ()
 Returns the symbol's type-and-value metadata.
virtual const TypeAndValue * GetTypeAndValue () const
 Returns the symbol's type-and-value metadata.
virtual bool IsResolved () const
 Returns true when symbol resolution has completed for this symbol.
bool IsTypeDefinition () const
 Returns true if this symbol defines a type, i.e. it is a struct or an enum.
Symbol * GetParentSymbol ()
 Returns the enclosing symbol.
const Symbol * GetParentSymbol () const
 Returns the enclosing symbol.
void SetParentSymbol (Symbol *parent)
 Sets the enclosing symbol.
Symbol * FindSymbol (const StringView &name)
 Finds a directly contained symbol by name.
const Symbol * FindSymbol (const StringView &name) const
 Finds a directly contained symbol by name.
Symbol * FindSymbol (const Token *name)
 Finds a directly contained symbol by token text.
const Symbol * FindSymbol (const Token *name) const
 Finds a directly contained symbol by token text.
Symbol * FindSymbol (const QualifiedIdentifier *identifier)
 Finds a symbol referenced by a qualified identifier.
const Symbol * FindSymbol (const QualifiedIdentifier *identifier) const
 Finds a symbol referenced by a qualified identifier.
Symbol * FindSymbol (const QualifiedIdentifier *identifier, bool &isAmbiguous)
 Finds a symbol referenced by a qualified identifier, flagging ambiguous matches.
const Symbol * FindSymbol (const QualifiedIdentifier *identifier, bool &isAmbiguous) const
 Finds a symbol referenced by a qualified identifier, flagging ambiguous matches.
void InsertSymbol (Symbol *symbol)
 Inserts a symbol at the front of this symbol's child list and sets this symbol as its parent.
bool IsAnonymous () const
 Returns true if this symbol has no explicit name.
bool Matches (const StringView &name) const
 Returns true if this symbol's name matches the given text.
virtual Symbol * Resolve ()
 Returns the symbol that lookups through this symbol should ultimately resolve to.
virtual const Symbol * Resolve () const
 Returns the symbol that lookups through this symbol should ultimately resolve to.
virtual UsingDirective * GetUsingNamespaceList ()
 Returns the list of namespaces opened in this scope via using-directives.
virtual const UsingDirective * GetUsingNamespaceList () const
 Returns the list of namespaces opened in this scope via using-directives.
virtual void AddUsingNamespace (UsingDirective *usingDirective)
 Opens a namespace into this scope, making its members visible to unqualified lookup.
Public Member Functions inherited from Bond::ListParseNode
virtual ~ListParseNode ()
 Destroys a ListParseNode object.
ListParseNode * GetNextNode ()
 Returns the next node in the list.
const ListParseNode * GetNextNode () const
 Returns the next node in the list.
void SetNextNode (ListParseNode *next)
 Sets the next node in the list.
Public Member Functions inherited from Bond::ParseNode
virtual ~ParseNode ()
 Destroys a ParseNode object.
virtual void Accept (ParseNodeVisitor &visitor)=0
 Dispatches this node to the given visitor.
virtual void Accept (ParseNodeVisitor &visitor) const =0
 Dispatches this node to the given visitor.

Protected Member Functions

 Symbol ()
Protected Member Functions inherited from Bond::ListParseNode
 ListParseNode ()
Protected Member Functions inherited from Bond::ParseNode
 ParseNode ()

Detailed Description

Base class for named entities that participate in symbol lookup.

Member Enumeration Documentation

◆ SymbolType

Identifies the concrete symbol category.

Enumerator
TYPE_NAMESPACE 

Namespace declaration symbol.

TYPE_STRUCT 

Struct declaration symbol.

TYPE_ENUM 

Enum declaration symbol.

TYPE_LOCALSCOPE 

Local scope symbol.

TYPE_VALUE 

Value symbol, such as a variable or enumerator.

TYPE_FUNCTION 

Function symbol.

Constructor & Destructor Documentation

◆ ~Symbol()

virtual Bond::Symbol::~Symbol ( )
inlinevirtual

Destroys a Symbol object.

◆ Symbol()

Bond::Symbol::Symbol ( )
inlineprotected

Member Function Documentation

◆ AddUsingNamespace()

virtual void Bond::Symbol::AddUsingNamespace ( UsingDirective * usingDirective)
inlinevirtual

Opens a namespace into this scope, making its members visible to unqualified lookup.

Parameters
usingDirectiveUsing-directive node to link into this scope's opened-namespace list.

Reimplemented in Bond::CompoundStatement, Bond::ForStatement, and Bond::SwitchSection.

◆ FindSymbol() [1/8]

Symbol * Bond::Symbol::FindSymbol ( const QualifiedIdentifier * identifier)

Finds a symbol referenced by a qualified identifier.

Parameters
identifierQualified identifier to resolve.
Returns
Matching symbol, or null if not found.

◆ FindSymbol() [2/8]

const Symbol * Bond::Symbol::FindSymbol ( const QualifiedIdentifier * identifier) const

Finds a symbol referenced by a qualified identifier.

Parameters
identifierQualified identifier to resolve.
Returns
Matching symbol, or null if not found.

◆ FindSymbol() [3/8]

Symbol * Bond::Symbol::FindSymbol ( const QualifiedIdentifier * identifier,
bool & isAmbiguous )

Finds a symbol referenced by a qualified identifier, flagging ambiguous matches.

Performs unqualified lookup of the first segment, walking outward from this symbol. As in C++, the members of a namespace opened by a using-directive are treated as members of the nearest namespace that encloses both the directive and the opened namespace.

Parameters
identifierQualified identifier to resolve.
isAmbiguousSet to true if the identifier resolves ambiguously at some scope level.
Returns
Best-effort matching symbol, or null if not found.

◆ FindSymbol() [4/8]

const Symbol * Bond::Symbol::FindSymbol ( const QualifiedIdentifier * identifier,
bool & isAmbiguous ) const

Finds a symbol referenced by a qualified identifier, flagging ambiguous matches.

Parameters
identifierQualified identifier to resolve.
isAmbiguousSet to true if the identifier resolves ambiguously at some scope level.
Returns
Best-effort matching symbol, or null if not found.

◆ FindSymbol() [5/8]

Symbol * Bond::Symbol::FindSymbol ( const StringView & name)

Finds a directly contained symbol by name.

Parameters
nameName to search for.
Returns
Matching symbol, or null if not found. If the match is a UsingDeclaration, the symbol it aliases is returned instead.

◆ FindSymbol() [6/8]

const Symbol * Bond::Symbol::FindSymbol ( const StringView & name) const

Finds a directly contained symbol by name.

Parameters
nameName to search for.
Returns
Matching symbol, or null if not found. If the match is a UsingDeclaration, the symbol it aliases is returned instead.

◆ FindSymbol() [7/8]

Symbol * Bond::Symbol::FindSymbol ( const Token * name)
inline

Finds a directly contained symbol by token text.

Parameters
nameName token to search for.
Returns
Matching symbol, or null if not found.

◆ FindSymbol() [8/8]

const Symbol * Bond::Symbol::FindSymbol ( const Token * name) const
inline

Finds a directly contained symbol by token text.

Parameters
nameName token to search for.
Returns
Matching symbol, or null if not found.

◆ GetContextToken()

virtual const Token * Bond::Symbol::GetContextToken ( ) const
inlineoverridevirtual

Returns the token used as source context for diagnostics.

Returns
A token associated with this node, or null if no token applies.

Implements Bond::ParseNode.

Reimplemented in Bond::ForStatement.

◆ GetName()

virtual const Token * Bond::Symbol::GetName ( ) const
inlinevirtual

Returns the symbol name token.

Returns
The name token, or null for anonymous symbols.

Reimplemented in Bond::EnumDeclaration, Bond::Enumerator, Bond::FunctionDefinition, Bond::NamedInitializer, Bond::NamespaceDefinition, Bond::Parameter, Bond::StructDeclaration, and Bond::UsingDeclaration.

◆ GetParentSymbol() [1/2]

Symbol * Bond::Symbol::GetParentSymbol ( )
inline

Returns the enclosing symbol.

Returns
The parent symbol, or null at global scope.

◆ GetParentSymbol() [2/2]

const Symbol * Bond::Symbol::GetParentSymbol ( ) const
inline

Returns the enclosing symbol.

Returns
The parent symbol, or null at global scope.

◆ GetSymbolType()

◆ GetTypeAndValue() [1/2]

virtual TypeAndValue * Bond::Symbol::GetTypeAndValue ( )
inlinevirtual

Returns the symbol's type-and-value metadata.

Returns
Type and value information, or null if not applicable.

Reimplemented in Bond::Enumerator, Bond::FunctionDefinition, Bond::NamedInitializer, Bond::Parameter, and Bond::UsingDeclaration.

◆ GetTypeAndValue() [2/2]

virtual const TypeAndValue * Bond::Symbol::GetTypeAndValue ( ) const
inlinevirtual

Returns the symbol's type-and-value metadata.

Returns
Type and value information, or null if not applicable.

Reimplemented in Bond::Enumerator, Bond::FunctionDefinition, Bond::NamedInitializer, Bond::Parameter, and Bond::UsingDeclaration.

◆ GetUsingNamespaceList() [1/2]

virtual UsingDirective * Bond::Symbol::GetUsingNamespaceList ( )
inlinevirtual

Returns the list of namespaces opened in this scope via using-directives.

Returns
The head of the list, or null if this symbol does not establish local scope.

Reimplemented in Bond::CompoundStatement, Bond::ForStatement, and Bond::SwitchSection.

◆ GetUsingNamespaceList() [2/2]

virtual const UsingDirective * Bond::Symbol::GetUsingNamespaceList ( ) const
inlinevirtual

Returns the list of namespaces opened in this scope via using-directives.

Returns
The head of the list, or null if this symbol does not establish local scope.

Reimplemented in Bond::CompoundStatement, Bond::ForStatement, and Bond::SwitchSection.

◆ InsertSymbol()

void Bond::Symbol::InsertSymbol ( Symbol * symbol)

Inserts a symbol at the front of this symbol's child list and sets this symbol as its parent.

Parameters
symbolSymbol to insert.

◆ IsAnonymous()

bool Bond::Symbol::IsAnonymous ( ) const
inline

Returns true if this symbol has no explicit name.

◆ IsResolved()

virtual bool Bond::Symbol::IsResolved ( ) const
inlinevirtual

Returns true when symbol resolution has completed for this symbol.

Reimplemented in Bond::StructDeclaration, and Bond::UsingDeclaration.

◆ IsTypeDefinition()

bool Bond::Symbol::IsTypeDefinition ( ) const

Returns true if this symbol defines a type, i.e. it is a struct or an enum.

◆ Matches()

bool Bond::Symbol::Matches ( const StringView & name) const

Returns true if this symbol's name matches the given text.

Parameters
nameName to compare against.

◆ Resolve() [1/2]

virtual Symbol * Bond::Symbol::Resolve ( )
inlinevirtual

Returns the symbol that lookups through this symbol should ultimately resolve to.

Overridden by UsingDeclaration so that a using-declaration alias is never observed outside of symbol lookup; every other symbol resolves to itself.

Reimplemented in Bond::UsingDeclaration.

◆ Resolve() [2/2]

virtual const Symbol * Bond::Symbol::Resolve ( ) const
inlinevirtual

Returns the symbol that lookups through this symbol should ultimately resolve to.

Reimplemented in Bond::UsingDeclaration.

◆ SetParentSymbol()

void Bond::Symbol::SetParentSymbol ( Symbol * parent)

Sets the enclosing symbol.

Parameters
parentParent symbol to assign.

The documentation for this class was generated from the following file:
  • include/bond/compiler/parsenodes.h