Esempio n. 1
0
        protected static IAstNode ParseExpressionToAst(string fragment)
        {
            var parseTree = ParseExpression(fragment);
            var visitor   = new AstBuilderVisitor();

            return(visitor.Visit(parseTree));
        }
Esempio n. 2
0
        protected static IAstNode ParseBlockToAst(string fragment)
        {
            var parseTree = ParseBlock(fragment);
            var visitor   = new AstBuilderVisitor();

            return(new Block((StatementList)visitor.Visit(parseTree)));
        }
Esempio n. 3
0
        protected static IAstNode ParseFunctionDeclToAst(string fragment)
        {
            var parseTree = ParseFunctionDecl(fragment);
            var visitor   = new AstBuilderVisitor();

            return(visitor.Visit(parseTree));
        }
Esempio n. 4
0
        public static IAstNode ParseExpressionToAst(ICharStream source)
        {
            var parseTree = ParseExpression(source);
            var visitor   = new AstBuilderVisitor();

            return(visitor.Visit(parseTree));
        }
        public void CanParseQualifiedVariablesInRoot()
        {
            var parser  = TestUtils.SetupParser(this.QualifiedVariableDeclarationInput);
            var context = parser.external_declaration_list();

            var subject = new AstBuilderVisitor();

            var result = subject.Visit(context);

            Assert.IsTrue(result is Root);
            var root = result as Root;

            Assert.AreEqual(1, root.Declarations.Count);
            var declarationList = root.Declarations[0] as VariableDeclarationList;

            var typeNameSpecifier = declarationList.Type as TypeNameSpecifier;

            Assert.IsNotNull(typeNameSpecifier);
            Assert.AreEqual("int", typeNameSpecifier.Identifier.Name);

            Assert.AreEqual(StorageQualifier.Uniform, typeNameSpecifier.Qualifier.Storage);

            Assert.IsNotNull(declarationList);
            Assert.AreEqual(1, declarationList.Declarations.Count);
            Assert.AreEqual("a", declarationList.Declarations[0].Name.Name);
        }
        public void CanParseStructVariablesInRoot()
        {
            var parser  = TestUtils.SetupParser(this.StructVariableDeclarationInput);
            var context = parser.external_declaration_list();

            var subject = new AstBuilderVisitor();

            var result = subject.Visit(context);

            Assert.IsTrue(result is Root);
            var root = result as Root;

            Assert.AreEqual(1, root.Declarations.Count);
            var declarationList = root.Declarations[0] as VariableDeclarationList;

            var structTypeSpecifier = declarationList.Type as StructTypeSpecifier;

            Assert.AreEqual(1, structTypeSpecifier.Members.Count);

            var memberType = structTypeSpecifier.Members[0].Type as TypeNameSpecifier;

            Assert.IsNotNull(memberType);
            Assert.AreEqual("int", memberType.Identifier.Name);

            Assert.AreEqual(1, structTypeSpecifier.Members[0].Identifiers.Count);
            Assert.AreEqual("a", structTypeSpecifier.Members[0].Identifiers[0].Name);

            Assert.AreEqual("b", declarationList.Declarations[0].Name.Name);
        }
Esempio n. 7
0
        protected static IAstNode ParseDeclAssignmentToAst(string fragment)
        {
            var parseTree = ParseDeclAssignment(fragment);
            var visitor   = new AstBuilderVisitor();

            return(visitor.Visit(parseTree));
        }
        public void CanParseFunctionDefinitionsInRoot()
        {
            var parser  = TestUtils.SetupParser(this.FunctionProtoInput);
            var context = parser.external_declaration_list();

            var subject = new AstBuilderVisitor();

            var result = subject.Visit(context);

            Assert.IsTrue(result is Root);
            var root = result as Root;

            Assert.AreEqual(1, root.Declarations.Count);
            var funcDeclaration = root.Declarations[0] as FunctionDeclaration;

            Assert.AreEqual("DoSomething", funcDeclaration.Name.Name);

            var typeSpec = funcDeclaration.TypeSpecifier as TypeNameSpecifier;

            Assert.IsNotNull(typeSpec);

            Assert.AreEqual("int", typeSpec.Identifier.Name);

            Assert.AreEqual(2, funcDeclaration.Parameters.Count);

            Assert.AreEqual("float", ((TypeNameSpecifier)funcDeclaration.Parameters[0].TypeSpecifier).Identifier.Name);
            Assert.AreEqual("a", funcDeclaration.Parameters[0].Name.Name);

            Assert.AreEqual("int", ((TypeNameSpecifier)funcDeclaration.Parameters[1].TypeSpecifier).Identifier.Name);
            Assert.AreEqual("b", funcDeclaration.Parameters[1].Name.Name);
        }
Esempio n. 9
0
        public static IAstNode ParseFunctionDeclToAst(ICharStream source)
        {
            var parseTree = ParseFunctionDecl(source);
            var visitor   = new AstBuilderVisitor();

            return(visitor.Visit(parseTree));
        }
Esempio n. 10
0
        public static IAstNode ParseProgramToAst(ICharStream source)
        {
            var parseTree = ParseProgram(source);
            var visitor   = new AstBuilderVisitor();
            var ast       = visitor.Visit(parseTree);

            return(ast);
        }
Esempio n. 11
0
        public static IAstNode ParseBlockToAst(ICharStream source)
        {
            var parseTree     = ParseBlock(source);
            var visitor       = new AstBuilderVisitor();
            var statementList = (StatementList)visitor.Visit(parseTree);

            return(new Block(statementList));
        }
Esempio n. 12
0
        protected static IAstNode ParseProgramToAst(string fragment)
        {
            var parseTree = ParseProgram(fragment);
            var visitor   = new AstBuilderVisitor();
            var ast       = visitor.Visit(parseTree);

            ast.Accept(new VerticalLinkageVisitor());
            return(ast);
        }
Esempio n. 13
0
        public void AstBuilding_Invalid_NotImplemented()
        {
            var path       = Path.Combine("tests", "ast-building", "invalid", "not-implemented");
            var astBuilder = new AstBuilderVisitor();

            foreach (var testFile in Directory.GetFiles(path, "*.js", SearchOption.AllDirectories))
            {
                var parser    = Program.CreateParser(File.ReadAllText(testFile));
                var parseTree = Program.TryToBuildParseTree(parser);
                Assert.ThrowsException <NotImplementedException>(() => astBuilder.Visit(parseTree));
            }
        }
Esempio n. 14
0
        public void CanParseShader()
        {
            var parser  = TestUtils.SetupParser(TestShaderSources.BigShaderText);
            var context = parser.external_declaration_list();

            var subject = new AstBuilderVisitor();

            var result = subject.Visit(context);

            Assert.IsTrue(result is Root);
            var root = result as Root;
        }
Esempio n. 15
0
        public void CanPrintShaderSource()
        {
            var parser  = TestUtils.SetupParser(TestShaderSources.BigShaderText);
            var context = parser.external_declaration_list();
            var builder = new AstBuilderVisitor();
            var tree    = builder.Visit(context);

            var subject = new AstPrinterVisitor();
            AstPrinterContext printerContext = new AstPrinterContext();

            var result = subject.Print(tree);
        }
Esempio n. 16
0
        public void AstBuilding_Valid()
        {
            var path         = Path.Combine("tests", "ast-building", "valid");
            var astBuilder   = new AstBuilderVisitor();
            var asciiPrinter = new AsciiTreeBuilderVisitor();

            foreach (var testFile in Directory.GetFiles(path, "*.js", SearchOption.AllDirectories))
            {
                var parser = Program.CreateParser(File.ReadAllText(testFile));
                asciiPrinter.Visit(astBuilder.Visit(Program.TryToBuildParseTree(parser)));

                var expected = File.ReadAllText(Path.ChangeExtension(testFile, ".tree.ascii"));
                Assert.AreEqual(asciiPrinter.GetStringTree(), expected);
                asciiPrinter.ClearTree();
            }
        }
        public void CanParsePrecisionDeclarationInRoot()
        {
            var parser  = TestUtils.SetupParser(this.PrecisionDeclarationInput);
            var context = parser.external_declaration_list();

            var subject = new AstBuilderVisitor();

            var result = subject.Visit(context);

            Assert.IsTrue(result is Root);
            var root = result as Root;

            Assert.AreEqual(1, root.Declarations.Count);
            var precDeclaration = root.Declarations[0] as PrecisionDeclaration;

            var typeSpec = precDeclaration.Type as TypeNameSpecifier;

            Assert.IsNotNull(typeSpec);
            Assert.AreEqual("float", typeSpec.Identifier.Name);

            Assert.AreEqual(PrecisionQualifier.HighP, precDeclaration.PrecisionQualifier);
        }