MysoreScript
Public Member Functions | Public Attributes | List of all members
AST::BinOpBase Struct Referenceabstract

Abstract superclass for binary operators. More...

#include <ast.hh>

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

Public Member Functions

virtual bool isComparison ()
 Returns whether this operation is a comparison. More...
 
bool isConstantExpression () override
 A binary operation is a constant expression if both of its operands are binary expressions. More...
 
Obj evaluateExpr (Interpreter::Context &c) override
 Evaluates the expression, either invoking a subclass evaluateWithIntegers method or by calling the relevant method on the left-hand side. More...
 
virtual llvm::Value * compileBinOp (Compiler::Context &c, llvm::Value *LHS, llvm::Value *RHS)=0
 Compile this binary operation with the two sides already already compiled. More...
 
llvm::Value * compileExpression (Compiler::Context &c) override
 Compile the expression by compiling the two sides and then calling compileBinOp (implemented in subclasses) to compile the operation. More...
 
virtual const char * methodName ()=0
 Return the method name that this operator expands to if the operands are not small integers. More...
 
void collectVarUses (std::unordered_set< std::string > &decls, std::unordered_set< std::string > &uses) override
 Collect the uses and declarations in this expression. More...
 
virtual intptr_t evaluateWithIntegers (intptr_t lhs, intptr_t rhs)=0
 Evaluate (interpret) this expression, having already determined that the two sides are integer values. More...
 
- Public Member Functions inherited from AST::Expression
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...
 

Public Attributes

ASTPtr< Expressionlhs
 The left-hand side of the operation. More...
 
ASTPtr< Expressionrhs
 The right-hand side of the operation. More...
 

Additional Inherited Members

- Protected Attributes inherited from AST::Expression
Interpreter::Value cache
 Cached result for constant expression. More...
 

Detailed Description

Abstract superclass for binary operators.

Definition at line 211 of file ast.hh.

Member Function Documentation

§ collectVarUses()

void AST::BinOpBase::collectVarUses ( std::unordered_set< std::string > &  decls,
std::unordered_set< std::string > &  uses 
)
inlineoverridevirtual

Collect the uses and declarations in this expression.

Neither side of a binary operation can contain declarations, but both sides can reference variables.

Implements AST::Statement.

Definition at line 271 of file ast.hh.

§ compileBinOp()

virtual llvm::Value* AST::BinOpBase::compileBinOp ( Compiler::Context c,
llvm::Value *  LHS,
llvm::Value *  RHS 
)
pure virtual

Compile this binary operation with the two sides already already compiled.

Implemented in AST::CmpGE, AST::CmpLE, AST::CmpGt, AST::CmpLt, AST::CmpNe, AST::CmpEq, AST::Subtract, AST::Add, AST::Divide, and AST::Multiply.

§ compileExpression()

llvm::Value* AST::BinOpBase::compileExpression ( Compiler::Context c)
inlineoverridevirtual

Compile the expression by compiling the two sides and then calling compileBinOp (implemented in subclasses) to compile the operation.

Implements AST::Expression.

Definition at line 255 of file ast.hh.

§ evaluateExpr()

Obj BinOpBase::evaluateExpr ( Interpreter::Context c)
overridevirtual

Evaluates the expression, either invoking a subclass evaluateWithIntegers method or by calling the relevant method on the left-hand side.

Implements AST::Expression.

Definition at line 665 of file interpreter.cc.

Here is the call graph for this function:

§ evaluateWithIntegers()

virtual intptr_t AST::BinOpBase::evaluateWithIntegers ( intptr_t  lhs,
intptr_t  rhs 
)
pure virtual

§ isComparison()

virtual bool AST::BinOpBase::isComparison ( )
inlinevirtual

Returns whether this operation is a comparison.

In MysoreScript, comparisons work on primitive values, but other binary operators can become methods if invoked with operands that are not integers.

Reimplemented in AST::Comparison< T >, AST::Comparison< std::greater_equal< intptr_t > >, AST::Comparison< std::less_equal< intptr_t > >, AST::Comparison< std::equal_to< intptr_t > >, AST::Comparison< std::less< intptr_t > >, AST::Comparison< std::greater< intptr_t > >, and AST::Comparison< std::not_equal_to< intptr_t > >.

Definition at line 226 of file ast.hh.

§ isConstantExpression()

bool AST::BinOpBase::isConstantExpression ( )
inlineoverridevirtual

A binary operation is a constant expression if both of its operands are binary expressions.

This is not quite true in the general case, as we could potentially add methods to the String class that take other constant expression values as arguments but have side effects. We don't currently though.

Reimplemented from AST::Expression.

Definition at line 234 of file ast.hh.

§ methodName()

virtual const char* AST::BinOpBase::methodName ( )
pure virtual

Member Data Documentation

§ lhs

ASTPtr<Expression> AST::BinOpBase::lhs

The left-hand side of the operation.

Definition at line 216 of file ast.hh.

§ rhs

ASTPtr<Expression> AST::BinOpBase::rhs

The right-hand side of the operation.

Definition at line 220 of file ast.hh.


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