Beispiel #1
0
 public static void TestCompileProgramWithError(string compiland, string expectedError)
 {
     using (TestCompilerContext context = TestCompilerContext.Create(compiland, null, CompilationFlags.NoDebug))
     {
         context.ParseProgram();
         Assert.IsTrue(context.ErrorCount > 0, "Expecting compiler error");
         Assert.AreEqual(expectedError, context.FirstError);
     }
 }
Beispiel #2
0
 public static void TestStatementParserWithError(string compiland, GlobalSymbolList symbols, string expectedError)
 {
     using (TestCompilerContext context = TestCompilerContext.Create(compiland, symbols, CompilationFlags.NoDebug))
     {
         context.ParseStatement();
         Assert.IsTrue(context.ErrorCount > 0, "Expecting compiler error");
         Assert.AreEqual(expectedError, context.FirstError);
     }
 }
Beispiel #3
0
 public static string TestStatementParser(string compiland, GlobalSymbolList symbols = null)
 {
     using (TestCompilerContext context = TestCompilerContext.Create(compiland, symbols, CompilationFlags.NoDebug))
     {
         context.ParseStatement();
         Assert.AreEqual(0, context.ErrorCount, context.FirstError.ToString());
         return(context.GetCompilerOutput());
     }
 }
Beispiel #4
0
        public static string TestCompileProgram(string compiland, bool writeDebugInfo = false)
        {
            CompilationFlags flags = writeDebugInfo ? CompilationFlags.None : CompilationFlags.NoDebug;

            using (TestCompilerContext context = TestCompilerContext.Create(compiland, null, flags))
            {
                context.ParseProgram();
                Assert.AreEqual(0, context.ErrorCount, context.FirstError.ToString());
                return(context.GetCompilerOutput());
            }
        }
        public static TestCompilerContext Create(string compiland, GlobalSymbolList globals, CompilationFlags flags)
        {
            byte[] buffer = Encoding.Default.GetBytes(compiland);
            MemoryStream input = new MemoryStream(buffer);
            StreamReader reader = new StreamReader(input);
            MemoryStream output = new MemoryStream();
            TextEmitter emitter = new TextEmitter(output);

            TestCompilerContext testContext = new TestCompilerContext(input, reader, output, emitter, flags);
            if (globals != null)
            {
                foreach (var symbol in globals.Items)
                    testContext.SymbolTable.Add(symbol.Item1, symbol.Item2, StorageClass.Global, null);
            }

            return testContext;
        }
Beispiel #6
0
        public static TestCompilerContext Create(string compiland, GlobalSymbolList globals, CompilationFlags flags)
        {
            byte[]       buffer  = Encoding.Default.GetBytes(compiland);
            MemoryStream input   = new MemoryStream(buffer);
            StreamReader reader  = new StreamReader(input);
            MemoryStream output  = new MemoryStream();
            TextEmitter  emitter = new TextEmitter(output);

            TestCompilerContext testContext = new TestCompilerContext(input, reader, output, emitter, flags);

            if (globals != null)
            {
                foreach (var symbol in globals.Items)
                {
                    testContext.SymbolTable.Add(symbol.Item1, symbol.Item2, StorageClass.Global, null);
                }
            }

            return(testContext);
        }