2
0
Эх сурвалжийг харах

2002-11-13 Gonzalo Paniagua Javier <[email protected]>

	* AspElements.cs: added ServerComment class.
	* AspParser.cs: ignore ServerComments tags. Remove server comments when
	in verbatim mode.

	Fixes #33482.

	* PageCompiler.cs: check if the type is already cached before generating
	the C# file.
	* TemplateFactory.cs: if csFile parameter is null, only checks if we
	already have the page compiled.

svn path=/trunk/mcs/; revision=8974
Gonzalo Paniagua Javier 23 жил өмнө
parent
commit
c8003f30ce

+ 30 - 1
mcs/class/System.Web/System.Web.Compilation/AspElements.cs

@@ -86,6 +86,7 @@ namespace System.Web.Compilation
 		PROPERTYTAG,
 		CODERENDER,
 		DATABINDING,
+		SERVERCOMMENT,
 		NOTYET
 	}
 
@@ -220,6 +221,8 @@ namespace System.Web.Compilation
 		protected bool hasDefaultID;
 		private static int ctrlNumber = 1;
 
+		internal Tag (ElementType etype) : base (etype) { }
+
 		internal Tag (Tag other) :
 			this (other.tag, other.attributes, other.self_closing)
 		{
@@ -296,7 +299,7 @@ namespace System.Web.Compilation
 			get { return hasDefaultID; }
 		}
 		
-		protected void SetNewID ()
+		protected virtual void SetNewID ()
 		{
 			if (attributes == null)
 				attributes = new TagAttributes ();
@@ -776,5 +779,31 @@ namespace System.Web.Compilation
 			get { return "<%#" + Data + "%>"; }
 		}	
 	}
+	
+	class ServerComment : Tag
+	{
+		public ServerComment (string tag)
+			: base (ElementType.TAG)
+		{
+			if (tag == null)
+				throw new ArgumentNullException ();
+
+			this.tag = tag;
+			this.attributes = null;
+			this.tagType = TagType.SERVERCOMMENT;
+			this.self_closing = true;
+			this.hasDefaultID = false;
+		}
+		
+		public override string ToString ()
+		{
+			return TagID;
+		}
+
+		protected override void SetNewID ()
+		{
+			throw new NotSupportedException ();
+		}
+	}
 }
 

+ 1 - 1
mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs

@@ -1343,7 +1343,7 @@ class AspGenerator
 	private Tag Map (Tag tag)
 	{
 		int pos = tag.TagID.IndexOf (":");
-		if (tag is CloseTag || 
+		if (tag is CloseTag ||
 		    ((tag.Attributes == null || 
 		    !tag.Attributes.IsRunAtServer ()) && pos == -1))
 			return tag;

+ 59 - 20
mcs/class/System.Web/System.Web.Compilation/AspParser.cs

@@ -83,10 +83,14 @@ namespace System.Web.Compilation
 					elements.Add (new CloseTag (tag));
 					tokenizer.Verbatim = false;
 				}
-				else if (token == '<'){
+				else if (token == '<') {
 					element = GetTag ();
 					if (element == null)
 						error ();
+
+					if (element is ServerComment)
+						continue;
+
 					if (!(element is Tag)){
 						AddPlainText (((PlainText) element).Text);
 						continue;
@@ -115,27 +119,10 @@ namespace System.Web.Compilation
 		{
 			int token = tokenizer.get_token ();
 			string id;
-			TagAttributes attributes;
 
 			switch (token){
 			case '%':
-				if (Eat ('@')){
-					id = (Eat (Token.DIRECTIVE) ? tokenizer.value : "Page");
-					attributes = GetAttributes ();
-					if (!Eat ('%') || !Eat ('>'))
-						error ("expecting '%>'");
-
-					return new Directive (id, attributes);
-				}
-
-				bool varname = Eat ('=');
-				bool databinding = !varname && Eat ('#');
-				tokenizer.Verbatim = true;
-				string inside_tags = GetVerbatim (tokenizer.get_token (), "%>");
-				tokenizer.Verbatim = false;
-				if (databinding)
-					return new DataBindingTag (inside_tags);
-				return new CodeRenderTag (varname, inside_tags);
+				return GetServerTag ();
 			case '/':
 				if (!Eat (Token.IDENTIFIER))
 					error ("expecting TAGNAME");
@@ -230,8 +217,60 @@ namespace System.Web.Compilation
 			if (token == Token.EOF)
 				return null;
 
-			return vb_text.ToString ();
+			return RemoveComments (vb_text.ToString ());
 		}
+
+		private string RemoveComments (string text)
+		{
+			int end;
+			int start = text.IndexOf ("<%--");
+
+			while (start != -1) {
+				end = text.IndexOf ("--%>");
+				if (end == -1 || end <= start + 1)
+					break;
+
+				text = text.Remove (start, end - start + 4);
+				start = text.IndexOf ("<%--");
+			}
+
+			return text;
+		}
+
+		private Element GetServerTag ()
+		{
+			string id;
+			string inside_tags;
+			TagAttributes attributes;
+
+			if (Eat ('@')){
+				id = (Eat (Token.DIRECTIVE) ? tokenizer.value : "Page");
+				attributes = GetAttributes ();
+				if (!Eat ('%') || !Eat ('>'))
+					error ("expecting '%>'");
+
+				return new Directive (id, attributes);
+			} else if (Eat (Token.DOUBLEDASH)) {
+				tokenizer.Verbatim = true;
+				inside_tags = GetVerbatim (tokenizer.get_token (), "--%>");
+				tokenizer.Verbatim = false;
+				return new ServerComment ("<%--" + inside_tags + "--%>");
+			}
+
+			bool varname;
+			bool databinding;
+			varname = Eat ('=');
+			databinding = !varname && Eat ('#');
+
+			tokenizer.Verbatim = true;
+			inside_tags = GetVerbatim (tokenizer.get_token (), "%>");
+			tokenizer.Verbatim = false;
+			if (databinding)
+				return new DataBindingTag (inside_tags);
+
+			return new CodeRenderTag (varname, inside_tags);
+		}
+
 	}
 
 }

+ 13 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,16 @@
+2002-11-13  Gonzalo Paniagua Javier <[email protected]>
+
+	* AspElements.cs: added ServerComment class.
+	* AspParser.cs: ignore ServerComments tags. Remove server comments when 
+	in verbatim mode.
+
+	Fixes #33482.
+
+	* PageCompiler.cs: check if the type is already cached before generating
+	the C# file.
+	* TemplateFactory.cs: if csFile parameter is null, only checks if we
+	already have the page compiled.
+
 2002-11-02  Gonzalo Paniagua Javier <[email protected]>
 
 	* AspGenerator.cs: undo one-liner change.

+ 4 - 0
mcs/class/System.Web/System.Web.Compilation/PageCompiler.cs

@@ -24,6 +24,10 @@ namespace System.Web.Compilation
 
 		public static Type CompilePageType (PageParser pageParser)
 		{
+			Type t = TemplateFactory.GetTypeFromSource (pageParser.InputFile, null); 
+			if (t != null)
+				return t;
+
 			string sourceFile = GenerateSourceFile (pageParser);
 			WebTrace.WriteLine ("Compiling {0} ({1})", sourceFile, pageParser.InputFile);
 			return TemplateFactory.GetTypeFromSource (pageParser.InputFile, sourceFile);

+ 3 - 3
mcs/class/System.Web/System.Web.Compilation/TemplateFactory.cs

@@ -242,14 +242,14 @@ namespace System.Web.Compilation
 
 		internal static Type GetTypeFromSource (string aspxFile, string csFile)
 		{
-			if (!File.Exists (csFile))
-				return null;
-
 			DateTime filedt = DateTime.Now;
 			Type type = AlreadyGotIt (aspxFile, ref filedt) as Type;
 			if (type != null)
 				return type;
 
+			if (csFile == null || !File.Exists (csFile))
+				return null; //FIXME: throw an exception if the file does not exists
+
 			PageBuilder builder = new PageBuilder (csFile);
 			lock (compiling) {
 				type = AlreadyGotIt (aspxFile, ref filedt) as Type;