public void Visit(SwitchStmt switchStmt, object[] args) { reader.MoveToAttribute("expr"); switchStmt.Expression = exprParser.ParseExpr(reader.Value, new Location(file, reader.LineNumber, reader.LinePosition).Offset(6)); switchStmt.SwitchCaseList = new List <SwitchCase>(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { SwitchCase switchCase = new SwitchCase(); switchCase.Parent = switchStmt; switchCase.Location = new Location(file, reader.LineNumber, reader.LinePosition); switchCase.Accept(this); switchStmt.SwitchCaseList.Add(switchCase); } else if (reader.NodeType == XmlNodeType.EndElement) { break; } } }
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 }