public void Visit(FunctionCallStmt funcCallStmt, object[] args) { FormalScope formalScope = new FormalScope(); foreach (KeyValuePair<string, Expr.Expression> actual in funcCallStmt.ParamMap) { Expr.RightValue rightValue = exprProcessor.Eval(actual.Value); formalScope.SetValue(actual.Key, rightValue); } kernel.RuntimeData.ScopeStack.Open(formalScope); kernel.RuntimeData.ScopeStack.Open(new LocalScope()); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CALL_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_LOCAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(InstructionStack.CLOSE_FORMAL_SCOPE_FLAG); kernel.RuntimeData.InstructionStack.Push(root.FuncDefMap[funcCallStmt.Name].FuncDefContent); CallStackElement elem = new CallStackElement(); elem.Destination = root.FuncDefMap[funcCallStmt.Name]; elem.Location = funcCallStmt.Location; elem.ReturnDest = exprProcessor.GetVarName(funcCallStmt.ReturnDest); kernel.RuntimeData.CallStack.Push(elem); kernel.Next(); }
public virtual void Visit(FunctionCallStmt funcCallStmt, object[] args) { }
public override void Visit(FunctionCallStmt funcCallStmt, object[] args) { if (!root.FuncDefMap.ContainsKey(funcCallStmt.Name)) { kernel.IssueError(ErrorType.FunctionNotExist, funcCallStmt.Location, funcCallStmt.Name); return; } FunctionDef def = root.FuncDefMap[funcCallStmt.Name]; //解析ParaStr if (funcCallStmt.ParaStr != null) { int count = funcCallStmt.ParaStr.Length; if (def.ParaStrMap.ContainsKey(count)) { for (int i = 0; i < funcCallStmt.ParaStr.Length; i++) { string varName = def.ParaStrMap[count][i]; string content = funcCallStmt.ParaStr[i]; if (funcCallStmt.ParamMap.ContainsKey(varName)) { kernel.IssueError(ErrorType.DuplicatedParaAndParaStr, funcCallStmt.Location, varName); } else { funcCallStmt.ParamMap.Add(varName, exprParser.CreateStringConst(content, funcCallStmt.Location)); } } } else { kernel.IssueError(ErrorType.NoMatchedParaStrDef, funcCallStmt.Location); } } //解析实参 List<KeyValuePair<string, Expression>> toModify = new List<KeyValuePair<string, Expression>>(); foreach (KeyValuePair<string, Expression> actual in funcCallStmt.ParamMap) { ParameterDef paramDef = def.ParaMap[actual.Key]; string actualStr = ((actual.Value as RightValueExpr).RightValue as StringConst).Value; Location loc = actual.Value.Location; RightValue parsedValue = null; RightValueExpr rightValueExpr = new RightValueExpr(); switch (paramDef.ParameterType) { case ParameterDef.ParameterTypeEnum.Auto: parsedValue = exprParser.ParseValue(actualStr, loc); break; case ParameterDef.ParameterTypeEnum.String: continue; case ParameterDef.ParameterTypeEnum.Expression: toModify.Add(new KeyValuePair<string,Expression>(actual.Key, exprParser.ParseExpr(actualStr, loc))); continue; case ParameterDef.ParameterTypeEnum.Int: parsedValue = exprParser.ParseValue(actualStr, DataType.Int, loc); break; case ParameterDef.ParameterTypeEnum.Float: parsedValue = exprParser.ParseValue(actualStr, DataType.Float, loc); break; case ParameterDef.ParameterTypeEnum.Bool: parsedValue = exprParser.ParseValue(actualStr, DataType.Bool, loc); break; } rightValueExpr.RightValue = parsedValue; rightValueExpr.Location = loc; toModify.Add(new KeyValuePair<string,Expression>(actual.Key, rightValueExpr)); } foreach(KeyValuePair<string,Expression> elem in toModify) { funcCallStmt.ParamMap[elem.Key] = elem.Value; } //添加默认值 foreach (KeyValuePair<string, ParameterDef> pDef in def.ParaMap) { if (!funcCallStmt.ParamMap.ContainsKey(pDef.Key) && pDef.Value.Default != null) { RightValueExpr expr = new RightValueExpr(); expr.RightValue = pDef.Value.Default; funcCallStmt.ParamMap.Add(pDef.Key, expr); } } //参数完整性检查 foreach (KeyValuePair<string, ParameterDef> pDef in def.ParaMap) { if (!funcCallStmt.ParamMap.ContainsKey(pDef.Key)) { kernel.IssueError(ErrorType.ParameterNotDefined, funcCallStmt.Location, pDef.Key); } } base.Visit(funcCallStmt, args); //TODO: 刷新Expression的DataType }