summaryrefslogtreecommitdiff
path: root/node/ExprNode.hh
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-25 16:14:41 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-25 16:14:41 +0800
commit958a811b18aee04e4795cf003fd8e3db00312c91 (patch)
tree92cbc52f7560af0e08febfe1da38ed657ad29735 /node/ExprNode.hh
parentc5e9f890dab0e4595482301d77876793c8bceb8c (diff)
finish function calls and lvalue
Diffstat (limited to 'node/ExprNode.hh')
-rw-r--r--node/ExprNode.hh42
1 files changed, 42 insertions, 0 deletions
diff --git a/node/ExprNode.hh b/node/ExprNode.hh
index ac62975..c80d955 100644
--- a/node/ExprNode.hh
+++ b/node/ExprNode.hh
@@ -1,6 +1,8 @@
#ifndef PCC_EXPRNODE_H
#define PCC_EXPRNODE_H
+#include <list>
+
#include "BaseNode.hh"
#include "Type.hh"
@@ -38,6 +40,46 @@ class UnaryExprNode : public ExprNode {
std::shared_ptr<ExprNode> value_;
};
+// when accessing lvalues, we need an extra load instruction to actually load
+// the value from the pointer, this is like clang's 'LValueToRValue' node below.
+// c++: int x=7; int y=x;
+// `-CompoundStmt 0xd28720 <col:9, line:9:1>
+// |-DeclStmt 0xd28638 <line:7:2, col:9>
+// | `-VarDecl 0xd285b0 <col:2, col:8> col:6 used x 'int' cinit
+// | `-IntegerLiteral 0xd28618 <col:8> 'int' 7
+// `-DeclStmt 0xd28708 <line:8:2, col:9>
+// `-VarDecl 0xd28668 <col:2, col:8> col:6 y 'int' cinit
+// `-ImplicitCastExpr 0xd286f0 <col:8> 'int' <LValueToRValue>
+// `-DeclRefExpr 0xd286d0 <col:8> 'int' lvalue Var 0xd285b0 'x' 'int'
+class L2RCastingNode : public ExprNode {
+ public:
+ L2RCastingNode(Context* context, std::shared_ptr<ExprNode> lvalue);
+ virtual Value CodeGen() override;
+
+ protected:
+ std::shared_ptr<ExprNode> lvalue_;
+};
+
+class IdentifierNode : public ExprNode {
+ public:
+ IdentifierNode(Context* context, const std::string& name);
+ virtual Value CodeGen() override;
+
+ protected:
+ std::string name_;
+};
+
+class FunctionCallNode : public ExprNode {
+ public:
+ FunctionCallNode(Context* context, const std::string& name,
+ std::list<std::shared_ptr<ExprNode>> args);
+ virtual Value CodeGen() override;
+
+ protected:
+ std::string name_;
+ std::list<std::shared_ptr<ExprNode>> args_;
+};
+
} // namespace pcc
#endif // !PCC_EXPRNODE_H