[xbuild] Fix bug #676671. Raise AnyEvent .
[mono.git] / mcs / mcs / cs-parser.jay
index c2920ce94d6706cb56dd959ce91ac004897d5480..71fc5692ba9465936f6cdd9203fa1f1cdf5e6b64 100644 (file)
@@ -115,7 +115,7 @@ namespace Mono.CSharp
 
                /// When using the interactive parser, this holds the
                /// resulting expression
-               public object InteractiveResult;
+               public Class InteractiveResult;
 
                //
                // Keeps track of global data changes to undo on parser error
@@ -124,12 +124,12 @@ namespace Mono.CSharp
                
                Stack<Linq.QueryBlock> linq_clause_blocks;
 
-               // A counter to create new class names in interactive mode
-               static int class_count;
-               
                ModuleContainer module;
                
-               CompilerContext compiler;
+               readonly CompilerContext compiler;
+               readonly LanguageVersion lang_version;
+               readonly bool doc_support;
+               readonly CompilerSettings settings;
                
                //
                // Instead of allocating carrier array everytime we
@@ -409,8 +409,8 @@ extern_alias_directive
                string s = lt.Value;
                if (s != "alias"){
                        syntax_error (lt.Location, "`alias' expected");
-               } else if (RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotAvailable (lt.Location, "external alias");
+               } else if (lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (lt.Location, "external alias");
                } else {
                        lt = (Tokenizer.LocatedToken) $3; 
                        current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
@@ -430,12 +430,12 @@ using_directives
 using_directive
        : using_alias_directive
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        | using_namespace_directive
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
@@ -444,6 +444,11 @@ using_alias_directive
        : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
          {
                var lt = (Tokenizer.LocatedToken) $2;
+               if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
+                       Report.Warning (440, 2, lt.Location,
+                        "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
+               }
+
                current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
          }
        | USING error
@@ -530,7 +535,7 @@ namespace_name
 namespace_body
        : OPEN_BRACE
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_extern_alias_directives
@@ -646,7 +651,7 @@ attribute_sections
                                        $$ = new Attributes (sect);
                                }
                                if ($$ == null) {
-                                       if (RootContext.Documentation != null) {
+                                       if (doc_support) {
                                                Lexer.check_incorrect_doc_comment ();
                                                Lexer.doc_state =
                                                        XmlCommentState.Allowed;
@@ -842,8 +847,8 @@ named_attribute_argument
 named_argument
        : IDENTIFIER COLON opt_named_modifier expression
          {
-               if (RootContext.Version <= LanguageVersion.V_3)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
+               if (lang_version <= LanguageVersion.V_3)
+                       FeatureIsNotAvailable (GetLocation ($1), "named argument");
                        
                // Avoid boxing in common case (no modifier)
                var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
@@ -916,7 +921,7 @@ struct_declaration
 
                current_class.SetParameterInfo ((List<Constraints>) $9);
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_container.DocComment = Lexer.consume_doc_comment ();
 
                lbag.AddMember (current_class, mod_locations, GetLocation ($4));
@@ -924,7 +929,7 @@ struct_declaration
          struct_body
          {
                --lexer.parsing_declaration;      
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_semicolon
@@ -941,7 +946,7 @@ struct_declaration
 struct_body
        : OPEN_BRACE
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_struct_member_declarations CLOSE_BRACE
@@ -996,7 +1001,7 @@ constant_declaration
          }
          constant_initializer opt_constant_declarators SEMICOLON
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1062,7 +1067,7 @@ field_declaration
                lexer.parsing_generic_declaration = false;
 
                FullNamedExpression type = (FullNamedExpression) $3;
-               if (type.Type == TypeManager.void_type)
+               if (type.Type != null && type.Type.Kind == MemberKind.Void)
                        Report.Error (670, GetLocation ($3), "Fields cannot have void type");
                        
                var lt = (Tokenizer.LocatedToken) $4;
@@ -1074,7 +1079,7 @@ field_declaration
          opt_field_declarators
          SEMICOLON
          { 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1087,8 +1092,8 @@ field_declaration
          opt_modifiers
          FIXED simple_type IDENTIFIER
          { 
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
 
                var lt = (Tokenizer.LocatedToken) $5;
                current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
@@ -1098,7 +1103,7 @@ field_declaration
          }
          fixed_field_size opt_fixed_field_declarators SEMICOLON
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
            }
@@ -1227,7 +1232,7 @@ variable_initializer
 method_declaration
        : method_header
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.NotAllowed;
 
                // Add it early in the case of body being eof for full aot
@@ -1244,7 +1249,7 @@ method_declaration
 
                current_local_parameters = null;
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
@@ -1288,7 +1293,7 @@ method_header
                                method.GetSignatureForError ());
                }
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
@@ -1322,7 +1327,7 @@ method_header
                GenericMethod generic = null;
                if (name.TypeArguments != null) {
                        generic = new GenericMethod (current_namespace, current_class, name,
-                               new TypeExpression (TypeManager.void_type, GetLocation ($4)),
+                               new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($4)),
                                current_local_parameters);
 
                        generic.SetParameterInfo ((List<Constraints>) $11);
@@ -1347,10 +1352,10 @@ method_header
                
                modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
                
-               method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
+               method = new Method (current_class, generic, new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($4)),
                                     modifiers, name, current_local_parameters, (Attributes) $1);
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                // TODO: lbag, push void
@@ -1372,7 +1377,7 @@ method_header
 
                current_local_parameters = (ParametersCompiled) $7;
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        method.DocComment = Lexer.consume_doc_comment ();
 
                $$ = method;
@@ -1523,8 +1528,8 @@ fixed_parameter
          constant_expression
          {
                --lexer.parsing_block;
-               if (RootContext.Version <= LanguageVersion.V_3) {
-                       Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
+               if (lang_version <= LanguageVersion.V_3) {
+                       FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
                }
                
                Parameter.Modifier mod = (Parameter.Modifier) $2;
@@ -1612,8 +1617,8 @@ parameter_modifier
                if ((valid_param_mod & ParameterModifierType.This) == 0)
                        Error_ParameterModifierNotValid ("this", GetLocation ($1));
 
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "extension methods");
                                
                $$ = Parameter.Modifier.This;
          }
@@ -1674,15 +1679,16 @@ property_declaration
          member_type
          member_declaration_name
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        tmpComment = Lexer.consume_doc_comment ();
          }
          OPEN_BRACE
          {
-               current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
+               var type = (FullNamedExpression) $3;
+               current_property = new Property (current_class, type, (Modifiers) $2,
                        (MemberName) $4, (Attributes) $1);
                        
-               if (current_property.TypeExpression.Type == TypeManager.void_type)
+               if (type.Type != null && type.Type.Kind == MemberKind.Void)
                        Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());                                     
                        
                current_container.AddProperty ((Property)current_property);
@@ -1694,7 +1700,7 @@ property_declaration
          {
                lexer.PropertyParsing = false;
                
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_property.DocComment = ConsumeStoredComment ();                          
          }
          CLOSE_BRACE
@@ -1714,8 +1720,8 @@ indexer_declaration
          opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
          {
                valid_param_mod = 0;
-         
-               Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+               var type = (FullNamedExpression) $3;
+               Indexer indexer = new Indexer (current_class, type,
                        (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
                        
                current_property = indexer;
@@ -1723,14 +1729,14 @@ indexer_declaration
                current_container.AddIndexer (indexer);
                lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
                
-               if (indexer.TypeExpression.Type == TypeManager.void_type)
+               if (type.Type != null && type.Type.Kind == MemberKind.Void)
                        Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());           
 
                if (indexer.Parameters.IsEmpty) {
                        Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
                }
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1743,7 +1749,7 @@ indexer_declaration
          }
          CLOSE_BRACE
          { 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_property.DocComment = ConsumeStoredComment ();
                        
                lbag.AppendToMember (current_property, GetLocation ($12));
@@ -1773,8 +1779,8 @@ accessor_declarations
 get_accessor_declaration
        : opt_attributes opt_modifiers GET
          {
-               if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+               if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
                }
          
                if (current_property.Get != null) {
@@ -1807,7 +1813,7 @@ get_accessor_declaration
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        if (Lexer.doc_state == XmlCommentState.Error)
                                Lexer.doc_state = XmlCommentState.NotAllowed;
          }
@@ -1816,8 +1822,8 @@ get_accessor_declaration
 set_accessor_declaration
        : opt_attributes opt_modifiers SET 
          {
-               if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
-                       Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+               if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
                }
                
                if (current_property.Set != null) {
@@ -1855,7 +1861,7 @@ set_accessor_declaration
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
-               if (RootContext.Documentation != null
+               if (doc_support
                        && Lexer.doc_state == XmlCommentState.Error)
                        Lexer.doc_state = XmlCommentState.NotAllowed;
          }
@@ -1896,7 +1902,7 @@ interface_declaration
 
                current_class.SetParameterInfo ((List<Constraints>) $9);
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -1904,7 +1910,7 @@ interface_declaration
          OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
          {
                --lexer.parsing_declaration;      
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_semicolon 
@@ -1968,7 +1974,7 @@ operator_declaration
                                current_local_parameters,
                                (ToplevelBlock) $5, (Attributes) $1, decl.location);
 
-                       if (RootContext.Documentation != null) {
+                       if (doc_support) {
                                op.DocComment = tmpComment;
                                Lexer.doc_state = XmlCommentState.Allowed;
                        }
@@ -1993,7 +1999,7 @@ operator_type
        | VOID
          {
                Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
-               $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+               $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
          }
        ;
 
@@ -2034,7 +2040,7 @@ operator_declarator
                        }
                }
                
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2085,7 +2091,7 @@ conversion_operator_declarator
                Location loc = GetLocation ($2);
                current_local_parameters = (ParametersCompiled)$6;  
                  
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2104,7 +2110,7 @@ conversion_operator_declarator
                Location loc = GetLocation ($2);
                current_local_parameters = (ParametersCompiled)$6;  
                  
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2133,13 +2139,13 @@ constructor_declaration
                Constructor c = (Constructor) $1;
                c.Block = (ToplevelBlock) $2;
                
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        c.DocComment = ConsumeStoredComment ();
 
                current_container.AddConstructor (c);
 
                current_local_parameters = null;
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
@@ -2149,7 +2155,7 @@ constructor_declarator
          opt_modifiers
          IDENTIFIER
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2238,7 +2244,7 @@ constructor_initializer
 destructor_declaration
        : opt_attributes opt_modifiers TILDE 
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2256,7 +2262,7 @@ destructor_declaration
                
                Destructor d = new Destructor (current_class, (Modifiers) $2,
                        ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        d.DocComment = ConsumeStoredComment ();
                  
                d.Block = (ToplevelBlock) $8;
@@ -2286,7 +2292,7 @@ event_declaration
          opt_event_declarators
          SEMICOLON
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_event_field.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2314,7 +2320,7 @@ event_declaration
          }
          CLOSE_BRACE
          {
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_event.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2483,12 +2489,12 @@ enum_declaration
          ENUM type_declaration_name
          opt_enum_base
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        enumTypeComment = Lexer.consume_doc_comment ();
          }
          OPEN_BRACE
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
 
                MemberName name = (MemberName) $4;
@@ -2501,17 +2507,17 @@ enum_declaration
          opt_enum_member_declarations
          {
                // here will be evaluated after CLOSE_BLACE is consumed.
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          CLOSE_BRACE opt_semicolon
          {
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        current_class.DocComment = enumTypeComment;
                        
                --lexer.parsing_declaration;
 
-//                     if (RootContext.Documentation != null)
+//                     if (doc_support)
 //                             em.DocComment = ev.DocComment;
 
                lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
@@ -2524,11 +2530,7 @@ opt_enum_base
        | COLON type
         {
                var te = $2 as TypeExpression;
-               if (te == null ||
-                       (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
-                       te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
-                       te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
-                       te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
+               if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
                        Enum.Error_1008 (GetLocation ($2), Report);
                        $$ = null;
                } else {
@@ -2567,7 +2569,7 @@ enum_member_declaration
                var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
                ((Enum) current_class).AddEnumMember (em);
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        em.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2577,7 +2579,7 @@ enum_member_declaration
        | opt_attributes IDENTIFIER
          {
                ++lexer.parsing_block;
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.NotAllowed;
                }
@@ -2591,7 +2593,7 @@ enum_member_declaration
                em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
                ((Enum) current_class).AddEnumMember (em);
                
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        em.DocComment = ConsumeStoredComment ();
 
                $$ = em;
@@ -2617,7 +2619,7 @@ delegate_declaration
                Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
                                             (Modifiers) $2, name, p, (Attributes) $1);
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        del.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -2645,8 +2647,8 @@ opt_nullable
        : /* empty */
        | INTERR_NULLABLE
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "nullable types");
          
                $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
          }
@@ -2688,8 +2690,8 @@ opt_type_argument_list
        : /* empty */
        | OP_GENERICS_LT type_arguments OP_GENERICS_GT
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");      
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "generics");     
          
                $$ = $2;
          }
@@ -2791,8 +2793,8 @@ opt_type_parameter_list
        : /* empty */
        | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "generics");
          
                $$ = $2;
                lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
@@ -2839,7 +2841,7 @@ type_and_void
        : type_expression_or_array
        | VOID
          {
-               $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+               $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
          }
        ;
        
@@ -2858,7 +2860,7 @@ type
        | VOID
          {
                Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
-               $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+               $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
          }     
        ;
        
@@ -2867,7 +2869,7 @@ simple_type
        | VOID
          {
                Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
-               $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+               $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
          }     
        ;
        
@@ -2876,7 +2878,7 @@ parameter_type
        | VOID
          {
                Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
-               $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+               $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
          }     
        ;
 
@@ -2917,7 +2919,7 @@ type_expression
          }
        | VOID pointer_stars
          {
-               $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
+               $$ = new ComposedCast (new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
          }
        ;
 
@@ -2956,25 +2958,25 @@ base_type_name
  * simple types, but we need this to reuse it easily in variable_type
  */
 builtin_types
-       : OBJECT        { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
-       | STRING        { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
-       | BOOL          { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
-       | DECIMAL       { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
-       | FLOAT         { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
-       | DOUBLE        { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
+       : OBJECT        { $$ = new TypeExpression (compiler.BuildinTypes.Object, GetLocation ($1)); }
+       | STRING        { $$ = new TypeExpression (compiler.BuildinTypes.String, GetLocation ($1)); }
+       | BOOL          { $$ = new TypeExpression (compiler.BuildinTypes.Bool, GetLocation ($1)); }
+       | DECIMAL       { $$ = new TypeExpression (compiler.BuildinTypes.Decimal, GetLocation ($1)); }
+       | FLOAT         { $$ = new TypeExpression (compiler.BuildinTypes.Float, GetLocation ($1)); }
+       | DOUBLE        { $$ = new TypeExpression (compiler.BuildinTypes.Double, GetLocation ($1)); }
        | integral_type
        ;
 
 integral_type
-       : SBYTE         { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
-       | BYTE          { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
-       | SHORT         { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
-       | USHORT        { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
-       | INT           { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
-       | UINT          { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
-       | LONG          { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
-       | ULONG         { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
-       | CHAR          { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
+       : SBYTE         { $$ = new TypeExpression (compiler.BuildinTypes.SByte, GetLocation ($1)); }
+       | BYTE          { $$ = new TypeExpression (compiler.BuildinTypes.Byte, GetLocation ($1)); }
+       | SHORT         { $$ = new TypeExpression (compiler.BuildinTypes.Short, GetLocation ($1)); }
+       | USHORT        { $$ = new TypeExpression (compiler.BuildinTypes.UShort, GetLocation ($1)); }
+       | INT           { $$ = new TypeExpression (compiler.BuildinTypes.Int, GetLocation ($1)); }
+       | UINT          { $$ = new TypeExpression (compiler.BuildinTypes.UInt, GetLocation ($1)); }
+       | LONG          { $$ = new TypeExpression (compiler.BuildinTypes.Long, GetLocation ($1)); }
+       | ULONG         { $$ = new TypeExpression (compiler.BuildinTypes.ULong, GetLocation ($1)); }
+       | CHAR          { $$ = new TypeExpression (compiler.BuildinTypes.Char, GetLocation ($1)); }
        ;
 
 //
@@ -3024,8 +3026,8 @@ literal
        ;
 
 boolean_literal
-       : TRUE                  { $$ = new BoolLiteral (true, GetLocation ($1)); }
-       | FALSE                 { $$ = new BoolLiteral (false, GetLocation ($1)); }
+       : TRUE                  { $$ = new BoolLiteral (compiler.BuildinTypes, true, GetLocation ($1)); }
+       | FALSE                 { $$ = new BoolLiteral (compiler.BuildinTypes, false, GetLocation ($1)); }
        ;
 
 
@@ -3377,8 +3379,8 @@ object_or_delegate_creation_expression
        : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
          {
                if ($6 != null) {
-                       if (RootContext.Version <= LanguageVersion.ISO_2)
-                               Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
+                       if (lang_version <= LanguageVersion.ISO_2)
+                               FeatureIsNotAvailable (GetLocation ($1), "object initializers");
                                
                        $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
                } else {
@@ -3389,8 +3391,8 @@ object_or_delegate_creation_expression
          }
        | NEW new_expr_type object_or_collection_initializer
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
          
                $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
          }
@@ -3416,8 +3418,8 @@ array_creation_expression
          }
        | NEW rank_specifier array_initializer
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
          
                $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
          }
@@ -3447,8 +3449,8 @@ new_expr_type
 anonymous_type_expression
        : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
 
                $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
                
@@ -3526,10 +3528,12 @@ rank_specifier
        : OPEN_BRACKET CLOSE_BRACKET
          {
                $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
+               lbag.AddLocation ($$, GetLocation ($2));
          }
        | OPEN_BRACKET dim_separators CLOSE_BRACKET
          {
                $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
+               lbag.AddLocation ($$, GetLocation ($3));
          }
        ;
 
@@ -3567,7 +3571,11 @@ array_initializer
          {
                var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
                ai.VariableDeclaration = current_variable;
-               lbag.AddLocation (ai, GetLocation ($3));
+               if ($3 != null) {
+                       lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
+               } else {
+                       lbag.AddLocation (ai, GetLocation ($4));
+               }
                $$ = ai;
          }
        ;
@@ -3650,8 +3658,8 @@ unbound_type_name
 generic_dimension
        : GENERIC_DIMENSION
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "generics");
 
                $$ = $1;
          }
@@ -3661,8 +3669,8 @@ qualified_alias_member
        : IDENTIFIER DOUBLE_COLON
          {
                var lt = (Tokenizer.LocatedToken) $1;
-               if (RootContext.Version == LanguageVersion.ISO_1)
-                       Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
+               if (lang_version == LanguageVersion.ISO_1)
+                       FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
 
                $$ = lt;                
          }
@@ -3734,8 +3742,8 @@ anonymous_method_signature
 default_value_expression
        : DEFAULT open_parens_any type CLOSE_PARENS
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "default value expression");
 
                $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
@@ -3941,8 +3949,8 @@ null_coalescing_expression
        : conditional_or_expression
        | conditional_or_expression OP_COALESCING null_coalescing_expression
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
+               if (lang_version < LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
                        
                $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
          }
@@ -4103,8 +4111,8 @@ lambda_expression
          }
        | OPEN_PARENS_LAMBDA
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
-                       Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
+               if (lang_version <= LanguageVersion.ISO_2)
+                       FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
          
                valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
          }
@@ -4116,7 +4124,7 @@ lambda_expression
          lambda_expression_body 
          {
                $$ = end_anonymous ((ParametersBlock) $7);
-               lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
+               lbag.AddLocation ($$, GetLocation ($4), GetLocation ($5));
          }
        ;
 
@@ -4160,7 +4168,12 @@ class_declaration
          type_declaration_name
          {
                MemberName name = MakeName ((MemberName) $6);
-               push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
+               Class c = new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1);
+               if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
+                       FeatureIsNotAvailable (c.Location, "static classes");
+               }
+                       
+               push_current_class (c, $3);
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
@@ -4170,7 +4183,7 @@ class_declaration
                current_class.SetParameterInfo ((List<Constraints>) $9);
                lbag.AddMember (current_class, mod_locations, GetLocation ($4));
 
-               if (RootContext.Documentation != null) {
+               if (doc_support) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
@@ -4178,7 +4191,7 @@ class_declaration
          OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
          {
                --lexer.parsing_declaration;
-               if (RootContext.Documentation != null)
+               if (doc_support)
                        Lexer.doc_state = XmlCommentState.Allowed;
          }
          opt_semicolon 
@@ -4297,7 +4310,7 @@ modifier
          {
                $$ = Modifiers.UNSAFE;
                StoreModifierLocation ($$, GetLocation ($1));
-               if (!RootContext.Unsafe)
+               if (!settings.Unsafe)
                        Error_UnsafeCodeNotAllowed (GetLocation ($1));
          }
        | ASYNC
@@ -4423,8 +4436,8 @@ opt_type_parameter_variance
          }
        | type_parameter_variance
          {
-               if (RootContext.Version <= LanguageVersion.V_3)
-                       Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
+               if (lang_version <= LanguageVersion.V_3)
+                       FeatureIsNotAvailable (lexer.Location, "generic type variance");
 
                $$ = $1;
          }
@@ -4686,12 +4699,12 @@ variable_type_simple
          }
        | VOID pointer_stars
          {
-               $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
+               $$ = new ComposedCast (new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
          }       
        | VOID
          {
                Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
-               $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+               $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
          }
        ;
        
@@ -4969,7 +4982,7 @@ switch_section
 switch_labels
        : switch_label 
          {
-               var labels = new List<SwitchLabel> (4);
+               var labels = new List<SwitchLabel> (2);
 
                labels.Add ((SwitchLabel) $1);
                $$ = labels;
@@ -5208,8 +5221,8 @@ yield_statement
                        Report.Error (1003, lt.Location, "; expected");
                } else if ($3 == null) {
                        Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
-               } else if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotAvailable (lt.Location, "iterators");
+               } else if (lang_version == LanguageVersion.ISO_1){
+                       FeatureIsNotAvailable (lt.Location, "iterators");
                }
                
                current_block.ParametersBlock.TopBlock.IsIterator = true;
@@ -5222,8 +5235,8 @@ yield_statement
                string s = lt.Value;
                if (s != "yield"){
                        Report.Error (1003, lt.Location, "; expected");
-               } else if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotAvailable (lt.Location, "iterators");
+               } else if (lang_version == LanguageVersion.ISO_1){
+                       FeatureIsNotAvailable (lt.Location, "iterators");
                }
                
                current_block.ParametersBlock.TopBlock.IsIterator = true;
@@ -5344,7 +5357,7 @@ unchecked_statement
 unsafe_statement
        : UNSAFE
          {
-               if (!RootContext.Unsafe)
+               if (!settings.Unsafe)
                        Error_UnsafeCodeNotAllowed (GetLocation ($1));
          } block {
                $$ = new Unsafe ((Block) $3, GetLocation ($1));
@@ -5367,6 +5380,7 @@ fixed_statement
          {
            start_block (GetLocation ($2));
            
+               current_block.IsCompilerGenerated = true;
                var lt = (Tokenizer.LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
@@ -5393,6 +5407,7 @@ using_statement
          {
            start_block (GetLocation ($2));
            
+               current_block.IsCompilerGenerated = true;
                var lt = (Tokenizer.LocatedToken) $4;
                var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
                current_block.AddLocalName (li);
@@ -5480,7 +5495,7 @@ query_expression
 first_from_clause
        : FROM_FIRST IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5488,7 +5503,7 @@ first_from_clause
          }
        | FROM_FIRST type IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $3;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5503,7 +5518,7 @@ first_from_clause
 nested_from_clause
        : FROM IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $2;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5511,7 +5526,7 @@ nested_from_clause
          }
        | FROM type IDENTIFIER IN expression
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          
                var lt = (Tokenizer.LocatedToken) $3;
                var rv = new Linq.RangeVariable (lt.Value, lt.Location);
@@ -5526,7 +5541,7 @@ nested_from_clause
 from_clause
        : FROM IDENTIFIER IN
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5541,7 +5556,7 @@ from_clause
          }       
        | FROM type IDENTIFIER IN
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5586,7 +5601,7 @@ query_body
 select_or_group_clause
        : SELECT
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5600,7 +5615,7 @@ select_or_group_clause
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
          }
          expression
@@ -5608,7 +5623,7 @@ select_or_group_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          BY expression
          {
@@ -5644,7 +5659,7 @@ query_body_clause
 let_clause
        : LET IDENTIFIER ASSIGN 
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression
          {
@@ -5662,11 +5677,11 @@ let_clause
 where_clause
        : WHERE
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
-         boolean_expression
+         expression
          {
-               $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
+               $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
 
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
@@ -5679,7 +5694,7 @@ join_clause
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression ON
@@ -5687,7 +5702,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression EQUALS
@@ -5696,7 +5711,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression opt_join_into
          {
@@ -5739,7 +5754,7 @@ join_clause
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
                        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression ON
@@ -5747,7 +5762,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
          }
          expression EQUALS
@@ -5756,7 +5771,7 @@ join_clause
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
 
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          expression opt_join_into
          {
@@ -5811,7 +5826,7 @@ opt_join_into
 orderby_clause
        : ORDERBY
          {
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          orderings
          {
@@ -5829,7 +5844,7 @@ orderings
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
          }
          orderings_then_by
          {
@@ -5845,7 +5860,7 @@ orderings_then_by
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
          
-               current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);         
+               current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);   
         }
         then_by
         {
@@ -5896,7 +5911,7 @@ opt_query_continuation
                current_block.SetEndLocation (GetLocation ($1));
                current_block = current_block.Parent;
        
-               current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+               current_block = new Linq.QueryBlock (current_block, lexer.Location);
                
                if (linq_clause_blocks == null)
                        linq_clause_blocks = new Stack<Linq.QueryBlock> ();
@@ -5930,33 +5945,34 @@ opt_query_continuation
 interactive_parsing
        : EVAL_STATEMENT_PARSER EOF 
        | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
-       | EVAL_STATEMENT_PARSER { 
-               Evaluator.LoadAliases (current_namespace);
-
-               push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
-                       Modifiers.PUBLIC, null), null);
-
-               var baseclass_list = new List<FullNamedExpression> ();
-               baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
-               current_container.AddBasesForPart (current_class, baseclass_list);
+       | EVAL_STATEMENT_PARSER
+        { 
+               current_container = new Class (current_namespace, current_class, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
+               current_class = current_container;
 
                // (ref object retval)
                Parameter [] mpar = new Parameter [1];
-               mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
+               mpar [0] = new Parameter (new TypeExpression (compiler.BuildinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
 
                ParametersCompiled pars = new ParametersCompiled (mpar);
+               var mods = Modifiers.PUBLIC | Modifiers.STATIC;
+               if (settings.Unsafe)
+                       mods |= Modifiers.UNSAFE;
+
                current_local_parameters = pars;
                Method method = new Method (
                        current_class,
                        null, // generic
-                       new TypeExpression (TypeManager.void_type, Location.Null),
-                       Modifiers.PUBLIC | Modifiers.STATIC,
+                       new TypeExpression (compiler.BuildinTypes.Void, Location.Null),
+                       mods,
                        new MemberName ("Host"),
                        pars,
                        null /* attributes */);
+                       
+               current_container.AddMethod (method);                   
 
                oob_stack.Push (method);
-               ++lexer.parsing_block;
+               ++lexer.parsing_block;
                start_block (lexer.Location);
          }             
          interactive_statement_list opt_COMPLETE_COMPLETION
@@ -5965,16 +5981,11 @@ interactive_parsing
                Method method = (Method) oob_stack.Pop ();
 
                method.Block = (ToplevelBlock) end_block(lexer.Location);
-               current_container.AddMethod (method);
 
-               --lexer.parsing_declaration;
-               InteractiveResult = pop_current_class ();
+               InteractiveResult = (Class) pop_current_class ();
                current_local_parameters = null;
          } 
-       | EVAL_COMPILATION_UNIT_PARSER {
-               Evaluator.LoadAliases (current_namespace);
-         }
-         interactive_compilation_unit
+       | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
        ;
 
 interactive_compilation_unit
@@ -6054,8 +6065,10 @@ void Error_NamedArgumentExpected (NamedArgument a)
 
 void push_current_class (TypeContainer tc, object partial_token)
 {
-       if (RootContext.EvalMode){
-               tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
+       if (module.Evaluator != null){
+               tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
+               if (undo == null)
+                       undo = new Undo ();
                undo.AddTypeContainer (current_container, tc);
        }
 
@@ -6157,14 +6170,19 @@ static CSharpParser ()
 }
 
 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
+       : this (reader, file, module, new NamespaceEntry (module, null, file, null))
 {
-       if (RootContext.EvalMode)
-               undo = new Undo ();
+}
 
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module, NamespaceEntry ns)
+{
        this.file = file;
        this.module = module;
        this.compiler = module.Compiler;
-       current_namespace = new NamespaceEntry (module, null, file, null);
+       this.settings = compiler.Settings;
+       lang_version = settings.Version;
+       doc_support = settings.Documentation != null;
+       current_namespace = ns;
        current_class = current_namespace.SlaveDeclSpace;
        current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
        oob_stack.Clear ();
@@ -6224,6 +6242,11 @@ string ConsumeStoredComment ()
        return s;
 }
 
+void FeatureIsNotAvailable (Location loc, string feature)
+{
+       compiler.Report.FeatureIsNotAvailable (compiler, loc, feature);
+}
+
 Location GetLocation (object obj)
 {
        var lt = obj as Tokenizer.LocatedToken;
@@ -6278,8 +6301,8 @@ end_block (Location loc)
 
 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
 {
-       if (RootContext.Version == LanguageVersion.ISO_1){
-               Report.FeatureIsNotAvailable (loc, "anonymous methods");
+       if (lang_version == LanguageVersion.ISO_1){
+               FeatureIsNotAvailable (loc, "anonymous methods");
        }
 
        oob_stack.Push (current_anonymous_method);