Files
BlitzNext/compiler/lib/exprnode.hpp
T

214 lines
4.6 KiB
C++
Raw Normal View History

2019-01-19 18:28:07 +01:00
#pragma once
#include <list>
#include <string>
#include <vector>
2019-01-18 15:55:51 +01:00
#include "node.hpp"
2019-01-19 18:28:07 +01:00
#include "type.hpp"
2014-01-31 08:23:00 +13:00
2019-01-19 18:28:07 +01:00
class Codegen;
class Environ;
struct DeclSeq;
struct Decl;
2019-01-18 17:04:57 +01:00
struct ConstNode; //is constant int,float or string
2019-01-19 18:28:07 +01:00
struct VarNode;
class ExprNode : public Node {
std::shared_ptr<Type> sem_type;
2014-01-31 08:23:00 +13:00
2019-01-19 18:28:07 +01:00
public:
ExprNode();
ExprNode(std::shared_ptr<Type> t);
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
ExprNode* castTo(Type* ty, Environ* e);
ExprNode* semant(Environ* e, Type* ty);
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:57 +01:00
virtual ExprNode* semant(Environ* e) = 0;
virtual TNode* translate(Codegen* g) = 0;
virtual ConstNode* constNode()
{
return 0;
}
2014-01-31 08:23:00 +13:00
};
2019-01-19 18:28:07 +01:00
class ExprSeqNode : public Node {
std::list<std::shared_ptr<ExprNode>> exprs;
public:
~ExprSeqNode();
void push_back(std::shared_ptr<ExprNode> e);
int size();
void semant(Environ* e);
2019-01-18 17:04:57 +01:00
TNode* translate(Codegen* g, bool userlib);
2014-01-31 08:23:00 +13:00
2019-01-19 18:28:07 +01:00
void castTo(DeclSeq* ds, Environ* e, bool userlib);
void castTo(Type* t, Environ* e);
};
2014-01-31 08:23:00 +13:00
struct CastNode : public ExprNode {
2019-01-18 17:04:57 +01:00
ExprNode* expr;
Type* type;
2019-01-19 18:28:07 +01:00
CastNode(ExprNode* ex, Type* ty);
~CastNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct CallNode : public ExprNode {
2019-01-19 18:28:07 +01:00
std::string ident, tag;
2019-01-18 17:04:57 +01:00
ExprSeqNode* exprs;
Decl* sem_decl;
2019-01-19 18:28:07 +01:00
CallNode(const std::string& i, const std::string& t, ExprSeqNode* e);
~CallNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct VarExprNode : public ExprNode {
2019-01-18 17:04:57 +01:00
VarNode* var;
2019-01-19 18:28:07 +01:00
VarExprNode(VarNode* v);
~VarExprNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct ConstNode : public ExprNode {
2019-01-19 18:28:07 +01:00
ExprNode* semant(Environ* e);
ConstNode* constNode();
virtual int intValue() = 0;
virtual float floatValue() = 0;
virtual std::string stringValue() = 0;
2014-01-31 08:23:00 +13:00
};
struct IntConstNode : public ConstNode {
2014-01-31 08:23:00 +13:00
int value;
IntConstNode(int n);
2019-01-19 18:28:07 +01:00
TNode* translate(Codegen* g);
int intValue();
float floatValue();
std::string stringValue();
2014-01-31 08:23:00 +13:00
};
struct FloatConstNode : public ConstNode {
2014-01-31 08:23:00 +13:00
float value;
FloatConstNode(float f);
2019-01-19 18:28:07 +01:00
TNode* translate(Codegen* g);
int intValue();
float floatValue();
std::string stringValue();
2014-01-31 08:23:00 +13:00
};
struct StringConstNode : public ConstNode {
2019-01-19 18:28:07 +01:00
std::string value;
StringConstNode(const std::string& s);
TNode* translate(Codegen* g);
int intValue();
float floatValue();
std::string stringValue();
2014-01-31 08:23:00 +13:00
};
struct UniExprNode : public ExprNode {
2019-01-18 17:04:57 +01:00
int op;
ExprNode* expr;
2019-01-19 18:28:07 +01:00
UniExprNode(int op, ExprNode* expr);
~UniExprNode();
2019-01-18 17:04:57 +01:00
ExprNode* constize();
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
// and, or, eor, lsl, lsr, asr
struct BinExprNode : public ExprNode {
2019-01-18 17:04:57 +01:00
int op;
ExprNode *lhs, *rhs;
2019-01-19 18:28:07 +01:00
BinExprNode(int op, ExprNode* lhs, ExprNode* rhs);
~BinExprNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
// *,/,Mod,+,-
struct ArithExprNode : public ExprNode {
2019-01-18 17:04:57 +01:00
int op;
ExprNode *lhs, *rhs;
2019-01-19 18:28:07 +01:00
ArithExprNode(int op, ExprNode* lhs, ExprNode* rhs);
~ArithExprNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
//<,=,>,<=,<>,>=
struct RelExprNode : public ExprNode {
2019-01-18 17:04:57 +01:00
int op;
ExprNode *lhs, *rhs;
Type* opType;
2019-01-19 18:28:07 +01:00
RelExprNode(int op, ExprNode* lhs, ExprNode* rhs);
~RelExprNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct NewNode : public ExprNode {
2019-01-19 18:28:07 +01:00
std::string ident;
NewNode(const std::string& i);
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct FirstNode : public ExprNode {
2019-01-19 18:28:07 +01:00
std::string ident;
FirstNode(const std::string& i);
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct LastNode : public ExprNode {
2019-01-19 18:28:07 +01:00
std::string ident;
LastNode(const std::string& i);
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct AfterNode : public ExprNode {
2019-01-18 17:04:57 +01:00
ExprNode* expr;
2019-01-19 18:28:07 +01:00
AfterNode(ExprNode* e);
~AfterNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct BeforeNode : public ExprNode {
2019-01-18 17:04:57 +01:00
ExprNode* expr;
2019-01-19 18:28:07 +01:00
BeforeNode(ExprNode* e);
~BeforeNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct NullNode : public ExprNode {
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct ObjectCastNode : public ExprNode {
2019-01-19 18:28:07 +01:00
ExprNode* expr;
std::string type_ident;
ObjectCastNode(ExprNode* e, const std::string& t);
~ObjectCastNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};
struct ObjectHandleNode : public ExprNode {
2019-01-18 17:04:57 +01:00
ExprNode* expr;
2019-01-19 18:28:07 +01:00
ObjectHandleNode(ExprNode* e);
~ObjectHandleNode();
2019-01-18 17:04:57 +01:00
ExprNode* semant(Environ* e);
TNode* translate(Codegen* g);
2014-01-31 08:23:00 +13:00
};