Пример #1
0
        void IRelocatable.SetStartLocation(AstLocation startLocation)
        {
            int lineDelta = startLocation.Line - this.startLocation.Line;

            endLocation        = new AstLocation(endLocation.Line + lineDelta, lineDelta != 0 ? endLocation.Column : endLocation.Column + startLocation.Column - this.startLocation.Column);
            this.startLocation = startLocation;
        }
		public DebuggerTooltipControl(AstLocation logicalPosition)
		{
			this.logicalPosition = logicalPosition;
			InitializeComponent();
			
			Loaded += new RoutedEventHandler(OnLoaded);
		}
        public DebuggerTooltipControl(AstLocation logicalPosition)
        {
            this.logicalPosition = logicalPosition;
            InitializeComponent();

            Loaded += new RoutedEventHandler(OnLoaded);
        }
Пример #4
0
 public BreakpointBookmark(MemberReference member, AstLocation location, ILRange range, BreakpointAction action, DecompiledLanguages language) : base(member, location)
 {
     this.action   = action;
     this.ILRange  = range;
     this.Tooltip  = string.Format("Language:{0}, Line:{1}, IL range:{2}-{3}", language.ToString(), location.Line, range.From, range.To);
     this.Language = language;
 }
Пример #5
0
		public BreakpointBookmark(MemberReference member, AstLocation location, ILRange range, BreakpointAction action, DecompiledLanguages language) : base(member, location)
		{
			this.action = action;
			this.ILRange = range;
			this.Tooltip = string.Format("Language:{0}, Line:{1}, IL range:{2}-{3}", language.ToString(), location.Line, range.From, range.To);
			this.Language = language;			
		}
Пример #6
0
 public PrimitiveExpression(object value, string stringValue, AstLocation startLocation, int length)
 {
     this.Value         = value;
     this.stringValue   = stringValue;
     this.startLocation = startLocation;
     this.length        = length;
 }
Пример #7
0
        public void VisitLocation(AstLocation location)
        {
            Assert.IsType <AstLocation>(this.expected);
            var expectedAst = (AstLocation)this.expected;

            Assert.Equal(expectedAst.Value, location.Value);
        }
Пример #8
0
        public IEnumerable <AstNode> GetNodesBetween(AstLocation start, AstLocation end)
        {
            AstNode node = this;

            while (node != null)
            {
                AstNode next;
                if (start <= node.StartLocation && node.EndLocation <= end)
                {
                    // Remember next before yielding node.
                    // This allows iteration to continue when the caller removes/replaces the node.
                    next = node.NextSibling;
                    yield return(node);
                }
                else
                {
                    if (node.EndLocation < start)
                    {
                        next = node.NextSibling;
                    }
                    else
                    {
                        next = node.FirstChild;
                    }
                }

                if (next != null && next.StartLocation > end)
                {
                    yield break;
                }
                node = next;
            }
        }
Пример #9
0
 public Token(int kind, int col, int line, string val)
 {
     this.kind        = kind;
     this.col         = col;
     this.line        = line;
     this.val         = val;
     this.endLocation = new AstLocation(line, col + (val == null ? 1 : val.Length));
 }
Пример #10
0
		public Token(int kind, int col, int line, string val)
		{
			this.kind         = kind;
			this.col          = col;
			this.line         = line;
			this.val          = val;
			this.endLocation  = new AstLocation(line, col + (val == null ? 1 : val.Length));
		}
Пример #11
0
 public DomRegion(string fileName, AstLocation begin)
 {
     this.fileName    = fileName;
     this.beginLine   = begin.Line;
     this.beginColumn = begin.Column;
     this.endLine     = -1;
     this.endColumn   = -1;
 }
Пример #12
0
		public UsingScope GetUsingScope(AstLocation location)
		{
			foreach (UsingScope scope in usingScopes) {
				if (scope.Region.IsInside(location.Line, location.Column))
					return scope;
			}
			return rootUsingScope;
		}
Пример #13
0
		public ITypeDefinition GetTopLevelTypeDefinition(AstLocation location)
		{
			foreach (ITypeDefinition typeDef in topLevelTypeDefinitions) {
				if (typeDef.Region.IsInside(location.Line, location.Column))
					return typeDef;
			}
			return null;
		}
Пример #14
0
		public Token(int kind, AstLocation startLocation, AstLocation endLocation, string val, object literalValue)
		{
			this.kind         = kind;
			this.col          = startLocation.Column;
			this.line         = startLocation.Line;
			this.endLocation = endLocation;
			this.val          = val;
			this.literalValue = literalValue;
		}
Пример #15
0
 public Token(int kind, AstLocation startLocation, AstLocation endLocation, string val, object literalValue)
 {
     this.kind         = kind;
     this.col          = startLocation.Column;
     this.line         = startLocation.Line;
     this.endLocation  = endLocation;
     this.val          = val;
     this.literalValue = literalValue;
 }
Пример #16
0
 public Identifier(string name, AstLocation location)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.Name          = name;
     this.startLocation = location;
 }
Пример #17
0
        void CheckContent(AstNode node, string content, XmlContentType type, AstLocation start, AstLocation end)
        {
            Assert.IsTrue(node is XmlContentExpression);
            XmlContentExpression expr = node as XmlContentExpression;

            Assert.AreEqual(type, expr.Type);
            Assert.AreEqual(content, expr.Content);
            Assert.AreEqual(start, expr.StartLocation);
            Assert.AreEqual(end, expr.EndLocation);
        }
Пример #18
0
        void PushContext(Context context, Token la, Token t)
        {
            string      indent = new string('\t', stack.Count);
            AstLocation l      = la == null ? (t == null ? AstLocation.Empty : t.EndLocation) : la.Location;

            stack.Push(new Block()
            {
                context = context, lastExpressionStart = l
            });
            Print(indent + "enter " + context);
        }
Пример #19
0
        void CheckElement(AstNode node, string name, AstLocation start, AstLocation end)
        {
            Assert.IsTrue(node is XmlElementExpression);
            XmlElementExpression expr = node as XmlElementExpression;

            Assert.IsEmpty(expr.Attributes);
            Assert.IsEmpty(expr.Children);
            Assert.IsFalse(expr.NameIsExpression);
            Assert.AreEqual(name, expr.XmlName);
            Assert.AreEqual(start, expr.StartLocation);
            Assert.AreEqual(end, expr.EndLocation);
        }
Пример #20
0
        public DebuggerPopup(DebuggerTooltipControl parentControl, AstLocation logicalPosition, bool showPins = true)
        {
            this.contentControl = new DebuggerTooltipControl(parentControl, logicalPosition, showPins);
            this.contentControl.containingPopup = this;
            this.Child  = this.contentControl;
            this.IsLeaf = false;

            //this.KeyDown += new KeyEventHandler(DebuggerPopup_KeyDown);

            //this.contentControl.Focusable = true;
            //Keyboard.Focus(this.contentControl);
            //this.AllowsTransparency = true;
            //this.PopupAnimation = PopupAnimation.Slide;
        }
Пример #21
0
        public void SimpleClassRegionTest()
        {
            const string    program = "class MyClass\n{\n}\n";
            TypeDeclaration td      = ParseUtilCSharp.ParseGlobal <TypeDeclaration>(program);

            Assert.AreEqual(1, td.StartLocation.Line, "StartLocation.Y");
            Assert.AreEqual(1, td.StartLocation.Column, "StartLocation.X");
            AstLocation bodyStartLocation = td.GetChildByRole(AstNode.Roles.LBrace).PrevSibling.EndLocation;

            Assert.AreEqual(1, bodyStartLocation.Line, "BodyStartLocation.Y");
            Assert.AreEqual(14, bodyStartLocation.Column, "BodyStartLocation.X");
            Assert.AreEqual(3, td.EndLocation.Line, "EndLocation.Y");
            Assert.AreEqual(2, td.EndLocation.Column, "EndLocation.Y");
        }
Пример #22
0
        /// <summary>
        /// Gets the tooltip control that shows the value of given variable.
        /// Return null if no tooltip is available.
        /// </summary>
        public object GetTooltipControl(AstLocation logicalPosition, string variableName)
        {
            try {
                var tooltipExpression = GetExpression(variableName);
                if (tooltipExpression == null)
                {
                    return(null);
                }

                string         imageName;
                var            image          = ExpressionNode.GetImageForLocalVariable(out imageName);
                ExpressionNode expressionNode = new ExpressionNode(image, variableName, tooltipExpression);
                expressionNode.ImageName = imageName;

                return(new DebuggerTooltipControl(logicalPosition, expressionNode));
            } catch (GetValueException) {
                return(null);
            }
        }
        void SearchMatchingExpressions(RefactoringOptions options)
        {
            var parser  = new CSharpParser();
            var astNode = parser.ParseExpression(new StringReader(expressionText));
            var data    = options.GetTextEditorData();
            var unit    = parser.Parse(data);

            if (unit != null)
            {
                var node = unit.GetNodeAt(data.Caret.Line, data.Caret.Column);
                while (node != null && !(node is BlockStatement))
                {
                    node = node.Parent;
                }
                if (node != null)
                {
                    var nodeStack = new Stack <AstNode> ();
                    nodeStack.Push(node);
                    var minLoc = new AstLocation(data.Caret.Line, data.Caret.Column);
                    while (nodeStack.Count > 0)
                    {
                        var curNode = nodeStack.Pop();

                        if (curNode.StartLocation > minLoc && curNode.IsMatch(astNode))
                        {
                            matches.Add(curNode);
                        }
                        foreach (var child in curNode.Children)
                        {
                            nodeStack.Push(child);
                        }
                    }
                }
            }

            if (matches.Count > 1)
            {
                var result = MessageService.AskQuestion(string.Format(GettextCatalog.GetString("Replace all {0} occurences ?"), matches.Count), AlertButton.Yes, AlertButton.No);
                replaceAll = result == AlertButton.Yes;
            }
        }
Пример #24
0
        public AstNode GetNodeAt(AstLocation location)
        {
            AstNode node = this;

            while (node.FirstChild != null)
            {
                var child = node.FirstChild;
                while (child != null)
                {
                    if (child.StartLocation <= location && location < child.EndLocation)
                    {
                        node = child;
                        break;
                    }
                    child = child.NextSibling;
                }
                // found no better child node - therefore the parent is the right one.
                if (child == null)
                {
                    break;
                }
            }
            return(node);
        }
Пример #25
0
 int GetOffset(TextBox textBox, AstLocation location)
 {
     return(textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1);
 }
		public DebuggerTooltipControl(AstLocation logicalPosition, IEnumerable<ITreeNode> nodes)
			: this(logicalPosition)
		{
			this.itemsSource = nodes;
		}
Пример #27
0
		protected void LineBreak ()
		{
			lastLineEnd = curLineEnd;
			curLineEnd = new AstLocation (line, col - 1);
		}
Пример #28
0
		public override int GetOffset (AstLocation location)
		{
			return Document.Editor.LocationToOffset (location.Line, location.Column);
		}
Пример #29
0
		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;
				}
			}
		}
Пример #30
0
 public bool IsInside(AstLocation location)
 {
     return(IsInside(location.Line, location.Column));
 }
Пример #31
0
 public DomRegion(AstLocation begin) : this(null, begin)
 {
 }
Пример #32
0
			Identifier CreateIdentifier (string name, AstLocation loc)
			{
				bool isQuoted = name != null ? name.StartsWith ("@") : false;
				string id = isQuoted ? name.Substring (1) : name;
				return new Identifier (id ?? "", loc) { IsQuoted = isQuoted };
			}
Пример #33
0
		public CurrentLineBookmark(MemberReference member, AstLocation location) : base(member, location)
		{
			
		}
Пример #34
0
		public CurrentLineBookmark(MemberReference member, AstLocation location, int ilOffset) : base(member, location)
		{
			this.ILOffset = ilOffset;
		}
		public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, 
			MonoDevelop.Ide.Gui.Document data, ProjectDom dom, DomLocation location, bool correctBlankLines, bool runAferCR = false)
		{
			var unit = data.ParsedDocument.CompilationUnit.Tag as MonoDevelop.CSharp.Ast.CompilationUnit;
			if (unit == null)
				return;

			AstLocation loc = new AstLocation (location.Line + (runAferCR ? -1 : 0), location.Column);
			AstNode member = null;
			foreach (AstNode node in MonoDevelop.CSharp.Ast.Utils.TreeTraversal.PreOrder (unit.Children, n => n.Parent != null && n.Parent.NodeType == NodeType.TypeDeclaration ? Enumerable.Empty<AstNode> () : n.Children)) {
				if (node.NodeType != NodeType.Member)
					continue;
				if (node.StartLocation < loc && loc <= node.EndLocation) {
					member = node;
					break;
				}
			}
			if (member == null)
				return;
			StringBuilder sb = new StringBuilder ();
			int closingBrackets = 0;
			var parent = member.Parent;
			while (parent != null) {
				if (parent.NodeType == NodeType.TypeDeclaration) {
					sb.Insert (0, "class Stub {");
					closingBrackets++;
				} else if (parent is NamespaceDeclaration) {
					sb.Insert (0, "namespace Stub {");
					closingBrackets++;
				}
				parent = parent.Parent;
			}
			sb.AppendLine ();
			System.Console.WriteLine ("caret offset:" + data.Editor.Caret.Offset);
			System.Console.WriteLine (data.Editor.Length);
			int startOffset = sb.Length;
			sb.Append (data.Editor.GetTextBetween (member.StartLocation.Line, 1, member.EndLocation.Line + (runAferCR ? 1 : 0), member.EndLocation.Column));
			int endOffset = sb.Length;
			sb.AppendLine ();
			sb.Append (new string ('}', closingBrackets));

			TextEditorData stubData = new TextEditorData () { Text = sb.ToString () };
			stubData.Document.FileName = data.FileName;
			var compilationUnit = new MonoDevelop.CSharp.Parser.CSharpParser ().Parse (stubData);

			var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
			var domSpacingVisitor = new AstSpacingVisitor (policy, stubData) {
				AutoAcceptChanges = false,
			};
			compilationUnit.AcceptVisitor (domSpacingVisitor, null);

			var domIndentationVisitor = new AstIndentationVisitor (policy, stubData) {
				AutoAcceptChanges = false,
			};
			domIndentationVisitor.CorrectBlankLines = correctBlankLines;
			compilationUnit.AcceptVisitor (domIndentationVisitor, null);

			var changes = new List<Change> ();
			changes.AddRange (domSpacingVisitor.Changes.Cast<TextReplaceChange> ().Where (c => startOffset < c.Offset && c.Offset < endOffset));
			changes.AddRange (domIndentationVisitor.Changes.Cast<TextReplaceChange> ().Where (c => startOffset < c.Offset && c.Offset < endOffset));
			int delta = data.Editor.LocationToOffset (member.StartLocation.Line, 1) - startOffset;
			HashSet<int> lines = new HashSet<int> ();
			foreach (TextReplaceChange change in changes) {
				if (change is AstSpacingVisitor.MyTextReplaceChange) 
					((AstSpacingVisitor.MyTextReplaceChange)change).SetTextEditorData (data.Editor);
				change.Offset += delta;
				lines.Add (data.Editor.OffsetToLineNumber (change.Offset));
			}
			RefactoringService.AcceptChanges (null, null, changes);
			foreach (int line in lines)
				data.Editor.Document.CommitLineUpdate (line);
			stubData.Dispose ();
		}
		public DebuggerTooltipControl(DebuggerTooltipControl parentControl, AstLocation logicalPosition, bool showPins = false)
			: this(logicalPosition)
		{
			this.parentControl = parentControl;
			this.showPins = showPins;
		}
Пример #37
0
 public DomRegion(AstLocation begin, AstLocation end) : this(null, begin, end)
 {
 }
Пример #38
0
		void ReadPreprocessorDirective()
		{
			AstLocation start = new AstLocation(Line, Col - 1);
			string directive = ReadIdent('#');
			// TODO : expression parser for PP directives
			// needed for proper conversion to e. g. C#
			string argument  = ReadToEndOfLine();
//			this.specialTracker.AddPreprocessingDirective(new PreprocessingDirective(directive, argument.Trim(), start, new AstLocation(start.Line, start.Column + directive.Length + argument.Length)));
		}
Пример #39
0
		void CheckXMLState(AstLocation startLocation)
		{
			if (inXmlMode && !xmlModeStack.Any())
				throw new InvalidOperationException("invalid XML stack state at " + startLocation);
		}
Пример #40
0
		Token NextInternal()
		{
			if (misreadExclamationMarkAsTypeCharacter) {
				misreadExclamationMarkAsTypeCharacter = false;
				return new Token(Tokens.ExclamationMark, Col - 1, Line);
			}
			
			unchecked {
				while (true) {
					AstLocation startLocation = new AstLocation(Line, Col);
					int nextChar = ReaderRead();
					if (nextChar == -1)
						return new Token(Tokens.EOF, Col, Line, string.Empty);
					char ch = (char)nextChar;
					#region XML mode
					CheckXMLState(startLocation);
					if (inXmlMode && xmlModeStack.Peek().level <= 0 && !xmlModeStack.Peek().isDocumentStart && !xmlModeStack.Peek().inXmlTag) {
						XmlModeInfo info = xmlModeStack.Peek();
						int peek = nextChar;
						while (true) {
							int step = -1;
							while (peek != -1 && XmlConvert.IsWhitespaceChar((char)peek)) {
								step++;
								peek = ReaderPeek(step);
							}
							
							if (peek == '<' && (ReaderPeek(step + 1) == '!' || ReaderPeek(step + 1) == '?')) {
								char lastCh = '\0';
								for (int i = 0; i < step + 2; i++)
									lastCh = (char)ReaderRead();
								
								if (lastCh == '!')
									return ReadXmlCommentOrCData(Col - 2, Line);
								else
									return ReadXmlProcessingInstruction(Col - 2, Line);
							}
							
							break;
						}
						inXmlMode = false;
						xmlModeStack.Pop();
					}
					if (inXmlMode) {
						XmlModeInfo info = xmlModeStack.Peek();
						int x = Col - 1;
						int y = Line;
						switch (ch) {
							case '<':
								if (ReaderPeek() == '/') {
									ReaderRead();
									info.inXmlCloseTag = true;
									return new Token(Tokens.XmlOpenEndTag, new AstLocation(y, x), new AstLocation(Line, Col));
								}
								if (ReaderPeek() == '%' && ReaderPeek(1) == '=') {
									inXmlMode = false;
									ReaderRead(); ReaderRead();
									return new Token(Tokens.XmlStartInlineVB, new AstLocation(y, x), new AstLocation(Line, Col));
								}
								if (ReaderPeek() == '?') {
									ReaderRead();
									Token t = ReadXmlProcessingInstruction(x, y);
									return t;
								}
								if (ReaderPeek() == '!') {
									ReaderRead();
									Token token = ReadXmlCommentOrCData(x, y);
									return token;
								}
								info.level++;
								info.isDocumentStart = false;
								info.inXmlTag = true;
								return new Token(Tokens.XmlOpenTag, x, y);
							case '/':
								if (ReaderPeek() == '>') {
									ReaderRead();
									info.inXmlTag = false;
									info.level--;
									return new Token(Tokens.XmlCloseTagEmptyElement, new AstLocation(y, x), new AstLocation(Line, Col));
								}
								break;
							case '>':
								if (info.inXmlCloseTag)
									info.level--;
								info.inXmlTag = info.inXmlCloseTag = false;
								return new Token(Tokens.XmlCloseTag, x, y);
							case '=':
								return new Token(Tokens.Assign, x, y);
							case '\'':
							case '"':
								string s = ReadXmlString(ch);
								return new Token(Tokens.LiteralString, x, y, ch + s + ch, s);
							default:
								if (info.inXmlCloseTag || info.inXmlTag) {
									if (XmlConvert.IsWhitespaceChar(ch))
										continue;
									return new Token(Tokens.Identifier, x, y, ReadXmlIdent(ch));
								} else {
									string content = ReadXmlContent(ch);
									return new Token(Tokens.XmlContent, startLocation, new AstLocation(Line, Col), content, null);
								}
						}
						#endregion
					} else {
						#region Standard Mode
						if (Char.IsWhiteSpace(ch)) {
							if (HandleLineEnd(ch)) {
								if (lineEnd) {
									// second line end before getting to a token
									// -> here was a blank line
//									specialTracker.AddEndOfLine(startLocation);
								} else {
									lineEnd = true;
									return new Token(Tokens.EOL, startLocation, new AstLocation(Line, Col), null, null);
								}
							}
							continue;
						}
						if (ch == '_') {
							if (ReaderPeek() == -1) {
								errors.Error(Line, Col, String.Format("No EOF expected after _"));
								return new Token(Tokens.EOF, Col, Line, string.Empty);
							}
							if (!Char.IsWhiteSpace((char)ReaderPeek())) {
								int x = Col - 1;
								int y = Line;
								string s = ReadIdent('_');
								lineEnd = false;
								return new Token(Tokens.Identifier, x, y, s);
							}
							encounteredLineContinuation = true;
							ch = (char)ReaderRead();
							
							bool oldLineEnd = lineEnd;
							lineEnd = false;
							while (Char.IsWhiteSpace(ch)) {
								if (HandleLineEnd(ch)) {
									lineEnd = true;
									break;
								}
								if (ReaderPeek() != -1) {
									ch = (char)ReaderRead();
								} else {
									errors.Error(Line, Col, String.Format("No EOF expected after _"));
									return new Token(Tokens.EOF, Col, Line, string.Empty);
								}
							}
							if (!lineEnd) {
								errors.Error(Line, Col, String.Format("NewLine expected"));
							}
							lineEnd = oldLineEnd;
							continue;
						}
						
						if (ch == '#') {
							while (Char.IsWhiteSpace((char)ReaderPeek())) {
								ReaderRead();
							}
							if (Char.IsDigit((char)ReaderPeek())) {
								int x = Col - 1;
								int y = Line;
								string s = ReadDate();
								DateTime time = new DateTime(1, 1, 1, 0, 0, 0);
								try {
									time = DateTime.Parse(s, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault);
								} catch (Exception e) {
									errors.Error(Line, Col, String.Format("Invalid date time {0}", e));
								}
								return new Token(Tokens.LiteralDate, x, y, s, time);
							} else {
								ReadPreprocessorDirective();
								continue;
							}
						}
						
						if (ch == '[') { // Identifier
							lineEnd = false;
							if (ReaderPeek() == -1) {
								errors.Error(Line, Col, String.Format("Identifier expected"));
							}
							ch = (char)ReaderRead();
							if (ch == ']' || Char.IsWhiteSpace(ch)) {
								errors.Error(Line, Col, String.Format("Identifier expected"));
							}
							int x = Col - 1;
							int y = Line;
							string s = ReadIdent(ch);
							if (ReaderPeek() == -1) {
								errors.Error(Line, Col, String.Format("']' expected"));
							}
							ch = (char)ReaderRead();
							if (!(ch == ']')) {
								errors.Error(Line, Col, String.Format("']' expected"));
							}
							return new Token(Tokens.Identifier, x, y, s);
						}
						if (Char.IsLetter(ch)) {
							int x = Col - 1;
							int y = Line;
							char typeCharacter;
							string s = ReadIdent(ch, out typeCharacter);
							if (typeCharacter == '\0') {
								int keyWordToken = Keywords.GetToken(s);
								if (keyWordToken >= 0) {
									// handle 'REM' comments
									if (keyWordToken == Tokens.Rem) {
										ReadComment();
										if (!lineEnd) {
											lineEnd = true;
											return new Token(Tokens.EOL, Col, Line, "\n");
										}
										continue;
									}
									
									lineEnd = false;
									return new Token(keyWordToken, x, y, s);
								}
							}
							
							lineEnd = false;
							return new Token(Tokens.Identifier, x, y, s);
							
						}
						if (Char.IsDigit(ch)) {
							lineEnd = false;
							return ReadDigit(ch, Col - 1);
						}
						if (ch == '&') {
							lineEnd = false;
							if (ReaderPeek() == -1) {
								return ReadOperator('&');
							}
							ch = (char)ReaderPeek();
							if (Char.ToUpper(ch, CultureInfo.InvariantCulture) == 'H' || Char.ToUpper(ch, CultureInfo.InvariantCulture) == 'O') {
								return ReadDigit('&', Col - 1);
							}
							return ReadOperator('&');
						}
						if (ch == '\'' || ch == '\u2018' || ch == '\u2019') {
							int x = Col - 1;
							int y = Line;
							ReadComment();
							if (!lineEnd) {
								lineEnd = true;
								return new Token(Tokens.EOL, x, y, "\n");
							}
							continue;
						}
						if (ch == '"') {
							lineEnd = false;
							int x = Col - 1;
							int y = Line;
							string s = ReadString();
							if (ReaderPeek() != -1 && (ReaderPeek() == 'C' || ReaderPeek() == 'c')) {
								ReaderRead();
								if (s.Length != 1) {
									errors.Error(Line, Col, String.Format("Chars can only have Length 1 "));
								}
								if (s.Length == 0) {
									s = "\0";
								}
								return new Token(Tokens.LiteralCharacter, x, y, '"' + s  + "\"C", s[0]);
							}
							return new Token(Tokens.LiteralString, x, y, '"' + s + '"', s);
						}
						if (ch == '%' && ReaderPeek() == '>') {
							int x = Col - 1;
							int y = Line;
							inXmlMode = true;
							ReaderRead();
							return new Token(Tokens.XmlEndInlineVB, new AstLocation(y, x), new AstLocation(Line, Col));
						}
						#endregion
						if (ch == '<' && (ef.NextTokenIsPotentialStartOfExpression || ef.NextTokenIsStartOfImportsOrAccessExpression)) {
							xmlModeStack.Push(new XmlModeInfo(ef.NextTokenIsStartOfImportsOrAccessExpression));
							XmlModeInfo info = xmlModeStack.Peek();
							int x = Col - 1;
							int y = Line;
							inXmlMode = true;
							if (ReaderPeek() == '/') {
								ReaderRead();
								info.inXmlCloseTag = true;
								return new Token(Tokens.XmlOpenEndTag, new AstLocation(y, x), new AstLocation(Line, Col));
							}
							// should we allow <%= at start of an expression? not valid with vbc ...
							if (ReaderPeek() == '%' && ReaderPeek(1) == '=') {
								inXmlMode = false;
								ReaderRead(); ReaderRead();
								return new Token(Tokens.XmlStartInlineVB, new AstLocation(y, x), new AstLocation(Line, Col));
							}
							if (ReaderPeek() == '!') {
								ReaderRead();
								Token t = ReadXmlCommentOrCData(x, y);
								return t;
							}
							if (ReaderPeek() == '?') {
								ReaderRead();
								Token t = ReadXmlProcessingInstruction(x, y);
								info.isDocumentStart = t.val.Trim().StartsWith("xml", StringComparison.OrdinalIgnoreCase);
								return t;
							}
							info.inXmlTag = true;
							info.level++;
							return new Token(Tokens.XmlOpenTag, x, y);
						}
						Token token = ReadOperator(ch);
						if (token != null) {
							lineEnd = false;
							return token;
						}
					}
					
					errors.Error(Line, Col, String.Format("Unknown char({0}) which can't be read", ch));
				}
			}
		}
Пример #41
0
 public VBModifierToken(AstLocation location, Modifiers modifier) : base(location, 0)
 {
     this.Modifier = modifier;
 }
Пример #42
0
		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);
				}
			}
		}
Пример #43
0
		public CSharpModifierToken (AstLocation location, Modifiers modifier) : base (location, 0)
		{
			this.Modifier = modifier;
		}
Пример #44
0
 public SavepointEventArgs(AstLocation savepointLocation, VBLexerMemento state)
 {
     this.SavepointLocation = savepointLocation;
     this.State             = state;
 }
Пример #45
0
 void IRelocatable.SetStartLocation(AstLocation startLocation)
 {
     this.Location = startLocation;
 }
		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;
				}
			}
		}
Пример #47
0
		public void SetInitialLocation(AstLocation location)
		{
			if (lastToken != null || curToken != null || peekToken != null)
				throw new InvalidOperationException();
			this.line = location.Line;
			this.col = location.Column;
		}
		public DebuggerTooltipControl(AstLocation logicalPosition, ITreeNode node)
			: this(logicalPosition, new ITreeNode[] { node })
		{
			
		}
Пример #49
0
 public override int GetOffset(AstLocation location)
 {
     return(Document.Editor.LocationToOffset(location.Line, location.Column));
 }
Пример #50
0
 public Token(int kind, AstLocation startLocation, AstLocation endLocation) : this(kind, startLocation, endLocation, "", null)
 {
 }
Пример #51
0
		int GetOffset(TextBox textBox, AstLocation location)
		{
			return textBox.GetFirstCharIndexFromLine(location.Line - 1) + location.Column - 1;
		}
Пример #52
0
		void CheckContent(AstNode node, string content, XmlContentType type, AstLocation start, AstLocation end)
		{
			Assert.IsTrue(node is XmlContentExpression);
			XmlContentExpression expr = node as XmlContentExpression;
			Assert.AreEqual(type, expr.Type);
			Assert.AreEqual(content, expr.Content);
			Assert.AreEqual(start, expr.StartLocation);
			Assert.AreEqual(end, expr.EndLocation);
		}
Пример #53
0
 public BookmarkBase(MemberReference member, AstLocation location)
 {
     this.MemberReference = member;
     this.Location        = location;
 }
Пример #54
0
 public XmlIdentifier(string name, AstLocation startLocation, AstLocation endLocation)
 {
     this.Name          = name;
     this.startLocation = startLocation;
     this.endLocation   = endLocation;
 }
Пример #55
0
 public FindNodeVisitor(AstLocation start, AstLocation end)
 {
     this.start = start;
     this.end   = end;
 }
Пример #56
0
		void ReadComment()
		{
			AstLocation startPos = new AstLocation(Line, Col);
			sb.Length = 0;
			StringBuilder curWord = specialCommentHash != null ? new StringBuilder() : null;
			int missingApostrophes = 2; // no. of ' missing until it is a documentation comment
			int nextChar;
			while ((nextChar = ReaderRead()) != -1) {
				char ch = (char)nextChar;
				
				if (HandleLineEnd(ch)) {
					break;
				}
				
				sb.Append(ch);
				
				if (missingApostrophes > 0) {
					if (ch == '\'' || ch == '\u2018' || ch == '\u2019') {
						if (--missingApostrophes == 0) {
//							specialTracker.StartComment(CommentType.Documentation, isAtLineBegin, startPos);
							sb.Length = 0;
						}
					} else {
//						specialTracker.StartComment(CommentType.SingleLine, isAtLineBegin, startPos);
						missingApostrophes = 0;
					}
				}
				
				if (specialCommentHash != null) {
					if (Char.IsLetter(ch)) {
						curWord.Append(ch);
					} else {
						string tag = curWord.ToString();
						curWord.Length = 0;
						if (specialCommentHash.ContainsKey(tag)) {
							AstLocation p = new AstLocation(Line, Col);
							string comment = ch + ReadToEndOfLine();
//							this.TagComments.Add(new TagComment(tag, comment, isAtLineBegin, p, new Location(Col, Line)));
							sb.Append(comment);
							break;
						}
					}
				}
			}
//			if (missingApostrophes > 0) {
//				specialTracker.StartComment(CommentType.SingleLine, isAtLineBegin, startPos);
//			}
//			specialTracker.AddString(sb.ToString());
//			specialTracker.FinishComment(new Location(Col, Line));
		}
Пример #57
0
		public SavepointEventArgs(AstLocation savepointLocation, VBLexerMemento state)
		{
			this.SavepointLocation = savepointLocation;
			this.State = state;
		}
Пример #58
0
		void CheckElement(AstNode node, string name, AstLocation start, AstLocation end)
		{
			Assert.IsTrue(node is XmlElementExpression);
			XmlElementExpression expr = node as XmlElementExpression;
			Assert.IsEmpty(expr.Attributes);
			Assert.IsEmpty(expr.Children);
			Assert.IsFalse(expr.NameIsExpression);
			Assert.AreEqual(name, expr.XmlName);
			Assert.AreEqual(start, expr.StartLocation);
			Assert.AreEqual(end, expr.EndLocation);
		}
Пример #59
0
		/// <summary>
		/// Gets the tooltip control that shows the value of given variable.
		/// Return null if no tooltip is available.
		/// </summary>
		public object GetTooltipControl(AstLocation logicalPosition, string variableName)
		{
			try {
				var tooltipExpression = GetExpression(variableName);
				if (tooltipExpression == null) return null;
				
				string imageName;
				var image = ExpressionNode.GetImageForLocalVariable(out imageName);
				ExpressionNode expressionNode = new ExpressionNode(image, variableName, tooltipExpression);
				expressionNode.ImageName = imageName;
				
				return new DebuggerTooltipControl(logicalPosition, expressionNode);
			} catch (GetValueException) {
				return null;
			}
		}
Пример #60
0
		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 AstLocation (comment.Line, comment.Col);
					var end =  new AstLocation (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;
		}