mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Data Fields | Private Types | Private Attributes
m::ast::Sema Struct Reference

#include <Sema.hpp>

Inheritance diagram for m::ast::Sema:
[legend]
Collaboration diagram for m::ast::Sema:
[legend]

Data Structures

struct  RequireContext
 Helper class to create a context when one is required but does not yet exist. More...
 
struct  SemaContext
 Holds context information used by semantic analysis of a single statement. More...
 

Public Types

template<typename T >
using Const = ASTExprVisitor::Const< T >
 

Public Member Functions

 Sema (Diagnostic &diag)
 
std::unique_ptr< DatabaseCommandanalyze (std::unique_ptr< ast::Command > ast)
 Perform semantic analysis of an ast::Command.
 
 M_AST_EXPR_LIST (DECLARE) M_AST_CLAUSE_LIST(DECLARE) M_AST_COMMAND_LIST(DECLARE) private
 
SemaContext pop_context ()
 
SemaContextget_context ()
 
const SemaContextget_context () const
 
bool is_nested () const
 Returns true iff the current statement, that is being analyzed, is a nested statement.
 
std::unique_ptr< Designatorcreate_designator (ThreadSafePooledString name, Token tok, const Expr &target)
 Creates a fresh Designator with the given name at location tok and with target target.
 
std::unique_ptr< Designatorcreate_designator (const Expr &name, const Expr &target, bool drop_table_name=false)
 Creates a fresh Designator with the same syntactical representation as name (except the table name if drop_table_name) and with target target.
 
std::unique_ptr< Designatorcreate_designator (Position pos, ThreadSafePooledString table_name, ThreadSafePooledString attr_name, typename Designator::target_type target, const Type *type)
 Creates an entirely new Designator.
 
void replace_by_fresh_designator_to (std::unique_ptr< Expr > &to_replace, const Expr &target)
 Replaces to_replace by a fresh Designator, that has the same syntactical representation as to_replace and targets target.
 
bool is_composable_of (const ast::Expr &expr, const std::vector< std::reference_wrapper< ast::Expr > > components)
 Computes whether the bound parts of expr are composable of elements in components.
 
void compose_of (std::unique_ptr< ast::Expr > &ptr, const std::vector< std::reference_wrapper< ast::Expr > > components)
 Recursively analyzes the ast::Expr referenced by ptr and replaces subexpressions that can be composed of the elements in components.
 
ThreadSafePooledOptionalString make_unique_id_from_binding_path (context_stack_t::reverse_iterator current_ctx, context_stack_t::reverse_iterator binding_ctx)
 Creates a unique ID from a sequence of SemaContexts by concatenating their aliases.
 

Data Fields

Diagnosticdiag
 

Private Types

using context_stack_t = std::vector< SemaContext * >
 

‍a stack of sema contexts; one per statement; grows by nesting statements


 

Private Attributes

context_stack_t contexts_
 
std::ostringstream oss
 

‍used to create textual representation of complex AST objects, e.g. expressions


 
std::unique_ptr< DatabaseCommandcommand_
 

‍the command to execute when semantic analysis completes without errors


 

Detailed Description

Definition at line 16 of file Sema.hpp.

Member Typedef Documentation

◆ Const

template<typename T >
using m::ast::ASTVisitor::Const = ASTExprVisitor::Const<T>
inherited

Definition at line 1071 of file AST.hpp.

◆ context_stack_t

using m::ast::Sema::context_stack_t = std::vector<SemaContext*>
private

‍a stack of sema contexts; one per statement; grows by nesting statements

Definition at line 100 of file Sema.hpp.

Constructor & Destructor Documentation

◆ Sema()

m::ast::Sema::Sema ( Diagnostic diag)
inline

Definition at line 108 of file Sema.hpp.

Member Function Documentation

◆ analyze()

std::unique_ptr< DatabaseCommand > Sema::analyze ( std::unique_ptr< ast::Command ast)

Perform semantic analysis of an ast::Command.

Returns an m::DatabaseCommand to execute when no semantic errors occurred, nullptr otherwise.

Definition at line 15 of file Sema.cpp.

References command_.

Referenced by m::command_from_string(), main(), and m::SerialScheduler::schedule_thread().

◆ compose_of()

void Sema::compose_of ( std::unique_ptr< ast::Expr > &  ptr,
const std::vector< std::reference_wrapper< ast::Expr > >  components 
)

Recursively analyzes the ast::Expr referenced by ptr and replaces subexpressions that can be composed of the elements in components.

Definition at line 115 of file Sema.cpp.

References m::and, is_composable_of(), replace_by_fresh_designator_to(), and m::visit().

◆ create_designator() [1/3]

std::unique_ptr< Designator > Sema::create_designator ( const Expr name,
const Expr target,
bool  drop_table_name = false 
)

Creates a fresh Designator with the same syntactical representation as name (except the table name if drop_table_name) and with target target.

Definition at line 41 of file Sema.cpp.

References m::ast::Token::CreateArtificial(), m::Catalog::Get(), oss, m::ast::Token::pos, m::ast::Expr::tok, and m::ast::Expr::type().

◆ create_designator() [2/3]

std::unique_ptr< Designator > m::ast::Sema::create_designator ( Position  pos,
ThreadSafePooledString  table_name,
ThreadSafePooledString  attr_name,
typename Designator::target_type  target,
const Type type 
)
inline

Creates an entirely new Designator.

This method is used to introduce artificial Designators to expand an anti-projection (SELECT with asterisk *).

Definition at line 161 of file Sema.hpp.

◆ create_designator() [3/3]

std::unique_ptr< Designator > Sema::create_designator ( ThreadSafePooledString  name,
Token  tok,
const Expr target 
)

Creates a fresh Designator with the given name at location tok and with target target.

Definition at line 32 of file Sema.cpp.

References m::ast::Token::CreateArtificial(), m::ast::Token::pos, and m::ast::Expr::type().

Referenced by replace_by_fresh_designator_to().

◆ get_context() [1/2]

SemaContext & m::ast::Sema::get_context ( )
inline

Definition at line 135 of file Sema.hpp.

References M_insist.

◆ get_context() [2/2]

const SemaContext & m::ast::Sema::get_context ( ) const
inline

Definition at line 139 of file Sema.hpp.

References M_insist.

◆ is_composable_of()

bool Sema::is_composable_of ( const ast::Expr expr,
const std::vector< std::reference_wrapper< ast::Expr > >  components 
)

Computes whether the bound parts of expr are composable of elements in components.

Definition at line 88 of file Sema.cpp.

References m::and, is_composable_of(), and m::visit().

Referenced by compose_of(), and is_composable_of().

◆ is_nested()

bool Sema::is_nested ( ) const

Returns true iff the current statement, that is being analyzed, is a nested statement.

Definition at line 23 of file Sema.cpp.

References contexts_.

◆ M_AST_EXPR_LIST()

m::ast::Sema::M_AST_EXPR_LIST ( DECLARE  )
inline

Definition at line 118 of file Sema.hpp.

◆ make_unique_id_from_binding_path()

ThreadSafePooledOptionalString Sema::make_unique_id_from_binding_path ( context_stack_t::reverse_iterator  current_ctx,
context_stack_t::reverse_iterator  binding_ctx 
)

Creates a unique ID from a sequence of SemaContexts by concatenating their aliases.

Definition at line 72 of file Sema.cpp.

References m::Catalog::Get(), M_insist, and oss.

◆ pop_context()

SemaContext m::ast::Sema::pop_context ( )
inline

Definition at line 129 of file Sema.hpp.

Referenced by m::ast::Sema::RequireContext::~RequireContext().

◆ replace_by_fresh_designator_to()

void Sema::replace_by_fresh_designator_to ( std::unique_ptr< Expr > &  to_replace,
const Expr target 
)

Replaces to_replace by a fresh Designator, that has the same syntactical representation as to_replace and targets target.

Definition at line 61 of file Sema.cpp.

References create_designator().

Referenced by compose_of().

Field Documentation

◆ command_

std::unique_ptr<DatabaseCommand> m::ast::Sema::command_
private

‍the command to execute when semantic analysis completes without errors

Definition at line 105 of file Sema.hpp.

Referenced by analyze().

◆ contexts_

context_stack_t m::ast::Sema::contexts_
private

Definition at line 101 of file Sema.hpp.

Referenced by is_nested().

◆ diag

Diagnostic& m::ast::Sema::diag

Definition at line 97 of file Sema.hpp.

◆ oss

std::ostringstream m::ast::Sema::oss
private

‍used to create textual representation of complex AST objects, e.g. expressions

Definition at line 103 of file Sema.hpp.

Referenced by create_designator(), and make_unique_id_from_binding_path().


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