public void TestAllCodePathsReturnValueBad()
        {
            Parser p = new Parser();
            var text = @"
            class Program:
            private int temp
            private int i
            private bool c
            public static int Main():
            i = 0
            c = false
            temp = i
            if (c):
            c = true
            return i
            else:
            i = 666 + (999  - 89)
            ";
            var res = p.Parse(text);
            Assert.IsTrue(res);

            var eval = new TypeEvaluator();
            res = eval.Evaluate(p.GetRootNode());
            Assert.IsTrue(res);

            var checker = new CodePathChecker();
            res = checker.Check(p.GetRootNode());
            Assert.IsFalse(res);
        }
Beispiel #2
0
        public bool Compile(string inputText, Stream outStream)
        {
            errorsContainer = new ErrorsContainer();

            if (!outStream.CanWrite)
            {
                return false;
            }

            // parse
            var parser = new Parser();
            parser.ErrorDispatcher.Error += this.OnErrorOccurred;
            if (!parser.Parse(inputText))
            {
                return false;
            }

            var rootNode = parser.GetRootNode();

            // check code paths
            var codePathChecker = new CodePathChecker();
            codePathChecker.ErrorDispatcher.Error += this.OnErrorOccurred;
            if (!codePathChecker.Check(rootNode))
            {
                return false;
            }

            // fill types && semantic checks
            var typeEval = new TypeEvaluator();
            typeEval.ErrorDispatcher.Error += this.OnErrorOccurred;
            if (!typeEval.Evaluate(rootNode))
            {
                return false;
            }

            // generate code
            var generator = new LLVMCodeGenerator();
            generator.SetSymbolTable(typeEval.GetSymbolTable());
            generator.ErrorDispatcher.Error += this.OnErrorOccurred;
            return generator.Generate(rootNode, outStream);
        }
        public void TestUnreachable()
        {
            Parser p = new Parser();
            var text = @"
            class Program:
            private int temp
            private int i
            private bool c
            public static int Main():
            i = 0
            c = false
            return temp
            temp = i

            ";
            var res = p.Parse(text);
            Assert.IsTrue(res);

            var eval = new TypeEvaluator();
            res = eval.Evaluate(p.GetRootNode());
            Assert.IsTrue(res);

            var checker = new CodePathChecker();
            res = checker.Check(p.GetRootNode());
            Assert.IsFalse(res);
        }