Browse Source

Updated mcs, fixed failing unit test.

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
0722289a8d
  1. 2
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ConditionalExpressionTests.cs
  2. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/attribute.cs
  3. 20
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cfold.cs
  4. 19
      ICSharpCode.NRefactory/CSharp/Parser/mcs/class.cs
  5. 1
      ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-tokenizer.cs
  6. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/delegate.cs
  7. 8
      ICSharpCode.NRefactory/CSharp/Parser/mcs/doc.cs
  8. 5
      ICSharpCode.NRefactory/CSharp/Parser/mcs/dynamic.cs
  9. 184
      ICSharpCode.NRefactory/CSharp/Parser/mcs/ecore.cs
  10. 8
      ICSharpCode.NRefactory/CSharp/Parser/mcs/enum.cs
  11. 76
      ICSharpCode.NRefactory/CSharp/Parser/mcs/expression.cs
  12. 39
      ICSharpCode.NRefactory/CSharp/Parser/mcs/generic.cs
  13. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/import.cs
  14. 39
      ICSharpCode.NRefactory/CSharp/Parser/mcs/namespace.cs
  15. 12
      ICSharpCode.NRefactory/CSharp/Parser/mcs/nullable.cs
  16. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/parameter.cs
  17. 2
      ICSharpCode.NRefactory/CSharp/Parser/mcs/report.cs
  18. 69
      ICSharpCode.NRefactory/CSharp/Parser/mcs/statement.cs

2
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ConditionalExpressionTests.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression); Assert.IsTrue(ce.FalseExpression is MemberReferenceExpression);
} }
[Test, Ignore("crashes the parser")] [Test]
public void ConditionalIsWithNullableExpressionTest() public void ConditionalIsWithNullableExpressionTest()
{ {
ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b? ? a() : a.B"); ConditionalExpression ce = ParseUtilCSharp.ParseExpression<ConditionalExpression>("a is b? ? a() : a.B");

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

@ -247,7 +247,7 @@ namespace Mono.CSharp {
TypeSpec ResolvePossibleAttributeType (ATypeNameExpression expr) TypeSpec ResolvePossibleAttributeType (ATypeNameExpression expr)
{ {
TypeExpr te = expr.ResolveAsTypeTerminal (context, false); TypeExpr te = expr.ResolveAsType (context);
if (te == null) if (te == null)
return null; return null;

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

@ -467,7 +467,7 @@ namespace Mono.CSharp {
} }
if (left is NullLiteral && right is NullLiteral) { if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -563,7 +563,7 @@ namespace Mono.CSharp {
case Binary.Operator.Multiply: case Binary.Operator.Multiply:
if (left is NullLiteral && right is NullLiteral) { if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -658,7 +658,7 @@ namespace Mono.CSharp {
case Binary.Operator.Division: case Binary.Operator.Division:
if (left is NullLiteral && right is NullLiteral) { if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -757,7 +757,7 @@ namespace Mono.CSharp {
case Binary.Operator.Modulus: case Binary.Operator.Modulus:
if (left is NullLiteral && right is NullLiteral) { if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -846,7 +846,7 @@ namespace Mono.CSharp {
// //
case Binary.Operator.LeftShift: case Binary.Operator.LeftShift:
if (left is NullLiteral && right is NullLiteral) { if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -882,7 +882,7 @@ namespace Mono.CSharp {
// //
case Binary.Operator.RightShift: case Binary.Operator.RightShift:
if (left is NullLiteral && right is NullLiteral) { if (left is NullLiteral && right is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -1003,7 +1003,7 @@ namespace Mono.CSharp {
case Binary.Operator.LessThan: case Binary.Operator.LessThan:
if (right is NullLiteral) { if (right is NullLiteral) {
if (left is NullLiteral) { if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -1042,7 +1042,7 @@ namespace Mono.CSharp {
case Binary.Operator.GreaterThan: case Binary.Operator.GreaterThan:
if (right is NullLiteral) { if (right is NullLiteral) {
if (left is NullLiteral) { if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -1081,7 +1081,7 @@ namespace Mono.CSharp {
case Binary.Operator.GreaterThanOrEqual: case Binary.Operator.GreaterThanOrEqual:
if (right is NullLiteral) { if (right is NullLiteral) {
if (left is NullLiteral) { if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }
@ -1120,7 +1120,7 @@ namespace Mono.CSharp {
case Binary.Operator.LessThanOrEqual: case Binary.Operator.LessThanOrEqual:
if (right is NullLiteral) { if (right is NullLiteral) {
if (left is NullLiteral) { if (left is NullLiteral) {
var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsTypeTerminal (ec, false); var lifted_int = new Nullable.NullableType (ec.BuiltinTypes.Int, loc).ResolveAsType (ec);
return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec); return (Constant) new Nullable.LiftedBinaryOperator (oper, lifted_int, right, loc).Resolve (ec);
} }

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

@ -916,7 +916,7 @@ namespace Mono.CSharp
for (int i = 0, j = 0; i < count; i++){ for (int i = 0, j = 0; i < count; i++){
FullNamedExpression fne = type_bases [i]; FullNamedExpression fne = type_bases [i];
TypeExpr fne_resolved = fne.ResolveAsTypeTerminal (base_context, false); TypeExpr fne_resolved = fne.ResolveAsType (base_context);
if (fne_resolved == null) if (fne_resolved == null)
continue; continue;
@ -2033,7 +2033,7 @@ namespace Mono.CSharp
// Performs the validation on a Method's modifiers (properties have // Performs the validation on a Method's modifiers (properties have
// the same properties). // the same properties).
// //
// TODO: Why is it not done at parse stage ? // TODO: Why is it not done at parse stage, move to Modifiers::Check
// //
public bool MethodModifiersValid (MemberCore mc) public bool MethodModifiersValid (MemberCore mc)
{ {
@ -2194,7 +2194,6 @@ namespace Mono.CSharp
return e; return e;
e = null; e = null;
int errors = Report.Errors;
if (arity == 0) { if (arity == 0) {
TypeParameter[] tp = CurrentTypeParameters; TypeParameter[] tp = CurrentTypeParameters;
@ -2212,12 +2211,18 @@ namespace Mono.CSharp
e = new TypeExpression (t, Location.Null); e = new TypeExpression (t, Location.Null);
else if (Parent != null) { else if (Parent != null) {
e = Parent.LookupNamespaceOrType (name, arity, loc, ignore_cs0104); e = Parent.LookupNamespaceOrType (name, arity, loc, ignore_cs0104);
} else } else {
int errors = Report.Errors;
e = NamespaceEntry.LookupNamespaceOrType (name, arity, loc, ignore_cs0104); e = NamespaceEntry.LookupNamespaceOrType (name, arity, loc, ignore_cs0104);
if (errors != Report.Errors)
return e;
}
} }
// TODO MemberCache: How to cache arity stuff ? // TODO MemberCache: How to cache arity stuff ?
if (errors == Report.Errors && arity == 0) if (arity == 0)
Cache[name] = e; Cache[name] = e;
return e; return e;
@ -3244,7 +3249,7 @@ namespace Mono.CSharp
} }
if (IsExplicitImpl) { if (IsExplicitImpl) {
TypeExpr iface_texpr = MemberName.Left.GetTypeExpression ().ResolveAsTypeTerminal (Parent, false); TypeExpr iface_texpr = MemberName.Left.GetTypeExpression ().ResolveAsType (Parent);
if (iface_texpr == null) if (iface_texpr == null)
return false; return false;
@ -3573,7 +3578,7 @@ namespace Mono.CSharp
if (member_type != null) if (member_type != null)
throw new InternalErrorException ("Multi-resolve"); throw new InternalErrorException ("Multi-resolve");
TypeExpr te = type_expr.ResolveAsTypeTerminal (this, false); TypeExpr te = type_expr.ResolveAsType (this);
if (te == null) if (te == null)
return false; return false;

1
ICSharpCode.NRefactory/CSharp/Parser/mcs/cs-tokenizer.cs

@ -1179,6 +1179,7 @@ namespace Mono.CSharp
case Token.CLOSE_PARENS: case Token.CLOSE_PARENS:
case Token.OPEN_BRACKET: case Token.OPEN_BRACKET:
case Token.OP_GENERICS_GT: case Token.OP_GENERICS_GT:
case Token.INTERR:
next_token = Token.INTERR_NULLABLE; next_token = Token.INTERR_NULLABLE;
break; break;

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

@ -150,7 +150,7 @@ namespace Mono.CSharp {
} }
} }
ReturnType = ReturnType.ResolveAsTypeTerminal (this, false); ReturnType = ReturnType.ResolveAsType (this);
if (ReturnType == null) if (ReturnType == null)
return false; return false;

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

@ -237,7 +237,7 @@ namespace Mono.CSharp
var left = ResolveMemberName (context, mn.Left); var left = ResolveMemberName (context, mn.Left);
var ns = left as Namespace; var ns = left as Namespace;
if (ns != null) if (ns != null)
return ns.Lookup (context, mn.Name, mn.Arity, Location.Null); return ns.LookupTypeOrNamespace (context, mn.Name, mn.Arity, Location.Null);
TypeExpr texpr = left as TypeExpr; TypeExpr texpr = left as TypeExpr;
if (texpr != null) { if (texpr != null) {
@ -320,7 +320,7 @@ namespace Mono.CSharp
if (fne != null) { if (fne != null) {
var ns = fne as Namespace; var ns = fne as Namespace;
if (ns != null) { if (ns != null) {
fne = ns.Lookup (mc, ParsedName.Name, ParsedName.Arity, Location.Null); fne = ns.LookupTypeOrNamespace (mc, ParsedName.Name, ParsedName.Arity, Location.Null);
if (fne != null) { if (fne != null) {
member = fne.Type; member = fne.Type;
} }
@ -345,9 +345,11 @@ namespace Mono.CSharp
} }
if (ParsedParameters != null) { if (ParsedParameters != null) {
var old_printer = mc.Module.Compiler.Report.SetPrinter (new NullReportPrinter ());
foreach (var pp in ParsedParameters) { foreach (var pp in ParsedParameters) {
pp.Resolve (mc); pp.Resolve (mc);
} }
mc.Module.Compiler.Report.SetPrinter (old_printer);
} }
if (type != null) { if (type != null) {
@ -583,7 +585,7 @@ namespace Mono.CSharp
public void Resolve (IMemberContext context) public void Resolve (IMemberContext context)
{ {
Type = Type.ResolveAsTypeTerminal (context, true); Type = Type.ResolveAsType (context);
} }
} }
} }

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

@ -47,8 +47,9 @@ namespace Mono.CSharp
this.loc = loc; this.loc = loc;
} }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) public override TypeExpr ResolveAsType (IMemberContext ec)
{ {
eclass = ExprClass.Type;
type = ec.Module.Compiler.BuiltinTypes.Dynamic; type = ec.Module.Compiler.BuiltinTypes.Dynamic;
return this; return this;
} }
@ -463,7 +464,7 @@ namespace Mono.CSharp
BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void); BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void);
instanceAccessExprType = instanceAccessExprType.ResolveAsTypeStep (bc, false); instanceAccessExprType = instanceAccessExprType.ResolveAsType (bc);
if (instanceAccessExprType == null) if (instanceAccessExprType == null)
return; return;

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

@ -186,66 +186,16 @@ namespace Mono.CSharp {
// This is used if the expression should be resolved as a type or namespace name. // This is used if the expression should be resolved as a type or namespace name.
// the default implementation fails. // the default implementation fails.
// //
public virtual FullNamedExpression ResolveAsTypeStep (IMemberContext rc, bool silent) public virtual TypeExpr ResolveAsType (IMemberContext mc)
{ {
if (!silent) { ResolveContext ec = new ResolveContext (mc);
ResolveContext ec = new ResolveContext (rc); Expression e = Resolve (ec);
Expression e = Resolve (ec); if (e != null)
if (e != null) e.Error_UnexpectedKind (ec, ResolveFlags.Type, loc);
e.Error_UnexpectedKind (ec, ResolveFlags.Type, loc);
}
return null; return null;
} }
//
// This is used to resolve the expression as a type, a null
// value will be returned if the expression is not a type
// reference
//
public virtual TypeExpr ResolveAsTypeTerminal (IMemberContext ec , bool silent)
{
// FIXME: THIS IS TOO SLOW and it should not be needed either
int errors = ec.Module.Compiler.Report.Errors;
FullNamedExpression fne = ResolveAsTypeStep (ec, silent);
if (fne == null)
return null;
TypeExpr te = fne as TypeExpr;
if (te == null) {
if (!silent && errors == ec.Module.Compiler.Report.Errors)
fne.Error_UnexpectedKind (ec.Module.Compiler.Report, null, "type", loc);
return null;
}
if (!te.type.IsAccessible (ec)) {
ec.Module.Compiler.Report.SymbolRelatedToPreviousError (te.Type);
ErrorIsInaccesible (ec, te.Type.GetSignatureForError (), loc);
}
te.loc = loc;
var dep = te.type.GetMissingDependencies ();
if (dep != null) {
ImportedTypeDefinition.Error_MissingDependency (ec, dep, loc);
}
//
// Obsolete checks cannot be done when resolving base context as they
// require type dependecies to be set but we are just resolving them
//
if (!silent && !(ec is TypeContainer.BaseContext)) {
ObsoleteAttribute obsolete_attr = te.Type.GetAttributeObsolete ();
if (obsolete_attr != null && !ec.IsObsolete) {
AttributeTester.Report_ObsoleteMessage (obsolete_attr, te.GetSignatureForError (), Location, ec.Module.Compiler.Report);
}
}
return te;
}
public static void ErrorIsInaccesible (IMemberContext rc, string member, Location loc) public static void ErrorIsInaccesible (IMemberContext rc, string member, Location loc)
{ {
rc.Module.Compiler.Report.Error (122, loc, "`{0}' is inaccessible due to its protection level", member); rc.Module.Compiler.Report.Error (122, loc, "`{0}' is inaccessible due to its protection level", member);
@ -2125,29 +2075,6 @@ namespace Mono.CSharp {
return; return;
} }
} }
/*
// TODO MemberCache: Implement
string ns = ec.CurrentType.Namespace;
string fullname = (ns.Length > 0) ? ns + "." + Name : Name;
foreach (Assembly a in GlobalRootNamespace.Instance.Assemblies) {
var type = a.GetType (fullname);
if (type != null) {
ec.Compiler.Report.SymbolRelatedToPreviousError (type);
Expression.ErrorIsInaccesible (loc, TypeManager.CSharpName (type), ec.Compiler.Report);
return;
}
}
if (ec.CurrentTypeDefinition != null) {
TypeSpec t = ec.CurrentTypeDefinition.LookupAnyGeneric (Name);
if (t != null) {
Namespace.Error_InvalidNumberOfTypeArguments (ec.Compiler.Report, t, loc);
return;
}
}
*/
} }
FullNamedExpression retval = ec.LookupNamespaceOrType (Name, -System.Math.Max (1, Arity), loc, true); FullNamedExpression retval = ec.LookupNamespaceOrType (Name, -System.Math.Max (1, Arity), loc, true);
@ -2176,16 +2103,15 @@ namespace Mono.CSharp {
return SimpleNameResolve (ec, right_side, false); return SimpleNameResolve (ec, right_side, false);
} }
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent) public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec)
{ {
int errors = ec.Module.Compiler.Report.Errors;
FullNamedExpression fne = ec.LookupNamespaceOrType (Name, Arity, loc, /*ignore_cs0104=*/ false); FullNamedExpression fne = ec.LookupNamespaceOrType (Name, Arity, loc, /*ignore_cs0104=*/ false);
if (fne != null) { if (fne != null) {
if (fne.Type != null && Arity > 0) { if (fne.Type != null && Arity > 0) {
if (HasTypeArguments) { if (HasTypeArguments) {
GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc); GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
return ct.ResolveAsTypeStep (ec, false); return ct.ResolveAsType (ec);
} }
return new GenericOpenTypeExpr (fne.Type, loc); return new GenericOpenTypeExpr (fne.Type, loc);
@ -2205,19 +2131,21 @@ namespace Mono.CSharp {
ec.Module.PredefinedAttributes.Dynamic.GetSignatureForError ()); ec.Module.PredefinedAttributes.Dynamic.GetSignatureForError ());
} }
return new DynamicTypeExpr (loc).ResolveAsTypeStep (ec, silent); return new DynamicTypeExpr (loc).ResolveAsType (ec);
} }
if (fne != null) if (fne != null)
return fne; return fne;
if (silent || errors != ec.Module.Compiler.Report.Errors)
return null;
Error_TypeOrNamespaceNotFound (ec); Error_TypeOrNamespaceNotFound (ec);
return null; return null;
} }
public bool IsPossibleTypeOrNamespace (IMemberContext mc)
{
return mc.LookupNamespaceOrType (Name, Arity, loc, /*ignore_cs0104=*/ false) != null;
}
public override Expression LookupNameExpression (ResolveContext rc, MemberLookupRestrictions restrictions) public override Expression LookupNameExpression (ResolveContext rc, MemberLookupRestrictions restrictions)
{ {
int lookup_arity = Arity; int lookup_arity = Arity;
@ -2329,14 +2257,13 @@ namespace Mono.CSharp {
// Stage 3: Lookup nested types, namespaces and type parameters in the context // Stage 3: Lookup nested types, namespaces and type parameters in the context
// //
if ((restrictions & MemberLookupRestrictions.InvocableOnly) == 0 && !variable_found) { if ((restrictions & MemberLookupRestrictions.InvocableOnly) == 0 && !variable_found) {
e = ResolveAsTypeStep (rc, lookup_arity == 0 || !errorMode); if (IsPossibleTypeOrNamespace (rc)) {
if (e != null) {
if (variable != null) { if (variable != null) {
rc.Report.SymbolRelatedToPreviousError (variable.Location, Name); rc.Report.SymbolRelatedToPreviousError (variable.Location, Name);
rc.Report.Error (135, loc, "`{0}' conflicts with a declaration in a child block", Name); rc.Report.Error (135, loc, "`{0}' conflicts with a declaration in a child block", Name);
} }
return e; return ResolveAsTypeOrNamespace (rc);
} }
} }
@ -2370,7 +2297,12 @@ namespace Mono.CSharp {
} while (ct != null); } while (ct != null);
} }
rc.Report.Error (103, loc, "The name `{0}' does not exist in the current context", Name); var retval = rc.LookupNamespaceOrType (Name, -System.Math.Max (1, Arity), loc, true);
if (retval != null) {
Error_TypeArgumentsCannotBeUsed (rc, retval.Type, Arity, loc);
} else {
rc.Report.Error (103, loc, "The name `{0}' does not exist in the current context", Name);
}
} }
return null; return null;
@ -2433,11 +2365,53 @@ namespace Mono.CSharp {
throw new NotSupportedException ("ET"); throw new NotSupportedException ("ET");
} }
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent) public abstract FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc);
//
// This is used to resolve the expression as a type, a null
// value will be returned if the expression is not a type
// reference
//
public override TypeExpr ResolveAsType (IMemberContext mc)
{ {
return this; FullNamedExpression fne = ResolveAsTypeOrNamespace (mc);
if (fne == null)
return null;
TypeExpr te = fne as TypeExpr;
if (te == null) {
fne.Error_UnexpectedKind (mc.Module.Compiler.Report, null, "type", loc);
return null;
}
if (!te.type.IsAccessible (mc)) {
mc.Module.Compiler.Report.SymbolRelatedToPreviousError (te.Type);
ErrorIsInaccesible (mc, te.Type.GetSignatureForError (), loc);
}
te.loc = loc;
var dep = te.type.GetMissingDependencies ();
if (dep != null) {
ImportedTypeDefinition.Error_MissingDependency (mc, dep, loc);
}
//
// Obsolete checks cannot be done when resolving base context as they
// require type dependecies to be set but we are just resolving them
//
if (!(mc is TypeContainer.BaseContext)) {
ObsoleteAttribute obsolete_attr = te.Type.GetAttributeObsolete ();
if (obsolete_attr != null && !mc.IsObsolete) {
AttributeTester.Report_ObsoleteMessage (obsolete_attr, te.GetSignatureForError (), Location, mc.Module.Compiler.Report);
}
}
return te;
} }
public override void Emit (EmitContext ec) public override void Emit (EmitContext ec)
{ {
throw new InternalErrorException ("FullNamedExpression `{0}' found in resolved tree", throw new InternalErrorException ("FullNamedExpression `{0}' found in resolved tree",
@ -2448,24 +2422,18 @@ namespace Mono.CSharp {
/// <summary> /// <summary>
/// Expression that evaluates to a type /// Expression that evaluates to a type
/// </summary> /// </summary>
public abstract class TypeExpr : FullNamedExpression { public abstract class TypeExpr : FullNamedExpression
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent) {
public sealed override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc)
{ {
TypeExpr t = DoResolveAsTypeStep (ec); return ResolveAsType (mc);
if (t == null)
return null;
eclass = ExprClass.Type;
return t;
} }
protected override Expression DoResolve (ResolveContext ec) protected sealed override Expression DoResolve (ResolveContext ec)
{ {
return ResolveAsTypeTerminal (ec, false); return ResolveAsType (ec);
} }
protected abstract TypeExpr DoResolveAsTypeStep (IMemberContext ec);
public override bool Equals (object obj) public override bool Equals (object obj)
{ {
TypeExpr tobj = obj as TypeExpr; TypeExpr tobj = obj as TypeExpr;
@ -2484,7 +2452,8 @@ namespace Mono.CSharp {
/// <summary> /// <summary>
/// Fully resolved Expression that already evaluated to a type /// Fully resolved Expression that already evaluated to a type
/// </summary> /// </summary>
public class TypeExpression : TypeExpr { public class TypeExpression : TypeExpr
{
public TypeExpression (TypeSpec t, Location l) public TypeExpression (TypeSpec t, Location l)
{ {
Type = t; Type = t;
@ -2492,12 +2461,7 @@ namespace Mono.CSharp {
loc = l; loc = l;
} }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) public sealed override TypeExpr ResolveAsType (IMemberContext ec)
{
return this;
}
public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{ {
return this; return this;
} }

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

@ -27,16 +27,12 @@ namespace Mono.CSharp {
{ {
class EnumTypeExpr : TypeExpr class EnumTypeExpr : TypeExpr
{ {
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) public override TypeExpr ResolveAsType (IMemberContext ec)
{ {
type = ec.CurrentType; type = ec.CurrentType;
eclass = ExprClass.Type;
return this; return this;
} }
public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{
return DoResolveAsTypeStep (ec);
}
} }
public EnumMember (Enum parent, MemberName name, Attributes attrs) public EnumMember (Enum parent, MemberName name, Attributes attrs)

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

@ -1297,7 +1297,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
probe_type_expr = ProbeType.ResolveAsTypeTerminal (ec, false); probe_type_expr = ProbeType.ResolveAsType (ec);
if (probe_type_expr == null) if (probe_type_expr == null)
return null; return null;
@ -1632,7 +1632,7 @@ namespace Mono.CSharp
if (expr == null) if (expr == null)
return null; return null;
TypeExpr target = target_type.ResolveAsTypeTerminal (ec, false); TypeExpr target = target_type.ResolveAsType (ec);
if (target == null) if (target == null)
return null; return null;
@ -1734,7 +1734,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
TypeExpr texpr = expr.ResolveAsTypeTerminal (ec, false); TypeExpr texpr = expr.ResolveAsType (ec);
if (texpr == null) if (texpr == null)
return null; return null;
@ -3616,11 +3616,6 @@ namespace Mono.CSharp
return combined; return combined;
} }
public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{
return null;
}
void CheckOutOfRangeComparison (ResolveContext ec, Constant c, TypeSpec type) void CheckOutOfRangeComparison (ResolveContext ec, Constant c, TypeSpec type)
{ {
if (c is IntegralConstant || c is CharConstant) { if (c is IntegralConstant || c is CharConstant) {
@ -4494,11 +4489,6 @@ namespace Mono.CSharp
return this; return this;
} }
public override TypeExpr ResolveAsTypeTerminal (IMemberContext ec, bool silent)
{
return null;
}
public override void Emit (EmitContext ec) public override void Emit (EmitContext ec)
{ {
Label false_target = ec.DefineLabel (); Label false_target = ec.DefineLabel ();
@ -5647,7 +5637,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
TypeExpr texpr = RequestedType.ResolveAsTypeTerminal (ec, false); TypeExpr texpr = RequestedType.ResolveAsType (ec);
if (texpr == null) if (texpr == null)
return null; return null;
@ -6305,7 +6295,7 @@ namespace Mono.CSharp
array_type_expr = requested_base_type; array_type_expr = requested_base_type;
} }
array_type_expr = array_type_expr.ResolveAsTypeTerminal (ec, false); array_type_expr = array_type_expr.ResolveAsType (ec);
if (array_type_expr == null) if (array_type_expr == null)
return false; return false;
@ -7137,7 +7127,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext rc) protected override Expression DoResolve (ResolveContext rc)
{ {
expr = expr.Resolve (rc); expr = expr.Resolve (rc);
texpr = texpr.ResolveAsTypeTerminal (rc, false); texpr = texpr.ResolveAsType (rc);
if (expr == null || texpr == null) if (expr == null || texpr == null)
return null; return null;
@ -7255,7 +7245,7 @@ namespace Mono.CSharp
// Pointer types are allowed without explicit unsafe, they are just tokens // Pointer types are allowed without explicit unsafe, they are just tokens
// //
using (ec.Set (ResolveContext.Options.UnsafeScope)) { using (ec.Set (ResolveContext.Options.UnsafeScope)) {
texpr = QueriedType.ResolveAsTypeTerminal (ec, false); texpr = QueriedType.ResolveAsType (ec);
} }
if (texpr == null) if (texpr == null)
@ -7484,7 +7474,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
TypeExpr texpr = QueriedType.ResolveAsTypeTerminal (ec, false); TypeExpr texpr = QueriedType.ResolveAsType (ec);
if (texpr == null) if (texpr == null)
return null; return null;
@ -7553,11 +7543,11 @@ namespace Mono.CSharp
this.alias = alias; this.alias = alias;
} }
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent) public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec)
{ {
if (alias == GlobalAlias) { if (alias == GlobalAlias) {
expr = ec.Module.GlobalRootNamespace; expr = ec.Module.GlobalRootNamespace;
return base.ResolveAsTypeStep (ec, silent); return base.ResolveAsTypeOrNamespace (ec);
} }
int errors = ec.Module.Compiler.Report.Errors; int errors = ec.Module.Compiler.Report.Errors;
@ -7568,15 +7558,14 @@ namespace Mono.CSharp
return null; return null;
} }
FullNamedExpression fne = base.ResolveAsTypeStep (ec, silent); FullNamedExpression fne = base.ResolveAsTypeOrNamespace (ec);
if (fne == null) if (fne == null)
return null; return null;
if (expr.eclass == ExprClass.Type) { if (expr.eclass == ExprClass.Type) {
if (!silent) { ec.Module.Compiler.Report.Error (431, loc,
ec.Module.Compiler.Report.Error (431, loc, "Alias `{0}' cannot be used with '::' since it denotes a type. Consider replacing '::' with '.'", alias);
"Alias `{0}' cannot be used with '::' since it denotes a type. Consider replacing '::' with '.'", alias);
}
return null; return null;
} }
@ -7585,7 +7574,7 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
return ResolveAsTypeStep (ec, false); return ResolveAsTypeOrNamespace (ec);
} }
protected override void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type, string identifier) protected override void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type, string identifier)
@ -7718,7 +7707,7 @@ namespace Mono.CSharp
Namespace ns = expr as Namespace; Namespace ns = expr as Namespace;
if (ns != null) { if (ns != null) {
FullNamedExpression retval = ns.Lookup (rc, Name, Arity, loc); var retval = ns.LookupTypeOrNamespace (rc, Name, Arity, loc);
if (retval == null) { if (retval == null) {
ns.Error_NamespaceDoesNotExist (loc, Name, Arity, rc); ns.Error_NamespaceDoesNotExist (loc, Name, Arity, rc);
@ -7857,33 +7846,31 @@ namespace Mono.CSharp
return me; return me;
} }
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent) public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext rc)
{ {
return ResolveNamespaceOrType (ec, silent); FullNamedExpression fexpr = expr as FullNamedExpression;
} if (fexpr == null)
return expr.ResolveAsType (rc);
public FullNamedExpression ResolveNamespaceOrType (IMemberContext rc, bool silent) FullNamedExpression expr_resolved = fexpr.ResolveAsTypeOrNamespace (rc);
{
FullNamedExpression expr_resolved = expr.ResolveAsTypeStep (rc, silent);
if (expr_resolved == null) if (expr_resolved == null)
return null; return null;
Namespace ns = expr_resolved as Namespace; Namespace ns = expr_resolved as Namespace;
if (ns != null) { if (ns != null) {
FullNamedExpression retval = ns.Lookup (rc, Name, Arity, loc); FullNamedExpression retval = ns.LookupTypeOrNamespace (rc, Name, Arity, loc);
if (retval == null) { if (retval == null) {
if (!silent) ns.Error_NamespaceDoesNotExist (loc, Name, Arity, rc);
ns.Error_NamespaceDoesNotExist (loc, Name, Arity, rc);
} else if (HasTypeArguments) { } else if (HasTypeArguments) {
retval = new GenericTypeExpr (retval.Type, targs, loc).ResolveAsTypeStep (rc, silent); retval = new GenericTypeExpr (retval.Type, targs, loc).ResolveAsType (rc);
} }
return retval; return retval;
} }
TypeExpr tnew_expr = expr_resolved.ResolveAsTypeTerminal (rc, false); TypeExpr tnew_expr = expr_resolved.ResolveAsType (rc);
if (tnew_expr == null) if (tnew_expr == null)
return null; return null;
@ -7898,9 +7885,6 @@ namespace Mono.CSharp
while (expr_type != null) { while (expr_type != null) {
nested = MemberCache.FindNestedType (expr_type, Name, Arity); nested = MemberCache.FindNestedType (expr_type, Name, Arity);
if (nested == null) { if (nested == null) {
if (silent)
return null;
if (expr_type == tnew_expr.Type) { if (expr_type == tnew_expr.Type) {
Error_IdentifierNotFound (rc, expr_type, Name); Error_IdentifierNotFound (rc, expr_type, Name);
return null; return null;
@ -7930,7 +7914,7 @@ namespace Mono.CSharp
texpr = new TypeExpression (nested, loc); texpr = new TypeExpression (nested, loc);
} }
return texpr.ResolveAsTypeStep (rc, false); return texpr.ResolveAsTypeOrNamespace (rc);
} }
protected virtual void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type, string identifier) protected virtual void Error_IdentifierNotFound (IMemberContext rc, TypeSpec expr_type, string identifier)
@ -8980,9 +8964,9 @@ namespace Mono.CSharp
this.loc = spec.Location; this.loc = spec.Location;
} }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) public override TypeExpr ResolveAsType (IMemberContext ec)
{ {
TypeExpr lexpr = left.ResolveAsTypeTerminal (ec, false); TypeExpr lexpr = left.ResolveAsType (ec);
if (lexpr == null) if (lexpr == null)
return null; return null;
@ -8993,7 +8977,7 @@ namespace Mono.CSharp
if (single_spec.IsNullable) { if (single_spec.IsNullable) {
lexpr = new Nullable.NullableType (lexpr, loc); lexpr = new Nullable.NullableType (lexpr, loc);
lexpr = lexpr.ResolveAsTypeTerminal (ec, false); lexpr = lexpr.ResolveAsType (ec);
if (lexpr != null) if (lexpr != null)
type = lexpr.Type; type = lexpr.Type;
@ -9186,7 +9170,7 @@ namespace Mono.CSharp
ec.Report.Error (255, loc, "Cannot use stackalloc in finally or catch"); ec.Report.Error (255, loc, "Cannot use stackalloc in finally or catch");
} }
TypeExpr texpr = t.ResolveAsTypeTerminal (ec, false); TypeExpr texpr = t.ResolveAsType (ec);
if (texpr == null) if (texpr == null)
return null; return null;

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

@ -59,6 +59,11 @@ namespace Mono.CSharp {
{ {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec)
{
throw new NotImplementedException ();
}
} }
// //
@ -169,7 +174,7 @@ namespace Mono.CSharp {
continue; continue;
} }
var type_expr = constraints[i] = constraint.ResolveAsTypeTerminal (context, false); var type_expr = constraints[i] = constraint.ResolveAsType (context);
if (type_expr == null) if (type_expr == null)
continue; continue;
@ -1362,23 +1367,12 @@ namespace Mono.CSharp {
/// <summary> /// <summary>
/// A TypeExpr which already resolved to a type parameter. /// A TypeExpr which already resolved to a type parameter.
/// </summary> /// </summary>
public class TypeParameterExpr : TypeExpr { public class TypeParameterExpr : TypeExpression
{
public TypeParameterExpr (TypeParameter type_parameter, Location loc) public TypeParameterExpr (TypeParameter type_parameter, Location loc)
: base (type_parameter.Type, loc)
{ {
this.type = type_parameter.Type;
this.eclass = ExprClass.TypeParameter; this.eclass = ExprClass.TypeParameter;
this.loc = loc;
}
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
{
throw new NotSupportedException ();
}
public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent)
{
return this;
} }
} }
@ -1811,7 +1805,7 @@ namespace Mono.CSharp {
atypes = new TypeSpec [count]; atypes = new TypeSpec [count];
for (int i = 0; i < count; i++){ for (int i = 0; i < count; i++){
TypeExpr te = args[i].ResolveAsTypeTerminal (ec, false); TypeExpr te = args[i].ResolveAsType (ec);
if (te == null) { if (te == null) {
ok = false; ok = false;
continue; continue;
@ -1929,7 +1923,7 @@ namespace Mono.CSharp {
return TypeManager.CSharpName (type); return TypeManager.CSharpName (type);
} }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) public override TypeExpr ResolveAsType (IMemberContext ec)
{ {
if (!args.Resolve (ec)) if (!args.Resolve (ec))
return null; return null;
@ -1940,6 +1934,7 @@ namespace Mono.CSharp {
// Now bind the parameters // Now bind the parameters
// //
type = open_type.MakeGenericType (ec, atypes); type = open_type.MakeGenericType (ec, atypes);
eclass = ExprClass.Type;
// //
// Check constraints when context is not method/base type // Check constraints when context is not method/base type
@ -2022,17 +2017,11 @@ namespace Mono.CSharp {
// //
// Generic type with unbound type arguments, used for typeof (G<,,>) // Generic type with unbound type arguments, used for typeof (G<,,>)
// //
class GenericOpenTypeExpr : TypeExpr class GenericOpenTypeExpr : TypeExpression
{ {
public GenericOpenTypeExpr (TypeSpec type, /*UnboundTypeArguments args,*/ Location loc) public GenericOpenTypeExpr (TypeSpec type, /*UnboundTypeArguments args,*/ Location loc)
: base (type.GetDefinition (), loc)
{ {
this.type = type.GetDefinition ();
this.loc = loc;
}
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
{
return this;
} }
} }

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

@ -1182,7 +1182,7 @@ namespace Mono.CSharp
if ((ma & MethodAttributes.Final) != 0) if ((ma & MethodAttributes.Final) != 0)
mod |= Modifiers.SEALED; mod |= Modifiers.SEALED;
if ((ma & MethodAttributes.Virtual) != 0 && !declaringType.IsSealed) { if ((ma & MethodAttributes.Virtual) != 0) {
// Not every member can be detected based on MethodAttribute, we // Not every member can be detected based on MethodAttribute, we
// set virtual or non-virtual only when we are certain. Further checks // set virtual or non-virtual only when we are certain. Further checks
// to really find out what `virtual' means for this member are done // to really find out what `virtual' means for this member are done

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

@ -73,7 +73,7 @@ namespace Mono.CSharp {
} }
// //
// Namespace cache for imported and compiler namespaces // Namespace cache for imported and compiled namespaces
// //
// This is an Expression to allow it to be referenced in the // This is an Expression to allow it to be referenced in the
// compiler parse/intermediate tree during name resolution. // compiler parse/intermediate tree during name resolution.
@ -161,7 +161,7 @@ namespace Mono.CSharp {
public virtual void Error_NamespaceDoesNotExist (Location loc, string name, int arity, IMemberContext ctx) public virtual void Error_NamespaceDoesNotExist (Location loc, string name, int arity, IMemberContext ctx)
{ {
FullNamedExpression retval = Lookup (ctx, name, -System.Math.Max (1, arity), loc); var retval = LookupType (ctx, name, -System.Math.Max (1, arity), loc);
if (retval != null) { if (retval != null) {
Error_TypeArgumentsCannotBeUsed (ctx, retval.Type, arity, loc); Error_TypeArgumentsCannotBeUsed (ctx, retval.Type, arity, loc);
return; return;
@ -317,12 +317,26 @@ namespace Mono.CSharp {
return null; return null;
} }
public FullNamedExpression Lookup (IMemberContext ctx, string name, int arity, Location loc) public FullNamedExpression LookupTypeOrNamespace (IMemberContext ctx, string name, int arity, Location loc)
{ {
if (arity == 0 && namespaces.ContainsKey (name)) var texpr = LookupType (ctx, name, arity, loc);
return namespaces [name];
return LookupType (ctx, name, arity, loc); Namespace ns;
if (arity == 0 && namespaces.TryGetValue (name, out ns)) {
if (texpr == null)
return ns;
ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (texpr.Type);
// ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (ns.loc, "");
ctx.Module.Compiler.Report.Warning (437, 2, loc,
"The type `{0}' conflicts with the imported namespace `{1}'. Using the definition found in the source file",
texpr.GetSignatureForError (), ns.GetSignatureForError ());
if (texpr.Type.MemberDefinition.IsImported)
return ns;
}
return texpr;
} }
// //
@ -452,6 +466,11 @@ namespace Mono.CSharp {
cached_types.Remove (name); cached_types.Remove (name);
} }
public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc)
{
return this;
}
public void SetBuiltinType (BuiltinTypeSpec pts) public void SetBuiltinType (BuiltinTypeSpec pts)
{ {
var found = types[pts.Name]; var found = types[pts.Name];
@ -858,7 +877,7 @@ namespace Mono.CSharp {
// //
// Check whether it's in the namespace. // Check whether it's in the namespace.
// //
FullNamedExpression fne = ns.Lookup (this, name, arity, loc); FullNamedExpression fne = ns.LookupTypeOrNamespace (this, name, arity, loc);
// //
// Check aliases. // Check aliases.
@ -1130,7 +1149,7 @@ namespace Mono.CSharp {
if (resolved != null) if (resolved != null)
return resolved; return resolved;
FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeStep (rc, false); FullNamedExpression fne = name.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
if (fne == null) if (fne == null)
return null; return null;
@ -1188,14 +1207,14 @@ namespace Mono.CSharp {
if (local) if (local)
return null; return null;
resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false); resolved = value.GetTypeExpression ().ResolveAsTypeOrNamespace (rc);
if (resolved == null) { if (resolved == null) {
value = null; value = null;
return null; return null;
} }
if (resolved is TypeExpr) if (resolved is TypeExpr)
resolved = resolved.ResolveAsTypeTerminal (rc, false); resolved = resolved.ResolveAsType (rc);
return resolved; return resolved;
} }

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

@ -37,7 +37,7 @@ namespace Mono.CSharp.Nullable
: this (new TypeExpression (type, loc), loc) : this (new TypeExpression (type, loc), loc)
{ } { }
protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec) public override TypeExpr ResolveAsType (IMemberContext ec)
{ {
var type = ec.Module.PredefinedTypes.Nullable.Resolve (); var type = ec.Module.PredefinedTypes.Nullable.Resolve ();
if (type == null) if (type == null)
@ -45,7 +45,7 @@ namespace Mono.CSharp.Nullable
TypeArguments args = new TypeArguments (underlying); TypeArguments args = new TypeArguments (underlying);
GenericTypeExpr ctype = new GenericTypeExpr (type, args, loc); GenericTypeExpr ctype = new GenericTypeExpr (type, args, loc);
return ctype.ResolveAsTypeTerminal (ec, false); return ctype.ResolveAsType (ec);
} }
} }
@ -522,7 +522,7 @@ namespace Mono.CSharp.Nullable
Expression LiftExpression (ResolveContext ec, Expression expr) Expression LiftExpression (ResolveContext ec, Expression expr)
{ {
TypeExpr lifted_type = new NullableType (expr.Type, expr.Location); TypeExpr lifted_type = new NullableType (expr.Type, expr.Location);
lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false); lifted_type = lifted_type.ResolveAsType (ec);
if (lifted_type == null) if (lifted_type == null)
return null; return null;
@ -872,7 +872,7 @@ namespace Mono.CSharp.Nullable
// //
if (left_unwrap == null || IsLeftNullLifted || left_unwrap.Type != left.Type || (left_unwrap != null && IsRightNullLifted)) { if (left_unwrap == null || IsLeftNullLifted || left_unwrap.Type != left.Type || (left_unwrap != null && IsRightNullLifted)) {
lifted_type = new NullableType (left.Type, loc); lifted_type = new NullableType (left.Type, loc);
lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false); lifted_type = lifted_type.ResolveAsType (ec);
if (lifted_type == null) if (lifted_type == null)
return null; return null;
@ -884,7 +884,7 @@ namespace Mono.CSharp.Nullable
if (left != right && (right_unwrap == null || IsRightNullLifted || right_unwrap.Type != right.Type || (right_unwrap != null && IsLeftNullLifted))) { if (left != right && (right_unwrap == null || IsRightNullLifted || right_unwrap.Type != right.Type || (right_unwrap != null && IsLeftNullLifted))) {
lifted_type = new NullableType (right.Type, loc); lifted_type = new NullableType (right.Type, loc);
lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false); lifted_type = lifted_type.ResolveAsType (ec);
if (lifted_type == null) if (lifted_type == null)
return null; return null;
@ -900,7 +900,7 @@ namespace Mono.CSharp.Nullable
if ((Oper & Operator.ComparisonMask) == 0) { if ((Oper & Operator.ComparisonMask) == 0) {
lifted_type = new NullableType (res_expr.Type, loc); lifted_type = new NullableType (res_expr.Type, loc);
lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false); lifted_type = lifted_type.ResolveAsType (ec);
if (lifted_type == null) if (lifted_type == null)
return null; return null;

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

@ -357,7 +357,7 @@ namespace Mono.CSharp {
if (attributes != null) if (attributes != null)
attributes.AttachTo (this, rc); attributes.AttachTo (this, rc);
var expr = texpr.ResolveAsTypeTerminal (rc, false); var expr = texpr.ResolveAsType (rc);
if (expr == null) if (expr == null)
return null; return null;

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

@ -54,7 +54,7 @@ namespace Mono.CSharp {
28, 67, 78, 28, 67, 78,
105, 108, 109, 114, 162, 164, 168, 169, 183, 184, 197, 105, 108, 109, 114, 162, 164, 168, 169, 183, 184, 197,
219, 251, 252, 253, 278, 282, 219, 251, 252, 253, 278, 282,
402, 414, 419, 420, 429, 436, 440, 458, 464, 465, 467, 469, 472, 402, 414, 419, 420, 429, 436, 437, 440, 458, 464, 465, 467, 469, 472,
612, 618, 626, 628, 642, 649, 652, 657, 658, 659, 660, 661, 665, 672, 675, 693, 612, 618, 626, 628, 642, 649, 652, 657, 658, 659, 660, 661, 665, 672, 675, 693,
728, 728,
809, 824, 809, 824,

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

@ -1366,46 +1366,45 @@ namespace Mono.CSharp {
{ {
if (li.Type == null) { if (li.Type == null) {
TypeSpec type = null; TypeSpec type = null;
if (type_expr is VarExpr) { var vexpr = type_expr as VarExpr;
//
// C# 3.0 introduced contextual keywords (var) which behaves like a type if type with
// same name exists or as a keyword when no type was found
//
var texpr = type_expr.ResolveAsTypeTerminal (bc, true);
if (texpr == null) {
if (bc.Module.Compiler.Settings.Version < LanguageVersion.V_3)
bc.Report.FeatureIsNotAvailable (bc.Module.Compiler, loc, "implicitly typed local variable");
if (li.IsFixed) {
bc.Report.Error (821, loc, "A fixed statement cannot use an implicitly typed local variable");
return false;
}
if (li.IsConstant) { //
bc.Report.Error (822, loc, "An implicitly typed local variable cannot be a constant"); // C# 3.0 introduced contextual keywords (var) which behaves like a type if type with
return false; // same name exists or as a keyword when no type was found
} //
if (vexpr != null && !vexpr.IsPossibleTypeOrNamespace (bc)) {
if (bc.Module.Compiler.Settings.Version < LanguageVersion.V_3)
bc.Report.FeatureIsNotAvailable (bc.Module.Compiler, loc, "implicitly typed local variable");
if (Initializer == null) { if (li.IsFixed) {
bc.Report.Error (818, loc, "An implicitly typed local variable declarator must include an initializer"); bc.Report.Error (821, loc, "A fixed statement cannot use an implicitly typed local variable");
return false; return false;
} }
if (declarators != null) { if (li.IsConstant) {
bc.Report.Error (819, loc, "An implicitly typed local variable declaration cannot include multiple declarators"); bc.Report.Error (822, loc, "An implicitly typed local variable cannot be a constant");
declarators = null; return false;
} }
Initializer = Initializer.Resolve (bc); if (Initializer == null) {
if (Initializer != null) { bc.Report.Error (818, loc, "An implicitly typed local variable declarator must include an initializer");
((VarExpr) type_expr).InferType (bc, Initializer); return false;
type = type_expr.Type; }
}
if (declarators != null) {
bc.Report.Error (819, loc, "An implicitly typed local variable declaration cannot include multiple declarators");
declarators = null;
}
Initializer = Initializer.Resolve (bc);
if (Initializer != null) {
((VarExpr) type_expr).InferType (bc, Initializer);
type = type_expr.Type;
} }
} }
if (type == null) { if (type == null) {
var texpr = type_expr.ResolveAsTypeTerminal (bc, false); var texpr = type_expr.ResolveAsType (bc);
if (texpr == null) if (texpr == null)
return false; return false;
@ -4771,7 +4770,7 @@ namespace Mono.CSharp {
{ {
using (ec.With (ResolveContext.Options.CatchScope, true)) { using (ec.With (ResolveContext.Options.CatchScope, true)) {
if (type_expr != null) { if (type_expr != null) {
TypeExpr te = type_expr.ResolveAsTypeTerminal (ec, false); TypeExpr te = type_expr.ResolveAsType (ec);
if (te == null) if (te == null)
return false; return false;
@ -5329,7 +5328,7 @@ namespace Mono.CSharp {
var_type = new TypeExpression (access.Type, ve.Location); var_type = new TypeExpression (access.Type, ve.Location);
} }
var_type = var_type.ResolveAsTypeTerminal (ec, false); var_type = var_type.ResolveAsType (ec);
if (var_type == null) if (var_type == null)
return false; return false;
@ -5692,7 +5691,7 @@ namespace Mono.CSharp {
current_pe = EmptyCast.Create (current_pe, ec.BuiltinTypes.Dynamic); current_pe = EmptyCast.Create (current_pe, ec.BuiltinTypes.Dynamic);
} }
var_type = var_type.ResolveAsTypeTerminal (ec, false); var_type = var_type.ResolveAsType (ec);
if (var_type == null) if (var_type == null)
return false; return false;

Loading…
Cancel
Save