示例#1
0
		public SLE.LambdaExpression CompileExpression (char[] Input, ref List<Diagnostic> Diagnostics)
		{
			IdentifierMappingTable idmtable = new IdentifierMappingTable ();
			IdentifierTable idtable = new IdentifierTable ();
			Parser parser = new Parser (Input, idtable, true);
			List<Comment> comments = null;
			BindingInfo bindinginfo = null;
			Expression expr = parser.ParseExpression (ref comments, ref bindinginfo);
			Diagnostics = parser.Diagnostics;
			RowanGenerator gen = new RowanGenerator (idmtable, idtable.InsertIdentifier("this"),  idtable.InsertIdentifier("arguments"));
			return gen.BindAndTransform (expr, bindinginfo);
		}
示例#2
0
		public void GenerateQuestion ()
		{
			Parser parser = new Parser ("foo?1:0;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.ConditionalExpression), exp, "#1");
		}
示例#3
0
		public void GenerateNull ()
		{
			Parser parser = new Parser ("null;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.ConstantExpression), exp, "#1");
			Assert.IsNull (((MSIA.ConstantExpression)exp).Value, "#2");
		}
示例#4
0
		public void GenerateIn ()
		{
			Parser parser = new Parser ("foo in bar;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.MethodCallExpression), exp, "#1");
			Assert.AreEqual (typeof (MJR.JSCompilerHelpers).GetMethod ("In"), ((MSIA.MethodCallExpression)exp).Method, "#2");
		}
示例#5
0
		public void GeneratePercent ()
		{
			Parser parser = new Parser ("foo % 1;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.ActionExpression), exp, "#1");
			Assert.IsInstanceOfType (typeof (MSA.DoOperationAction), ((MSIA.ActionExpression)exp).Action, "#2");
			Assert.AreEqual (MSO.Mod, ((MSA.DoOperationAction)((MSIA.ActionExpression)exp).Action).Operation, "#3");
		}
示例#6
0
		public void GeneratePostfixMinusMinus ()
		{
			Parser parser = new Parser ("foo--;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.CommaExpression), exp, "#1");
			Assert.AreEqual (2, ((MSIA.CommaExpression)exp).Expressions.Count, "#2");
			Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment), ((MSIA.CommaExpression)exp).Expressions[0], "#3");
			Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment), ((MSIA.CommaExpression)exp).Expressions[1], "#4");
			Assert.IsInstanceOfType (typeof (MSIA.MethodCallExpression), ((MSIA.BoundAssignment)((MSIA.CommaExpression)exp).Expressions[0]).Value, "#5");
			Assert.AreEqual (typeof (MJR.Convert).GetMethod ("ToNumber", new Type[] {typeof(object)}), ((MSIA.MethodCallExpression)((MSIA.BoundAssignment)((MSIA.CommaExpression)exp).Expressions[0]).Value).Method, "#6");
			Assert.IsInstanceOfType (typeof (MSIA.ActionExpression), ((MSIA.BoundAssignment)((MSIA.CommaExpression)exp).Expressions[1]).Value, "#7");
			MSIA.ActionExpression action = (MSIA.ActionExpression)((MSIA.BoundAssignment)((MSIA.CommaExpression)exp).Expressions[1]).Value;
			Assert.IsInstanceOfType (typeof (MSA.DoOperationAction), action.Action, "#8");
			Assert.AreEqual (MSO.Subtract, ((MSA.DoOperationAction)action.Action).Operation, "#9");
		}
示例#7
0
		public void GenerateBarEqual ()
		{
			Parser parser = new Parser ("foo |= 5;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment), exp, "#1");
			Assert.AreEqual (MSO.InPlaceBitwiseOr, ((MSIA.BoundAssignment)exp).Operator, "#2");
		}
示例#8
0
		public void GeneratePrefixMinusMinus ()
		{
			Parser parser = new Parser ("--foo;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment), exp, "#1");
			Assert.IsInstanceOfType (typeof (MSIA.ActionExpression), ((MSIA.BoundAssignment)exp).Value, "#2");
			MSA.Action action = ((MSIA.ActionExpression)((MSIA.BoundAssignment)exp).Value).Action;
			Assert.IsInstanceOfType (typeof (MSA.DoOperationAction), action, "#3");
			Assert.AreEqual (MSO.Subtract, ((MSA.DoOperationAction)action).Operation, "#4");
		}
示例#9
0
		public void GenerateFunctionExp ()
		{
			Parser parser = new Parser ("function foo() {}".ToCharArray (), idtable);
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment), exp, "#1");
			Assert.AreEqual (MSO.None, ((MSIA.BoundAssignment)exp).Operator, "#2");
			//TODO more test
		}
示例#10
0
		public void GenerateQualified ()
		{
			Parser parser = new Parser ("this.foo;".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.ActionExpression), exp, "#1");
			Assert.IsInstanceOfType (typeof (MSA.GetMemberAction), ((MSIA.ActionExpression)exp).Action, "#2");
		}
示例#11
0
		public void GenerateIdentifier ()
		{
			Parser parser = new Parser ("foo;".ToCharArray (), idtable);
			List<Comment> comms = new List<Comment> ();
			MJCP.Expression input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.BoundExpression), exp, "#1");
			Assert.AreEqual (maptable.GetRowanID (idtable.InsertIdentifier ("foo")), ((MSIA.BoundExpression)exp).Name, "#2");
			Assert.AreEqual (maptable.GetRowanID (idtable.InsertIdentifier("foo")), ((MSIA.BoundExpression)exp).Reference.Name, "#3");
		}
示例#12
0
		public void Generatethis ()
		{
			MJCP.Expression input = new MJCP.Expression (MJCP.Expression.Operation.@this, new TextSpan (0,0,0,0,0,0));
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			MSIA.Expression exp = gen.Generate (input);
			Assert.IsInstanceOfType (typeof (MSIA.MethodCallExpression), exp, "#1");
			//here strange so must detect that there is no parent function
			Assert.AreEqual ("GetGlobalObject", ((MSIA.MethodCallExpression)exp).Method.Name, "#2");
			Assert.IsNull ( ((MSIA.MethodCallExpression)exp).Instance, "#3");
			Assert.AreEqual (1,((MSIA.MethodCallExpression)exp).Arguments.Count, "#4");
			Assert.IsInstanceOfType (typeof (MSIA.CodeContextExpression), ((MSIA.MethodCallExpression)exp).Arguments[0], "#5");

			// 2cd pass with a parent function to have a real this
			Parser parser = new Parser ("function foo () { var bar; this.bar=5;}".ToCharArray ());
			List<Comment> comms = new List<Comment> ();
			input = parser.ParseExpression (ref comms);
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			exp = gen.Generate (input);
			IList<MSIA.Statement> statements = ((MSIA.BlockStatement)((MSIA.CodeBlockExpression)((MSIA.MethodCallExpression)((MSIA.BoundAssignment)exp).Value).Arguments[3]).Block.Body).Statements;
			exp = ((MSIA.ExpressionStatement)statements[0]).Expression;//the this
			Assert.IsInstanceOfType (typeof (MSIA.BoundAssignment), exp, "#6");
			//((MSIA.BoundAssignment)exp).Reference.Name.
			//maptable.

		}