@@ -172,7 +172,7 @@ void FunNode::addNode(BasicNode *node)
172172{
173173 if (!this ->funEntity ->isVLP ()) // 支持变长参数就先不进行参数个数检查
174174 if (this ->sonNode .size ()+1 >this ->funEntity ->getParnum ())
175- throw string ( " Exceeding the number of function parameters " );
175+ throw parameterNumExceedingExcep ( );
176176
177177 this ->sonNode .push_back (node);
178178}
@@ -181,7 +181,21 @@ BasicNode* FunNode::eval()
181181{
182182 if (this ->funEntity ==nullptr )
183183 throw string (" funEntity is null" );
184- return this ->funEntity ->eval (this ->sonNode );
184+ #ifdef PARTEVAL
185+ try
186+ {
187+ #endif
188+ return this ->funEntity ->eval (this ->sonNode );
189+ }
190+ #ifdef PARTEVAL
191+ catch (callCheckMismatchExcep e) // 因为未赋值变量未求值使得参数类型不匹配,放弃对这个函数求值
192+ {
193+ if (e.getType ()==TypeMisMatch)
194+ return this ;
195+ else
196+ throw e;
197+ }
198+ #endif
185199}
186200
187201
@@ -197,12 +211,14 @@ void recursionEval(BasicNode* &node)
197211 {
198212 BasicNode* result;
199213 #ifdef PARTEVAL
200- try {
214+ try
215+ {
201216 #endif
202217 result=node->eval ();
203218 #ifdef PARTEVAL
204219 }
205- catch (unassignedEvalExcep) {}
220+ catch (unassignedEvalExcep) // 对未赋值变量求值,保持原样
221+ {result=node;}
206222 #endif
207223 if (node->getType ()!=Var)
208224 delete node;
@@ -225,32 +241,32 @@ BasicNode* Function::eval(vector<BasicNode *> &sonNode)
225241 if (this ->canBEfun (sonNode)) // 参数合法
226242 return this ->BEfun (sonNode);
227243 else
228- throw string ( " sonNode type mismatch " );
244+ throw callCheckMismatchExcep (TypeMisMatch );
229245 }
230246 else // 不能基础求值就是正常有函数体Pro的
231247 {
232- this ->bindFormalPar (sonNode); // 子节点绑定到实参
248+ this ->bindArgument (sonNode); // 子节点绑定到实参
233249 vector<BasicNode*>&funbody=this ->pronode ->sonNode ;
234- for (int i=0 ;i<funbody.size ()-1 ;i++) // 最后一个可能是返回值,先留着后面单独处理
250+ for (unsigned int i=0 ;i<funbody.size ()-1 ;i++) // 最后一个可能是返回值,先留着后面单独处理
235251 {
236252 recursionEval (funbody.at (i));
237253 if (funbody.at (i)->isRet ())
238254 {
239- this ->unbindFormalPar ();
255+ this ->unbindArgument ();
240256 return funbody.at (i);
241257 }
242258 }
243259 // 前面都不是返回值,最后一个是
244260 BasicNode* lastnode=funbody.at (funbody.size ()-1 );
245261 if (lastnode==nullptr )
246262 {
247- this ->unbindFormalPar ();
263+ this ->unbindArgument ();
248264 return nullptr ;
249265 }
250266 else
251267 {
252268 recursionEval (lastnode);
253- this ->unbindFormalPar ();
269+ this ->unbindArgument ();
254270 return lastnode;
255271 }
256272 }
@@ -259,30 +275,30 @@ BasicNode* Function::eval(vector<BasicNode *> &sonNode)
259275Function::~Function ()
260276{
261277 delete this ->pronode ;
262- for (VarReference* i:this ->formalParList )
278+ for (VarReference* i:this ->argumentList )
263279 delete i;
264280}
265281
266- void Function::addFormalPar (VarReference *var)
282+ void Function::addArgument (VarReference *var)
267283{
268- if (this ->formalParList .size ()+1 >this ->getParnum ())
269- throw string ( " Exceeding the number of parameters " );
270- this ->formalParList .push_back (var);
284+ if (this ->argumentList .size ()+1 >this ->getParnum ())
285+ throw argumentNumExceedingExcep ( );
286+ this ->argumentList .push_back (var);
271287}
272288
273- void Function::unbindFormalPar ()
289+ void Function::unbindArgument ()
274290{
275- for (VarReference* i:this ->formalParList )
291+ for (VarReference* i:this ->argumentList )
276292 i->unbind ();
277293}
278294
279- void Function::bindFormalPar (vector<BasicNode *> &sonNode)
295+ void Function::bindArgument (vector<BasicNode *> &sonNode)
280296{
281- if (sonNode.size ()!=this ->formalParList .size ())
282- throw string ( " sonNode number mismatch " );
283- for (int i=0 ;i<this ->formalParList .size ();i++)
297+ if (sonNode.size ()!=this ->argumentList .size ())
298+ throw callCheckMismatchExcep (NumberMismatch );
299+ for (unsigned int i=0 ;i<this ->argumentList .size ();i++)
284300 {
285- VarReference* formalpar=this ->formalParList .at (i);
301+ VarReference* formalpar=this ->argumentList .at (i);
286302 formalpar->bind (sonNode.at (i));
287303 }
288304}
0 commit comments