• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ConversionVisitor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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];
				Comment 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 AstLocation (comment.Line, comment.Col);
					var end = new AstLocation (comment.EndLine, comment.EndCol);
					newLeaf = new Comment (type, start, end) {
							StartsLine = comment.StartsLine,
							Content = comment.Content
					};
				} else {
					// TODO: Proper handling of pre processor directives (atm got treated as comments Ast wise)
					var directive = special as SpecialsBag.PreProcessorDirective;
					if (directive != null) {
						newLeaf = new Comment (CommentType.SingleLine, new AstLocation (directive.Line, directive.Col), new AstLocation (directive.EndLine, directive.EndCol + 1));
						
						if (!directive.Take) {
							SpecialsBag.PreProcessorDirective endif = null;
							int endifLevel = 0;
							for (int j = i + 1; j < top.SpecialsBag.Specials.Count; j++) {
								var s = top.SpecialsBag.Specials [j] as SpecialsBag.PreProcessorDirective;
								if (s == null)
									continue;
								if (s.Cmd == Tokenizer.PreprocessorDirective.If) {
									endifLevel++;
									continue;
								}
								if (s.Cmd == Tokenizer.PreprocessorDirective.Endif || endifLevel == 0 && s.Cmd == Tokenizer.PreprocessorDirective.Else) {
									if (endifLevel == 0) {
										endif = s;
										i = j;
										break;
									}
									endifLevel--;
								}
							}
							if (endif != null)
								newLeaf = new Comment (CommentType.SingleLine, new AstLocation (directive.Line, directive.Col), new AstLocation (endif.EndLine, endif.EndCol));
						}
					}
				}
				
				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;
						}
						node.InsertChildBefore (leaf, newLeaf, AstNode.Roles.Comment);
						leaf = newLeaf;
						break;
					}
					
					// insert comment at the end
					if (nextLeaf == null) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						node.AddChild (newLeaf, AstNode.Roles.Comment);
						leaf = newLeaf;
						break;
					}
					
					// comment is between 2 nodes
					if (leaf.EndLocation <= newLeaf.StartLocation && newLeaf.StartLocation <= nextLeaf.StartLocation) {
						var node = leaf.Parent ?? conversionVisitor.Unit;
						node.InsertChildAfter (leaf, newLeaf, AstNode.Roles.Comment);
						leaf = newLeaf;
						break;
					}
					leaf = nextLeaf;
				}
			}
		}
开发者ID:severinh,项目名称:monodevelop-vala-afrodite-update,代码行数:87,代码来源:CSharpParser.cs


示例17: 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);
			}
			var expr = top.LastYYValue as Mono.CSharp.Expression;
			if (expr != null)
				conversionVisitor.Unit.TopExpression = expr.Accept(conversionVisitor) as AstNode;

			conversionVisitor.Unit.FileName = fileName;
			var conditionals = new List<string>();
			foreach (var settings in compilerSettings.ConditionalSymbols) {
				if (top.Conditionals.ContainsKey(settings) && !top.Conditionals [settings])
					continue;
				conditionals.Add(settings);
			}
			foreach (var kv in top.Conditionals) {
				if (!kv.Value || compilerSettings.ConditionalSymbols.Contains(kv.Key))
					continue;
				conditionals.Add(kv.Key);
			}
			conversionVisitor.Unit.ConditionalSymbols = conditionals;
			return conversionVisitor.Unit;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:33,代码来源:CSharpParser.cs


示例18: 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.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;
			return conversionVisitor.Unit;
		}
开发者ID:head-thrash,项目名称:monodevelop,代码行数:17,代码来源:CSharpParser.cs


示例19: 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, Console.Out);
				}
	
				if (top == null)
					return null;
				CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
				top.UsingsBag.Global.Accept (conversionVisitor);
				return conversionVisitor.Unit;
			}
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:15,代码来源:CSharpParser.cs


示例20: Parse

		public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			lock (CompilerCallableEntryPoint.parseLock) {
				if (string.IsNullOrEmpty (content))
					return null;
				
				List<string> compilerArguments = new List<string> ();
				
				var unit =  new MonoDevelop.Projects.Dom.CompilationUnit (fileName);;
				var result = new ParsedDocument (fileName);
				result.CompilationUnit = unit;
				
				ICSharpCode.NRefactory.Parser.CSharp.Lexer lexer = new ICSharpCode.NRefactory.Parser.CSharp.Lexer (new StringReader (content));
				lexer.SpecialCommentTags = ProjectDomService.SpecialCommentTags.GetNames ();
				lexer.EvaluateConditionalCompilation = true;
				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) {
						lexer.SetConditionalCompilationSymbols (par.DefineSymbols);
						if (!string.IsNullOrEmpty (par.DefineSymbols)) {
							compilerArg 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ConversionsBase类代码示例发布时间:2022-05-24
下一篇:
C# ConversionStorage类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap