/// <summary> /// Gets the base name and generic symbols for a type token. /// </summary> /// <param name="typeTokenReference">A reference to the type token.</param> /// <param name="typeTokens">The list of tokens in the type.</param> /// <param name="startIndex">The start index within the symbol list.</param> /// <param name="generic">Returns a value indicating whether the type is generic.</param> /// <param name="unsafeCode">Indicates whether the type is within a block of unsafe code.</param> private void GetTypeTokenBaseName( Reference<ICodePart> typeTokenReference, ref MasterList<CsToken> typeTokens, ref int startIndex, out GenericType generic, bool unsafeCode) { Param.AssertNotNull(typeTokenReference, "typeTokenReference"); Param.AssertNotNull(typeTokens, "typeTokens"); Param.AssertGreaterThanOrEqualToZero(startIndex, "startIndex"); Param.Ignore(unsafeCode); generic = null; Symbol symbol = this.symbols.Peek(startIndex); // First get the full name of the type. int index = -1; while (true) { // Add any whitespace. while (symbol != null && (symbol.SymbolType == SymbolType.WhiteSpace || symbol.SymbolType == SymbolType.EndOfLine || symbol.SymbolType == SymbolType.SingleLineComment || symbol.SymbolType == SymbolType.MultiLineComment || symbol.SymbolType == SymbolType.PreprocessorDirective)) { typeTokens.Add(this.ConvertSymbol(symbol, TokenTypeFromSymbolType(symbol.SymbolType), typeTokenReference)); symbol = this.symbols.Peek(++startIndex); } // Add the next word. The type of the next word must either be an unknown // word type, which will be the name of the next item in the type, or else // it must be the 'this' keyword. This is used when implementing an explicit // interface member which is an indexer. if (symbol.SymbolType == SymbolType.Other || symbol.SymbolType == SymbolType.This) { typeTokens.Add(new CsToken(symbol.Text, CsTokenType.Other, symbol.Location, typeTokenReference, this.symbols.Generated)); } else { throw new SyntaxException(this.document.SourceCode, symbol.LineNumber); } ++startIndex; // Look at the type of the next non-whitespace character. index = this.GetNextCodeSymbolIndex(startIndex); if (index == -1) { break; } // If the next character is an opening generic bracket, get the generic. symbol = this.symbols.Peek(index); if (symbol.SymbolType == SymbolType.LessThan) { int end; MasterList<CsToken> genericTypeTokens = this.GetGenericArgumentList( typeTokenReference, unsafeCode, null, startIndex, out end); if (genericTypeTokens != null) { // Add the tokens from this generic into our token list. typeTokens.AddRange(genericTypeTokens); // Create a new GenericTypeToken which represents this generic type. CodeLocation genericTypeLocation = CsToken.JoinLocations(typeTokens.First, typeTokens.Last); generic = new GenericType(typeTokens, genericTypeLocation, typeTokenReference, this.symbols.Generated); Reference<ICodePart> genericReference = new Reference<ICodePart>(generic); foreach (CsToken token in typeTokens) { token.ParentRef = genericReference; } // Reset the token list and add this generic token as the first item in the list. typeTokens = new MasterList<CsToken>(); typeTokens.Add(generic); // Advance the symbol index. startIndex = end + 1; // Look at the type of the next non-whitespace character. index = this.GetNextCodeSymbolIndex(startIndex); if (index == -1) { break; } } } // If the next character is not a dot or a qualified alias, break now. symbol = this.symbols.Peek(index); if (symbol.SymbolType != SymbolType.Dot && symbol.SymbolType != SymbolType.QualifiedAlias) { break; } // Add any whitspace. symbol = this.symbols.Peek(startIndex); while (symbol != null && (symbol.SymbolType == SymbolType.WhiteSpace || symbol.SymbolType == SymbolType.EndOfLine || symbol.SymbolType == SymbolType.SingleLineComment || symbol.SymbolType == SymbolType.MultiLineComment || symbol.SymbolType == SymbolType.PreprocessorDirective)) { typeTokens.Add(this.ConvertSymbol(symbol, TokenTypeFromSymbolType(symbol.SymbolType), typeTokenReference)); symbol = this.symbols.Peek(++startIndex); } // Add the dot or qualified alias. if (symbol.SymbolType == SymbolType.Dot) { typeTokens.Add(new OperatorSymbol( symbol.Text, OperatorCategory.Reference, OperatorType.MemberAccess, symbol.Location, typeTokenReference, this.symbols.Generated)); } else { Debug.Assert(symbol.SymbolType == SymbolType.QualifiedAlias, "Expected a qualified alias keyword"); typeTokens.Add(new OperatorSymbol( symbol.Text, OperatorCategory.Reference, OperatorType.QualifiedAlias, symbol.Location, typeTokenReference, this.symbols.Generated)); } // Get the next symbol. symbol = this.symbols.Peek(++startIndex); } }
private void GetTypeTokenBaseName(ref MasterList<CsToken> typeTokens, ref int startIndex, out GenericType generic, bool unsafeCode) { generic = null; Symbol symbol = this.symbols.Peek(startIndex); int count = -1; Label_0045: while ((symbol != null) && ((((symbol.SymbolType == SymbolType.WhiteSpace) || (symbol.SymbolType == SymbolType.EndOfLine)) || ((symbol.SymbolType == SymbolType.SingleLineComment) || (symbol.SymbolType == SymbolType.MultiLineComment))) || (symbol.SymbolType == SymbolType.PreprocessorDirective))) { int num3; typeTokens.Add(this.ConvertSymbol(symbol, TokenTypeFromSymbolType(symbol.SymbolType))); startIndex = num3 = startIndex + 1; symbol = this.symbols.Peek(num3); } if ((symbol.SymbolType != SymbolType.Other) && (symbol.SymbolType != SymbolType.This)) { throw new SyntaxException(this.document.SourceCode, symbol.LineNumber); } typeTokens.Add(new CsToken(symbol.Text, CsTokenType.Other, symbol.Location, this.symbols.Generated)); startIndex++; count = this.GetNextCodeSymbolIndex(startIndex); if (count != -1) { if (this.symbols.Peek(count).SymbolType == SymbolType.LessThan) { int num2; MasterList<CsToken> items = this.GetGenericArgumentList(unsafeCode, null, startIndex, out num2); if (items != null) { typeTokens.AddRange(items); CodeLocation location = CodeLocation.Join<CsToken>(typeTokens.First, typeTokens.Last); generic = new GenericType(typeTokens, location, this.symbols.Generated); typeTokens = new MasterList<CsToken>(); typeTokens.Add(generic); startIndex = num2 + 1; count = this.GetNextCodeSymbolIndex(startIndex); if (count == -1) { return; } } } symbol = this.symbols.Peek(count); if ((symbol.SymbolType == SymbolType.Dot) || (symbol.SymbolType == SymbolType.QualifiedAlias)) { int num5; symbol = this.symbols.Peek(startIndex); while ((symbol != null) && ((((symbol.SymbolType == SymbolType.WhiteSpace) || (symbol.SymbolType == SymbolType.EndOfLine)) || ((symbol.SymbolType == SymbolType.SingleLineComment) || (symbol.SymbolType == SymbolType.MultiLineComment))) || (symbol.SymbolType == SymbolType.PreprocessorDirective))) { int num4; typeTokens.Add(this.ConvertSymbol(symbol, TokenTypeFromSymbolType(symbol.SymbolType))); startIndex = num4 = startIndex + 1; symbol = this.symbols.Peek(num4); } if (symbol.SymbolType == SymbolType.Dot) { typeTokens.Add(new OperatorSymbol(symbol.Text, OperatorCategory.Reference, OperatorType.MemberAccess, symbol.Location, this.symbols.Generated)); } else { typeTokens.Add(new OperatorSymbol(symbol.Text, OperatorCategory.Reference, OperatorType.QualifiedAlias, symbol.Location, this.symbols.Generated)); } startIndex = num5 = startIndex + 1; symbol = this.symbols.Peek(num5); goto Label_0045; } } }