MysoreScript
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AST::Expression Class Referenceabstract

Abstract superclass for expressions (statements that evaluate to something). More...

#include <ast.hh>

Inheritance diagram for AST::Expression:
Inheritance graph
[legend]
Collaboration diagram for AST::Expression:
Collaboration graph
[legend]

Public Member Functions

virtual bool isConstantExpression ()
 Returns true if the expression is constant and therefore doesn't need interpreting every time. More...
 
Obj evaluate (Interpreter::Context &c)
 Evaluate the expression, caching the result if it's a constant expression. More...
 
void interpret (Interpreter::Context &c) override final
 Interpret this expression as if it were a statement. More...
 
void compile (Compiler::Context &c) override final
 Compile this expression as if it were a statement. More...
 
virtual llvm::Value * compileExpression (Compiler::Context &c)=0
 Compile the expression, returning the LLVM value that represents the result of the expression. More...
 
- Public Member Functions inherited from AST::Statement
virtual void collectVarUses (std::unordered_set< std::string > &decls, std::unordered_set< std::string > &uses)=0
 Recursively visit all of the children of this statement, collecting variables that are declared and used in it. More...
 

Protected Member Functions

virtual Obj evaluateExpr (Interpreter::Context &c)=0
 Evaluate the expression. More...
 

Protected Attributes

Interpreter::Value cache
 Cached result for constant expression. More...
 

Detailed Description

Abstract superclass for expressions (statements that evaluate to something).

Definition at line 52 of file ast.hh.

Member Function Documentation

§ compile()

void AST::Expression::compile ( Compiler::Context c)
inlinefinaloverridevirtual

Compile this expression as if it were a statement.

Reimplemented from AST::Statement.

Definition at line 85 of file ast.hh.

§ compileExpression()

virtual llvm::Value* AST::Expression::compileExpression ( Compiler::Context c)
pure virtual

Compile the expression, returning the LLVM value that represents the result of the expression.

Implemented in AST::Call, AST::VarRef, AST::ClosureDecl, AST::BinOpBase, AST::StringLiteral, and AST::Number.

§ evaluate()

Obj Expression::evaluate ( Interpreter::Context c)

Evaluate the expression, caching the result if it's a constant expression.

Definition at line 398 of file interpreter.cc.

§ evaluateExpr()

virtual Obj AST::Expression::evaluateExpr ( Interpreter::Context c)
protectedpure virtual

Evaluate the expression.

Implemented in AST::Call, AST::VarRef, AST::ClosureDecl, AST::BinOpBase, AST::StringLiteral, and AST::Number.

§ interpret()

void AST::Expression::interpret ( Interpreter::Context c)
inlinefinaloverridevirtual

Interpret this expression as if it were a statement.

Implements AST::Statement.

Definition at line 78 of file ast.hh.

§ isConstantExpression()

virtual bool AST::Expression::isConstantExpression ( )
inlinevirtual

Returns true if the expression is constant and therefore doesn't need interpreting every time.

The result will be cached after the first time.

Reimplemented in AST::BinOpBase, AST::StringLiteral, and AST::Number.

Definition at line 69 of file ast.hh.

Member Data Documentation

§ cache

Interpreter::Value AST::Expression::cache
protected

Cached result for constant expression.

Definition at line 58 of file ast.hh.


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