[Monodevelop-patches-list] r2230 - in trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory: . src src/PrettyPrinter

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Thu Feb 3 15:05:45 EST 2005


Author: jluke
Date: 2005-02-03 15:05:44 -0500 (Thu, 03 Feb 2005)
New Revision: 2230

Added:
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/a.cs
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintOptions.cs
Modified:
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/ChangeLog
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/Makefile.am
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/Main.cs
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/OutputFormatter.cs
   trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintVisitor.cs
Log:
pretty printing testing



Property changes on: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
ICSharpCode.SharpRefactory.dll
ICSharpCode.SharpRefactory.dll.mdb
SharpRefactory.pidb

   + Makefile
Makefile.in
ICSharpCode.SharpRefactory.dll
ICSharpCode.SharpRefactory.dll.mdb
SharpRefactory.pidb
test-parser.exe


Modified: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/ChangeLog	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/ChangeLog	2005-02-03 20:05:44 UTC (rev 2230)
@@ -1,3 +1,12 @@
+2005-02-03  John Luke  <john.luke at gmail.com>
+
+	* Makefile.am: add PrettyPrintOptions.cs
+	* src/PrettyPrinter/PrettyPrintVisitor.cs:
+	* src/PrettyPrinter/OutputFormatter.cs
+	* src/PrettyPrinter/PrettyPrintOptions.cs:
+	update these from SD, and make it output
+	mono-like format by default (not done yet)
+
 2005-01-31  John Luke  <john.luke at gmail.com>
 
 	* src/Parser/generated/Error.cs: lets not

Modified: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/Makefile.am
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/Makefile.am	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/Makefile.am	2005-02-03 20:05:44 UTC (rev 2230)
@@ -105,6 +105,7 @@
 src/Parser/generated/keywordlist/Keywords.cs \
 src/PrettyPrinter/OutputFormatter.cs \
 src/PrettyPrinter/PrettyPrintVisitor.cs \
+src/PrettyPrinter/PrettyPrintOptions.cs \
 src/PrettyPrinter/PrettyPrintUtil.cs \
 src/PrettyPrinter/PrettyPrintData.cs \
 src/PrettyPrinter/SpecialVisitor.cs \

Added: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/a.cs
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/a.cs	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/a.cs	2005-02-03 20:05:44 UTC (rev 2230)
@@ -0,0 +1,104 @@
+using System; using System.Reflection;
+using Blah = Gtk.Window;
+
+namespace Foo
+{
+	public interface IFoo
+	{
+		int Dummy { get; set; }
+		void DummyMethod();
+		event EventHandler Fooed;
+	}
+
+		[Flags]
+			[Serializable]
+	public enum FooFlags : int
+	{
+		None = 1,
+	}
+
+	public class Bar : System.Object {
+
+		static string a, b, c;
+
+		static void Moo (out string a, ref string b)
+		{
+		}
+
+		static void Main(string[]  args)
+		{
+			int foo 			= 			5;
+			this.Fooed += new EventHandler (OnFooed);
+
+			this.Moo (out a, ref b);
+
+			foo = sizeof (IntPtr);
+
+			base.GetHashCode ();
+
+			FooFlags |= FakeFlags.None;
+
+			if (this is object)
+			{}
+
+			string[] names = new string[] {""};
+
+			unsafe { /* blah */ a++; }
+
+			checked { }
+
+			//unchecked ((int) 0x80000000) {}
+			unchecked {}
+
+			// this wont compile
+			fixed (byte* buf = &buffer[offset]) {}
+
+			using (StreamReader r = new StreamReader()) {}
+
+			foreach (string s in args)
+			{
+				Console.Write(s);
+			}
+
+			for(;;){}
+
+			while (true){}
+
+			do {
+			}
+			while (true);
+
+			lock (typeof (Bar)) { }
+
+			switch (args[0]) {
+				case "a":
+					break;
+				case "b":
+					goto fancy_label;
+				default:
+					break;
+			}
+
+		fancy_label:
+			throw;
+
+		try {} catch (Exception e) {} finally {}
+
+			return 0;
+		}
+
+		~Bar ()
+		{
+		}
+
+		public Bar () : base ()
+		{
+		}
+
+		public Bar (string foo) : this () {}
+	}
+
+	public struct Baz {
+	}
+
+}

Modified: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/Main.cs
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/Main.cs	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/Main.cs	2005-02-03 20:05:44 UTC (rev 2230)
@@ -87,7 +87,6 @@
 			string content = sr.ReadToEnd();
 			sr.Close();
 			PrettyPrintVisitor ppv = new PrettyPrintVisitor(content);
-			Console.WriteLine (typeof (PrettyPrintVisitor));
 			ppv.Visit(p.compilationUnit, null);
 			
 			Console.WriteLine(ppv.Text);

Modified: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/OutputFormatter.cs
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/OutputFormatter.cs	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/OutputFormatter.cs	2005-02-03 20:05:44 UTC (rev 2230)
@@ -30,9 +30,13 @@
 		int           indentationLevel = 0;
 		StringBuilder text             = new StringBuilder();
 		Lexer         lexer; 
-		bool          indent       = true;
+		
+		PrettyPrintOptions prettyPrintOptions;
+		
+		bool          indent         = true;
 		bool          doNewLine      = true;
-		bool          emitSemicolon = true;
+		bool          emitSemicolon  = true;
+		
 		public string Text {
 			get {
 				return text.ToString();
@@ -73,8 +77,9 @@
 			}
 		}
 		Token token;
-		public OutputFormatter(string originalSourceFile)
+		public OutputFormatter(string originalSourceFile, PrettyPrintOptions prettyPrintOptions)
 		{
+			this.prettyPrintOptions = prettyPrintOptions;
 			lexer = new Lexer(new StringReader(originalSourceFile));
 //			token = lexer.NextToken();
 //			PrintSpecials(token.kind);
@@ -83,8 +88,18 @@
 		public void Indent()
 		{
 			if (DoIndent) {
-				for (int i = 0; i < indentationLevel; ++i) {
-					text.Append('\t');
+				int indent = 0;
+				while (indent < prettyPrintOptions.IndentSize * indentationLevel) {
+					char ch = prettyPrintOptions.IndentationChar;
+					if (ch == '\t' && indent + prettyPrintOptions.TabSize > prettyPrintOptions.IndentSize * indentationLevel) {
+						ch = ' ';
+					}
+					text.Append(ch);
+					if (ch == '\t') {
+						indent += prettyPrintOptions.TabSize;
+					} else {
+						++indent;
+					}
 				}
 			}
 		}
@@ -109,28 +124,29 @@
 					case CommentType.SingleLine:
 						text.Append("//");	
 						text.Append(comment.CommentText);	
-						text.Append("\n");
+						text.Append(Environment.NewLine);
 						Indent();
 						break;
 					case CommentType.Documentation:
 						text.Append("///");	
 						text.Append(comment.CommentText);	
-						text.Append("\n");	
+						text.Append(Environment.NewLine);	
 						Indent();
 						break;
 					case CommentType.Block:
 						text.Append("/*");	
 						text.Append(comment.CommentText);	
-						text.Append("*/\n");	
+						text.Append("*/");
+						text.Append(Environment.NewLine);	
 						Indent();
 						break;
 				}
 				PrintSpecials(tokenKind);
 			} else if (o is BlankLine) {
-				if (!gotBlankLine) {
-//						text.Append("\n");
-//						Indent();
-				} 
+				/*if (!gotBlankLine) {
+						text.Append(Environment.NewLine);
+						Indent();
+				}*/
 				gotBlankLine = false;
 				PrintSpecials(tokenKind);
 			} else if (o is PreProcessingDirective) { 
@@ -142,7 +158,7 @@
 					text.Append(" ");
 					text.Append(ppd.Arg);
 				}
-				text.Append("\n");
+				text.Append(Environment.NewLine);
 				Indent();
 				PrintSpecials(tokenKind);
 			} else {
@@ -157,7 +173,7 @@
 		public void NewLine()
 		{
 			if (DoNewLine) {
-				text.Append("\n");
+				text.Append(Environment.NewLine);
 				gotBlankLine = true;
 			}
 		}
@@ -215,5 +231,69 @@
 			PrintSpecials(token.kind);
 			text.Append(identifier);
 		}
+		
+		Stack braceStack = new Stack();
+		
+		public void BeginBrace(BraceStyle style)
+		{
+			switch (style) {
+				case BraceStyle.EndOfLine:
+					text.Append(" ");
+					PrintToken(Tokens.OpenCurlyBrace);
+					NewLine();
+					++IndentationLevel;
+					break;
+				case BraceStyle.NextLine:
+					NewLine();
+					Indent();
+					PrintToken(Tokens.OpenCurlyBrace);
+					NewLine();
+					++IndentationLevel;
+					break;
+				case BraceStyle.NextLineShifted:
+					NewLine();
+					++IndentationLevel;
+					Indent();
+					PrintToken(Tokens.OpenCurlyBrace);
+					NewLine();
+					break;
+				case BraceStyle.NextLineShifted2:
+					NewLine();
+					++IndentationLevel;
+					Indent();
+					PrintToken(Tokens.OpenCurlyBrace);
+					NewLine();
+					++IndentationLevel;
+					break;
+			}
+			braceStack.Push(style);
+		}
+		
+		public void EndBrace()
+		{
+			BraceStyle style = (BraceStyle)braceStack.Pop();
+			switch (style) {
+				case BraceStyle.EndOfLine:
+				case BraceStyle.NextLine:
+					--IndentationLevel;
+					Indent();
+					PrintToken(Tokens.CloseCurlyBrace);
+					NewLine();
+					break;
+				case BraceStyle.NextLineShifted:
+					Indent();
+					PrintToken(Tokens.CloseCurlyBrace);
+					NewLine();
+					--IndentationLevel;
+					break;
+				case BraceStyle.NextLineShifted2:
+					--IndentationLevel;
+					Indent();
+					PrintToken(Tokens.CloseCurlyBrace);
+					NewLine();
+					--IndentationLevel;
+					break;
+			}
+		}
 	}
 }

Added: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintOptions.cs
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintOptions.cs	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintOptions.cs	2005-02-03 20:05:44 UTC (rev 2230)
@@ -0,0 +1,185 @@
+// OutputFormatter.cs
+// Copyright (C) 2003 Mike Krueger (mike at icsharpcode.net)
+// 
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+using System;
+using System.Text;
+using System.Collections;
+using System.Diagnostics;
+
+using ICSharpCode.SharpRefactory.Parser;
+using ICSharpCode.SharpRefactory.Parser.AST;
+
+namespace ICSharpCode.SharpRefactory.PrettyPrinter
+{
+	public enum BraceStyle {
+		EndOfLine,
+		NextLine,
+		NextLineShifted,
+		NextLineShifted2
+	}
+	
+	/// <summary>
+	/// Description of PrettyPrintOptions.	
+	/// </summary>
+	public class PrettyPrintOptions
+	{
+		char indentationChar = '\t';
+		int  tabSize         = 4;
+		int  indentSize      = 4;
+		
+		BraceStyle nameSpaceBraceStyle = BraceStyle.NextLine;
+		BraceStyle classBraceStyle     = BraceStyle.NextLine;
+		BraceStyle interfaceBraceStyle = BraceStyle.NextLine;
+		BraceStyle structBraceStyle    = BraceStyle.NextLine;
+		BraceStyle enumBraceStyle      = BraceStyle.NextLine;
+		
+		BraceStyle constructorBraceStyle  = BraceStyle.NextLine; // was EndOfLine
+		BraceStyle destructorBraceStyle   = BraceStyle.NextLine; // was EndOfLine
+		BraceStyle methodBraceStyle       = BraceStyle.NextLine; // was EndOfLine
+		
+		BraceStyle propertyBraceStyle     = BraceStyle.EndOfLine;
+		BraceStyle propertyGetBraceStyle  = BraceStyle.EndOfLine;
+		BraceStyle propertySetBraceStyle  = BraceStyle.EndOfLine;
+		
+		public char IndentationChar {
+			get {
+				return indentationChar;
+			}
+			set {
+				indentationChar = value;
+			}
+		}
+		
+		public int TabSize {
+			get {
+				return tabSize;
+			}
+			set {
+				tabSize = value;
+			}
+		}
+		
+		public int IndentSize {
+			get {
+				return indentSize;
+			}
+			set {
+				indentSize = value;
+			}
+		}
+		
+		public BraceStyle NameSpaceBraceStyle {
+			get {
+				return nameSpaceBraceStyle;
+			}
+			set {
+				nameSpaceBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle ClassBraceStyle {
+			get {
+				return classBraceStyle;
+			}
+			set {
+				classBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle InterfaceBraceStyle {
+			get {
+				return interfaceBraceStyle;
+			}
+			set {
+				interfaceBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle StructBraceStyle {
+			get {
+				return structBraceStyle;
+			}
+			set {
+				structBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle EnumBraceStyle {
+			get {
+				return enumBraceStyle;
+			}
+			set {
+				enumBraceStyle = value;
+			}
+		}
+		
+		
+		public BraceStyle ConstructorBraceStyle {
+			get {
+				return constructorBraceStyle;
+			}
+			set {
+				constructorBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle DestructorBraceStyle {
+			get {
+				return destructorBraceStyle;
+			}
+			set {
+				destructorBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle MethodBraceStyle {
+			get {
+				return methodBraceStyle;
+			}
+			set {
+				methodBraceStyle = value;
+			}
+		}
+		
+		public BraceStyle PropertyBraceStyle {
+			get {
+				return propertyBraceStyle;
+			}
+			set {
+				propertyBraceStyle = value;
+			}
+		}
+		public BraceStyle PropertyGetBraceStyle {
+			get {
+				return propertyGetBraceStyle;
+			}
+			set {
+				propertyGetBraceStyle = value;
+			}
+		}
+		public BraceStyle PropertySetBraceStyle {
+			get {
+				return propertySetBraceStyle;
+			}
+			set {
+				propertySetBraceStyle = value;
+			}
+		}
+		
+		
+	}
+}

Modified: trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintVisitor.cs
===================================================================
--- trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintVisitor.cs	2005-02-03 17:10:42 UTC (rev 2229)
+++ trunk/MonoDevelop/Core/src/ICSharpCode.SharpRefactory/src/PrettyPrinter/PrettyPrintVisitor.cs	2005-02-03 20:05:44 UTC (rev 2230)
@@ -29,21 +29,29 @@
 	{
 		Errors  errors = new Errors();
 		OutputFormatter outputFormatter;
+		PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions();
 		
 		public string Text {
 			get {
 				return outputFormatter.Text;
 			}
 		}
+		
 		public Errors Errors {
 			get {
 				return errors;
 			}
 		}
 		
+		public PrettyPrintOptions PrettyPrintOptions {
+			get {
+				return prettyPrintOptions;
+			}
+		}
+		
 		public PrettyPrintVisitor(string originalSourceFile)
 		{
-			outputFormatter = new OutputFormatter(originalSourceFile);
+			outputFormatter = new OutputFormatter(originalSourceFile, prettyPrintOptions);
 		}
 		
 		public override object Visit(INode node, object data)
@@ -67,28 +75,30 @@
 			for (int j = 0; j < section.Attributes.Count; ++j) {
 				ICSharpCode.SharpRefactory.Parser.AST.Attribute a = (ICSharpCode.SharpRefactory.Parser.AST.Attribute)section.Attributes[j];
 				outputFormatter.PrintIdentifier(a.Name);
-				outputFormatter.PrintToken(Tokens.OpenParenthesis);
-				this.AppendCommaSeparatedList(a.PositionalArguments);
+				if (a.PositionalArguments != null && a.PositionalArguments.Count > 0) {
+					outputFormatter.PrintToken(Tokens.OpenParenthesis);
+					this.AppendCommaSeparatedList(a.PositionalArguments);
 				
-				if (a.NamedArguments != null && a.NamedArguments.Count > 0) {
-					if (a.PositionalArguments.Count > 0) {
-						outputFormatter.PrintToken(Tokens.Comma);
-						outputFormatter.Space();
-					}
-					for (int i = 0; i < a.NamedArguments.Count; ++i) {
-						NamedArgument n = (NamedArgument)a.NamedArguments[i];
-						outputFormatter.PrintIdentifier(n.Name);
-						outputFormatter.Space();
-						outputFormatter.PrintToken(Tokens.Assign);
-						outputFormatter.Space();
-						n.Expr.AcceptVisitor(this, data);
-						if (i + 1 < a.NamedArguments.Count) {
+					if (a.NamedArguments != null && a.NamedArguments.Count > 0) {
+						if (a.PositionalArguments.Count > 0) {
 							outputFormatter.PrintToken(Tokens.Comma);
 							outputFormatter.Space();
 						}
+						for (int i = 0; i < a.NamedArguments.Count; ++i) {
+							NamedArgument n = (NamedArgument)a.NamedArguments[i];
+							outputFormatter.PrintIdentifier(n.Name);
+							outputFormatter.Space();
+							outputFormatter.PrintToken(Tokens.Assign);
+							outputFormatter.Space();
+							n.Expr.AcceptVisitor(this, data);
+							if (i + 1 < a.NamedArguments.Count) {
+								outputFormatter.PrintToken(Tokens.Comma);
+								outputFormatter.Space();
+							}
+						}
 					}
+					outputFormatter.PrintToken(Tokens.CloseParenthesis);
 				}
-				outputFormatter.PrintToken(Tokens.CloseParenthesis);
 				if (j + 1 < section.Attributes.Count) {
 					outputFormatter.PrintToken(Tokens.Comma);
 					outputFormatter.Space();
@@ -134,20 +144,18 @@
 		
 		public override object Visit(NamespaceDeclaration namespaceDeclaration, object data)
 		{
+			outputFormatter.NewLine ();
 			outputFormatter.Indent();
 			outputFormatter.PrintToken(Tokens.Namespace);
 			outputFormatter.Space();
 			outputFormatter.PrintIdentifier(namespaceDeclaration.NameSpace);
-			outputFormatter.NewLine();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
+			
+			outputFormatter.BeginBrace(this.prettyPrintOptions.NameSpaceBraceStyle);
+			
 			namespaceDeclaration.AcceptChildren(this, data);
-			--outputFormatter.IndentationLevel;
 			
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
-			outputFormatter.NewLine();
+			outputFormatter.EndBrace();
+			
 			return null;
 		}
 		
@@ -301,21 +309,29 @@
 					}
 				}
 			}
-			outputFormatter.NewLine();
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
 			
-			++outputFormatter.IndentationLevel;
+			switch (typeDeclaration.Type) {
+				case Types.Class:
+					outputFormatter.BeginBrace(this.prettyPrintOptions.ClassBraceStyle);
+					break;
+				case Types.Enum:
+					outputFormatter.BeginBrace(this.prettyPrintOptions.EnumBraceStyle);
+					break;
+				case Types.Interface:
+					outputFormatter.BeginBrace(this.prettyPrintOptions.InterfaceBraceStyle);
+					break;
+				case Types.Struct:
+					outputFormatter.BeginBrace(this.prettyPrintOptions.StructBraceStyle);
+					break;
+			}
+			
 			if (typeDeclaration.Type == Types.Enum) {
 				VisitEnumMembers(typeDeclaration, data);
 			} else {
 				typeDeclaration.AcceptChildren(this, data);
 			}
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
-			outputFormatter.NewLine();
+			outputFormatter.EndBrace();
+			
 			return null;
 		}
 		
@@ -393,22 +409,17 @@
 				outputFormatter.PrintIdentifier(eventDeclaration.Name);
 				if (eventDeclaration.AddRegion == null && eventDeclaration.RemoveRegion == null) {
 					outputFormatter.PrintToken(Tokens.Semicolon);
-				} else {
-					outputFormatter.Space();
-					outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
 					outputFormatter.NewLine();
-					++outputFormatter.IndentationLevel;
+				} else {
+					outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyBraceStyle);
 					if (eventDeclaration.AddRegion != null) {
 						eventDeclaration.AddRegion.AcceptVisitor(this, data);
 					}
 					if (eventDeclaration.RemoveRegion != null) {
 						eventDeclaration.RemoveRegion.AcceptVisitor(this, data);
 					}
-					--outputFormatter.IndentationLevel;
-					outputFormatter.Indent();
-					outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
+					outputFormatter.EndBrace();
 				}
-				outputFormatter.NewLine();
 			}
 			return null;
 		}
@@ -420,17 +431,12 @@
 			outputFormatter.PrintIdentifier("add");
 			if (addRegion.Block == null) {
 				outputFormatter.PrintToken(Tokens.Semicolon);
-			} else {
-				outputFormatter.Space();
-				outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
 				outputFormatter.NewLine();
-				++outputFormatter.IndentationLevel;
+			} else {
+				outputFormatter.BeginBrace(this.prettyPrintOptions.PropertyGetBraceStyle);
 				addRegion.Block.AcceptChildren(this, false);
-				--outputFormatter.IndentationLevel;
-				outputFormatter.Indent();
-				outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
+				outputFormatter.EndBrace();
 			}
-			outputFormatter.NewLine();
 			return null;
 		}
 		
@@ -441,17 +447,12 @@
 			outputFormatter.PrintIdentifier("remove");
 			if (removeRegion.Block == null) {
 				outputFormatter.PrintToken(Tokens.Semicolon);
-			} else {
-				outputFormatter.Space();
-				outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
 				outputFormatter.NewLine();
-				++outputFormatter.IndentationLevel;
+			} else {
+				outputFormatter.BeginBrace(this.prettyPrintOptions.PropertySetBraceStyle);
 				removeRegion.Block.AcceptChildren(this, false);
-				--outputFormatter.IndentationLevel;
-				outputFormatter.Indent();
-				outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
+				outputFormatter.EndBrace();
 			}
-			outputFormatter.NewLine();
 			return null;
 		}
 		
@@ -474,6 +475,7 @@
 			outputFormatter.Indent();
 			VisitModifier(constructorDeclaration.Modifier);
 			outputFormatter.PrintIdentifier(constructorDeclaration.Name);
+			outputFormatter.Space ();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			AppendCommaSeparatedList(constructorDeclaration.Parameters);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
@@ -487,21 +489,15 @@
 				} else {
 					outputFormatter.PrintToken(Tokens.This);
 				}
+				outputFormatter.Space ();
 				outputFormatter.PrintToken(Tokens.OpenParenthesis);
 				AppendCommaSeparatedList(constructorDeclaration.ConstructorInitializer.Arguments);
 				outputFormatter.PrintToken(Tokens.CloseParenthesis);
 			}
 			
-			outputFormatter.NewLine();
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
+			outputFormatter.BeginBrace(this.prettyPrintOptions.ConstructorBraceStyle);
 			constructorDeclaration.Body.AcceptChildren(this, data);
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
-			outputFormatter.NewLine();
+			outputFormatter.EndBrace();
 			return null;
 		}
 		
@@ -512,18 +508,13 @@
 			VisitModifier(destructorDeclaration.Modifier);
 			outputFormatter.PrintToken(Tokens.BitwiseComplement);
 			outputFormatter.PrintIdentifier(destructorDeclaration.Name);
+			outputFormatter.Space ();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
-			outputFormatter.NewLine();
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
+			
+			outputFormatter.BeginBrace(this.prettyPrintOptions.DestructorBraceStyle);
 			destructorDeclaration.Body.AcceptChildren(this, data);
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
-			outputFormatter.NewLine();
+			outputFormatter.EndBrace();
 			return null;
 		}
 		
@@ -535,23 +526,18 @@
 			Visit(methodDeclaration.TypeReference, data);
 			outputFormatter.Space();
 			outputFormatter.PrintIdentifier(methodDeclaration.Name);
+			outputFormatter.Space();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			AppendCommaSeparatedList(methodDeclaration.Parameters);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
 			if (methodDeclaration.Body == null) {
 				outputFormatter.PrintToken(Tokens.Semicolon);
-			} else {
 				outputFormatter.NewLine();
-				outputFormatter.Indent();
-				outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-				outputFormatter.NewLine();
-				++outputFormatter.IndentationLevel;
+			} else {
+				outputFormatter.BeginBrace(this.prettyPrintOptions.MethodBraceStyle);
 				methodDeclaration.Body.AcceptChildren(this, data);
-				--outputFormatter.IndentationLevel;
-				outputFormatter.Indent();
-				outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
+				outputFormatter.EndBrace();
 			}
-			outputFormatter.NewLine();
 			return null;
 		}
 		
@@ -718,9 +704,10 @@
 			outputFormatter.NewLine();
 			return null;
 		}
+
 		public override object Visit(BlockStatement blockStatement, object data)
 		{
-			outputFormatter.Indent();
+			outputFormatter.Space();
 			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
 			outputFormatter.NewLine();
 			++outputFormatter.IndentationLevel;
@@ -749,7 +736,7 @@
 						outputFormatter.PrintToken(Tokens.Comma);
 					}
 				}
-			} 
+			}
 			outputFormatter.EmitSemicolon = true;
 			outputFormatter.PrintToken(Tokens.Semicolon);
 			outputFormatter.EmitSemicolon = false;
@@ -774,14 +761,12 @@
 			outputFormatter.EmitSemicolon = true;
 			outputFormatter.DoNewLine     = true;
 			outputFormatter.DoIndent      = true;
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			if (forStatement.EmbeddedStatement is BlockStatement) {
 				Visit((BlockStatement)forStatement.EmbeddedStatement, false);
 			} else {
+				outputFormatter.NewLine();
 				forStatement.EmbeddedStatement.AcceptVisitor(this, data);
 			}
-			--outputFormatter.IndentationLevel;
 			return null;
 		}
 		
@@ -799,14 +784,12 @@
 			outputFormatter.Space();
 			foreachStatement.Expression.AcceptVisitor(this, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			if (foreachStatement.EmbeddedStatement is BlockStatement) {
 				Visit((BlockStatement)foreachStatement.EmbeddedStatement, false);
 			} else {
+				outputFormatter.NewLine();
 				foreachStatement.EmbeddedStatement.AcceptVisitor(this, data);
 			}
-			--outputFormatter.IndentationLevel;
 			return null;
 		}
 		
@@ -818,14 +801,12 @@
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			whileStatement.Condition.AcceptVisitor(this, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			if (whileStatement.EmbeddedStatement is BlockStatement) {
 				Visit((BlockStatement)whileStatement.EmbeddedStatement, false);
 			} else {
+				outputFormatter.NewLine();
 				whileStatement.EmbeddedStatement.AcceptVisitor(this, data);
 			}
-			--outputFormatter.IndentationLevel;
 			return null;
 		}
 		
@@ -833,14 +814,12 @@
 		{
 			outputFormatter.Indent();
 			outputFormatter.PrintToken(Tokens.Do);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			if (doWhileStatement.EmbeddedStatement is BlockStatement) {
 				Visit((BlockStatement)doWhileStatement.EmbeddedStatement, false);
 			} else {
+				outputFormatter.NewLine();
 				doWhileStatement.EmbeddedStatement.AcceptVisitor(this, data);
 			}
-			--outputFormatter.IndentationLevel;
 			outputFormatter.Indent();
 			outputFormatter.PrintToken(Tokens.While);
 			outputFormatter.Space();
@@ -874,14 +853,7 @@
 		{
 			outputFormatter.Indent();
 			outputFormatter.PrintToken(Tokens.Checked);
-			outputFormatter.Space();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			checkedStatement.Block.AcceptChildren(this, false);
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
 			outputFormatter.NewLine();
 			return null;
 		}
@@ -890,14 +862,7 @@
 		{
 			outputFormatter.Indent();
 			outputFormatter.PrintToken(Tokens.Unchecked);
-			outputFormatter.Space();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			uncheckedStatement.Block.AcceptVisitor(this, false);
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
 			outputFormatter.NewLine();
 			return null;
 		}
@@ -912,18 +877,12 @@
 			outputFormatter.Space();
 			AppendCommaSeparatedList(fixedStatement.PointerDeclarators);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
-			outputFormatter.Space();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			if (fixedStatement.EmbeddedStatement is BlockStatement) {
 				Visit((BlockStatement)fixedStatement.EmbeddedStatement, false);
 			} else {
+				outputFormatter.NewLine();
 				fixedStatement.EmbeddedStatement.AcceptVisitor(this, data);
 			}
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
 			outputFormatter.NewLine();
 			return null;
 		}
@@ -965,15 +924,11 @@
 			ifElseStatement.Condition.AcceptVisitor(this,data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
 			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			ifElseStatement.EmbeddedStatement.AcceptVisitor(this,data);
-			--outputFormatter.IndentationLevel;
 			outputFormatter.Indent();
 			outputFormatter.PrintToken(Tokens.Else);
 			outputFormatter.NewLine();
-			++outputFormatter.IndentationLevel;
 			ifElseStatement.EmbeddedElseStatement.AcceptVisitor(this,data);
-			--outputFormatter.IndentationLevel;
 			return null;
 		}
 		
@@ -985,10 +940,7 @@
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			ifStatement.Condition.AcceptVisitor(this,data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
-			outputFormatter.Space();
-			++outputFormatter.IndentationLevel;
 			ifStatement.EmbeddedStatement.AcceptVisitor(this,data);
-			--outputFormatter.IndentationLevel;
 			return null;
 		}
 		
@@ -1010,14 +962,7 @@
 			lockStatement.LockExpression.AcceptVisitor(this, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
 			outputFormatter.Space();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			
-			++outputFormatter.IndentationLevel;
 			lockStatement.EmbeddedStatement.AcceptVisitor(this, data);
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
 			outputFormatter.NewLine();
 			return null;
 		}
@@ -1107,7 +1052,8 @@
 				foreach (CatchClause catchClause in tryCatchStatement.CatchClauses) {
 					outputFormatter.Indent();
 					outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
-					outputFormatter.Space();
+					outputFormatter.NewLine();
+					outputFormatter.Indent();
 					outputFormatter.PrintToken(Tokens.Catch);
 					outputFormatter.Space();
 					if (catchClause.Type == null) {
@@ -1132,7 +1078,8 @@
 			if (tryCatchStatement.FinallyBlock != null) {
 				outputFormatter.Indent();
 				outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
-				outputFormatter.Space();
+				outputFormatter.NewLine();
+				outputFormatter.Indent();
 				outputFormatter.PrintToken(Tokens.Finally);
 				outputFormatter.Space();
 				outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
@@ -1163,15 +1110,7 @@
 			outputFormatter.EmitSemicolon = true;
 			
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
-			outputFormatter.Space();
-			outputFormatter.PrintToken(Tokens.OpenCurlyBrace);
-			outputFormatter.NewLine();
-			
-			++outputFormatter.IndentationLevel;
 			usingStatement.EmbeddedStatement.AcceptVisitor(this,data);
-			--outputFormatter.IndentationLevel;
-			outputFormatter.Indent();
-			outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
 			outputFormatter.NewLine();
 			return null;
 		}
@@ -1198,6 +1137,15 @@
 			return null;
 		}
 		
+		public override object Visit(UnsafeStatement unsafeStatement, object data)
+		{
+			outputFormatter.Indent();
+			outputFormatter.PrintToken(Tokens.Unsafe);
+			unsafeStatement.Block.AcceptVisitor(this, data);
+			return null;
+		}
+		
+		
 #region Expressions
 		public override object Visit(ArrayCreateExpression arrayCreateExpression, object data)
 		{
@@ -1369,6 +1317,7 @@
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			Visit(castExpression.CastTo, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
+			outputFormatter.Space ();
 			castExpression.Expression.AcceptVisitor(this, data);
 			return null;
 		}
@@ -1438,6 +1387,7 @@
 		public override object Visit(InvocationExpression invocationExpression, object data)
 		{
 			invocationExpression.TargetObject.AcceptVisitor(this, data);
+			outputFormatter.Space ();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			AppendCommaSeparatedList(invocationExpression.Parameters);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
@@ -1449,6 +1399,7 @@
 			outputFormatter.PrintToken(Tokens.New);
 			outputFormatter.Space();
 			this.Visit(objectCreateExpression.CreateType, data);
+			outputFormatter.Space();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			AppendCommaSeparatedList(objectCreateExpression.Parameters);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
@@ -1480,6 +1431,7 @@
 		public override object Visit(SizeOfExpression sizeOfExpression, object data)
 		{
 			outputFormatter.PrintToken(Tokens.Sizeof);
+			outputFormatter.Space ();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			Visit(sizeOfExpression.TypeReference, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
@@ -1489,6 +1441,7 @@
 		public override object Visit(StackAllocExpression stackAllocExpression, object data)
 		{
 			outputFormatter.PrintToken(Tokens.Stackalloc);
+			outputFormatter.Space();
 			Visit(stackAllocExpression.Type, data);
 			outputFormatter.PrintToken(Tokens.OpenSquareBracket);
 			stackAllocExpression.Expression.AcceptVisitor(this, data);
@@ -1505,6 +1458,7 @@
 		public override object Visit(TypeOfExpression typeOfExpression, object data)
 		{
 			outputFormatter.PrintToken(Tokens.Typeof);
+			outputFormatter.Space ();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			Visit(typeOfExpression.TypeReference, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);
@@ -1560,6 +1514,7 @@
 		public override object Visit(UncheckedExpression uncheckedExpression, object data)
 		{
 			outputFormatter.PrintToken(Tokens.Unchecked);
+			outputFormatter.Space ();
 			outputFormatter.PrintToken(Tokens.OpenParenthesis);
 			uncheckedExpression.Expression.AcceptVisitor(this, data);
 			outputFormatter.PrintToken(Tokens.CloseParenthesis);




More information about the Monodevelop-patches-list mailing list