@@ -56,17 +56,17 @@ class StringNode : public BasicNode
5656class VariableNode : public BasicNode
5757{
5858protected:
59- BasicNode val;
59+ BasicNode* val= nullptr ;
6060 bool isempty=true ;
6161public:
6262 virtual int getType () {return Variable;}
6363 virtual void addNode (BasicNode* node) {throw string (" VariableNode no sonNode" );}
64- virtual BasicNode* eval () {return dynamic_cast <BasicNode*>(this );}
64+ virtual BasicNode* eval ();
65+ virtual ~VariableNode ();
6566
6667 bool isEmpty () {return this ->isempty ;}
67- void setVal (BasicNode val);
68- BasicNode getVal () {return this ->val ;}
69- void clearVal () {this ->isempty =true ;}
68+ void setVal (BasicNode* val); // 注意,传进来的应该是new出来的,传进来意味着转移所有权到本类
69+ void clearVal ();
7070};
7171
7272
@@ -85,7 +85,7 @@ class Function
8585{
8686private:
8787 int parnum; // 参数个数
88- ProNode* pronode; // 是ret节点返回,最后一个元素视为返回值(如果没有填nullptr)
88+ ProNode* pronode; // 是ret节点返回,最后一个元素视为返回值(如果没有填nullptr)(fix:这个路子是错的,ret方式需要更改)
8989 bool VLP; // 是否不进行参数个数检查
9090 // 关于基础求值
9191 canBE canBEfun;
@@ -98,7 +98,7 @@ class Function
9898 parnum (parnum),canBEfun(canBEfun),BEfun(BEfun),VLP(VLP),iscanBE(true ){} // 调用到函数接口
9999 ~Function () {delete pronode;}
100100
101- ProNode* getPronode () {return this ->pronode ;}
101+ ProNode* getFunBody () {return this ->pronode ;}
102102 int getParnum () {return this ->parnum ;}
103103 bool isVLP () {return this ->VLP ;}
104104 BasicNode* eval (vector<BasicNode *> &sonNode);
@@ -115,5 +115,5 @@ class FunNode : public BasicNode
115115 virtual BasicNode* eval ();
116116 FunNode (Function* funEntity):funEntity(funEntity){}
117117
118- ProNode* getFunBody () {return this ->funEntity ->getPronode ();}
118+ ProNode* getFunBody () {return this ->funEntity ->getFunBody ();}
119119};
0 commit comments