2007-12-28 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Fri, 28 Dec 2007 00:51:57 +0000 (00:51 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Fri, 28 Dec 2007 00:51:57 +0000 (00:51 -0000)
* PageCompiler.cs: MS.NET compatibility: added the
__fileDependencies object to the generated class.
Refactored the output to match MS.NET more closely.
IHttpHandler or IHttpAsyncHandler are now added to the generated
class list of implemented interfaces.

* BaseCompiler.cs: Main class field references are prefixed with
'global::' now.
Refactored the output to match MS.NET more closely.

svn path=/trunk/mcs/; revision=91973

mcs/class/System.Web/System.Web.Compilation/BaseCompiler.cs
mcs/class/System.Web/System.Web.Compilation/ChangeLog
mcs/class/System.Web/System.Web.Compilation/PageCompiler.cs

index 49c1d8963baef7d890b5c576bcf2c90bf86c106c..4f577bf008ec3d99c591843ca78a4cf67440e672 100644 (file)
@@ -183,6 +183,18 @@ namespace System.Web.Compilation
                        CreateConstructor (null, null);
                }
 
+               internal CodeFieldReferenceExpression GetMainClassFieldReferenceExpression (string fieldName)
+               {
+                       CodeTypeReference mainClassTypeRef;
+                       mainClassTypeRef = new CodeTypeReference (mainNS.Name + "." + mainClass.Name);
+
+#if NET_2_0
+                       mainClassTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
+#endif
+                       return new CodeFieldReferenceExpression (
+                               new CodeTypeReferenceExpression (mainClassTypeRef), fieldName);
+               }
+               
                protected virtual void CreateStaticFields ()
                {
                        CodeMemberField fld = new CodeMemberField (typeof (bool), "__initialized");
@@ -227,21 +239,14 @@ namespace System.Web.Compilation
                        ctor.Attributes = MemberAttributes.Public;
                        mainClass.Members.Add (ctor);
 
-#if NET_2_0
-                       AssignAppRelativeVirtualPath (ctor);
-#endif
                        if (localVars != null)
                                ctor.Statements.AddRange (localVars);
 
-                       CodeTypeReferenceExpression r;
 #if NET_2_0
-                       if (parser.IsPartial)
-                               r = new CodeTypeReferenceExpression (mainClass.Name);
-                       else
+                       AssignAppRelativeVirtualPath (ctor);
 #endif
-                       r = new CodeTypeReferenceExpression (mainNS.Name + "." + mainClass.Name);
-                       CodeFieldReferenceExpression initialized;
-                       initialized = new CodeFieldReferenceExpression (r, "__initialized");
+
+                       CodeFieldReferenceExpression initialized = GetMainClassFieldReferenceExpression ("__initialized");
                        
                        CodeBinaryOperatorExpression bin;
                        bin = new CodeBinaryOperatorExpression (initialized,
@@ -251,9 +256,12 @@ namespace System.Web.Compilation
                        CodeAssignStatement assign = new CodeAssignStatement (initialized,
                                                                              new CodePrimitiveExpression (true));
 
-                       CodeConditionStatement cond = new CodeConditionStatement (bin, assign);
+                       CodeConditionStatement cond = new CodeConditionStatement ();
+                       cond.Condition = bin;
+                       
                        if (trueStmt != null)
                                cond.TrueStatements.AddRange (trueStmt);
+                       cond.TrueStatements.Add (assign);
                        
                        ctor.Statements.Add (cond);
                }
index 01a163f5d34dbb824a832d814b58d94f7258d187..e1d2497a823d7a87d7f72420094e3f104fe2fefe 100644 (file)
@@ -1,3 +1,15 @@
+2007-12-28  Marek Habersack  <mhabersack@novell.com>
+
+       * PageCompiler.cs: MS.NET compatibility: added the
+       __fileDependencies object to the generated class.
+       Refactored the output to match MS.NET more closely.
+       IHttpHandler or IHttpAsyncHandler are now added to the generated
+       class list of implemented interfaces.
+       
+       * BaseCompiler.cs: Main class field references are prefixed with
+       'global::' now. 
+       Refactored the output to match MS.NET more closely.
+
 2007-12-27  Marek Habersack  <mhabersack@novell.com>
 
        * BaseCompiler.cs: check for base type globality in all the
index 9519e65b319c3ff119c72a27b34eda70a84a9703..1287861c83e11235020534decf23088945f0fc4f 100644 (file)
@@ -29,6 +29,7 @@
 //
 using System;
 using System.CodeDom;
+using System.Collections;
 using System.IO;
 using System.Reflection;
 using System.Text;
@@ -53,6 +54,18 @@ namespace System.Web.Compilation
                        this.pageParser = pageParser;
                }
 
+#if NET_2_0
+               protected override void CreateStaticFields ()
+               {
+                       base.CreateStaticFields ();
+                       
+                       CodeMemberField fld = new CodeMemberField (typeof (object), "__fileDependencies");
+                       fld.Attributes = MemberAttributes.Private | MemberAttributes.Static;
+                       fld.InitExpression = new CodePrimitiveExpression (null);
+                       mainClass.Members.Add (fld);
+               }
+#endif
+               
                protected override void CreateConstructor (CodeStatementCollection localVars,
                                                           CodeStatementCollection trueStmt)
                {
@@ -65,6 +78,48 @@ namespace System.Web.Compilation
                                localVars.Add (new CodeAssignStatement (prop, ct));
                        }
 
+#if NET_2_0
+                       ArrayList deps = pageParser.Dependencies;
+                       int depsCount = deps != null ? deps.Count : 0;
+                       
+                       if (depsCount > 0) {
+                               if (localVars == null)
+                                       localVars = new CodeStatementCollection ();
+                               if (trueStmt == null)
+                                       trueStmt = new CodeStatementCollection ();
+
+                               localVars.Add (
+                                       new CodeVariableDeclarationStatement (
+                                               typeof (string[]),
+                                               "dependencies")
+                               );
+
+                               CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression ("dependencies");
+                               trueStmt.Add (
+                                       new CodeAssignStatement (dependencies, new CodeArrayCreateExpression (typeof (string), depsCount))
+                               );
+                               
+                               CodeArrayIndexerExpression arrayIndex;
+                               CodeAssignStatement assign;
+                               object o;
+                               
+                               for (int i = 0; i < depsCount; i++) {
+                                       o = deps [i];
+                                       arrayIndex = new CodeArrayIndexerExpression (dependencies, new CodeExpression[] {new CodePrimitiveExpression (i)});
+                                       assign = new CodeAssignStatement (arrayIndex, new CodePrimitiveExpression (o));
+                                       trueStmt.Add (assign);
+                               }
+                               
+                               CodeMethodInvokeExpression getDepsCall = new CodeMethodInvokeExpression (
+                                       thisRef,
+                                       "GetWrappedFileDependencies",
+                                       new CodeExpression[] {dependencies}
+                               );
+
+                               assign = new CodeAssignStatement (GetMainClassFieldReferenceExpression ("__fileDependencies"), getDepsCall);
+                               trueStmt.Add (assign);
+                       }
+#endif
                        base.CreateConstructor (localVars, trueStmt);
                }
                
@@ -74,9 +129,8 @@ namespace System.Web.Compilation
                        CodeTypeReference cref;
                        
                        if (pageParser.EnableSessionState) {
-                               cref = new CodeTypeReference (typeof(IRequiresSessionState));
+                               cref = new CodeTypeReference (typeof (IRequiresSessionState));
 #if NET_2_0
-                               cref.Options |= CodeTypeReferenceOptions.GlobalReference;
                                if (partialClass != null)
                                        partialClass.BaseTypes.Add (cref);
                                else
@@ -87,13 +141,20 @@ namespace System.Web.Compilation
                        if (pageParser.ReadOnlySessionState) {
                                cref = new CodeTypeReference (typeof (IReadOnlySessionState));
 #if NET_2_0
-                               cref.Options |= CodeTypeReferenceOptions.GlobalReference;
                                if (partialClass != null)
                                        partialClass.BaseTypes.Add (cref);                                      
                                else
 #endif
                                        mainClass.BaseTypes.Add (cref);
                        }
+
+#if NET_2_0
+                       if (pageParser.Async)
+                               cref = new CodeTypeReference (typeof (System.Web.IHttpAsyncHandler));
+                       else
+                               cref = new CodeTypeReference (typeof (System.Web.IHttpHandler));
+                       mainClass.BaseTypes.Add (cref);
+#endif
                }
 
                void CreateGetTypeHashCode () 
@@ -160,6 +221,24 @@ namespace System.Web.Compilation
 
                protected override void AppendStatementsToFrameworkInitialize (CodeMemberMethod method)
                {
+                       base.AppendStatementsToFrameworkInitialize (method);
+                       
+#if NET_2_0
+                       ArrayList deps = pageParser.Dependencies;
+                       int depsCount = deps != null ? deps.Count : 0;
+                       
+                       if (depsCount > 0) {
+                               CodeFieldReferenceExpression fileDependencies = GetMainClassFieldReferenceExpression ("__fileDependencies");
+
+                               method.Statements.Add (
+                                       new CodeMethodInvokeExpression (
+                                               thisRef,
+                                               "AddWrappedFileDependencies",
+                                               new CodeExpression[] {fileDependencies})
+                               );
+                       }
+#endif
+                       
                        string responseEncoding = pageParser.ResponseEncoding;
                        if (responseEncoding != null)
                                method.Statements.Add (CreatePropertyAssign ("ResponseEncoding", responseEncoding));
@@ -246,8 +325,6 @@ namespace System.Web.Compilation
                                method.Statements.Add (stmt);
                        }
 #endif
-                        
-                       base.AppendStatementsToFrameworkInitialize (method);
                }
 
                private CodeExpression[] OutputCacheParams ()