public void Visit(SelectStmt selectStmt, object[] args) { bool complex = (dic[reader.Name] == "selectWithValue"); reader.MoveToAttribute("return"); selectStmt.Return = exprParser.ParseLeftValueExpr(reader.Value, new Location(file, reader.LineNumber, reader.LinePosition).Offset(8)); selectStmt.OptionList = new List <SelectOption>(); //FINISH: 复杂形式 if (!complex) { string text = reader.ReadString(); string[] lines = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); int counter = 0; foreach (string line in lines) { string trimed = line.Trim(); if (trimed.Length == 0) { continue; } SelectOption option = new SelectOption(); option.Parent = selectStmt; option.Location = new Location(file, reader.LineNumber, reader.LinePosition); option.Text = trimed; option.Value = exprParser.ParseValue(counter, FireEngine.FireMLEngine.Expr.DataType.Int, new Location(file, reader.LineNumber, reader.LinePosition)); selectStmt.OptionList.Add(option); counter++; } } else { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: SelectOption option = new SelectOption(); option.Parent = selectStmt; option.Location = getCurrentLoc(); option.Accept(this); selectStmt.OptionList.Add(option); break; case XmlNodeType.EndElement: return; } } } }
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 }