private SymbolTable GetScope(ICodeUnit ast)
        {
            var scanner = new ScopeScanner();

            ast.Accept(scanner);
            return(scanner.SymbolTable);
        }
        private static void Assert(ICodeUnit ast, int expectedRefCount)
        {
            var sut = new ReferenceScanner();

            ast.Accept(sut);

            sut.References.Count.Should().Be(expectedRefCount);
        }
Exemple #3
0
        public void AssignNames(ICodeUnit unit)
        {
            var scanner = new ReferenceScanner();

            unit.Accept(scanner);

            var references = scanner.References.Distinct();

            AssignIdentifiersToImplicityReferences(references);
        }
        public IEnumerable <IntermediateCode> Generate(ICodeUnit codeUnit)
        {
            implicitReferenceCount = 0;
            labelCount             = 0;

            var codeGeneratingVisitor = new CodeUnitGeneratingVisitor();

            codeUnit.Accept(codeGeneratingVisitor);

            var code = codeGeneratingVisitor.Code;

            AssignNames(code.ToList());

            return(codeGeneratingVisitor.Code);
        }
        private static void AssertScope(ICodeUnit expressionNode, SymbolTable expectedScope)
        {
            var sut = new ScopeScanner();

            var nameAssigner = new ImplicitReferenceNameAssigner();

            nameAssigner.AssignNames(expressionNode);

            expressionNode.Accept(sut);

            var actual = sut.SymbolTable;

            actual.WithDeepEqual(expectedScope)
            .IgnoreProperty(r => r.Name == "Parent")
            .Assert();
        }