Joos1W Compiler Framework
All Classes Functions Typedefs Pages
ast::ScopeID Class Referencefinal

Immutable struct that represents a unique identifier for a scope. This captures the position of the lexical scope in the AST to be used after AST construction, when lexical information has been lost. More...

#include <AstNode.h>

Public Member Functions

ScopeID const * next (BumpAllocator &alloc, ScopeID const *parent) const
 Move on to the next declaration in the given scope. More...
 
bool canView (ScopeID const *other) const
 Returns true if we can view the "other" scope from this scope. More...
 
const ScopeIDparent () const
 
std::string toString () const
 
std::ostream & print (std::ostream &os) const
 
void dump () const
 

Static Public Member Functions

static const ScopeIDNew (BumpAllocator &alloc)
 

Friends

std::ostream & operator<< (std::ostream &os, const ScopeID &id)
 

Detailed Description

Immutable struct that represents a unique identifier for a scope. This captures the position of the lexical scope in the AST to be used after AST construction, when lexical information has been lost.

Definition at line 349 of file AstNode.h.

Member Function Documentation

◆ canView()

bool ast::ScopeID::canView ( ScopeID const *  other) const

Returns true if we can view the "other" scope from this scope.

Parameters
otherThe other scope we want to view

Definition at line 24 of file ScopeID.cc.

24  {
25  assert(other != nullptr && "Can't view the null scope");
26  // If under same scope, we can view other iff we are later position
27  if(this->parent_ == other->parent_) {
28  return this->pos_ >= other->pos_;
29  }
30  // If under different scope, check if other is visible from parent
31  if(this->parent_) {
32  return this->parent_->canView(other);
33  }
34  // If we're the topmost scope, then other is a child we cannot see.
35  return false;
36 }
bool canView(ScopeID const *other) const
Returns true if we can view the "other" scope from this scope.
Definition: ScopeID.cc:24

References canView().

Referenced by canView().

◆ next()

ScopeID const* ast::ScopeID::next ( BumpAllocator &  alloc,
ScopeID const *  parent 
) const
inline

Move on to the next declaration in the given scope.

Parameters
allocThe allocator to allocate the new scope
parentThe parent scope
Returns
ScopeID const* The ScopeID for this declaration

Definition at line 361 of file AstNode.h.

361  {
362  void* mem = alloc.allocate_bytes(sizeof(ScopeID), alignof(ScopeID));
363  return new(mem) ScopeID{parent, pos_ + 1};
364  }

Referenced by ast::Semantic::EnterLexicalScope(), and ast::Semantic::ExitLexicalScope().


The documentation for this class was generated from the following files: