コード例 #1
0
		public override void WriteToken(Role role, string token, TextTokenType tokenType)
		{
			WriteIndentation();
			column += token.Length;
			textWriter.Write(token);
			isAtStartOfLine = false;
		}
コード例 #2
0
		public override void WriteToken(Role role, string token, TextTokenType tokenType)
		{
			// Avoid that two +, - or ? tokens are combined into a ++, -- or ?? token.
			// Note that we don't need to handle tokens like = because there's no valid
			// C# program that contains the single token twice in a row.
			// (for +, - and &, this can happen with unary operators;
			// for ?, this can happen in "a is int? ? b : c" or "a as int? ?? 0";
			// and for /, this can happen with "1/ *ptr" or "1/ //comment".)
			if (lastWritten == LastWritten.Plus && token[0] == '+' ||
			    lastWritten == LastWritten.Minus && token[0] == '-' ||
			    lastWritten == LastWritten.Ampersand && token[0] == '&' ||
			    lastWritten == LastWritten.QuestionMark && token[0] == '?' ||
			    lastWritten == LastWritten.Division && token[0] == '*') {
				base.Space();
			}
			base.WriteToken(role, token, tokenType);
			if (token == "+") {
				lastWritten = LastWritten.Plus;
			} else if (token == "-") {
				lastWritten = LastWritten.Minus;
			} else if (token == "&") {
				lastWritten = LastWritten.Ampersand;
			} else if (token == "?") {
				lastWritten = LastWritten.QuestionMark;
			} else if (token == "/") {
				lastWritten = LastWritten.Division;
			} else {
				lastWritten = LastWritten.Other;
			}
		}
コード例 #3
0
		public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType)
		{
			WriteIndentation();
			if (tokenType != TextTokenType.Keyword && (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier))) {
				textWriter.Write('@');
				column++;
			}
			textWriter.Write(identifier.Name);
			column += identifier.Name.Length;
			isAtStartOfLine = false;
		}
コード例 #4
0
		public override void WriteToken(Role role, string token, TextTokenType tokenType)
		{
			CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
			t.Role = role;
			EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement;
			if (node == null)
				currentList.Add(t);
			else {
				node.Location = locationProvider.Location;
			}
			base.WriteToken(role, token, tokenType);
		}
コード例 #5
0
		public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType)
		{
			if (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier)) {
				if (lastWritten == LastWritten.KeywordOrIdentifier) {
					// this space is not strictly required, so we call Space()
					Space();
				}
			} else if (lastWritten == LastWritten.KeywordOrIdentifier) {
				// this space is strictly required, so we directly call the formatter
				base.Space();
			}
			base.WriteIdentifier(identifier, tokenType);
			lastWritten = LastWritten.KeywordOrIdentifier;
		}
コード例 #6
0
ファイル: NewTextEditor.cs プロジェクト: arkanoid1/dnSpy
		static void UpdateTextEditorResource(TextTokenType colorType, string name) {
			var theme = Themes.Theme;

			var color = theme.GetColor(colorType).TextInheritedColor;
			App.Current.Resources[Theme.GetTextInheritedForegroundResourceKey(name)] = GetBrush(color.Foreground);
			App.Current.Resources[Theme.GetTextInheritedBackgroundResourceKey(name)] = GetBrush(color.Background);
			App.Current.Resources[Theme.GetTextInheritedFontStyleResourceKey(name)] = color.FontStyle ?? FontStyles.Normal;
			App.Current.Resources[Theme.GetTextInheritedFontWeightResourceKey(name)] = color.FontWeight ?? FontWeights.Normal;

			color = theme.GetColor(colorType).InheritedColor;
			App.Current.Resources[Theme.GetInheritedForegroundResourceKey(name)] = GetBrush(color.Foreground);
			App.Current.Resources[Theme.GetInheritedBackgroundResourceKey(name)] = GetBrush(color.Background);
			App.Current.Resources[Theme.GetInheritedFontStyleResourceKey(name)] = color.FontStyle ?? FontStyles.Normal;
			App.Current.Resources[Theme.GetInheritedFontWeightResourceKey(name)] = color.FontWeight ?? FontWeights.Normal;
		}
コード例 #7
0
ファイル: LanguageTokens.cs プロジェクト: nakijun/dnSpy
		public bool Find(int offset, out int defaultTextLength, out TextTokenType tokenType, out int tokenLength) {
			Debug.Assert(tokenInfos != null, "You must call Finish() before you call this method");
			int index;
			if (!offsetToTokenInfoIndex.TryGetValue(offset, out index)) {
				defaultTextLength = 0;
				tokenType = TextTokenType.Last;
				tokenLength = 0;
				return false;
			}

			ushort val = tokenInfos[index];
			defaultTextLength = (val >> TEXT_TOKEN_LENGTH_BIT) & TEXT_TOKEN_LENGTH_MAX;
			tokenType = (TextTokenType)((val >> TOKEN_TYPE_BIT) & TOKEN_TYPE_MAX);
			tokenLength = (val >> TOKEN_LENGTH_BIT) & TOKEN_LENGTH_MAX;
			return true;
		}
コード例 #8
0
ファイル: TextTokenWriter.cs プロジェクト: arkanoid1/dnSpy
		public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType)
		{
			if (tokenType == TextTokenType.Text)
				tokenType = TextTokenHelper.GetTextTokenType(identifier.AnnotationVT<TextTokenType>() ?? identifier.Annotation<object>());

			if (tokenType != TextTokenType.Keyword && (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier))) {
				output.Write('@', TextTokenType.Operator);
			}
			
			var definition = GetCurrentDefinition(identifier);
			if (definition != null) {
				output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType, false);
				return;
			}
			
			object memberRef = GetCurrentMemberReference();

			if (memberRef != null) {
				output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType);
				return;
			}

			definition = GetCurrentLocalDefinition();
			if (definition != null) {
				output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType);
				return;
			}

			memberRef = GetCurrentLocalReference();
			if (memberRef != null) {
				output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType, true);
				return;
			}

			if (firstUsingDeclaration) {
				output.MarkFoldStart(defaultCollapsed: true);
				firstUsingDeclaration = false;
			}

			var s = identifier.Name;
			if (identifier.Annotation<IdentifierFormatted>() == null)
				s = IdentifierEscaper.Escape(s);
			output.Write(s, tokenType);
		}
コード例 #9
0
ファイル: TextTokenWriter.cs プロジェクト: lisong521/dnSpy
		public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType)
		{
			if (tokenType == TextTokenType.Text)
				tokenType = TextTokenHelper.GetTextTokenType(identifier.AnnotationVT<TextTokenType>() ?? identifier.Annotation<object>());

			var definition = GetCurrentDefinition(identifier);
			if (definition != null) {
				output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType, false);
				return;
			}
			
			object memberRef = GetCurrentMemberReference();

			if (memberRef != null) {
				output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType);
				return;
			}

			definition = GetCurrentLocalDefinition();
			if (definition != null) {
				output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType);
				return;
			}

			memberRef = GetCurrentLocalReference();
			if (memberRef != null) {
				output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType, true);
				return;
			}

			if (firstUsingDeclaration) {
				output.MarkFoldStart(defaultCollapsed: true);
				firstUsingDeclaration = false;
			}

			output.Write(IdentifierEscaper.Escape(identifier.Name), tokenType);
		}
コード例 #10
0
 public void Write(string text, TextTokenType tokenType)
 {
     WriteIndent();
     Append(tokenType, text);
 }
コード例 #11
0
ファイル: AvalonEditTextOutput.cs プロジェクト: danysu/dnSpy
 public void Write(char ch, TextTokenType tokenType)
 {
     WriteIndent();
     Append(tokenType, ch);
 }
コード例 #12
0
ファイル: AvalonEditTextOutput.cs プロジェクト: danysu/dnSpy
 void Append(TextTokenType tokenType, char c)
 {
     tokens.Append(tokenType, c);
     b.Append(c);
     Debug.Assert(b.Length == tokens.Length);
 }
コード例 #13
0
        public IEnumerator <string> GetEnumerator()
        {
            bool          insideQuote = false;
            TextTokenType quoteType   = TextTokenType.Separator;
            StringBuilder result      = new StringBuilder();

            foreach (TextToken token in tokenizer)
            {
                switch (token.Type)
                {
                case TextTokenType.Separator:
                    if (insideQuote)
                    {
                        result.Append(token.Value);
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(token.Value) || result.Length > 0)
                        {
                            yield return(result.ToString());
                        }
                        result.Length = 0;
                    }
                    break;

                case TextTokenType.SingleQuote:
                case TextTokenType.DoubleQoute:
                    if (!insideQuote)
                    {
                        quoteType   = token.Type;
                        insideQuote = true;
                        if (result.Length > 0)
                        {
                            yield return(result.ToString());
                        }
                        result.Length = 0;
                    }
                    else if (token.Type == quoteType)
                    {
                        insideQuote = false;
                        quoteType   = TextTokenType.Separator;
                    }
                    else
                    {
                        result.Append(token.Value);
                    }
                    break;

                case TextTokenType.Value:
                    result.Append(token.Value);
                    break;

                default:
                    throw new InvalidOperationException("Unknown token type: " + token.Type);
                }
            }
            if (result.Length > 0)
            {
                yield return(result.ToString());
            }
        }
コード例 #14
0
ファイル: LanguageTokens.cs プロジェクト: BahNahNah/dnSpy
        // Gets called to add one token. No newlines are allowed
        void AppendInternal(TextTokenType tokenType, int length)
        {
            Debug.Assert(length >= 0);
            if (length == 0)
                return;

            redo:
            if (isAppendingDefaultText) {
                if (tokenType == TextTokenType.Text) {
                    int newLength = currentDefaultTextLength + length;
                    while (newLength > TEXT_TOKEN_LENGTH_MAX) {
                        currentDefaultTextLength = Math.Min(newLength, TEXT_TOKEN_LENGTH_MAX);
                        EndCurrentToken(0);
                        newLength -= TEXT_TOKEN_LENGTH_MAX;
                    }
                    currentDefaultTextLength = newLength;
                    currentOffset += length;
                    return;
                }
                isAppendingDefaultText = false;
                currentTokenType = tokenType;
            }

            if (currentTokenType != tokenType) {
                EndCurrentToken(0);
                goto redo;
            }

            {
                int newLength = currentTokenLength + length;
                while (newLength > TOKEN_LENGTH_MAX) {
                    currentTokenLength = Math.Min(newLength, TOKEN_LENGTH_MAX);
                    EndCurrentToken(0);
                    newLength -= TOKEN_LENGTH_MAX;
                    isAppendingDefaultText = false;
                    currentTokenType = tokenType;
                }
                currentTokenLength = newLength;
                if (currentTokenLength == 0)
                    isAppendingDefaultText = true;
                currentOffset += length;
            }
        }
コード例 #15
0
ファイル: Theme.cs プロジェクト: se7ensoft/dnSpy
 public Color GetColor(TextTokenType tokenType)
 {
     return GetColor((ColorType)tokenType);
 }
コード例 #16
0
 void Append(TextTokenType tokenType, char c)
 {
     tokens.Append(tokenType, c);
     b.Append(c);
     Debug.Assert(b.Length == tokens.Length);
 }
コード例 #17
0
ファイル: XmlDocRenderer.cs プロジェクト: danysu/dnSpy
 void IXmlDocOutput.Write(string s, TextTokenType tokenType)
 {
     ret.Append(s);
 }
コード例 #18
0
 public TextToken(TextTokenType type, string text)
 {
     Type = type;
     Text = text;
 }
コード例 #19
0
 public void Append(TextTokenType tokenType, char c)
 {
     Append(tokenType, c.ToString());
 }
コード例 #20
0
        public static void WriteOffsetReference(ITextOutput writer, Instruction instruction, MethodDef method, TextTokenType tokenType = TextTokenType.Label)
        {
            var r = instruction == null ? null : method == null ? (object)instruction : new InstructionReference(method, instruction);

            writer.WriteReference(DnlibExtensions.OffsetToString(instruction.GetOffset()), r, tokenType);
        }
コード例 #21
0
 public SimpleType(TextTokenType tokenType, string identifier, TextLocation location)
 {
     SetChildByRole(Roles.Identifier, new Identifier (tokenType, identifier, location));
 }
コード例 #22
0
 public TextToken(TextTokenType type, string value)
 {
     Value = value;
     Type  = type;
 }
コード例 #23
0
 public void WriteDefinition(string text, object definition, TextTokenType tokenType, bool isLocal)
 {
     WriteIndent();
     int start = this.TextLength;
     Append(tokenType, text);
     int end = this.TextLength;
     this.DefinitionLookup.AddDefinition(definition, this.TextLength);
     references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = definition, IsLocal = isLocal, IsLocalTarget = true });
 }
コード例 #24
0
 public void WriteIdentifier(string ident, TextTokenType tokenType)
 {
     WriteIndentation();
     textWriter.Write(ident);
 }
コード例 #25
0
 public void WriteReference(string text, object reference, TextTokenType tokenType, bool isLocal)
 {
     WriteIndent();
     int start = this.TextLength;
     Append(tokenType, text);
     int end = this.TextLength;
     references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = reference, IsLocal = isLocal });
 }
コード例 #26
0
ファイル: LanguageTokens.cs プロジェクト: BahNahNah/dnSpy
 public void Append(TextTokenType tokenType, char c)
 {
     Append(tokenType, c.ToString());
 }
コード例 #27
0
 void Append(TextTokenType tokenType, string s)
 {
     tokens.Append(tokenType, s);
     b.Append(s);
     Debug.Assert(b.Length == tokens.Length);
 }
コード例 #28
0
		public override void WritePrimitiveValue(object value, TextTokenType? tokenType = null, string literalValue = null)
		{
			Expression node = nodes.Peek().LastOrDefault() as Expression;
			if (node is PrimitiveExpression) {
				((PrimitiveExpression)node).SetStartLocation(locationProvider.Location);
			}
			if (node is NullReferenceExpression) {
				((NullReferenceExpression)node).SetStartLocation(locationProvider.Location);
			}
			base.WritePrimitiveValue(value, tokenType, literalValue);
		}
コード例 #29
0
ファイル: LanguageTokens.cs プロジェクト: BahNahNah/dnSpy
        public void Append(TextTokenType tokenType, string s)
        {
            int oldCurrentOffset = currentOffset;

            // Newlines could be part of the input string
            int so = 0;
            while (so < s.Length) {
                int nlOffs = s.IndexOfAny(newLineChars, so);
                if (nlOffs >= 0) {
                    AppendInternal(tokenType, nlOffs - so);
                    so = nlOffs;
                    int nlLen = s[so] == '\r' && so + 1 < s.Length && s[so + 1] == '\n' ? 2 : 1;
                    currentOffset += nlLen;
                    EndCurrentToken(nlLen);
                    so += nlLen;
                }
                else {
                    AppendInternal(tokenType, s.Length - so);
                    break;
                }
            }

            Debug.Assert(oldCurrentOffset + s.Length == currentOffset);
        }
コード例 #30
0
 public SimpleType(TextTokenType tokenType, string identifier)
 {
     this.IdentifierToken = Ast.Identifier.Create(tokenType, identifier);
 }
コード例 #31
0
ファイル: LanguageTokens.cs プロジェクト: BahNahNah/dnSpy
        void EndCurrentToken(int lengthTillNextToken)
        {
            Debug.Assert(currentTokenLength == 0 || !isAppendingDefaultText);
            int totalLength = currentDefaultTextLength + currentTokenLength;
            if (totalLength != 0) {
                offsetToTokenInfoIndex.Add(currentTokenOffset, tokenInfosList.Count);
                Debug.Assert((int)currentTokenType <= TOKEN_TYPE_MAX);
                Debug.Assert((int)currentTokenLength <= TOKEN_LENGTH_MAX);
                Debug.Assert((int)currentDefaultTextLength <= TEXT_TOKEN_LENGTH_MAX);
                ushort compressedValue = (ushort)(
                            ((int)currentTokenType << TOKEN_TYPE_BIT) |
                            (currentTokenLength << TOKEN_LENGTH_BIT) |
                            (currentDefaultTextLength << TEXT_TOKEN_LENGTH_BIT));
                tokenInfosList.Add(compressedValue);
            }

            currentTokenOffset += totalLength + lengthTillNextToken;
            currentDefaultTextLength = 0;
            currentTokenLength = 0;
            currentTokenType = TextTokenType.Last;
            isAppendingDefaultText = true;
        }
コード例 #32
0
ファイル: NewTextEditor.cs プロジェクト: softearth/dnSpy
 HighlightingColor GetColor(TextTokenType tokenType)
 {
     return(Themes.Theme.GetColor(tokenType).TextInheritedColor);
 }
コード例 #33
0
		public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType)
		{
			if (!identifier.IsNull)
				identifier.SetStartLocation(locationProvider.Location);
			currentList.Add(identifier);
			base.WriteIdentifier(identifier, tokenType);
		}
コード例 #34
0
ファイル: Script.cs プロジェクト: JackWangCUMT/NRefactory
			public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType)
			{
				int startOffset = stringWriter.GetStringBuilder ().Length;
				int endOffset = startOffset + (identifier.Name ?? "").Length + (identifier.IsVerbatim ? 1 : 0);
				NewSegments.Add(new KeyValuePair<AstNode, Segment>(identifier, new Segment(startOffset, endOffset - startOffset)));
				base.WriteIdentifier (identifier, tokenType);
			}
コード例 #35
0
ファイル: SimpleHighlighter.cs プロジェクト: BahNahNah/dnSpy
 HighlightingColor GetColor(TextTokenType tokenType)
 {
     var color = Themes.Theme.GetColor(tokenType).TextInheritedColor;
     Debug.Assert(color != null);
     return color;
 }
コード例 #36
0
ファイル: AvalonEditTextOutput.cs プロジェクト: danysu/dnSpy
 void Append(TextTokenType tokenType, string s)
 {
     tokens.Append(tokenType, s);
     b.Append(s);
     Debug.Assert(b.Length == tokens.Length);
 }
コード例 #37
0
 public static void WriteOffsetReference(ITextOutput writer, Instruction instruction, MethodDef method, TextTokenType tokenType = TextTokenType.Label)
 {
     var r = instruction == null ? null : method == null ? (object)instruction : new InstructionReference(method, instruction);
     writer.WriteReference(DnlibExtensions.OffsetToString(instruction.GetOffset()), r, tokenType);
 }
コード例 #38
0
ファイル: TextTokenWriter.cs プロジェクト: damnya/dnSpy
 public override void WritePrimitiveValue(object value, TextTokenType? tokenType = null, string literalValue = null)
 {
     int column = 0;
     TextWriterTokenWriter.WritePrimitiveValue(value, tokenType, literalValue, ref column, (a, b) => output.Write(a, b), (a, b, c) => WriteToken(a, b, c));
 }
コード例 #39
0
ファイル: SimpleHighlighter.cs プロジェクト: BahNahNah/dnSpy
 public void Write(string s, TextTokenType tokenType)
 {
     if (needsNewLine)
         WriteNewLine();
     output.Write(s, tokenType);
 }
コード例 #40
0
ファイル: AvalonEditTextOutput.cs プロジェクト: danysu/dnSpy
 public void Write(string text, TextTokenType tokenType)
 {
     WriteIndent();
     Append(tokenType, text);
 }
コード例 #41
0
ファイル: XmlDocRenderer.cs プロジェクト: BahNahNah/dnSpy
 void IXmlDocOutput.Write(string s, TextTokenType tokenType)
 {
     ret.Append(s);
 }
コード例 #42
0
 public void WriteToken(string token, TextTokenType tokenType)
 {
     // Attach member reference to token only if there's no identifier in the current node.
     IMemberRef memberRef = GetCurrentMemberReference();
     if (memberRef != null && nodeStack.Peek().GetChildByRole(AstNode.Roles.Identifier).IsNull)
         output.WriteReference(token, memberRef, tokenType);
     else
         output.Write(token, tokenType);
 }
コード例 #43
0
ファイル: TextTokenWriter.cs プロジェクト: damnya/dnSpy
        public override void WriteToken(Role role, string token, TextTokenType tokenType)
        {
            IMemberRef memberRef = GetCurrentMemberReference();
            var node = nodeStack.Peek();

            bool addRef = memberRef != null &&
                    (node is BinaryOperatorExpression ||
                    node is UnaryOperatorExpression ||
                    node is AssignmentExpression ||
                    node is IndexerExpression);

            // Add a ref to the method if it's a delegate call
            if (!addRef && node is InvocationExpression && memberRef is IMethod) {
                var md = (memberRef as IMethod).Resolve();
                if (md != null && md.DeclaringType.IsDelegate())
                    addRef = true;
            }

            if (addRef)
                output.WriteReference(token, memberRef, tokenType);
            else
                output.Write(token, tokenType);
        }
コード例 #44
0
 public void Write(char ch, TextTokenType tokenType)
 {
     WriteIndent();
     Append(tokenType, ch);
 }