Merge remote branch 'upstream/master'
[mono.git] / mcs / mcs / cs-tokenizer.cs
index 809ac1d35ccdec280abdff4e6d69d4d57f63e981..4692fccda80b3e80cd5badfa0ae906bff34030d2 100644 (file)
@@ -15,9 +15,7 @@
 using System;
 using System.Text;
 using System.Collections.Generic;
-using System.IO;
 using System.Globalization;
-using System.Reflection;
 using System.Diagnostics;
 
 namespace Mono.CSharp
@@ -303,15 +301,9 @@ namespace Mono.CSharp
                        escaped_identifiers.Add (loc);
                }
 
-               public bool IsEscapedIdentifier (Location loc)
+               public bool IsEscapedIdentifier (MemberName name)
                {
-                       if (escaped_identifiers != null) {
-                               foreach (Location lt in escaped_identifiers)
-                                       if (lt.Equals (loc))
-                                               return true;
-                       }
-
-                       return false;
+                       return escaped_identifiers != null && escaped_identifiers.Contains (name.Location);
                }
 
                //
@@ -361,17 +353,6 @@ namespace Mono.CSharp
 
                static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
                
-               //
-               // Details about the error encoutered by the tokenizer
-               //
-               string error_details;
-               
-               public string error {
-                       get {
-                               return error_details;
-                       }
-               }
-               
                public int Line {
                        get {
                                return ref_line;
@@ -573,6 +554,7 @@ namespace Mono.CSharp
                        AddKeyword ("while", Token.WHILE);
                        AddKeyword ("partial", Token.PARTIAL);
                        AddKeyword ("where", Token.WHERE);
+                       AddKeyword ("async", Token.ASYNC);
 
                        // LINQ keywords
                        AddKeyword ("from", Token.FROM);
@@ -781,6 +763,13 @@ namespace Mono.CSharp
 
                                res = -1;
                                break;
+
+                       case Token.ASYNC:
+                               if (parsing_block > 0 || RootContext.Version != LanguageVersion.Future) {
+                                       res = -1;
+                                       break;
+                               }
+                               break;
                        }
 
                        return res;
@@ -962,6 +951,12 @@ namespace Mono.CSharp
                                case Token.IDENTIFIER:
                                        switch (ptoken) {
                                        case Token.DOT:
+                                               if (bracket_level == 0) {
+                                                       is_type = false;
+                                                       can_be_type = true;
+                                               }
+
+                                               continue;
                                        case Token.OP_GENERICS_LT:
                                        case Token.COMMA:
                                        case Token.DOUBLE_COLON:
@@ -2187,7 +2182,7 @@ namespace Mono.CSharp
                                                                                Report.RegisterWarningRegion (loc).WarningEnable (loc, code, Report);
                                                                        }
                                                                }
-                                                       } while (code >= 0 && c != '\n');
+                                                       } while (code >= 0 && c != '\n' && c != -1);
                                                }
 
                                                return;
@@ -2612,24 +2607,23 @@ namespace Mono.CSharp
                        int c;
                        string_builder.Length = 0;
 
-                       while ((c = get_char ()) != -1){
-                               if (c == '"'){
-                                       if (quoted && peek_char () == '"'){
+                       while (true){
+                               c = get_char ();
+                               if (c == '"') {
+                                       if (quoted && peek_char () == '"') {
                                                string_builder.Append ((char) c);
                                                get_char ();
                                                continue;
-                                       } else {
-                                               val = new StringLiteral (string_builder.ToString (), Location);
-                                               return Token.LITERAL;
                                        }
+
+                                       val = new StringLiteral (string_builder.ToString (), Location);
+                                       return Token.LITERAL;
                                }
 
-                               if (c == '\n'){
+                               if (c == '\n') {
                                        if (!quoted)
                                                Report.Error (1010, Location, "Newline in constant");
-                               }
-
-                               if (!quoted){
+                               } else if (c == '\\' && !quoted) {
                                        int surrogate;
                                        c = escape (c, out surrogate);
                                        if (c == -1)
@@ -2638,12 +2632,13 @@ namespace Mono.CSharp
                                                string_builder.Append ((char) c);
                                                c = surrogate;
                                        }
+                               } else if (c == -1) {
+                                       Report.Error (1039, Location, "Unterminated string literal");
+                                       return Token.EOF;
                                }
+
                                string_builder.Append ((char) c);
                        }
-
-                       Report.Error (1039, Location, "Unterminated string literal");
-                       return Token.EOF;
                }
 
                private int consume_identifier (int s)
@@ -2708,8 +2703,8 @@ namespace Mono.CSharp
                                }
                        } catch (IndexOutOfRangeException) {
                                Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
-                               col += pos - 1;
-                               return Token.ERROR;
+                               --pos;
+                               col += pos;
                        }
 
                        col += pos - 1;
@@ -3219,8 +3214,7 @@ namespace Mono.CSharp
                                        return consume_identifier (c);
                                }
 
-                               error_details = ((char)c).ToString ();
-                               return Token.ERROR;
+                               Report.Error (1056, Location, "Unexpected character `{0}'", ((char) c).ToString ());
                        }
 
                        if (CompleteOnEOF){
@@ -3240,10 +3234,11 @@ namespace Mono.CSharp
                        int c = get_char ();
                        tokens_seen = true;
                        if (c == '\'') {
-                               error_details = "Empty character literal";
-                               Report.Error (1011, Location, error_details);
-                               return Token.ERROR;
+                               val = new CharLiteral ((char) c, Location);
+                               Report.Error (1011, Location, "Empty character literal");
+                               return Token.LITERAL;
                        }
+
                        if (c == '\r' || c == '\n') {
                                Report.Error (1010, Location, "Newline in constant");
                                return Token.ERROR;
@@ -3267,7 +3262,6 @@ namespace Mono.CSharp
                                        if (c == '\n' || c == '\'')
                                                break;
                                }
-                               return Token.ERROR;
                        }
 
                        return Token.LITERAL;