Browse Source

Updated mcs.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
19c344c55c
  1. 30
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs
  3. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs
  4. 13
      ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs
  5. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs
  6. 103
      ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs
  7. 20
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  8. 9900
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  9. 168
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  10. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs
  11. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs
  12. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  13. 5
      ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
  14. 14
      ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs
  15. 256
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  16. 24
      ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs
  17. 8
      ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs
  18. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs
  19. 26
      ICSharpCode.NRefactory.CSharp/Parser/mcs/linq.cs
  20. 70
      ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs
  21. 39
      ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs
  22. 568
      ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs
  23. 20
      ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs
  24. 19
      ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs
  25. 56
      ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs
  26. 14
      ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs
  27. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/roottypes.cs
  28. 215
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  29. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs

30
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -208,8 +208,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (loc != null) if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (loc [pos++]), 1), AttributeSection.Roles.LPar);
if (attr.PosArguments != null) { if (attr.PositionalArguments != null) {
foreach (var arg in attr.PosArguments) { foreach (var arg in attr.PositionalArguments) {
var na = arg as NamedArgument; var na = arg as NamedArgument;
if (na != null) { if (na != null) {
var newArg = new NamedArgumentExpression (); var newArg = new NamedArgumentExpression ();
@ -1465,7 +1465,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override object Visit (StatementErrorExpression statementErrorExpression) public override object Visit (StatementErrorExpression statementErrorExpression)
{ {
var result = new ExpressionStatement (); var result = new ExpressionStatement ();
var expr = statementErrorExpression.Expression.Accept (this) as Expression; var expr = statementErrorExpression.Expr.Accept (this) as Expression;
if (expr != null) if (expr != null)
result.AddChild ((Expression)expr, ExpressionStatement.Roles.Expression); result.AddChild ((Expression)expr, ExpressionStatement.Roles.Expression);
return result; return result;
@ -1849,14 +1849,14 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole); result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole);
if (tryCatchStatement.Block != null) if (tryCatchStatement.Block != null)
result.AddChild ((BlockStatement)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole); result.AddChild ((BlockStatement)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole);
if (tryCatchStatement.Specific != null) { if (tryCatchStatement.Clauses != null) {
foreach (Catch ctch in tryCatchStatement.Specific) { foreach (Catch ctch in tryCatchStatement.Clauses) {
result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole); result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
} }
} }
if (tryCatchStatement.General != null) /* if (tryCatchStatement. != null)
result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole); result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole);
*/
return result; return result;
} }
@ -1868,8 +1868,8 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (usingStatement.loc), "using".Length), UsingStatement.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (usingStatement.loc), "using".Length), UsingStatement.Roles.Keyword);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), UsingStatement.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), UsingStatement.Roles.LPar);
if (usingStatement.Expression != null) if (usingStatement.Expr != null)
result.AddChild ((AstNode)usingStatement.Expression.Accept (this), UsingStatement.ResourceAcquisitionRole); result.AddChild ((AstNode)usingStatement.Expr.Accept (this), UsingStatement.ResourceAcquisitionRole);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [1]), 1), UsingStatement.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location [1]), 1), UsingStatement.Roles.RPar);
@ -1889,8 +1889,8 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), ForeachStatement.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), ForeachStatement.Roles.LPar);
if (foreachStatement.TypeExpr != null) if (foreachStatement.TypeExpression != null)
result.AddChild (ConvertToType (foreachStatement.TypeExpr), ForeachStatement.Roles.Type); result.AddChild (ConvertToType (foreachStatement.TypeExpression), ForeachStatement.Roles.Type);
if (foreachStatement.Variable != null) if (foreachStatement.Variable != null)
result.AddChild (Identifier.Create (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier); result.AddChild (Identifier.Create (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), ForeachStatement.Roles.Identifier);
@ -2260,7 +2260,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
var result = new BinaryOperatorExpression (); var result = new BinaryOperatorExpression ();
result.Operator = BinaryOperatorType.NullCoalescing; result.Operator = BinaryOperatorType.NullCoalescing;
result.AddChild ((Expression)nullCoalescingOperator.Left.Accept (this), BinaryOperatorExpression.LeftRole); result.AddChild ((Expression)nullCoalescingOperator.LeftExpression.Accept (this), BinaryOperatorExpression.LeftRole);
result.AddChild (new CSharpTokenNode (Convert (nullCoalescingOperator.Location), 2), BinaryOperatorExpression.OperatorRole); result.AddChild (new CSharpTokenNode (Convert (nullCoalescingOperator.Location), 2), BinaryOperatorExpression.OperatorRole);
result.AddChild ((Expression)nullCoalescingOperator.Right.Accept (this), BinaryOperatorExpression.RightRole); result.AddChild ((Expression)nullCoalescingOperator.Right.Accept (this), BinaryOperatorExpression.RightRole);
return result; return result;
@ -2489,8 +2489,8 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
var result = new InvocationExpression (); var result = new InvocationExpression ();
var location = LocationsBag.GetLocations (invocationExpression); var location = LocationsBag.GetLocations (invocationExpression);
if (invocationExpression.Expression != null) if (invocationExpression.Exp != null)
result.AddChild ((Expression)invocationExpression.Expression.Accept (this), InvocationExpression.Roles.TargetExpression); result.AddChild ((Expression)invocationExpression.Exp.Accept (this), InvocationExpression.Roles.TargetExpression);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), InvocationExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), InvocationExpression.Roles.LPar);
AddArguments (result, location, invocationExpression.Arguments); AddArguments (result, location, invocationExpression.Arguments);
@ -2796,7 +2796,7 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword); result.AddChild (new CSharpTokenNode (Convert (sizeOfExpression.Location), "sizeof".Length), TypeOfExpression.Roles.Keyword);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar); result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), TypeOfExpression.Roles.LPar);
result.AddChild (ConvertToType (sizeOfExpression.QueriedType), TypeOfExpression.Roles.Type); result.AddChild (ConvertToType (sizeOfExpression.TypeExpression), TypeOfExpression.Roles.Type);
if (location != null) if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar); result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), TypeOfExpression.Roles.RPar);
return result; return result;

3
ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs

@ -885,9 +885,8 @@ namespace Mono.CSharp {
public ParametersBlock Block; public ParametersBlock Block;
public AnonymousMethodExpression (bool isAsync, Location loc) public AnonymousMethodExpression (Location loc)
{ {
this.IsAsync = isAsync;
this.loc = loc; this.loc = loc;
this.compatibles = new Dictionary<TypeSpec, Expression> (); this.compatibles = new Dictionary<TypeSpec, Expression> ();
} }

11
ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs

@ -1090,8 +1090,7 @@ namespace Mono.CSharp
public abstract bool HasObjectType (T assembly); public abstract bool HasObjectType (T assembly);
protected abstract string[] GetDefaultReferences (); protected abstract string[] GetDefaultReferences ();
public abstract T LoadAssemblyFile (string fileName); public abstract T LoadAssemblyFile (string fileName, bool isImplicitReference);
public abstract T LoadAssemblyDefault (string assembly);
public abstract void LoadReferences (ModuleContainer module); public abstract void LoadReferences (ModuleContainer module);
protected void Error_FileNotFound (string fileName) protected void Error_FileNotFound (string fileName)
@ -1128,14 +1127,14 @@ namespace Mono.CSharp
// Load mscorlib.dll as the first // Load mscorlib.dll as the first
// //
if (module.Compiler.Settings.StdLib) { if (module.Compiler.Settings.StdLib) {
corlib_assembly = LoadAssemblyDefault ("mscorlib.dll"); corlib_assembly = LoadAssemblyFile ("mscorlib.dll", true);
} else { } else {
corlib_assembly = default (T); corlib_assembly = default (T);
} }
T a; T a;
foreach (string r in module.Compiler.Settings.AssemblyReferences) { foreach (string r in module.Compiler.Settings.AssemblyReferences) {
a = LoadAssemblyFile (r); a = LoadAssemblyFile (r, false);
if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly)) if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly))
continue; continue;
@ -1153,7 +1152,7 @@ namespace Mono.CSharp
} }
foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) { foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) {
a = LoadAssemblyFile (entry.Item2); a = LoadAssemblyFile (entry.Item2, false);
if (a == null) if (a == null)
continue; continue;
@ -1166,7 +1165,7 @@ namespace Mono.CSharp
if (compiler.Settings.LoadDefaultReferences) { if (compiler.Settings.LoadDefaultReferences) {
foreach (string r in GetDefaultReferences ()) { foreach (string r in GetDefaultReferences ()) {
a = LoadAssemblyDefault (r); a = LoadAssemblyFile (r, true);
if (a == null) if (a == null)
continue; continue;

13
ICSharpCode.NRefactory.CSharp/Parser/mcs/assign.cs

@ -418,6 +418,11 @@ namespace Mono.CSharp {
_target.target = target.Clone (clonectx); _target.target = target.Clone (clonectx);
_target.source = source.Clone (clonectx); _target.source = source.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class SimpleAssign : Assign public class SimpleAssign : Assign
@ -653,6 +658,12 @@ namespace Mono.CSharp {
this.left = left; this.left = left;
} }
public Binary.Operator Operator {
get {
return op;
}
}
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
right = right.Resolve (ec); right = right.Resolve (ec);
@ -811,10 +822,10 @@ namespace Mono.CSharp {
ctarget.right = ctarget.source = source.Clone (clonectx); ctarget.right = ctarget.source = source.Clone (clonectx);
ctarget.target = target.Clone (clonectx); ctarget.target = target.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
} }
} }
} }

6
ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs

@ -40,6 +40,12 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
public Expression Expr {
get {
return expr;
}
}
protected override void CloneTo (CloneContext clonectx, Expression target) protected override void CloneTo (CloneContext clonectx, Expression target)
{ {
var t = (Await) target; var t = (Await) target;

103
ICSharpCode.NRefactory.CSharp/Parser/mcs/attribute.cs

@ -89,8 +89,7 @@ namespace Mono.CSharp {
public AttributeTargets Target; public AttributeTargets Target;
readonly ATypeNameExpression expression; readonly ATypeNameExpression expression;
public Arguments PosArguments; Arguments pos_args, named_args;
public Arguments NamedArguments;
bool resolve_error; bool resolve_error;
bool arg_resolved; bool arg_resolved;
@ -118,8 +117,8 @@ namespace Mono.CSharp {
{ {
this.expression = expr; this.expression = expr;
if (args != null) { if (args != null) {
PosArguments = args[0]; pos_args = args[0];
NamedArguments = args[1]; named_args = args[1];
} }
this.loc = loc; this.loc = loc;
ExplicitTarget = target; ExplicitTarget = target;
@ -132,6 +131,24 @@ namespace Mono.CSharp {
} }
} }
public Arguments NamedArguments {
get {
return named_args;
}
}
public Arguments PositionalArguments {
get {
return pos_args;
}
}
public ATypeNameExpression TypeExpression {
get {
return expression;
}
}
void AddModuleCharSet (ResolveContext rc) void AddModuleCharSet (ResolveContext rc)
{ {
const string dll_import_char_set = "CharSet"; const string dll_import_char_set = "CharSet";
@ -147,7 +164,7 @@ namespace Mono.CSharp {
} }
if (NamedArguments == null) if (NamedArguments == null)
NamedArguments = new Arguments (1); named_args = new Arguments (1);
var value = Constant.CreateConstant (rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location); var value = Constant.CreateConstant (rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location);
NamedArguments.Add (new NamedArgument (dll_import_char_set, loc, value)); NamedArguments.Add (new NamedArgument (dll_import_char_set, loc, value));
@ -156,8 +173,8 @@ namespace Mono.CSharp {
public Attribute Clone () public Attribute Clone ()
{ {
Attribute a = new Attribute (ExplicitTarget, expression, null, loc, nameEscaped); Attribute a = new Attribute (ExplicitTarget, expression, null, loc, nameEscaped);
a.PosArguments = PosArguments; a.pos_args = pos_args;
a.NamedArguments = NamedArguments; a.named_args = NamedArguments;
return a; return a;
} }
@ -432,14 +449,14 @@ namespace Mono.CSharp {
MethodSpec ctor; MethodSpec ctor;
// Try if the attribute is simple and has been resolved before // Try if the attribute is simple and has been resolved before
if (PosArguments != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) { if (pos_args != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) {
rc = CreateResolveContext (); rc = CreateResolveContext ();
ctor = ResolveConstructor (rc); ctor = ResolveConstructor (rc);
if (ctor == null) { if (ctor == null) {
return null; return null;
} }
if (PosArguments == null && ctor.Parameters.IsEmpty) if (pos_args == null && ctor.Parameters.IsEmpty)
context.Module.AttributeConstructorCache.Add (Type, ctor); context.Module.AttributeConstructorCache.Add (Type, ctor);
} }
@ -468,16 +485,16 @@ namespace Mono.CSharp {
MethodSpec ResolveConstructor (ResolveContext ec) MethodSpec ResolveConstructor (ResolveContext ec)
{ {
if (PosArguments != null) { if (pos_args != null) {
bool dynamic; bool dynamic;
PosArguments.Resolve (ec, out dynamic); pos_args.Resolve (ec, out dynamic);
if (dynamic) { if (dynamic) {
Error_AttributeArgumentIsDynamic (ec.MemberContext, loc); Error_AttributeArgumentIsDynamic (ec.MemberContext, loc);
return null; return null;
} }
} }
return Expression.ConstructorLookup (ec, Type, ref PosArguments, loc); return Expression.ConstructorLookup (ec, Type, ref pos_args, loc);
} }
bool ResolveNamedArguments (ResolveContext ec) bool ResolveNamedArguments (ResolveContext ec)
@ -637,7 +654,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return DefaultUsageAttribute; return DefaultUsageAttribute;
AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)((Constant) PosArguments [0].Expr).GetValue ()); AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets) ((Constant) pos_args[0].Expr).GetValue ());
var field = GetNamedValue ("AllowMultiple") as BoolConstant; var field = GetNamedValue ("AllowMultiple") as BoolConstant;
if (field != null) if (field != null)
@ -660,10 +677,10 @@ namespace Mono.CSharp {
// But because a lot of attribute class code must be rewritten will be better to wait... // But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (); Resolve ();
if (resolve_error || PosArguments.Count != 1 || !(PosArguments [0].Expr is Constant)) if (resolve_error || pos_args.Count != 1 || !(pos_args[0].Expr is Constant))
return null; return null;
return ((Constant) PosArguments [0].Expr).GetValue () as string; return ((Constant) pos_args[0].Expr).GetValue () as string;
} }
/// <summary> /// <summary>
@ -679,7 +696,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return null; return null;
return ((Constant) PosArguments[0].Expr).GetValue () as string; return ((Constant) pos_args[0].Expr).GetValue () as string;
} }
/// <summary> /// <summary>
@ -701,14 +718,14 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return null; return null;
if (PosArguments == null) if (pos_args == null)
return new ObsoleteAttribute (); return new ObsoleteAttribute ();
string msg = ((Constant) PosArguments[0].Expr).GetValue () as string; string msg = ((Constant) pos_args[0].Expr).GetValue () as string;
if (PosArguments.Count == 1) if (pos_args.Count == 1)
return new ObsoleteAttribute (msg); return new ObsoleteAttribute (msg);
return new ObsoleteAttribute (msg, ((BoolConstant) PosArguments[1].Expr).Value); return new ObsoleteAttribute (msg, ((BoolConstant) pos_args[1].Expr).Value);
} }
/// <summary> /// <summary>
@ -726,7 +743,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return false; return false;
return ((BoolConstant) PosArguments[0].Expr).Value; return ((BoolConstant) pos_args[0].Expr).Value;
} }
public TypeSpec GetCoClassAttributeValue () public TypeSpec GetCoClassAttributeValue ()
@ -812,7 +829,7 @@ namespace Mono.CSharp {
System.Security.Permissions.SecurityAction GetSecurityActionValue () System.Security.Permissions.SecurityAction GetSecurityActionValue ()
{ {
return (SecurityAction) ((Constant) PosArguments[0].Expr).GetValue (); return (SecurityAction) ((Constant) pos_args[0].Expr).GetValue ();
} }
/// <summary> /// <summary>
@ -822,9 +839,9 @@ namespace Mono.CSharp {
public void ExtractSecurityPermissionSet (MethodSpec ctor, ref SecurityType permissions) public void ExtractSecurityPermissionSet (MethodSpec ctor, ref SecurityType permissions)
{ {
#if STATIC #if STATIC
object[] values = new object [PosArguments.Count]; object[] values = new object[pos_args.Count];
for (int i = 0; i < values.Length; ++i) for (int i = 0; i < values.Length; ++i)
values [i] = ((Constant) PosArguments [i].Expr).GetValue (); values[i] = ((Constant) pos_args[i].Expr).GetValue ();
PropertyInfo[] prop; PropertyInfo[] prop;
object[] prop_values; object[] prop_values;
@ -865,7 +882,7 @@ namespace Mono.CSharp {
public CharSet GetCharSetValue () public CharSet GetCharSetValue ()
{ {
return (CharSet)System.Enum.Parse (typeof (CharSet), ((Constant) PosArguments [0].Expr).GetValue ().ToString ()); return (CharSet) System.Enum.Parse (typeof (CharSet), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
} }
public bool HasField (string fieldName) public bool HasField (string fieldName)
@ -887,8 +904,8 @@ namespace Mono.CSharp {
public bool IsInternalCall () public bool IsInternalCall ()
{ {
MethodImplOptions options = 0; MethodImplOptions options = 0;
if (PosArguments.Count == 1) { if (pos_args.Count == 1) {
options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
} else if (HasField ("Value")) { } else if (HasField ("Value")) {
var named = GetNamedValue ("Value"); var named = GetNamedValue ("Value");
options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), named.GetValue ().ToString ()); options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), named.GetValue ().ToString ());
@ -902,19 +919,19 @@ namespace Mono.CSharp {
// //
public bool IsExplicitLayoutKind () public bool IsExplicitLayoutKind ()
{ {
if (PosArguments == null || PosArguments.Count != 1) if (pos_args == null || pos_args.Count != 1)
return false; return false;
var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
return value == LayoutKind.Explicit; return value == LayoutKind.Explicit;
} }
public Expression GetParameterDefaultValue () public Expression GetParameterDefaultValue ()
{ {
if (PosArguments == null) if (pos_args == null)
return null; return null;
return PosArguments[0].Expr; return pos_args[0].Expr;
} }
public override bool Equals (object obj) public override bool Equals (object obj)
@ -951,16 +968,16 @@ namespace Mono.CSharp {
} }
byte[] cdata; byte[] cdata;
if (PosArguments == null && named_values == null) { if (pos_args == null && named_values == null) {
cdata = AttributeEncoder.Empty; cdata = AttributeEncoder.Empty;
} else { } else {
AttributeEncoder encoder = new AttributeEncoder (); AttributeEncoder encoder = new AttributeEncoder ();
if (PosArguments != null) { if (pos_args != null) {
var param_types = ctor.Parameters.Types; var param_types = ctor.Parameters.Types;
for (int j = 0; j < PosArguments.Count; ++j) { for (int j = 0; j < pos_args.Count; ++j) {
var pt = param_types[j]; var pt = param_types[j];
var arg_expr = PosArguments[j].Expr; var arg_expr = pos_args[j].Expr;
if (j == 0) { if (j == 0) {
if ((Type == predefined.IndexerName || Type == predefined.Conditional) && arg_expr is Constant) { if ((Type == predefined.IndexerName || Type == predefined.Conditional) && arg_expr is Constant) {
string v = ((Constant) arg_expr).GetValue () as string; string v = ((Constant) arg_expr).GetValue () as string;
@ -984,15 +1001,15 @@ namespace Mono.CSharp {
"System.AttributeUsage"); "System.AttributeUsage");
} }
} else if (Type == predefined.MarshalAs) { } else if (Type == predefined.MarshalAs) {
if (PosArguments.Count == 1) { if (pos_args.Count == 1) {
var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) PosArguments[0].Expr).GetValue ().ToString ()); var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) pos_args[0].Expr).GetValue ().ToString ());
if (u_type == UnmanagedType.ByValArray && !(Owner is FieldBase)) { if (u_type == UnmanagedType.ByValArray && !(Owner is FieldBase)) {
Error_AttributeEmitError ("Specified unmanaged type is only valid on fields"); Error_AttributeEmitError ("Specified unmanaged type is only valid on fields");
} }
} }
} else if (Type == predefined.DllImport) { } else if (Type == predefined.DllImport) {
if (PosArguments.Count == 1 && PosArguments[0].Expr is Constant) { if (pos_args.Count == 1 && pos_args[0].Expr is Constant) {
var value = ((Constant) PosArguments[0].Expr).GetValue () as string; var value = ((Constant) pos_args[0].Expr).GetValue () as string;
if (string.IsNullOrEmpty (value)) if (string.IsNullOrEmpty (value))
Error_AttributeEmitError ("DllName cannot be empty"); Error_AttributeEmitError ("DllName cannot be empty");
} }
@ -1055,8 +1072,8 @@ namespace Mono.CSharp {
// Here we are testing attribute arguments for array usage (error 3016) // Here we are testing attribute arguments for array usage (error 3016)
if (Owner.IsClsComplianceRequired ()) { if (Owner.IsClsComplianceRequired ()) {
if (PosArguments != null) if (pos_args != null)
PosArguments.CheckArrayAsAttribute (context.Module.Compiler); pos_args.CheckArrayAsAttribute (context.Module.Compiler);
if (NamedArguments == null) if (NamedArguments == null)
return; return;
@ -1067,10 +1084,10 @@ namespace Mono.CSharp {
private Expression GetValue () private Expression GetValue ()
{ {
if (PosArguments == null || PosArguments.Count < 1) if (pos_args == null || pos_args.Count < 1)
return null; return null;
return PosArguments [0].Expr; return pos_args[0].Expr;
} }
public string GetString () public string GetString ()

20
ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs

@ -201,7 +201,7 @@ namespace Mono.CSharp
// from classes from the arraylist `type_bases' // from classes from the arraylist `type_bases'
// //
protected TypeSpec base_type; protected TypeSpec base_type;
protected FullNamedExpression base_type_expr; // TODO: It's temporary variable FullNamedExpression base_type_expr; // TODO: It's temporary variable
protected TypeSpec[] iface_exprs; protected TypeSpec[] iface_exprs;
protected List<FullNamedExpression> type_bases; protected List<FullNamedExpression> type_bases;
@ -256,6 +256,12 @@ namespace Mono.CSharp
#region Properties #region Properties
public List<FullNamedExpression> BaseTypeExpressions {
get {
return type_bases;
}
}
public override TypeSpec CurrentType { public override TypeSpec CurrentType {
get { get {
if (current_type == null) { if (current_type == null) {
@ -332,7 +338,7 @@ namespace Mono.CSharp
{ {
visitor.Visit (this); visitor.Visit (this);
} }
public bool AddMember (MemberCore symbol) public bool AddMember (MemberCore symbol)
{ {
return AddToContainer (symbol, symbol.MemberName.Basename); return AddToContainer (symbol, symbol.MemberName.Basename);
@ -1366,9 +1372,13 @@ namespace Mono.CSharp
type_defined = true; type_defined = true;
// TODO: Driver resolves only first level of namespace, do the rest here for now // Nested type share same namespace
if (IsTopLevel && (ModFlags & Modifiers.COMPILER_GENERATED) == 0) { if (IsTopLevel && !IsCompilerGenerated) {
NamespaceEntry.Resolve (); NamespaceEntry.Define ();
if (partial_parts != null) {
foreach (var part in partial_parts)
part.NamespaceEntry.Define ();
}
} }
if (!DefineBaseTypes ()) { if (!DefineBaseTypes ()) {

9900
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs

File diff suppressed because it is too large Load Diff

168
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

@ -428,19 +428,26 @@ extern_alias_directive
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
string s = lt.Value; string s = lt.Value;
if (s != "alias"){ if (s != "alias") {
syntax_error (lt.Location, "`alias' expected"); syntax_error (lt.Location, "`alias' expected");
} else if (lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (lt.Location, "external alias");
} else { } else {
lt = (Tokenizer.LocatedToken) $3; if (lang_version == LanguageVersion.ISO_1)
current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, report); FeatureIsNotAvailable (lt.Location, "external alias");
ubag.AddExternAlias (GetLocation ($1), GetLocation ($2), lt, GetLocation ($4));
lt = (Tokenizer.LocatedToken) $3;
if (lt.Value == QualifiedAliasMember.GlobalAlias) {
RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
}
var na = new UsingExternAlias (new MemberName (lt.Value, lt.Location), GetLocation ($1));
current_namespace.AddUsing (na);
lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
} }
} }
| EXTERN_ALIAS error | EXTERN_ALIAS error
{ {
syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better Error_SyntaxError (yyToken);
} }
; ;
@ -450,20 +457,22 @@ using_directives
; ;
using_directive using_directive
: using_alias_directive : using_namespace
{
if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
| using_namespace_directive
{ {
if (doc_support) if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed; Lexer.doc_state = XmlCommentState.Allowed;
} }
; ;
using_alias_directive using_namespace
: USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON : USING namespace_name SEMICOLON
{
var un = new UsingNamespace ((MemberName) $2, GetLocation ($1));
current_namespace.AddUsing (un);
lbag.AddLocation (un, GetLocation ($3));
}
| USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") { if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
@ -471,22 +480,16 @@ using_alias_directive
"An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead"); "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
} }
current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1)); var un = new UsingAliasNamespace (new MemberName (lt.Value, lt.Location), (MemberName) $4, GetLocation ($1));
ubag.AddUsingAlias (GetLocation ($1), lt, GetLocation ($3), (MemberName) $4, GetLocation ($5)); current_namespace.AddUsing (un);
}
lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
}
| USING error | USING error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
$$ = null; $$ = null;
} }
;
using_namespace_directive
: USING namespace_name SEMICOLON
{
current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
ubag.AddUsing (GetLocation ($1), (MemberName) $2, GetLocation ($3));
}
; ;
// //
@ -5103,7 +5106,7 @@ statement_expression
ExpressionStatement s = $1 as ExpressionStatement; ExpressionStatement s = $1 as ExpressionStatement;
if (s == null) { if (s == null) {
Expression.Error_InvalidExpressionStatement (report, GetLocation ($1)); Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
$$ = new InvalidStatementExpression ($1 as Expression); $$ = new StatementErrorExpression ($1 as Expression);
} else { } else {
$$ = new StatementExpression (s); $$ = new StatementExpression (s);
} }
@ -5152,9 +5155,10 @@ if_statement
if ($7 is EmptyStatement) if ($7 is EmptyStatement)
Warning_EmptyStatement (GetLocation ($7)); Warning_EmptyStatement (GetLocation ($7));
} }
| IF open_parens_any boolean_expression error { | IF open_parens_any boolean_expression error
var eloc = GetLocation ($3); {
report.Error (1026, eloc, "Expected a ')'"); Error_SyntaxError (yyToken);
$$ = new If ((BooleanExpression) $3, null, GetLocation ($1)); $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2)); lbag.AddStatement ($$, GetLocation ($2));
} }
@ -5171,6 +5175,13 @@ switch_statement
end_block (GetLocation ($8)); end_block (GetLocation ($8));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($5), GetLocation ($8)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($5), GetLocation ($8));
} }
| SWITCH open_parens_any expression error
{
Error_SyntaxError (yyToken);
$$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
; ;
opt_switch_sections opt_switch_sections
@ -5199,7 +5210,7 @@ switch_sections
} }
| error | error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
$$ = new List<SwitchSection> (); $$ = new List<SwitchSection> ();
} }
; ;
@ -5260,24 +5271,30 @@ while_statement
$$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1)); $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
} }
| WHILE open_parens_any boolean_expression error
{
Error_SyntaxError (yyToken);
$$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
; ;
do_statement do_statement
: DO embedded_statement : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
{ {
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1)); $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7)); lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
} }
| DO embedded_statement error | DO embedded_statement error
{ {
var loc = GetLocation ($1); Error_SyntaxError (yyToken);
report.Error (-100, loc, "Expected `while'"); $$ = new Do ((Statement) $2, null, GetLocation ($1));
$$ = new Do ((Statement) $2, null, loc);
} }
| DO embedded_statement | DO embedded_statement WHILE open_parens_any boolean_expression error
WHILE open_parens_any boolean_expression error
{ {
Error_SyntaxError (yyToken);
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1)); $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
} }
@ -5383,10 +5400,35 @@ statement_expression_list
; ;
foreach_statement foreach_statement
: FOREACH open_parens_any type IN expression CLOSE_PARENS : FOREACH open_parens_any type error
{ {
report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement"); report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
$$ = null;
start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true;
Foreach f = new Foreach ((Expression) $3, null, null, null, GetLocation ($1));
current_block.AddStatement (f);
lbag.AddStatement (f, GetLocation ($2));
$$ = end_block (GetLocation ($4));
}
| FOREACH open_parens_any type identifier_inside_body error
{
Error_SyntaxError (yyToken);
start_block (GetLocation ($2));
current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li);
Foreach f = new Foreach ((Expression) $3, li, null, null, GetLocation ($1));
current_block.AddStatement (f);
lbag.AddStatement (f, GetLocation ($2));
$$ = end_block (GetLocation ($5));
} }
| FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
{ {
@ -5544,9 +5586,9 @@ try_statement
$$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1)); $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($4));
} }
| TRY block error | TRY block error
{ {
report.Error (1524, GetLocation ($1), "Expected catch or finally"); Error_SyntaxError (1524, yyToken);
$$ = new TryCatch ((Block) $2, null, GetLocation ($1), false); $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
} }
; ;
@ -5564,15 +5606,11 @@ catch_clauses
var l = (List<Catch>) $1; var l = (List<Catch>) $1;
Catch c = (Catch) $2; Catch c = (Catch) $2;
if (l [0].IsGeneral) { if (l [l.Count - 1].IsGeneral) {
report.Error (1017, c.loc, "Try statement already has an empty catch block"); report.Error (1017, c.loc, "Try statement already has an empty catch block");
} else {
if (c.IsGeneral)
l.Insert (0, c);
else
l.Add (c);
} }
l.Add (c);
$$ = l; $$ = l;
} }
; ;
@ -5652,6 +5690,13 @@ lock_statement
$$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1)); $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
} }
| LOCK open_parens_any expression error
{
Error_SyntaxError (yyToken);
$$ = new Lock ((Expression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
; ;
fixed_statement fixed_statement
@ -5713,9 +5758,15 @@ using_statement
if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE) if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
Warning_EmptyStatement (GetLocation ($5)); Warning_EmptyStatement (GetLocation ($5));
Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1)); $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement (u, GetLocation ($2), GetLocation ($4)); lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
$$ = u; }
| USING open_parens_any expression error
{
Error_SyntaxError (yyToken);
$$ = new Using ((Expression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
} }
; ;
@ -5959,7 +6010,7 @@ let_clause
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
$$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1)); $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($3)); lbag.AddLocation ($$, GetLocation ($3));
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent; current_block = current_block.Parent;
@ -6747,12 +6798,12 @@ void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync
if (lang_version <= LanguageVersion.ISO_2) if (lang_version <= LanguageVersion.ISO_2)
FeatureIsNotAvailable (loc, "lambda expressions"); FeatureIsNotAvailable (loc, "lambda expressions");
current_anonymous_method = new LambdaExpression (isAsync, loc); current_anonymous_method = new LambdaExpression (loc);
} else { } else {
if (lang_version == LanguageVersion.ISO_1) if (lang_version == LanguageVersion.ISO_1)
FeatureIsNotAvailable (loc, "anonymous methods"); FeatureIsNotAvailable (loc, "anonymous methods");
current_anonymous_method = new AnonymousMethodExpression (isAsync, loc); current_anonymous_method = new AnonymousMethodExpression (loc);
} }
async_block = isAsync; async_block = isAsync;
@ -6784,7 +6835,12 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
void Error_SyntaxError (int token) void Error_SyntaxError (int token)
{ {
Error_SyntaxError (0, token, "Unexpected symbol"); Error_SyntaxError (0, token);
}
void Error_SyntaxError (int error_code, int token)
{
Error_SyntaxError (error_code, token, "Unexpected symbol");
} }
void Error_SyntaxError (int error_code, int token, string msg) void Error_SyntaxError (int error_code, int token, string msg)

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs

@ -47,7 +47,6 @@ namespace Mono.CSharp {
bool is_double_colon; bool is_double_colon;
public bool IsDoubleColon { get { return is_double_colon; } }
#if FULL_AST #if FULL_AST
public Location DotLocation { public Location DotLocation {
@ -124,6 +123,12 @@ namespace Mono.CSharp {
} }
} }
public bool IsDoubleColon {
get {
return is_double_colon;
}
}
public bool IsGeneric { public bool IsGeneric {
get { get {
if (TypeArguments != null) if (TypeArguments != null)

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs

@ -81,6 +81,13 @@ namespace Mono.CSharp {
return parameters; return parameters;
} }
} }
public FullNamedExpression TypExpression {
get {
return ReturnType;
}
}
#endregion #endregion
public override void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs

@ -300,7 +300,7 @@ namespace Mono.CSharp
tr.Start (TimeReporter.TimerType.UsingResolve); tr.Start (TimeReporter.TimerType.UsingResolve);
foreach (var source_file in ctx.SourceFiles) { foreach (var source_file in ctx.SourceFiles) {
source_file.NamespaceContainer.Resolve (); source_file.NamespaceContainer.Define ();
} }
tr.Stop (TimeReporter.TimerType.UsingResolve); tr.Stop (TimeReporter.TimerType.UsingResolve);

5
ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs

@ -4418,7 +4418,10 @@ namespace Mono.CSharp {
var ac_p = p as ArrayContainer; var ac_p = p as ArrayContainer;
if (ac_p != null) { if (ac_p != null) {
var ac_q = ((ArrayContainer) q); var ac_q = q as ArrayContainer;
if (ac_q == null)
return null;
TypeSpec specific = MoreSpecific (ac_p.Element, ac_q.Element); TypeSpec specific = MoreSpecific (ac_p.Element, ac_q.Element);
if (specific == ac_p.Element) if (specific == ac_p.Element)
return p; return p;

14
ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs

@ -373,6 +373,7 @@ namespace Mono.CSharp
// Need to setup MemberCache // Need to setup MemberCache
parser_result.CreateType (); parser_result.CreateType ();
parser_result.NamespaceEntry.Define ();
var method = parser_result.Methods[0] as Method; var method = parser_result.Methods[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void); BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
@ -768,12 +769,17 @@ namespace Mono.CSharp
return sb.ToString (); return sb.ToString ();
} }
internal ICollection<string> GetUsingList () internal List<string> GetUsingList ()
{ {
var res = new List<string> (); var res = new List<string> ();
foreach (var ue in source_file.NamespaceContainer.Usings) foreach (var ue in source_file.NamespaceContainer.Usings) {
res.Add (ue.Name); if (ue.Alias != null)
continue;
res.Add (ue.NamespaceName.Name);
}
return res; return res;
} }
@ -814,7 +820,7 @@ namespace Mono.CSharp
public void LoadAssembly (string file) public void LoadAssembly (string file)
{ {
var loader = new DynamicLoader (importer, ctx); var loader = new DynamicLoader (importer, ctx);
var assembly = loader.LoadAssemblyFile (file); var assembly = loader.LoadAssemblyFile (file, false);
if (assembly == null) if (assembly == null)
return; return;

256
ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs

@ -801,18 +801,18 @@ namespace Mono.CSharp
LocalTemporary temporary; LocalTemporary temporary;
bool prepared; bool prepared;
public Expression Expr {
get {
return expr;
}
}
public Indirection (Expression expr, Location l) public Indirection (Expression expr, Location l)
{ {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr {
get {
return expr;
}
}
public bool IsFixed { public bool IsFixed {
get { return true; } get { return true; }
} }
@ -1017,6 +1017,13 @@ namespace Mono.CSharp
// Holds the real operation // Holds the real operation
Expression operation; Expression operation;
public UnaryMutator (Mode m, Expression e, Location loc)
{
mode = m;
this.loc = loc;
expr = e;
}
public Mode UnaryMutatorMode { public Mode UnaryMutatorMode {
get { get {
return mode; return mode;
@ -1029,13 +1036,6 @@ namespace Mono.CSharp
} }
} }
public UnaryMutator (Mode m, Expression e, Location loc)
{
mode = m;
this.loc = loc;
expr = e;
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return expr.ContainsEmitWithAwait (); return expr.ContainsEmitWithAwait ();
@ -1283,6 +1283,7 @@ namespace Mono.CSharp
target.expr = expr.Clone (clonectx); target.expr = expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -1371,6 +1372,10 @@ namespace Mono.CSharp
{ {
} }
protected override string OperatorName {
get { return "is"; }
}
public override Expression CreateExpressionTree (ResolveContext ec) public override Expression CreateExpressionTree (ResolveContext ec)
{ {
Arguments args = Arguments.CreateForExpressionTree (ec, null, Arguments args = Arguments.CreateForExpressionTree (ec, null,
@ -1545,10 +1550,6 @@ namespace Mono.CSharp
return this; return this;
} }
protected override string OperatorName {
get { return "is"; }
}
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -1566,6 +1567,10 @@ namespace Mono.CSharp
{ {
} }
protected override string OperatorName {
get { return "as"; }
}
public override Expression CreateExpressionTree (ResolveContext ec) public override Expression CreateExpressionTree (ResolveContext ec)
{ {
Arguments args = Arguments.CreateForExpressionTree (ec, null, Arguments args = Arguments.CreateForExpressionTree (ec, null,
@ -1644,14 +1649,10 @@ namespace Mono.CSharp
return null; return null;
} }
protected override string OperatorName {
get { return "as"; }
}
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
} }
} }
// //
@ -1753,13 +1754,6 @@ namespace Mono.CSharp
public class DefaultValueExpression : Expression public class DefaultValueExpression : Expression
{ {
Expression expr; Expression expr;
public Expression Expr {
get {
return this.expr;
}
}
public DefaultValueExpression (Expression expr, Location loc) public DefaultValueExpression (Expression expr, Location loc)
{ {
@ -1767,6 +1761,12 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
public Expression Expr {
get {
return this.expr;
}
}
public override bool IsSideEffectFree { public override bool IsSideEffectFree {
get { get {
return true; return true;
@ -2225,11 +2225,15 @@ namespace Mono.CSharp
} }
public Expression Left { public Expression Left {
get { return this.left; } get {
return this.left;
}
} }
public Expression Right { public Expression Right {
get { return this.right; } get {
return this.right;
}
} }
#endregion #endregion
@ -5235,7 +5239,7 @@ namespace Mono.CSharp
} }
} }
public Expression Expression { public Expression Exp {
get { get {
return expr; return expr;
} }
@ -5490,6 +5494,7 @@ namespace Mono.CSharp
return SLE.Expression.Call (instance_expr, (MethodInfo) mi.GetMetaInfo (), Arguments.MakeExpression (args, ctx)); return SLE.Expression.Call (instance_expr, (MethodInfo) mi.GetMetaInfo (), Arguments.MakeExpression (args, ctx));
#endif #endif
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -5541,6 +5546,12 @@ namespace Mono.CSharp
} }
} }
public Expression TypeExpression {
get {
return RequestedType;
}
}
#endregion #endregion
/// <summary> /// <summary>
@ -5933,6 +5944,12 @@ namespace Mono.CSharp
get { return elements.Count; } get { return elements.Count; }
} }
public List<Expression> Elements {
get {
return elements;
}
}
public Expression this [int index] { public Expression this [int index] {
get { get {
return elements [index]; return elements [index];
@ -5947,12 +5964,6 @@ namespace Mono.CSharp
variable = value; variable = value;
} }
} }
public List<Expression> Elements {
get {
return this.elements;
}
}
#endregion #endregion
public void Add (Expression expr) public void Add (Expression expr)
@ -6044,24 +6055,16 @@ namespace Mono.CSharp
// The number of constants in array initializers // The number of constants in array initializers
int const_initializers_count; int const_initializers_count;
// bool only_constant_initializers; bool only_constant_initializers;
public List<Expression> Arguments { public List<Expression> Arguments {
get { return this.arguments; } get { return this.arguments; }
} }
public ComposedTypeSpecifier Rank {
get { return this.rank; }
}
public FullNamedExpression NewType { public FullNamedExpression NewType {
get { return this.requested_base_type; } get { return this.requested_base_type; }
} }
public ArrayInitializer Initializers {
get { return this.initializers; }
}
public ArrayCreation (FullNamedExpression requested_base_type, List<Expression> exprs, ComposedTypeSpecifier rank, ArrayInitializer initializers, Location l) public ArrayCreation (FullNamedExpression requested_base_type, List<Expression> exprs, ComposedTypeSpecifier rank, ArrayInitializer initializers, Location l)
: this (requested_base_type, rank, initializers, l) : this (requested_base_type, rank, initializers, l)
{ {
@ -6099,6 +6102,24 @@ namespace Mono.CSharp
{ {
} }
public ComposedTypeSpecifier Rank {
get {
return this.rank;
}
}
public FullNamedExpression TypeExpression {
get {
return this.requested_base_type;
}
}
public ArrayInitializer Initializers {
get {
return this.initializers;
}
}
bool CheckIndices (ResolveContext ec, ArrayInitializer probe, int idx, bool specified_dims, int child_bounds) bool CheckIndices (ResolveContext ec, ArrayInitializer probe, int idx, bool specified_dims, int child_bounds)
{ {
if (initializers != null && bounds == null) { if (initializers != null && bounds == null) {
@ -6179,7 +6200,7 @@ namespace Mono.CSharp
++const_initializers_count; ++const_initializers_count;
} }
} else { } else {
// only_constant_initializers = false; only_constant_initializers = false;
} }
array_data.Add (element); array_data.Add (element);
@ -6284,7 +6305,7 @@ namespace Mono.CSharp
protected bool ResolveInitializers (ResolveContext ec) protected bool ResolveInitializers (ResolveContext ec)
{ {
// only_constant_initializers = true; only_constant_initializers = true;
if (arguments != null) { if (arguments != null) {
bool res = true; bool res = true;
@ -7124,8 +7145,8 @@ namespace Mono.CSharp
/// </summary> /// </summary>
public class Arglist : Expression public class Arglist : Expression
{ {
public Arguments Arguments { get; private set; } Arguments arguments;
public Arglist (Location loc) public Arglist (Location loc)
: this (null, loc) : this (null, loc)
{ {
@ -7133,18 +7154,24 @@ namespace Mono.CSharp
public Arglist (Arguments args, Location l) public Arglist (Arguments args, Location l)
{ {
Arguments = args; arguments = args;
loc = l; loc = l;
} }
public Arguments Arguments {
get {
return arguments;
}
}
public MetaType[] ArgumentTypes { public MetaType[] ArgumentTypes {
get { get {
if (Arguments == null) if (arguments == null)
return MetaType.EmptyTypes; return MetaType.EmptyTypes;
var retval = new MetaType[Arguments.Count]; var retval = new MetaType[arguments.Count];
for (int i = 0; i < retval.Length; i++) for (int i = 0; i < retval.Length; i++)
retval[i] = Arguments[i].Expr.Type.GetMetaInfo (); retval[i] = arguments[i].Expr.Type.GetMetaInfo ();
return retval; return retval;
} }
@ -7165,9 +7192,9 @@ namespace Mono.CSharp
{ {
eclass = ExprClass.Variable; eclass = ExprClass.Variable;
type = InternalType.Arglist; type = InternalType.Arglist;
if (Arguments != null) { if (arguments != null) {
bool dynamic; // Can be ignored as there is always only 1 overload bool dynamic; // Can be ignored as there is always only 1 overload
Arguments.Resolve (ec, out dynamic); arguments.Resolve (ec, out dynamic);
} }
return this; return this;
@ -7175,17 +7202,18 @@ namespace Mono.CSharp
public override void Emit (EmitContext ec) public override void Emit (EmitContext ec)
{ {
if (Arguments != null) if (arguments != null)
Arguments.Emit (ec); arguments.Emit (ec);
} }
protected override void CloneTo (CloneContext clonectx, Expression t) protected override void CloneTo (CloneContext clonectx, Expression t)
{ {
Arglist target = (Arglist) t; Arglist target = (Arglist) t;
if (Arguments != null) if (arguments != null)
target.Arguments = Arguments.Clone (clonectx); target.arguments = arguments.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -7207,6 +7235,12 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
public FullNamedExpression TypeExpression {
get {
return texpr;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -7597,12 +7631,12 @@ namespace Mono.CSharp
/// Implements the sizeof expression /// Implements the sizeof expression
/// </summary> /// </summary>
public class SizeOf : Expression { public class SizeOf : Expression {
public readonly Expression QueriedType; readonly Expression texpr;
TypeSpec type_queried; TypeSpec type_queried;
public SizeOf (Expression queried_type, Location l) public SizeOf (Expression queried_type, Location l)
{ {
this.QueriedType = queried_type; this.texpr = queried_type;
loc = l; loc = l;
} }
@ -7612,6 +7646,12 @@ namespace Mono.CSharp
} }
} }
public Expression TypeExpression {
get {
return texpr;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -7625,7 +7665,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
type_queried = QueriedType.ResolveAsType (ec); type_queried = texpr.ResolveAsType (ec);
if (type_queried == null) if (type_queried == null)
return null; return null;
@ -7693,6 +7733,12 @@ namespace Mono.CSharp
this.alias = alias; this.alias = alias;
} }
public string Alias {
get {
return alias;
}
}
public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec) public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec)
{ {
if (alias == GlobalAlias) { if (alias == GlobalAlias) {
@ -7707,19 +7753,8 @@ namespace Mono.CSharp
ec.Module.Compiler.Report.Error (432, loc, "Alias `{0}' not found", alias); ec.Module.Compiler.Report.Error (432, loc, "Alias `{0}' not found", alias);
return null; return null;
} }
FullNamedExpression fne = base.ResolveAsTypeOrNamespace (ec); return base.ResolveAsTypeOrNamespace (ec);
if (fne == null)
return null;
if (expr.eclass == ExprClass.Type) {
ec.Module.Compiler.Report.Error (431, loc,
"Alias `{0}' cannot be used with '::' since it denotes a type. Consider replacing '::' with '.'", alias);
return null;
}
return fne;
} }
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
@ -7727,13 +7762,6 @@ namespace Mono.CSharp
return ResolveAsTypeOrNamespace (ec); return ResolveAsTypeOrNamespace (ec);
} }
protected override void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type, string identifier)
{
rc.Module.Compiler.Report.Error (687, loc,
"A namespace alias qualifier `{0}' did not resolve to a namespace or a type",
GetSignatureForError ());
}
public override string GetSignatureForError () public override string GetSignatureForError ()
{ {
string name = Name; string name = Name;
@ -7746,6 +7774,14 @@ namespace Mono.CSharp
public override Expression LookupNameExpression (ResolveContext rc, MemberLookupRestrictions restrictions) public override Expression LookupNameExpression (ResolveContext rc, MemberLookupRestrictions restrictions)
{ {
if ((restrictions & MemberLookupRestrictions.InvocableOnly) != 0) {
rc.Module.Compiler.Report.Error (687, loc,
"The namespace alias qualifier `::' cannot be used to invoke a method. Consider using `.' instead",
GetSignatureForError ());
return null;
}
return DoResolve (rc); return DoResolve (rc);
} }
@ -8105,6 +8141,14 @@ namespace Mono.CSharp
return null; return null;
} }
var qam = this as QualifiedAliasMember;
if (qam != null) {
rc.Module.Compiler.Report.Error (431, loc,
"Alias `{0}' cannot be used with `::' since it denotes a type. Consider replacing `::' with `.'",
qam.Alias);
}
TypeSpec nested = null; TypeSpec nested = null;
while (expr_type != null) { while (expr_type != null) {
nested = MemberCache.FindNestedType (expr_type, Name, Arity); nested = MemberCache.FindNestedType (expr_type, Name, Arity);
@ -8265,6 +8309,7 @@ namespace Mono.CSharp
target.Expr = Expr.Clone (clonectx); target.Expr = Expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -8329,6 +8374,7 @@ namespace Mono.CSharp
target.Expr = Expr.Clone (clonectx); target.Expr = Expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -9539,15 +9585,7 @@ namespace Mono.CSharp
TypeSpec otype; TypeSpec otype;
Expression t; Expression t;
Expression count; Expression count;
public Expression TypeExpression {
get { return this.t; }
}
public Expression CountExpression {
get { return this.count; }
}
public StackAlloc (Expression type, Expression count, Location l) public StackAlloc (Expression type, Expression count, Location l)
{ {
t = type; t = type;
@ -9555,6 +9593,18 @@ namespace Mono.CSharp
loc = l; loc = l;
} }
public Expression TypeExpression {
get {
return this.t;
}
}
public Expression CountExpression {
get {
return this.count;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -10033,18 +10083,18 @@ namespace Mono.CSharp
CollectionOrObjectInitializers initializers; CollectionOrObjectInitializers initializers;
IMemoryLocation instance; IMemoryLocation instance;
public CollectionOrObjectInitializers Initializers {
get {
return initializers;
}
}
public NewInitialize (FullNamedExpression requested_type, Arguments arguments, CollectionOrObjectInitializers initializers, Location l) public NewInitialize (FullNamedExpression requested_type, Arguments arguments, CollectionOrObjectInitializers initializers, Location l)
: base (requested_type, arguments, l) : base (requested_type, arguments, l)
{ {
this.initializers = initializers; this.initializers = initializers;
} }
public CollectionOrObjectInitializers Initializers {
get {
return initializers;
}
}
protected override void CloneTo (CloneContext clonectx, Expression t) protected override void CloneTo (CloneContext clonectx, Expression t)
{ {
base.CloneTo (clonectx, t); base.CloneTo (clonectx, t);
@ -10155,10 +10205,6 @@ namespace Mono.CSharp
readonly TypeContainer parent; readonly TypeContainer parent;
AnonymousTypeClass anonymous_type; AnonymousTypeClass anonymous_type;
public List<AnonymousTypeParameter> Parameters {
get { return this.parameters; }
}
public NewAnonymousType (List<AnonymousTypeParameter> parameters, TypeContainer parent, Location loc) public NewAnonymousType (List<AnonymousTypeParameter> parameters, TypeContainer parent, Location loc)
: base (null, null, loc) : base (null, null, loc)
{ {
@ -10166,6 +10212,12 @@ namespace Mono.CSharp
this.parent = parent; this.parent = parent;
} }
public List<AnonymousTypeParameter> Parameters {
get {
return this.parameters;
}
}
protected override void CloneTo (CloneContext clonectx, Expression target) protected override void CloneTo (CloneContext clonectx, Expression target)
{ {
if (parameters == null) if (parameters == null)

24
ICSharpCode.NRefactory.CSharp/Parser/mcs/generic.cs

@ -94,6 +94,12 @@ namespace Mono.CSharp {
#region Properties #region Properties
public List<FullNamedExpression> TypeExpressions {
get {
return constraints;
}
}
public Location Location { public Location Location {
get { get {
return loc; return loc;
@ -385,6 +391,12 @@ namespace Mono.CSharp {
} }
} }
public Constraints Constraints {
get {
return constraints;
}
}
public IAssemblyDefinition DeclaringAssembly { public IAssemblyDefinition DeclaringAssembly {
get { get {
return Module.DeclaringAssembly; return Module.DeclaringAssembly;
@ -440,12 +452,6 @@ namespace Mono.CSharp {
} }
} }
public Constraints Constraints {
get {
return this.constraints;
}
}
#endregion #endregion
// //
@ -1911,6 +1917,12 @@ namespace Mono.CSharp {
} }
} }
public List<FullNamedExpression> TypeExpressions {
get {
return this.args;
}
}
public string GetSignatureForError() public string GetSignatureForError()
{ {
StringBuilder sb = new StringBuilder (); StringBuilder sb = new StringBuilder ();

8
ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs

@ -33,16 +33,16 @@ namespace Mono.CSharp
protected T machine_initializer; protected T machine_initializer;
int resume_pc; int resume_pc;
public Expression Expr {
get { return this.expr; }
}
protected YieldStatement (Expression expr, Location l) protected YieldStatement (Expression expr, Location l)
{ {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr {
get { return this.expr; }
}
protected override void CloneTo (CloneContext clonectx, Statement t) protected override void CloneTo (CloneContext clonectx, Statement t)
{ {
var target = (YieldStatement<T>) t; var target = (YieldStatement<T>) t;

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/lambda.cs

@ -24,13 +24,8 @@ namespace Mono.CSharp {
// A list of Parameters (explicitly typed parameters) // A list of Parameters (explicitly typed parameters)
// An ImplicitLambdaParameter // An ImplicitLambdaParameter
// //
public LambdaExpression (bool isAsync, Location loc)
: base (isAsync, loc)
{
}
public LambdaExpression (Location loc) public LambdaExpression (Location loc)
: this (false, loc) : base (loc)
{ {
} }

26
ICSharpCode.NRefactory.CSharp/Parser/mcs/linq.cs

@ -287,6 +287,12 @@ namespace Mono.CSharp.Linq
this.identifier = identifier; this.identifier = identifier;
} }
public RangeVariable Identifier {
get {
return identifier;
}
}
public FullNamedExpression IdentifierType { get; set; } public FullNamedExpression IdentifierType { get; set; }
protected Invocation CreateCastExpression (Expression lSide) protected Invocation CreateCastExpression (Expression lSide)
@ -476,6 +482,12 @@ namespace Mono.CSharp.Linq
} }
} }
public Expression SelectorExpression {
get {
return element_selector;
}
}
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args)
{ {
base.CreateArguments (ec, parameter, ref args); base.CreateArguments (ec, parameter, ref args);
@ -519,6 +531,13 @@ namespace Mono.CSharp.Linq
get { return this.GetIntoVariable (); } get { return this.GetIntoVariable (); }
} }
public Join (QueryBlock block, RangeVariable lt, Expression inner, QueryBlock outerSelector, QueryBlock innerSelector, Location loc)
: base (block, lt, inner, loc)
{
this.outer_selector = outerSelector;
this.inner_selector = innerSelector;
}
public QueryBlock InnerSelector { public QueryBlock InnerSelector {
get { get {
return inner_selector; return inner_selector;
@ -530,13 +549,6 @@ namespace Mono.CSharp.Linq
return outer_selector; return outer_selector;
} }
} }
public Join (QueryBlock block, RangeVariable lt, Expression inner, QueryBlock outerSelector, QueryBlock innerSelector, Location loc)
: base (block, lt, inner, loc)
{
this.outer_selector = outerSelector;
this.inner_selector = innerSelector;
}
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args)
{ {

70
ICSharpCode.NRefactory.CSharp/Parser/mcs/literal.cs

@ -95,8 +95,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class CharLiteral : CharConstant, ILiteralConstant public class CharLiteral : CharConstant, ILiteralConstant
@ -111,8 +116,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class IntLiteral : IntConstant, ILiteralConstant public class IntLiteral : IntConstant, ILiteralConstant
@ -143,8 +153,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class UIntLiteral : UIntConstant, ILiteralConstant public class UIntLiteral : UIntConstant, ILiteralConstant
@ -159,8 +174,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class LongLiteral : LongConstant, ILiteralConstant public class LongLiteral : LongConstant, ILiteralConstant
@ -175,8 +195,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class ULongLiteral : ULongConstant, ILiteralConstant public class ULongLiteral : ULongConstant, ILiteralConstant
@ -191,8 +216,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class FloatLiteral : FloatConstant, ILiteralConstant public class FloatLiteral : FloatConstant, ILiteralConstant
@ -207,8 +237,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class DoubleLiteral : DoubleConstant, ILiteralConstant public class DoubleLiteral : DoubleConstant, ILiteralConstant
@ -245,8 +280,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class DecimalLiteral : DecimalConstant, ILiteralConstant public class DecimalLiteral : DecimalConstant, ILiteralConstant
@ -261,8 +301,13 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
public class StringLiteral : StringConstant, ILiteralConstant public class StringLiteral : StringConstant, ILiteralConstant
@ -277,7 +322,12 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
char[] ILiteralConstant.ParsedValue { get; set; } public char[] ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
} }

39
ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs

@ -899,6 +899,11 @@ namespace Mono.CSharp {
#endregion #endregion
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public static Method Create (DeclSpace parent, GenericMethod generic, FullNamedExpression returnType, Modifiers mod, public static Method Create (DeclSpace parent, GenericMethod generic, FullNamedExpression returnType, Modifiers mod,
MemberName name, ParametersCompiled parameters, Attributes attrs, bool hasConstraints) MemberName name, ParametersCompiled parameters, Attributes attrs, bool hasConstraints)
{ {
@ -1175,11 +1180,6 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
// //
// Creates the type // Creates the type
// //
@ -1569,6 +1569,11 @@ namespace Mono.CSharp {
(Initializer.Arguments == null); (Initializer.Arguments == null);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.IsValidSecurityAttribute ()) { if (a.IsValidSecurityAttribute ()) {
@ -1614,11 +1619,6 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
// //
// Creates the ConstructorBuilder // Creates the ConstructorBuilder
// //
@ -2155,6 +2155,11 @@ namespace Mono.CSharp {
ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE; ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.Type == pa.Conditional) { if (a.Type == pa.Conditional) {
@ -2164,10 +2169,6 @@ namespace Mono.CSharp {
base.ApplyAttributeBuilder (a, ctor, cdata, pa); base.ApplyAttributeBuilder (a, ctor, cdata, pa);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
protected override bool CheckBase () protected override bool CheckBase ()
{ {
@ -2514,6 +2515,11 @@ namespace Mono.CSharp {
Block = block; Block = block;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.Type == pa.Conditional) { if (a.Type == pa.Conditional) {
@ -2524,11 +2530,6 @@ namespace Mono.CSharp {
base.ApplyAttributeBuilder (a, ctor, cdata, pa); base.ApplyAttributeBuilder (a, ctor, cdata, pa);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define () public override bool Define ()
{ {
const Modifiers RequiredModifiers = Modifiers.PUBLIC | Modifiers.STATIC; const Modifiers RequiredModifiers = Modifiers.PUBLIC | Modifiers.STATIC;

568
ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs

@ -35,6 +35,11 @@ namespace Mono.CSharp {
} }
} }
public static void Error_GlobalNamespaceRedefined (Report report, Location loc)
{
report.Error (1681, loc, "The global extern alias cannot be redefined");
}
public void RegisterNamespace (Namespace child) public void RegisterNamespace (Namespace child)
{ {
if (child != this) if (child != this)
@ -578,6 +583,9 @@ namespace Mono.CSharp {
// //
public class NamespaceContainer : IMemberContext, ITypesContainer public class NamespaceContainer : IMemberContext, ITypesContainer
{ {
static readonly Namespace[] empty_namespaces = new Namespace[0];
static readonly string[] empty_using_list = new string[0];
Namespace ns; Namespace ns;
readonly ModuleContainer module; readonly ModuleContainer module;
@ -588,20 +596,18 @@ namespace Mono.CSharp {
NamespaceContainer implicit_parent; NamespaceContainer implicit_parent;
int symfile_id; int symfile_id;
// Namespace using import block List<UsingNamespace> clauses;
List<NamespaceUsingAlias> using_aliases;
List<NamespaceUsing> using_clauses; // Used by parsed to check for parser errors
public bool DeclarationFound; public bool DeclarationFound;
// End
bool resolved; bool resolved;
public readonly bool IsImplicit; public readonly bool IsImplicit;
public readonly TypeContainer SlaveDeclSpace; public readonly TypeContainer SlaveDeclSpace;
static readonly Namespace [] empty_namespaces = new Namespace [0];
static readonly string[] empty_using_list = new string[0];
Namespace [] namespace_using_table; Namespace[] namespace_using_table;
Dictionary<string, UsingAliasNamespace> aliases;
public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile) public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
{ {
@ -644,89 +650,30 @@ namespace Mono.CSharp {
} }
} }
public CompilationSourceFile SourceFile { public NamespaceContainer Parent {
get { get {
return file; return parent;
} }
} }
public List<NamespaceUsing> Usings { public CompilationSourceFile SourceFile {
get { get {
return using_clauses; return file;
} }
} }
#endregion public List<UsingNamespace> Usings {
//
// Extracts the using alises and using clauses into a couple of
// arrays that might already have the same information; Used by the
// C# Eval mode.
//
public void Extract (List<NamespaceUsingAlias> out_using_aliases, List<NamespaceUsing> out_using_clauses)
{
if (using_aliases != null){
foreach (NamespaceUsingAlias uae in using_aliases){
bool replaced = false;
for (int i = 0; i < out_using_aliases.Count; i++){
NamespaceUsingAlias out_uea = (NamespaceUsingAlias) out_using_aliases [i];
if (out_uea.Alias == uae.Alias){
out_using_aliases [i] = uae;
replaced = true;
break;
}
}
if (!replaced)
out_using_aliases.Add (uae);
}
}
if (using_clauses != null){
foreach (NamespaceUsing ue in using_clauses){
bool found = false;
foreach (NamespaceUsing out_ue in out_using_clauses)
if (out_ue.Name == ue.Name){
found = true;
break;
}
if (!found)
out_using_clauses.Add (ue);
}
}
}
//
// According to section 16.3.1 (using-alias-directive), the namespace-or-type-name is
// resolved as if the immediately containing namespace body has no using-directives.
//
// Section 16.3.2 says that the same rule is applied when resolving the namespace-name
// in the using-namespace-directive.
//
// To implement these rules, the expressions in the using directives are resolved using
// the "doppelganger" (ghostly bodiless duplicate).
//
NamespaceContainer doppelganger;
NamespaceContainer Doppelganger {
get { get {
if (!IsImplicit && doppelganger == null) { return clauses;
doppelganger = new NamespaceContainer (module, ImplicitParent, file, ns, true);
doppelganger.using_aliases = using_aliases;
}
return doppelganger;
} }
} }
#endregion
public Namespace NS { public Namespace NS {
get { return ns; } get { return ns; }
} }
public NamespaceContainer Parent {
get { return parent; }
}
public NamespaceContainer ImplicitParent { public NamespaceContainer ImplicitParent {
get { get {
if (parent == null) if (parent == null)
@ -740,78 +687,47 @@ namespace Mono.CSharp {
} }
} }
/// <summary> public void AddUsing (UsingNamespace un)
/// Records a new namespace for resolving name references
/// </summary>
public void AddUsing (MemberName name, Location loc)
{ {
if (DeclarationFound){ if (DeclarationFound){
Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations"); Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
} }
if (using_clauses == null) { if (clauses == null)
using_clauses = new List<NamespaceUsing> (); clauses = new List<UsingNamespace> ();
} else {
foreach (NamespaceUsing old_entry in using_clauses) {
if (name.Equals (old_entry.MemberName)) {
Compiler.Report.SymbolRelatedToPreviousError (old_entry.Location, old_entry.GetSignatureForError ());
Compiler.Report.Warning (105, 3, loc, "The using directive for `{0}' appeared previously in this namespace", name.GetSignatureForError ());
return;
}
}
}
using_clauses.Add (new NamespaceUsing (name)); clauses.Add (un);
}
public void AddUsingAlias (string alias, MemberName name, Location loc) resolved = false;
{
if (DeclarationFound){
Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
}
AddUsingAlias (new LocalUsingAliasEntry (alias, name, loc));
} }
public void AddUsingExternalAlias (string alias, Location loc, Report Report) public void AddUsing (UsingAliasNamespace un)
{ {
bool not_first = using_clauses != null || DeclarationFound; if (DeclarationFound){
if (using_aliases != null && !not_first) { Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations");
foreach (NamespaceUsingAlias uae in using_aliases) {
if (uae is LocalUsingAliasEntry) {
not_first = true;
break;
}
}
}
if (not_first)
Report.Error (439, loc, "An extern alias declaration must precede all other elements");
if (alias == "global") {
Error_GlobalNamespaceRedefined (loc, Report);
return;
} }
AddUsingAlias (new NamespaceUsingAlias (alias, loc)); AddAlias (un);
} }
void AddUsingAlias (NamespaceUsingAlias uae) void AddAlias (UsingAliasNamespace un)
{ {
if (using_aliases == null) { if (clauses == null) {
using_aliases = new List<NamespaceUsingAlias> (); clauses = new List<UsingNamespace> ();
} else { } else {
foreach (NamespaceUsingAlias entry in using_aliases) { foreach (var entry in clauses) {
if (uae.Alias == entry.Alias) { var a = entry as UsingAliasNamespace;
Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias); if (a != null && a.Alias.Equals (un.Alias)) {
Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace", Compiler.Report.SymbolRelatedToPreviousError (a.Location, "");
entry.Alias); Compiler.Report.Error (1537, un.Location,
return; "The using alias `{0}' appeared previously in this namespace", un.Alias.GetSignatureForError ());
} }
} }
} }
using_aliases.Add (uae); clauses.Add (un);
resolved = false;
} }
// //
@ -821,7 +737,7 @@ namespace Mono.CSharp {
public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity) public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
{ {
List<MethodSpec> candidates = null; List<MethodSpec> candidates = null;
foreach (Namespace n in GetUsingTable ()) { foreach (Namespace n in namespace_using_table) {
var a = n.LookupExtensionMethod (this, extensionType, name, arity); var a = n.LookupExtensionMethod (this, extensionType, name, arity);
if (a == null) if (a == null)
continue; continue;
@ -866,7 +782,7 @@ namespace Mono.CSharp {
IEnumerable<string> all = Enumerable.Empty<string> (); IEnumerable<string> all = Enumerable.Empty<string> ();
for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){ for (NamespaceContainer curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
foreach (Namespace using_ns in GetUsingTable ()){ foreach (Namespace using_ns in namespace_using_table){
if (prefix.StartsWith (using_ns.Name)){ if (prefix.StartsWith (using_ns.Name)){
int ld = prefix.LastIndexOf ('.'); int ld = prefix.LastIndexOf ('.');
if (ld != -1){ if (ld != -1){
@ -881,18 +797,35 @@ namespace Mono.CSharp {
return all.Distinct ().ToList (); return all.Distinct ().ToList ();
} }
//
// Looks-up a alias named @name in this and surrounding namespace declarations
//
public FullNamedExpression LookupExternAlias (string name)
{
if (aliases == null)
return null;
UsingAliasNamespace uan;
if (aliases.TryGetValue (name, out uan) && uan is UsingExternAlias)
return uan.ResolvedExpression;
return null;
}
//
// Looks-up a alias named @name in this and surrounding namespace declarations // Looks-up a alias named @name in this and surrounding namespace declarations
//
public FullNamedExpression LookupNamespaceAlias (string name) public FullNamedExpression LookupNamespaceAlias (string name)
{ {
for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) { for (NamespaceContainer n = this; n != null; n = n.ImplicitParent) {
if (n.using_aliases == null) if (n.aliases == null)
continue; continue;
foreach (NamespaceUsingAlias ue in n.using_aliases) { UsingAliasNamespace uan;
if (ue.Alias == name) if (n.aliases.TryGetValue (name, out uan))
return ue.Resolve (Doppelganger ?? this, Doppelganger == null); return uan.ResolvedExpression;
}
} }
return null; return null;
@ -908,26 +841,19 @@ namespace Mono.CSharp {
// //
// Check aliases. // Check aliases.
// //
if (using_aliases != null && arity == 0) { if (aliases != null && arity == 0) {
foreach (NamespaceUsingAlias ue in using_aliases) { UsingAliasNamespace uan;
if (ue.Alias == name) { if (aliases.TryGetValue (name, out uan)) {
if (fne != null) { if (fne != null) {
if (Doppelganger != null) { // TODO: Namespace has broken location
if (mode == LookupMode.Normal) { //Report.SymbolRelatedToPreviousError (fne.Location, null);
// TODO: Namespace has broken location Compiler.Report.SymbolRelatedToPreviousError (uan.Location, null);
//Report.SymbolRelatedToPreviousError (fne.Location, null); Compiler.Report.Error (576, loc,
Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null); "Namespace `{0}' contains a definition with same name as alias `{1}'",
Compiler.Report.Error (576, loc, GetSignatureForError (), name);
"Namespace `{0}' contains a definition with same name as alias `{1}'",
GetSignatureForError (), name);
}
} else {
return fne;
}
}
return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
} }
return uan.ResolvedExpression;
} }
} }
@ -941,9 +867,11 @@ namespace Mono.CSharp {
// Check using entries. // Check using entries.
// //
FullNamedExpression match = null; FullNamedExpression match = null;
foreach (Namespace using_ns in GetUsingTable ()) { foreach (Namespace using_ns in namespace_using_table) {
//
// A using directive imports only types contained in the namespace, it // A using directive imports only types contained in the namespace, it
// does not import any nested namespaces // does not import any nested namespaces
//
fne = using_ns.LookupType (this, name, arity, mode, loc); fne = using_ns.LookupType (this, name, arity, mode, loc);
if (fne == null) if (fne == null)
continue; continue;
@ -983,41 +911,20 @@ namespace Mono.CSharp {
return match; return match;
} }
Namespace [] GetUsingTable ()
{
if (namespace_using_table != null)
return namespace_using_table;
if (using_clauses == null)
return empty_namespaces;
var list = new List<Namespace> (using_clauses.Count);
foreach (NamespaceUsing ue in using_clauses) {
Namespace using_ns = ue.Resolve (Doppelganger);
if (using_ns == null)
continue;
list.Add (using_ns);
}
if (Compiler.Settings.StatementMode)
return list.ToArray ();
namespace_using_table = list.ToArray ();
return namespace_using_table;
}
public int SymbolFileID { public int SymbolFileID {
get { get {
if (symfile_id == 0 && file.SourceFileEntry != null) { if (symfile_id == 0 && file.SourceFileEntry != null) {
int parent_id = parent == null ? 0 : parent.SymbolFileID; int parent_id = parent == null ? 0 : parent.SymbolFileID;
string [] using_list = empty_using_list; string [] using_list = empty_using_list;
if (using_clauses != null) { if (clauses != null) {
using_list = new string [using_clauses.Count]; // TODO: Why is it needed, what to do with aliases
for (int i = 0; i < using_clauses.Count; i++) var ul = new List<string> ();
using_list [i] = ((NamespaceUsing) using_clauses [i]).MemberName.GetName (); foreach (var c in clauses) {
ul.Add (c.NamespaceName.GetName ());
}
using_list = ul.ToArray ();
} }
symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id); symfile_id = SymbolWriter.DefineNamespace (ns.Name, file.CompileUnitEntry, using_list, parent_id);
@ -1036,11 +943,6 @@ namespace Mono.CSharp {
Console.WriteLine (" Try using -pkg:" + s); Console.WriteLine (" Try using -pkg:" + s);
} }
public static void Error_GlobalNamespaceRedefined (Location loc, Report Report)
{
Report.Error (1681, loc, "The global extern alias cannot be redefined");
}
public static void Error_NamespaceNotFound (Location loc, string name, Report Report) public static void Error_NamespaceNotFound (Location loc, string name, Report Report)
{ {
Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?", Report.Error (246, loc, "The type or namespace name `{0}' could not be found. Are you missing a using directive or an assembly reference?",
@ -1069,29 +971,76 @@ namespace Mono.CSharp {
} }
} }
/// <summary> public void Define ()
/// Used to validate that all the using clauses are correct
/// after we are finished parsing all the files.
/// </summary>
public void Resolve ()
{ {
if (resolved) if (resolved)
return; return;
// FIXME: Because we call Define from bottom not top
if (parent != null)
parent.Define ();
namespace_using_table = empty_namespaces;
resolved = true; resolved = true;
if (using_aliases != null) { if (clauses != null) {
foreach (NamespaceUsingAlias ue in using_aliases) var list = new List<Namespace> (clauses.Count);
ue.Resolve (Doppelganger, Doppelganger == null); bool post_process_using_aliases = false;
}
for (int i = 0; i < clauses.Count; ++i) {
var entry = clauses[i];
if (entry.Alias != null) {
if (aliases == null)
aliases = new Dictionary<string, UsingAliasNamespace> ();
//
// Aliases are not available when resolving using section
// except extern aliases
//
if (entry is UsingExternAlias) {
entry.Define (this);
if (entry.ResolvedExpression != null)
aliases.Add (entry.Alias.Name, (UsingExternAlias) entry);
clauses.RemoveAt (i--);
} else {
post_process_using_aliases = true;
}
if (using_clauses != null) { continue;
foreach (NamespaceUsing ue in using_clauses) }
ue.Resolve (Doppelganger);
}
if (parent != null) entry.Define (this);
parent.Resolve ();
Namespace using_ns = entry.ResolvedExpression as Namespace;
if (using_ns == null)
continue;
if (list.Contains (using_ns)) {
Compiler.Report.Warning (105, 3, entry.Location,
"The using directive for `{0}' appeared previously in this namespace", using_ns.GetSignatureForError ());
} else {
list.Add (using_ns);
}
}
namespace_using_table = list.ToArray ();
if (post_process_using_aliases) {
for (int i = 0; i < clauses.Count; ++i) {
var entry = clauses[i];
if (entry.Alias != null) {
entry.Define (this);
if (entry.ResolvedExpression != null) {
aliases.Add (entry.Alias.Name, (UsingAliasNamespace) entry);
}
clauses.RemoveAt (i--);
}
}
}
}
} }
public string GetSignatureForError () public string GetSignatureForError ()
@ -1118,7 +1067,7 @@ namespace Mono.CSharp {
} }
public bool IsObsolete { public bool IsObsolete {
get { return SlaveDeclSpace.IsObsolete; } get { return false; }
} }
public bool IsUnsafe { public bool IsUnsafe {
@ -1136,106 +1085,199 @@ namespace Mono.CSharp {
#endregion #endregion
} }
public class NamespaceUsing public class UsingNamespace
{ {
readonly MemberName name; readonly MemberName name;
Namespace resolved; readonly Location loc;
protected FullNamedExpression resolved;
public NamespaceUsing (MemberName name) public UsingNamespace (MemberName name, Location loc)
{ {
this.name = name; this.name = name;
this.loc = loc;
} }
public string GetSignatureForError () #region Properties
{
return name.GetSignatureForError ();
}
public Location Location public virtual MemberName Alias {
{ get {
get { return name.Location; } return null;
}
} }
public MemberName MemberName public Location Location {
{ get {
get { return name; } return loc;
}
} }
public string Name public MemberName NamespaceName {
{ get {
get { return GetSignatureForError (); } return name;
}
} }
public Namespace Resolve (IMemberContext rc) public FullNamedExpression ResolvedExpression {
{ get {
if (resolved != null)
return resolved; return resolved;
}
}
FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeOrNamespace (rc); #endregion
if (fne == null)
return null;
resolved = fne as Namespace; public string GetSignatureForError ()
if (resolved == null) { {
rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type); return name.GetSignatureForError ();
rc.Module.Compiler.Report.Error (138, Location, }
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ()); public virtual void Define (NamespaceContainer ctx)
{
resolved = name.GetTypeExpression ().ResolveAsTypeOrNamespace (ctx);
var ns = resolved as Namespace;
if (ns == null) {
if (resolved != null) {
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (resolved.Type);
ctx.Module.Compiler.Report.Error (138, Location,
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ());
}
} }
return resolved;
} }
} }
public class NamespaceUsingAlias public class UsingExternAlias : UsingAliasNamespace
{ {
public readonly string Alias; public UsingExternAlias (MemberName alias, Location loc)
public Location Location; : base (alias, null, loc)
public NamespaceUsingAlias (string alias, Location loc)
{ {
this.Alias = alias;
this.Location = loc;
} }
public virtual FullNamedExpression Resolve (IMemberContext rc, bool local) public override void Define (NamespaceContainer ctx)
{ {
FullNamedExpression fne = rc.Module.GetRootNamespace (Alias); resolved = ctx.Module.GetRootNamespace (Alias.Name);
if (fne == null) { if (resolved == null) {
rc.Module.Compiler.Report.Error (430, Location, ctx.Module.Compiler.Report.Error (430, Location,
"The extern alias `{0}' was not specified in -reference option", "The extern alias `{0}' was not specified in -reference option",
Alias); Alias.Name);
} }
return fne;
} }
} }
class LocalUsingAliasEntry : NamespaceUsingAlias public class UsingAliasNamespace : UsingNamespace
{ {
FullNamedExpression resolved; readonly MemberName alias;
MemberName value;
public LocalUsingAliasEntry (string alias, MemberName name, Location loc) struct AliasContext : IMemberContext
: base (alias, loc)
{ {
this.value = name; readonly NamespaceContainer ns;
}
public override FullNamedExpression Resolve (IMemberContext rc, bool local) public AliasContext (NamespaceContainer ns)
{ {
if (resolved != null || value == null) this.ns = ns;
return resolved; }
public TypeSpec CurrentType {
get {
return null;
}
}
public TypeParameter[] CurrentTypeParameters {
get {
return null;
}
}
public MemberCore CurrentMemberDefinition {
get {
return null;
}
}
public bool IsObsolete {
get {
return false;
}
}
public bool IsUnsafe {
get {
throw new NotImplementedException ();
}
}
public bool IsStatic {
get {
throw new NotImplementedException ();
}
}
public ModuleContainer Module {
get {
return ns.Module;
}
}
public string GetSignatureForError ()
{
throw new NotImplementedException ();
}
if (local) public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
{
return null; return null;
}
public FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
{
var fne = ns.NS.LookupTypeOrNamespace (ns, name, arity, mode, loc);
if (fne != null)
return fne;
//
// Only extern aliases are allowed in this context
//
fne = ns.LookupExternAlias (name);
if (fne != null)
return fne;
if (ns.ImplicitParent != null)
return ns.ImplicitParent.LookupNamespaceOrType (name, arity, mode, loc);
resolved = value.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
if (resolved == null) {
value = null;
return null; return null;
} }
return resolved; public FullNamedExpression LookupNamespaceAlias (string name)
{
return ns.LookupNamespaceAlias (name);
}
}
public UsingAliasNamespace (MemberName alias, MemberName ns, Location loc)
: base (ns, loc)
{
this.alias = alias;
}
public override MemberName Alias {
get {
return alias;
}
}
public override void Define (NamespaceContainer ctx)
{
//
// The namespace-or-type-name of a using-alias-directive is resolved as if
// the immediately containing compilation unit or namespace body had no
// using-directives. A using-alias-directive may however be affected
// by extern-alias-directives in the immediately containing compilation
// unit or namespace body
//
// We achieve that by introducing alias-context which redirect any local
// namespace or type resolve calls to parent namespace
//
resolved = NamespaceName.GetTypeExpression ().ResolveAsTypeOrNamespace (new AliasContext (ctx));
} }
} }
} }

20
ICSharpCode.NRefactory.CSharp/Parser/mcs/nullable.cs

@ -1001,20 +1001,24 @@ namespace Mono.CSharp.Nullable
Expression left, right; Expression left, right;
Unwrap unwrap; Unwrap unwrap;
public Expression Left {
get { return this.left; }
}
public Expression Right {
get { return this.right; }
}
public NullCoalescingOperator (Expression left, Expression right, Location loc) public NullCoalescingOperator (Expression left, Expression right, Location loc)
{ {
this.left = left; this.left = left;
this.right = right; this.right = right;
this.loc = loc; this.loc = loc;
} }
public Expression LeftExpression {
get {
return left;
}
}
public Expression Right {
get {
return right;
}
}
public override Expression CreateExpressionTree (ResolveContext ec) public override Expression CreateExpressionTree (ResolveContext ec)
{ {

19
ICSharpCode.NRefactory.CSharp/Parser/mcs/parameter.cs

@ -234,10 +234,7 @@ namespace Mono.CSharp {
TemporaryVariableReference expr_tree_variable; TemporaryVariableReference expr_tree_variable;
HoistedVariable hoisted_variant; HoistedVariable hoisted_variant;
public Modifier ParameterModifier { get { return modFlags; }}
public Expression DefaultExpression { get { return default_expr; }}
public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc) public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc)
{ {
this.name = name; this.name = name;
@ -251,6 +248,12 @@ namespace Mono.CSharp {
#region Properties #region Properties
public Expression DefaultExpression {
get {
return default_expr;
}
}
public DefaultParameterValueExpression DefaultValue { public DefaultParameterValueExpression DefaultValue {
get { get {
return default_expr as DefaultParameterValueExpression; return default_expr as DefaultParameterValueExpression;
@ -279,6 +282,12 @@ namespace Mono.CSharp {
} }
} }
public Modifier ParameterModifier {
get {
return modFlags;
}
}
public TypeSpec Type { public TypeSpec Type {
get { get {
return parameter_type; return parameter_type;
@ -1212,7 +1221,7 @@ namespace Mono.CSharp {
// //
// Default parameter value expression. We need this wrapper to handle // Default parameter value expression. We need this wrapper to handle
// default parameter values of folded constants when for indexer parameters // default parameter values of folded constants (e.g. indexer parameters).
// The expression is resolved only once but applied to two methods which // The expression is resolved only once but applied to two methods which
// both share reference to this expression and we ensure that resolving // both share reference to this expression and we ensure that resolving
// this expression always returns same instance // this expression always returns same instance

56
ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs

@ -733,6 +733,12 @@ namespace Mono.CSharp
{ {
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
void CreateAutomaticProperty () void CreateAutomaticProperty ()
{ {
// Create backing field // Create backing field
@ -757,11 +763,6 @@ namespace Mono.CSharp
Set.Block.AddStatement (new StatementExpression (a)); Set.Block.AddStatement (new StatementExpression (a));
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define () public override bool Define ()
{ {
if (!base.Define ()) if (!base.Define ())
@ -857,6 +858,11 @@ namespace Mono.CSharp
{ {
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define() public override bool Define()
{ {
if (!base.Define ()) if (!base.Define ())
@ -871,12 +877,6 @@ namespace Mono.CSharp
return attribute_targets; return attribute_targets;
} }
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
} }
/// <summary> /// <summary>
@ -999,6 +999,12 @@ namespace Mono.CSharp
#region Properties #region Properties
public List<FieldDeclarator> Declarators {
get {
return this.declarators;
}
}
bool HasBackingField { bool HasBackingField {
get { get {
return !IsInterface && (ModFlags & Modifiers.ABSTRACT) == 0; return !IsInterface && (ModFlags & Modifiers.ABSTRACT) == 0;
@ -1020,14 +1026,14 @@ namespace Mono.CSharp
} }
} }
public List<FieldDeclarator> Declarators {
get {
return this.declarators;
}
}
#endregion #endregion
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public void AddDeclarator (FieldDeclarator declarator) public void AddDeclarator (FieldDeclarator declarator)
{ {
if (declarators == null) if (declarators == null)
@ -1105,11 +1111,6 @@ namespace Mono.CSharp
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
} }
public abstract class Event : PropertyBasedMember public abstract class Event : PropertyBasedMember
@ -1513,6 +1514,12 @@ namespace Mono.CSharp
#endregion #endregion
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{ {
if (a.Type == pa.IndexerName) { if (a.Type == pa.IndexerName) {
@ -1534,11 +1541,6 @@ namespace Mono.CSharp
return Parent.MemberCache.CheckExistingMembersOverloads (this, parameters); return Parent.MemberCache.CheckExistingMembersOverloads (this, parameters);
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
public override bool Define () public override bool Define ()
{ {
if (!base.Define ()) if (!base.Define ())

14
ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs

@ -442,12 +442,7 @@ namespace Mono.CSharp
return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null; return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null;
} }
public override Assembly LoadAssemblyFile (string fileName) public override Assembly LoadAssemblyFile (string assembly, bool isImplicitReference)
{
return LoadAssemblyFile (fileName, false);
}
Assembly LoadAssemblyFile (string assembly, bool soft)
{ {
Assembly a = null; Assembly a = null;
@ -464,7 +459,7 @@ namespace Mono.CSharp
a = Assembly.Load (ass); a = Assembly.Load (ass);
} }
} catch (FileNotFoundException) { } catch (FileNotFoundException) {
bool err = !soft; bool err = !isImplicitReference;
foreach (string dir in paths) { foreach (string dir in paths) {
string full_path = Path.Combine (dir, assembly); string full_path = Path.Combine (dir, assembly);
if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe")) if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe"))
@ -490,11 +485,6 @@ namespace Mono.CSharp
return a; return a;
} }
public override Assembly LoadAssemblyDefault (string fileName)
{
return LoadAssemblyFile (fileName, true);
}
Module LoadModuleFile (AssemblyDefinitionDynamic assembly, string module) Module LoadModuleFile (AssemblyDefinitionDynamic assembly, string module)
{ {
string total_log = ""; string total_log = "";

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/roottypes.cs

@ -367,7 +367,7 @@ namespace Mono.CSharp
public RootNamespace CreateRootNamespace (string alias) public RootNamespace CreateRootNamespace (string alias)
{ {
if (alias == global_ns.Alias) { if (alias == global_ns.Alias) {
NamespaceContainer.Error_GlobalNamespaceRedefined (Location.Null, Report); RootNamespace.Error_GlobalNamespaceRedefined (Report, Location.Null);
return global_ns; return global_ns;
} }

215
ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs

@ -154,9 +154,11 @@ namespace Mono.CSharp {
FalseStatement = false_statement; FalseStatement = false_statement;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
@ -639,9 +641,11 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
loc = expr.Location; loc = expr.Location;
} }
public ExpressionStatement Expr { public ExpressionStatement Expr {
get { return this.expr; } get {
return this.expr;
}
} }
protected override void CloneTo (CloneContext clonectx, Statement t) protected override void CloneTo (CloneContext clonectx, Statement t)
@ -676,7 +680,7 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
} }
public Expression Expression { public Expression Expr {
get { get {
return expr; return expr;
} }
@ -779,25 +783,30 @@ namespace Mono.CSharp {
/// </summary> /// </summary>
public class Return : ExitStatement public class Return : ExitStatement
{ {
public Expression Expr { get; protected set; } Expression expr;
public Return (Expression expr, Location l) public Return (Expression expr, Location l)
{ {
Expr = expr; this.expr = expr;
loc = l; loc = l;
} }
#region Properties #region Properties
public Expression Expression {
public Expression Expr {
get { get {
return Expr; return expr;
}
protected set {
expr = value;
} }
} }
#endregion #endregion
protected override bool DoResolve (BlockContext ec) protected override bool DoResolve (BlockContext ec)
{ {
if (Expr == null) { if (expr == null) {
if (ec.ReturnType.Kind == MemberKind.Void) if (ec.ReturnType.Kind == MemberKind.Void)
return true; return true;
@ -811,7 +820,7 @@ namespace Mono.CSharp {
// //
// Extra trick not to emit ret/leave inside awaiter body // Extra trick not to emit ret/leave inside awaiter body
// //
Expr = EmptyExpression.Null; expr = EmptyExpression.Null;
return true; return true;
} }
} }
@ -827,7 +836,7 @@ namespace Mono.CSharp {
return false; return false;
} }
Expr = Expr.Resolve (ec); expr = expr.Resolve (ec);
TypeSpec block_return_type = ec.ReturnType; TypeSpec block_return_type = ec.ReturnType;
AnonymousExpression am = ec.CurrentAnonymousMethod; AnonymousExpression am = ec.CurrentAnonymousMethod;
@ -845,12 +854,12 @@ namespace Mono.CSharp {
var async_block = am as AsyncInitializer; var async_block = am as AsyncInitializer;
if (async_block != null) { if (async_block != null) {
if (Expr != null) { if (expr != null) {
var storey = (AsyncTaskStorey) am.Storey; var storey = (AsyncTaskStorey) am.Storey;
var async_type = storey.ReturnType; var async_type = storey.ReturnType;
if (async_type == null && async_block.ReturnTypeInference != null) { if (async_type == null && async_block.ReturnTypeInference != null) {
async_block.ReturnTypeInference.AddCommonTypeBound (Expr.Type); async_block.ReturnTypeInference.AddCommonTypeBound (expr.Type);
return true; return true;
} }
@ -871,20 +880,20 @@ namespace Mono.CSharp {
} }
} else { } else {
var l = am as AnonymousMethodBody; var l = am as AnonymousMethodBody;
if (l != null && l.ReturnTypeInference != null && Expr != null) { if (l != null && l.ReturnTypeInference != null && expr != null) {
l.ReturnTypeInference.AddCommonTypeBound (Expr.Type); l.ReturnTypeInference.AddCommonTypeBound (expr.Type);
return true; return true;
} }
} }
} }
if (Expr == null) if (expr == null)
return false; return false;
if (Expr.Type != block_return_type) { if (expr.Type != block_return_type) {
Expr = Convert.ImplicitConversionRequired (ec, Expr, block_return_type, loc); expr = Convert.ImplicitConversionRequired (ec, expr, block_return_type, loc);
if (Expr == null) { if (expr == null) {
if (am != null && block_return_type == ec.ReturnType) { if (am != null && block_return_type == ec.ReturnType) {
ec.Report.Error (1662, loc, ec.Report.Error (1662, loc,
"Cannot convert `{0}' to delegate type `{1}' because some of the return types in the block are not implicitly convertible to the delegate return type", "Cannot convert `{0}' to delegate type `{1}' because some of the return types in the block are not implicitly convertible to the delegate return type",
@ -899,8 +908,8 @@ namespace Mono.CSharp {
protected override void DoEmit (EmitContext ec) protected override void DoEmit (EmitContext ec)
{ {
if (Expr != null) { if (expr != null) {
Expr.Emit (ec); expr.Emit (ec);
var async_body = ec.CurrentAnonymousMethod as AsyncInitializer; var async_body = ec.CurrentAnonymousMethod as AsyncInitializer;
if (async_body != null) { if (async_body != null) {
@ -936,9 +945,10 @@ namespace Mono.CSharp {
{ {
Return target = (Return) t; Return target = (Return) t;
// It's null for simple return; // It's null for simple return;
if (Expr != null) if (expr != null)
target.Expr = Expr.Clone (clonectx); target.expr = expr.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -1135,9 +1145,11 @@ namespace Mono.CSharp {
expr = e; expr = e;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
@ -1207,11 +1219,13 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
if (expr == null) { if (expr == null) {
@ -1872,6 +1886,7 @@ namespace Mono.CSharp {
public static string GetCompilerGeneratedName (Block block) public static string GetCompilerGeneratedName (Block block)
{ {
// HACK: Debugger depends on the name semantics
return "$locvar" + block.ParametersBlock.TemporaryLocalsCount++.ToString ("X"); return "$locvar" + block.ParametersBlock.TemporaryLocalsCount++.ToString ("X");
} }
@ -1988,7 +2003,7 @@ namespace Mono.CSharp {
int? resolving_init_idx; int? resolving_init_idx;
protected Block original; Block original;
#if DEBUG #if DEBUG
static int id; static int id;
@ -2035,6 +2050,9 @@ namespace Mono.CSharp {
get { get {
return original; return original;
} }
protected set {
original = value;
}
} }
public bool IsCompilerGenerated { public bool IsCompilerGenerated {
@ -2051,10 +2069,11 @@ namespace Mono.CSharp {
get { return (flags & Flags.Unsafe) != 0; } get { return (flags & Flags.Unsafe) != 0; }
set { flags |= Flags.Unsafe; } set { flags |= Flags.Unsafe; }
} }
public List<Statement> Statements { public List<Statement> Statements {
get { return this.statements; } get { return statements; }
} }
#endregion #endregion
public Block CreateSwitchBlock (Location start) public Block CreateSwitchBlock (Location start)
@ -2328,6 +2347,7 @@ namespace Mono.CSharp {
foreach (Statement s in statements) foreach (Statement s in statements)
target.statements.Add (s.Clone (clonectx)); target.statements.Add (s.Clone (clonectx));
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -2692,7 +2712,7 @@ namespace Mono.CSharp {
// Overwrite original for comparison purposes when linking cross references // Overwrite original for comparison purposes when linking cross references
// between anonymous methods // between anonymous methods
// //
original = source; Original = source;
} }
#region Properties #region Properties
@ -2906,7 +2926,7 @@ namespace Mono.CSharp {
ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation); ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation);
pb.EndLocation = EndLocation; pb.EndLocation = EndLocation;
pb.statements = statements; pb.statements = statements;
pb.original = this; pb.Original = this;
var iterator = new Iterator (pb, method, host, iterator_type, is_enumerable); var iterator = new Iterator (pb, method, host, iterator_type, is_enumerable);
am_storey = new IteratorStorey (iterator); am_storey = new IteratorStorey (iterator);
@ -2921,7 +2941,7 @@ namespace Mono.CSharp {
ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation); ParametersBlock pb = new ParametersBlock (this, ParametersCompiled.EmptyReadOnlyParameters, StartLocation);
pb.EndLocation = EndLocation; pb.EndLocation = EndLocation;
pb.statements = statements; pb.statements = statements;
pb.original = this; pb.Original = this;
var block_type = host.Module.Compiler.BuiltinTypes.Void; var block_type = host.Module.Compiler.BuiltinTypes.Void;
var initializer = new AsyncInitializer (pb, host, block_type); var initializer = new AsyncInitializer (pb, host, block_type);
@ -4468,11 +4488,13 @@ namespace Mono.CSharp {
{ {
this.expr = expr; this.expr = expr;
} }
public Expression Expr { public Expression Expr {
get { return this.expr; } get {
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
expr = expr.Resolve (ec); expr = expr.Resolve (ec);
@ -5151,6 +5173,12 @@ namespace Mono.CSharp {
this.fini = fini; this.fini = fini;
} }
public Block Finallyblock {
get {
return fini;
}
}
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
bool ok = true; bool ok = true;
@ -5202,23 +5230,20 @@ namespace Mono.CSharp {
public class TryCatch : ExceptionStatement public class TryCatch : ExceptionStatement
{ {
public Block Block; public Block Block;
public List<Catch> Specific; List<Catch> clauses;
public Catch General;
readonly bool inside_try_finally; readonly bool inside_try_finally;
public TryCatch (Block block, List<Catch> catch_clauses, Location l, bool inside_try_finally) public TryCatch (Block block, List<Catch> catch_clauses, Location l, bool inside_try_finally)
: base (l) : base (l)
{ {
this.Block = block; this.Block = block;
this.Specific = catch_clauses; this.clauses = catch_clauses;
this.inside_try_finally = inside_try_finally; this.inside_try_finally = inside_try_finally;
}
if (catch_clauses != null) {
Catch c = catch_clauses [0]; public List<Catch> Clauses {
if (c.IsGeneral) { get {
this.General = c; return clauses;
catch_clauses.RemoveAt (0);
}
} }
} }
@ -5237,9 +5262,8 @@ namespace Mono.CSharp {
if (!Block.Resolve (ec)) if (!Block.Resolve (ec))
ok = false; ok = false;
TypeSpec[] prev_catches = new TypeSpec [Specific.Count]; for (int i = 0; i < clauses.Count; ++i) {
int last_index = 0; var c = clauses[i];
foreach (Catch c in Specific){
ec.CurrentBranching.CreateSibling (c.Block, FlowBranching.SiblingType.Catch); ec.CurrentBranching.CreateSibling (c.Block, FlowBranching.SiblingType.Catch);
if (!c.Resolve (ec)) { if (!c.Resolve (ec)) {
@ -5248,37 +5272,40 @@ namespace Mono.CSharp {
} }
TypeSpec resolved_type = c.CatchType; TypeSpec resolved_type = c.CatchType;
for (int ii = 0; ii < last_index; ++ii) { for (int ii = 0; ii < clauses.Count; ++ii) {
if (resolved_type == prev_catches[ii] || TypeSpec.IsBaseClass (resolved_type, prev_catches[ii], true)) { if (ii == i)
ec.Report.Error (160, c.loc, continue;
"A previous catch clause already catches all exceptions of this or a super type `{0}'",
TypeManager.CSharpName (prev_catches [ii]));
ok = false;
}
}
prev_catches [last_index++] = resolved_type; if (clauses[ii].IsGeneral) {
} if (resolved_type.BuiltinType != BuiltinTypeSpec.Type.Exception)
continue;
if (!ec.Module.DeclaringAssembly.WrapNonExceptionThrows)
continue;
if (!ec.Module.PredefinedAttributes.RuntimeCompatibility.IsDefined)
continue;
ec.Report.Warning (1058, 1, c.loc,
"A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a `System.Runtime.CompilerServices.RuntimeWrappedException'");
if (General != null) {
foreach (Catch c in Specific) {
if (c.CatchType.BuiltinType != BuiltinTypeSpec.Type.Exception)
continue; continue;
}
if (!ec.Module.DeclaringAssembly.WrapNonExceptionThrows) if (ii >= i)
continue; continue;
if (!ec.Module.PredefinedAttributes.RuntimeCompatibility.IsDefined) var ct = clauses[ii].CatchType;
if (ct == null)
continue; continue;
ec.Report.Warning (1058, 1, c.loc, if (resolved_type == ct || TypeSpec.IsBaseClass (resolved_type, ct, true)) {
"A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a `System.Runtime.CompilerServices.RuntimeWrappedException'"); ec.Report.Error (160, c.loc,
"A previous catch clause already catches all exceptions of this or a super type `{0}'",
ct.GetSignatureForError ());
ok = false;
}
} }
ec.CurrentBranching.CreateSibling (General.Block, FlowBranching.SiblingType.Catch);
if (!General.Resolve (ec))
ok = false;
} }
ec.EndFlowBranching (); ec.EndFlowBranching ();
@ -5293,12 +5320,9 @@ namespace Mono.CSharp {
Block.Emit (ec); Block.Emit (ec);
foreach (Catch c in Specific) foreach (Catch c in clauses)
c.Emit (ec); c.Emit (ec);
if (General != null)
General.Emit (ec);
if (!inside_try_finally) if (!inside_try_finally)
ec.EndExceptionBlock (); ec.EndExceptionBlock ();
} }
@ -5308,14 +5332,13 @@ namespace Mono.CSharp {
TryCatch target = (TryCatch) t; TryCatch target = (TryCatch) t;
target.Block = clonectx.LookupBlock (Block); target.Block = clonectx.LookupBlock (Block);
if (General != null) if (clauses != null){
target.General = (Catch) General.Clone (clonectx); target.clauses = new List<Catch> ();
if (Specific != null){ foreach (Catch c in clauses)
target.Specific = new List<Catch> (); target.clauses.Add ((Catch) c.Clone (clonectx));
foreach (Catch c in Specific)
target.Specific.Add ((Catch) c.Clone (clonectx));
} }
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -5468,7 +5491,7 @@ namespace Mono.CSharp {
declarators = null; declarators = null;
return stmt; return stmt;
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
@ -5492,7 +5515,7 @@ namespace Mono.CSharp {
#region Properties #region Properties
public Expression Expression { public Expression Expr {
get { get {
return decl.Variable == null ? decl.Initializer : null; return decl.Variable == null ? decl.Initializer : null;
} }
@ -5571,6 +5594,7 @@ namespace Mono.CSharp {
target.decl = (VariableDeclaration) decl.Clone (clonectx); target.decl = (VariableDeclaration) decl.Clone (clonectx);
target.stmt = stmt.Clone (clonectx); target.stmt = stmt.Clone (clonectx);
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
return visitor.Visit (this); return visitor.Visit (this);
@ -6114,14 +6138,6 @@ namespace Mono.CSharp {
LocalVariable variable; LocalVariable variable;
Expression expr; Expression expr;
Statement statement; Statement statement;
public Expression TypeExpr {
get { return this.type; }
}
public LocalVariable Variable {
get { return this.variable; }
}
public Foreach (Expression type, LocalVariable var, Expression expr, Statement stmt, Location l) public Foreach (Expression type, LocalVariable var, Expression expr, Statement stmt, Location l)
{ {
@ -6132,14 +6148,23 @@ namespace Mono.CSharp {
loc = l; loc = l;
} }
public Expression Expr {
get { return expr; }
}
public Statement Statement { public Statement Statement {
get { return statement; } get { return statement; }
} }
public Expression Expr { public Expression TypeExpression {
get { return this.expr; } get { return type; }
} }
public LocalVariable Variable {
get { return variable; }
}
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
expr = expr.Resolve (ec); expr = expr.Resolve (ec);

3
ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs

@ -37,7 +37,7 @@ namespace Mono.CSharp {
return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (obj); return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (obj);
} }
} }
#if !NET_4_0
public class Tuple<T1, T2> : IEquatable<Tuple<T1, T2>> public class Tuple<T1, T2> : IEquatable<Tuple<T1, T2>>
{ {
public Tuple (T1 item1, T2 item2) public Tuple (T1 item1, T2 item2)
@ -107,6 +107,7 @@ namespace Mono.CSharp {
return new Tuple<T1, T2, T3> (item1, item2, item3); return new Tuple<T1, T2, T3> (item1, item2, item3);
} }
} }
#endif
static class ArrayComparer static class ArrayComparer
{ {

Loading…
Cancel
Save