From 45bead5f286fd34b7e2363b3eda61fb8d6b66ac1 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 15 Jul 2005 13:00:06 +0000 Subject: [PATCH] C# <-> VB.Net converters now convert comments. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@180 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Parser/Parser.cs | 4 +- .../VBNetBinding/Project/Src/Parser/Parser.cs | 4 +- .../NRefactory/Project/NRefactory.csproj | 3 +- .../Project/Src/Lexer/AbstractLexer.cs | 6 +- .../Project/Src/Lexer/CSharp/Lexer.cs | 13 +- .../NRefactory/Project/Src/Lexer/ILexer.cs | 3 +- .../Project/Src/Lexer/Special/BlankLine.cs | 13 +- .../Project/Src/Lexer/Special/Comment.cs | 24 +- .../Project/Src/Lexer/Special/ISpecial.cs | 74 ++ .../Lexer/Special/PreProcessingDirective.cs | 31 +- .../Src/Lexer/Special/SpecialTracker.cs | 25 +- .../Project/Src/Lexer/Special/SpecialType.cs | 13 - .../Project/Src/Lexer/Special/TagComment.cs | 2 +- .../Project/Src/Lexer/VBNet/Lexer.cs | 9 +- .../Src/Output/AbstractOutputFormatter.cs | 80 +- .../Src/Output/CSharp/CSharpOutputVisitor.cs | 36 +- .../Src/Output/CSharp/OutputFormatter.cs | 103 +-- .../Project/Src/Output/NodeInformVisitor.cs | 14 + .../Src/Output/SpecialNodesInserter.cs | 118 +++ .../Src/Output/VBNet/VBNetOutputFormatter.cs | 20 +- .../Src/Output/VBNet/VBNetOutputVisitor.cs | 103 ++- .../Project/Src/Parser/CSharp/Parser.cs | 836 +++++++++--------- .../Project/Src/Parser/CSharp/cs.ATG | 7 + .../VBConverter/CSharpConvertBuffer.cs | 7 +- .../Src/Commands/VBConverter/ConvertBuffer.cs | 10 +- .../RefactoringService/RefactoringService.cs | 8 +- 26 files changed, 892 insertions(+), 674 deletions(-) create mode 100644 src/Libraries/NRefactory/Project/Src/Lexer/Special/ISpecial.cs delete mode 100644 src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialType.cs create mode 100644 src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs index 7b428e9790..eeb075c593 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs @@ -64,7 +64,7 @@ namespace CSharpBinding.Parser case "#endregion": --deep; if (deep == 0) { - cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DefaultRegion(directive.Start, new Point(nextDirective.End.X, nextDirective.End.Y)))); + cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DefaultRegion(directive.StartPosition, nextDirective.EndPosition))); goto end; } break; @@ -107,7 +107,7 @@ namespace CSharpBinding.Parser return visitor.Cu; } - void AddCommentTags(ICompilationUnit cu, ArrayList tagComments) + void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List tagComments) { foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) { DefaultRegion tagRegion = new DefaultRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X); diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs index e2c49d5f5c..1cce98fdf8 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs @@ -76,7 +76,7 @@ namespace VBNetBinding.Parser if (nextDirective.Arg.ToLower() == "region") { --deep; if (deep == 0) { - cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DefaultRegion(directive.Start, nextDirective.End))); + cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DefaultRegion(directive.StartPosition, nextDirective.EndPosition))); goto end; } } @@ -119,7 +119,7 @@ namespace VBNetBinding.Parser return visitor.Cu; } - void AddCommentTags(ICompilationUnit cu, ArrayList tagComments) + void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List tagComments) { foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) { diff --git a/src/Libraries/NRefactory/Project/NRefactory.csproj b/src/Libraries/NRefactory/Project/NRefactory.csproj index 6521954291..21840dd3b4 100644 --- a/src/Libraries/NRefactory/Project/NRefactory.csproj +++ b/src/Libraries/NRefactory/Project/NRefactory.csproj @@ -60,7 +60,6 @@ - @@ -184,6 +183,8 @@ + + diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs b/src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs index 8cd2e4bd53..fa7a0fff1d 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs @@ -10,6 +10,7 @@ using System; using System.Text; using System.Collections; +using System.Collections.Generic; using System.IO; namespace ICSharpCode.NRefactory.Parser @@ -32,8 +33,7 @@ namespace ICSharpCode.NRefactory.Parser string[] specialCommentTags = null; protected Hashtable specialCommentHash = null; -// protected List tagComments = new List(); - protected ArrayList tagComments = new ArrayList(); + protected List tagComments = new List(); protected StringBuilder sb = new StringBuilder(); protected SpecialTracker specialTracker = new SpecialTracker(); @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.Parser /// /// Returns the comments that had been read and containing tag key words. /// - public ArrayList TagComments { + public List TagComments { get { return tagComments; } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs index d8fd42e67f..47a1f3287a 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs @@ -748,6 +748,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp break; } + sb.Append(ch); if (specialCommentHash != null) { if (Char.IsLetter(ch)) { curWord.Append(ch); @@ -755,16 +756,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp string tag = curWord.ToString(); curWord.Length = 0; if (specialCommentHash.ContainsKey(tag)) { - Point p = new Point(col ,line); + Point p = new Point(col, line); string comment = ReadToEOL(); - tagComments.Add(new TagComment(tag, comment, p)); - sb.Append(tag); + tagComments.Add(new TagComment(tag, comment, p, new Point(col, line))); sb.Append(comment); break; } } } - sb.Append(ch); } return sb.ToString(); } @@ -773,7 +772,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp { specialTracker.StartComment(commentType, new Point(col, line)); specialTracker.AddString(ReadCommentToEOL()); - specialTracker.FinishComment(); + specialTracker.FinishComment(new Point(col, line)); } void ReadMultiLineComment() @@ -793,12 +792,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp if (ch == '*' && reader.Peek() == '/') { reader.Read(); ++col; - specialTracker.FinishComment(); + specialTracker.FinishComment(new Point(col, line)); return; } specialTracker.AddChar(ch); } - specialTracker.FinishComment(); + specialTracker.FinishComment(new Point(col, line)); // Reached EOF before end of multiline comment. errors.Error(line, col, String.Format("Reached EOF before the end of a multiline comment")); } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs b/src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs index d76e128c82..c39999bc4c 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs @@ -9,6 +9,7 @@ using System; using System.Collections; +using System.Collections.Generic; namespace ICSharpCode.NRefactory.Parser { @@ -46,7 +47,7 @@ namespace ICSharpCode.NRefactory.Parser /// /// Returns the comments that had been read and containing tag key words. /// - ArrayList TagComments { + List TagComments { get; } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/BlankLine.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/BlankLine.cs index d8cc4cafc1..b90ca534d9 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/Special/BlankLine.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/Special/BlankLine.cs @@ -1,14 +1,17 @@ using System; -using System.Text; -using System.CodeDom; -using System.Collections; +using System.Drawing; namespace ICSharpCode.NRefactory.Parser { - public class BlankLine + public class BlankLine : AbstractSpecial { - public BlankLine() + public BlankLine(Point point) : base(point) { } + + public override object AcceptVisitor(ISpecialVisitor visitor, object data) + { + return visitor.Visit(this, data); + } } } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/Comment.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/Comment.cs index cf3717e805..eefc9abf84 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/Special/Comment.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/Special/Comment.cs @@ -6,11 +6,10 @@ using System.Drawing; namespace ICSharpCode.NRefactory.Parser { - public class Comment + public class Comment : AbstractSpecial { CommentType commentType; string comment; - Point startPosition; public CommentType CommentType { get { @@ -30,27 +29,22 @@ namespace ICSharpCode.NRefactory.Parser } } - public Point StartPosition { - get { - return startPosition; - } - set { - startPosition = value; - } - } - - public Comment(CommentType commentType, string comment, Point startPosition) + public Comment(CommentType commentType, string comment, Point startPosition, Point endPosition) + : base(startPosition, endPosition) { this.commentType = commentType; this.comment = comment; - this.startPosition = startPosition; } public override string ToString() { - return String.Format("[Comment: CommentType = {0}]", - CommentType); + return String.Format("[{0}: Type = {1}, Text = {2}, Start = {3}, End = {4}]", + GetType().Name, CommentType, CommentText, StartPosition, EndPosition); } + public override object AcceptVisitor(ISpecialVisitor visitor, object data) + { + return visitor.Visit(this, data); + } } } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/ISpecial.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/ISpecial.cs new file mode 100644 index 0000000000..0d67d6f585 --- /dev/null +++ b/src/Libraries/NRefactory/Project/Src/Lexer/Special/ISpecial.cs @@ -0,0 +1,74 @@ +/* + * Created by SharpDevelop. + * User: Daniel Grunwald + * Date: 15.07.2005 + * Time: 12:05 + */ + +using System; +using System.Drawing; + +namespace ICSharpCode.NRefactory.Parser +{ + /// + /// Interface for all specials. + /// + public interface ISpecial + { + Point StartPosition { get; } + Point EndPosition { get; } + + object AcceptVisitor(ISpecialVisitor visitor, object data); + } + + public interface ISpecialVisitor + { + object Visit(ISpecial special, object data); + object Visit(BlankLine special, object data); + object Visit(Comment special, object data); + object Visit(PreProcessingDirective special, object data); + } + + public abstract class AbstractSpecial : ISpecial + { + public abstract object AcceptVisitor(ISpecialVisitor visitor, object data); + + Point startPosition, endPosition; + + public AbstractSpecial(Point position) + { + this.startPosition = position; + this.endPosition = position; + } + + public AbstractSpecial(Point startPosition, Point endPosition) + { + this.startPosition = startPosition; + this.endPosition = endPosition; + } + + public Point StartPosition { + get { + return startPosition; + } + set { + startPosition = value; + } + } + + public Point EndPosition { + get { + return endPosition; + } + set { + endPosition = value; + } + } + + public override string ToString() + { + return String.Format("[{0}: Start = {1}, End = {2}]", + GetType().Name, StartPosition, EndPosition); + } + } +} diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs index 18297c7422..19431f72a1 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs @@ -6,30 +6,10 @@ using System.Collections; namespace ICSharpCode.NRefactory.Parser { - public class PreProcessingDirective + public class PreProcessingDirective : AbstractSpecial { string cmd; string arg; - Point start; - Point end; - - public Point Start { - get { - return start; - } - set { - start = value; - } - } - - public Point End { - get { - return end; - } - set { - end = value; - } - } public string Cmd { get { @@ -48,6 +28,7 @@ namespace ICSharpCode.NRefactory.Parser arg = value; } } + public override string ToString() { return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]", @@ -56,11 +37,15 @@ namespace ICSharpCode.NRefactory.Parser } public PreProcessingDirective(string cmd, string arg, Point start, Point end) + : base(start, end) { this.cmd = cmd; this.arg = arg; - this.start = start; - this.end = end; + } + + public override object AcceptVisitor(ISpecialVisitor visitor, object data) + { + return visitor.Visit(this, data); } } } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs index ed7ce3531f..a2e67be2c9 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs @@ -1,20 +1,20 @@ using System; using System.Text; using System.CodeDom; -using System.Collections; +using System.Collections.Generic; using System.Drawing; namespace ICSharpCode.NRefactory.Parser { public class SpecialTracker { - ArrayList currentSpecials = new ArrayList(); + List currentSpecials = new List(); CommentType currentCommentType; StringBuilder sb = new StringBuilder(); Point startPosition; - public ArrayList CurrentSpecials { + public List CurrentSpecials { get { return currentSpecials; } @@ -22,19 +22,22 @@ namespace ICSharpCode.NRefactory.Parser public void InformToken(int kind) { - currentSpecials.Add(kind); + } - public ArrayList RetrieveSpecials() + /// + /// Gets the specials from the SpecialTracker and resets the lists. + /// + public List RetrieveSpecials() { - ArrayList tmp = currentSpecials; - currentSpecials = new ArrayList(); + List tmp = currentSpecials; + currentSpecials = new List(); return tmp; } - public void AddEndOfLine() + public void AddEndOfLine(Point point) { - currentSpecials.Add(new BlankLine()); + currentSpecials.Add(new BlankLine(point)); } public void AddPreProcessingDirective(string cmd, string arg, Point start, Point end) @@ -60,9 +63,9 @@ namespace ICSharpCode.NRefactory.Parser sb.Append(s); } - public void FinishComment() + public void FinishComment(Point endPosition) { - currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), startPosition)); + currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), startPosition, endPosition)); } } } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialType.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialType.cs deleted file mode 100644 index 55201d7be7..0000000000 --- a/src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialType.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Text; -using System.CodeDom; -using System.Collections; - -namespace ICSharpCode.NRefactory.Parser -{ - public enum SpecialType { - SingleLine, - Documentation, - Block - } -} diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/Special/TagComment.cs b/src/Libraries/NRefactory/Project/Src/Lexer/Special/TagComment.cs index aaf837b8e4..9ff040538b 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/Special/TagComment.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/Special/TagComment.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser } } - public TagComment(string tag, string comment, Point startPosition) : base(CommentType.SingleLine, comment, startPosition) + public TagComment(string tag, string comment, Point startPosition, Point endPosition) : base(CommentType.SingleLine, comment, startPosition, endPosition) { this.tag = tag; } diff --git a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs index 7e8a6c6470..a4037a92bd 100644 --- a/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs +++ b/src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs @@ -83,6 +83,7 @@ namespace ICSharpCode.NRefactory.Parser.VB if (ch == '_') { if (reader.Peek() == -1) { errors.Error(line, col, String.Format("No EOF expected after _")); + return new Token(Tokens.EOF); } ++col; if (!Char.IsWhiteSpace((char)reader.Peek())) { @@ -517,6 +518,7 @@ namespace ICSharpCode.NRefactory.Parser.VB break; } + sb.Append(ch); if (specialCommentHash != null) { if (Char.IsLetter(ch)) { curWord.Append(ch); @@ -524,10 +526,9 @@ namespace ICSharpCode.NRefactory.Parser.VB string tag = curWord.ToString(); curWord.Length = 0; if (specialCommentHash.ContainsKey(tag)) { - Point p = new Point(col ,line); + Point p = new Point(col, line); string comment = ReadToEOL(); - tagComments.Add(new TagComment(tag, comment, p)); - sb.Append(tag); + tagComments.Add(new TagComment(tag, comment, p, new Point(col, line))); sb.Append(comment); break; } @@ -535,7 +536,7 @@ namespace ICSharpCode.NRefactory.Parser.VB } } specialTracker.AddString(sb.ToString()); - specialTracker.FinishComment(); + specialTracker.FinishComment(new Point(col, line)); } Token ReadOperator(char ch) diff --git a/src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs b/src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs index 378c29c253..0a8c1e0d28 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs @@ -19,12 +19,12 @@ using ICSharpCode.NRefactory.Parser.AST; namespace ICSharpCode.NRefactory.PrettyPrinter { /// - /// Description of VBNetOutputFormatter. + /// Base class of output formatters. /// public abstract class AbstractOutputFormatter { int indentationLevel = 0; - protected StringBuilder text = new StringBuilder(); + StringBuilder text = new StringBuilder(); bool indent = true; bool doNewLine = true; @@ -69,6 +69,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter this.prettyPrintOptions = prettyPrintOptions; } + bool isIndented = false; + public void Indent() { if (DoIndent) { @@ -85,6 +87,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter ++indent; } } + isIndented = true; } } @@ -93,52 +96,79 @@ namespace ICSharpCode.NRefactory.PrettyPrinter text.Append(' '); } - public void NewLine() + bool gotBlankLine = true; + ArrayList specialsText = new ArrayList(); + + public virtual void NewLine() { if (DoNewLine) { text.Append(Environment.NewLine); -// gotBlankLine = true; + gotBlankLine = true; + isIndented = false; + WriteSpecials(); } } - public void EndFile() + public virtual void EndFile() { -// while (this.token == null || this.token.kind > 0) { -// this.token = lexer.NextToken(); -// PrintSpecials(token.kind); -// } -// PrintSpecials(-1); -// foreach (object o in lexer.SpecialTracker.CurrentSpecials) { -// Console.WriteLine(o); -// } + WriteSpecials(); } + protected void WriteInNextNewLine(string text) + { + specialsText.Add(text); + if (gotBlankLine) { + WriteSpecials(); + } + } + + void WriteSpecials() + { + if (isIndented) { + foreach (string txt in specialsText) { + text.Append(txt); + text.Append(Environment.NewLine); + Indent(); + } + } else { + foreach (string txt in specialsText) { + Indent(); + text.Append(txt); + text.Append(Environment.NewLine); + } + isIndented = false; + } + specialsText.Clear(); + } public void PrintTokenList(ArrayList tokenList) { -// ArrayList trackList = (ArrayList)tokenList.Clone(); -// while (this.token == null || trackList.Count > 0) { -// this.token = lexer.NextToken(); -//// PrintSpecials(this.token.kind); -// for (int i = 0; i < trackList.Count; ++i) { -// trackList.RemoveAt(i); -// break; -// } -// } + gotBlankLine = false; foreach (int token in tokenList) { PrintToken(token); Space(); } } + public abstract void PrintComment(Comment comment); + + public virtual void PrintPreProcessingDirective(PreProcessingDirective directive) + { + WriteInNextNewLine(directive.Cmd + directive.Arg); + } + public abstract void PrintToken(int token); + protected void PrintToken(string text) + { + gotBlankLine = false; + this.text.Append(text); + } + public void PrintIdentifier(string identifier) { -// this.token = lexer.NextToken(); -// PrintSpecials(token.kind); + gotBlankLine = false; text.Append(identifier); } - } } diff --git a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs index e1e4e2b4b4..3759188b08 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs @@ -20,10 +20,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { public class CSharpOutputVisitor : IOutputASTVisitor { - Errors errors = new Errors(); - OutputFormatter outputFormatter; - PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions(); - NodeTracker nodeTracker; + Errors errors = new Errors(); + CSharpOutputFormatter outputFormatter; + PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions(); + NodeTracker nodeTracker; // Stack withExpressionStack = new Stack(); Stack withExpressionStack = new Stack(); @@ -48,9 +48,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } + public CSharpOutputFormatter OutputFormatter { + get { + return outputFormatter; + } + } + + public NodeTracker NodeTracker { + get { + return nodeTracker; + } + } + public CSharpOutputVisitor() { - outputFormatter = new OutputFormatter(prettyPrintOptions); + outputFormatter = new CSharpOutputFormatter(prettyPrintOptions); nodeTracker = new NodeTracker(this); } @@ -63,7 +75,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public object Visit(CompilationUnit compilationUnit, object data) { - compilationUnit.AcceptChildren(this, data); + nodeTracker.TrackedVisitChildren(compilationUnit, data); outputFormatter.EndFile(); return null; } @@ -243,7 +255,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter public object Visit(UsingDeclaration usingDeclaration, object data) { foreach (Using u in usingDeclaration.Usings) { - u.AcceptVisitor(this, data); + nodeTracker.TrackedVisit(u, data); } return null; } @@ -257,7 +269,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.BeginBrace(this.prettyPrintOptions.NameSpaceBraceStyle); - namespaceDeclaration.AcceptChildren(this, data); + nodeTracker.TrackedVisitChildren(namespaceDeclaration, data); outputFormatter.EndBrace(); @@ -317,7 +329,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } foreach (TemplateDefinition templateDefinition in typeDeclaration.Templates) { - templateDefinition.AcceptVisitor(this, data); + nodeTracker.TrackedVisit(templateDefinition, data); } switch (typeDeclaration.Type) { @@ -338,7 +350,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter if (typeDeclaration.Type == Types.Enum) { OutputEnumMembers(typeDeclaration, data); } else { - typeDeclaration.AcceptChildren(this, data); + nodeTracker.TrackedVisitChildren(typeDeclaration, data); } outputFormatter.EndBrace(); @@ -356,7 +368,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter for (int i = 0; i < templateDefinition.Bases.Count; ++i) { outputFormatter.Space(); - templateDefinition.Bases[i].AcceptVisitor(this, data); + nodeTracker.TrackedVisit(templateDefinition.Bases[i], data); if (i + 1 < templateDefinition.Bases.Count) { PrintFormattedComma(); } @@ -865,7 +877,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter Debug.Assert(yieldStatement.Statement != null); outputFormatter.PrintIdentifier("yield"); outputFormatter.Space(); - yieldStatement.Statement.AcceptVisitor(this, data); + nodeTracker.TrackedVisit(yieldStatement.Statement, data); return null; } diff --git a/src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs b/src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs index 25ffade658..1bb3fcf1a4 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs @@ -26,10 +26,8 @@ using ICSharpCode.NRefactory.Parser.AST; namespace ICSharpCode.NRefactory.PrettyPrinter { - public class OutputFormatter : AbstractOutputFormatter + public sealed class CSharpOutputFormatter : AbstractOutputFormatter { -// Lexer lexer; - PrettyPrintOptions prettyPrintOptions; bool emitSemicolon = true; @@ -43,91 +41,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } -// Token token; - public OutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions) + public CSharpOutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions) { this.prettyPrintOptions = prettyPrintOptions; -// lexer = new Lexer(new StringReader(originalSourceFile)); -// token = lexer.NextToken(); -// PrintSpecials(token.kind); } -// bool gotBlankLine = false; -// int currentSpecial = 0; - -// void PrintSpecials(int tokenKind) -// { -// if (currentSpecial >= lexer.SpecialTracker.CurrentSpecials.Count) { -// return; -// } -// object o = lexer.SpecialTracker.CurrentSpecials[currentSpecial++]; -// if (o is Comment) { -//// Console.WriteLine("COMMENT " + o); -// Comment comment = (Comment)o; -// switch (comment.CommentType) { -// case CommentType.SingleLine: -// text.Append("//"); -// text.Append(comment.CommentText); -// text.Append("\n"); -// Indent(); -// break; -// case CommentType.Documentation: -// text.Append("///"); -// text.Append(comment.CommentText); -// text.Append("\n"); -// Indent(); -// break; -// case CommentType.Block: -// text.Append("/*"); -// text.Append(comment.CommentText); -// text.Append("*/\n"); -// Indent(); -// break; -// } -// PrintSpecials(tokenKind); -// } else if (o is BlankLine) { -// if (!gotBlankLine) { -//// text.Append("\n"); -//// Indent(); -// } -// gotBlankLine = false; -// PrintSpecials(tokenKind); -// } else if (o is PreProcessingDirective) { -//// Console.WriteLine("PPD:" + o); -// text.Append("\n"); -// PreProcessingDirective ppd = (PreProcessingDirective)o; -// text.Append(ppd.Cmd); -// if (ppd.Arg != null && ppd.Arg.Length > 0) { -// text.Append(" "); -// text.Append(ppd.Arg); -// } -// text.Append("\n"); -// Indent(); -// PrintSpecials(tokenKind); -// } else { -// int kind = (int)o; -//// Console.WriteLine(kind + " -- " + Tokens.GetTokenString(kind)); -// if (kind != tokenKind) { -// PrintSpecials(tokenKind); -// } -// } -// } - public override void PrintToken(int token) { -// Console.WriteLine("PRINT TOKEN:" + token); if (token == Tokens.Semicolon && !EmitSemicolon) { return; } -// while (this.token == null || this.token.kind > 0) { -// this.token = lexer.NextToken(); -//// PrintSpecials(this.token.kind); -// if (this.token.kind == token) { -// break; -// } -// } - text.Append(Tokens.GetTokenString(token)); -// gotBlankLine = false; + PrintToken(Tokens.GetTokenString(token)); } Stack braceStack = new Stack(); @@ -136,7 +60,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { switch (style) { case BraceStyle.EndOfLine: - text.Append(" "); + Space(); PrintToken(Tokens.OpenCurlyBrace); NewLine(); ++IndentationLevel; @@ -194,12 +118,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } - public void BeginNode(INode node) - { - } - - public void EndNode(INode node) + public override void PrintComment(Comment comment) { + switch (comment.CommentType) { + case CommentType.Block: + PrintToken("/*"); + PrintToken(comment.CommentText); + PrintToken("*/"); + break; + case CommentType.Documentation: + WriteInNextNewLine("///" + comment.CommentText); + break; + default: + WriteInNextNewLine("//" + comment.CommentText); + break; + } } } } diff --git a/src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs index d66d1369f9..0285d25ce7 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs @@ -24,6 +24,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter { IASTVisitor callVisitor; + public IASTVisitor CallVisitor { + get { + return callVisitor; + } + } + public NodeTracker(IASTVisitor callVisitor) { this.callVisitor = callVisitor; @@ -51,6 +57,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return ret; } + public object TrackedVisitChildren(INode node, object data) + { + foreach (INode child in node.Children) { + TrackedVisit(child, data); + } + return data; + } + public event InformNode NodeVisiting; public event InformNode NodeVisited; } diff --git a/src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs b/src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs new file mode 100644 index 0000000000..16155553e9 --- /dev/null +++ b/src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs @@ -0,0 +1,118 @@ +/* + * Created by SharpDevelop. + * User: Daniel Grunwald + * Date: 15.07.2005 + * Time: 12:29 + */ + +using System; +using System.Drawing; +using System.Collections.Generic; +using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Parser.AST; + +namespace ICSharpCode.NRefactory.PrettyPrinter +{ + public class SpecialOutputVisitor : ISpecialVisitor + { + AbstractOutputFormatter formatter; + + public SpecialOutputVisitor(AbstractOutputFormatter formatter) + { + this.formatter = formatter; + } + + public object Visit(ISpecial special, object data) + { + Console.WriteLine("Warning: SpecialOutputVisitor.Visit(ISpecial) called with " + special); + return data; + } + + public object Visit(BlankLine special, object data) + { + formatter.NewLine(); + return data; + } + + public object Visit(Comment special, object data) + { + formatter.PrintComment(special); + return data; + } + + public object Visit(PreProcessingDirective special, object data) + { + formatter.PrintPreProcessingDirective(special); + return data; + } + } + + /// + /// This class inserts specials between INodes. + /// + public class SpecialNodesInserter + { + IEnumerator enumerator; + SpecialOutputVisitor visitor; + bool available; // true when more specials are available + + public SpecialNodesInserter(IEnumerable specials, SpecialOutputVisitor visitor) + { + if (specials == null) throw new ArgumentNullException("specials"); + if (visitor == null) throw new ArgumentNullException("visitor"); + enumerator = specials.GetEnumerator(); + this.visitor = visitor; + available = enumerator.MoveNext(); + } + + void WriteCurrent() + { + enumerator.Current.AcceptVisitor(visitor, null); + available = enumerator.MoveNext(); + } + + /// + /// Writes all specials up to the start position of the node. + /// + public void AcceptNodeStart(INode node) + { + Console.Write("Start node " + node.GetType().Name + ": "); + AcceptPoint(node.StartLocation); + } + + /// + /// Writes all specials up to the end position of the node. + /// + public void AcceptNodeEnd(INode node) + { + Console.Write("End node " + node.GetType().Name + ": "); + AcceptPoint(node.EndLocation); + } + + /// + /// Writes all specials up to the specified location. + /// + public void AcceptPoint(Point a) + { + Console.WriteLine(a.Y + ", " + a.X); + while (available) { + Point b = enumerator.Current.StartPosition; + if (b.Y < a.Y || (b.Y == a.Y && b.X <= a.X)) { + WriteCurrent(); + } else { + break; + } + } + } + + /// + /// Outputs all missing specials to the writer. + /// + public void Finish() + { + while (available) { + WriteCurrent(); + } + } + } +} diff --git a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputFormatter.cs b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputFormatter.cs index d5834fbef6..8bbe703483 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputFormatter.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputFormatter.cs @@ -21,16 +21,30 @@ namespace ICSharpCode.NRefactory.PrettyPrinter /// /// Description of VBNetOutputFormatter. /// - public class VBNetOutputFormatter : AbstractOutputFormatter + public sealed class VBNetOutputFormatter : AbstractOutputFormatter { - public VBNetOutputFormatter(VBNetPrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions) { } public override void PrintToken(int token) { - text.Append(Tokens.GetTokenString(token)); + PrintToken(Tokens.GetTokenString(token)); + } + + public override void PrintComment(Comment comment) + { + switch (comment.CommentType) { + case CommentType.Block: + WriteInNextNewLine("'" + comment.CommentText.Replace("\n", "\n'")); + break; + case CommentType.Documentation: + WriteInNextNewLine("'''" + comment.CommentText); + break; + default: + WriteInNextNewLine("'" + comment.CommentText); + break; + } } } } diff --git a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs index f84a36d84e..55930ac053 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs @@ -1,6 +1,7 @@ using System; using System.Text; using System.Collections; +using System.Collections.Generic; using System.Diagnostics; using ICSharpCode.NRefactory.Parser; @@ -40,6 +41,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } } + public NodeTracker NodeTracker { + get { + return nodeTracker; + } + } + + public VBNetOutputFormatter OutputFormatter { + get { + return outputFormatter; + } + } + public VBNetOutputVisitor() { outputFormatter = new VBNetOutputFormatter(prettyPrintOptions); @@ -53,8 +66,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return node.AcceptChildren(this, data); } - public object Visit(CompilationUnit compilationUnit, object data) { - compilationUnit.AcceptChildren(this, data); + public object Visit(CompilationUnit compilationUnit, object data) + { + nodeTracker.TrackedVisitChildren(compilationUnit, data); outputFormatter.EndFile(); return null; } @@ -88,7 +102,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return "Void"; case "System.Object": return "Object"; - + case "System.UInt64": return "System.UInt64"; case "System.UInt32": @@ -101,7 +115,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return typeString; } - public object Visit(TypeReference typeReference, object data) + public object Visit(TypeReference typeReference, object data) { if (typeReference.Type == null || typeReference.Type.Length ==0) { outputFormatter.PrintIdentifier("Void"); @@ -128,7 +142,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } #region Global scope - public object Visit(AttributeSection attributeSection, object data) + public object Visit(AttributeSection attributeSection, object data) { outputFormatter.Indent(); outputFormatter.PrintIdentifier("<"); @@ -144,12 +158,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.PrintToken(Tokens.Comma); } } - outputFormatter.PrintIdentifier("> _"); + if ("assembly".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase) + || "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) { + outputFormatter.PrintIdentifier(">"); + } else { + outputFormatter.PrintIdentifier("> _"); + } outputFormatter.NewLine(); return null; } - public object Visit(ICSharpCode.NRefactory.Parser.AST.Attribute attribute, object data) + public object Visit(ICSharpCode.NRefactory.Parser.AST.Attribute attribute, object data) { outputFormatter.PrintIdentifier(attribute.Name); outputFormatter.PrintToken(Tokens.OpenParenthesis); @@ -217,7 +236,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.NewLine(); ++outputFormatter.IndentationLevel; - namespaceDeclaration.AcceptChildren(this, data); + nodeTracker.TrackedVisitChildren(namespaceDeclaration, data); --outputFormatter.IndentationLevel; outputFormatter.Indent(); @@ -238,7 +257,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter case Types.Interface: return Tokens.Interface; case Types.Struct: - // FixMe: This should be better in VBNetRefactory class because it is an AST transformation, but currently I'm too lazy + // FIXME: This should be better in VBNetRefactory class because it is an AST transformation, but currently I'm too lazy if (TypeHasOnlyStaticMembers(typeDeclaration)) { goto case Types.Class; } @@ -286,7 +305,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter TypeDeclaration oldType = currentType; currentType = typeDeclaration; - typeDeclaration.AcceptChildren(this, data); + nodeTracker.TrackedVisitChildren(typeDeclaration, data); currentType = oldType; --outputFormatter.IndentationLevel; @@ -412,7 +431,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.Assign); outputFormatter.Space(); - variableDeclaration.Initializer.AcceptVisitor(this, data); + nodeTracker.TrackedVisit(variableDeclaration.Initializer, data); } return null; } @@ -497,7 +516,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter } TypeReference currentEventType = null; - public object Visit(EventDeclaration eventDeclaration, object data) + public object Visit(EventDeclaration eventDeclaration, object data) { if (eventDeclaration.VariableDeclarators.Count > 0) { foreach (VariableDeclaration var in eventDeclaration.VariableDeclarators) { @@ -516,7 +535,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data); + nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data); outputFormatter.NewLine(); } @@ -543,7 +562,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintToken(Tokens.As); outputFormatter.Space(); - nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data); + nodeTracker.TrackedVisit(eventDeclaration.TypeReference, data); outputFormatter.NewLine(); if (customEvent) { @@ -566,7 +585,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(EventAddRegion eventAddRegion, object data) + public object Visit(EventAddRegion eventAddRegion, object data) { VisitAttributes(eventAddRegion.Attributes, data); outputFormatter.Indent(); @@ -648,8 +667,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Indent(); OutputModifier(methodDeclaration.Modifier); - bool isSub = methodDeclaration.TypeReference.IsNull || - methodDeclaration.TypeReference.SystemType == "System.Void"; + bool isSub = methodDeclaration.TypeReference.IsNull || + methodDeclaration.TypeReference.SystemType == "System.Void"; if (isSub) { outputFormatter.PrintToken(Tokens.Sub); @@ -689,7 +708,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(ConstructorDeclaration constructorDeclaration, object data) + public object Visit(ConstructorDeclaration constructorDeclaration, object data) { VisitAttributes(constructorDeclaration.Attributes, data); outputFormatter.Indent(); @@ -718,7 +737,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(ConstructorInitializer constructorInitializer, object data) + public object Visit(ConstructorInitializer constructorInitializer, object data) { errors.Error(-1, -1, String.Format("ConstructorInitializer not supported.")); return null; @@ -768,7 +787,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(DestructorDeclaration destructorDeclaration, object data) + public object Visit(DestructorDeclaration destructorDeclaration, object data) { outputFormatter.Indent(); @@ -804,7 +823,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(DeclareDeclaration declareDeclaration, object data) + public object Visit(DeclareDeclaration declareDeclaration, object data) { VisitAttributes(declareDeclaration.Attributes, data); outputFormatter.Indent(); @@ -844,7 +863,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); outputFormatter.PrintIdentifier('"' + declareDeclaration.Library + '"'); outputFormatter.Space(); - + if (declareDeclaration.Alias.Length > 0) { outputFormatter.PrintToken(Tokens.Alias); outputFormatter.Space(); @@ -983,7 +1002,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(ReturnStatement returnStatement, object data) + public object Visit(ReturnStatement returnStatement, object data) { outputFormatter.PrintToken(Tokens.Return); if (!returnStatement.Expression.IsNull) { @@ -1085,7 +1104,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(LabelStatement labelStatement, object data) + public object Visit(LabelStatement labelStatement, object data) { outputFormatter.PrintIdentifier(labelStatement.Label); outputFormatter.PrintToken(Tokens.Colon); @@ -1182,7 +1201,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(BreakStatement breakStatement, object data) + public object Visit(BreakStatement breakStatement, object data) { outputFormatter.PrintToken(Tokens.Exit); if (exitTokenStack.Count > 0) { @@ -1292,8 +1311,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter break; } outputFormatter.Space(); - nodeTracker.TrackedVisit(doLoopStatement.Condition, null); - } + nodeTracker.TrackedVisit(doLoopStatement.Condition, null); + } exitTokenStack.Pop(); return null; } @@ -1339,7 +1358,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter return null; } - public object Visit(LockStatement lockStatement, object data) + public object Visit(LockStatement lockStatement, object data) { errors.Error(-1, -1, String.Format("LockStatement is unsupported")); return null; @@ -1671,31 +1690,31 @@ namespace ICSharpCode.NRefactory.PrettyPrinter case BinaryOperatorType.Add: op = Tokens.Plus; break; - + case BinaryOperatorType.Subtract: op = Tokens.Minus; break; - + case BinaryOperatorType.Multiply: op = Tokens.Times; break; - + case BinaryOperatorType.Divide: op = Tokens.Div; break; - + case BinaryOperatorType.Modulus: op = Tokens.Mod; break; - + case BinaryOperatorType.ShiftLeft: op = Tokens.ShiftLeft; break; - + case BinaryOperatorType.ShiftRight: op = Tokens.ShiftRight; break; - + case BinaryOperatorType.BitwiseAnd: op = Tokens.And; break; @@ -1705,14 +1724,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter case BinaryOperatorType.ExclusiveOr: op = Tokens.Xor; break; - + case BinaryOperatorType.LogicalAnd: op = Tokens.AndAlso; break; case BinaryOperatorType.LogicalOr: op = Tokens.OrElse; break; - + case BinaryOperatorType.AS: outputFormatter.PrintIdentifier("CType(Microsoft.VisualBasic.IIf(TypeOf "); nodeTracker.TrackedVisit(binaryOperatorExpression.Left, data); @@ -1821,7 +1840,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter nodeTracker.TrackedVisit(unaryOperatorExpression.Expression, data); outputFormatter.PrintIdentifier(")"); return null; - + case UnaryOperatorType.Minus: outputFormatter.PrintToken(Tokens.Minus); outputFormatter.Space(); @@ -1905,7 +1924,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter case AssignmentOperatorType.ShiftRight: op = Tokens.ShiftRightAssign; break; - + case AssignmentOperatorType.ExclusiveOr: op = Tokens.Xor; unsupportedOpAssignment = true; @@ -2254,17 +2273,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); } - // TODO : Extern + // TODO : Extern if ((modifier & Modifier.Extern) == Modifier.Extern) { errors.Error(-1, -1, String.Format("'Extern' modifier not convertable")); } - // TODO : Volatile + // TODO : Volatile if ((modifier & Modifier.Volatile) == Modifier.Volatile) { errors.Error(-1, -1, String.Format("'Volatile' modifier not convertable")); } - // TODO : Unsafe + // TODO : Unsafe if ((modifier & Modifier.Unsafe) == Modifier.Unsafe) { errors.Error(-1, -1, String.Format("'Unsafe' modifier not convertable")); } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs index 2e6b853042..41f4a99ea8 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs @@ -703,43 +703,43 @@ out expr); } void Expr( -#line 1849 "cs.ATG" +#line 1856 "cs.ATG" out Expression expr) { -#line 1850 "cs.ATG" +#line 1857 "cs.ATG" expr = null; Expression expr1 = null, expr2 = null; UnaryExpr( -#line 1852 "cs.ATG" +#line 1859 "cs.ATG" out expr); if (StartOf(5)) { ConditionalOrExpr( -#line 1855 "cs.ATG" +#line 1862 "cs.ATG" ref expr); if (la.kind == 12) { lexer.NextToken(); Expr( -#line 1855 "cs.ATG" +#line 1862 "cs.ATG" out expr1); Expect(9); Expr( -#line 1855 "cs.ATG" +#line 1862 "cs.ATG" out expr2); -#line 1855 "cs.ATG" +#line 1862 "cs.ATG" expr = new ConditionalExpression(expr, expr1, expr2); } } else if (StartOf(6)) { -#line 1857 "cs.ATG" +#line 1864 "cs.ATG" AssignmentOperatorType op; Expression val; AssignmentOperator( -#line 1857 "cs.ATG" +#line 1864 "cs.ATG" out op); Expr( -#line 1857 "cs.ATG" +#line 1864 "cs.ATG" out val); -#line 1857 "cs.ATG" +#line 1864 "cs.ATG" expr = new AssignmentExpression(expr, op, val); } else SynErr(127); } @@ -1145,39 +1145,39 @@ templates); } void TypeParameterList( -#line 2203 "cs.ATG" +#line 2210 "cs.ATG" List templates) { -#line 2205 "cs.ATG" +#line 2212 "cs.ATG" AttributeSection section; ArrayList attributes = new ArrayList(); Expect(22); while (la.kind == 17) { AttributeSection( -#line 2209 "cs.ATG" +#line 2216 "cs.ATG" out section); -#line 2209 "cs.ATG" +#line 2216 "cs.ATG" attributes.Add(section); } Expect(1); -#line 2210 "cs.ATG" +#line 2217 "cs.ATG" templates.Add(new TemplateDefinition(t.val, attributes)); while (la.kind == 13) { lexer.NextToken(); while (la.kind == 17) { AttributeSection( -#line 2211 "cs.ATG" +#line 2218 "cs.ATG" out section); -#line 2211 "cs.ATG" +#line 2218 "cs.ATG" attributes.Add(section); } Expect(1); -#line 2212 "cs.ATG" +#line 2219 "cs.ATG" templates.Add(new TemplateDefinition(t.val, attributes)); } Expect(21); @@ -1211,25 +1211,25 @@ out qualident); } void TypeParameterConstraintsClause( -#line 2216 "cs.ATG" +#line 2223 "cs.ATG" List templates) { -#line 2217 "cs.ATG" +#line 2224 "cs.ATG" string name = ""; TypeReference type; Expect(1); -#line 2219 "cs.ATG" +#line 2226 "cs.ATG" if (t.val != "where") Error("where expected"); Expect(1); -#line 2220 "cs.ATG" +#line 2227 "cs.ATG" name = t.val; Expect(9); TypeParameterConstraintsClauseBase( -#line 2222 "cs.ATG" +#line 2229 "cs.ATG" out type); -#line 2223 "cs.ATG" +#line 2230 "cs.ATG" TemplateDefinition td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { @@ -1242,10 +1242,10 @@ out type); while (la.kind == 13) { lexer.NextToken(); TypeParameterConstraintsClauseBase( -#line 2232 "cs.ATG" +#line 2239 "cs.ATG" out type); -#line 2233 "cs.ATG" +#line 2240 "cs.ATG" td = null; foreach (TemplateDefinition d in templates) { if (d.Name == name) { @@ -2621,20 +2621,20 @@ out type); } void TypeName( -#line 2185 "cs.ATG" +#line 2192 "cs.ATG" out string qualident, out List types) { -#line 2186 "cs.ATG" +#line 2193 "cs.ATG" List t; types = new List(); Qualident( -#line 2188 "cs.ATG" +#line 2195 "cs.ATG" out qualident); if (la.kind == 22) { TypeArgumentList( -#line 2189 "cs.ATG" +#line 2196 "cs.ATG" out t); -#line 2189 "cs.ATG" +#line 2196 "cs.ATG" types = t; } } @@ -3223,70 +3223,78 @@ out expr); TypeReference type; Expression expr; Statement stmt; + Point startPos = la.Location; if ( -#line 1628 "cs.ATG" +#line 1629 "cs.ATG" IsLabel()) { Expect(1); -#line 1628 "cs.ATG" +#line 1629 "cs.ATG" compilationUnit.AddChild(new LabelStatement(t.val)); Expect(9); Statement(); } else if (la.kind == 58) { lexer.NextToken(); Type( -#line 1631 "cs.ATG" +#line 1632 "cs.ATG" out type); -#line 1631 "cs.ATG" +#line 1632 "cs.ATG" LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifier.Const); string ident = null; var.StartLocation = t.Location; Expect(1); -#line 1632 "cs.ATG" +#line 1633 "cs.ATG" ident = t.val; Expect(3); Expr( -#line 1633 "cs.ATG" +#line 1634 "cs.ATG" out expr); -#line 1633 "cs.ATG" +#line 1634 "cs.ATG" var.Variables.Add(new VariableDeclaration(ident, expr)); while (la.kind == 13) { lexer.NextToken(); Expect(1); -#line 1634 "cs.ATG" +#line 1635 "cs.ATG" ident = t.val; Expect(3); Expr( -#line 1634 "cs.ATG" +#line 1635 "cs.ATG" out expr); -#line 1634 "cs.ATG" +#line 1635 "cs.ATG" var.Variables.Add(new VariableDeclaration(ident, expr)); } Expect(11); -#line 1635 "cs.ATG" +#line 1636 "cs.ATG" compilationUnit.AddChild(var); } else if ( -#line 1637 "cs.ATG" +#line 1638 "cs.ATG" IsLocalVarDecl()) { LocalVariableDecl( -#line 1637 "cs.ATG" +#line 1638 "cs.ATG" out stmt); Expect(11); -#line 1637 "cs.ATG" +#line 1638 "cs.ATG" compilationUnit.AddChild(stmt); } else if (StartOf(22)) { EmbeddedStatement( -#line 1638 "cs.ATG" +#line 1639 "cs.ATG" out stmt); -#line 1638 "cs.ATG" +#line 1639 "cs.ATG" compilationUnit.AddChild(stmt); + +#line 1644 "cs.ATG" + if (stmt != null) { + stmt.StartLocation = startPos; + stmt.EndLocation = t.EndLocation; + } + } else SynErr(164); } @@ -3502,10 +3510,10 @@ out expr); } void EmbeddedStatement( -#line 1644 "cs.ATG" +#line 1651 "cs.ATG" out Statement statement) { -#line 1646 "cs.ATG" +#line 1653 "cs.ATG" TypeReference type = null; Expression expr = null; Statement embeddedStatement = null; @@ -3513,156 +3521,156 @@ out Statement statement) { if (la.kind == 15) { Block( -#line 1652 "cs.ATG" +#line 1659 "cs.ATG" out statement); } else if (la.kind == 11) { lexer.NextToken(); -#line 1654 "cs.ATG" +#line 1661 "cs.ATG" statement = new EmptyStatement(); } else if ( -#line 1656 "cs.ATG" +#line 1663 "cs.ATG" UnCheckedAndLBrace()) { -#line 1656 "cs.ATG" +#line 1663 "cs.ATG" Statement block; bool isChecked = true; if (la.kind == 56) { lexer.NextToken(); } else if (la.kind == 116) { lexer.NextToken(); -#line 1657 "cs.ATG" +#line 1664 "cs.ATG" isChecked = false; } else SynErr(166); Block( -#line 1658 "cs.ATG" +#line 1665 "cs.ATG" out block); -#line 1658 "cs.ATG" +#line 1665 "cs.ATG" statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); } else if (la.kind == 77) { lexer.NextToken(); -#line 1660 "cs.ATG" +#line 1667 "cs.ATG" Statement elseStatement = null; Expect(19); Expr( -#line 1661 "cs.ATG" +#line 1668 "cs.ATG" out expr); Expect(20); EmbeddedStatement( -#line 1662 "cs.ATG" +#line 1669 "cs.ATG" out embeddedStatement); if (la.kind == 65) { lexer.NextToken(); EmbeddedStatement( -#line 1663 "cs.ATG" +#line 1670 "cs.ATG" out elseStatement); } -#line 1664 "cs.ATG" +#line 1671 "cs.ATG" statement = elseStatement != null ? (Statement)new IfElseStatement(expr, embeddedStatement, elseStatement) : (Statement)new IfElseStatement(expr, embeddedStatement); } else if (la.kind == 108) { lexer.NextToken(); -#line 1665 "cs.ATG" +#line 1672 "cs.ATG" ArrayList switchSections = new ArrayList(); SwitchSection switchSection; Expect(19); Expr( -#line 1666 "cs.ATG" +#line 1673 "cs.ATG" out expr); Expect(20); Expect(15); while (la.kind == 53 || la.kind == 61) { SwitchSection( -#line 1667 "cs.ATG" +#line 1674 "cs.ATG" out switchSection); -#line 1667 "cs.ATG" +#line 1674 "cs.ATG" switchSections.Add(switchSection); } Expect(16); -#line 1668 "cs.ATG" +#line 1675 "cs.ATG" statement = new SwitchStatement(expr, switchSections); } else if (la.kind == 123) { lexer.NextToken(); Expect(19); Expr( -#line 1670 "cs.ATG" +#line 1677 "cs.ATG" out expr); Expect(20); EmbeddedStatement( -#line 1672 "cs.ATG" +#line 1679 "cs.ATG" out embeddedStatement); -#line 1672 "cs.ATG" +#line 1679 "cs.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); } else if (la.kind == 63) { lexer.NextToken(); EmbeddedStatement( -#line 1673 "cs.ATG" +#line 1680 "cs.ATG" out embeddedStatement); Expect(123); Expect(19); Expr( -#line 1674 "cs.ATG" +#line 1681 "cs.ATG" out expr); Expect(20); Expect(11); -#line 1674 "cs.ATG" +#line 1681 "cs.ATG" statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); } else if (la.kind == 74) { lexer.NextToken(); -#line 1675 "cs.ATG" +#line 1682 "cs.ATG" ArrayList initializer = null; ArrayList iterator = null; Expect(19); if (StartOf(4)) { ForInitializer( -#line 1676 "cs.ATG" +#line 1683 "cs.ATG" out initializer); } Expect(11); if (StartOf(4)) { Expr( -#line 1677 "cs.ATG" +#line 1684 "cs.ATG" out expr); } Expect(11); if (StartOf(4)) { ForIterator( -#line 1678 "cs.ATG" +#line 1685 "cs.ATG" out iterator); } Expect(20); EmbeddedStatement( -#line 1679 "cs.ATG" +#line 1686 "cs.ATG" out embeddedStatement); -#line 1679 "cs.ATG" +#line 1686 "cs.ATG" statement = new ForStatement(initializer, expr, iterator, embeddedStatement); } else if (la.kind == 75) { lexer.NextToken(); Expect(19); Type( -#line 1680 "cs.ATG" +#line 1687 "cs.ATG" out type); Expect(1); -#line 1680 "cs.ATG" +#line 1687 "cs.ATG" string varName = t.val; Point start = t.Location; Expect(79); Expr( -#line 1681 "cs.ATG" +#line 1688 "cs.ATG" out expr); Expect(20); EmbeddedStatement( -#line 1682 "cs.ATG" +#line 1689 "cs.ATG" out embeddedStatement); -#line 1682 "cs.ATG" +#line 1689 "cs.ATG" statement = new ForeachStatement(type, varName , expr, embeddedStatement); statement.EndLocation = t.EndLocation; @@ -3670,34 +3678,34 @@ out embeddedStatement); lexer.NextToken(); Expect(11); -#line 1686 "cs.ATG" +#line 1693 "cs.ATG" statement = new BreakStatement(); } else if (la.kind == 59) { lexer.NextToken(); Expect(11); -#line 1687 "cs.ATG" +#line 1694 "cs.ATG" statement = new ContinueStatement(); } else if (la.kind == 76) { GotoStatement( -#line 1688 "cs.ATG" +#line 1695 "cs.ATG" out statement); } else if ( -#line 1689 "cs.ATG" +#line 1696 "cs.ATG" IsYieldStatement()) { Expect(1); if (la.kind == 99) { lexer.NextToken(); Expr( -#line 1689 "cs.ATG" +#line 1696 "cs.ATG" out expr); -#line 1689 "cs.ATG" +#line 1696 "cs.ATG" statement = new YieldStatement(new ReturnStatement(expr)); } else if (la.kind == 51) { lexer.NextToken(); -#line 1690 "cs.ATG" +#line 1697 "cs.ATG" statement = new YieldStatement(new BreakStatement()); } else SynErr(167); Expect(11); @@ -3705,375 +3713,375 @@ out expr); lexer.NextToken(); if (StartOf(4)) { Expr( -#line 1691 "cs.ATG" +#line 1698 "cs.ATG" out expr); } Expect(11); -#line 1691 "cs.ATG" +#line 1698 "cs.ATG" statement = new ReturnStatement(expr); } else if (la.kind == 110) { lexer.NextToken(); if (StartOf(4)) { Expr( -#line 1692 "cs.ATG" +#line 1699 "cs.ATG" out expr); } Expect(11); -#line 1692 "cs.ATG" +#line 1699 "cs.ATG" statement = new ThrowStatement(expr); } else if (StartOf(4)) { StatementExpr( -#line 1694 "cs.ATG" +#line 1701 "cs.ATG" out statement); Expect(11); } else if (la.kind == 112) { TryStatement( -#line 1696 "cs.ATG" +#line 1703 "cs.ATG" out statement); } else if (la.kind == 84) { lexer.NextToken(); Expect(19); Expr( -#line 1698 "cs.ATG" +#line 1705 "cs.ATG" out expr); Expect(20); EmbeddedStatement( -#line 1699 "cs.ATG" +#line 1706 "cs.ATG" out embeddedStatement); -#line 1699 "cs.ATG" +#line 1706 "cs.ATG" statement = new LockStatement(expr, embeddedStatement); } else if (la.kind == 119) { -#line 1701 "cs.ATG" +#line 1708 "cs.ATG" Statement resourceAcquisitionStmt = null; lexer.NextToken(); Expect(19); ResourceAcquisition( -#line 1703 "cs.ATG" +#line 1710 "cs.ATG" out resourceAcquisitionStmt); Expect(20); EmbeddedStatement( -#line 1704 "cs.ATG" +#line 1711 "cs.ATG" out embeddedStatement); -#line 1704 "cs.ATG" +#line 1711 "cs.ATG" statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); } else if (la.kind == 117) { lexer.NextToken(); Block( -#line 1706 "cs.ATG" +#line 1713 "cs.ATG" out embeddedStatement); -#line 1706 "cs.ATG" +#line 1713 "cs.ATG" statement = new UnsafeStatement(embeddedStatement); } else if (la.kind == 72) { lexer.NextToken(); Expect(19); Type( -#line 1709 "cs.ATG" +#line 1716 "cs.ATG" out type); -#line 1709 "cs.ATG" +#line 1716 "cs.ATG" if (type.PointerNestingLevel == 0) Error("can only fix pointer types"); ArrayList pointerDeclarators = new ArrayList(1); Expect(1); -#line 1712 "cs.ATG" +#line 1719 "cs.ATG" string identifier = t.val; Expect(3); Expr( -#line 1713 "cs.ATG" +#line 1720 "cs.ATG" out expr); -#line 1713 "cs.ATG" +#line 1720 "cs.ATG" pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); while (la.kind == 13) { lexer.NextToken(); Expect(1); -#line 1715 "cs.ATG" +#line 1722 "cs.ATG" identifier = t.val; Expect(3); Expr( -#line 1716 "cs.ATG" +#line 1723 "cs.ATG" out expr); -#line 1716 "cs.ATG" +#line 1723 "cs.ATG" pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); } Expect(20); EmbeddedStatement( -#line 1718 "cs.ATG" +#line 1725 "cs.ATG" out embeddedStatement); -#line 1718 "cs.ATG" +#line 1725 "cs.ATG" statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); } else SynErr(168); } void SwitchSection( -#line 1740 "cs.ATG" +#line 1747 "cs.ATG" out SwitchSection stmt) { -#line 1742 "cs.ATG" +#line 1749 "cs.ATG" SwitchSection switchSection = new SwitchSection(); CaseLabel label; SwitchLabel( -#line 1746 "cs.ATG" +#line 1753 "cs.ATG" out label); -#line 1746 "cs.ATG" +#line 1753 "cs.ATG" switchSection.SwitchLabels.Add(label); while (la.kind == 53 || la.kind == 61) { SwitchLabel( -#line 1748 "cs.ATG" +#line 1755 "cs.ATG" out label); -#line 1748 "cs.ATG" +#line 1755 "cs.ATG" switchSection.SwitchLabels.Add(label); } -#line 1750 "cs.ATG" +#line 1757 "cs.ATG" compilationUnit.BlockStart(switchSection); Statement(); while (StartOf(20)) { Statement(); } -#line 1753 "cs.ATG" +#line 1760 "cs.ATG" compilationUnit.BlockEnd(); stmt = switchSection; } void ForInitializer( -#line 1721 "cs.ATG" +#line 1728 "cs.ATG" out ArrayList initializer) { -#line 1723 "cs.ATG" +#line 1730 "cs.ATG" Statement stmt; initializer = new ArrayList(); if ( -#line 1727 "cs.ATG" +#line 1734 "cs.ATG" IsLocalVarDecl()) { LocalVariableDecl( -#line 1727 "cs.ATG" +#line 1734 "cs.ATG" out stmt); -#line 1727 "cs.ATG" +#line 1734 "cs.ATG" initializer.Add(stmt); } else if (StartOf(4)) { StatementExpr( -#line 1728 "cs.ATG" +#line 1735 "cs.ATG" out stmt); -#line 1728 "cs.ATG" +#line 1735 "cs.ATG" initializer.Add(stmt); while (la.kind == 13) { lexer.NextToken(); StatementExpr( -#line 1728 "cs.ATG" +#line 1735 "cs.ATG" out stmt); -#line 1728 "cs.ATG" +#line 1735 "cs.ATG" initializer.Add(stmt); } -#line 1728 "cs.ATG" +#line 1735 "cs.ATG" initializer.Add(stmt); } else SynErr(169); } void ForIterator( -#line 1731 "cs.ATG" +#line 1738 "cs.ATG" out ArrayList iterator) { -#line 1733 "cs.ATG" +#line 1740 "cs.ATG" Statement stmt; iterator = new ArrayList(); StatementExpr( -#line 1737 "cs.ATG" +#line 1744 "cs.ATG" out stmt); -#line 1737 "cs.ATG" +#line 1744 "cs.ATG" iterator.Add(stmt); while (la.kind == 13) { lexer.NextToken(); StatementExpr( -#line 1737 "cs.ATG" +#line 1744 "cs.ATG" out stmt); -#line 1737 "cs.ATG" +#line 1744 "cs.ATG" iterator.Add(stmt); } } void GotoStatement( -#line 1803 "cs.ATG" +#line 1810 "cs.ATG" out Statement stmt) { -#line 1804 "cs.ATG" +#line 1811 "cs.ATG" Expression expr; stmt = null; Expect(76); if (la.kind == 1) { lexer.NextToken(); -#line 1808 "cs.ATG" +#line 1815 "cs.ATG" stmt = new GotoStatement(t.val); Expect(11); } else if (la.kind == 53) { lexer.NextToken(); Expr( -#line 1809 "cs.ATG" +#line 1816 "cs.ATG" out expr); Expect(11); -#line 1809 "cs.ATG" +#line 1816 "cs.ATG" stmt = new GotoCaseStatement(expr); } else if (la.kind == 61) { lexer.NextToken(); Expect(11); -#line 1810 "cs.ATG" +#line 1817 "cs.ATG" stmt = new GotoCaseStatement(null); } else SynErr(170); } void StatementExpr( -#line 1830 "cs.ATG" +#line 1837 "cs.ATG" out Statement stmt) { -#line 1835 "cs.ATG" +#line 1842 "cs.ATG" bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || la.kind == Tokens.Not || la.kind == Tokens.BitwiseComplement || la.kind == Tokens.Times || la.kind == Tokens.BitwiseAnd || IsTypeCast(); Expression expr = null; UnaryExpr( -#line 1841 "cs.ATG" +#line 1848 "cs.ATG" out expr); if (StartOf(6)) { -#line 1844 "cs.ATG" +#line 1851 "cs.ATG" AssignmentOperatorType op; Expression val; AssignmentOperator( -#line 1844 "cs.ATG" +#line 1851 "cs.ATG" out op); Expr( -#line 1844 "cs.ATG" +#line 1851 "cs.ATG" out val); -#line 1844 "cs.ATG" +#line 1851 "cs.ATG" expr = new AssignmentExpression(expr, op, val); } else if (la.kind == 11 || la.kind == 13 || la.kind == 20) { -#line 1845 "cs.ATG" +#line 1852 "cs.ATG" if (mustBeAssignment) Error("error in assignment."); } else SynErr(171); -#line 1846 "cs.ATG" +#line 1853 "cs.ATG" stmt = new StatementExpression(expr); } void TryStatement( -#line 1765 "cs.ATG" +#line 1772 "cs.ATG" out Statement tryStatement) { -#line 1767 "cs.ATG" +#line 1774 "cs.ATG" Statement blockStmt = null, finallyStmt = null; ArrayList catchClauses = null; Expect(112); Block( -#line 1771 "cs.ATG" +#line 1778 "cs.ATG" out blockStmt); if (la.kind == 54) { CatchClauses( -#line 1773 "cs.ATG" +#line 1780 "cs.ATG" out catchClauses); if (la.kind == 71) { lexer.NextToken(); Block( -#line 1773 "cs.ATG" +#line 1780 "cs.ATG" out finallyStmt); } } else if (la.kind == 71) { lexer.NextToken(); Block( -#line 1774 "cs.ATG" +#line 1781 "cs.ATG" out finallyStmt); } else SynErr(172); -#line 1777 "cs.ATG" +#line 1784 "cs.ATG" tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); } void ResourceAcquisition( -#line 1814 "cs.ATG" +#line 1821 "cs.ATG" out Statement stmt) { -#line 1816 "cs.ATG" +#line 1823 "cs.ATG" stmt = null; Expression expr; if ( -#line 1821 "cs.ATG" +#line 1828 "cs.ATG" IsLocalVarDecl()) { LocalVariableDecl( -#line 1821 "cs.ATG" +#line 1828 "cs.ATG" out stmt); } else if (StartOf(4)) { Expr( -#line 1822 "cs.ATG" +#line 1829 "cs.ATG" out expr); -#line 1826 "cs.ATG" +#line 1833 "cs.ATG" stmt = new StatementExpression(expr); } else SynErr(173); } void SwitchLabel( -#line 1758 "cs.ATG" +#line 1765 "cs.ATG" out CaseLabel label) { -#line 1759 "cs.ATG" +#line 1766 "cs.ATG" Expression expr = null; label = null; if (la.kind == 53) { lexer.NextToken(); Expr( -#line 1761 "cs.ATG" +#line 1768 "cs.ATG" out expr); Expect(9); -#line 1761 "cs.ATG" +#line 1768 "cs.ATG" label = new CaseLabel(expr); } else if (la.kind == 61) { lexer.NextToken(); Expect(9); -#line 1762 "cs.ATG" +#line 1769 "cs.ATG" label = new CaseLabel(); } else SynErr(174); } void CatchClauses( -#line 1782 "cs.ATG" +#line 1789 "cs.ATG" out ArrayList catchClauses) { -#line 1784 "cs.ATG" +#line 1791 "cs.ATG" catchClauses = new ArrayList(); Expect(54); -#line 1787 "cs.ATG" +#line 1794 "cs.ATG" string name; string identifier; Statement stmt; @@ -4081,138 +4089,138 @@ out ArrayList catchClauses) { if (la.kind == 15) { Block( -#line 1794 "cs.ATG" +#line 1801 "cs.ATG" out stmt); -#line 1794 "cs.ATG" +#line 1801 "cs.ATG" catchClauses.Add(new CatchClause(stmt)); } else if (la.kind == 19) { lexer.NextToken(); ClassType( -#line 1796 "cs.ATG" +#line 1803 "cs.ATG" out name, out types); -#line 1796 "cs.ATG" +#line 1803 "cs.ATG" identifier = null; if (la.kind == 1) { lexer.NextToken(); -#line 1796 "cs.ATG" +#line 1803 "cs.ATG" identifier = t.val; } Expect(20); Block( -#line 1796 "cs.ATG" +#line 1803 "cs.ATG" out stmt); -#line 1796 "cs.ATG" +#line 1803 "cs.ATG" catchClauses.Add(new CatchClause(new TypeReference(name, 0, null, types), identifier, stmt)); while ( -#line 1797 "cs.ATG" +#line 1804 "cs.ATG" IsTypedCatch()) { Expect(54); Expect(19); ClassType( -#line 1797 "cs.ATG" +#line 1804 "cs.ATG" out name, out types); -#line 1797 "cs.ATG" +#line 1804 "cs.ATG" identifier = null; if (la.kind == 1) { lexer.NextToken(); -#line 1797 "cs.ATG" +#line 1804 "cs.ATG" identifier = t.val; } Expect(20); Block( -#line 1797 "cs.ATG" +#line 1804 "cs.ATG" out stmt); -#line 1797 "cs.ATG" +#line 1804 "cs.ATG" catchClauses.Add(new CatchClause(new TypeReference(name, 0, null, types), identifier, stmt)); } if (la.kind == 54) { lexer.NextToken(); Block( -#line 1799 "cs.ATG" +#line 1806 "cs.ATG" out stmt); -#line 1799 "cs.ATG" +#line 1806 "cs.ATG" catchClauses.Add(new CatchClause(stmt)); } } else SynErr(175); } void UnaryExpr( -#line 1862 "cs.ATG" +#line 1869 "cs.ATG" out Expression uExpr) { -#line 1864 "cs.ATG" +#line 1871 "cs.ATG" TypeReference type = null; Expression expr; ArrayList expressions = new ArrayList(); uExpr = null; while (StartOf(24) || -#line 1888 "cs.ATG" +#line 1895 "cs.ATG" IsTypeCast()) { if (la.kind == 4) { lexer.NextToken(); -#line 1873 "cs.ATG" +#line 1880 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); } else if (la.kind == 5) { lexer.NextToken(); -#line 1874 "cs.ATG" +#line 1881 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); } else if (la.kind == 23) { lexer.NextToken(); -#line 1875 "cs.ATG" +#line 1882 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); } else if (la.kind == 26) { lexer.NextToken(); -#line 1876 "cs.ATG" +#line 1883 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); } else if (la.kind == 6) { lexer.NextToken(); -#line 1877 "cs.ATG" +#line 1884 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Star)); } else if (la.kind == 30) { lexer.NextToken(); -#line 1878 "cs.ATG" +#line 1885 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); } else if (la.kind == 31) { lexer.NextToken(); -#line 1879 "cs.ATG" +#line 1886 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); } else if (la.kind == 27) { lexer.NextToken(); -#line 1880 "cs.ATG" +#line 1887 "cs.ATG" expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitWiseAnd)); } else { Expect(19); Type( -#line 1888 "cs.ATG" +#line 1895 "cs.ATG" out type); Expect(20); -#line 1888 "cs.ATG" +#line 1895 "cs.ATG" expressions.Add(new CastExpression(type)); } } PrimaryExpr( -#line 1892 "cs.ATG" +#line 1899 "cs.ATG" out expr); -#line 1892 "cs.ATG" +#line 1899 "cs.ATG" for (int i = 0; i < expressions.Count; ++i) { Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr; if (expressions[i] is CastExpression) { @@ -4230,33 +4238,33 @@ out expr); } void ConditionalOrExpr( -#line 2063 "cs.ATG" +#line 2070 "cs.ATG" ref Expression outExpr) { -#line 2064 "cs.ATG" +#line 2071 "cs.ATG" Expression expr; ConditionalAndExpr( -#line 2066 "cs.ATG" +#line 2073 "cs.ATG" ref outExpr); while (la.kind == 25) { lexer.NextToken(); UnaryExpr( -#line 2066 "cs.ATG" +#line 2073 "cs.ATG" out expr); ConditionalAndExpr( -#line 2066 "cs.ATG" +#line 2073 "cs.ATG" ref expr); -#line 2066 "cs.ATG" +#line 2073 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); } } void PrimaryExpr( -#line 1909 "cs.ATG" +#line 1916 "cs.ATG" out Expression pexpr) { -#line 1911 "cs.ATG" +#line 1918 "cs.ATG" TypeReference type = null; List typeList = null; bool isArrayCreation = false; @@ -4267,349 +4275,349 @@ out Expression pexpr) { case 111: { lexer.NextToken(); -#line 1919 "cs.ATG" +#line 1926 "cs.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 70: { lexer.NextToken(); -#line 1920 "cs.ATG" +#line 1927 "cs.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 88: { lexer.NextToken(); -#line 1921 "cs.ATG" +#line 1928 "cs.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 2: { lexer.NextToken(); -#line 1922 "cs.ATG" +#line 1929 "cs.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val); break; } case 1: { lexer.NextToken(); -#line 1924 "cs.ATG" +#line 1931 "cs.ATG" pexpr = new IdentifierExpression(t.val); break; } case 19: { lexer.NextToken(); Expr( -#line 1926 "cs.ATG" +#line 1933 "cs.ATG" out expr); Expect(20); -#line 1926 "cs.ATG" +#line 1933 "cs.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 50: case 52: case 55: case 60: case 64: case 73: case 80: case 85: case 89: case 100: case 102: case 106: case 114: case 115: case 118: { -#line 1928 "cs.ATG" +#line 1935 "cs.ATG" string val = null; switch (la.kind) { case 50: { lexer.NextToken(); -#line 1930 "cs.ATG" +#line 1937 "cs.ATG" val = "bool"; break; } case 52: { lexer.NextToken(); -#line 1931 "cs.ATG" +#line 1938 "cs.ATG" val = "byte"; break; } case 55: { lexer.NextToken(); -#line 1932 "cs.ATG" +#line 1939 "cs.ATG" val = "char"; break; } case 60: { lexer.NextToken(); -#line 1933 "cs.ATG" +#line 1940 "cs.ATG" val = "decimal"; break; } case 64: { lexer.NextToken(); -#line 1934 "cs.ATG" +#line 1941 "cs.ATG" val = "double"; break; } case 73: { lexer.NextToken(); -#line 1935 "cs.ATG" +#line 1942 "cs.ATG" val = "float"; break; } case 80: { lexer.NextToken(); -#line 1936 "cs.ATG" +#line 1943 "cs.ATG" val = "int"; break; } case 85: { lexer.NextToken(); -#line 1937 "cs.ATG" +#line 1944 "cs.ATG" val = "long"; break; } case 89: { lexer.NextToken(); -#line 1938 "cs.ATG" +#line 1945 "cs.ATG" val = "object"; break; } case 100: { lexer.NextToken(); -#line 1939 "cs.ATG" +#line 1946 "cs.ATG" val = "sbyte"; break; } case 102: { lexer.NextToken(); -#line 1940 "cs.ATG" +#line 1947 "cs.ATG" val = "short"; break; } case 106: { lexer.NextToken(); -#line 1941 "cs.ATG" +#line 1948 "cs.ATG" val = "string"; break; } case 114: { lexer.NextToken(); -#line 1942 "cs.ATG" +#line 1949 "cs.ATG" val = "uint"; break; } case 115: { lexer.NextToken(); -#line 1943 "cs.ATG" +#line 1950 "cs.ATG" val = "ulong"; break; } case 118: { lexer.NextToken(); -#line 1944 "cs.ATG" +#line 1951 "cs.ATG" val = "ushort"; break; } } -#line 1945 "cs.ATG" +#line 1952 "cs.ATG" t.val = ""; Expect(14); Expect(1); -#line 1945 "cs.ATG" +#line 1952 "cs.ATG" pexpr = new FieldReferenceExpression(new TypeReferenceExpression(val), t.val); break; } case 109: { lexer.NextToken(); -#line 1947 "cs.ATG" +#line 1954 "cs.ATG" pexpr = new ThisReferenceExpression(); break; } case 49: { lexer.NextToken(); -#line 1949 "cs.ATG" +#line 1956 "cs.ATG" Expression retExpr = new BaseReferenceExpression(); if (la.kind == 14) { lexer.NextToken(); Expect(1); -#line 1951 "cs.ATG" +#line 1958 "cs.ATG" retExpr = new FieldReferenceExpression(retExpr, t.val); } else if (la.kind == 17) { lexer.NextToken(); Expr( -#line 1952 "cs.ATG" +#line 1959 "cs.ATG" out expr); -#line 1952 "cs.ATG" +#line 1959 "cs.ATG" ArrayList indices = new ArrayList(); if (expr != null) { indices.Add(expr); } while (la.kind == 13) { lexer.NextToken(); Expr( -#line 1953 "cs.ATG" +#line 1960 "cs.ATG" out expr); -#line 1953 "cs.ATG" +#line 1960 "cs.ATG" if (expr != null) { indices.Add(expr); } } Expect(18); -#line 1954 "cs.ATG" +#line 1961 "cs.ATG" retExpr = new IndexerExpression(retExpr, indices); } else SynErr(176); -#line 1955 "cs.ATG" +#line 1962 "cs.ATG" pexpr = retExpr; break; } case 87: { lexer.NextToken(); NonArrayType( -#line 1956 "cs.ATG" +#line 1963 "cs.ATG" out type); -#line 1956 "cs.ATG" +#line 1963 "cs.ATG" ArrayList parameters = new ArrayList(); if (la.kind == 19) { lexer.NextToken(); -#line 1961 "cs.ATG" +#line 1968 "cs.ATG" ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); if (StartOf(21)) { Argument( -#line 1962 "cs.ATG" +#line 1969 "cs.ATG" out expr); -#line 1962 "cs.ATG" +#line 1969 "cs.ATG" if (expr != null) { parameters.Add(expr); } while (la.kind == 13) { lexer.NextToken(); Argument( -#line 1963 "cs.ATG" +#line 1970 "cs.ATG" out expr); -#line 1963 "cs.ATG" +#line 1970 "cs.ATG" if (expr != null) { parameters.Add(expr); } } } Expect(20); -#line 1965 "cs.ATG" +#line 1972 "cs.ATG" pexpr = oce; } else if (la.kind == 17) { -#line 1967 "cs.ATG" +#line 1974 "cs.ATG" isArrayCreation = true; ArrayCreateExpression ace = new ArrayCreateExpression(type); pexpr = ace; lexer.NextToken(); -#line 1968 "cs.ATG" +#line 1975 "cs.ATG" int dims = 0; ArrayList rank = new ArrayList(); ArrayList parameterExpression = new ArrayList(); if (StartOf(4)) { Expr( -#line 1972 "cs.ATG" +#line 1979 "cs.ATG" out expr); -#line 1972 "cs.ATG" +#line 1979 "cs.ATG" if (expr != null) { parameterExpression.Add(expr); } while (la.kind == 13) { lexer.NextToken(); Expr( -#line 1974 "cs.ATG" +#line 1981 "cs.ATG" out expr); -#line 1974 "cs.ATG" +#line 1981 "cs.ATG" if (expr != null) { parameterExpression.Add(expr); } } Expect(18); -#line 1976 "cs.ATG" +#line 1983 "cs.ATG" parameters.Add(new ArrayCreationParameter(parameterExpression)); ace.Parameters = parameters; while ( -#line 1979 "cs.ATG" +#line 1986 "cs.ATG" IsDims()) { Expect(17); -#line 1979 "cs.ATG" +#line 1986 "cs.ATG" dims =0; while (la.kind == 13) { lexer.NextToken(); -#line 1980 "cs.ATG" +#line 1987 "cs.ATG" dims++; } -#line 1980 "cs.ATG" +#line 1987 "cs.ATG" rank.Add(dims); parameters.Add(new ArrayCreationParameter(dims)); Expect(18); } -#line 1984 "cs.ATG" +#line 1991 "cs.ATG" if (rank.Count > 0) { ace.Rank = (int[])rank.ToArray(typeof (int)); } if (la.kind == 15) { ArrayInitializer( -#line 1988 "cs.ATG" +#line 1995 "cs.ATG" out expr); -#line 1988 "cs.ATG" +#line 1995 "cs.ATG" ace.ArrayInitializer = (ArrayInitializerExpression)expr; } } else if (la.kind == 13 || la.kind == 18) { while (la.kind == 13) { lexer.NextToken(); -#line 1990 "cs.ATG" +#line 1997 "cs.ATG" dims++; } -#line 1991 "cs.ATG" +#line 1998 "cs.ATG" parameters.Add(new ArrayCreationParameter(dims)); Expect(18); while ( -#line 1993 "cs.ATG" +#line 2000 "cs.ATG" IsDims()) { Expect(17); -#line 1993 "cs.ATG" +#line 2000 "cs.ATG" dims =0; while (la.kind == 13) { lexer.NextToken(); -#line 1993 "cs.ATG" +#line 2000 "cs.ATG" dims++; } -#line 1993 "cs.ATG" +#line 2000 "cs.ATG" parameters.Add(new ArrayCreationParameter(dims)); Expect(18); } ArrayInitializer( -#line 1993 "cs.ATG" +#line 2000 "cs.ATG" out expr); -#line 1993 "cs.ATG" +#line 2000 "cs.ATG" ace.ArrayInitializer = (ArrayInitializerExpression)expr; ace.Parameters = parameters; } else SynErr(177); } else SynErr(178); @@ -4619,20 +4627,20 @@ out expr); lexer.NextToken(); Expect(19); if ( -#line 1999 "cs.ATG" +#line 2006 "cs.ATG" NotVoidPointer()) { Expect(121); -#line 1999 "cs.ATG" +#line 2006 "cs.ATG" type = new TypeReference("void"); } else if (StartOf(8)) { Type( -#line 2000 "cs.ATG" +#line 2007 "cs.ATG" out type); } else SynErr(179); Expect(20); -#line 2001 "cs.ATG" +#line 2008 "cs.ATG" pexpr = new TypeOfExpression(type); break; } @@ -4640,11 +4648,11 @@ out type); lexer.NextToken(); Expect(19); Type( -#line 2002 "cs.ATG" +#line 2009 "cs.ATG" out type); Expect(20); -#line 2002 "cs.ATG" +#line 2009 "cs.ATG" pexpr = new SizeOfExpression(type); break; } @@ -4652,11 +4660,11 @@ out type); lexer.NextToken(); Expect(19); Expr( -#line 2003 "cs.ATG" +#line 2010 "cs.ATG" out expr); Expect(20); -#line 2003 "cs.ATG" +#line 2010 "cs.ATG" pexpr = new CheckedExpression(expr); break; } @@ -4664,158 +4672,158 @@ out expr); lexer.NextToken(); Expect(19); Expr( -#line 2004 "cs.ATG" +#line 2011 "cs.ATG" out expr); Expect(20); -#line 2004 "cs.ATG" +#line 2011 "cs.ATG" pexpr = new UncheckedExpression(expr); break; } case 62: { lexer.NextToken(); AnonymousMethodExpr( -#line 2005 "cs.ATG" +#line 2012 "cs.ATG" out expr); -#line 2005 "cs.ATG" +#line 2012 "cs.ATG" pexpr = expr; break; } default: SynErr(180); break; } while (StartOf(25) || -#line 2016 "cs.ATG" +#line 2023 "cs.ATG" IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr) || -#line 2024 "cs.ATG" +#line 2031 "cs.ATG" IsGenericFollowedBy(Tokens.OpenParenthesis)) { if (la.kind == 30 || la.kind == 31) { if (la.kind == 30) { lexer.NextToken(); -#line 2009 "cs.ATG" +#line 2016 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); } else if (la.kind == 31) { lexer.NextToken(); -#line 2010 "cs.ATG" +#line 2017 "cs.ATG" pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); } else SynErr(181); } else if (la.kind == 46) { lexer.NextToken(); Expect(1); -#line 2013 "cs.ATG" +#line 2020 "cs.ATG" pexpr = new PointerReferenceExpression(pexpr, t.val); } else if (la.kind == 14) { lexer.NextToken(); Expect(1); -#line 2014 "cs.ATG" +#line 2021 "cs.ATG" pexpr = new FieldReferenceExpression(pexpr, t.val); } else if ( -#line 2016 "cs.ATG" +#line 2023 "cs.ATG" IsGenericFollowedBy(Tokens.Dot) && IsTypeReferenceExpression(pexpr)) { TypeArgumentList( -#line 2017 "cs.ATG" +#line 2024 "cs.ATG" out typeList); Expect(14); Expect(1); -#line 2018 "cs.ATG" +#line 2025 "cs.ATG" pexpr = new FieldReferenceExpression(GetTypeReferenceExpression(pexpr, typeList), t.val); } else if (la.kind == 19) { lexer.NextToken(); -#line 2020 "cs.ATG" +#line 2027 "cs.ATG" ArrayList parameters = new ArrayList(); if (StartOf(21)) { Argument( -#line 2021 "cs.ATG" +#line 2028 "cs.ATG" out expr); -#line 2021 "cs.ATG" +#line 2028 "cs.ATG" if (expr != null) {parameters.Add(expr);} while (la.kind == 13) { lexer.NextToken(); Argument( -#line 2022 "cs.ATG" +#line 2029 "cs.ATG" out expr); -#line 2022 "cs.ATG" +#line 2029 "cs.ATG" if (expr != null) {parameters.Add(expr);} } } Expect(20); -#line 2023 "cs.ATG" +#line 2030 "cs.ATG" pexpr = new InvocationExpression(pexpr, parameters); } else if ( -#line 2024 "cs.ATG" +#line 2031 "cs.ATG" IsGenericFollowedBy(Tokens.OpenParenthesis)) { TypeArgumentList( -#line 2024 "cs.ATG" +#line 2031 "cs.ATG" out typeList); Expect(19); -#line 2025 "cs.ATG" +#line 2032 "cs.ATG" ArrayList parameters = new ArrayList(); if (StartOf(21)) { Argument( -#line 2026 "cs.ATG" +#line 2033 "cs.ATG" out expr); -#line 2026 "cs.ATG" +#line 2033 "cs.ATG" if (expr != null) {parameters.Add(expr);} while (la.kind == 13) { lexer.NextToken(); Argument( -#line 2027 "cs.ATG" +#line 2034 "cs.ATG" out expr); -#line 2027 "cs.ATG" +#line 2034 "cs.ATG" if (expr != null) {parameters.Add(expr);} } } Expect(20); -#line 2028 "cs.ATG" +#line 2035 "cs.ATG" pexpr = new InvocationExpression(pexpr, parameters, typeList); } else { -#line 2030 "cs.ATG" +#line 2037 "cs.ATG" if (isArrayCreation) Error("element access not allow on array creation"); ArrayList indices = new ArrayList(); lexer.NextToken(); Expr( -#line 2033 "cs.ATG" +#line 2040 "cs.ATG" out expr); -#line 2033 "cs.ATG" +#line 2040 "cs.ATG" if (expr != null) { indices.Add(expr); } while (la.kind == 13) { lexer.NextToken(); Expr( -#line 2034 "cs.ATG" +#line 2041 "cs.ATG" out expr); -#line 2034 "cs.ATG" +#line 2041 "cs.ATG" if (expr != null) { indices.Add(expr); } } Expect(18); -#line 2035 "cs.ATG" +#line 2042 "cs.ATG" pexpr = new IndexerExpression(pexpr, indices); } } } void AnonymousMethodExpr( -#line 2039 "cs.ATG" +#line 2046 "cs.ATG" out Expression outExpr) { -#line 2041 "cs.ATG" +#line 2048 "cs.ATG" AnonymousMethodExpression expr = new AnonymousMethodExpression(); expr.StartLocation = t.Location; Statement stmt; @@ -4825,336 +4833,336 @@ out Expression outExpr) { Expect(19); if (StartOf(9)) { FormalParameterList( -#line 2049 "cs.ATG" +#line 2056 "cs.ATG" out p); -#line 2049 "cs.ATG" +#line 2056 "cs.ATG" expr.Parameters = p; } Expect(20); -#line 2053 "cs.ATG" +#line 2060 "cs.ATG" if (compilationUnit != null) { Block( -#line 2054 "cs.ATG" +#line 2061 "cs.ATG" out stmt); -#line 2054 "cs.ATG" +#line 2061 "cs.ATG" expr.Body = (BlockStatement)stmt; -#line 2055 "cs.ATG" +#line 2062 "cs.ATG" } else { Expect(15); -#line 2057 "cs.ATG" +#line 2064 "cs.ATG" lexer.SkipCurrentBlock(); Expect(16); -#line 2059 "cs.ATG" +#line 2066 "cs.ATG" } -#line 2060 "cs.ATG" +#line 2067 "cs.ATG" expr.EndLocation = t.Location; } void TypeArgumentList( -#line 2192 "cs.ATG" +#line 2199 "cs.ATG" out List types) { -#line 2194 "cs.ATG" +#line 2201 "cs.ATG" types = new List(); TypeReference type = null; Expect(22); Type( -#line 2198 "cs.ATG" +#line 2205 "cs.ATG" out type); -#line 2198 "cs.ATG" +#line 2205 "cs.ATG" types.Add(type); while (la.kind == 13) { lexer.NextToken(); Type( -#line 2199 "cs.ATG" +#line 2206 "cs.ATG" out type); -#line 2199 "cs.ATG" +#line 2206 "cs.ATG" types.Add(type); } Expect(21); } void ConditionalAndExpr( -#line 2069 "cs.ATG" +#line 2076 "cs.ATG" ref Expression outExpr) { -#line 2070 "cs.ATG" +#line 2077 "cs.ATG" Expression expr; InclusiveOrExpr( -#line 2072 "cs.ATG" +#line 2079 "cs.ATG" ref outExpr); while (la.kind == 24) { lexer.NextToken(); UnaryExpr( -#line 2072 "cs.ATG" +#line 2079 "cs.ATG" out expr); InclusiveOrExpr( -#line 2072 "cs.ATG" +#line 2079 "cs.ATG" ref expr); -#line 2072 "cs.ATG" +#line 2079 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); } } void InclusiveOrExpr( -#line 2075 "cs.ATG" +#line 2082 "cs.ATG" ref Expression outExpr) { -#line 2076 "cs.ATG" +#line 2083 "cs.ATG" Expression expr; ExclusiveOrExpr( -#line 2078 "cs.ATG" +#line 2085 "cs.ATG" ref outExpr); while (la.kind == 28) { lexer.NextToken(); UnaryExpr( -#line 2078 "cs.ATG" +#line 2085 "cs.ATG" out expr); ExclusiveOrExpr( -#line 2078 "cs.ATG" +#line 2085 "cs.ATG" ref expr); -#line 2078 "cs.ATG" +#line 2085 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); } } void ExclusiveOrExpr( -#line 2081 "cs.ATG" +#line 2088 "cs.ATG" ref Expression outExpr) { -#line 2082 "cs.ATG" +#line 2089 "cs.ATG" Expression expr; AndExpr( -#line 2084 "cs.ATG" +#line 2091 "cs.ATG" ref outExpr); while (la.kind == 29) { lexer.NextToken(); UnaryExpr( -#line 2084 "cs.ATG" +#line 2091 "cs.ATG" out expr); AndExpr( -#line 2084 "cs.ATG" +#line 2091 "cs.ATG" ref expr); -#line 2084 "cs.ATG" +#line 2091 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); } } void AndExpr( -#line 2087 "cs.ATG" +#line 2094 "cs.ATG" ref Expression outExpr) { -#line 2088 "cs.ATG" +#line 2095 "cs.ATG" Expression expr; EqualityExpr( -#line 2090 "cs.ATG" +#line 2097 "cs.ATG" ref outExpr); while (la.kind == 27) { lexer.NextToken(); UnaryExpr( -#line 2090 "cs.ATG" +#line 2097 "cs.ATG" out expr); EqualityExpr( -#line 2090 "cs.ATG" +#line 2097 "cs.ATG" ref expr); -#line 2090 "cs.ATG" +#line 2097 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); } } void EqualityExpr( -#line 2093 "cs.ATG" +#line 2100 "cs.ATG" ref Expression outExpr) { -#line 2095 "cs.ATG" +#line 2102 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; RelationalExpr( -#line 2099 "cs.ATG" +#line 2106 "cs.ATG" ref outExpr); while (la.kind == 32 || la.kind == 33) { if (la.kind == 33) { lexer.NextToken(); -#line 2102 "cs.ATG" +#line 2109 "cs.ATG" op = BinaryOperatorType.InEquality; } else { lexer.NextToken(); -#line 2103 "cs.ATG" +#line 2110 "cs.ATG" op = BinaryOperatorType.Equality; } UnaryExpr( -#line 2105 "cs.ATG" +#line 2112 "cs.ATG" out expr); RelationalExpr( -#line 2105 "cs.ATG" +#line 2112 "cs.ATG" ref expr); -#line 2105 "cs.ATG" +#line 2112 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void RelationalExpr( -#line 2109 "cs.ATG" +#line 2116 "cs.ATG" ref Expression outExpr) { -#line 2111 "cs.ATG" +#line 2118 "cs.ATG" TypeReference type; Expression expr; BinaryOperatorType op = BinaryOperatorType.None; ShiftExpr( -#line 2116 "cs.ATG" +#line 2123 "cs.ATG" ref outExpr); while (StartOf(26)) { if (StartOf(27)) { if (la.kind == 22) { lexer.NextToken(); -#line 2119 "cs.ATG" +#line 2126 "cs.ATG" op = BinaryOperatorType.LessThan; } else if (la.kind == 21) { lexer.NextToken(); -#line 2120 "cs.ATG" +#line 2127 "cs.ATG" op = BinaryOperatorType.GreaterThan; } else if (la.kind == 35) { lexer.NextToken(); -#line 2121 "cs.ATG" +#line 2128 "cs.ATG" op = BinaryOperatorType.LessThanOrEqual; } else if (la.kind == 34) { lexer.NextToken(); -#line 2122 "cs.ATG" +#line 2129 "cs.ATG" op = BinaryOperatorType.GreaterThanOrEqual; } else SynErr(182); UnaryExpr( -#line 2124 "cs.ATG" +#line 2131 "cs.ATG" out expr); ShiftExpr( -#line 2124 "cs.ATG" +#line 2131 "cs.ATG" ref expr); -#line 2124 "cs.ATG" +#line 2131 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } else { if (la.kind == 83) { lexer.NextToken(); -#line 2127 "cs.ATG" +#line 2134 "cs.ATG" op = BinaryOperatorType.IS; } else if (la.kind == 48) { lexer.NextToken(); -#line 2128 "cs.ATG" +#line 2135 "cs.ATG" op = BinaryOperatorType.AS; } else SynErr(183); Type( -#line 2130 "cs.ATG" +#line 2137 "cs.ATG" out type); -#line 2130 "cs.ATG" +#line 2137 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, new TypeReferenceExpression(type)); } } } void ShiftExpr( -#line 2134 "cs.ATG" +#line 2141 "cs.ATG" ref Expression outExpr) { -#line 2136 "cs.ATG" +#line 2143 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; AdditiveExpr( -#line 2140 "cs.ATG" +#line 2147 "cs.ATG" ref outExpr); while (la.kind == 36 || -#line 2143 "cs.ATG" +#line 2150 "cs.ATG" IsShiftRight()) { if (la.kind == 36) { lexer.NextToken(); -#line 2142 "cs.ATG" +#line 2149 "cs.ATG" op = BinaryOperatorType.ShiftLeft; } else { Expect(21); Expect(21); -#line 2144 "cs.ATG" +#line 2151 "cs.ATG" op = BinaryOperatorType.ShiftRight; } UnaryExpr( -#line 2147 "cs.ATG" +#line 2154 "cs.ATG" out expr); AdditiveExpr( -#line 2147 "cs.ATG" +#line 2154 "cs.ATG" ref expr); -#line 2147 "cs.ATG" +#line 2154 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void AdditiveExpr( -#line 2151 "cs.ATG" +#line 2158 "cs.ATG" ref Expression outExpr) { -#line 2153 "cs.ATG" +#line 2160 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; MultiplicativeExpr( -#line 2157 "cs.ATG" +#line 2164 "cs.ATG" ref outExpr); while (la.kind == 4 || la.kind == 5) { if (la.kind == 4) { lexer.NextToken(); -#line 2160 "cs.ATG" +#line 2167 "cs.ATG" op = BinaryOperatorType.Add; } else { lexer.NextToken(); -#line 2161 "cs.ATG" +#line 2168 "cs.ATG" op = BinaryOperatorType.Subtract; } UnaryExpr( -#line 2163 "cs.ATG" +#line 2170 "cs.ATG" out expr); MultiplicativeExpr( -#line 2163 "cs.ATG" +#line 2170 "cs.ATG" ref expr); -#line 2163 "cs.ATG" +#line 2170 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void MultiplicativeExpr( -#line 2167 "cs.ATG" +#line 2174 "cs.ATG" ref Expression outExpr) { -#line 2169 "cs.ATG" +#line 2176 "cs.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; @@ -5162,57 +5170,57 @@ ref Expression outExpr) { if (la.kind == 6) { lexer.NextToken(); -#line 2175 "cs.ATG" +#line 2182 "cs.ATG" op = BinaryOperatorType.Multiply; } else if (la.kind == 7) { lexer.NextToken(); -#line 2176 "cs.ATG" +#line 2183 "cs.ATG" op = BinaryOperatorType.Divide; } else { lexer.NextToken(); -#line 2177 "cs.ATG" +#line 2184 "cs.ATG" op = BinaryOperatorType.Modulus; } UnaryExpr( -#line 2179 "cs.ATG" +#line 2186 "cs.ATG" out expr); -#line 2179 "cs.ATG" +#line 2186 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } } void TypeParameterConstraintsClauseBase( -#line 2244 "cs.ATG" +#line 2251 "cs.ATG" out TypeReference type) { -#line 2245 "cs.ATG" +#line 2252 "cs.ATG" TypeReference t; type = null; if (la.kind == 107) { lexer.NextToken(); -#line 2247 "cs.ATG" +#line 2254 "cs.ATG" type = new TypeReference("struct"); } else if (la.kind == 57) { lexer.NextToken(); -#line 2248 "cs.ATG" +#line 2255 "cs.ATG" type = new TypeReference("struct"); } else if (la.kind == 87) { lexer.NextToken(); Expect(19); Expect(20); -#line 2249 "cs.ATG" +#line 2256 "cs.ATG" type = new TypeReference("struct"); } else if (StartOf(8)) { Type( -#line 2250 "cs.ATG" +#line 2257 "cs.ATG" out t); -#line 2250 "cs.ATG" +#line 2257 "cs.ATG" type = t; } else SynErr(184); } @@ -5495,4 +5503,4 @@ out t); }; } // end Parser -} \ No newline at end of file +} diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG index f6e37c634c..d106e21d04 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG @@ -1622,6 +1622,7 @@ Statement TypeReference type; Expression expr; Statement stmt; + Point startPos = la.Location; .) = /*--- labeled statement: */ @@ -1639,6 +1640,12 @@ Statement /* LL(1) confict: LocalVariableDecl * * <-> StatementExpr * * ident {"." ident} { "[" Expr ... */ + + (. if (stmt != null) { + stmt.StartLocation = startPos; + stmt.EndLocation = t.EndLocation; + } + .) . EmbeddedStatement diff --git a/src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs b/src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs index 67d5486a62..1d4d335b2b 100644 --- a/src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs +++ b/src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs @@ -1,4 +1,4 @@ -// +// // // // @@ -42,7 +42,12 @@ namespace ICSharpCode.SharpDevelop.Commands return; } ICSharpCode.NRefactory.PrettyPrinter.CSharpOutputVisitor vbv = new ICSharpCode.NRefactory.PrettyPrinter.CSharpOutputVisitor(); + SpecialNodesInserter sni = new SpecialNodesInserter(p.Lexer.SpecialTracker.CurrentSpecials, + new SpecialOutputVisitor(vbv.OutputFormatter)); + vbv.NodeTracker.NodeVisiting += sni.AcceptNodeStart; + vbv.NodeTracker.NodeVisited += sni.AcceptNodeEnd; vbv.Visit(p.CompilationUnit, null); + sni.Finish(); FileService.NewFile("Generated.CS", "C#", vbv.Text); diff --git a/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs b/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs index abf6d29575..f1ef5965f2 100644 --- a/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs +++ b/src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs @@ -1,4 +1,4 @@ -// +// // // // @@ -41,9 +41,15 @@ namespace ICSharpCode.SharpDevelop.Commands MessageService.ShowError("Correct source code errors first (only correct source code would convert)."); return; } + ICSharpCode.NRefactory.PrettyPrinter.VBNetOutputVisitor vbv = new ICSharpCode.NRefactory.PrettyPrinter.VBNetOutputVisitor(); - vbv.Visit(p.CompilationUnit, null); + SpecialNodesInserter sni = new SpecialNodesInserter(p.Lexer.SpecialTracker.CurrentSpecials, + new SpecialOutputVisitor(vbv.OutputFormatter)); + vbv.NodeTracker.NodeVisiting += sni.AcceptNodeStart; + vbv.NodeTracker.NodeVisited += sni.AcceptNodeEnd; + vbv.Visit(p.CompilationUnit, null); + sni.Finish(); FileService.NewFile("Generated.VB", "VBNET", vbv.Text); } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs index 5c499d57ff..09b8462010 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs @@ -88,13 +88,17 @@ namespace ICSharpCode.Core static void AddReferences(List list, IClass parentClass, IMember member, string fileName, string fileContent) { string lowerFileContent = fileContent.ToLower(); - if (lowerFileContent.IndexOf(parentClass.Name.ToLower()) < 0) return; + + // The name of the class does not necessarily exist in the file if the name of a + // derived class exists. + //if (lowerFileContent.IndexOf(parentClass.Name.ToLower()) < 0) return; + string lowerMemberName; if (member is IMethod && ((IMethod)member).IsConstructor) lowerMemberName = parentClass.Name.ToLower(); else lowerMemberName = member.Name.ToLower(); - //Console.WriteLine(fileName + " / " + lowerMemberName); + int pos = -1; IExpressionFinder expressionFinder = null; while ((pos = lowerFileContent.IndexOf(lowerMemberName, pos + 1)) >= 0) {