/// <summary>
        /// Test the C# compiler error message can be mapped to the correct
        /// line/column in the LSL source when an undeclared variable is used.
        /// </summary>
        //[Test]
        public void TestUseUndeclaredVariable()
        {
            m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");

            string input = @"default
{
    state_entry()
    {
        integer y = x + 3;
    }
}";

            CSCodeGenerator cg     = new CSCodeGenerator();
            string          output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" +
                                     "namespace SecondLife { " +
                                     "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" +
                                     "public Script() { } " +
                                     cg.Convert(input) +
                                     "} }\n";
            Dictionary <KeyValuePair <int, int>, KeyValuePair <int, int> > positionMap = cg.PositionMap;

            m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);

            Assert.AreEqual(new KeyValuePair <int, int>(5, 21),
                            positionMap[new KeyValuePair <int, int>(m_compilerResults.Errors[0].Line, m_compilerResults.Errors[0].Column)]);
        }
Exemple #2
0
        private CompilerResults CompileScript(
            string input, out Dictionary <KeyValuePair <int, int>, KeyValuePair <int, int> > positionMap)
        {
            m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");

            CSCodeGenerator cg     = new CSCodeGenerator();
            string          output = cg.Convert(input);

            output = Compiler.CreateCSCompilerScript(output, "script1", typeof(ScriptBaseClass).FullName, null);
            //            System.Console.WriteLine(output);

            positionMap = cg.PositionMap;

            CompilerResults compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);

            //            foreach (KeyValuePair<int, int> key in positionMap.Keys)
            //            {
            //                KeyValuePair<int, int> val = positionMap[key];
            //
            //                System.Console.WriteLine("{0},{1} => {2},{3}", key.Key, key.Value, val.Key, val.Value);
            //            }
            //
            //            foreach (CompilerError compErr in m_compilerResults.Errors)
            //            {
            //                System.Console.WriteLine("Error: {0},{1} => {2}", compErr.Line, compErr.Column, compErr);
            //            }

            return(compilerResults);
        }
        /// <summary>
        /// Test that a string can be cast to string and another string
        /// concatenated.
        /// </summary>
        //[Test]
        public void TestCastAndConcatString()
        {
            m_compilerParameters.OutputAssembly = Path.Combine(m_testDir, Path.GetRandomFileName() + ".dll");

            string input = @"string s = "" a string"";

default
{
    state_entry()
    {
        key gAvatarKey = llDetectedKey(0);
        string tmp = (string) gAvatarKey + s;
        llSay(0, tmp);
    }
}";

            CSCodeGenerator cg     = new CSCodeGenerator();
            string          output = "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\n" +
                                     "namespace SecondLife { " +
                                     "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass {\n" +
                                     "public Script() { } " +
                                     cg.Convert(input) +
                                     "} }\n";

            m_compilerResults = m_CSCodeProvider.CompileAssemblyFromSource(m_compilerParameters, output);

            Assert.AreEqual(0, m_compilerResults.Errors.Count);
        }
 public void Convert(string Script, out string CompiledScript,
                     out object PositionMap)
 {
     // Its LSL, convert it to C#
     LSL_Converter  = new CSCodeGenerator(m_compiler);
     CompiledScript = LSL_Converter.Convert(Script);
     PositionMap    = LSL_Converter.PositionMap;
 }
Exemple #5
0
        public void Convert(string Script, out string CompiledScript, out Dictionary <KeyValuePair <int, int>, KeyValuePair <int, int> > PositionMap)
        {
            // Its LSL, convert it to C#
            LSL_Converter  = new CSCodeGenerator(m_compiler);
            CompiledScript = LSL_Converter.Convert(Script);
            PositionMap    = LSL_Converter.PositionMap;

            LSL_Converter.Dispose(); //Resets it for next time
        }
Exemple #6
0
        public void Convert(string Script, out string CompiledScript,
                            out object PositionMap)
        {
            // Its LSL, convert it to C#
            LSL_Converter  = new CSCodeGenerator(m_compiler);
            CompiledScript = LSL_Converter.Convert(Script);
            PositionMap    = LSL_Converter.PositionMap;

            //Unless we are using the same LSL_Converter more than once, we don't need to do this
            //LSL_Converter.Dispose(); //Resets it for next time
        }
    public static void Main(string[] argv)
    {
        StreamReader s      = new StreamReader(argv[0]);
        string       source = s.ReadToEnd();

        CSCodeGenerator cscg   = new CSCodeGenerator();
        string          output = cscg.Convert(source);

        if (1 < argv.Length && "-t" == argv[1])
        {
            Parser p = new LSLSyntax();
            LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(source));
            SYMBOL ast = codeTransformer.Transform();
            printThisTree(ast);
        }
        else
        {
            Console.Write(output);
        }
    }
Exemple #8
0
        private void TestCompile(string script, bool expectException)
        {
            bool      gotException = false;
            Exception ge           = null;

            try
            {
                m_cg.Convert(script);
            }
            catch (Exception e)
            {
                gotException = true;
                ge           = e;
            }

            Assert.That(
                gotException,
                Is.EqualTo(expectException),
                "Failed on {0}, exception {1}", script, ge != null ? ge.ToString() : "n/a");
        }