internal Preprocessor(string text, CsTokenClass tokenClass, CodeLocation location, bool generated) : base(text, CsTokenType.PreprocessorDirective, tokenClass, location, generated) { this.preprocessorType = string.Empty; int num = 0; while (true) { if (text[num] == '#') { break; } num++; } string str = string.Empty; int num2 = num; while ((num2 + 1) < text.Length) { if (!char.IsLetter(text[num2 + 1])) { break; } num2++; } if (num2 > num) { str = text.Substring(num + 1, num2 - num); } this.preprocessorType = str; }
internal Parameter(TypeToken type, string name, ParameterModifiers modifiers, CodeLocation location, CsTokenList tokens, bool generated) { this.type = type; this.name = name; this.modifiers = modifiers; this.location = location; this.tokens = tokens; this.generated = generated; }
private Symbol GetWhitespace() { StringBuilder builder = new StringBuilder(); while (true) { char ch = this.codeReader.Peek(); if ((ch == '\0') || ((ch != ' ') && (ch != '\t'))) { break; } builder.Append(ch); this.codeReader.ReadNext(); } CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + builder.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + builder.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol symbol = new Symbol(builder.ToString(), SymbolType.WhiteSpace, location); this.marker.Index += builder.Length; this.marker.IndexOnLine += builder.Length; return symbol; }
public Token(CodeLocation location, bool generated) { Param.RequireNotNull(location, "location"); this.location = location; this.generated = generated; }
internal ConstructorConstraint(MasterList<CsToken> childTokens, CodeLocation location, bool generated) : base(CsTokenType.Other, CsTokenClass.ConstructorConstraint, location, generated) { this.childTokens = childTokens; }
internal Attribute(MasterList<CsToken> childTokens, CodeLocation location, ICollection<AttributeExpression> attributeExpressions, bool generated) : base(CsTokenType.Attribute, CsTokenClass.Attribute, location, generated) { this.childTokens = childTokens; this.attributeExpressions = attributeExpressions; }
/// <summary> /// Joins the two given locations. /// </summary> /// <param name="location1">The first location to join.</param> /// <param name="location2">The second location to join.</param> /// <returns>Returns the joined <see cref="CodeLocation"/>.</returns> public static CodeLocation Join(CodeLocation location1, CodeLocation location2) { Param.Ignore(location1, location2); if (location1 == null) { return location2; } else if (location2 == null) { return location1; } else { // Figure out which IndexOnLine and EndIndexOnLine to use. int indexOnLine; int endIndexOnLine; if (location1.StartPoint.LineNumber == location2.StartPoint.LineNumber) { indexOnLine = Math.Min(location1.StartPoint.IndexOnLine, location2.StartPoint.IndexOnLine); endIndexOnLine = Math.Max(location1.EndPoint.IndexOnLine, location2.EndPoint.IndexOnLine); } else if (location1.StartPoint.LineNumber < location2.StartPoint.LineNumber) { indexOnLine = location1.StartPoint.IndexOnLine; endIndexOnLine = location2.EndPoint.IndexOnLine; } else { indexOnLine = location2.StartPoint.IndexOnLine; endIndexOnLine = location1.EndPoint.IndexOnLine; } return new CodeLocation( Math.Min(location1.StartPoint.Index, location2.StartPoint.Index), Math.Max(location1.EndPoint.Index, location2.EndPoint.Index), indexOnLine, endIndexOnLine, Math.Min(location1.StartPoint.LineNumber, location2.StartPoint.LineNumber), Math.Max(location2.EndPoint.LineNumber, location2.EndPoint.LineNumber)); } }
private Symbol GetNewLine() { Symbol symbol = null; char ch = this.codeReader.Peek(); if (ch != '\0') { this.codeReader.ReadNext(); int index = this.marker.Index; int endIndex = this.marker.Index; if ((ch == '\r') && (this.codeReader.Peek() == '\n')) { this.codeReader.ReadNext(); this.marker.Index++; endIndex++; } CodeLocation location = new CodeLocation(index, endIndex, this.marker.IndexOnLine, this.marker.IndexOnLine + (endIndex - index), this.marker.LineNumber, this.marker.LineNumber); symbol = new Symbol("\n", SymbolType.EndOfLine, location); this.marker.Index++; this.marker.LineNumber++; this.marker.IndexOnLine = 0; } return symbol; }
private Symbol GetLiteralString(StringBuilder text) { char ch2; int index = this.marker.Index; int endIndex = this.marker.Index; int indexOnLine = this.marker.IndexOnLine; int endIndexOnLine = this.marker.IndexOnLine; int lineNumber = this.marker.LineNumber; int endLineNumber = this.marker.LineNumber; char ch = this.codeReader.Peek(); text.Append(ch); this.codeReader.ReadNext(); endIndex += 2; endIndexOnLine += 2; Label_0074: ch2 = this.codeReader.Peek(); if (ch2 == '\0') { goto Label_0152; } if (ch2 == ch) { this.codeReader.ReadNext(); text.Append(ch2); endIndex++; endIndexOnLine++; ch2 = this.codeReader.Peek(); if (ch2 != ch) { goto Label_0152; } this.codeReader.ReadNext(); text.Append(ch2); endIndex++; endIndexOnLine++; } else { if ((ch2 == '\r') || (ch2 == '\n')) { if (ch == '\'') { throw new SyntaxException(this.source, this.marker.LineNumber); } switch (ch2) { case '\n': endLineNumber++; endIndexOnLine = -1; break; case '\r': this.codeReader.ReadNext(); goto Label_0074; } } this.codeReader.ReadNext(); text.Append(ch2); endIndex++; endIndexOnLine++; } goto Label_0074; Label_0152: if ((text.Length <= 2) || (text[text.Length - 1] != ch)) { throw new SyntaxException(this.source, this.marker.LineNumber); } CodeLocation location = new CodeLocation(index, endIndex, indexOnLine, endIndexOnLine, lineNumber, endLineNumber); Symbol symbol = new Symbol(text.ToString(), SymbolType.String, location); this.marker.Index = endIndex + 1; this.marker.IndexOnLine = endIndexOnLine + 1; this.marker.LineNumber = endLineNumber; return symbol; }
internal Preprocessor(string text, CodeLocation location, bool generated) : this(text, CsTokenClass.PreprocessorDirective, location, generated) { }
internal Bracket(string text, CsTokenType tokenType, CodeLocation location, bool generated) : base(text, tokenType, CsTokenClass.Bracket, location, generated) { }
internal OperatorSymbol(string text, OperatorCategory category, OperatorType symbolType, CodeLocation location, bool generated) : base(text, CsTokenType.OperatorSymbol, CsTokenClass.OperatorSymbol, location, generated) { this.category = category; this.symbolType = symbolType; }
public Token(string text, CodeLocation location, bool generated) : this(location, generated) { Param.RequireNotNull(text, "text"); this.text = text; }
private Symbol GetXmlHeaderLine(StringBuilder text) { this.AdvanceToEndOfLine(text); CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + text.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + text.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol symbol = new Symbol(text.ToString(), SymbolType.XmlHeaderLine, location); this.marker.Index += text.Length; this.marker.IndexOnLine += text.Length; return symbol; }
internal ConditionalCompilationDirective(string text, Microsoft.StyleCop.CSharp.ConditionalCompilationDirectiveType type, Expression body, CodeLocation location, bool generated) : base(text, CsTokenClass.ConditionalCompilationDirective, location, generated) { this.type = type; this.body = body; }
private Symbol GetLiteralKeyword(StringBuilder text) { this.ReadToEndOfOtherSymbol(text); if (text.Length == 1) { throw new SyntaxException(this.source, this.marker.LineNumber); } CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + text.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + text.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol symbol = new Symbol(text.ToString(), SymbolType.Other, location); this.marker.Index += text.Length; this.marker.IndexOnLine += text.Length; return symbol; }
internal XmlHeader(MasterList<CsToken> childTokens, CodeLocation location, bool generated) : base(CsTokenType.XmlHeader, CsTokenClass.XmlHeader, location, generated) { this.childTokens = childTokens; }
private Symbol GetMultiLineComment(StringBuilder text) { int index = this.marker.Index; int endIndex = this.marker.Index + 1; int indexOnLine = this.marker.IndexOnLine; int endIndexOnLine = this.marker.IndexOnLine + 1; int lineNumber = this.marker.LineNumber; int endLineNumber = this.marker.LineNumber; bool flag = false; bool flag2 = false; while (true) { char ch = this.codeReader.Peek(); if (ch == '\0') { break; } text.Append(this.codeReader.ReadNext()); if (flag && (ch == '/')) { break; } if (ch == '*') { if (flag2) { flag = true; } else { flag2 = true; } } else { flag = false; if (ch == '\n') { endLineNumber++; endIndexOnLine = -1; } else if ((ch == '\r') && (this.codeReader.Peek() != '\n')) { endLineNumber++; endIndexOnLine = -1; } } endIndex++; endIndexOnLine++; } CodeLocation location = new CodeLocation(index, endIndex, indexOnLine, endIndexOnLine, lineNumber, endLineNumber); Symbol symbol = new Symbol(text.ToString(), SymbolType.MultiLineComment, location); this.marker.Index = endIndex + 1; this.marker.IndexOnLine = endIndexOnLine + 1; this.marker.LineNumber = endLineNumber; return symbol; }
private Symbol GetOperatorSymbol(char character) { SymbolType other = SymbolType.Other; StringBuilder builder = new StringBuilder(); if (character == '.') { builder.Append("."); other = SymbolType.Dot; this.codeReader.ReadNext(); } else if (character == '~') { builder.Append("~"); other = SymbolType.Tilde; this.codeReader.ReadNext(); } else if (character == '+') { builder.Append("+"); other = SymbolType.Plus; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '+') { builder.Append("+"); other = SymbolType.Increment; this.codeReader.ReadNext(); } else if (character == '=') { builder.Append("="); other = SymbolType.PlusEquals; this.codeReader.ReadNext(); } } else if (character == '-') { builder.Append("-"); other = SymbolType.Minus; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '-') { builder.Append("-"); other = SymbolType.Decrement; this.codeReader.ReadNext(); } else if (character == '=') { builder.Append("="); other = SymbolType.MinusEquals; this.codeReader.ReadNext(); } else if (character == '>') { builder.Append(">"); other = SymbolType.Pointer; this.codeReader.ReadNext(); } } else if (character == '*') { builder.Append("*"); other = SymbolType.Multiplication; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("*"); other = SymbolType.MultiplicationEquals; this.codeReader.ReadNext(); } } else if (character == '/') { builder.Append("/"); other = SymbolType.Division; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.DivisionEquals; this.codeReader.ReadNext(); } } else if (character == '|') { builder.Append("|"); other = SymbolType.LogicalOr; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.OrEquals; this.codeReader.ReadNext(); } else if (character == '|') { builder.Append("|"); other = SymbolType.ConditionalOr; this.codeReader.ReadNext(); } } else if (character == '&') { builder.Append("&"); other = SymbolType.LogicalAnd; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.AndEquals; this.codeReader.ReadNext(); } else if (character == '&') { builder.Append("&"); other = SymbolType.ConditionalAnd; this.codeReader.ReadNext(); } } else if (character == '^') { builder.Append("^"); other = SymbolType.LogicalXor; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.XorEquals; this.codeReader.ReadNext(); } } else if (character == '!') { builder.Append("!"); other = SymbolType.Not; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.NotEquals; this.codeReader.ReadNext(); } } else if (character == '%') { builder.Append("%"); other = SymbolType.Mod; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.ModEquals; this.codeReader.ReadNext(); } } else if (character == '=') { builder.Append("="); other = SymbolType.Equals; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.ConditionalEquals; this.codeReader.ReadNext(); } else if (character == '>') { builder.Append(">"); other = SymbolType.Lambda; this.codeReader.ReadNext(); } } else if (character == '<') { builder.Append("<"); other = SymbolType.LessThan; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.LessThanOrEquals; this.codeReader.ReadNext(); } else if (character == '<') { builder.Append("<"); other = SymbolType.LeftShift; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.LeftShiftEquals; this.codeReader.ReadNext(); } } } else if (character == '>') { builder.Append(">"); other = SymbolType.GreaterThan; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '=') { builder.Append("="); other = SymbolType.GreaterThanOrEquals; this.codeReader.ReadNext(); } } else if (character == '?') { builder.Append("?"); other = SymbolType.QuestionMark; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == '?') { builder.Append("?"); other = SymbolType.NullCoalescingSymbol; this.codeReader.ReadNext(); } } else if (character == ':') { builder.Append(":"); other = SymbolType.Colon; this.codeReader.ReadNext(); character = this.codeReader.Peek(); if (character == ':') { builder.Append(":"); other = SymbolType.QualifiedAlias; this.codeReader.ReadNext(); } } if ((builder == null) || (builder.Length == 0)) { throw new SyntaxException(this.source, this.marker.LineNumber); } CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + builder.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + builder.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol symbol = new Symbol(builder.ToString(), other, location); this.marker.Index += builder.Length; this.marker.IndexOnLine += builder.Length; return symbol; }
private Symbol GetNumber() { int positiveNumber = -1; char ch = this.codeReader.Peek(); switch (ch) { case '-': case '+': ch = this.codeReader.Peek(1); if ((ch >= '0') && (ch <= '9')) { positiveNumber = this.GetPositiveNumber(this.marker.Index + 1); } break; default: positiveNumber = this.GetPositiveNumber(this.marker.Index); break; } Symbol symbol = null; if (positiveNumber >= this.marker.Index) { int count = (positiveNumber - this.marker.Index) + 1; string text = this.codeReader.ReadString(count); CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + count) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + count) - 1, this.marker.LineNumber, this.marker.LineNumber); symbol = new Symbol(text, SymbolType.Number, location); this.marker.Index += count; this.marker.IndexOnLine += count; } return symbol; }
private Symbol GetOtherSymbol(Microsoft.StyleCop.SourceCode sourceCode) { StringBuilder text = new StringBuilder(); this.ReadToEndOfOtherSymbol(text); if (text.Length == 0) { throw new SyntaxException(sourceCode, 1); } string str = text.ToString(); CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + text.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + text.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol symbol = new Symbol(str, GetOtherSymbolType(str), location); this.marker.Index += text.Length; this.marker.IndexOnLine += text.Length; return symbol; }
internal Number(string token, CodeLocation location, bool generated) : base(token, CsTokenType.Number, CsTokenClass.Number, location, generated) { }
private Symbol GetPreprocessorDirectiveSymbol(Microsoft.StyleCop.SourceCode sourceCode, Configuration configuration, bool evaluate) { StringBuilder text = new StringBuilder(); this.AdvanceToEndOfLine(text); if (text.Length == 1) { throw new SyntaxException(Microsoft.StyleCop.CSharp.Strings.UnexpectedEndOfFile); } CodeLocation location = new CodeLocation(this.marker.Index, (this.marker.Index + text.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + text.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol preprocessorSymbol = new Symbol(text.ToString(), SymbolType.PreprocessorDirective, location); this.marker.Index += text.Length; this.marker.IndexOnLine += text.Length; if (evaluate && (configuration != null)) { this.CheckForConditionalCompilationDirective(sourceCode, preprocessorSymbol, configuration); } return preprocessorSymbol; }
internal Region(string text, CodeLocation location, bool beginning, bool generated) : base(text, CsTokenClass.RegionDirective, location, generated) { this.beginning = beginning; }
private Symbol GetString() { CodeLocation location; StringBuilder builder = new StringBuilder(); char ch = this.codeReader.ReadNext(); builder.Append(ch); bool flag = false; while (true) { char ch2 = this.codeReader.Peek(); if ((ch2 == '\0') || ((ch2 == ch) && !flag)) { builder.Append(ch2); this.codeReader.ReadNext(); break; } if (ch2 == '\\') { flag = !flag; } else { flag = false; switch (ch2) { case '\r': case '\n': goto Label_0076; } } builder.Append(ch2); this.codeReader.ReadNext(); } Label_0076: location = new CodeLocation(this.marker.Index, (this.marker.Index + builder.Length) - 1, this.marker.IndexOnLine, (this.marker.IndexOnLine + builder.Length) - 1, this.marker.LineNumber, this.marker.LineNumber); Symbol symbol = new Symbol(builder.ToString(), SymbolType.String, location); this.marker.Index += builder.Length; this.marker.IndexOnLine += builder.Length; return symbol; }
internal Symbol(string text, Microsoft.StyleCop.CSharp.SymbolType symbolType, CodeLocation location) { this.text = text; this.symbolType = symbolType; this.location = location; }
internal TypeToken(MasterList<CsToken> childTokens, CodeLocation location, CsTokenClass tokenClass, bool generated) : base(CsTokenType.Other, tokenClass, location, generated) { this.childTokens = childTokens; }