Beispiel #1
0
        public void Visit(FunctionCallStmt funcCallStmt, object[] args)
        {
            //检查存在性!
            funcCallStmt.Name     = reader.Name;
            funcCallStmt.ParamMap = new Dictionary <string, FireEngine.FireMLEngine.Expr.Expression>();

            int attCount = reader.AttributeCount;

            for (int i = 0; i < attCount; i++)
            {
                reader.MoveToAttribute(i);
                if (reader.Name == "return")
                {
                    funcCallStmt.ReturnDest = exprParser.ParseLeftValueExpr(reader.Value,
                                                                            new Location(file, reader.LineNumber, reader.LinePosition).Offset(reader.Name.Length + 2)); //TODO: Location
                }
                else if (reader.Name == "par")
                {
                    //FINISH: 解析参数字串!
                    string[] paraStrList = ParaStrProcessor.ReadParaCallList(reader.Value);
                    if (paraStrList == null)
                    {
                        kernel.IssueError(ErrorType.ParaStrCallFormatError, getCurrentLoc(), reader.Value);
                    }
                    else
                    {
                        funcCallStmt.ParaStr = paraStrList;
                    }
                }
                else
                {
                    //先把实参按字符串暂存,之后扫描AST树时再按指定类型解析
                    funcCallStmt.ParamMap.Add(reader.Name,
                                              exprParser.CreateStringConst(reader.Value,
                                                                           new Location(file, reader.LineNumber, reader.LinePosition).Offset(reader.Name.Length + 2) //TODO: Location
                                                                           ));
                }
            }
        }
Beispiel #2
0
        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
        }