Esempio n. 1
0
        public IHttpActionResult Post([FromBody]string source)
        {
            if (source == null) {
                return BadRequest();
            }

            List<ParseException> errors = new List<ParseException>();
            List<ParseExceptionResult> errorResults = new List<ParseExceptionResult>();

            Parser parser = new Parser(source);
            parser.parse();
            CFGVisitor cfgv = new CFGVisitor(parser.ast);
            ScopeVisitor sv = new ScopeVisitor(parser.ast);
            DDGVisitor ddgv = new DDGVisitor(parser.ast);

            errors.AddRange(parser.errors);
            errors.AddRange(sv.errors);
            errors.AddRange(ddgv.errors);

            foreach (ParseException error in errors)
            {
                errorResults.Add(new ParseExceptionResult(error.row, error.column, error.reason, error.level.ToString()));

            }

            return Ok(errorResults);
        }
Esempio n. 2
0
        public void BlockSurroundedIf()
        {
            const int COUNT = 7;
            Parser parser = new Parser(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data\BlockSurroundedIf.gngr"));
            parser.parse();
            ASTVisitor astv = new ASTVisitor(parser.ast);
            TestVisitor tv = new TestVisitor(astv.cfg);

            // create new instance to fool compiler
            CFGEntry entry = new CFGEntry();
            CFGBasicBlock b1 = new CFGBasicBlock();
            CFGBasicBlock b2 = new CFGBasicBlock();
            CFGBasicBlock b3 = new CFGBasicBlock();
            CFGBasicBlock b4 = new CFGBasicBlock();
            CFGBasicBlock b5 = new CFGBasicBlock();

            for (int i = 0; i < COUNT; i++)
            {
                switch (i)
                {
                    case 0:
                        entry = (CFGEntry)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(entry, typeof(CFGEntry), $"{i}/1");
                        break;
                    case 1:
                        b1 = (CFGBasicBlock)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(b1, typeof(CFGBasicBlock), $"{i}/1");
                        Assert.AreEqual(entry, b1.parents[0], $"{i}/1");
                        break;
                    case 2:
                        b2 = (CFGBasicBlock)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(b2, typeof(CFGBasicBlock), $"{i}/1");
                        Assert.AreEqual(b1, b2.parents[0], $"{i}/2");
                        break;
                    case 3:
                        b3 = (CFGBasicBlock)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(b3, typeof(CFGBasicBlock), $"{i}/1");
                        Assert.AreEqual(b2, b3.parents[0], $"{i}/2");
                        break;
                    case 4:
                        b4 = (CFGBasicBlock)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(b4, typeof(CFGBasicBlock), $"{i}/1");
                        Assert.AreEqual(b3, b4.parents[0], $"{i}/2");
                        Assert.AreEqual(b2, b4.parents[1], $"{i}/3");
                        break;
                    case 5:
                        b5 = (CFGBasicBlock)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(b5, typeof(CFGBasicBlock), $"{i}/1");
                        Assert.AreEqual(b4, b5.parents[0], $"{i}/2");
                        Assert.AreEqual(b1, b5.parents[1], $"{i}/3");
                        break;
                    case 6:
                        CFGExit exit = (CFGExit)tv.visitedNodes[i];
                        Assert.IsInstanceOfType(exit, typeof(CFGExit), $"{i}/1");
                        Assert.AreEqual(b5, exit.parents[0], $"{i}/2");
                        break;
                }
            }
        }
Esempio n. 3
0
        public IHttpActionResult Post([FromBody]string source)
        {
            if (source == null)
            {
                return BadRequest();
            }

            Parser parser = new Parser(source);
            parser.parse();
            CFGVisitor cfgv = new CFGVisitor(parser.ast);
            ScopeVisitor sv = new ScopeVisitor(parser.ast);
            DDGVisitor ddgv = new DDGVisitor(parser.ast);
            JSONVisitor jsonv = new JSONVisitor(parser.ast);

            return Ok(jsonv.graph);
        }