Joos1W Compiler Framework
All Classes Functions Typedefs Pages
ast::Semantic Class Reference

Public Member Functions

 Semantic (BumpAllocator &alloc, diagnostics::DiagnosticEngine &diag)
 
UnresolvedTypeBuildUnresolvedType (SourceRange loc={})
 
ReferenceTypeBuildReferenceType (Decl const *decl)
 
ArrayTypeBuildArrayType (Type *elementType, SourceRange loc={})
 
BuiltInTypeBuildBuiltInType (parsetree::BasicType::Type type, SourceRange loc={})
 
BuiltInTypeBuildBuiltInType (parsetree::Literal::Type type)
 
BuiltInTypeBuildBuiltInType (ast::BuiltInType::Kind type)
 
VarDeclBuildVarDecl (Type *type, SourceRange location, string_view name, ScopeID const *scope, Expr *init=nullptr)
 
FieldDeclBuildFieldDecl (Modifiers modifiers, SourceRange location, Type *type, string_view name, Expr *init=nullptr, bool allowFinal=false)
 
LinkingUnitBuildLinkingUnit (array_ref< CompilationUnit * > compilationUnits)
 
CompilationUnitBuildCompilationUnit (ReferenceType *package, array_ref< ImportDeclaration > imports, SourceRange location, DeclContext *body)
 
ClassDeclBuildClassDecl (Modifiers modifiers, SourceRange location, string_view name, ReferenceType *superClass, array_ref< ReferenceType * > interfaces, array_ref< Decl * > classBodyDecls)
 
InterfaceDeclBuildInterfaceDecl (Modifiers modifiers, SourceRange location, string_view name, array_ref< ReferenceType * > extends, array_ref< Decl * > interfaceBodyDecls)
 
MethodDeclBuildMethodDecl (Modifiers modifiers, SourceRange location, string_view name, Type *returnType, array_ref< VarDecl * > parameters, bool isConstructor, Stmt *body)
 
BlockStatementBuildBlockStatement (array_ref< Stmt * > stmts)
 
DeclStmtBuildDeclStmt (VarDecl *decl)
 
ExprStmtBuildExprStmt (Expr *expr)
 
IfStmtBuildIfStmt (Expr *condition, Stmt *thenStmt, Stmt *elseStmt=nullptr)
 
WhileStmtBuildWhileStmt (Expr *condition, Stmt *body)
 
ForStmtBuildForStmt (Stmt *init, Expr *condition, Stmt *update, Stmt *body)
 
ReturnStmtBuildReturnStmt (SourceRange loc, Expr *expr)
 
NullStmtBuildNullStmt ()
 
BumpAllocator & allocator ()
 
void ResetLexicalLocalScope ()
 Clears the lexical local scope names.
 
bool AddLexicalLocal (VarDecl *decl)
 Checks if a name is in the lexical local scope and if it is not, add it to the scope. More...
 
int EnterLexicalScope ()
 Called when a new lexical scope is entered. Returns the size of the local declaration stack so it can be restored when the scope is exited. More...
 
void ExitLexicalScope (int size)
 Called when a lexical scope is exited. Resizes the local decl stack to the size it was when the scope was entered. Deletes the locals from the set as well. More...
 
auto getAllLexicalDecls () const
 Get all the lexical declarations in the current scope.
 
ast::ScopeID const * NextScopeID ()
 
ast::ScopeID const * CurrentScopeID () const
 
ast::ScopeID const * NextFieldScopeID ()
 
ast::ScopeID const * CurrentFieldScopeID () const
 
void ResetFieldScope ()
 

Detailed Description

Definition at line 15 of file Semantic.h.

Member Function Documentation

◆ AddLexicalLocal()

bool ast::Semantic::AddLexicalLocal ( VarDecl decl)
inline

Checks if a name is in the lexical local scope and if it is not, add it to the scope.

Parameters
nameThe name to add to the scope
Returns
true If the name was added to the scope
false If the name was already in the scope

Definition at line 96 of file Semantic.h.

96  {
97  std::string nameCpy{decl->name()};
98  if(lexicalLocalScope.find(nameCpy) != lexicalLocalScope.end()) return false;
99  lexicalLocalScope[nameCpy] = decl;
100  lexicalLocalDecls.push_back(decl);
101  lexicalLocalDeclStack.push_back(decl);
102  return true;
103  }

References ast::Decl::name().

◆ EnterLexicalScope()

int ast::Semantic::EnterLexicalScope ( )
inline

Called when a new lexical scope is entered. Returns the size of the local declaration stack so it can be restored when the scope is exited.

Returns
int Returns the size of the local declaration stack

Definition at line 110 of file Semantic.h.

110  {
111  int size = lexicalLocalDeclStack.size();
112  currentScope_ = currentScope_->next(alloc, currentScope_);
113  return size;
114  }
ScopeID const * next(BumpAllocator &alloc, ScopeID const *parent) const
Move on to the next declaration in the given scope.
Definition: AstNode.h:361

References ast::ScopeID::next().

◆ ExitLexicalScope()

void ast::Semantic::ExitLexicalScope ( int  size)
inline

Called when a lexical scope is exited. Resizes the local decl stack to the size it was when the scope was entered. Deletes the locals from the set as well.

Parameters
sizeThe size of the local declaration stack when the scope was entered

Definition at line 123 of file Semantic.h.

123  {
124  for(int i = lexicalLocalDeclStack.size() - 1; i >= size; --i)
125  lexicalLocalScope.erase(lexicalLocalDeclStack[i]->name().data());
126  lexicalLocalDeclStack.resize(size);
127  assert(currentScope_->parent() != nullptr);
128  currentScope_ =
129  currentScope_->next(alloc, currentScope_->parent()->parent());
130  }

References ast::ScopeID::next().


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