slang::Lookup class

Centralized functionality for looking up symbols by name in the AST.

Contents

Public static functions

static void name(const NameSyntax& syntax, const BindContext& context, bitmask<LookupFlags> flags, LookupResult& result)
static auto unqualified(const Scope& scope, string_view name, bitmask<LookupFlags> flags = LookupFlags::None) -> const Symbol*
static auto unqualifiedAt(const Scope& scope, string_view name, LookupLocation location, SourceRange sourceRange, bitmask<LookupFlags> flags = LookupFlags::None) -> const Symbol*
static auto selectChild(const Symbol& symbol, span<const ElementSelectSyntax*const> selectors, const BindContext& context, LookupResult& result) -> const Symbol*
static auto findClass(const NameSyntax& name, const BindContext& context, optional<DiagCode> requireInterfaceClass = {}) -> const ClassType*
static auto getContainingClass(const Scope& scope) -> std::pair<const ClassType*, bool>
static auto getVisibility(const Symbol& symbol) -> Visibility
static auto isVisibleFrom(const Symbol& symbol, const Scope& scope) -> bool
static auto isAccessibleFrom(const Symbol& target, const Symbol& sourceScope) -> bool
static auto ensureVisible(const Symbol& symbol, const BindContext& context, optional<SourceRange> sourceRange) -> bool
static auto ensureAccessible(const Symbol& symbol, const BindContext& context, optional<SourceRange> sourceRange) -> bool
static auto findIterator(const Scope& scope, const IteratorSymbol& symbol, const NameSyntax& name, LookupResult& result) -> bool
static auto withinClassRandomize(const Scope& scope, span<const string_view> nameRestrictions, const NameSyntax& syntax, bitmask<LookupFlags> flags, LookupResult& result) -> bool

Function documentation

static void slang::Lookup::name(const NameSyntax& syntax, const BindContext& context, bitmask<LookupFlags> flags, LookupResult& result)

Performs a full fledged name lookup starting in the current scope, following all SystemVerilog rules for qualified or unqualified name resolution.

static const Symbol* slang::Lookup::unqualified(const Scope& scope, string_view name, bitmask<LookupFlags> flags = LookupFlags::None)

Performs an unqualified lookup in this scope, then recursively up the parent chain until we reach root or the symbol is found. No errors are reported if no symbol can be found.

static const Symbol* slang::Lookup::unqualifiedAt(const Scope& scope, string_view name, LookupLocation location, SourceRange sourceRange, bitmask<LookupFlags> flags = LookupFlags::None)

Performs an unqualified lookup in this scope, then recursively up the parent chain until we reach root or the symbol is found. Reports an error if the symbol is not found.

static const Symbol* slang::Lookup::selectChild(const Symbol& symbol, span<const ElementSelectSyntax*const> selectors, const BindContext& context, LookupResult& result)

Applies the given selectors to the symbol and returns the selected child. If any errors occur, diagnostics are issued to result and nullptr is returned.

static const ClassType* slang::Lookup::findClass(const NameSyntax& name, const BindContext& context, optional<DiagCode> requireInterfaceClass = {})

Searches for a class with the given name within context – if no symbol is found, or if the found symbol is not a class type, appropriate diagnostics are issued. If requireInterfaceClass is given the resulting class will be required to be an interface class; nullptr will be returned and a diagnostic issued if it's not.

static std::pair<const ClassType*, bool> slang::Lookup::getContainingClass(const Scope& scope)

Gets the containing class for the given scope. The return value is a pair, with the first element being the found class or nullptr if the scope is not within a class definition. The second element indicates whether the given scope was found to be within a static method.

static Visibility slang::Lookup::getVisibility(const Symbol& symbol)

If the given symbol is a member of a class, returns its access visibility. Otherwise, returns Visibility::Public.

static bool slang::Lookup::isVisibleFrom(const Symbol& symbol, const Scope& scope)

Returns whether the given symbol is visible from the provided scope, taking into account class accessibility modifiers.

static bool slang::Lookup::isAccessibleFrom(const Symbol& target, const Symbol& sourceScope)

Returns whether the given target instance symbol is accessible from the provided scope, taking into account the class that owns the target (if any) and the class that owns the provided scope (if any). This is for checking access of instance members and doesn't look at visibility of the symbol.

static bool slang::Lookup::ensureVisible(const Symbol& symbol, const BindContext& context, optional<SourceRange> sourceRange)

If the given symbol is not a class member, returns true without doing any other work. Otherwise, if the member is visible from the provided context, returns true. If it's not visible, and sourceRange is provided, an appropriate diganostic will be issued and false returned.

static bool slang::Lookup::ensureAccessible(const Symbol& symbol, const BindContext& context, optional<SourceRange> sourceRange)

If the given symbol is not a class member, returns true without doing any other work. Otherwise, if the member is accessible from the provided context (in terms of static vs instance members), returns true. If it's not accessible, and sourceRange is provided, an appropriate diganostic will be issued and false returned.

static bool slang::Lookup::findIterator(const Scope& scope, const IteratorSymbol& symbol, const NameSyntax& name, LookupResult& result)

Searches a linked list of iterator symbols to see if any match the given name. If one is found, populates result and returns true. Otherwise returns false.

static bool slang::Lookup::withinClassRandomize(const Scope& scope, span<const string_view> nameRestrictions, const NameSyntax& syntax, bitmask<LookupFlags> flags, LookupResult& result)

Performs a lookup within the given class randomize() scope, respecting the name restrictions provided. If the symbol is not found, or if the name starts with 'local::', it is expected that the caller will then perform a normal lookup in the local scope. Returns true if the symbol is found and false otherwise.