Ejemplo n.º 1
0
        /*public void Bind()
         * {
         *      throw new NotImplementedException();
         * }*/

        public SLE.LambdaExpression BindAndTransform(MJCP.Expression expression, MJCP.BindingInfo bindingInfo)
        {
            Init();
            //TODO test to know the internal of this and know the use of bindinginfo
            builder.Body = SLE.Expression.Block(Generate(expression));
            return(builder.MakeLambda());
        }
Ejemplo n.º 2
0
		public ObjectLiteralElement(Expression Name, Expression Value, TextPoint ColonLocation, TextPoint CommaLocation)
		{
			this.Name = Name;
			this.Value = Value;
			this.ColonLocation = ColonLocation;
			this.CommaLocation = CommaLocation;
		}
Ejemplo n.º 3
0
		public ForInStatement(Statement.Operation Opcode, Expression Collection, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint In, TextPoint LeftParen, TextPoint RightParen)
			:base(Opcode, Body, Location, LeftParen, RightParen)
		{
			this.Collection = Collection;
			this.HeaderLocation = HeaderLocation;
			this.In = In;
		}
Ejemplo n.º 4
0
		public DoStatement(Statement Body, Expression Condition, TextSpan Location, TextSpan HeaderLocation, TextPoint While, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.Do, Body, Location, LeftParen, RightParen)
		{
			this.While = While;
			this.Condition = Condition;
			this.HeaderLocation = HeaderLocation;
		}
		public BinaryOperatorExpression(Expression Left, Expression Right, Expression.Operation Opcode, TextSpan Location, TextPoint OperatorLocation)
			: base(Opcode,Location)
		{
			this.Left = Left;
			this.Right = Right;
			this.operatorLocation = OperatorLocation;
		}
Ejemplo n.º 6
0
		public SubscriptExpression(Expression Base, Expression Subscript, TextSpan Location, TextPoint LeftBracketLocation)
			: base(Operation.Subscript, Location)
		{
			this.Base = Base;
			this.Subscript = Subscript;
			this.LeftBracketLocation = LeftBracketLocation;
		}
		public DeclarationForInStatement(VariableDeclaration Item, Expression Collection, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint In, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.DeclarationForIn,Collection,Body,Location,HeaderLocation,In,LeftParen,RightParen)
		{
			this.Item = Item;
			this.In = In;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
		}
Ejemplo n.º 8
0
		public QualifiedExpression(Expression Base, Identifier Qualifier, TextSpan Location, TextPoint DotLocation, TextPoint QualifierLocation)
			:base(Operation.Qualified, Location)
		{
			this.Base = Base;
			this.Qualifier = Qualifier;
			this.DotLocation = DotLocation;
			this.QualifierLocation = QualifierLocation;
		}
		public TernaryOperatorExpression(Expression First, Expression Second, Expression Third, Expression.Operation opcode, TextSpan Location, TextPoint FirstOperatorLocation, TextPoint SecondOperatorLocation)
			:base(opcode,Location)
		{
			this.First = First;
			this.Second = Second;
			this.Third = Third;
			this.FirstOperatorLocation = FirstOperatorLocation;
			this.SecondOperatorLocation = SecondOperatorLocation;
		}
Ejemplo n.º 10
0
		public WithStatement(Expression Scope, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.With,Location)
		{
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
			this.Body = Body;
			this.HeaderLocation = HeaderLocation;
			this.Scope = Scope;
		}
Ejemplo n.º 11
0
		public ForStatement(Statement.Operation Opcode, Expression Condition, Expression Increment, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint FirstSemicolon, TextPoint SecondSemicolon, TextPoint LeftParen, TextPoint RightParen)
			:base(Opcode,Body,Location,LeftParen,RightParen)
		{
			this.Condition = Condition;
			this.Increment = Increment;
			this.HeaderLocation = HeaderLocation;
			this.FirstSemicolon= FirstSemicolon;
			this.SecondSemicolon = SecondSemicolon;
		}
Ejemplo n.º 12
0
		public SwitchStatement(Expression Value, DList<CaseClause, SwitchStatement> Cases, TextSpan Location, TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen, TextPoint LeftBrace)
			:base(Operation.Switch,Location)
		{
			this.Value = Value;
			this.Cases = Cases;
			this.HeaderLocation = HeaderLocation;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
			this.LeftBrace = LeftBrace;
		}
Ejemplo n.º 13
0
		public IfStatement (Expression Condition, Statement IfBody, Statement ElseBody, TextSpan Location,
				    TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen, TextPoint Else)
			: base (Operation.If, Location)
		{
			this.Condition = Condition;
			this.IfBody = IfBody;
			this.ElseBody = ElseBody;
			this.HeaderLocation = HeaderLocation;
			this.LeftParen = LeftParen;
			this.RightParen = RightParen;
			this.Else = Else;
		}
Ejemplo n.º 14
0
		public void GenerateSyntaxError ()
		{
			MJCP.Expression input = new MJCP.Expression (MJCP.Expression.Operation.SyntaxError, new TextSpan (0,0,0,0,0,0));
			gen.SetGlobals (new MSIA.CodeBlock ("", new List<MSIA.Parameter> (0), new MSIA.EmptyStatement ()));
			Assert.IsNull (gen.Generate (input), "#1");
		}
Ejemplo n.º 15
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.

		}
Ejemplo n.º 16
0
		public ExpressionListElement(Expression Value, TextPoint CommaLocation)
		{
			this.Value = Value;
			this.CommaLocation = CommaLocation;
		}
Ejemplo n.º 17
0
		private Expression ParseLeftHandSideExpression ()
		{
			Token start = current;
			Expression expr;
			switch (current.Kind) {
				//primary expression
				case Token.Type.@this:
					expr = new Expression (Expression.Operation.@this, new TextSpan (current, current));
					break;
				case Token.Type.Identifier:
					expr = new IdentifierExpression ((current as IdentifierToken).Spelling, new TextSpan (current, current));
					break;
				case Token.Type.@null:
					expr = new NullExpression (new TextSpan (current, current));
					break;
				case Token.Type.@true:
					expr = new Expression (Expression.Operation.@true, new TextSpan (current, current));
					break;
				case Token.Type.@false:
					expr = new Expression (Expression.Operation.@false, new TextSpan (current, current));
					break;
				case Token.Type.NumericLiteral:
					expr = new NumericLiteralExpression (((NumericLiteralToken)current).Spelling, new TextSpan (current, current));
					break;
				case Token.Type.OctalIntegerLiteral:
					expr = new OctalLiteralExpression (((OctalIntegerLiteralToken)current).Value, new TextSpan (current, current));
					break;
				case Token.Type.HexIntegerLiteral:
					expr = new HexLiteralExpression (((HexIntegerLiteralToken)current).Value, new TextSpan (current, current));
					break;
				case Token.Type.StringLiteral:
					expr = new StringLiteralExpression ((current as StringLiteralToken).Value, (current as StringLiteralToken).Spelling, new TextSpan (current, current));
					break;
				case Token.Type.LeftBracket:
					expr = ParseArrayLiteral ();
					break;
				case Token.Type.LeftBrace:
					expr = ParseObjectLiteral ();
					break;
				case Token.Type.LeftParenthesis:
					Next ();
					expr = new UnaryOperatorExpression(ParseExpression (), Expression.Operation.Parenthesized, new TextSpan(current,current));
					CheckSyntaxExpected (Token.Type.RightParenthesis);
					break;
				//end primary
				case Token.Type.function:
					expr = new FunctionExpression (ParseFunctionDefinition ());
					break;
				case Token.Type.@new:
					Next ();
					Expression target = ParseExpression ();
					ArgumentList arguments;
					if (current.Kind == Token.Type.LeftParenthesis) {
						arguments = this.ParseArgumentList ();
					} else {
						arguments = new ArgumentList (new List<ExpressionListElement> (), new TextSpan (start, current));
					}
					expr = new InvocationExpression (target, arguments,Expression.Operation.@new, new TextSpan(start,current));
					break;
				default:
					SyntaxError.Add ("Expression start with a strange token :" + current.Kind.ToString ());
					return new Expression (Expression.Operation.SyntaxError, new TextSpan (start, current));
			}
			Next (); // to go ahead for other part
			return ParseRightExpression (expr);
		}
Ejemplo n.º 18
0
		public ExpressionForInStatement(Expression Item, Expression Collection, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint In, TextPoint LeftParen, TextPoint RightParen)
			: base(Operation.ExpressionFor, Collection, Body, Location, HeaderLocation, In, LeftParen, RightParen)
		{
			this.Item = Item;
		}
Ejemplo n.º 19
0
		public UnaryOperatorExpression(Expression Operand, Expression.Operation Opcode, TextSpan Location)
			:base(Opcode, Location)
		{
			this.Operand = Operand;
		}
Ejemplo n.º 20
0
		public ValueCaseClause(Expression Value, DList<Statement, CaseClause> Children, TextSpan Location, TextSpan HeaderLocation, TextPoint Colon)
			:base(Children, Location, HeaderLocation, Colon)
		{
			this.Value = Value;
		}
Ejemplo n.º 21
0
		public ExpressionForStatement(Expression Initial, Expression Condition, Expression Increment, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint FirstSemicolon, TextPoint SecondSemicolon, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.ExpressionFor, Condition, Increment, Body, Location, HeaderLocation, FirstSemicolon, SecondSemicolon, LeftParen, RightParen)
		{
			this.Initial = Initial;
		}
Ejemplo n.º 22
0
		public WhileStatement(Expression Condition, Statement Body, TextSpan Location, TextSpan HeaderLocation, TextPoint LeftParen, TextPoint RightParen)
			:base(Operation.While, Body, Location, LeftParen, RightParen)
		{
			this.HeaderLocation = HeaderLocation;
			this.Condition = Condition;
		}
Ejemplo n.º 23
0
		//not in ecma but more clean to cut it from left hand side expr
		//group some of member expression and call expression
		private Expression ParseRightExpression (Expression expr)
		{
			Token start = current;
			while(true) {
				switch (current.Kind) {
					case Token.Type.LeftParenthesis:
						ArgumentList argumentList = ParseArgumentList ();
						expr = new InvocationExpression (expr, argumentList, Expression.Operation.Invocation, new TextSpan (start, current));
						Next ();
						break;
					case Token.Type.LeftBracket:
						Next ();
						Expression subscript = ParseExpression ();
						CheckSyntaxExpected (Token.Type.RightBracket);
						expr = new SubscriptExpression (expr, subscript, new TextSpan (start, current), new TextPoint (start.StartPosition));
						Next ();
						break;
					case Token.Type.Dot:
						Next ();
						Identifier id = null;
						if (CheckSyntaxExpected (Token.Type.Identifier))
							id = ((IdentifierToken)current).Spelling;
						expr = new QualifiedExpression (expr, id, new TextSpan (start, current), new TextPoint (start.StartPosition), new TextPoint (current.StartPosition));
						Next ();
						break;
					default:
						return expr;
				}
			}
		}
Ejemplo n.º 24
0
		public ReturnOrThrowStatement(Statement.Operation Opcode, Expression Value, TextSpan Location)
			: base(Opcode, Location)
		{
			this.Value = Value;
		}
		public InitializerVariableDeclaration(Identifier Name, Expression Initializer, TextSpan Location, TextPoint Equal)
			: base(Name, Location)
		{
			this.Initializer = Initializer;
			this.Equal = Equal;
		}
Ejemplo n.º 26
0
		public ExpressionStatement(Expression Expression, TextSpan Location)
			:base(Operation.Expression, Location)
		{
			this.Expression = Expression;
		}
Ejemplo n.º 27
0
		public InvocationExpression(Expression Target, ArgumentList Arguments, Expression.Operation Opcode, TextSpan Location)
			: base(Opcode, Location)
		{
			this.Target = Target;
			this.Arguments = Arguments;
		}