Browse Source

Revert "Updated mcs."

This reverts commit 19c344c55c.
newNRvisualizers
Mike Krüger 14 years ago
parent
commit
e9903adbf9
  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. 9902
      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.PositionalArguments != null) { if (attr.PosArguments != null) {
foreach (var arg in attr.PositionalArguments) { foreach (var arg in attr.PosArguments) {
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.Expr.Accept (this) as Expression; var expr = statementErrorExpression.Expression.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.Clauses != null) { if (tryCatchStatement.Specific != null) {
foreach (Catch ctch in tryCatchStatement.Clauses) { foreach (Catch ctch in tryCatchStatement.Specific) {
result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole); result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
} }
} }
/* if (tryCatchStatement. != null) if (tryCatchStatement.General != 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.Expr != null) if (usingStatement.Expression != null)
result.AddChild ((AstNode)usingStatement.Expr.Accept (this), UsingStatement.ResourceAcquisitionRole); result.AddChild ((AstNode)usingStatement.Expression.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.TypeExpression != null) if (foreachStatement.TypeExpr != null)
result.AddChild (ConvertToType (foreachStatement.TypeExpression), ForeachStatement.Roles.Type); result.AddChild (ConvertToType (foreachStatement.TypeExpr), 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.LeftExpression.Accept (this), BinaryOperatorExpression.LeftRole); result.AddChild ((Expression)nullCoalescingOperator.Left.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.Exp != null) if (invocationExpression.Expression != null)
result.AddChild ((Expression)invocationExpression.Exp.Accept (this), InvocationExpression.Roles.TargetExpression); result.AddChild ((Expression)invocationExpression.Expression.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.TypeExpression), TypeOfExpression.Roles.Type); result.AddChild (ConvertToType (sizeOfExpression.QueriedType), 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,8 +885,9 @@ namespace Mono.CSharp {
public ParametersBlock Block; public ParametersBlock Block;
public AnonymousMethodExpression (Location loc) public AnonymousMethodExpression (bool isAsync, 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,7 +1090,8 @@ 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, bool isImplicitReference); public abstract T LoadAssemblyFile (string fileName);
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)
@ -1127,14 +1128,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 = LoadAssemblyFile ("mscorlib.dll", true); corlib_assembly = LoadAssemblyDefault ("mscorlib.dll");
} 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, false); a = LoadAssemblyFile (r);
if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly)) if (a == null || EqualityComparer<T>.Default.Equals (a, corlib_assembly))
continue; continue;
@ -1152,7 +1153,7 @@ namespace Mono.CSharp
} }
foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) { foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases) {
a = LoadAssemblyFile (entry.Item2, false); a = LoadAssemblyFile (entry.Item2);
if (a == null) if (a == null)
continue; continue;
@ -1165,7 +1166,7 @@ namespace Mono.CSharp
if (compiler.Settings.LoadDefaultReferences) { if (compiler.Settings.LoadDefaultReferences) {
foreach (string r in GetDefaultReferences ()) { foreach (string r in GetDefaultReferences ()) {
a = LoadAssemblyFile (r, true); a = LoadAssemblyDefault (r);
if (a == null) if (a == null)
continue; continue;

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

@ -418,11 +418,6 @@ 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
@ -658,12 +653,6 @@ 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);
@ -822,10 +811,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,12 +40,6 @@ 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,7 +89,8 @@ namespace Mono.CSharp {
public AttributeTargets Target; public AttributeTargets Target;
readonly ATypeNameExpression expression; readonly ATypeNameExpression expression;
Arguments pos_args, named_args; public Arguments PosArguments;
public Arguments NamedArguments;
bool resolve_error; bool resolve_error;
bool arg_resolved; bool arg_resolved;
@ -117,8 +118,8 @@ namespace Mono.CSharp {
{ {
this.expression = expr; this.expression = expr;
if (args != null) { if (args != null) {
pos_args = args[0]; PosArguments = args[0];
named_args = args[1]; NamedArguments = args[1];
} }
this.loc = loc; this.loc = loc;
ExplicitTarget = target; ExplicitTarget = target;
@ -131,24 +132,6 @@ 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";
@ -164,7 +147,7 @@ namespace Mono.CSharp {
} }
if (NamedArguments == null) if (NamedArguments == null)
named_args = new Arguments (1); NamedArguments = 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));
@ -173,8 +156,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.pos_args = pos_args; a.PosArguments = PosArguments;
a.named_args = NamedArguments; a.NamedArguments = NamedArguments;
return a; return a;
} }
@ -449,14 +432,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 (pos_args != null || !context.Module.AttributeConstructorCache.TryGetValue (Type, out ctor)) { if (PosArguments != 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 (pos_args == null && ctor.Parameters.IsEmpty) if (PosArguments == null && ctor.Parameters.IsEmpty)
context.Module.AttributeConstructorCache.Add (Type, ctor); context.Module.AttributeConstructorCache.Add (Type, ctor);
} }
@ -485,16 +468,16 @@ namespace Mono.CSharp {
MethodSpec ResolveConstructor (ResolveContext ec) MethodSpec ResolveConstructor (ResolveContext ec)
{ {
if (pos_args != null) { if (PosArguments != null) {
bool dynamic; bool dynamic;
pos_args.Resolve (ec, out dynamic); PosArguments.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 pos_args, loc); return Expression.ConstructorLookup (ec, Type, ref PosArguments, loc);
} }
bool ResolveNamedArguments (ResolveContext ec) bool ResolveNamedArguments (ResolveContext ec)
@ -654,7 +637,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return DefaultUsageAttribute; return DefaultUsageAttribute;
AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets) ((Constant) pos_args[0].Expr).GetValue ()); AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)((Constant) PosArguments [0].Expr).GetValue ());
var field = GetNamedValue ("AllowMultiple") as BoolConstant; var field = GetNamedValue ("AllowMultiple") as BoolConstant;
if (field != null) if (field != null)
@ -677,10 +660,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 || pos_args.Count != 1 || !(pos_args[0].Expr is Constant)) if (resolve_error || PosArguments.Count != 1 || !(PosArguments [0].Expr is Constant))
return null; return null;
return ((Constant) pos_args[0].Expr).GetValue () as string; return ((Constant) PosArguments [0].Expr).GetValue () as string;
} }
/// <summary> /// <summary>
@ -696,7 +679,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return null; return null;
return ((Constant) pos_args[0].Expr).GetValue () as string; return ((Constant) PosArguments[0].Expr).GetValue () as string;
} }
/// <summary> /// <summary>
@ -718,14 +701,14 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return null; return null;
if (pos_args == null) if (PosArguments == null)
return new ObsoleteAttribute (); return new ObsoleteAttribute ();
string msg = ((Constant) pos_args[0].Expr).GetValue () as string; string msg = ((Constant) PosArguments[0].Expr).GetValue () as string;
if (pos_args.Count == 1) if (PosArguments.Count == 1)
return new ObsoleteAttribute (msg); return new ObsoleteAttribute (msg);
return new ObsoleteAttribute (msg, ((BoolConstant) pos_args[1].Expr).Value); return new ObsoleteAttribute (msg, ((BoolConstant) PosArguments[1].Expr).Value);
} }
/// <summary> /// <summary>
@ -743,7 +726,7 @@ namespace Mono.CSharp {
if (resolve_error) if (resolve_error)
return false; return false;
return ((BoolConstant) pos_args[0].Expr).Value; return ((BoolConstant) PosArguments[0].Expr).Value;
} }
public TypeSpec GetCoClassAttributeValue () public TypeSpec GetCoClassAttributeValue ()
@ -829,7 +812,7 @@ namespace Mono.CSharp {
System.Security.Permissions.SecurityAction GetSecurityActionValue () System.Security.Permissions.SecurityAction GetSecurityActionValue ()
{ {
return (SecurityAction) ((Constant) pos_args[0].Expr).GetValue (); return (SecurityAction) ((Constant) PosArguments[0].Expr).GetValue ();
} }
/// <summary> /// <summary>
@ -839,9 +822,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[pos_args.Count]; object[] values = new object [PosArguments.Count];
for (int i = 0; i < values.Length; ++i) for (int i = 0; i < values.Length; ++i)
values[i] = ((Constant) pos_args[i].Expr).GetValue (); values [i] = ((Constant) PosArguments [i].Expr).GetValue ();
PropertyInfo[] prop; PropertyInfo[] prop;
object[] prop_values; object[] prop_values;
@ -882,7 +865,7 @@ namespace Mono.CSharp {
public CharSet GetCharSetValue () public CharSet GetCharSetValue ()
{ {
return (CharSet) System.Enum.Parse (typeof (CharSet), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); return (CharSet)System.Enum.Parse (typeof (CharSet), ((Constant) PosArguments [0].Expr).GetValue ().ToString ());
} }
public bool HasField (string fieldName) public bool HasField (string fieldName)
@ -904,8 +887,8 @@ namespace Mono.CSharp {
public bool IsInternalCall () public bool IsInternalCall ()
{ {
MethodImplOptions options = 0; MethodImplOptions options = 0;
if (pos_args.Count == 1) { if (PosArguments.Count == 1) {
options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); options = (MethodImplOptions) System.Enum.Parse (typeof (MethodImplOptions), ((Constant) PosArguments[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 ());
@ -919,19 +902,19 @@ namespace Mono.CSharp {
// //
public bool IsExplicitLayoutKind () public bool IsExplicitLayoutKind ()
{ {
if (pos_args == null || pos_args.Count != 1) if (PosArguments == null || PosArguments.Count != 1)
return false; return false;
var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); var value = (LayoutKind) System.Enum.Parse (typeof (LayoutKind), ((Constant) PosArguments[0].Expr).GetValue ().ToString ());
return value == LayoutKind.Explicit; return value == LayoutKind.Explicit;
} }
public Expression GetParameterDefaultValue () public Expression GetParameterDefaultValue ()
{ {
if (pos_args == null) if (PosArguments == null)
return null; return null;
return pos_args[0].Expr; return PosArguments[0].Expr;
} }
public override bool Equals (object obj) public override bool Equals (object obj)
@ -968,16 +951,16 @@ namespace Mono.CSharp {
} }
byte[] cdata; byte[] cdata;
if (pos_args == null && named_values == null) { if (PosArguments == null && named_values == null) {
cdata = AttributeEncoder.Empty; cdata = AttributeEncoder.Empty;
} else { } else {
AttributeEncoder encoder = new AttributeEncoder (); AttributeEncoder encoder = new AttributeEncoder ();
if (pos_args != null) { if (PosArguments != null) {
var param_types = ctor.Parameters.Types; var param_types = ctor.Parameters.Types;
for (int j = 0; j < pos_args.Count; ++j) { for (int j = 0; j < PosArguments.Count; ++j) {
var pt = param_types[j]; var pt = param_types[j];
var arg_expr = pos_args[j].Expr; var arg_expr = PosArguments[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;
@ -1001,15 +984,15 @@ namespace Mono.CSharp {
"System.AttributeUsage"); "System.AttributeUsage");
} }
} else if (Type == predefined.MarshalAs) { } else if (Type == predefined.MarshalAs) {
if (pos_args.Count == 1) { if (PosArguments.Count == 1) {
var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) pos_args[0].Expr).GetValue ().ToString ()); var u_type = (UnmanagedType) System.Enum.Parse (typeof (UnmanagedType), ((Constant) PosArguments[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 (pos_args.Count == 1 && pos_args[0].Expr is Constant) { if (PosArguments.Count == 1 && PosArguments[0].Expr is Constant) {
var value = ((Constant) pos_args[0].Expr).GetValue () as string; var value = ((Constant) PosArguments[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");
} }
@ -1072,8 +1055,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 (pos_args != null) if (PosArguments != null)
pos_args.CheckArrayAsAttribute (context.Module.Compiler); PosArguments.CheckArrayAsAttribute (context.Module.Compiler);
if (NamedArguments == null) if (NamedArguments == null)
return; return;
@ -1084,10 +1067,10 @@ namespace Mono.CSharp {
private Expression GetValue () private Expression GetValue ()
{ {
if (pos_args == null || pos_args.Count < 1) if (PosArguments == null || PosArguments.Count < 1)
return null; return null;
return pos_args[0].Expr; return PosArguments [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;
FullNamedExpression base_type_expr; // TODO: It's temporary variable protected 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,12 +256,6 @@ 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) {
@ -338,7 +332,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);
@ -1372,13 +1366,9 @@ namespace Mono.CSharp
type_defined = true; type_defined = true;
// Nested type share same namespace // TODO: Driver resolves only first level of namespace, do the rest here for now
if (IsTopLevel && !IsCompilerGenerated) { if (IsTopLevel && (ModFlags & Modifiers.COMPILER_GENERATED) == 0) {
NamespaceEntry.Define (); NamespaceEntry.Resolve ();
if (partial_parts != null) {
foreach (var part in partial_parts)
part.NamespaceEntry.Define ();
}
} }
if (!DefineBaseTypes ()) { if (!DefineBaseTypes ()) {

9902
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,26 +428,19 @@ 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 {
if (lang_version == LanguageVersion.ISO_1) lt = (Tokenizer.LocatedToken) $3;
FeatureIsNotAvailable (lt.Location, "external alias"); current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, report);
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
{ {
Error_SyntaxError (yyToken); syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
} }
; ;
@ -457,22 +450,20 @@ using_directives
; ;
using_directive using_directive
: using_namespace : using_alias_directive
{ {
if (doc_support) if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed; Lexer.doc_state = XmlCommentState.Allowed;
} }
; | using_namespace_directive
using_namespace
: USING namespace_name SEMICOLON
{ {
var un = new UsingNamespace ((MemberName) $2, GetLocation ($1)); if (doc_support)
current_namespace.AddUsing (un); Lexer.doc_state = XmlCommentState.Allowed;
lbag.AddLocation (un, GetLocation ($3));
} }
| USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON ;
using_alias_directive
: 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") {
@ -480,16 +471,22 @@ using_namespace
"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");
} }
var un = new UsingAliasNamespace (new MemberName (lt.Value, lt.Location), (MemberName) $4, GetLocation ($1)); current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
current_namespace.AddUsing (un); ubag.AddUsingAlias (GetLocation ($1), lt, GetLocation ($3), (MemberName) $4, GetLocation ($5));
}
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));
}
; ;
// //
@ -5106,7 +5103,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 StatementErrorExpression ($1 as Expression); $$ = new InvalidStatementExpression ($1 as Expression);
} else { } else {
$$ = new StatementExpression (s); $$ = new StatementExpression (s);
} }
@ -5155,10 +5152,9 @@ 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);
Error_SyntaxError (yyToken); report.Error (1026, eloc, "Expected a ')'");
$$ = new If ((BooleanExpression) $3, null, GetLocation ($1)); $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2)); lbag.AddStatement ($$, GetLocation ($2));
} }
@ -5175,13 +5171,6 @@ 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
@ -5210,7 +5199,7 @@ switch_sections
} }
| error | error
{ {
Error_SyntaxError (yyToken); Error_SyntaxError (yyToken);
$$ = new List<SwitchSection> (); $$ = new List<SwitchSection> ();
} }
; ;
@ -5271,30 +5260,24 @@ 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 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON : DO embedded_statement
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
{ {
Error_SyntaxError (yyToken); var loc = GetLocation ($1);
$$ = new Do ((Statement) $2, null, GetLocation ($1)); report.Error (-100, loc, "Expected `while'");
$$ = new Do ((Statement) $2, null, loc);
} }
| DO embedded_statement WHILE open_parens_any boolean_expression error | DO embedded_statement
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));
} }
@ -5400,35 +5383,10 @@ statement_expression_list
; ;
foreach_statement foreach_statement
: FOREACH open_parens_any type error : FOREACH open_parens_any type IN expression CLOSE_PARENS
{ {
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
{ {
@ -5586,9 +5544,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
{ {
Error_SyntaxError (1524, yyToken); report.Error (1524, GetLocation ($1), "Expected catch or finally");
$$ = new TryCatch ((Block) $2, null, GetLocation ($1), false); $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
} }
; ;
@ -5606,11 +5564,15 @@ catch_clauses
var l = (List<Catch>) $1; var l = (List<Catch>) $1;
Catch c = (Catch) $2; Catch c = (Catch) $2;
if (l [l.Count - 1].IsGeneral) { if (l [0].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;
} }
; ;
@ -5690,13 +5652,6 @@ 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
@ -5758,15 +5713,9 @@ 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));
$$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1)); Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4)); lbag.AddStatement (u, 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));
} }
; ;
@ -6010,7 +5959,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;
@ -6798,12 +6747,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 (loc); current_anonymous_method = new LambdaExpression (isAsync, 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 (loc); current_anonymous_method = new AnonymousMethodExpression (isAsync, loc);
} }
async_block = isAsync; async_block = isAsync;
@ -6835,12 +6784,7 @@ AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
void Error_SyntaxError (int token) void Error_SyntaxError (int token)
{ {
Error_SyntaxError (0, token); Error_SyntaxError (0, token, "Unexpected symbol");
}
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,6 +47,7 @@ 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 {
@ -123,12 +124,6 @@ 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,13 +81,6 @@ 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.Define (); source_file.NamespaceContainer.Resolve ();
} }
tr.Stop (TimeReporter.TimerType.UsingResolve); tr.Stop (TimeReporter.TimerType.UsingResolve);

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

@ -4418,10 +4418,7 @@ 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 = q as ArrayContainer; var ac_q = ((ArrayContainer) q);
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,7 +373,6 @@ 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);
@ -769,17 +768,12 @@ namespace Mono.CSharp
return sb.ToString (); return sb.ToString ();
} }
internal List<string> GetUsingList () internal ICollection<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)
if (ue.Alias != null) res.Add (ue.Name);
continue;
res.Add (ue.NamespaceName.Name);
}
return res; return res;
} }
@ -820,7 +814,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, false); var assembly = loader.LoadAssemblyFile (file);
if (assembly == null) if (assembly == null)
return; return;

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

@ -801,17 +801,17 @@ namespace Mono.CSharp
LocalTemporary temporary; LocalTemporary temporary;
bool prepared; bool prepared;
public Indirection (Expression expr, Location l)
{
this.expr = expr;
loc = l;
}
public Expression Expr { public Expression Expr {
get { get {
return expr; return expr;
} }
} }
public Indirection (Expression expr, Location l)
{
this.expr = expr;
loc = l;
}
public bool IsFixed { public bool IsFixed {
get { return true; } get { return true; }
@ -1017,13 +1017,6 @@ 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;
@ -1036,6 +1029,13 @@ 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,7 +1283,6 @@ 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);
@ -1372,10 +1371,6 @@ 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,
@ -1550,6 +1545,10 @@ 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);
@ -1567,10 +1566,6 @@ 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,
@ -1649,10 +1644,14 @@ 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);
} }
} }
// //
@ -1754,6 +1753,13 @@ 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)
{ {
@ -1761,12 +1767,6 @@ 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,15 +2225,11 @@ namespace Mono.CSharp
} }
public Expression Left { public Expression Left {
get { get { return this.left; }
return this.left;
}
} }
public Expression Right { public Expression Right {
get { get { return this.right; }
return this.right;
}
} }
#endregion #endregion
@ -5239,7 +5235,7 @@ namespace Mono.CSharp
} }
} }
public Expression Exp { public Expression Expression {
get { get {
return expr; return expr;
} }
@ -5494,7 +5490,6 @@ 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);
@ -5546,12 +5541,6 @@ namespace Mono.CSharp
} }
} }
public Expression TypeExpression {
get {
return RequestedType;
}
}
#endregion #endregion
/// <summary> /// <summary>
@ -5944,12 +5933,6 @@ 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];
@ -5964,6 +5947,12 @@ 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)
@ -6055,16 +6044,24 @@ 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)
{ {
@ -6102,24 +6099,6 @@ 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) {
@ -6200,7 +6179,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);
@ -6305,7 +6284,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;
@ -7145,8 +7124,8 @@ namespace Mono.CSharp
/// </summary> /// </summary>
public class Arglist : Expression public class Arglist : Expression
{ {
Arguments arguments; public Arguments Arguments { get; private set; }
public Arglist (Location loc) public Arglist (Location loc)
: this (null, loc) : this (null, loc)
{ {
@ -7154,24 +7133,18 @@ 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;
} }
@ -7192,9 +7165,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;
@ -7202,18 +7175,17 @@ 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);
@ -7235,12 +7207,6 @@ 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;
@ -7631,12 +7597,12 @@ namespace Mono.CSharp
/// Implements the sizeof expression /// Implements the sizeof expression
/// </summary> /// </summary>
public class SizeOf : Expression { public class SizeOf : Expression {
readonly Expression texpr; public readonly Expression QueriedType;
TypeSpec type_queried; TypeSpec type_queried;
public SizeOf (Expression queried_type, Location l) public SizeOf (Expression queried_type, Location l)
{ {
this.texpr = queried_type; this.QueriedType = queried_type;
loc = l; loc = l;
} }
@ -7646,12 +7612,6 @@ namespace Mono.CSharp
} }
} }
public Expression TypeExpression {
get {
return texpr;
}
}
public override bool ContainsEmitWithAwait () public override bool ContainsEmitWithAwait ()
{ {
return false; return false;
@ -7665,7 +7625,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
type_queried = texpr.ResolveAsType (ec); type_queried = QueriedType.ResolveAsType (ec);
if (type_queried == null) if (type_queried == null)
return null; return null;
@ -7733,12 +7693,6 @@ 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) {
@ -7753,8 +7707,19 @@ 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;
} }
return base.ResolveAsTypeOrNamespace (ec); FullNamedExpression fne = 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)
@ -7762,6 +7727,13 @@ 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;
@ -7774,14 +7746,6 @@ 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);
} }
@ -8141,14 +8105,6 @@ 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);
@ -8309,7 +8265,6 @@ 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);
@ -8374,7 +8329,6 @@ 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);
@ -9585,7 +9539,15 @@ 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;
@ -9593,18 +9555,6 @@ 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;
@ -10083,18 +10033,18 @@ namespace Mono.CSharp
CollectionOrObjectInitializers initializers; CollectionOrObjectInitializers initializers;
IMemoryLocation instance; IMemoryLocation instance;
public NewInitialize (FullNamedExpression requested_type, Arguments arguments, CollectionOrObjectInitializers initializers, Location l)
: base (requested_type, arguments, l)
{
this.initializers = initializers;
}
public CollectionOrObjectInitializers Initializers { public CollectionOrObjectInitializers Initializers {
get { get {
return initializers; return initializers;
} }
} }
public NewInitialize (FullNamedExpression requested_type, Arguments arguments, CollectionOrObjectInitializers initializers, Location l)
: base (requested_type, arguments, l)
{
this.initializers = 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);
@ -10205,6 +10155,10 @@ 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)
{ {
@ -10212,12 +10166,6 @@ 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,12 +94,6 @@ 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;
@ -391,12 +385,6 @@ namespace Mono.CSharp {
} }
} }
public Constraints Constraints {
get {
return constraints;
}
}
public IAssemblyDefinition DeclaringAssembly { public IAssemblyDefinition DeclaringAssembly {
get { get {
return Module.DeclaringAssembly; return Module.DeclaringAssembly;
@ -452,6 +440,12 @@ namespace Mono.CSharp {
} }
} }
public Constraints Constraints {
get {
return this.constraints;
}
}
#endregion #endregion
// //
@ -1917,12 +1911,6 @@ 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,8 +24,13 @@ 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)
: base (loc) : this (false, loc)
{ {
} }

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

@ -287,12 +287,6 @@ 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)
@ -482,12 +476,6 @@ 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);
@ -531,13 +519,6 @@ 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;
@ -549,6 +530,13 @@ 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,13 +95,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -116,13 +111,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -153,13 +143,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -174,13 +159,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -195,13 +175,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -216,13 +191,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -237,13 +207,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -280,13 +245,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -301,13 +261,8 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.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
@ -322,12 +277,7 @@ namespace Mono.CSharp
} }
#if FULL_AST #if FULL_AST
public char[] ParsedValue { get; set; } char[] ILiteralConstant.ParsedValue { get; set; }
#endif #endif
public override object Accept (StructuralVisitor visitor)
{
return visitor.Visit (this);
}
} }
} }

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

@ -899,11 +899,6 @@ 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)
{ {
@ -1180,6 +1175,11 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
// //
// Creates the type // Creates the type
// //
@ -1569,11 +1569,6 @@ 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 ()) {
@ -1619,6 +1614,11 @@ namespace Mono.CSharp {
return true; return true;
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
// //
// Creates the ConstructorBuilder // Creates the ConstructorBuilder
// //
@ -2155,11 +2155,6 @@ 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) {
@ -2169,6 +2164,10 @@ 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 ()
{ {
@ -2515,11 +2514,6 @@ 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) {
@ -2530,6 +2524,11 @@ 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,11 +35,6 @@ 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)
@ -583,9 +578,6 @@ 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;
@ -596,18 +588,20 @@ namespace Mono.CSharp {
NamespaceContainer implicit_parent; NamespaceContainer implicit_parent;
int symfile_id; int symfile_id;
List<UsingNamespace> clauses; // Namespace using import block
List<NamespaceUsingAlias> using_aliases;
// Used by parsed to check for parser errors List<NamespaceUsing> using_clauses;
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)
{ {
@ -650,30 +644,89 @@ namespace Mono.CSharp {
} }
} }
public NamespaceContainer Parent {
get {
return parent;
}
}
public CompilationSourceFile SourceFile { public CompilationSourceFile SourceFile {
get { get {
return file; return file;
} }
} }
public List<UsingNamespace> Usings { public List<NamespaceUsing> Usings {
get { get {
return clauses; return using_clauses;
} }
} }
#endregion #endregion
//
// 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 {
if (!IsImplicit && doppelganger == null) {
doppelganger = new NamespaceContainer (module, ImplicitParent, file, ns, true);
doppelganger.using_aliases = using_aliases;
}
return doppelganger;
}
}
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)
@ -687,47 +740,78 @@ namespace Mono.CSharp {
} }
} }
public void AddUsing (UsingNamespace un) /// <summary>
/// Records a new namespace for resolving name references
/// </summary>
public void AddUsing (MemberName name, Location loc)
{ {
if (DeclarationFound){ if (DeclarationFound){
Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations"); Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
} }
if (clauses == null) if (using_clauses == null) {
clauses = new List<UsingNamespace> (); using_clauses = new List<NamespaceUsing> ();
} else {
clauses.Add (un); 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;
}
}
}
resolved = false; using_clauses.Add (new NamespaceUsing (name));
} }
public void AddUsing (UsingAliasNamespace un) public void AddUsingAlias (string alias, MemberName name, Location loc)
{ {
if (DeclarationFound){ if (DeclarationFound){
Compiler.Report.Error (1529, un.Location, "A using clause must precede all other namespace elements except extern alias declarations"); Compiler.Report.Error (1529, loc, "A using clause must precede all other namespace elements except extern alias declarations");
} }
AddAlias (un); AddUsingAlias (new LocalUsingAliasEntry (alias, name, loc));
} }
void AddAlias (UsingAliasNamespace un) public void AddUsingExternalAlias (string alias, Location loc, Report Report)
{ {
if (clauses == null) { bool not_first = using_clauses != null || DeclarationFound;
clauses = new List<UsingNamespace> (); if (using_aliases != null && !not_first) {
} else { foreach (NamespaceUsingAlias uae in using_aliases) {
foreach (var entry in clauses) { if (uae is LocalUsingAliasEntry) {
var a = entry as UsingAliasNamespace; not_first = true;
if (a != null && a.Alias.Equals (un.Alias)) { break;
Compiler.Report.SymbolRelatedToPreviousError (a.Location, "");
Compiler.Report.Error (1537, un.Location,
"The using alias `{0}' appeared previously in this namespace", un.Alias.GetSignatureForError ());
} }
} }
} }
clauses.Add (un); 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));
}
void AddUsingAlias (NamespaceUsingAlias uae)
{
if (using_aliases == null) {
using_aliases = new List<NamespaceUsingAlias> ();
} else {
foreach (NamespaceUsingAlias entry in using_aliases) {
if (uae.Alias == entry.Alias) {
Compiler.Report.SymbolRelatedToPreviousError (uae.Location, uae.Alias);
Compiler.Report.Error (1537, entry.Location, "The using alias `{0}' appeared previously in this namespace",
entry.Alias);
return;
}
}
}
resolved = false; using_aliases.Add (uae);
} }
// //
@ -737,7 +821,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 namespace_using_table) { foreach (Namespace n in GetUsingTable ()) {
var a = n.LookupExtensionMethod (this, extensionType, name, arity); var a = n.LookupExtensionMethod (this, extensionType, name, arity);
if (a == null) if (a == null)
continue; continue;
@ -782,7 +866,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 namespace_using_table){ foreach (Namespace using_ns in GetUsingTable ()){
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){
@ -797,35 +881,18 @@ 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.aliases == null) if (n.using_aliases == null)
continue; continue;
UsingAliasNamespace uan; foreach (NamespaceUsingAlias ue in n.using_aliases) {
if (n.aliases.TryGetValue (name, out uan)) if (ue.Alias == name)
return uan.ResolvedExpression; return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
}
} }
return null; return null;
@ -841,19 +908,26 @@ namespace Mono.CSharp {
// //
// Check aliases. // Check aliases.
// //
if (aliases != null && arity == 0) { if (using_aliases != null && arity == 0) {
UsingAliasNamespace uan; foreach (NamespaceUsingAlias ue in using_aliases) {
if (aliases.TryGetValue (name, out uan)) { if (ue.Alias == name) {
if (fne != null) { if (fne != null) {
// TODO: Namespace has broken location if (Doppelganger != null) {
//Report.SymbolRelatedToPreviousError (fne.Location, null); if (mode == LookupMode.Normal) {
Compiler.Report.SymbolRelatedToPreviousError (uan.Location, null); // TODO: Namespace has broken location
Compiler.Report.Error (576, loc, //Report.SymbolRelatedToPreviousError (fne.Location, null);
"Namespace `{0}' contains a definition with same name as alias `{1}'", Compiler.Report.SymbolRelatedToPreviousError (ue.Location, null);
GetSignatureForError (), name); Compiler.Report.Error (576, loc,
} "Namespace `{0}' contains a definition with same name as alias `{1}'",
GetSignatureForError (), name);
}
} else {
return fne;
}
}
return uan.ResolvedExpression; return ue.Resolve (Doppelganger ?? this, Doppelganger == null);
}
} }
} }
@ -867,11 +941,9 @@ namespace Mono.CSharp {
// Check using entries. // Check using entries.
// //
FullNamedExpression match = null; FullNamedExpression match = null;
foreach (Namespace using_ns in namespace_using_table) { foreach (Namespace using_ns in GetUsingTable ()) {
//
// 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;
@ -911,20 +983,41 @@ 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 (clauses != null) { if (using_clauses != null) {
// TODO: Why is it needed, what to do with aliases using_list = new string [using_clauses.Count];
var ul = new List<string> (); for (int i = 0; i < using_clauses.Count; i++)
foreach (var c in clauses) { using_list [i] = ((NamespaceUsing) using_clauses [i]).MemberName.GetName ();
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);
@ -943,6 +1036,11 @@ 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?",
@ -971,76 +1069,29 @@ namespace Mono.CSharp {
} }
} }
public void Define () /// <summary>
/// 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 (clauses != null) { if (using_aliases != null) {
var list = new List<Namespace> (clauses.Count); foreach (NamespaceUsingAlias ue in using_aliases)
bool post_process_using_aliases = false; ue.Resolve (Doppelganger, Doppelganger == null);
}
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;
}
continue;
}
entry.Define (this);
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--); if (using_clauses != null) {
} foreach (NamespaceUsing ue in using_clauses)
} ue.Resolve (Doppelganger);
}
} }
if (parent != null)
parent.Resolve ();
} }
public string GetSignatureForError () public string GetSignatureForError ()
@ -1067,7 +1118,7 @@ namespace Mono.CSharp {
} }
public bool IsObsolete { public bool IsObsolete {
get { return false; } get { return SlaveDeclSpace.IsObsolete; }
} }
public bool IsUnsafe { public bool IsUnsafe {
@ -1085,199 +1136,106 @@ namespace Mono.CSharp {
#endregion #endregion
} }
public class UsingNamespace public class NamespaceUsing
{ {
readonly MemberName name; readonly MemberName name;
readonly Location loc; Namespace resolved;
protected FullNamedExpression resolved;
public UsingNamespace (MemberName name, Location loc) public NamespaceUsing (MemberName name)
{ {
this.name = name; this.name = name;
this.loc = loc;
} }
#region Properties public string GetSignatureForError ()
{
public virtual MemberName Alias { return name.GetSignatureForError ();
get {
return null;
}
}
public Location Location {
get {
return loc;
}
} }
public MemberName NamespaceName { public Location Location
get { {
return name; get { return name.Location; }
}
} }
public FullNamedExpression ResolvedExpression { public MemberName MemberName
get { {
return resolved; get { return name; }
}
} }
#endregion public string Name
public string GetSignatureForError ()
{ {
return name.GetSignatureForError (); get { return GetSignatureForError (); }
} }
public virtual void Define (NamespaceContainer ctx) public Namespace Resolve (IMemberContext rc)
{ {
resolved = name.GetTypeExpression ().ResolveAsTypeOrNamespace (ctx); if (resolved != null)
var ns = resolved as Namespace; return resolved;
if (ns == null) {
if (resolved != null) { FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (resolved.Type); if (fne == null)
ctx.Module.Compiler.Report.Error (138, Location, return null;
"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
GetSignatureForError ()); resolved = fne as Namespace;
} if (resolved == null) {
rc.Module.Compiler.Report.SymbolRelatedToPreviousError (fne.Type);
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 ());
} }
return resolved;
} }
} }
public class UsingExternAlias : UsingAliasNamespace public class NamespaceUsingAlias
{ {
public UsingExternAlias (MemberName alias, Location loc) public readonly string Alias;
: base (alias, null, loc) public Location Location;
public NamespaceUsingAlias (string alias, Location loc)
{ {
this.Alias = alias;
this.Location = loc;
} }
public override void Define (NamespaceContainer ctx) public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
{ {
resolved = ctx.Module.GetRootNamespace (Alias.Name); FullNamedExpression fne = rc.Module.GetRootNamespace (Alias);
if (resolved == null) { if (fne == null) {
ctx.Module.Compiler.Report.Error (430, Location, rc.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.Name); Alias);
} }
return fne;
} }
} }
public class UsingAliasNamespace : UsingNamespace class LocalUsingAliasEntry : NamespaceUsingAlias
{ {
readonly MemberName alias; FullNamedExpression resolved;
MemberName value;
struct AliasContext : IMemberContext public LocalUsingAliasEntry (string alias, MemberName name, Location loc)
: base (alias, loc)
{ {
readonly NamespaceContainer ns; this.value = name;
}
public AliasContext (NamespaceContainer ns)
{
this.ns = ns;
}
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 () public override FullNamedExpression Resolve (IMemberContext rc, bool local)
{ {
throw new NotImplementedException (); if (resolved != null || value == null)
} return resolved;
public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity) if (local)
{
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;
} }
public FullNamedExpression LookupNamespaceAlias (string name) return resolved;
{
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,24 +1001,20 @@ 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,7 +234,10 @@ 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;
@ -248,12 +251,6 @@ 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;
@ -282,12 +279,6 @@ namespace Mono.CSharp {
} }
} }
public Modifier ParameterModifier {
get {
return modFlags;
}
}
public TypeSpec Type { public TypeSpec Type {
get { get {
return parameter_type; return parameter_type;
@ -1221,7 +1212,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 (e.g. indexer parameters). // default parameter values of folded constants when for 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,12 +733,6 @@ namespace Mono.CSharp
{ {
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
void CreateAutomaticProperty () void CreateAutomaticProperty ()
{ {
// Create backing field // Create backing field
@ -763,6 +757,11 @@ 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 ())
@ -858,11 +857,6 @@ 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 ())
@ -877,6 +871,12 @@ namespace Mono.CSharp
return attribute_targets; return attribute_targets;
} }
} }
public override void Accept (StructuralVisitor visitor)
{
visitor.Visit (this);
}
} }
/// <summary> /// <summary>
@ -999,12 +999,6 @@ 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;
@ -1026,14 +1020,14 @@ namespace Mono.CSharp
} }
} }
#endregion public List<FieldDeclarator> Declarators {
get {
return this.declarators;
public override void Accept (StructuralVisitor visitor) }
{
visitor.Visit (this);
} }
#endregion
public void AddDeclarator (FieldDeclarator declarator) public void AddDeclarator (FieldDeclarator declarator)
{ {
if (declarators == null) if (declarators == null)
@ -1111,6 +1105,11 @@ 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
@ -1514,12 +1513,6 @@ 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) {
@ -1541,6 +1534,11 @@ 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,7 +442,12 @@ namespace Mono.CSharp
return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null; return assembly.GetType (compiler.BuiltinTypes.Object.FullName) != null;
} }
public override Assembly LoadAssemblyFile (string assembly, bool isImplicitReference) public override Assembly LoadAssemblyFile (string fileName)
{
return LoadAssemblyFile (fileName, false);
}
Assembly LoadAssemblyFile (string assembly, bool soft)
{ {
Assembly a = null; Assembly a = null;
@ -459,7 +464,7 @@ namespace Mono.CSharp
a = Assembly.Load (ass); a = Assembly.Load (ass);
} }
} catch (FileNotFoundException) { } catch (FileNotFoundException) {
bool err = !isImplicitReference; bool err = !soft;
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"))
@ -485,6 +490,11 @@ 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) {
RootNamespace.Error_GlobalNamespaceRedefined (Report, Location.Null); NamespaceContainer.Error_GlobalNamespaceRedefined (Location.Null, Report);
return global_ns; return global_ns;
} }

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

@ -154,11 +154,9 @@ namespace Mono.CSharp {
FalseStatement = false_statement; FalseStatement = false_statement;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { get { return this.expr; }
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
@ -641,11 +639,9 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
loc = expr.Location; loc = expr.Location;
} }
public ExpressionStatement Expr { public ExpressionStatement Expr {
get { get { return this.expr; }
return this.expr;
}
} }
protected override void CloneTo (CloneContext clonectx, Statement t) protected override void CloneTo (CloneContext clonectx, Statement t)
@ -680,7 +676,7 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
} }
public Expression Expr { public Expression Expression {
get { get {
return expr; return expr;
} }
@ -783,30 +779,25 @@ namespace Mono.CSharp {
/// </summary> /// </summary>
public class Return : ExitStatement public class Return : ExitStatement
{ {
Expression expr; public Expression Expr { get; protected set; }
public Return (Expression expr, Location l) public Return (Expression expr, Location l)
{ {
this.expr = expr; 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;
@ -820,7 +811,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;
} }
} }
@ -836,7 +827,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;
@ -854,12 +845,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;
} }
@ -880,20 +871,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",
@ -908,8 +899,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) {
@ -945,10 +936,9 @@ 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);
@ -1145,11 +1135,9 @@ namespace Mono.CSharp {
expr = e; expr = e;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { get { return this.expr; }
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
@ -1219,13 +1207,11 @@ namespace Mono.CSharp {
this.expr = expr; this.expr = expr;
loc = l; loc = l;
} }
public Expression Expr { public Expression Expr {
get { get { return this.expr; }
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
if (expr == null) { if (expr == null) {
@ -1886,7 +1872,6 @@ 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");
} }
@ -2003,7 +1988,7 @@ namespace Mono.CSharp {
int? resolving_init_idx; int? resolving_init_idx;
Block original; protected Block original;
#if DEBUG #if DEBUG
static int id; static int id;
@ -2050,9 +2035,6 @@ namespace Mono.CSharp {
get { get {
return original; return original;
} }
protected set {
original = value;
}
} }
public bool IsCompilerGenerated { public bool IsCompilerGenerated {
@ -2069,11 +2051,10 @@ 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 statements; } get { return this.statements; }
} }
#endregion #endregion
public Block CreateSwitchBlock (Location start) public Block CreateSwitchBlock (Location start)
@ -2347,7 +2328,6 @@ 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);
@ -2712,7 +2692,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
@ -2926,7 +2906,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);
@ -2941,7 +2921,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);
@ -4488,13 +4468,11 @@ namespace Mono.CSharp {
{ {
this.expr = expr; this.expr = expr;
} }
public Expression Expr { public Expression Expr {
get { get { return this.expr; }
return this.expr;
}
} }
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
expr = expr.Resolve (ec); expr = expr.Resolve (ec);
@ -5173,12 +5151,6 @@ 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;
@ -5230,20 +5202,23 @@ namespace Mono.CSharp {
public class TryCatch : ExceptionStatement public class TryCatch : ExceptionStatement
{ {
public Block Block; public Block Block;
List<Catch> clauses; public List<Catch> Specific;
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.clauses = catch_clauses; this.Specific = catch_clauses;
this.inside_try_finally = inside_try_finally; this.inside_try_finally = inside_try_finally;
}
if (catch_clauses != null) {
public List<Catch> Clauses { Catch c = catch_clauses [0];
get { if (c.IsGeneral) {
return clauses; this.General = c;
catch_clauses.RemoveAt (0);
}
} }
} }
@ -5262,8 +5237,9 @@ namespace Mono.CSharp {
if (!Block.Resolve (ec)) if (!Block.Resolve (ec))
ok = false; ok = false;
for (int i = 0; i < clauses.Count; ++i) { TypeSpec[] prev_catches = new TypeSpec [Specific.Count];
var c = clauses[i]; int last_index = 0;
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)) {
@ -5272,40 +5248,37 @@ namespace Mono.CSharp {
} }
TypeSpec resolved_type = c.CatchType; TypeSpec resolved_type = c.CatchType;
for (int ii = 0; ii < clauses.Count; ++ii) { for (int ii = 0; ii < last_index; ++ii) {
if (ii == i) if (resolved_type == prev_catches[ii] || TypeSpec.IsBaseClass (resolved_type, prev_catches[ii], true)) {
continue; ec.Report.Error (160, c.loc,
"A previous catch clause already catches all exceptions of this or a super type `{0}'",
if (clauses[ii].IsGeneral) { TypeManager.CSharpName (prev_catches [ii]));
if (resolved_type.BuiltinType != BuiltinTypeSpec.Type.Exception) ok = false;
continue; }
}
if (!ec.Module.DeclaringAssembly.WrapNonExceptionThrows)
continue;
if (!ec.Module.PredefinedAttributes.RuntimeCompatibility.IsDefined)
continue;
ec.Report.Warning (1058, 1, c.loc, prev_catches [last_index++] = resolved_type;
"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 (ii >= i) if (!ec.Module.DeclaringAssembly.WrapNonExceptionThrows)
continue; continue;
var ct = clauses[ii].CatchType; if (!ec.Module.PredefinedAttributes.RuntimeCompatibility.IsDefined)
if (ct == null)
continue; continue;
if (resolved_type == ct || TypeSpec.IsBaseClass (resolved_type, ct, true)) { ec.Report.Warning (1058, 1, c.loc,
ec.Report.Error (160, c.loc, "A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a `System.Runtime.CompilerServices.RuntimeWrappedException'");
"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 ();
@ -5320,9 +5293,12 @@ namespace Mono.CSharp {
Block.Emit (ec); Block.Emit (ec);
foreach (Catch c in clauses) foreach (Catch c in Specific)
c.Emit (ec); c.Emit (ec);
if (General != null)
General.Emit (ec);
if (!inside_try_finally) if (!inside_try_finally)
ec.EndExceptionBlock (); ec.EndExceptionBlock ();
} }
@ -5332,13 +5308,14 @@ namespace Mono.CSharp {
TryCatch target = (TryCatch) t; TryCatch target = (TryCatch) t;
target.Block = clonectx.LookupBlock (Block); target.Block = clonectx.LookupBlock (Block);
if (clauses != null){ if (General != null)
target.clauses = new List<Catch> (); target.General = (Catch) General.Clone (clonectx);
foreach (Catch c in clauses) if (Specific != null){
target.clauses.Add ((Catch) c.Clone (clonectx)); target.Specific = new List<Catch> ();
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);
@ -5491,7 +5468,7 @@ namespace Mono.CSharp {
declarators = null; declarators = null;
return stmt; return stmt;
} }
public override object Accept (StructuralVisitor visitor) public override object Accept (StructuralVisitor visitor)
{ {
@ -5515,7 +5492,7 @@ namespace Mono.CSharp {
#region Properties #region Properties
public Expression Expr { public Expression Expression {
get { get {
return decl.Variable == null ? decl.Initializer : null; return decl.Variable == null ? decl.Initializer : null;
} }
@ -5594,7 +5571,6 @@ 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);
@ -6138,6 +6114,14 @@ 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)
{ {
@ -6148,23 +6132,14 @@ 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 TypeExpression { public Expression Expr {
get { return type; } get { return this.expr; }
}
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,7 +107,6 @@ 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