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


C# CSharp.CompilerCompilationUnit类代码示例

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


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

示例1: 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

示例2: 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

示例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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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


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