Răsfoiți Sursa

2010-03-02 Marek Safar <[email protected]>

	* cs-tokenizer.cs, argument.cs, dynamic.cs, assign.cs, anonymous.cs,
	nullable.cs, expression.cs, statement.cs, cs-parser.jay, cfold.cs:
	Report correct location for operator errors.


svn path=/trunk/mcs/; revision=152826
Marek Safar 16 ani în urmă
părinte
comite
a3adb502b6

+ 6 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,9 @@
+2010-03-02  Marek Safar  <[email protected]>
+
+	* cs-tokenizer.cs, argument.cs, dynamic.cs, assign.cs, anonymous.cs,
+	nullable.cs, expression.cs, statement.cs, cs-parser.jay, cfold.cs:
+	Report correct location for operator errors.
+
 2010-03-02  Marek Safar  <[email protected]>
 
 	* typemanager.cs (IsDynamicType): Don't check external types when

+ 20 - 15
mcs/mcs/anonymous.cs

@@ -1847,11 +1847,11 @@ namespace Mono.CSharp {
 
 				IntConstant FNV_prime = new IntConstant (16777619, loc);				
 				rs_hashcode = new Binary (Binary.Operator.Multiply,
-					new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode),
-					FNV_prime);
+					new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode, loc),
+					FNV_prime, loc);
 
 				Expression field_to_string = new Conditional (new BooleanExpression (new Binary (Binary.Operator.Inequality,
-					new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc))),
+					new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc), loc)),
 					new Invocation (new MemberAccess (
 						new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
 					new StringConstant (string.Empty, loc));
@@ -1862,7 +1862,9 @@ namespace Mono.CSharp {
 						string_concat,
 						new Binary (Binary.Operator.Addition,
 							new StringConstant (" " + p.Name + " = ", loc),
-							field_to_string));
+							field_to_string,
+							loc),
+						loc);
 					continue;
 				}
 
@@ -1872,15 +1874,18 @@ namespace Mono.CSharp {
 				string_concat = new Binary (Binary.Operator.Addition,
 					new Binary (Binary.Operator.Addition,
 						string_concat,
-						new StringConstant (", " + p.Name + " = ", loc)),
-					field_to_string);
+						new StringConstant (", " + p.Name + " = ", loc),
+						loc),
+					field_to_string,
+					loc);
 
-				rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
+				rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal, loc);
 			}
 
 			string_concat = new Binary (Binary.Operator.Addition,
 				string_concat,
-				new StringConstant (" }", loc));
+				new StringConstant (" }", loc),
+				loc);
 
 			//
 			// Equals (object obj) override
@@ -1891,9 +1896,9 @@ namespace Mono.CSharp {
 					new As (equals_block.GetParameterReference ("obj", loc),
 						current_type, loc), loc)));
 
-			Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc));
+			Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc), loc);
 			if (rs_equals != null)
-				equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals);
+				equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals, loc);
 			equals_block.AddStatement (new Return (equals_test, loc));
 
 			equals.Block = equals_block;
@@ -1934,19 +1939,19 @@ namespace Mono.CSharp {
 
 			hashcode_block.AddStatement (new StatementExpression (
 				new CompoundAssign (Binary.Operator.Addition, hash_variable,
-					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (13, loc)))));
+					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (13, loc), loc))));
 			hashcode_block.AddStatement (new StatementExpression (
 				new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable,
-					new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (7, loc)))));
+					new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (7, loc), loc))));
 			hashcode_block.AddStatement (new StatementExpression (
 				new CompoundAssign (Binary.Operator.Addition, hash_variable,
-					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (3, loc)))));
+					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (3, loc), loc))));
 			hashcode_block.AddStatement (new StatementExpression (
 				new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable,
-					new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (17, loc)))));
+					new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (17, loc), loc))));
 			hashcode_block.AddStatement (new StatementExpression (
 				new CompoundAssign (Binary.Operator.Addition, hash_variable,
-					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (5, loc)))));
+					new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (5, loc), loc))));
 
 			hashcode_block.AddStatement (new Return (hash_variable, loc));
 			hashcode.Block = hashcode_top;

+ 6 - 6
mcs/mcs/argument.cs

@@ -240,16 +240,16 @@ namespace Mono.CSharp
 				var constant = a.Expr as Constant;
 				if (constant != null && constant.IsLiteral) {
 					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc));
+						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), loc);
 				} else if (a.ArgType == Argument.AType.Ref) {
 					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc));
+						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc), loc);
 				} else if (a.ArgType == Argument.AType.Out) {
 					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc));
+						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc), loc);
 				} else if (a.ArgType == Argument.AType.DynamicTypeName) {
 					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc));
+						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc), loc);
 				}
 
 				var arg_type = a.Expr.Type;
@@ -270,14 +270,14 @@ namespace Mono.CSharp
 					}
 
 					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
+						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
 				}
 
 				string named_value;
 				NamedArgument na = a as NamedArgument;
 				if (na != null) {
 					info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc));
+						new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc), loc);
 
 					named_value = na.Name;
 				} else {

+ 1 - 1
mcs/mcs/assign.cs

@@ -657,7 +657,7 @@ namespace Mono.CSharp {
 			if (left == null)
 				left = new TargetExpression (target);
 
-			source = new Binary (op, left, right, true);
+			source = new Binary (op, left, right, true, loc);
 
 			if (target is DynamicMemberBinder) {
 				Arguments targs = ((DynamicMemberBinder) target).Arguments;

+ 2 - 2
mcs/mcs/cfold.cs

@@ -837,7 +837,7 @@ namespace Mono.CSharp {
 					if (left.IsNull || right.IsNull) {
 						return ReducedExpression.Create (
 							new BoolConstant (left.IsNull == right.IsNull, left.Location).Resolve (ec),
-							new Binary (oper, left, right));
+							new Binary (oper, left, right, loc));
 					}
 
 					if (left is StringConstant && right is StringConstant)
@@ -879,7 +879,7 @@ namespace Mono.CSharp {
 					if (left.IsNull || right.IsNull) {
 						return ReducedExpression.Create (
 							new BoolConstant (left.IsNull != right.IsNull, left.Location).Resolve (ec),
-							new Binary (oper, left, right));
+							new Binary (oper, left, right, loc));
 					}
 
 					if (left is StringConstant && right is StringConstant)

+ 34 - 32
mcs/mcs/cs-parser.jay

@@ -2523,7 +2523,7 @@ opt_enum_base
 	 }
 	| COLON error
 	 {
-	 	Error_TypeExpected (lexer.Location);
+	 	Error_TypeExpected (GetLocation ($1));
 		$$ = TypeManager.system_int32_expr;
 	 }
 	;
@@ -3049,7 +3049,6 @@ boolean_literal
 open_parens_any
 	: OPEN_PARENS
 	| OPEN_PARENS_CAST
-	| OPEN_PARENS_LAMBDA
 	;
 
 // 
@@ -3261,11 +3260,11 @@ non_simple_argument
 	  { 
 		$$ = new Argument ((Expression) $2, Argument.AType.Out);
 	  }
-	| ARGLIST open_parens_any argument_list CLOSE_PARENS
+	| ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
 	  {
 		$$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
 	  }
-	| ARGLIST open_parens_any CLOSE_PARENS
+	| ARGLIST OPEN_PARENS CLOSE_PARENS
 	  {
 		$$ = new Argument (new Arglist (GetLocation ($1)));
 	  }	  
@@ -3379,14 +3378,14 @@ base_access
 post_increment_expression
 	: primary_expression OP_INC
 	  {
-		$$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
+		$$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
 	  }
 	;
 
 post_decrement_expression
 	: primary_expression OP_DEC
 	  {
-		$$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
+		$$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
 	  }
 	;
 
@@ -3784,11 +3783,11 @@ unary_expression
 	: primary_expression
 	| BANG prefixed_unary_expression
 	  {
-		$$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
+		$$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
 	  }
 	| TILDE prefixed_unary_expression
 	  {
-		$$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
+		$$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
 	  }
 	| cast_expression
 	;
@@ -3812,19 +3811,19 @@ prefixed_unary_expression
 	: unary_expression
 	| PLUS prefixed_unary_expression
 	  { 
-	  	$$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
+	  	$$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
 	  } 
 	| MINUS prefixed_unary_expression 
 	  { 
-		$$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
+		$$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
 	  }
 	| OP_INC prefixed_unary_expression 
 	  {
-		$$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
+		$$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
 	  }
 	| OP_DEC prefixed_unary_expression 
 	  {
-		$$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
+		$$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
 	  }
 	| STAR prefixed_unary_expression
 	  {
@@ -3832,7 +3831,7 @@ prefixed_unary_expression
 	  }
 	| BITWISE_AND prefixed_unary_expression
 	  {
-		$$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
+		$$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
 	  }
 	;
 
@@ -3841,17 +3840,17 @@ multiplicative_expression
 	| multiplicative_expression STAR prefixed_unary_expression
 	  {
 		$$ = new Binary (Binary.Operator.Multiply, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| multiplicative_expression DIV prefixed_unary_expression
 	  {
 		$$ = new Binary (Binary.Operator.Division, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| multiplicative_expression PERCENT prefixed_unary_expression 
 	  {
 		$$ = new Binary (Binary.Operator.Modulus, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 
@@ -3860,16 +3859,16 @@ additive_expression
 	| additive_expression PLUS multiplicative_expression 
 	  {
 		$$ = new Binary (Binary.Operator.Addition, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| additive_expression MINUS multiplicative_expression
 	  {
-		$$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+		$$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
   	| parenthesized_expression MINUS multiplicative_expression
 	  {
 	  	// Shift/Reduce conflict
-		$$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+		$$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
   	  }
 	| additive_expression AS type
 	  {
@@ -3886,12 +3885,12 @@ shift_expression
 	| shift_expression OP_SHIFT_LEFT additive_expression
 	  {
 		$$ = new Binary (Binary.Operator.LeftShift, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| shift_expression OP_SHIFT_RIGHT additive_expression
 	  {
 		$$ = new Binary (Binary.Operator.RightShift, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	; 
 
@@ -3900,22 +3899,22 @@ relational_expression
 	| relational_expression OP_LT shift_expression
 	  {
 		$$ = new Binary (Binary.Operator.LessThan, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| relational_expression OP_GT shift_expression
 	  {
 		$$ = new Binary (Binary.Operator.GreaterThan, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| relational_expression OP_LE shift_expression
 	  {
 		$$ = new Binary (Binary.Operator.LessThanOrEqual, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| relational_expression OP_GE shift_expression
 	  {
 		$$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 
@@ -3924,12 +3923,12 @@ equality_expression
 	| equality_expression OP_EQ relational_expression
 	  {
 		$$ = new Binary (Binary.Operator.Equality, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	| equality_expression OP_NE relational_expression
 	  {
 		$$ = new Binary (Binary.Operator.Inequality, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	; 
 
@@ -3938,7 +3937,7 @@ and_expression
 	| and_expression BITWISE_AND equality_expression
 	  {
 		$$ = new Binary (Binary.Operator.BitwiseAnd, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 
@@ -3947,7 +3946,7 @@ exclusive_or_expression
 	| exclusive_or_expression CARRET and_expression
 	  {
 		$$ = new Binary (Binary.Operator.ExclusiveOr, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 
@@ -3956,7 +3955,7 @@ inclusive_or_expression
 	| inclusive_or_expression BITWISE_OR exclusive_or_expression
 	  {
 		$$ = new Binary (Binary.Operator.BitwiseOr, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 
@@ -3965,7 +3964,7 @@ conditional_and_expression
 	| conditional_and_expression OP_AND inclusive_or_expression
 	  {
 		$$ = new Binary (Binary.Operator.LogicalAnd, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 
@@ -3974,7 +3973,7 @@ conditional_or_expression
 	| conditional_or_expression OP_OR conditional_and_expression
 	  {
 		$$ = new Binary (Binary.Operator.LogicalOr, 
-			         (Expression) $1, (Expression) $3);
+			         (Expression) $1, (Expression) $3, GetLocation ($2));
 	  }
 	;
 	
@@ -4131,6 +4130,9 @@ lambda_expression
 	  }
 	| OPEN_PARENS_LAMBDA
 	  {
+		if (RootContext.Version <= LanguageVersion.ISO_2)
+			Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
+	  
 	  	valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
 	  }
 	  opt_lambda_parameter_list CLOSE_PARENS ARROW 

+ 19 - 9
mcs/mcs/cs-tokenizer.cs

@@ -289,7 +289,7 @@ namespace Mono.CSharp
 		// Values for the associated token returned
 		//
 		internal int putback_char; 	// Used by repl only
-		Object val;
+		object val;
 
 		//
 		// Pre-processor
@@ -353,6 +353,7 @@ namespace Mono.CSharp
 			public Stack<int> ifstack;
 			public int parsing_generic_less_than;
 			public int current_token;
+			public object val;
 
 			public Position (Tokenizer t)
 			{
@@ -372,6 +373,7 @@ namespace Mono.CSharp
 				}
 				parsing_generic_less_than = t.parsing_generic_less_than;
 				current_token = t.current_token;
+				val = t.val;
 			}
 		}
 		
@@ -394,6 +396,7 @@ namespace Mono.CSharp
 			ifstack = p.ifstack;
 			parsing_generic_less_than = p.parsing_generic_less_than;
 			current_token = p.current_token;
+			val = p.val;
 		}
 
 		// Do not reset the position, ignore it.
@@ -767,8 +770,7 @@ namespace Mono.CSharp
 
 		//
 		// Open parens micro parser. Detects both lambda and cast ambiguity.
-		//
-		
+		//	
 		int TokenizeOpenParens ()
 		{
 			int ptoken;
@@ -789,12 +791,8 @@ namespace Mono.CSharp
 					//
 					// Expression inside parens is lambda, (int i) => 
 					//
-					if (current_token == Token.ARROW) {
-						if (RootContext.Version <= LanguageVersion.ISO_2)
-							Report.FeatureIsNotAvailable (Location, "lambda expressions");
-
+					if (current_token == Token.ARROW)
 						return Token.OPEN_PARENS_LAMBDA;
-					}
 
 					//
 					// Expression inside parens is single type, (int[])
@@ -2664,8 +2662,10 @@ namespace Mono.CSharp
 				case ';':
 					return Token.SEMICOLON;
 				case '~':
+					val = LocatedToken.Create (ref_line, col);
 					return Token.TILDE;
 				case '?':
+					val = LocatedToken.Create (ref_line, col);
 					return TokenizePossibleNullableType ();
 				case '<':
 					if (parsing_generic_less_than++ > 0)
@@ -2700,6 +2700,7 @@ namespace Mono.CSharp
 					return Token.OP_GT;
 
 				case '+':
+					val = LocatedToken.Create (ref_line, col);
 					d = peek_char ();
 					if (d == '+') {
 						d = Token.OP_INC;
@@ -2712,6 +2713,7 @@ namespace Mono.CSharp
 					return d;
 
 				case '-':
+					val = LocatedToken.Create (ref_line, col);
 					d = peek_char ();
 					if (d == '-') {
 						d = Token.OP_DEC;
@@ -2726,6 +2728,7 @@ namespace Mono.CSharp
 					return d;
 
 				case '!':
+					val = LocatedToken.Create (ref_line, col);
 					if (peek_char () == '='){
 						get_char ();
 						return Token.OP_NE;
@@ -2733,6 +2736,7 @@ namespace Mono.CSharp
 					return Token.BANG;
 
 				case '=':
+					val = LocatedToken.Create (ref_line, col);
 					d = peek_char ();
 					if (d == '='){
 						get_char ();
@@ -2746,6 +2750,7 @@ namespace Mono.CSharp
 					return Token.ASSIGN;
 
 				case '&':
+					val = LocatedToken.Create (ref_line, col);
 					d = peek_char ();
 					if (d == '&'){
 						get_char ();
@@ -2758,6 +2763,7 @@ namespace Mono.CSharp
 					return Token.BITWISE_AND;
 
 				case '|':
+					val = LocatedToken.Create (ref_line, col);
 					d = peek_char ();
 					if (d == '|'){
 						get_char ();
@@ -2770,16 +2776,17 @@ namespace Mono.CSharp
 					return Token.BITWISE_OR;
 
 				case '*':
+					val = LocatedToken.Create (ref_line, col);
 					if (peek_char () == '='){
 						get_char ();
 						return Token.OP_MULT_ASSIGN;
 					}
-					val = LocatedToken.Create (ref_line, col);
 					return Token.STAR;
 
 				case '/':
 					d = peek_char ();
 					if (d == '='){
+						val = LocatedToken.Create (ref_line, col);
 						get_char ();
 						return Token.OP_DIV_ASSIGN;
 					}
@@ -2856,6 +2863,7 @@ namespace Mono.CSharp
 					return Token.DIV;
 
 				case '%':
+					val = LocatedToken.Create (ref_line, col);
 					if (peek_char () == '='){
 						get_char ();
 						return Token.OP_MOD_ASSIGN;
@@ -2863,6 +2871,7 @@ namespace Mono.CSharp
 					return Token.PERCENT;
 
 				case '^':
+					val = LocatedToken.Create (ref_line, col);
 					if (peek_char () == '='){
 						get_char ();
 						return Token.OP_XOR_ASSIGN;
@@ -2870,6 +2879,7 @@ namespace Mono.CSharp
 					return Token.CARRET;
 
 				case ':':
+					val = LocatedToken.Create (ref_line, col);
 					if (peek_char () == ':') {
 						get_char ();
 						return Token.DOUBLE_COLON;

+ 2 - 2
mcs/mcs/dynamic.cs

@@ -358,7 +358,7 @@ namespace Mono.CSharp
 			
 			BlockContext bc = new BlockContext (ec.MemberContext, null, TypeManager.void_type);		
 			if (s.Resolve (bc)) {
-				Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
+				Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc), loc), s, loc);
 				init.Emit (ec);
 			}
 
@@ -482,7 +482,7 @@ namespace Mono.CSharp
 			type = TypeManager.bool_type;
 
 			condition = new If (
-				new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc)),
+				new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc), loc),
 				new StatementExpression (invoke), new StatementExpression (assignment),
 				loc);
 		}

+ 15 - 16
mcs/mcs/expression.cs

@@ -123,11 +123,11 @@ namespace Mono.CSharp {
 		public Expression Expr;
 		Expression enum_conversion;
 
-		public Unary (Operator op, Expression expr)
+		public Unary (Operator op, Expression expr, Location loc)
 		{
 			Oper = op;
 			Expr = expr;
-			loc = expr.Location;
+			this.loc = loc;
 		}
 
 		// <summary>
@@ -442,7 +442,7 @@ namespace Mono.CSharp {
 			}
 
 			if (TypeManager.IsNullableType (Expr.Type))
-				return new Nullable.LiftedUnaryOperator (Oper, Expr).Resolve (ec);
+				return new Nullable.LiftedUnaryOperator (Oper, Expr, loc).Resolve (ec);
 
 			//
 			// Attempt to use a constant folding operation.
@@ -988,10 +988,10 @@ namespace Mono.CSharp {
 		// Holds the real operation
 		Expression operation;
 
-		public UnaryMutator (Mode m, Expression e)
+		public UnaryMutator (Mode m, Expression e, Location loc)
 		{
 			mode = m;
-			loc = e.Location;
+			this.loc = loc;
 			expr = e;
 		}
 
@@ -1130,7 +1130,7 @@ namespace Mono.CSharp {
 				// TODO: Cache this based on type when using EmptyExpression in
 				// context cache
 				Binary.Operator op = IsDecrement ? Binary.Operator.Subtraction : Binary.Operator.Addition;
-				operation = new Binary (op, operation, one);
+				operation = new Binary (op, operation, one, loc);
 				operation = operation.Resolve (ec);
 				if (operation != null && operation.Type != type)
 					operation = Convert.ExplicitNumericConversion (operation, type);
@@ -1687,7 +1687,6 @@ namespace Mono.CSharp {
 	/// </summary>
 	public class Binary : Expression, IDynamicBinder
 	{
-
 		protected class PredefinedOperator {
 			protected readonly Type left;
 			protected readonly Type right;
@@ -1849,7 +1848,7 @@ namespace Mono.CSharp {
 				// b = b.left >> b.right & (0x1f|0x3f)
 				//
 				b.right = new Binary (Operator.BitwiseAnd,
-					b.right, new IntConstant (right_mask, b.right.Location)).Resolve (ec);
+					b.right, new IntConstant (right_mask, b.right.Location), b.loc).Resolve (ec);
 
 				//
 				// Expression tree representation does not use & mask
@@ -1982,18 +1981,18 @@ namespace Mono.CSharp {
 		static PredefinedOperator [] standard_operators;
 		static PredefinedOperator [] pointer_operators;
 		
-		public Binary (Operator oper, Expression left, Expression right, bool isCompound)
-			: this (oper, left, right)
+		public Binary (Operator oper, Expression left, Expression right, bool isCompound, Location loc)
+			: this (oper, left, right, loc)
 		{
 			this.is_compound = isCompound;
 		}
 
-		public Binary (Operator oper, Expression left, Expression right)
+		public Binary (Operator oper, Expression left, Expression right, Location loc)
 		{
 			this.oper = oper;
 			this.left = left;
 			this.right = right;
-			this.loc = left.Location;
+			this.loc = loc;
 		}
 
 		public Operator Oper {
@@ -2076,7 +2075,7 @@ namespace Mono.CSharp {
 
 		public static void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right, Operator oper, Location loc)
 		{
-			new Binary (oper, left, right).Error_OperatorCannotBeApplied (ec, left, right);
+			new Binary (oper, left, right, loc).Error_OperatorCannotBeApplied (ec, left, right);
 		}
 
 		public static void Error_OperatorCannotBeApplied (ResolveContext ec, Expression left, Expression right, string oper, Location loc)
@@ -4089,7 +4088,7 @@ namespace Mono.CSharp {
 					
 					// TODO: Should be the checks resolve context sensitive?
 					ResolveContext rc = new ResolveContext (ec.MemberContext, ResolveContext.Options.UnsafeScope);
-					right = new Binary (Binary.Operator.Multiply, right, right_const).Resolve (rc);
+					right = new Binary (Binary.Operator.Multiply, right, right_const, loc).Resolve (rc);
 					if (right == null)
 						return;
 				}
@@ -4253,7 +4252,7 @@ namespace Mono.CSharp {
 					// Check if both can convert implicitly to each other's type
 					//
 					if (Convert.ImplicitConversion (ec, false_expr, true_type, loc) != null) {
-						ec.Report.Error (172, loc,
+						ec.Report.Error (172, true_expr.Location,
 							"Type of conditional expression cannot be determined as `{0}' and `{1}' convert implicitly to each other",
 							TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type));
 						return null;
@@ -4263,7 +4262,7 @@ namespace Mono.CSharp {
 				} else if ((conv = Convert.ImplicitConversion (ec, false_expr, true_type, loc)) != null) {
 					false_expr = conv;
 				} else {
-					ec.Report.Error (173, loc,
+					ec.Report.Error (173, true_expr.Location,
 						"Type of conditional expression cannot be determined because there is no implicit conversion between `{0}' and `{1}'",
 						TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type));
 					return null;

+ 5 - 7
mcs/mcs/nullable.cs

@@ -459,8 +459,8 @@ namespace Mono.CSharp.Nullable
 		Unwrap unwrap;
 		Expression user_operator;
 
-		public LiftedUnaryOperator (Unary.Operator op, Expression expr)
-			: base (op, expr)
+		public LiftedUnaryOperator (Unary.Operator op, Expression expr, Location loc)
+			: base (op, expr, loc)
 		{
 		}
 
@@ -575,11 +575,9 @@ namespace Mono.CSharp.Nullable
 		Expression user_operator;
 		MethodSpec wrap_ctor;
 
-		public LiftedBinaryOperator (Binary.Operator op, Expression left, Expression right,
-					     Location loc)
-			: base (op, left, right)
+		public LiftedBinaryOperator (Binary.Operator op, Expression left, Expression right, Location loc)
+			: base (op, left, right, loc)
 		{
-			this.loc = loc;
 		}
 
 		public override Expression CreateExpressionTree (ResolveContext ec)
@@ -1141,7 +1139,7 @@ namespace Mono.CSharp.Nullable
 			if (unwrap == null)
 				return null;
 
-			underlying = (UnaryMutator) new UnaryMutator (Mode, unwrap).Resolve (ec);
+			underlying = (UnaryMutator) new UnaryMutator (Mode, unwrap, loc).Resolve (ec);
 			if (underlying == null)
 				return null;
 

+ 3 - 3
mcs/mcs/statement.cs

@@ -4464,8 +4464,8 @@ namespace Mono.CSharp {
 					// fixed (T* e_ptr = (e == null || e.Length == 0) ? null : converted [0])
 					//
 					converted = new Conditional (new BooleanExpression (new Binary (Binary.Operator.LogicalOr,
-						new Binary (Binary.Operator.Equality, e, new NullLiteral (loc)),
-						new Binary (Binary.Operator.Equality, new MemberAccess (e, "Length"), new IntConstant (0, loc)))),
+						new Binary (Binary.Operator.Equality, e, new NullLiteral (loc), loc),
+						new Binary (Binary.Operator.Equality, new MemberAccess (e, "Length"), new IntConstant (0, loc), loc), loc)),
 							new NullPointer (loc),
 							converted);
 
@@ -5132,7 +5132,7 @@ namespace Mono.CSharp {
 
 				public void ResolveIncrement (BlockContext ec)
 				{
-					increment = new StatementExpression (new UnaryMutator (UnaryMutator.Mode.PostIncrement, this));
+					increment = new StatementExpression (new UnaryMutator (UnaryMutator.Mode.PostIncrement, this, loc));
 					increment.Resolve (ec);
 				}