当前位置: 首页>>代码示例>>C#>>正文


C# ConversionVisitor类代码示例

本文整理汇总了C#中ConversionVisitor的典型用法代码示例。如果您正苦于以下问题:C# ConversionVisitor类的具体用法?C# ConversionVisitor怎么用?C# ConversionVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConversionVisitor类属于命名空间,在下文中一共展示了ConversionVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        public CompilationUnit Parse(Stream stream)
        {
            lock (CompilerCallableEntryPoint.parseLock) {
                CompilerCompilationUnit top = CompilerCallableEntryPoint.ParseFile (new string[] { "-v", "-unsafe"}, stream, "parsed.cs", Console.Out);

                if (top == null)
                    return null;
                CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
                top.UsingsBag.Global.Accept (conversionVisitor);
                InsertComments (top, conversionVisitor);
                return conversionVisitor.Unit;
            }
        }
开发者ID:HEskandari,项目名称:ILSpy,代码行数:13,代码来源:CSharpParser.cs

示例2: Parse

        /// <summary>
        /// Converts a Mono.CSharp syntax tree into an NRefactory syntax tree.
        /// </summary>
        public SyntaxTree Parse(CompilerCompilationUnit top, string fileName)
        {
            if (top == null) {
                return null;
            }
            CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (GenerateTypeSystemMode, top.LocationsBag);
            top.ModuleCompiled.Accept(conversionVisitor);
            InsertComments(top, conversionVisitor);
            if (CompilationUnitCallback != null) {
                CompilationUnitCallback(top);
            }
            if (top.LastYYValue is Mono.CSharp.Expression) {
                conversionVisitor.Unit.TopExpression = ((Mono.CSharp.Expression)top.LastYYValue).Accept(conversionVisitor) as AstNode;
            }

            conversionVisitor.Unit.FileName = fileName;
            conversionVisitor.Unit.ConditionalSymbols = top.Conditionals.Concat (compilerSettings.ConditionalSymbols).ToArray ();
            return conversionVisitor.Unit;
        }
开发者ID:kaagati,项目名称:NRefactory,代码行数:22,代码来源:CSharpParser.cs

示例3: Parse

		public CompilationUnit Parse (CompilerCompilationUnit top, string fileName, int lineModifier = 0)
		{
			if (top == null)
				return null;
			CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (GenerateTypeSystemMode, top.LocationsBag);
			top.UsingsBag.Global.Accept (conversionVisitor);
			conversionVisitor.AddAttributeSection (conversionVisitor.Unit, top.ModuleCompiled);
			InsertComments (top, conversionVisitor);
			if (CompilationUnitCallback != null)
				CompilationUnitCallback (top);
			if (lineModifier != 0)
				AdjustLineLocations (conversionVisitor.Unit, lineModifier);
			if (top.LastYYValue is Mono.CSharp.Expression)
				conversionVisitor.Unit.TopExpression = ((Mono.CSharp.Expression)top.LastYYValue).Accept (conversionVisitor) as AstNode;
			conversionVisitor.Unit.FileName = fileName;
			return conversionVisitor.Unit;
		}
开发者ID:N3X15,项目名称:ILSpy,代码行数:17,代码来源:CSharpParser.cs

示例4: InsertComments

		static void InsertComments (CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
		{
			var leaf = GetOuterLeft (conversionVisitor.Unit);
			for (int i = 0; i < top.SpecialsBag.Specials.Count; i++) {
				var special = top.SpecialsBag.Specials [i];
				AstNode newLeaf = null;
				var comment = special as SpecialsBag.Comment;
				if (comment != null) {
					if (conversionVisitor.convertTypeSystemMode && (comment.CommentType != SpecialsBag.CommentType.Documentation))
						continue;
					var type = (CommentType)comment.CommentType;
					var start = new TextLocation (comment.Line, comment.Col);
					var end = new TextLocation (comment.EndLine, comment.EndCol);
					newLeaf = new Comment (type, start, end) {
							StartsLine = comment.StartsLine,
							Content = comment.Content
					};
				} else {
					var directive = special as SpecialsBag.PreProcessorDirective;
					if (directive != null) {
						newLeaf = new PreProcessorDirective ((ICSharpCode.NRefactory.CSharp.PreProcessorDirectiveType)((int)directive.Cmd & 0xF), new TextLocation (directive.Line, directive.Col), new TextLocation (directive.EndLine, directive.EndCol)) {
							Argument = directive.Arg,
							Take = directive.Take
						};
					}
				}
				if (newLeaf == null)
					continue;
				
				while (true) {
					var nextLeaf = NextLeaf (leaf);
					// insert comment at begin
					if (newLeaf.StartLocation < leaf.StartLocation) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						while (node.Parent != null && node.FirstChild == leaf) {
							leaf = node;
							node = node.Parent;
						}
						if (newLeaf is Comment) {
							node.InsertChildBefore (leaf, (Comment)newLeaf, AstNode.Roles.Comment);
						} else {
							node.InsertChildBefore (leaf, (PreProcessorDirective)newLeaf, AstNode.Roles.PreProcessorDirective);
						}
						leaf = newLeaf;
						break;
					}
					
					// insert comment at the end
					if (nextLeaf == null) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						if (newLeaf is Comment) {
							node.AddChild ((Comment)newLeaf, AstNode.Roles.Comment);
						} else {
							node.AddChild ((PreProcessorDirective)newLeaf, AstNode.Roles.PreProcessorDirective);
						}
						leaf = newLeaf;
						break;
					}
					
					// comment is between 2 nodes
					if (leaf.EndLocation <= newLeaf.StartLocation && newLeaf.StartLocation <= nextLeaf.StartLocation) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						if (newLeaf is Comment) {
							node.InsertChildAfter (leaf, (Comment)newLeaf, AstNode.Roles.Comment);
						} else {
							node.InsertChildAfter (leaf, (PreProcessorDirective)newLeaf, AstNode.Roles.PreProcessorDirective);
						}
						leaf = newLeaf;
						break;
					}
					leaf = nextLeaf;
				}
			}
		}
开发者ID:N3X15,项目名称:ILSpy,代码行数:74,代码来源:CSharpParser.cs

示例5: InsertComments

 void InsertComments(CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
 {
     AstNode insertionPoint = conversionVisitor.Unit.FirstChild;
     for (int i = 0; i < top.SpecialsBag.Specials.Count; i++) {
         var special = top.SpecialsBag.Specials [i];
         AstNode newLeaf = null;
         Role role = null;
         bool isDocumentationComment = false;
         var comment = special as SpecialsBag.Comment;
         if (comment != null) {
             // HACK: multiline documentation comment detection; better move this logic into the mcs tokenizer
             bool isMultilineDocumentationComment = (
                 comment.CommentType == SpecialsBag.CommentType.Multi
                 && comment.Content.StartsWith("*", StringComparison.Ordinal)
                 && !comment.Content.StartsWith("**", StringComparison.Ordinal)
             );
             isDocumentationComment = comment.CommentType == SpecialsBag.CommentType.Documentation || isMultilineDocumentationComment;
             if (conversionVisitor.convertTypeSystemMode && !isDocumentationComment)
                 continue;
             var type = isMultilineDocumentationComment ? CommentType.MultiLineDocumentation : (CommentType)comment.CommentType;
             var start = new TextLocation (comment.Line, comment.Col);
             var end = new TextLocation (comment.EndLine, comment.EndCol);
             newLeaf = new Comment (type, start, end) {
                 StartsLine = comment.StartsLine,
                 Content = isMultilineDocumentationComment ? comment.Content.Substring(1) : comment.Content
             };
             role = Roles.Comment;
         } else if (!GenerateTypeSystemMode) {
             var pragmaDirective = special as SpecialsBag.PragmaPreProcessorDirective;
             if (pragmaDirective != null) {
                 var pragma = new PragmaWarningPreprocssorDirective(new TextLocation(pragmaDirective.Line, pragmaDirective.Col), new TextLocation(pragmaDirective.EndLine, pragmaDirective.EndCol));
                 pragma.Disable = pragmaDirective.Disalbe;
                 pragma.AddWarnings(pragmaDirective.Codes);
                 newLeaf = pragma;
                 role = Roles.PreProcessorDirective;
             } else {
                 var directive = special as SpecialsBag.PreProcessorDirective;
                 if (directive != null) {
                     newLeaf = new PreProcessorDirective ((ICSharpCode.NRefactory.CSharp.PreProcessorDirectiveType)((int)directive.Cmd & 0xF), new TextLocation (directive.Line, directive.Col), new TextLocation (directive.EndLine, directive.EndCol)) {
                         Argument = directive.Arg,
                         Take = directive.Take
                     };
                     role = Roles.PreProcessorDirective;
                 }
             }
         }
         if (newLeaf != null) {
             InsertComment(ref insertionPoint, newLeaf, role, isDocumentationComment, conversionVisitor.Unit);
         }
     }
     if (!GenerateTypeSystemMode) {
         // We cannot insert newlines in the same loop as comments/preprocessor directives
         // because they are not correctly ordered in the specials bag
         insertionPoint = conversionVisitor.Unit.FirstChild;
         for (int i = 0; i < top.SpecialsBag.Specials.Count; i++) {
             var newLine = top.SpecialsBag.Specials[i] as SpecialsBag.NewLineToken;
             if (newLine != null) {
                 AstNode newLeaf;
                 if (newLine.NewLine == SpecialsBag.NewLine.Unix) {
                     newLeaf = new UnixNewLine (new TextLocation (newLine.Line, newLine.Col + 1));
                 } else {
                     newLeaf = new WindowsNewLine (new TextLocation (newLine.Line, newLine.Col + 1));
                 }
                 InsertComment(ref insertionPoint, newLeaf, Roles.NewLine, false, conversionVisitor.Unit);
             }
         }
     }
 }
开发者ID:sawilde,项目名称:NRefactory,代码行数:68,代码来源:CSharpParser.cs

示例6: ParseSnippet

		/*
		/// <summary>
		/// Parses a file snippet; guessing what the code snippet represents (whole file, type members, block, type reference, expression).
		/// </summary>
		public AstNode ParseSnippet (string code)
		{
			// TODO: add support for parsing a part of a file
			throw new NotImplementedException ();
		}
		 */
		public DocumentationReference ParseDocumentationReference(string cref)
		{
			// see Mono.CSharp.DocumentationBuilder.HandleXrefCommon
			if (cref == null)
				throw new ArgumentNullException("cref");
			
			// Additional symbols for < and > are allowed for easier XML typing
			cref = cref.Replace('{', '<').Replace('}', '>');
			
			lock (parseLock) {
				errorReportPrinter = new ErrorReportPrinter("");
				var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
				ctx.Settings.TabSize = 1;
				var reader = new SeekableStreamReader(new StringTextSource(cref));
				var file = new SourceFile("", "", 0);
				Location.Initialize(new List<SourceFile>(new [] { file }));
				var module = new ModuleContainer(ctx);
				module.DocumentationBuilder = new DocumentationBuilder(module);
				var source_file = new CompilationSourceFile(module);
				var report = new Report(ctx, errorReportPrinter);
				var session = new ParserSession();
				session.LocationsBag = new LocationsBag();
				var parser = new Mono.CSharp.CSharpParser(reader, source_file, report, session);
				parser.Lexer.Line += initialLocation.Line - 1;
				parser.Lexer.Column += initialLocation.Column - 1;
				parser.Lexer.putback_char = Tokenizer.DocumentationXref;
				parser.Lexer.parsing_generic_declaration_doc = true;
				parser.parse();
				if (report.Errors > 0) {
//					Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
//					                mc.GetSignatureForError (), cref);
				}
				
				var conversionVisitor = new ConversionVisitor(false, session.LocationsBag);
				var docRef = conversionVisitor.ConvertXmlDoc(module.DocumentationBuilder);
				CompilerCallableEntryPoint.Reset();
				return docRef;
			}
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:49,代码来源:CSharpParser.cs

示例7: InsertComments

		void InsertComments(CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
		{
			AstNode insertionPoint = conversionVisitor.Unit.FirstChild;
			foreach (var special in top.SpecialsBag.Specials) {
				AstNode newLeaf = null;
				Role role = null;
				bool isDocumentationComment = false;
				var comment = special as SpecialsBag.Comment;
				if (comment != null) {
					// HACK: multiline documentation comment detection; better move this logic into the mcs tokenizer
					bool isMultilineDocumentationComment = (comment.CommentType == SpecialsBag.CommentType.Multi && comment.Content.StartsWith("*", StringComparison.Ordinal) && !comment.Content.StartsWith("**", StringComparison.Ordinal));
					isDocumentationComment = comment.CommentType == SpecialsBag.CommentType.Documentation || isMultilineDocumentationComment;
					if (conversionVisitor.convertTypeSystemMode && !isDocumentationComment)
						continue;
					var type = isMultilineDocumentationComment ? CommentType.MultiLineDocumentation : (CommentType)comment.CommentType;
					var start = new TextLocation(comment.Line, comment.Col);
					var end = new TextLocation(comment.EndLine, comment.EndCol);
					newLeaf = new Comment(type, start, end) {
						StartsLine = comment.StartsLine,
						Content = isMultilineDocumentationComment ? comment.Content.Substring(1) : comment.Content
					};
					role = Roles.Comment;
				} else if (!GenerateTypeSystemMode) {
					var pragmaDirective = special as SpecialsBag.PragmaPreProcessorDirective;
					if (pragmaDirective != null) {
						var pragma = new PragmaWarningPreprocessorDirective(new TextLocation(pragmaDirective.Line, pragmaDirective.Col), new TextLocation(pragmaDirective.EndLine, pragmaDirective.EndCol));
						pragma.AddChild(new CSharpTokenNode(new TextLocation(pragmaDirective.Line, pragmaDirective.Col), PragmaWarningPreprocessorDirective.PragmaKeywordRole), PragmaWarningPreprocessorDirective.PragmaKeywordRole);
						pragma.AddChild(new CSharpTokenNode(new TextLocation(pragmaDirective.Line, pragmaDirective.WarningColumn), PragmaWarningPreprocessorDirective.WarningKeywordRole), PragmaWarningPreprocessorDirective.WarningKeywordRole);
						var pragmaRole = pragmaDirective.Disalbe ? PragmaWarningPreprocessorDirective.DisableKeywordRole : PragmaWarningPreprocessorDirective.RestoreKeywordRole;
						pragma.AddChild(new CSharpTokenNode(new TextLocation(pragmaDirective.Line, pragmaDirective.DisableRestoreColumn), pragmaRole), pragmaRole);
						foreach (var code in pragmaDirective.Codes) {
							pragma.AddChild((PrimitiveExpression)conversionVisitor.Visit(code), PragmaWarningPreprocessorDirective.WarningRole);
						}
						newLeaf = pragma;
						role = Roles.PreProcessorDirective;
						goto end;
					}
					var lineDirective = special as SpecialsBag.LineProcessorDirective;
					if (lineDirective != null) {
						var pragma = new LinePreprocessorDirective(new TextLocation(lineDirective.Line, lineDirective.Col), new TextLocation(lineDirective.EndLine, lineDirective.EndCol));
						pragma.LineNumber = lineDirective.LineNumber;
						pragma.FileName = lineDirective.FileName;
						newLeaf = pragma;
						role = Roles.PreProcessorDirective;
						goto end;
					}
					var directive = special as SpecialsBag.PreProcessorDirective;
					if (directive != null) {
						newLeaf = new PreProcessorDirective((PreProcessorDirectiveType)((int)directive.Cmd & 0xF), new TextLocation(directive.Line, directive.Col), new TextLocation(directive.EndLine, directive.EndCol)) {
							Argument = directive.Arg,
							Take = directive.Take
						};
						role = Roles.PreProcessorDirective;
					}
					end:
					;
				}
				if (newLeaf != null) {
					InsertComment(ref insertionPoint, newLeaf, role, isDocumentationComment, conversionVisitor.Unit);
				}
			}
			if (!GenerateTypeSystemMode) {
				// We cannot insert newlines in the same loop as comments/preprocessor directives
				// because they are not correctly ordered in the specials bag
				insertionPoint = conversionVisitor.Unit.FirstChild;
				for (int i = 0; i < top.SpecialsBag.Specials.Count; i++) {
					var newLine = top.SpecialsBag.Specials [i] as SpecialsBag.NewLineToken;
					if (newLine != null) {
						var newLeaf = new NewLineNode(new TextLocation(newLine.Line, newLine.Col + 1));
						newLeaf.NewLineType = newLine.NewLine == SpecialsBag.NewLine.Unix ? UnicodeNewline.LF : UnicodeNewline.CRLF;
						InsertComment(ref insertionPoint, newLeaf, Roles.NewLine, false, conversionVisitor.Unit);
					}
				}
			}
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:75,代码来源:CSharpParser.cs

示例8: Parse

		internal static MonoDevelop.CSharp.Ast.CompilationUnit Parse (CompilerCompilationUnit top)
		{
			if (top == null)
				return null;
			CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
			top.UsingsBag.Global.Accept (conversionVisitor);
			
			foreach (var special in top.SpecialsBag.Specials) {
				var comment = special as SpecialsBag.Comment;
				
				if (comment != null) {
					var type  = (MonoDevelop.CSharp.Ast.CommentType)comment.CommentType;
					var start =  new DomLocation (comment.Line, comment.Col);
					var end =  new DomLocation (comment.EndLine, comment.EndCol);
					var domComment = new MonoDevelop.CSharp.Ast.Comment (type, start, end);
					domComment.StartsLine = comment.StartsLine;
					domComment.Content = comment.Content;
					InsertComment (conversionVisitor.Unit, domComment);
				}
			}
			
			return conversionVisitor.Unit;
		}
开发者ID:tech-uday-mca,项目名称:monodevelop,代码行数:23,代码来源:CSharpParser.cs

示例9: Parse

		public MonoDevelop.CSharp.Dom.CompilationUnit Parse (TextEditorData data)
		{
			lock (CompilerCallableEntryPoint.parseLock) {
				CompilerCompilationUnit top;
				using (Stream stream = data.OpenStream ()) {
					top = CompilerCallableEntryPoint.ParseFile (new string[] { "-v", "-unsafe"}, stream, data.Document.FileName ?? "empty.cs", Console.Out);
				}
	
				if (top == null)
					return null;
				CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
				top.UsingsBag.Global.Accept (conversionVisitor);
				
				foreach (var special in top.SpecialsBag.Specials) {
					var comment = special as SpecialsBag.Comment;
					
					if (comment != null) {
						var type  = (MonoDevelop.CSharp.Dom.CommentType)comment.CommentType;
						var start =  new DomLocation (comment.Line, comment.Col);
						var end =  new DomLocation (comment.EndLine, comment.EndCol);
						var domComment = new MonoDevelop.CSharp.Dom.Comment (type, start, end);
						domComment.StartsLine = comment.StartsLine;
						domComment.Content = comment.Content;
						InsertComment (conversionVisitor.Unit, domComment);
					}
				}
				
				return conversionVisitor.Unit;
			}
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:30,代码来源:CSharpParser.cs

示例10: InsertComments

		void InsertComments (CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
		{
			foreach (var special in top.SpecialsBag.Specials) {
				var comment = special as SpecialsBag.Comment;
				
				if (comment != null) {
					var type  = (CommentType)comment.CommentType;
					var start =  new AstLocation (comment.Line, comment.Col);
					var end =  new AstLocation (comment.EndLine, comment.EndCol);
					var domComment = new Comment (type, start, end);
					domComment.StartsLine = comment.StartsLine;
					domComment.Content = comment.Content;
					InsertComment (conversionVisitor.Unit, domComment);
				}
			}
		}
开发者ID:madkat,项目名称:NRefactory,代码行数:16,代码来源:CSharpParser.cs

示例11: Parse

		internal static CompilationUnit Parse (CompilerCompilationUnit top)
		{
			if (top == null)
				return null;
			CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
			top.UsingsBag.Global.Accept (conversionVisitor);
			InsertComments (top, conversionVisitor);
			return conversionVisitor.Unit;
		}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:9,代码来源:CSharpParser.cs

示例12: Parse

		public CompilationUnit Parse (CompilerCompilationUnit top, int line)
		{
			if (top == null)
				return null;
			CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
			conversionVisitor.AddAttributeSection (conversionVisitor.Unit, top.ModuleCompiled);
			top.UsingsBag.Global.Accept (conversionVisitor);
			InsertComments (top, conversionVisitor);
			if (line != 0)
				AdjustLineLocations (conversionVisitor.Unit, line);
			return conversionVisitor.Unit;
		}
开发者ID:hduregger,项目名称:monodevelop,代码行数:12,代码来源:CSharpParser.cs

示例13: InsertComments

        static void InsertComments(CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
        {
            var leaf = GetOuterLeft (conversionVisitor.Unit);
            for (int i = 0; i < top.SpecialsBag.Specials.Count; i++) {
                var special = top.SpecialsBag.Specials [i];
                AstNode newLeaf = null;
                var comment = special as SpecialsBag.Comment;
                if (comment != null) {
                    // HACK: multiline documentation comment detection; better move this logic into the mcs tokenizer
                    bool isMultilineDocumentationComment = (
                        comment.CommentType == SpecialsBag.CommentType.Multi
                        && comment.Content.StartsWith("*", StringComparison.Ordinal)
                        && !comment.Content.StartsWith("**", StringComparison.Ordinal)
                    );
                    if (conversionVisitor.convertTypeSystemMode && !(comment.CommentType == SpecialsBag.CommentType.Documentation || isMultilineDocumentationComment))
                        continue;
                    var type = isMultilineDocumentationComment ? CommentType.MultiLineDocumentation : (CommentType)comment.CommentType;
                    var start = new TextLocation (comment.Line, comment.Col);
                    var end = new TextLocation (comment.EndLine, comment.EndCol);
                    newLeaf = new Comment (type, start, end) {
                        StartsLine = comment.StartsLine,
                        Content = isMultilineDocumentationComment ? comment.Content.Substring(1) : comment.Content
                    };
                } else {
                    var directive = special as SpecialsBag.PreProcessorDirective;
                    if (directive != null) {
                        newLeaf = new PreProcessorDirective ((ICSharpCode.NRefactory.CSharp.PreProcessorDirectiveType)((int)directive.Cmd & 0xF), new TextLocation (directive.Line, directive.Col), new TextLocation (directive.EndLine, directive.EndCol)) {
                            Argument = directive.Arg,
                            Take = directive.Take
                        };
                    } else {
            /*					var newLine = special as SpecialsBag.NewLineToken;
                        if (newLine != null) {
                            if (newLine.NewLine == SpecialsBag.NewLine.Unix) {
                                newLeaf = new UnixNewLine (new TextLocation (newLine.Line, newLine.Col));
                            } else {
                                newLeaf = new WindowsNewLine (new TextLocation (newLine.Line, newLine.Col));
                            }
                        }*/
                    }
                }
                if (newLeaf == null)
                    continue;

                while (true) {
                    var nextLeaf = NextLeaf (leaf);
                    // insert comment at begin
                    if (newLeaf.StartLocation < leaf.StartLocation) {
                        var node = leaf.Parent ?? conversionVisitor.Unit;
                        while (node.Parent != null && node.FirstChild == leaf) {
                            leaf = node;
                            node = node.Parent;
                        }
                        if (newLeaf is NewLineNode) {
                            node.InsertChildBefore (leaf, (NewLineNode)newLeaf, Roles.NewLine);
                        } else if (newLeaf is Comment) {
                            node.InsertChildBefore (leaf, (Comment)newLeaf, Roles.Comment);
                        } else {
                            node.InsertChildBefore (leaf, (PreProcessorDirective)newLeaf, Roles.PreProcessorDirective);
                        }
                        leaf = newLeaf;
                        break;
                    }

                    // insert comment at the end
                    if (nextLeaf == null) {
                        var node = leaf.Parent ?? conversionVisitor.Unit;
                        if (newLeaf is NewLineNode) {
                            node.AddChild ((NewLineNode)newLeaf, Roles.NewLine);
                        } else if (newLeaf is Comment) {
                            node.AddChild ((Comment)newLeaf, Roles.Comment);
                        } else {
                            node.AddChild ((PreProcessorDirective)newLeaf, Roles.PreProcessorDirective);
                        }
                        leaf = newLeaf;
                        break;
                    }

                    // comment is between 2 nodes
                    if (leaf.EndLocation <= newLeaf.StartLocation && newLeaf.StartLocation <= nextLeaf.StartLocation) {
                        var node = leaf.Parent ?? conversionVisitor.Unit;
                        if (newLeaf is NewLineNode) {
                            node.InsertChildAfter (leaf, (NewLineNode)newLeaf, Roles.NewLine);
                        } else if (newLeaf is Comment) {
                            node.InsertChildAfter (leaf, (Comment)newLeaf, Roles.Comment);
                        } else {
                            node.InsertChildAfter (leaf, (PreProcessorDirective)newLeaf, Roles.PreProcessorDirective);
                        }
                        leaf = newLeaf;
                        break;
                    }
                    leaf = nextLeaf;
                }
            }
        }
开发者ID:kaagati,项目名称:NRefactory,代码行数:95,代码来源:CSharpParser.cs

示例14: InsertComments

		static void InsertComments (CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
		{
			var leaf = GetOuterLeft(conversionVisitor.Unit);
			
			foreach (var special in top.SpecialsBag.Specials) {
				var comment = special as SpecialsBag.Comment;
				if (comment == null)
					continue;
				if (conversionVisitor.convertTypeSystemMode && (comment.CommentType != SpecialsBag.CommentType.Documentation))
					continue;
				var type = (CommentType)comment.CommentType;
				var start = new AstLocation (comment.Line, comment.Col);
				var end = new AstLocation (comment.EndLine, comment.EndCol);
				var domComment = new Comment (type, start, end);
				domComment.StartsLine = comment.StartsLine;
				domComment.Content = comment.Content;
				
				while (true) {
					var nextLeaf = NextLeaf(leaf);
					// instert comment at the end
					if (nextLeaf == null) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						node.AddChild(domComment, AstNode.Roles.Comment);
						leaf = domComment;
						break;
					}
					
					// comment is between 2 nodes
					if (leaf.EndLocation <= domComment.StartLocation && domComment.StartLocation <= nextLeaf.StartLocation) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						node.InsertChildAfter(leaf, domComment, AstNode.Roles.Comment);
						leaf = domComment;
						break;
					}
					leaf = nextLeaf;
				}
			}
		}
开发者ID:aleksandersumowski,项目名称:monodevelop,代码行数:38,代码来源:CSharpParser.cs

示例15: Parse

		public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			var result = new ParsedDocument (fileName);
			var unit = new MonoDevelop.Projects.Dom.CompilationUnit (fileName);
			result.CompilationUnit = unit;
				
			if (string.IsNullOrEmpty (content))
				return result;
			
			lock (CompilerCallableEntryPoint.parseLock) {
				var tagComments = ProjectDomService.SpecialCommentTags.GetNames ();
				List<string > compilerArguments = new List<string> ();
				if (dom != null && dom.Project != null && MonoDevelop.Ide.IdeApp.Workspace != null) {
					DotNetProjectConfiguration configuration = dom.Project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration;
					CSharpCompilerParameters par = configuration != null ? configuration.CompilationParameters as CSharpCompilerParameters : null;
					if (par != null) {
						if (!string.IsNullOrEmpty (par.DefineSymbols)) {
							compilerArguments.Add ("-define:" + string.Join (";", par.DefineSymbols.Split (';', ',', ' ', '\t').Where (s => !string.IsNullOrWhiteSpace (s))));
						}
						if (par.UnsafeCode)
							compilerArguments.Add ("-unsafe");
						if (par.TreatWarningsAsErrors)
							compilerArguments.Add ("-warnaserror");
						if (!string.IsNullOrEmpty (par.NoWarnings))
							compilerArguments.Add ("-nowarn:" + string.Join (",", par.NoWarnings.Split (';', ',', ' ', '\t')));
						compilerArguments.Add ("-warn:" + par.WarningLevel);
						compilerArguments.Add ("-langversion:" + GetLangString (par.LangVersion));
						if (par.GenerateOverflowChecks)
							compilerArguments.Add ("-checked");
					}
				}
				
				
				CompilerCompilationUnit top;
				ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter ();
				using (var stream = new MemoryStream (Encoding.UTF8.GetBytes (content))) {
					top = CompilerCallableEntryPoint.ParseFile (compilerArguments.ToArray (), stream, fileName, errorReportPrinter);
				}
				if (top == null)
					return null;
				foreach (var special in top.SpecialsBag.Specials) {
					var comment = special as SpecialsBag.Comment;
					if (comment != null) {
						VisitComment (result, comment, tagComments);
					} else {
						VisitPreprocessorDirective (result, special as SpecialsBag.PreProcessorDirective);
					}
				}
				// convert DOM
				var conversionVisitor = new ConversionVisitor (top.LocationsBag);
				try {
					conversionVisitor.Dom = dom;
					conversionVisitor.ParsedDocument = result;
					conversionVisitor.Unit = unit;
					top.UsingsBag.Global.Accept (conversionVisitor);
					top.ModuleCompiled.Accept (conversionVisitor);
				} catch (Exception ex) {
					System.Console.WriteLine (ex);
				}
				result.LanguageAST = new ICSharpCode.NRefactory.CSharp.CSharpParser().Parse (top, 0);
				// parser errorse
				errorReportPrinter.Errors.ForEach (e => conversionVisitor.ParsedDocument.Add (e));
				return result;
			}
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:65,代码来源:McsParser.cs


注:本文中的ConversionVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。