Browse Source

Updated mcs.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
0df05c304f
  1. 8
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cfold.cs
  2. 19
      ICSharpCode.NRefactory.CSharp/Parser/mcs/constant.cs
  3. 22
      ICSharpCode.NRefactory.CSharp/Parser/mcs/context.cs
  4. 35
      ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs
  5. 807
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  6. 15
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  7. 22
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  8. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  9. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  10. 49
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  11. 152
      ICSharpCode.NRefactory.CSharp/Parser/mcs/support.cs
  12. 1
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PrimitiveExpressionTests.cs

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

@ -149,7 +149,7 @@ namespace Mono.CSharp { @@ -149,7 +149,7 @@ namespace Mono.CSharp {
case Binary.Operator.ExclusiveOr:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null)
result = result.TryReduce (ec, lt);
result = result.Reduce (ec, lt);
return result;
///
@ -158,7 +158,7 @@ namespace Mono.CSharp { @@ -158,7 +158,7 @@ namespace Mono.CSharp {
case Binary.Operator.Subtraction:
result = BinaryFold (ec, oper, ((EnumConstant)left).Child, ((EnumConstant)right).Child, loc);
if (result != null)
result = result.TryReduce (ec, EnumSpec.GetUnderlyingType (lt));
result = result.Reduce (ec, EnumSpec.GetUnderlyingType (lt));
return result;
///
@ -340,7 +340,7 @@ namespace Mono.CSharp { @@ -340,7 +340,7 @@ namespace Mono.CSharp {
if (result == null)
return null;
result = result.TryReduce (ec, lt);
result = result.Reduce (ec, lt);
if (result == null)
return null;
@ -459,7 +459,7 @@ namespace Mono.CSharp { @@ -459,7 +459,7 @@ namespace Mono.CSharp {
if (result == null)
return null;
result = result.TryReduce (ec, lt);
result = result.Reduce (ec, lt);
if (result == null)
return null;

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

@ -251,10 +251,12 @@ namespace Mono.CSharp { @@ -251,10 +251,12 @@ namespace Mono.CSharp {
return this;
}
/// <summary>
/// Attempts to do a compile-time folding of a constant cast.
/// </summary>
public Constant TryReduce (ResolveContext ec, TypeSpec target_type)
//
// Attempts to do a compile-time folding of a constant cast and handles
// error reporting for constant overlows only, on normal conversion
// errors returns null
//
public Constant Reduce (ResolveContext ec, TypeSpec target_type)
{
try {
return TryReduceConstant (ec, target_type);
@ -271,6 +273,15 @@ namespace Mono.CSharp { @@ -271,6 +273,15 @@ namespace Mono.CSharp {
}
}
public Constant TryReduce (ResolveContext rc, TypeSpec targetType)
{
try {
return TryReduceConstant (rc, targetType);
} catch (OverflowException) {
return null;
}
}
Constant TryReduceConstant (ResolveContext ec, TypeSpec target_type)
{
if (Type == target_type) {

22
ICSharpCode.NRefactory.CSharp/Parser/mcs/context.cs

@ -105,6 +105,24 @@ namespace Mono.CSharp @@ -105,6 +105,24 @@ namespace Mono.CSharp
get { return return_type; }
}
public bool IsUnreachable {
get {
return HasSet (Options.UnreachableScope);
}
set {
flags = value ? flags | Options.UnreachableScope : flags & ~Options.UnreachableScope;
}
}
public bool UnreachableReported {
get {
return HasSet (Options.UnreachableReported);
}
set {
flags = value ? flags | Options.UnreachableReported : flags & ~Options.UnreachableScope;
}
}
// <summary>
// Starts a new code branching. This inherits the state of all local
// variables and parameters from the current branching.
@ -257,6 +275,10 @@ namespace Mono.CSharp @@ -257,6 +275,10 @@ namespace Mono.CSharp
LockScope = 1 << 13,
UnreachableScope = 1 << 14,
UnreachableReported = 1 << 15,
/// <summary>
/// Whether control flow analysis is enabled
/// </summary>

35
ICSharpCode.NRefactory.CSharp/Parser/mcs/convert.cs

@ -1196,7 +1196,7 @@ namespace Mono.CSharp { @@ -1196,7 +1196,7 @@ namespace Mono.CSharp {
if (s_x != source_type) {
var c = source as Constant;
if (c != null) {
source = c.TryReduce (ec, s_x);
source = c.Reduce (ec, s_x);
if (source == null)
c = null;
}
@ -1990,21 +1990,28 @@ namespace Mono.CSharp { @@ -1990,21 +1990,28 @@ namespace Mono.CSharp {
if (expr_type == real_target)
return EmptyCast.Create (expr, target_type);
ne = ImplicitNumericConversion (expr, real_target);
if (ne != null)
return EmptyCast.Create (ne, target_type);
ne = ExplicitNumericConversion (ec, expr, real_target);
if (ne != null)
return EmptyCast.Create (ne, target_type);
Constant c = expr as Constant;
if (c != null) {
c = c.TryReduce (ec, real_target);
if (c != null)
return c;
} else {
ne = ImplicitNumericConversion (expr, real_target);
if (ne != null)
return EmptyCast.Create (ne, target_type);
//
// LAMESPEC: IntPtr and UIntPtr conversion to any Enum is allowed
//
if (expr_type.BuiltinType == BuiltinTypeSpec.Type.IntPtr || expr_type.BuiltinType == BuiltinTypeSpec.Type.UIntPtr) {
ne = ExplicitUserConversion (ec, expr, real_target, loc);
ne = ExplicitNumericConversion (ec, expr, real_target);
if (ne != null)
return ExplicitConversionCore (ec, ne, target_type, loc);
return EmptyCast.Create (ne, target_type);
//
// LAMESPEC: IntPtr and UIntPtr conversion to any Enum is allowed
//
if (expr_type.BuiltinType == BuiltinTypeSpec.Type.IntPtr || expr_type.BuiltinType == BuiltinTypeSpec.Type.UIntPtr) {
ne = ExplicitUserConversion (ec, expr, real_target, loc);
if (ne != null)
return ExplicitConversionCore (ec, ne, target_type, loc);
}
}
} else {
ne = ExplicitNumericConversion (ec, expr, target_type);

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

File diff suppressed because it is too large Load Diff

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

@ -1737,7 +1737,7 @@ indexer_declaration @@ -1737,7 +1737,7 @@ indexer_declaration
{
valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
}
opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
opt_formal_parameter_list CLOSE_BRACKET
{
valid_param_mod = 0;
var type = (FullNamedExpression) $3;
@ -1746,7 +1746,7 @@ indexer_declaration @@ -1746,7 +1746,7 @@ indexer_declaration
current_property = indexer;
current_type.AddIndexer (indexer);
lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($5), GetLocation ($8), GetLocation ($9));
lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($5), GetLocation ($8));
if (type.Type != null && type.Type.Kind == MemberKind.Void)
report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
@ -1762,7 +1762,7 @@ indexer_declaration @@ -1762,7 +1762,7 @@ indexer_declaration
lexer.PropertyParsing = true;
}
accessor_declarations
OPEN_BRACE accessor_declarations
{
lexer.PropertyParsing = false;
}
@ -1774,7 +1774,7 @@ indexer_declaration @@ -1774,7 +1774,7 @@ indexer_declaration
if (doc_support)
current_property.DocComment = ConsumeStoredComment ();
lbag.AppendToMember (current_property, GetLocation ($12));
lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
current_property = null;
}
;
@ -3348,7 +3348,8 @@ argument_list @@ -3348,7 +3348,8 @@ argument_list
}
| argument_list COMMA error
{
lexer.putback (')'); // TODO: Wrong but what can I do
if (lexer.putback_char == -1)
lexer.putback (')'); // TODO: Wrong but what can I do
Error_SyntaxError (yyToken);
$$ = $1;
}
@ -6987,6 +6988,10 @@ void Error_SyntaxError (int error_code, int token, string msg) @@ -6987,6 +6988,10 @@ void Error_SyntaxError (int error_code, int token, string msg)
// An error message has been reported by tokenizer
if (token == Token.ERROR)
return;
// Avoid duplicit error message after unterminated string literals
if (token == Token.LITERAL && lexer.Location.Column == 0)
return;
string symbol = GetSymbolName (token);
string expecting = GetExpecting ();

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

@ -1809,6 +1809,26 @@ namespace Mono.CSharp @@ -1809,6 +1809,26 @@ namespace Mono.CSharp
return x;
}
int get_char_withwithoutskippingwindowseol ()
{
int x;
if (putback_char != -1) {
x = putback_char;
putback_char = -1;
} else {
x = reader.Read ();
}
if (x == '\r') {
} else if (x == '\n') {
advance_line ();
} else {
col++;
}
return x;
}
void advance_line ()
{
line++;
@ -2901,7 +2921,7 @@ namespace Mono.CSharp @@ -2901,7 +2921,7 @@ namespace Mono.CSharp
#endif
while (true){
c = get_char ();
c = get_char_withwithoutskippingwindowseol ();
if (c == '"') {
if (quoted && peek_char () == '"') {
if (pos == value_builder.Length)

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

@ -173,7 +173,7 @@ namespace Mono.CSharp @@ -173,7 +173,7 @@ namespace Mono.CSharp
parser.parse ();
return parser;
}
public static int Main (string[] args)
{
Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";

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

@ -1702,7 +1702,7 @@ namespace Mono.CSharp @@ -1702,7 +1702,7 @@ namespace Mono.CSharp
Constant c = expr as Constant;
if (c != null) {
c = c.TryReduce (ec, type);
c = c.Reduce (ec, type);
if (c != null)
return c;
}
@ -2661,7 +2661,7 @@ namespace Mono.CSharp @@ -2661,7 +2661,7 @@ namespace Mono.CSharp
return left;
if (left.IsZeroInteger)
return left.TryReduce (ec, right.Type);
return left.Reduce (ec, right.Type);
break;

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

@ -49,13 +49,21 @@ namespace Mono.CSharp { @@ -49,13 +49,21 @@ namespace Mono.CSharp {
// in unreachable code, for instance.
//
if (warn)
bool unreachable = false;
if (warn && !ec.UnreachableReported) {
ec.UnreachableReported = true;
unreachable = true;
ec.Report.Warning (162, 2, loc, "Unreachable code detected");
}
ec.StartFlowBranching (FlowBranching.BranchingType.Block, loc);
bool ok = Resolve (ec);
ec.KillFlowBranching ();
if (unreachable) {
ec.UnreachableReported = false;
}
return ok;
}
@ -1225,7 +1233,7 @@ namespace Mono.CSharp { @@ -1225,7 +1233,7 @@ namespace Mono.CSharp {
res = c;
} else {
TypeSpec type = ec.Switch.SwitchType;
res = c.TryReduce (ec, type);
res = c.Reduce (ec, type);
if (res == null) {
c.Error_ValueCannotBeConverted (ec, type, true);
return false;
@ -2073,9 +2081,7 @@ namespace Mono.CSharp { @@ -2073,9 +2081,7 @@ namespace Mono.CSharp {
#endif
// int assignable_slots;
bool unreachable_shown;
bool unreachable;
public Block (Block parent, Location start, Location end)
: this (parent, 0, start, end)
{
@ -2247,6 +2253,8 @@ namespace Mono.CSharp { @@ -2247,6 +2253,8 @@ namespace Mono.CSharp {
Block prev_block = ec.CurrentBlock;
bool ok = true;
bool unreachable = ec.IsUnreachable;
bool prev_unreachable = unreachable;
ec.CurrentBlock = this;
ec.StartFlowBranching (this);
@ -2279,14 +2287,10 @@ namespace Mono.CSharp { @@ -2279,14 +2287,10 @@ namespace Mono.CSharp {
if (s is EmptyStatement)
continue;
if (!unreachable_shown && !(s is LabeledStatement)) {
if (!ec.UnreachableReported && !(s is LabeledStatement)) {
ec.Report.Warning (162, 2, s.loc, "Unreachable code detected");
unreachable_shown = true;
ec.UnreachableReported = true;
}
Block c_block = s as Block;
if (c_block != null)
c_block.unreachable = c_block.unreachable_shown = true;
}
//
@ -2310,8 +2314,15 @@ namespace Mono.CSharp { @@ -2310,8 +2314,15 @@ namespace Mono.CSharp {
statements [ix] = new EmptyStatement (s.loc);
unreachable = ec.CurrentBranching.CurrentUsageVector.IsUnreachable;
if (unreachable && s is LabeledStatement)
throw new InternalErrorException ("should not happen");
if (unreachable) {
ec.IsUnreachable = true;
} else if (ec.IsUnreachable)
ec.IsUnreachable = false;
}
if (unreachable != prev_unreachable) {
ec.IsUnreachable = prev_unreachable;
ec.UnreachableReported = false;
}
while (ec.CurrentBranching is FlowBranchingLabeled)
@ -2335,17 +2346,21 @@ namespace Mono.CSharp { @@ -2335,17 +2346,21 @@ namespace Mono.CSharp {
public override bool ResolveUnreachable (BlockContext ec, bool warn)
{
unreachable_shown = true;
unreachable = true;
if (warn)
bool unreachable = false;
if (warn && !ec.UnreachableReported) {
ec.UnreachableReported = true;
unreachable = true;
ec.Report.Warning (162, 2, loc, "Unreachable code detected");
}
var fb = ec.StartFlowBranching (FlowBranching.BranchingType.Block, loc);
fb.CurrentUsageVector.IsUnreachable = true;
bool ok = Resolve (ec);
ec.KillFlowBranching ();
if (unreachable)
ec.UnreachableReported = false;
return ok;
}

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

@ -127,6 +127,158 @@ namespace Mono.CSharp { @@ -127,6 +127,158 @@ namespace Mono.CSharp {
return true;
}
}
#if !FULL_AST
/// <summary>
/// This is an arbitrarily seekable StreamReader wrapper.
///
/// It uses a self-tuning buffer to cache the seekable data,
/// but if the seek is too far, it may read the underly
/// stream all over from the beginning.
/// </summary>
public class SeekableStreamReader : IDisposable
{
public const int DefaultReadAheadSize =
4096 / 2;
StreamReader reader;
Stream stream;
char[] buffer;
int read_ahead_length; // the length of read buffer
int buffer_start; // in chars
int char_count; // count of filled characters in buffer[]
int pos; // index into buffer[]
public SeekableStreamReader (Stream stream, Encoding encoding, char[] sharedBuffer = null)
{
this.stream = stream;
this.buffer = sharedBuffer;
InitializeStream (DefaultReadAheadSize);
reader = new StreamReader (stream, encoding, true);
}
public void Dispose ()
{
// Needed to release stream reader buffers
reader.Dispose ();
}
void InitializeStream (int read_length_inc)
{
read_ahead_length += read_length_inc;
int required_buffer_size = read_ahead_length * 2;
if (buffer == null || buffer.Length < required_buffer_size)
buffer = new char [required_buffer_size];
stream.Position = 0;
buffer_start = char_count = pos = 0;
}
/// <remarks>
/// This value corresponds to the current position in a stream of characters.
/// The StreamReader hides its manipulation of the underlying byte stream and all
/// character set/decoding issues. Thus, we cannot use this position to guess at
/// the corresponding position in the underlying byte stream even though there is
/// a correlation between them.
/// </remarks>
public int Position {
get {
return buffer_start + pos;
}
set {
//
// If the lookahead was too small, re-read from the beginning. Increase the buffer size while we're at it
// This should never happen until we are parsing some weird source code
//
if (value < buffer_start) {
InitializeStream (read_ahead_length);
//
// Discard buffer data after underlying stream changed position
// Cannot use handy reader.DiscardBufferedData () because it for
// some strange reason resets encoding as well
//
reader = new StreamReader (stream, reader.CurrentEncoding, true);
}
while (value > buffer_start + char_count) {
pos = char_count;
if (!ReadBuffer ())
throw new InternalErrorException ("Seek beyond end of file: " + (buffer_start + char_count - value));
}
pos = value - buffer_start;
}
}
bool ReadBuffer ()
{
int slack = buffer.Length - char_count;
//
// read_ahead_length is only half of the buffer to deal with
// reads ahead and moves back without re-reading whole buffer
//
if (slack <= read_ahead_length) {
//
// shift the buffer to make room for read_ahead_length number of characters
//
int shift = read_ahead_length - slack;
Array.Copy (buffer, shift, buffer, 0, char_count - shift);
// Update all counters
pos -= shift;
char_count -= shift;
buffer_start += shift;
slack += shift;
}
char_count += reader.Read (buffer, char_count, slack);
return pos < char_count;
}
public char GetChar (int position)
{
if (buffer_start <= position && position < buffer.Length)
return buffer[position];
return '\0';
}
public char[] ReadChars (int fromPosition, int toPosition)
{
char[] chars = new char[toPosition - fromPosition];
if (buffer_start <= fromPosition && toPosition <= buffer_start + buffer.Length) {
Array.Copy (buffer, fromPosition - buffer_start, chars, 0, chars.Length);
} else {
throw new NotImplementedException ();
}
return chars;
}
public int Peek ()
{
if ((pos >= char_count) && !ReadBuffer ())
return -1;
return buffer [pos];
}
public int Read ()
{
if ((pos >= char_count) && !ReadBuffer ())
return -1;
return buffer [pos++];
}
}
#endif
public class UnixUtils {
[System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
extern static int _isatty (int fd);

1
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/PrimitiveExpressionTests.cs

@ -244,7 +244,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression @@ -244,7 +244,6 @@ namespace ICSharpCode.NRefactory.CSharp.Parser.Expression
Assert.AreEqual(code, pe.LiteralValue);
}
[Ignore("Waiting for upstream fix.")]
[Test]
public void LargeVerbatimString()
{

Loading…
Cancel
Save