Exemple #1
0
        public ActionResult GetReadable([FromBody] ReadableRequestBody requestBody)
        {
            try
            {
                Console.WriteLine(requestBody.Instance);

                var rawSpacerInstance = requestBody.SpacerInstance;
                var lemmas            = JsonConvert.DeserializeObject <SpacerInstance>(rawSpacerInstance);
                using (var ctx = new Context())
                {
                    foreach (var kvp in lemmas.Lemmas)
                    {
                        if (kvp.Value.Raw == "")
                        {
                            continue;
                        }
                        var parsedSmtLib =
                            SmtLib.StringToSmtLib(ctx, string.Format(SmtPrefix, requestBody.DeclareStatements, kvp.Value.Raw));

                        lemmas.Lemmas[kvp.Key].Readable = ReadableParser.ParseResult(parsedSmtLib);
                    }
                    ctx.Dispose();
                }
                Console.WriteLine("Readable complete");
                return(Ok(JsonConvert.SerializeObject(lemmas.Lemmas)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.TargetSite);
                Console.WriteLine("Error: " + ex.Message);
                return(StatusCode(500, ex.Message));
            }
        }
Exemple #2
0
        public ActionResult ApplyTransformation([FromBody] ApplyTransformRequestBody requestBody)
        {
            try
            {
                Console.WriteLine(requestBody.Instance);
                Console.WriteLine(requestBody.Program);
                var finalProgram = ProgramNode.Parse(requestBody.Program, _grammar.Value);

                var rawSpacerInstance = requestBody.SpacerInstance;
                var lemmas            = JsonConvert.DeserializeObject <SpacerInstance>(rawSpacerInstance);
                using (var ctx = new Context())
                {
                    foreach (var kvp in lemmas.Lemmas)
                    {
                        if (kvp.Value.Raw != "")
                        {
                            var parsedSmtLib =
                                SmtLib.StringToSmtLib(ctx, string.Format(SmtPrefix, requestBody.DeclareStatements, kvp.Value.Raw));
                            if (parsedSmtLib.FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_OR)
                            {
                                var input      = Utils.HandleSmtLibParsed(parsedSmtLib, ctx);
                                var stateInput = State.CreateForExecution(_grammar.Value.InputSymbol, input);
                                var result     = (Node)finalProgram.Invoke(stateInput);

                                lemmas.Lemmas[kvp.Key].Raw      = result.Expr.ToString();
                                lemmas.Lemmas[kvp.Key].Readable = ReadableParser.ParseResult(result.Expr);
                            }
                        }
                    }
                    ctx.Dispose();
                }
                Console.WriteLine("Transformation complete");
                return(Ok(JsonConvert.SerializeObject(lemmas.Lemmas)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.TargetSite);
                Console.WriteLine("Error: " + ex.Message);
                return(StatusCode(500, ex.Message));
            }
        }