예제 #1
0
        public void RequestDatabaseEvaluation(DAPRequest request, UInt32 databaseId)
        {
            List <DAPRequest> requests;

            if (!PendingDatabaseRequests.TryGetValue(databaseId, out requests))
            {
                requests = new List <DAPRequest>();
                PendingDatabaseRequests[databaseId] = requests;
            }

            if (requests.Count == 0)
            {
                var databaseDebugInfo = DebugInfo.Databases[databaseId];
                DatabaseContents[databaseId] = ResultManager.MakeResults(databaseDebugInfo.ParamTypes.Count);
            }

            requests.Add(request);

            DbgClient.SendGetDatabaseContents(databaseId);
        }
        public void EvaluateCall(DAPRequest request, Statement stmt, CoalescedFrame frame, bool allowMutation)
        {
            NodeDebugInfo node;
            var           func = new FunctionNameAndArity(stmt.Name, stmt.Params.Count);

            if (!NameToNodeMap.TryGetValue(func, out node))
            {
                DAP.SendReply(request, "Name not found: " + func);
                return;
            }

            var function = DebugInfo.Functions[node.FunctionName];
            var args     = ParamsToTuple(stmt.Params, frame);

            DbgEvaluate.Types.EvalType evalType;
            switch (node.Type)
            {
            case Node.Type.Database:
                if (stmt.Not)
                {
                    evalType = DbgEvaluate.Types.EvalType.Insert;
                }
                else
                {
                    evalType = DbgEvaluate.Types.EvalType.Delete;
                }
                break;

            case Node.Type.Proc:
                if (stmt.Not)
                {
                    throw new RequestFailedException("\"NOT\" statements not supported for PROCs");
                }

                evalType = DbgEvaluate.Types.EvalType.Insert;
                break;

            case Node.Type.DivQuery:
            case Node.Type.InternalQuery:
            case Node.Type.UserQuery:
                if (stmt.Not)
                {
                    throw new RequestFailedException("\"NOT\" statements not supported for QRYs");
                }

                evalType = DbgEvaluate.Types.EvalType.IsValid;
                break;

            default:
                throw new RequestFailedException($"Eval node type not supported: {node.Type}");
            }

            if ((evalType != DbgEvaluate.Types.EvalType.IsValid ||
                 node.Type == Node.Type.UserQuery) &&
                !allowMutation)
            {
                throw new RequestFailedException($"Evaluation could cause game state change");
            }

            UInt32 seq = DbgClient.SendEvaluate(evalType, node.Id, args);

            var argNames = function.Params.Select(arg => arg.Name).ToList();
            var eval     = new PendingExpressionEvaluation
            {
                Request  = request,
                Results  = EvalResults.MakeResults(function.Params.Count, argNames),
                Node     = node,
                Function = function
            };

            PendingEvaluations.Add(seq, eval);
        }