Joos1W Compiler Framework
All Classes Functions Typedefs Pages
codegen::details::ValueWrapper Class Reference

Wraps a value for expression evaluation. This distinguishes an LValue from an RValue, wrapping the tir::Value* mapped from an ExprValue. The criteria for an L/R value is as follows: More...

#include <CGExpr.h>

Public Types

enum class  Kind {
  StaticFn , MemberFn , AstType , AstDecl ,
  L , R
}
 

Public Member Functions

 ValueWrapper (ast::Type const *aty)
 Wrap an AST Type node. This can not be an IR value. More...
 
 ValueWrapper (ast::Decl const *decl)
 Wrap an AST FieldDecl node. This can not be an IR value. More...
 
tir::ValueasRValue (tir::IRBuilder &) const
 
tir::ValueasLValue () const
 
tir::ValueasFn () const
 
ast::Type const * astType () const
 
tir::TypeirType () const
 
Kind kind () const
 
bool validate (CodeGenerator &cg) const
 
ast::Decl const * asDecl () const
 
tir::ValuethisRef () const
 
void dump () const
 

Static Public Member Functions

static ValueWrapper L (ast::Type const *aty, tir::Type *elemTy, tir::Value *value)
 Create an L-value wrapper for a pointer value. More...
 
static ValueWrapper R (ast::Type const *aty, tir::Value *value)
 Create an R-value wrapper for a non-pointer value. More...
 
static ValueWrapper Fn (Kind kind, ast::Decl const *fn, tir::Value *value, tir::Value *refThis=nullptr)
 Wrap a static function value or a member function value. More...
 

Detailed Description

Wraps a value for expression evaluation. This distinguishes an LValue from an RValue, wrapping the tir::Value* mapped from an ExprValue. The criteria for an L/R value is as follows:

  • Constants are wrapped R values always
  • Var and field decls are wrapped as L values always
  • Expressions are wrapped as R values always
  • Function decls are neither L nor R values The tir::Value can then be unwrapped using a conversion function.

Definition at line 24 of file CGExpr.h.

Constructor & Destructor Documentation

◆ ValueWrapper() [1/2]

codegen::details::ValueWrapper::ValueWrapper ( ast::Type const *  aty)
inlineexplicit

Wrap an AST Type node. This can not be an IR value.

Parameters
atyThe AST type node to wrap.

Definition at line 45 of file CGExpr.h.

46  : kind_{Kind::AstType}, data_{aty} {}

◆ ValueWrapper() [2/2]

codegen::details::ValueWrapper::ValueWrapper ( ast::Decl const *  decl)
inlineexplicit

Wrap an AST FieldDecl node. This can not be an IR value.

Parameters
declThe AST field declaration node to wrap.

Definition at line 53 of file CGExpr.h.

54  : kind_{Kind::AstDecl}, data_{decl} {}

Member Function Documentation

◆ Fn()

static ValueWrapper codegen::details::ValueWrapper::Fn ( Kind  kind,
ast::Decl const *  fn,
tir::Value value,
tir::Value refThis = nullptr 
)
inlinestatic

Wrap a static function value or a member function value.

Parameters
valueThe IR function value to wrap.
Returns
ValueWrapper The wrapped value.

Definition at line 96 of file CGExpr.h.

97  {
98  assert(kind == Kind::StaticFn || kind == Kind::MemberFn);
99  return ValueWrapper{kind, FnWrapped{fn, refThis, value}};
100  }
ValueWrapper(ast::Type const *aty)
Wrap an AST Type node. This can not be an IR value.
Definition: CGExpr.h:45

◆ L()

static ValueWrapper codegen::details::ValueWrapper::L ( ast::Type const *  aty,
tir::Type elemTy,
tir::Value value 
)
inlinestatic

Create an L-value wrapper for a pointer value.

Parameters
atyThe AST type of the reference.
elemTyThe dereferenced IR type.
valueThe pointer value to wrap.
Returns
ValueWrapper

Definition at line 73 of file CGExpr.h.

74  {
75  return ValueWrapper{Kind::L, TirWrapped{aty, elemTy, value}};
76  }

◆ R()

static ValueWrapper codegen::details::ValueWrapper::R ( ast::Type const *  aty,
tir::Value value 
)
inlinestatic

Create an R-value wrapper for a non-pointer value.

Parameters
atyThe AST type of the value.
valueThe IR value to wrap.
Returns
ValueWrapper The wrapped value.

Definition at line 85 of file CGExpr.h.

85  {
86  assert(!value->type()->isPointerType() || isAstTypeReference(aty));
87  return ValueWrapper{Kind::R, TirWrapped{aty, value->type(), value}};
88  }

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