Exemple #1
0
        public static Trapl.Core.Session Compile(string src)
        {
            var session = new Trapl.Core.Session();
            session.PrimitiveBool = session.CreatePrimitiveStruct(Trapl.Core.Name.FromPath("Bool"));
            session.PrimitiveInt = session.CreatePrimitiveStruct(Trapl.Core.Name.FromPath("Int"));
            session.PrimitiveUInt = session.CreatePrimitiveStruct(Trapl.Core.Name.FromPath("UInt"));

            var input = Trapl.Core.TextInput.MakeFromString(src);
            var tokens = Trapl.Grammar.Tokenizer.Tokenize(session, input);
            var topLevelNode = Trapl.Grammar.ASTParser.Parse(session, tokens);

            if (session.HasInternalErrors())
                Assert.Inconclusive("Internal compiler error.");

            if (session.HasErrors() || topLevelNode == null)
                Assert.Inconclusive("Syntax error.");

            var resolver = new Trapl.Semantics.DeclResolver(session);
            resolver.ResolveTopLevelDeclGroup(topLevelNode);
            resolver.ResolveStructFields();

            if (!Trapl.Semantics.StructRecursionChecker.Check(session))
            {
                resolver.ResolveFunctHeaders();
                resolver.ResolveFunctBodies();
            }

            session.PrintMessagesToConsole();

            return session;
        }
Exemple #2
0
        public static Trapl.Core.Session Fail(this Trapl.Core.Session session)
        {
            if (session.HasInternalErrors())
            {
                Assert.Inconclusive("Internal compiler error.");
            }

            Assert.IsTrue(session.HasErrors(), "Compilation encountered no errors, but some were expected.");
            return(session);
        }
Exemple #3
0
        public static Trapl.Core.Session FailWithCode(this Trapl.Core.Session session, Trapl.Diagnostics.MessageCode code)
        {
            if (session.HasInternalErrors())
            {
                Assert.Inconclusive("Internal compiler error.");
            }

            Assert.IsTrue(session.HasErrors(), "Compilation encountered no errors, but some were expected.");
            Assert.IsTrue(session.HasMessagesWithCode(code), "No errors of the specified code were encountered.");

            return(session);
        }
Exemple #4
0
        public static Trapl.Core.Session Compile(string src)
        {
            var session = new Trapl.Core.Session();

            session.PrimitiveBool = session.CreatePrimitiveStruct(Trapl.Core.Name.FromPath("Bool"));
            session.PrimitiveInt  = session.CreatePrimitiveStruct(Trapl.Core.Name.FromPath("Int"));
            session.PrimitiveUInt = session.CreatePrimitiveStruct(Trapl.Core.Name.FromPath("UInt"));

            var input        = Trapl.Core.TextInput.MakeFromString(src);
            var tokens       = Trapl.Grammar.Tokenizer.Tokenize(session, input);
            var topLevelNode = Trapl.Grammar.ASTParser.Parse(session, tokens);

            if (session.HasInternalErrors())
            {
                Assert.Inconclusive("Internal compiler error.");
            }

            if (session.HasErrors() || topLevelNode == null)
            {
                Assert.Inconclusive("Syntax error.");
            }

            var resolver = new Trapl.Semantics.DeclResolver(session);

            resolver.ResolveTopLevelDeclGroup(topLevelNode);
            resolver.ResolveStructFields();

            if (!Trapl.Semantics.StructRecursionChecker.Check(session))
            {
                resolver.ResolveFunctHeaders();
                resolver.ResolveFunctBodies();
            }

            session.PrintMessagesToConsole();

            return(session);
        }