In mcs and gmcs:
[mono.git] / mcs / mcs / cs-tokenizer.cs
index 607c9b44dad692839b2b643883600491e9822b6b..c94047322cf4444794735fb0e6dc442a7ca07b5e 100644 (file)
@@ -405,7 +405,7 @@ namespace Mono.CSharp
                        // FIXME: This could be `Location.Push' but we have to
                        // find out why the MS compiler allows this
                        //
-                       Mono.CSharp.Location.Push (file, 0);
+                       Mono.CSharp.Location.Push (file);
                }
 
                static bool is_identifier_start_character (char c)
@@ -696,12 +696,12 @@ namespace Mono.CSharp
                        return seen_digits;
                }
 
-               bool is_hex (int e)
+               static bool is_hex (int e)
                {
                        return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
                }
                                
-               int real_type_suffix (int c)
+               static int real_type_suffix (int c)
                {
                        int t;
 
@@ -858,7 +858,7 @@ namespace Mono.CSharp
                                break;
                        case Token.LITERAL_FLOAT:
                                try {
-                                       val = (float) System.Double.Parse (s, styles, csharp_format_info);
+                                       val = float.Parse (s, styles, csharp_format_info);
                                } catch (OverflowException) {
                                        val = 0.0f;     
                                        Report.Error (594, Location, error_details, "float");
@@ -1160,7 +1160,7 @@ namespace Mono.CSharp
                        return val;
                }
 
-               bool IsCastToken (int token)
+               static bool IsCastToken (int token)
                {
                        switch (token) {
                        case Token.BANG:
@@ -1270,13 +1270,13 @@ namespace Mono.CSharp
                //
                bool PreProcessLine (string arg)
                {
-                       if (arg == "")
+                       if (arg.Length == 0)
                                return false;
 
                        if (arg == "default"){
                                ref_line = line;
                                ref_name = file_name;
-                               Location.Push (ref_name, line);
+                               Location.Push (ref_name);
                                return true;
                        } else if (arg == "hidden"){
                                //
@@ -1298,7 +1298,7 @@ namespace Mono.CSharp
                                        ref_name = Location.LookupFile (name);
                                        file_name.HasLineDirective = true;
                                        ref_name.HasLineDirective = true;
-                                       Location.Push (ref_name, ref_line);
+                                       Location.Push (ref_name);
                                } else {
                                        ref_line = System.Int32.Parse (arg);
                                }
@@ -1314,7 +1314,7 @@ namespace Mono.CSharp
                //
                void PreProcessDefinition (bool is_define, string arg)
                {
-                       if (arg == "" || arg == "true" || arg == "false"){
+                       if (arg.Length == 0 || arg == "true" || arg == "false"){
                                Report.Error (1001, Location, "Missing identifer to pre-processor directive");
                                return;
                        }
@@ -1595,13 +1595,6 @@ namespace Mono.CSharp
                // 
                bool process_directives = true;
 
-               // get current status of if blocks.
-               bool is_inside_disabled_block ()
-               {
-                       return ifstack != null && ifstack.Count != 0 &&
-                               ((int) ifstack.Peek ()) & TAKING == 0;
-               }
-
                //
                // if true, then the code continues processing the code
                // if false, the code stays in a loop until another directive is
@@ -1611,7 +1604,6 @@ namespace Mono.CSharp
                {
                        string cmd, arg;
                        bool region_directive = false;
-                       current_location = new Location (ref_line, Col);
 
                        get_cmd_arg (out cmd, out arg);
 
@@ -1632,22 +1624,12 @@ namespace Mono.CSharp
 
                                PreProcessPragma (arg);
                                return caller_is_taking;
-                       case "define":
-                               if (any_token_seen){
-                                       Error_TokensSeen ();
-                                       return true;
-                               }
-                               if (caller_is_taking)
-                                       PreProcessDefinition (true, arg);
-                               return true;
 
-                       case "undef":
-                               if (any_token_seen){
-                                       Error_TokensSeen ();
-                                       return caller_is_taking;
-                               }
-                               if (caller_is_taking)
-                                       PreProcessDefinition (false, arg);
+                       case "line":
+                               if (!PreProcessLine (arg))
+                                       Report.Error (
+                                               1576, Location,
+                                               "The line number specified for #line directive is missing or invalid");
                                return caller_is_taking;
 
                        case "region":
@@ -1660,13 +1642,13 @@ namespace Mono.CSharp
                                goto case "endif";
                                
                        case "if":
-                               if (arg == ""){
+                               if (arg.Length == 0){
                                        Error_InvalidDirective ();
                                        return true;
                                }
                                bool taking = false;
                                if (ifstack == null)
-                                       ifstack = new Stack ();
+                                       ifstack = new Stack (2);
 
                                if (ifstack.Count == 0){
                                        taking = true;
@@ -1780,14 +1762,6 @@ namespace Mono.CSharp
                                        
                                        return ret;
                                }
-                       case "line":
-                       case "error":
-                       case "warning":
-                               // processed only when current code block is not disabled.
-                               break; 
-                       default:
-                               Report.Error (1024, Location, "Wrong preprocessor directive");
-                               return caller_is_taking;
                        }
 
                        //
@@ -1797,12 +1771,21 @@ namespace Mono.CSharp
                                return false;
                                        
                        switch (cmd){
-                       case "line":
-                               if (!PreProcessLine (arg))
-                                       Report.Error (
-                                               1576, Location,
-                                               "The line number specified for #line directive is missing or invalid");
-                               return caller_is_taking;
+                       case "define":
+                               if (any_token_seen){
+                                       Error_TokensSeen ();
+                                       return true;
+                               }
+                               PreProcessDefinition (true, arg);
+                               return true;
+
+                       case "undef":
+                               if (any_token_seen){
+                                       Error_TokensSeen ();
+                                       return true;
+                               }
+                               PreProcessDefinition (false, arg);
+                               return true;
 
                        case "error":
                                Report.Error (1029, Location, "#error: '" + arg + "'");
@@ -1812,7 +1795,10 @@ namespace Mono.CSharp
                                Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
                                return true;
                        }
+
+                       Report.Error (1024, Location, "Wrong preprocessor directive");
                        return true;
+
                }
 
                private int consume_string (bool quoted)