@ -83,6 +83,11 @@ namespace Mono.CSharp
@@ -83,6 +83,11 @@ namespace Mono.CSharp
call . EmitPredefined ( ec , oper , arguments , loc ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
arguments . FlowAnalysis ( fc ) ;
}
public override SLE . Expression MakeExpression ( BuilderContext ctx )
{
#if STATIC
@ -572,6 +577,31 @@ namespace Mono.CSharp
@@ -572,6 +577,31 @@ namespace Mono.CSharp
Expr . EmitSideEffect ( ec ) ;
}
public static void Error_Ambiguous ( ResolveContext rc , string oper , TypeSpec type , Location loc )
{
rc . Report . Error ( 3 5 , loc , "Operator `{0}' is ambiguous on an operand of type `{1}'" ,
oper , type . GetSignatureForError ( ) ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
if ( Oper = = Operator . AddressOf ) {
var vr = Expr as VariableReference ;
if ( vr ! = null & & vr . VariableInfo ! = null )
fc . SetVariableAssigned ( vr . VariableInfo ) ;
return ;
}
Expr . FlowAnalysis ( fc ) ;
if ( Oper = = Operator . LogicalNot ) {
var temp = fc . DefiniteAssignmentOnTrue ;
fc . DefiniteAssignmentOnTrue = fc . DefiniteAssignmentOnFalse ;
fc . DefiniteAssignmentOnFalse = temp ;
}
}
//
// Converts operator to System.Linq.Expressions.ExpressionType enum name
//
@ -627,7 +657,7 @@ namespace Mono.CSharp
@@ -627,7 +657,7 @@ namespace Mono.CSharp
return is_checked ? SLE . Expression . NegateChecked ( expr ) : SLE . Expression . Negate ( expr ) ;
case Operator . LogicalNot :
return SLE . Expression . Not ( expr ) ;
#if NET_4_0 || MONODROID
#if NET_4_0 || MOBILE_DYNAMIC
case Operator . OnesComplement :
return SLE . Expression . OnesComplement ( expr ) ;
#endif
@ -757,8 +787,7 @@ namespace Mono.CSharp
@@ -757,8 +787,7 @@ namespace Mono.CSharp
int result = OverloadResolver . BetterTypeConversion ( ec , best_expr . Type , t ) ;
if ( result = = 0 ) {
if ( ( oper_expr is UserOperatorCall | | oper_expr is UserCast ) & & ( best_expr is UserOperatorCall | | best_expr is UserCast ) ) {
ec . Report . Error ( 3 5 , loc , "Operator `{0}' is ambiguous on an operand of type `{1}'" ,
OperName ( Oper ) , expr . Type . GetSignatureForError ( ) ) ;
Error_Ambiguous ( ec , OperName ( Oper ) , expr . Type , loc ) ;
} else {
Error_OperatorCannotBeApplied ( ec , loc , OperName ( Oper ) , expr . Type ) ;
}
@ -1199,14 +1228,33 @@ namespace Mono.CSharp
@@ -1199,14 +1228,33 @@ namespace Mono.CSharp
source = operation ;
} else {
Expression best_source = null ;
foreach ( var t in ec . BuiltinTypes . OperatorsUnaryMutator ) {
source = Convert . ImplicitUserConversion ( ec , operation , t , loc ) ;
// LAMESPEC: It should error on ambiguous operators but that would make us incompatible
if ( source ! = null ) {
break ;
if ( source = = null )
continue ;
if ( best_source = = null ) {
best_source = source ;
continue ;
}
var better = OverloadResolver . BetterTypeConversion ( ec , best_source . Type , source . Type ) ;
if ( better = = 1 )
continue ;
if ( better = = 2 ) {
best_source = source ;
continue ;
}
Unary . Error_Ambiguous ( ec , OperName ( mode ) , type , loc ) ;
break ;
}
source = best_source ;
}
// ++/-- on enum types
@ -1274,6 +1322,11 @@ namespace Mono.CSharp
@@ -1274,6 +1322,11 @@ namespace Mono.CSharp
EmitCode ( ec , false ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
expr . FlowAnalysis ( fc ) ;
}
//
// Converts operator to System.Linq.Expressions.ExpressionType enum name
//
@ -1287,7 +1340,7 @@ namespace Mono.CSharp
@@ -1287,7 +1340,7 @@ namespace Mono.CSharp
}
#if NET_4_0 || MONODROID
#if NET_4_0 || MOBILE_DYNAMIC
public override SLE . Expression MakeExpression ( BuilderContext ctx )
{
var target = ( ( RuntimeValueExpression ) expr ) . MetaObject . Expression ;
@ -1296,6 +1349,11 @@ namespace Mono.CSharp
@@ -1296,6 +1349,11 @@ namespace Mono.CSharp
}
#endif
public static string OperName ( Mode oper )
{
return ( oper & Mode . IsDecrement ) ! = 0 ? "--" : "++" ;
}
protected override void CloneTo ( CloneContext clonectx , Expression t )
{
UnaryMutator target = ( UnaryMutator ) t ;
@ -1367,6 +1425,11 @@ namespace Mono.CSharp
@@ -1367,6 +1425,11 @@ namespace Mono.CSharp
return this ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
expr . FlowAnalysis ( fc ) ;
}
protected abstract string OperatorName { get ; }
protected override void CloneTo ( CloneContext clonectx , Expression t )
@ -1859,7 +1922,7 @@ namespace Mono.CSharp
@@ -1859,7 +1922,7 @@ namespace Mono.CSharp
temp_storage . Release ( ec ) ;
}
#if (NET_4_0 || MONODROID ) && !STATIC
#if (NET_4_0 || MOBILE_DYNAMIC ) && !STATIC
public override SLE . Expression MakeExpression ( BuilderContext ctx )
{
return SLE . Expression . Default ( type . GetMetaInfo ( ) ) ;
@ -2518,6 +2581,49 @@ namespace Mono.CSharp
@@ -2518,6 +2581,49 @@ namespace Mono.CSharp
Error_OperatorCannotBeApplied ( ec , left , right , OperName ( oper ) , loc ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
if ( ( oper & Operator . LogicalMask ) = = 0 ) {
left . FlowAnalysis ( fc ) ;
right . FlowAnalysis ( fc ) ;
return ;
}
//
// Optimized version when on-true/on-false data are not needed
//
bool set_on_true_false ;
if ( fc . DefiniteAssignmentOnTrue = = null & & fc . DefiniteAssignmentOnFalse = = null ) {
fc . DefiniteAssignmentOnFalse = fc . DefiniteAssignmentOnTrue = fc . DefiniteAssignment ;
set_on_true_false = false ;
} else {
set_on_true_false = true ;
}
left . FlowAnalysis ( fc ) ;
var left_fc = fc . DefiniteAssignment ;
var left_fc_ontrue = fc . DefiniteAssignmentOnTrue ;
var left_fc_onfalse = fc . DefiniteAssignmentOnFalse ;
fc . DefiniteAssignmentOnTrue = fc . DefiniteAssignmentOnFalse = fc . DefiniteAssignment = new DefiniteAssignmentBitSet (
oper = = Operator . LogicalOr ? left_fc_onfalse : left_fc_ontrue ) ;
right . FlowAnalysis ( fc ) ;
fc . DefiniteAssignment = left_fc ;
if ( ! set_on_true_false ) {
fc . DefiniteAssignmentOnFalse = fc . DefiniteAssignmentOnTrue = null ;
return ;
}
if ( oper = = Operator . LogicalOr ) {
fc . DefiniteAssignmentOnTrue = new DefiniteAssignmentBitSet ( left_fc_ontrue ) ;
fc . DefiniteAssignmentOnFalse = left_fc_onfalse | fc . DefiniteAssignmentOnFalse ;
} else {
fc . DefiniteAssignmentOnTrue = left_fc_ontrue | fc . DefiniteAssignmentOnTrue ;
fc . DefiniteAssignmentOnFalse = new DefiniteAssignmentBitSet ( left_fc_onfalse ) ;
}
}
//
// Converts operator to System.Linq.Expressions.ExpressionType enum name
//
@ -4890,6 +4996,11 @@ namespace Mono.CSharp
@@ -4890,6 +4996,11 @@ namespace Mono.CSharp
}
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
arguments . FlowAnalysis ( fc ) ;
}
public override SLE . Expression MakeExpression ( BuilderContext ctx )
{
if ( arguments . Count ! = 2 )
@ -5259,32 +5370,8 @@ namespace Mono.CSharp
@@ -5259,32 +5370,8 @@ namespace Mono.CSharp
protected override Expression DoResolve ( ResolveContext ec )
{
expr = expr . Resolve ( ec ) ;
//
// Unreachable code needs different resolve path. For instance for await
// expression to not generate unreachable resumable statement
//
Constant c = expr as Constant ;
if ( c ! = null & & ec . CurrentBranching ! = null ) {
bool unreachable = ec . CurrentBranching . CurrentUsageVector . IsUnreachable ;
if ( c . IsDefaultValue ) {
ec . CurrentBranching . CurrentUsageVector . IsUnreachable = true ;
true_expr = true_expr . Resolve ( ec ) ;
ec . CurrentBranching . CurrentUsageVector . IsUnreachable = unreachable ;
false_expr = false_expr . Resolve ( ec ) ;
} else {
true_expr = true_expr . Resolve ( ec ) ;
ec . CurrentBranching . CurrentUsageVector . IsUnreachable = true ;
false_expr = false_expr . Resolve ( ec ) ;
ec . CurrentBranching . CurrentUsageVector . IsUnreachable = unreachable ;
}
} else {
true_expr = true_expr . Resolve ( ec ) ;
false_expr = false_expr . Resolve ( ec ) ;
}
true_expr = true_expr . Resolve ( ec ) ;
false_expr = false_expr . Resolve ( ec ) ;
if ( true_expr = = null | | false_expr = = null | | expr = = null )
return null ;
@ -5345,8 +5432,9 @@ namespace Mono.CSharp
@@ -5345,8 +5432,9 @@ namespace Mono.CSharp
true_type . GetSignatureForError ( ) , false_type . GetSignatureForError ( ) ) ;
return null ;
}
}
}
Constant c = expr as Constant ;
if ( c ! = null ) {
bool is_false = c . IsDefaultValue ;
@ -5392,6 +5480,28 @@ namespace Mono.CSharp
@@ -5392,6 +5480,28 @@ namespace Mono.CSharp
ec . MarkLabel ( end_target ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
fc . DefiniteAssignmentOnTrue = fc . DefiniteAssignmentOnFalse = fc . DefiniteAssignment ;
expr . FlowAnalysis ( fc ) ;
var da_true = fc . DefiniteAssignmentOnTrue ;
var da_false = fc . DefiniteAssignmentOnFalse ;
fc . DefiniteAssignment = new DefiniteAssignmentBitSet ( da_true ) ;
true_expr . FlowAnalysis ( fc ) ;
var true_fc = fc . DefiniteAssignment ;
fc . DefiniteAssignment = new DefiniteAssignmentBitSet ( da_false ) ;
false_expr . FlowAnalysis ( fc ) ;
fc . DefiniteAssignment & = true_fc ;
if ( fc . DefiniteAssignmentOnTrue ! = null )
fc . DefiniteAssignmentOnTrue = fc . DefiniteAssignment ;
if ( fc . DefiniteAssignmentOnFalse ! = null )
fc . DefiniteAssignmentOnFalse = fc . DefiniteAssignment ;
}
protected override void CloneTo ( CloneContext clonectx , Expression t )
{
Conditional target = ( Conditional ) t ;
@ -5414,7 +5524,6 @@ namespace Mono.CSharp
@@ -5414,7 +5524,6 @@ namespace Mono.CSharp
#region Abstract
public abstract HoistedVariable GetHoistedVariable ( AnonymousExpression ae ) ;
public abstract void SetHasAddressTaken ( ) ;
public abstract void VerifyDefiniteAssignment ( ResolveContext rc ) ;
public abstract bool IsLockedByStatement { get ; set ; }
@ -5647,17 +5756,17 @@ namespace Mono.CSharp
@@ -5647,17 +5756,17 @@ namespace Mono.CSharp
#endregion
public override void VerifyDefiniteAssignment ( ResolveContext r c)
public override void FlowAnalysis ( FlowAnalysisContext f c)
{
VariableInfo variable_info = VariableInfo ;
if ( variable_info = = null )
return ;
if ( variable_info . IsAssigned ( rc ) )
if ( fc . IsDefinitelyAssigned ( variable_info ) )
return ;
r c. Report . Error ( 1 6 5 , loc , "Use of unassigned local variable `{0}'" , Name ) ;
variable_info . SetAssigned ( rc ) ;
f c. Report . Error ( 1 6 5 , loc , "Use of unassigned local variable `{0}'" , Name ) ;
variable_info . SetAssigned ( fc . DefiniteAssignment , true ) ;
}
public override void SetHasAddressTaken ( )
@ -5694,8 +5803,6 @@ namespace Mono.CSharp
@@ -5694,8 +5803,6 @@ namespace Mono.CSharp
{
local_info . SetIsUsed ( ) ;
VerifyDefiniteAssignment ( ec ) ;
DoResolveBase ( ec ) ;
return this ;
}
@ -5710,22 +5817,22 @@ namespace Mono.CSharp
@@ -5710,22 +5817,22 @@ namespace Mono.CSharp
local_info . SetIsUsed ( ) ;
if ( local_info . IsReadonly & & ! ec . HasAny ( ResolveContext . Options . FieldInitializerScope | ResolveContext . Options . UsingInitializerScope ) ) {
int code ;
string msg ;
if ( rhs = = EmptyExpression . OutAccess ) {
code = 1 6 5 7 ; msg = "Cannot pass `{0}' as a ref or out argument because it is a `{1}'" ;
} else if ( rhs = = EmptyExpression . LValueMemberAccess ) {
code = 1 6 5 4 ; msg = "Cannot assign to members of `{0}' because it is a `{1}'" ;
} else if ( rhs = = EmptyExpression . LValueMemberOutAccess ) {
code = 1 6 5 5 ; msg = "Cannot pass members of `{0}' as ref or out arguments because it is a `{1}'" ;
} else if ( rhs = = EmptyExpression . UnaryAddress ) {
code = 4 5 9 ; msg = "Cannot take the address of {1} `{0}'" ;
if ( rhs = = EmptyExpression . LValueMemberAccess ) {
// CS1654 already reported
} else {
code = 1 6 5 6 ; msg = "Cannot assign to `{0}' because it is a `{1}'" ;
int code ;
string msg ;
if ( rhs = = EmptyExpression . OutAccess ) {
code = 1 6 5 7 ; msg = "Cannot pass `{0}' as a ref or out argument because it is a `{1}'" ;
} else if ( rhs = = EmptyExpression . LValueMemberOutAccess ) {
code = 1 6 5 5 ; msg = "Cannot pass members of `{0}' as ref or out arguments because it is a `{1}'" ;
} else if ( rhs = = EmptyExpression . UnaryAddress ) {
code = 4 5 9 ; msg = "Cannot take the address of {1} `{0}'" ;
} else {
code = 1 6 5 6 ; msg = "Cannot assign to `{0}' because it is a `{1}'" ;
}
ec . Report . Error ( code , loc , msg , Name , local_info . GetReadOnlyContext ( ) ) ;
}
ec . Report . Error ( code , loc , msg , Name , local_info . GetReadOnlyContext ( ) ) ;
} else if ( VariableInfo ! = null ) {
VariableInfo . SetAssigned ( ec ) ;
}
if ( eclass = = ExprClass . Unresolved )
@ -5850,15 +5957,6 @@ namespace Mono.CSharp
@@ -5850,15 +5957,6 @@ namespace Mono.CSharp
Parameter . HasAddressTaken = true ;
}
void SetAssigned ( ResolveContext ec )
{
if ( Parameter . HoistedVariant ! = null )
Parameter . HoistedVariant . IsAssigned = true ;
if ( HasOutModifier & & ec . DoFlowAnalysis )
ec . CurrentBranching . SetAssigned ( VariableInfo ) ;
}
bool DoResolveBase ( ResolveContext ec )
{
if ( eclass ! = ExprClass . Unresolved )
@ -5924,7 +6022,6 @@ namespace Mono.CSharp
@@ -5924,7 +6022,6 @@ namespace Mono.CSharp
if ( ! DoResolveBase ( ec ) )
return null ;
VerifyDefiniteAssignment ( ec ) ;
return this ;
}
@ -5933,21 +6030,23 @@ namespace Mono.CSharp
@@ -5933,21 +6030,23 @@ namespace Mono.CSharp
if ( ! DoResolveBase ( ec ) )
return null ;
SetAssigned ( ec ) ;
if ( Parameter . HoistedVariant ! = null )
Parameter . HoistedVariant . IsAssigned = true ;
return base . DoResolveLValue ( ec , right_side ) ;
}
public override void VerifyDefiniteAssignment ( ResolveContext r c)
public override void FlowAnalysis ( FlowAnalysisContext f c)
{
VariableInfo variable_info = VariableInfo ;
if ( variable_info = = null )
return ;
if ( variable_info . IsAssigned ( rc ) )
if ( fc . IsDefinitelyAssigned ( variable_info ) )
return ;
r c. Report . Error ( 2 6 9 , loc , "Use of unassigned out parameter `{0}'" , Name ) ;
variable_info . SetAssigned ( rc ) ;
f c. Report . Error ( 2 6 9 , loc , "Use of unassigned out parameter `{0}'" , Name ) ;
fc . SetVariable Assigned ( variable_info ) ;
}
}
@ -6215,6 +6314,17 @@ namespace Mono.CSharp
@@ -6215,6 +6314,17 @@ namespace Mono.CSharp
return mg . OverloadResolve ( ec , ref arguments , null , OverloadResolver . Restrictions . None ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
if ( mg . IsConditionallyExcluded )
return ;
mg . FlowAnalysis ( fc ) ;
if ( arguments ! = null )
arguments . FlowAnalysis ( fc ) ;
}
public override string GetSignatureForError ( )
{
return mg . GetSignatureForError ( ) ;
@ -6255,6 +6365,9 @@ namespace Mono.CSharp
@@ -6255,6 +6365,9 @@ namespace Mono.CSharp
public override void Emit ( EmitContext ec )
{
if ( mg . IsConditionallyExcluded )
return ;
mg . EmitCall ( ec , arguments ) ;
}
@ -6646,6 +6759,12 @@ namespace Mono.CSharp
@@ -6646,6 +6759,12 @@ namespace Mono.CSharp
ec . Emit ( OpCodes . Pop ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
if ( arguments ! = null )
arguments . FlowAnalysis ( fc ) ;
}
public void AddressOf ( EmitContext ec , AddressOp mode )
{
EmitAddressOf ( ec , mode ) ;
@ -6805,6 +6924,11 @@ namespace Mono.CSharp
@@ -6805,6 +6924,11 @@ namespace Mono.CSharp
{
throw new InternalErrorException ( "Missing Resolve call" ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
throw new InternalErrorException ( "Missing Resolve call" ) ;
}
public override object Accept ( StructuralVisitor visitor )
{
@ -7070,6 +7194,17 @@ namespace Mono.CSharp
@@ -7070,6 +7194,17 @@ namespace Mono.CSharp
ec . Report . Error ( 2 4 8 , loc , "Cannot create an array with a negative size" ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
foreach ( var arg in arguments )
arg . FlowAnalysis ( fc ) ;
if ( array_data ! = null ) {
foreach ( var ad in array_data )
ad . FlowAnalysis ( fc ) ;
}
}
bool InitializersContainAwait ( )
{
if ( array_data = = null )
@ -7309,7 +7444,7 @@ namespace Mono.CSharp
@@ -7309,7 +7444,7 @@ namespace Mono.CSharp
return data ;
}
#if NET_4_0 || MONODROID
#if NET_4_0 || MOBILE_DYNAMIC
public override SLE . Expression MakeExpression ( BuilderContext ctx )
{
#if STATIC
@ -7714,7 +7849,7 @@ namespace Mono.CSharp
@@ -7714,7 +7849,7 @@ namespace Mono.CSharp
#endregion
public void CheckStructThisDefiniteAssignment ( ResolveContext r c)
void CheckStructThisDefiniteAssignment ( FlowAnalysisContext f c)
{
//
// It's null for all cases when we don't need to check `this'
@ -7723,13 +7858,10 @@ namespace Mono.CSharp
@@ -7723,13 +7858,10 @@ namespace Mono.CSharp
if ( variable_info = = null )
return ;
if ( rc . OmitStructFlowAnalysis )
if ( fc . IsDefinitelyAssigned ( variable_info ) )
return ;
if ( ! variable_info . IsAssigned ( rc ) ) {
rc . Report . Error ( 1 8 8 , loc ,
"The `this' object cannot be used before all of its fields are assigned to" ) ;
}
fc . Report . Error ( 1 8 8 , loc , "The `this' object cannot be used before all of its fields are assigned to" ) ;
}
protected virtual void Error_ThisNotAvailable ( ResolveContext ec )
@ -7745,6 +7877,11 @@ namespace Mono.CSharp
@@ -7745,6 +7877,11 @@ namespace Mono.CSharp
}
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
CheckStructThisDefiniteAssignment ( fc ) ;
}
public override HoistedVariable GetHoistedVariable ( AnonymousExpression ae )
{
if ( ae = = null )
@ -7802,9 +7939,6 @@ namespace Mono.CSharp
@@ -7802,9 +7939,6 @@ namespace Mono.CSharp
protected override Expression DoResolve ( ResolveContext ec )
{
ResolveBase ( ec ) ;
CheckStructThisDefiniteAssignment ( ec ) ;
return this ;
}
@ -7813,9 +7947,6 @@ namespace Mono.CSharp
@@ -7813,9 +7947,6 @@ namespace Mono.CSharp
if ( eclass = = ExprClass . Unresolved )
ResolveBase ( ec ) ;
if ( variable_info ! = null )
variable_info . SetAssigned ( ec ) ;
if ( type . IsClass ) {
if ( right_side = = EmptyExpression . UnaryAddress )
ec . Report . Error ( 4 5 9 , loc , "Cannot take the address of `this' because it is read-only" ) ;
@ -7851,12 +7982,6 @@ namespace Mono.CSharp
@@ -7851,12 +7982,6 @@ namespace Mono.CSharp
{
// Nothing
}
public override void VerifyDefiniteAssignment ( ResolveContext rc )
{
}
public override object Accept ( StructuralVisitor visitor )
{
@ -8643,50 +8768,25 @@ namespace Mono.CSharp
@@ -8643,50 +8768,25 @@ namespace Mono.CSharp
protected override Expression DoResolve ( ResolveContext rc )
{
var e = DoResolveName ( rc , null ) ;
if ( ! rc . OmitStructFlowAnalysis ) {
var fe = e as FieldExpr ;
if ( fe ! = null ) {
fe . VerifyAssignedStructField ( rc , null ) ;
}
}
var e = LookupNameExpression ( rc , MemberLookupRestrictions . ReadAccess ) ;
if ( e ! = null )
e = e . Resolve ( rc , ResolveFlags . VariableOrValue | ResolveFlags . Type | ResolveFlags . MethodGroup ) ;
return e ;
}
public override Expression DoResolveLValue ( ResolveContext rc , Expression rhs )
{
var e = DoResolveName ( rc , rhs ) ;
if ( ! rc . OmitStructFlowAnalysis ) {
var fe = e as FieldExpr ;
if ( fe ! = null & & fe . InstanceExpression is FieldExpr ) {
fe = ( FieldExpr ) fe . InstanceExpression ;
fe . VerifyAssignedStructField ( rc , rhs ) ;
}
}
var e = LookupNameExpression ( rc , MemberLookupRestrictions . None ) ;
return e ;
}
Expression DoResolveName ( ResolveContext rc , Expression right_side )
{
Expression e = LookupNameExpression ( rc , right_side = = null ? MemberLookupRestrictions . ReadAccess : MemberLookupRestrictions . None ) ;
if ( e = = null )
if ( e is TypeExpr ) {
e . Error_UnexpectedKind ( rc , ResolveFlags . VariableOrValue , loc ) ;
return null ;
if ( right_side ! = null ) {
if ( e is TypeExpr ) {
e . Error_UnexpectedKind ( rc , ResolveFlags . VariableOrValue , loc ) ;
return null ;
}
e = e . ResolveLValue ( rc , right_side ) ;
} else {
e = e . Resolve ( rc , ResolveFlags . VariableOrValue | ResolveFlags . Type | ResolveFlags . MethodGroup ) ;
}
if ( e ! = null )
e = e . ResolveLValue ( rc , rhs ) ;
return e ;
}
@ -8711,32 +8811,22 @@ namespace Mono.CSharp
@@ -8711,32 +8811,22 @@ namespace Mono.CSharp
var sn = expr as SimpleName ;
const ResolveFlags flags = ResolveFlags . VariableOrValue | ResolveFlags . Type ;
//
// Resolve the expression with flow analysis turned off, we'll do the definite
// assignment checks later. This is because we don't know yet what the expression
// will resolve to - it may resolve to a FieldExpr and in this case we must do the
// definite assignment check on the actual field and not on the whole struct.
//
using ( rc . Set ( ResolveContext . Options . OmitStructFlowAnalysis ) ) {
if ( sn ! = null ) {
expr = sn . LookupNameExpression ( rc , MemberLookupRestrictions . ReadAccess | MemberLookupRestrictions . ExactArity ) ;
if ( sn ! = null ) {
expr = sn . LookupNameExpression ( rc , MemberLookupRestrictions . ReadAccess | MemberLookupRestrictions . ExactArity ) ;
//
// Resolve expression which does have type set as we need expression type
// with disable flow analysis as we don't know whether left side expression
// is used as variable or type
//
if ( expr is VariableReference | | expr is ConstantExpr | | expr is Linq . TransparentMemberAccess ) {
using ( rc . With ( ResolveContext . Options . DoFlowAnalysis , false ) ) {
expr = expr . Resolve ( rc ) ;
}
} else if ( expr is TypeParameterExpr ) {
expr . Error_UnexpectedKind ( rc , flags , sn . Location ) ;
expr = null ;
}
} else {
expr = expr . Resolve ( rc , flags ) ;
//
// Resolve expression which does have type set as we need expression type
// with disable flow analysis as we don't know whether left side expression
// is used as variable or type
//
if ( expr is VariableReference | | expr is ConstantExpr | | expr is Linq . TransparentMemberAccess ) {
expr = expr . Resolve ( rc ) ;
} else if ( expr is TypeParameterExpr ) {
expr . Error_UnexpectedKind ( rc , flags , sn . Location ) ;
expr = null ;
}
} else {
expr = expr . Resolve ( rc , flags ) ;
}
if ( expr = = null )
@ -8764,16 +8854,6 @@ namespace Mono.CSharp
@@ -8764,16 +8854,6 @@ namespace Mono.CSharp
if ( me ! = null )
me . ResolveInstanceExpression ( rc , null ) ;
//
// Run defined assigned checks on expressions resolved with
// disabled flow-analysis
//
if ( sn ! = null ) {
var vr = expr as VariableReference ;
if ( vr ! = null )
vr . VerifyDefiniteAssignment ( rc ) ;
}
Arguments args = new Arguments ( 1 ) ;
args . Add ( new Argument ( expr ) ) ;
return new DynamicMemberBinder ( Name , args , loc ) ;
@ -8804,16 +8884,6 @@ namespace Mono.CSharp
@@ -8804,16 +8884,6 @@ namespace Mono.CSharp
emg . SetTypeArguments ( rc , targs ) ;
}
//
// Run defined assigned checks on expressions resolved with
// disabled flow-analysis
//
if ( sn ! = null & & ! errorMode ) {
var vr = expr as VariableReference ;
if ( vr ! = null )
vr . VerifyDefiniteAssignment ( rc ) ;
}
// TODO: it should really skip the checks bellow
return emg . Resolve ( rc ) ;
}
@ -8886,16 +8956,6 @@ namespace Mono.CSharp
@@ -8886,16 +8956,6 @@ namespace Mono.CSharp
me . SetTypeArguments ( rc , targs ) ;
}
//
// Run defined assigned checks on expressions resolved with
// disabled flow-analysis
//
if ( sn ! = null & & ! ( me is FieldExpr & & TypeSpec . IsValueType ( expr_type ) ) ) {
var vr = expr as VariableReference ;
if ( vr ! = null )
vr . VerifyDefiniteAssignment ( rc ) ;
}
return me ;
}
@ -9108,6 +9168,11 @@ namespace Mono.CSharp
@@ -9108,6 +9168,11 @@ namespace Mono.CSharp
Expr . EmitBranchable ( ec , target , on_true ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
Expr . FlowAnalysis ( fc ) ;
}
public override SLE . Expression MakeExpression ( BuilderContext ctx )
{
using ( ctx . With ( BuilderContext . Options . CheckedScope , true ) ) {
@ -9180,6 +9245,11 @@ namespace Mono.CSharp
@@ -9180,6 +9245,11 @@ namespace Mono.CSharp
Expr . EmitBranchable ( ec , target , on_true ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
Expr . FlowAnalysis ( fc ) ;
}
protected override void CloneTo ( CloneContext clonectx , Expression t )
{
UnCheckedExpr target = ( UnCheckedExpr ) t ;
@ -9263,17 +9333,24 @@ namespace Mono.CSharp
@@ -9263,17 +9333,24 @@ namespace Mono.CSharp
return CreateExpressionFactoryCall ( ec , "ArrayIndex" , args ) ;
}
Expression MakePointerAccess ( ResolveContext e c, TypeSpec type )
Expression MakePointerAccess ( ResolveContext r c, TypeSpec type )
{
if ( Arguments . Count ! = 1 ) {
e c. Report . Error ( 1 9 6 , loc , "A pointer must be indexed by only one value" ) ;
r c. Report . Error ( 1 9 6 , loc , "A pointer must be indexed by only one value" ) ;
return null ;
}
if ( Arguments [ 0 ] is NamedArgument )
Error_NamedArgument ( ( NamedArgument ) Arguments [ 0 ] , ec . Report ) ;
var arg = Arguments [ 0 ] ;
if ( arg is NamedArgument )
Error_NamedArgument ( ( NamedArgument ) arg , rc . Report ) ;
var index = arg . Expr . Resolve ( rc ) ;
if ( index = = null )
return null ;
index = ConvertExpressionToArrayIndex ( rc , index , true ) ;
Expression p = new PointerArithmetic ( Binary . Operator . Addition , Expr , Arguments [ 0 ] . Expr . Resolve ( ec ) , type , loc ) ;
Expression p = new PointerArithmetic ( Binary . Operator . Addition , Expr , index , type , loc ) ;
return new Indirection ( p , loc ) ;
}
@ -9318,6 +9395,12 @@ namespace Mono.CSharp
@@ -9318,6 +9395,12 @@ namespace Mono.CSharp
Report . Error ( 1 7 4 2 , na . Location , "An element access expression cannot use named argument" ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
Expr . FlowAnalysis ( fc ) ;
Arguments . FlowAnalysis ( fc ) ;
}
public override string GetSignatureForError ( )
{
return Expr . GetSignatureForError ( ) ;
@ -9420,6 +9503,11 @@ namespace Mono.CSharp
@@ -9420,6 +9503,11 @@ namespace Mono.CSharp
ec . Report . Warning ( 2 5 1 , 2 , loc , "Indexing an array with a negative index (array indices always start at zero)" ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
ea . FlowAnalysis ( fc ) ;
}
//
// Load the array arguments into the stack.
//
@ -9557,7 +9645,7 @@ namespace Mono.CSharp
@@ -9557,7 +9645,7 @@ namespace Mono.CSharp
public SLE . Expression MakeAssignExpression ( BuilderContext ctx , Expression source )
{
#if NET_4_0 || MONODROID
#if NET_4_0 || MOBILE_DYNAMIC
return SLE . Expression . ArrayAccess ( ea . Expr . MakeExpression ( ctx ) , MakeExpressionArguments ( ctx ) ) ;
#else
throw new NotImplementedException ( ) ;
@ -9717,6 +9805,13 @@ namespace Mono.CSharp
@@ -9717,6 +9805,13 @@ namespace Mono.CSharp
}
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
// TODO: Check the order
base . FlowAnalysis ( fc ) ;
arguments . FlowAnalysis ( fc ) ;
}
public override string GetSignatureForError ( )
{
return best_candidate . GetSignatureForError ( ) ;
@ -9729,7 +9824,7 @@ namespace Mono.CSharp
@@ -9729,7 +9824,7 @@ namespace Mono.CSharp
#else
var value = new [ ] { source . MakeExpression ( ctx ) } ;
var args = Arguments . MakeExpression ( arguments , ctx ) . Concat ( value ) ;
#if NET_4_0 || MONODROID
#if NET_4_0 || MOBILE_DYNAMIC
return SLE . Expression . Block (
SLE . Expression . Call ( InstanceExpression . MakeExpression ( ctx ) , ( MethodInfo ) Setter . GetMetaInfo ( ) , args ) ,
value [ 0 ] ) ;
@ -9874,8 +9969,8 @@ namespace Mono.CSharp
@@ -9874,8 +9969,8 @@ namespace Mono.CSharp
{
base . Emit ( ec ) ;
var context_type = ec . CurrentType ;
if ( context_type . IsStruct ) {
if ( type = = ec . Module . Compiler . BuiltinTypes . ValueType ) {
var context_type = ec . CurrentType ;
ec . Emit ( OpCodes . Ldobj , context_type ) ;
ec . Emit ( OpCodes . Box , context_type ) ;
}
@ -10142,6 +10237,11 @@ namespace Mono.CSharp
@@ -10142,6 +10237,11 @@ namespace Mono.CSharp
ec . Emit ( OpCodes . Call , method ) ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
source . FlowAnalysis ( fc ) ;
}
public override string GetSignatureForError ( )
{
return TypeManager . CSharpSignature ( method ) ;
@ -10858,6 +10958,12 @@ namespace Mono.CSharp
@@ -10858,6 +10958,12 @@ namespace Mono.CSharp
e . EmitStatement ( ec ) ;
}
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
foreach ( var initializer in initializers )
initializer . FlowAnalysis ( fc ) ;
}
}
//
@ -11052,6 +11158,12 @@ namespace Mono.CSharp
@@ -11052,6 +11158,12 @@ namespace Mono.CSharp
return instance ;
}
public override void FlowAnalysis ( FlowAnalysisContext fc )
{
base . FlowAnalysis ( fc ) ;
initializers . FlowAnalysis ( fc ) ;
}
public override object Accept ( StructuralVisitor visitor )
{
return visitor . Visit ( this ) ;