public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			using (ICSharpCode.NRefactory.IParser parser = ICSharpCode.NRefactory.ParserFactory.CreateParser (ICSharpCode.NRefactory.SupportedLanguage.CSharp, new StringReader (content))) {

				ParsedDocument result = new ParsedDocument (fileName);
				result.CompilationUnit = new MonoDevelop.Projects.Dom.CompilationUnit (fileName);
				
				parser.Errors.Error += delegate(int line, int col, string message) { result.Add (new Error (ErrorType.Error, line, col, message)); };
				parser.Lexer.SpecialCommentTags = LexerTags;
				parser.Lexer.EvaluateConditionalCompilation = true;
				if (dom != null && dom.Project != null) {
					DotNetProjectConfiguration conf = dom.Project.DefaultConfiguration as DotNetProjectConfiguration;
					CSharpCompilerParameters par = conf != null ? conf.CompilationParameters as CSharpCompilerParameters : null;
					if (par != null)
						parser.Lexer.SetConditionalCompilationSymbols (par.DefineSymbols);
				}
				parser.Parse ();
				
				SpecialTracker tracker = new SpecialTracker (result);
				foreach (ICSharpCode.NRefactory.ISpecial special in parser.Lexer.SpecialTracker.CurrentSpecials) {
					special.AcceptVisitor (tracker, null);
				}

				foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in parser.Lexer.TagComments) {
					result.Add (new Tag (tagComment.Tag, tagComment.CommentText, new DomRegion (tagComment.StartPosition.Y, tagComment.StartPosition.X, tagComment.EndPosition.Y, tagComment.EndPosition.X)));
				}
				ConversionVisitior visitor = new ConversionVisitior (result, parser.Lexer.SpecialTracker.CurrentSpecials);
				visitor.VisitCompilationUnit (parser.CompilationUnit, null);
				result.CompilationUnit.Tag = parser.CompilationUnit;
				LastUnit = parser.CompilationUnit;
				return result;
			}
		}
Esempio n. 2
0
		void RetrieveRegions(CompilationUnit cu, SpecialTracker tracker)
		{
			for (int i = 0; i < tracker.CurrentSpecials.Count; ++i) {
				PreProcessingDirective directive = tracker.CurrentSpecials[i] as PreProcessingDirective;
				if (directive != null) {
					if (directive.Cmd == "#region") {
						int deep = 1; 
						for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j) {
							PreProcessingDirective nextDirective = tracker.CurrentSpecials[j] as PreProcessingDirective;
							if (nextDirective != null) {
								switch (nextDirective.Cmd) {
									case "#region":
										++deep;
										break;
									case "#endregion":
										--deep;
										if (deep == 0) {
											cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DefaultRegion(directive.Start, new Point(nextDirective.End.X - 2, nextDirective.End.Y))));
											goto end;
										}
										break;
								}
							}
						}
						end: ;
					}
				}
			}
		}
        private static void RetrieveRegions(ICompilationUnit cu, SpecialTracker tracker)
        {
            for (int i = 0; i < tracker.CurrentSpecials.Count; ++i)
            {
                var directive = tracker.CurrentSpecials[i] as PreprocessingDirective;
                if (directive != null)
                {
                    if (directive.Cmd == "#region")
                    {
                        int deep = 1;
                        for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j)
                        {
                            var nextDirective = tracker.CurrentSpecials[j] as PreprocessingDirective;
                            if (nextDirective != null)
                            {
                                switch (nextDirective.Cmd)
                                {
                                case "#region":
                                    ++deep;
                                    break;

                                case "#endregion":
                                    --deep;
                                    if (deep == 0)
                                    {
                                        cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(),
                                                                                DomRegion.FromLocation(
                                                                                    directive.StartPosition,
                                                                                    nextDirective.EndPosition)));
                                        goto end;
                                    }
                                    break;
                                }
                            }
                        }
end:
                        ;
                    }
                }
            }
        }
Esempio n. 4
0
        void RetrieveRegions(CompilationUnit cu, SpecialTracker tracker)
        {
            for (int i = 0; i < tracker.CurrentSpecials.Count; ++i)
            {
                PreProcessingDirective directive = tracker.CurrentSpecials[i] as PreProcessingDirective;
                if (directive != null)
                {
                    if (directive.Cmd == "#region")
                    {
                        int deep = 1;
                        for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j)
                        {
                            PreProcessingDirective nextDirective = tracker.CurrentSpecials[j] as PreProcessingDirective;
                            if (nextDirective != null)
                            {
                                switch (nextDirective.Cmd)
                                {
                                case "#region":
                                    ++deep;
                                    break;

                                case "#endregion":
                                    --deep;
                                    if (deep == 0)
                                    {
                                        cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DefaultRegion(directive.Start, new Point(nextDirective.End.X - 2, nextDirective.End.Y))));
                                        goto end;
                                    }
                                    break;
                                }
                            }
                        }
                        end :;
                    }
                }
            }
        }
Esempio n. 5
0
		public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
		{
			using (ICSharpCode.NRefactory.IParser parser = ICSharpCode.NRefactory.ParserFactory.CreateParser (ICSharpCode.NRefactory.SupportedLanguage.CSharp, new StringReader (content))) {
				ParsedDocument result = new ParsedDocument (fileName);
				result.CompilationUnit = new MonoDevelop.Projects.Dom.CompilationUnit (fileName);
				
				parser.ParseMethodBodies = false;
				parser.Errors.Error += delegate(int line, int col, string message) { result.Add (new Error (ErrorType.Error, line, col, message)); };
				parser.Lexer.SpecialCommentTags = ProjectDomService.SpecialCommentTags.GetNames ();
				parser.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)
						parser.Lexer.SetConditionalCompilationSymbols (par.DefineSymbols);
				}
				parser.Parse ();
				
				SpecialTracker tracker = new SpecialTracker (result);
				foreach (ICSharpCode.NRefactory.ISpecial special in parser.Lexer.SpecialTracker.CurrentSpecials) {
					special.AcceptVisitor (tracker, null);
				}

				foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in parser.Lexer.TagComments) {
					result.Add (new Tag (tagComment.Tag, tagComment.CommentText, new DomRegion (tagComment.StartPosition.Y, tagComment.StartPosition.X, tagComment.EndPosition.Y, tagComment.EndPosition.X)));
				}
				ConversionVisitior visitor = new ConversionVisitior (dom, result, parser.Lexer.SpecialTracker.CurrentSpecials);
				visitor.VisitCompilationUnit (parser.CompilationUnit, null);
				result.CompilationUnit.Tag = parser.CompilationUnit;
				LastUnit = parser.CompilationUnit;
				return result;
			}
		}
Esempio n. 6
0
		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)) {
							compilerArguments.Add ("-define:" + string.Join (";", par.DefineSymbols.Split (';', ',', ' ', '\t')));
						}
						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");
					}
				}
	//			compilerArguments.ForEach (arg => Console.WriteLine (arg));
				while (lexer.NextToken ().Kind != ICSharpCode.NRefactory.Parser.CSharp.Tokens.EOF)
					;
				
				CompilerCompilationUnit top;
				ErrorReportPrinter errorReportPrinter = new ErrorReportPrinter ();
				using (var stream = new MemoryStream (Encoding.Default.GetBytes (content))) {
					top = CompilerCallableEntryPoint.ParseFile (compilerArguments.ToArray (), stream, fileName, errorReportPrinter);
				}
				if (top == null)
					return null;
				
				SpecialTracker tracker = new SpecialTracker (result);
				foreach (ICSharpCode.NRefactory.ISpecial special in lexer.SpecialTracker.CurrentSpecials) {
					special.AcceptVisitor (tracker, null);
				}	
				
				
				// convert DOM
				var conversionVisitor = new ConversionVisitor (top.LocationsBag, lexer.SpecialTracker.CurrentSpecials);
				conversionVisitor.Dom = dom;
				conversionVisitor.Unit = unit;
				conversionVisitor.ParsedDocument = result;
				top.UsingsBag.Global.Accept (conversionVisitor);
				
				unit.Tag = top;
				
				// parser errors
				errorReportPrinter.Errors.ForEach (e => conversionVisitor.ParsedDocument.Add (e));
				return result;
			}
		}