Browse Source

Updated mcs (fixed char posititions).

newNRvisualizers
Mike Krüger 15 years ago
parent
commit
7ed3af27fc
  1. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  2. 22
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  3. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/ecore.cs
  4. 40
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  5. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/flowanalysis.cs
  6. 79
      ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs
  7. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/pending.cs
  8. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs

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

@ -319,6 +319,12 @@ namespace Mono.CSharp
} }
} }
public TypeSpec[] Interfaces {
get {
return iface_exprs;
}
}
#endregion #endregion
public override void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)

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

@ -3188,7 +3188,6 @@ namespace Mono.CSharp
} }
// Handle double-slash comments. // Handle double-slash comments.
if (d == '/') { if (d == '/') {
Console.WriteLine (line + "/" + col);
get_char (); get_char ();
if (doc_processing) { if (doc_processing) {
if (peek_char () == '/') { if (peek_char () == '/') {
@ -3432,16 +3431,20 @@ namespace Mono.CSharp
int TokenizeBackslash () int TokenizeBackslash ()
{ {
#if FULL_AST
int read_start = reader.Position;
#endif
Location start_location = Location;
int c = get_char (); int c = get_char ();
tokens_seen = true; tokens_seen = true;
if (c == '\'') { if (c == '\'') {
val = new CharLiteral (context.BuiltinTypes, (char) c, Location); val = new CharLiteral (context.BuiltinTypes, (char) c, start_location);
Report.Error (1011, Location, "Empty character literal"); Report.Error (1011, start_location, "Empty character literal");
return Token.LITERAL; return Token.LITERAL;
} }
if (c == '\n') { if (c == '\r') {
Report.Error (1010, Location, "Newline in constant"); Report.Error (1010, start_location, "Newline in constant");
return Token.ERROR; return Token.ERROR;
} }
@ -3452,11 +3455,12 @@ namespace Mono.CSharp
if (d != 0) if (d != 0)
throw new NotImplementedException (); throw new NotImplementedException ();
val = new CharLiteral (context.BuiltinTypes, (char) c, Location); ILiteralConstant res = new CharLiteral (context.BuiltinTypes, (char) c, start_location);
val = res;
c = get_char (); c = get_char ();
if (c != '\'') { if (c != '\'') {
Report.Error (1012, Location, "Too many characters in character literal"); Report.Error (1012, start_location, "Too many characters in character literal");
// Try to recover, read until newline or next "'" // Try to recover, read until newline or next "'"
while ((c = get_char ()) != -1) { while ((c = get_char ()) != -1) {
@ -3465,6 +3469,10 @@ namespace Mono.CSharp
} }
} }
#if FULL_AST
res.ParsedValue = reader.ReadChars (read_start - 1, reader.Position);
#endif
return Token.LITERAL; return Token.LITERAL;
} }

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

@ -1862,6 +1862,17 @@ namespace Mono.CSharp {
c = new ReducedConstantExpression (c, orig_expr); c = new ReducedConstantExpression (c, orig_expr);
return c; return c;
} }
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
//
// LAMESPEC: Reduced conditional expression is allowed as an attribute argument
//
if (orig_expr is Conditional)
child.EncodeAttributeValue (rc, enc, targetType);
else
base.EncodeAttributeValue (rc, enc, targetType);
}
} }
sealed class ReducedExpressionStatement : ExpressionStatement sealed class ReducedExpressionStatement : ExpressionStatement

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

@ -4563,8 +4563,32 @@ namespace Mono.CSharp
protected override Expression DoResolve (ResolveContext ec) protected override Expression DoResolve (ResolveContext ec)
{ {
expr = expr.Resolve (ec); expr = expr.Resolve (ec);
//
// Unreachable code needs different resolve path. For instance for await
// expression to not generate unreachable resumable statement
//
Constant c = expr as Constant;
if (c != null && ec.CurrentBranching != null) {
bool unreachable = ec.CurrentBranching.CurrentUsageVector.IsUnreachable;
if (c.IsDefaultValue) {
ec.CurrentBranching.CurrentUsageVector.IsUnreachable = true;
true_expr = true_expr.Resolve (ec);
ec.CurrentBranching.CurrentUsageVector.IsUnreachable = unreachable;
false_expr = false_expr.Resolve (ec);
} else {
true_expr = true_expr.Resolve (ec);
ec.CurrentBranching.CurrentUsageVector.IsUnreachable = true;
false_expr = false_expr.Resolve (ec);
ec.CurrentBranching.CurrentUsageVector.IsUnreachable = unreachable;
}
} else {
true_expr = true_expr.Resolve (ec); true_expr = true_expr.Resolve (ec);
false_expr = false_expr.Resolve (ec); false_expr = false_expr.Resolve (ec);
}
if (true_expr == null || false_expr == null || expr == null) if (true_expr == null || false_expr == null || expr == null)
return null; return null;
@ -4604,11 +4628,17 @@ namespace Mono.CSharp
} }
} }
// Dead code optimalization if (c != null) {
Constant c = expr as Constant;
if (c != null){
bool is_false = c.IsDefaultValue; bool is_false = c.IsDefaultValue;
ec.Report.Warning (429, 4, is_false ? true_expr.Location : false_expr.Location, "Unreachable expression code detected");
//
// Don't issue the warning for constant expressions
//
if (!(is_false ? true_expr is Constant : false_expr is Constant)) {
ec.Report.Warning (429, 4, is_false ? true_expr.Location : false_expr.Location,
"Unreachable expression code detected");
}
return ReducedExpression.Create ( return ReducedExpression.Create (
is_false ? false_expr : true_expr, this, is_false ? false_expr : true_expr, this,
false_expr is Constant && true_expr is Constant).Resolve (ec); false_expr is Constant && true_expr is Constant).Resolve (ec);
@ -5965,7 +5995,7 @@ namespace Mono.CSharp
{ {
var current_field = rc.CurrentMemberDefinition as FieldBase; var current_field = rc.CurrentMemberDefinition as FieldBase;
TypeExpression type; TypeExpression type;
if (current_field != null) { if (current_field != null && rc.CurrentAnonymousMethod == null) {
type = new TypeExpression (current_field.MemberType, current_field.Location); type = new TypeExpression (current_field.MemberType, current_field.Location);
} else if (variable != null) { } else if (variable != null) {
if (variable.TypeExpression is VarExpr) { if (variable.TypeExpression is VarExpr) {

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

@ -251,7 +251,12 @@ namespace Mono.CSharp
} }
public bool IsUnreachable { public bool IsUnreachable {
get { return is_unreachable; } get {
return is_unreachable;
}
set {
is_unreachable = value;
}
} }
public void ResetBarrier () public void ResetBarrier ()

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

@ -613,7 +613,7 @@ namespace Mono.CSharp {
MethodData = new MethodData ( MethodData = new MethodData (
this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method); this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method);
if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName), Report)) if (!MethodData.Define (Parent.PartialContainer, GetFullName (MemberName)))
return false; return false;
MethodBuilder = MethodData.MethodBuilder; MethodBuilder = MethodData.MethodBuilder;
@ -1819,32 +1819,34 @@ namespace Mono.CSharp {
this.parent_method = parent_method; this.parent_method = parent_method;
} }
public bool Define (DeclSpace parent, string method_full_name, Report Report) public bool Define (TypeContainer container, string method_full_name)
{ {
TypeContainer container = parent.PartialContainer;
PendingImplementation pending = container.PendingImplementations; PendingImplementation pending = container.PendingImplementations;
MethodSpec ambig_iface_method; MethodSpec ambig_iface_method;
bool optional = false;
if (pending != null) { if (pending != null) {
implementing = pending.IsInterfaceMethod (method.MethodName, member.InterfaceType, this, out ambig_iface_method); implementing = pending.IsInterfaceMethod (method.MethodName, member.InterfaceType, this, out ambig_iface_method, ref optional);
if (member.InterfaceType != null) { if (member.InterfaceType != null) {
if (implementing == null) { if (implementing == null) {
if (member is PropertyBase) { if (member is PropertyBase) {
Report.Error (550, method.Location, "`{0}' is an accessor not found in interface member `{1}{2}'", container.Compiler.Report.Error (550, method.Location,
"`{0}' is an accessor not found in interface member `{1}{2}'",
method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType), method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType),
member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.'))); member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.')));
} else { } else {
Report.Error (539, method.Location, container.Compiler.Report.Error (539, method.Location,
"`{0}.{1}' in explicit interface declaration is not a member of interface", "`{0}.{1}' in explicit interface declaration is not a member of interface",
TypeManager.CSharpName (member.InterfaceType), member.ShortName); TypeManager.CSharpName (member.InterfaceType), member.ShortName);
} }
return false; return false;
} }
if (implementing.IsAccessor && !method.IsAccessor) { if (implementing.IsAccessor && !method.IsAccessor) {
Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
Report.Error (683, method.Location, "`{0}' explicit method implementation cannot implement `{1}' because it is an accessor", container.Compiler.Report.Error (683, method.Location,
"`{0}' explicit method implementation cannot implement `{1}' because it is an accessor",
member.GetSignatureForError (), TypeManager.CSharpSignature (implementing)); member.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
return false; return false;
} }
@ -1852,20 +1854,23 @@ namespace Mono.CSharp {
if (implementing != null) { if (implementing != null) {
if (!method.IsAccessor) { if (!method.IsAccessor) {
if (implementing.IsAccessor) { if (implementing.IsAccessor) {
Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
Report.Error (470, method.Location, "Method `{0}' cannot implement interface accessor `{1}'", container.Compiler.Report.Error (470, method.Location,
"Method `{0}' cannot implement interface accessor `{1}'",
method.GetSignatureForError (), TypeManager.CSharpSignature (implementing)); method.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
} }
} else if (implementing.DeclaringType.IsInterface) { } else if (implementing.DeclaringType.IsInterface) {
if (!implementing.IsAccessor) { if (!implementing.IsAccessor) {
Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
Report.Error (686, method.Location, "Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation", container.Compiler.Report.Error (686, method.Location,
"Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation",
method.GetSignatureForError (), TypeManager.CSharpSignature (implementing), container.GetSignatureForError ()); method.GetSignatureForError (), TypeManager.CSharpSignature (implementing), container.GetSignatureForError ());
} else { } else {
PropertyBase.PropertyMethod pm = method as PropertyBase.PropertyMethod; PropertyBase.PropertyMethod pm = method as PropertyBase.PropertyMethod;
if (pm != null && pm.HasCustomAccessModifier && (pm.ModFlags & Modifiers.PUBLIC) == 0) { if (pm != null && pm.HasCustomAccessModifier && (pm.ModFlags & Modifiers.PUBLIC) == 0) {
Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
Report.Error (277, method.Location, "Accessor `{0}' must be declared public to implement interface member `{1}'", container.Compiler.Report.Error (277, method.Location,
"Accessor `{0}' must be declared public to implement interface member `{1}'",
method.GetSignatureForError (), implementing.GetSignatureForError ()); method.GetSignatureForError (), implementing.GetSignatureForError ());
} }
} }
@ -1881,43 +1886,44 @@ namespace Mono.CSharp {
// explicit implementations, make sure we are private. // explicit implementations, make sure we are private.
// //
if (implementing != null){ if (implementing != null){
// if (member.IsExplicitImpl) {
// Setting null inside this block will trigger a more
// verbose error reporting for missing interface implementations
//
// The "candidate" function has been flagged already
// but it wont get cleared
//
if (member.IsExplicitImpl){
if (method.ParameterInfo.HasParams && !implementing.Parameters.HasParams) { if (method.ParameterInfo.HasParams && !implementing.Parameters.HasParams) {
Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
Report.Error (466, method.Location, "`{0}': the explicit interface implementation cannot introduce the params modifier", container.Compiler.Report.Error (466, method.Location,
"`{0}': the explicit interface implementation cannot introduce the params modifier",
method.GetSignatureForError ()); method.GetSignatureForError ());
} }
if (ambig_iface_method != null) { if (ambig_iface_method != null) {
Report.SymbolRelatedToPreviousError (ambig_iface_method); container.Compiler.Report.SymbolRelatedToPreviousError (ambig_iface_method);
Report.SymbolRelatedToPreviousError (implementing); container.Compiler.Report.SymbolRelatedToPreviousError (implementing);
Report.Warning (473, 2, method.Location, container.Compiler.Report.Warning (473, 2, method.Location,
"Explicit interface implementation `{0}' matches more than one interface member. Consider using a non-explicit implementation instead", "Explicit interface implementation `{0}' matches more than one interface member. Consider using a non-explicit implementation instead",
method.GetSignatureForError ()); method.GetSignatureForError ());
} }
} else { } else {
//
// Setting implementin to null inside this block will trigger a more
// verbose error reporting for missing interface implementations
//
if (implementing.DeclaringType.IsInterface) { if (implementing.DeclaringType.IsInterface) {
// //
// If this is an interface method implementation, // If this is an interface method implementation,
// check for public accessibility // check for public accessibility
// //
if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public) if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public) {
{ implementing = null;
} else if (optional && (container.Interfaces == null || Array.IndexOf (container.Interfaces, implementing.DeclaringType) < 0)) {
//
// We are not implementing interface when base class already implemented it
//
implementing = null; implementing = null;
} }
} else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private){ } else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) {
// We may never be private. // We may never be private.
implementing = null; implementing = null;
} else if ((modifiers & Modifiers.OVERRIDE) == 0){ } else if ((modifiers & Modifiers.OVERRIDE) == 0) {
// //
// We may be protected if we're overriding something. // We may be protected if we're overriding something.
// //
@ -1941,8 +1947,7 @@ namespace Mono.CSharp {
// When implementing interface methods, set NewSlot // When implementing interface methods, set NewSlot
// unless, we are overwriting a method. // unless, we are overwriting a method.
// //
if (implementing.DeclaringType.IsInterface){ if ((modifiers & Modifiers.OVERRIDE) == 0 && implementing.DeclaringType.IsInterface) {
if ((modifiers & Modifiers.OVERRIDE) == 0)
flags |= MethodAttributes.NewSlot; flags |= MethodAttributes.NewSlot;
} }
@ -1955,8 +1960,8 @@ namespace Mono.CSharp {
// //
// clear the pending implementation flag (requires explicit methods to be defined first) // clear the pending implementation flag (requires explicit methods to be defined first)
// //
parent.PartialContainer.PendingImplementations.ImplementMethod (method.MethodName, pending.ImplementMethod (method.MethodName,
member.InterfaceType, this, member.IsExplicitImpl, out ambig_iface_method); member.InterfaceType, this, member.IsExplicitImpl, out ambig_iface_method, ref optional);
// //
// Update indexer accessor name to match implementing abstract accessor // Update indexer accessor name to match implementing abstract accessor

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

@ -345,14 +345,14 @@ namespace Mono.CSharp {
/// <summary> /// <summary>
/// Whether the specified method is an interface method implementation /// Whether the specified method is an interface method implementation
/// </summary> /// </summary>
public MethodSpec IsInterfaceMethod (MemberName name, TypeSpec ifaceType, MethodData method, out MethodSpec ambiguousCandidate) public MethodSpec IsInterfaceMethod (MemberName name, TypeSpec ifaceType, MethodData method, out MethodSpec ambiguousCandidate, ref bool optional)
{ {
return InterfaceMethod (name, ifaceType, method, Operation.Lookup, out ambiguousCandidate); return InterfaceMethod (name, ifaceType, method, Operation.Lookup, out ambiguousCandidate, ref optional);
} }
public void ImplementMethod (MemberName name, TypeSpec ifaceType, MethodData method, bool clear_one, out MethodSpec ambiguousCandidate) public void ImplementMethod (MemberName name, TypeSpec ifaceType, MethodData method, bool clear_one, out MethodSpec ambiguousCandidate, ref bool optional)
{ {
InterfaceMethod (name, ifaceType, method, clear_one ? Operation.ClearOne : Operation.ClearAll, out ambiguousCandidate); InterfaceMethod (name, ifaceType, method, clear_one ? Operation.ClearOne : Operation.ClearAll, out ambiguousCandidate, ref optional);
} }
/// <remarks> /// <remarks>
@ -372,7 +372,7 @@ namespace Mono.CSharp {
/// that was used in the interface, then we always need to create a proxy for it. /// that was used in the interface, then we always need to create a proxy for it.
/// ///
/// </remarks> /// </remarks>
public MethodSpec InterfaceMethod (MemberName name, TypeSpec iType, MethodData method, Operation op, out MethodSpec ambiguousCandidate) public MethodSpec InterfaceMethod (MemberName name, TypeSpec iType, MethodData method, Operation op, out MethodSpec ambiguousCandidate, ref bool optional)
{ {
ambiguousCandidate = null; ambiguousCandidate = null;
@ -439,6 +439,7 @@ namespace Mono.CSharp {
} }
} else { } else {
tm.found [i] = method; tm.found [i] = method;
optional = tm.optional;
} }
if (op == Operation.Lookup && name.Left != null && ambiguousCandidate == null) { if (op == Operation.Lookup && name.Left != null && ambiguousCandidate == null) {

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

@ -205,7 +205,7 @@ namespace Mono.CSharp
method_data = new MethodData (method, ModFlags, flags, this); method_data = new MethodData (method, ModFlags, flags, this);
if (!method_data.Define (parent, method.GetFullName (MemberName), Report)) if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null; return null;
Spec.SetMetaInfo (method_data.MethodBuilder); Spec.SetMetaInfo (method_data.MethodBuilder);
@ -272,7 +272,7 @@ namespace Mono.CSharp
method_data = new MethodData (method, ModFlags, flags, this); method_data = new MethodData (method, ModFlags, flags, this);
if (!method_data.Define (parent, method.GetFullName (MemberName), Report)) if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null; return null;
Spec.SetMetaInfo (method_data.MethodBuilder); Spec.SetMetaInfo (method_data.MethodBuilder);
@ -1165,7 +1165,7 @@ namespace Mono.CSharp
method_data = new MethodData (method, method.ModFlags, method_data = new MethodData (method, method.ModFlags,
method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this); method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
if (!method_data.Define (parent, method.GetFullName (MemberName), Report)) if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null; return null;
MethodBuilder mb = method_data.MethodBuilder; MethodBuilder mb = method_data.MethodBuilder;

Loading…
Cancel
Save