Exemple #1
0
        private bool VisitArrayTypeName(ArrayTypeName arrayTypeName)
        {
            bool resolved = DispatchTypeName(arrayTypeName.ElementType, genericArgumentCount: 0, isAttribute: false);

            if (resolved)
            {
                var resolvedType = arrayTypeName.GetReflectionType();
                TypeCache.Add(arrayTypeName, _typeResolutionState, resolvedType);
            }

            return(resolved);
        }
Exemple #2
0
 private ITypeName CompleteArrayTypeName(ITypeName elementType, TypeName typeForAssemblyQualification, Token firstTokenAfterLBracket)
 {
     Token token;
     Token token1;
     while (true)
     {
         TokenKind kind = firstTokenAfterLBracket.Kind;
         if (kind == TokenKind.EndOfInput)
         {
             this.UngetToken(firstTokenAfterLBracket);
             this.ReportError(Parser.Before(firstTokenAfterLBracket), ParserStrings.EndSquareBracketExpectedAtEndOfAttribute, new object[0]);
         }
         else
         {
             if (kind == TokenKind.RBracket)
             {
                 elementType = new ArrayTypeName(Parser.ExtentOf(elementType.Extent, firstTokenAfterLBracket.Extent), elementType, 1);
             }
             else
             {
                 if (kind != TokenKind.Comma)
                 {
                     object[] text = new object[1];
                     text[0] = firstTokenAfterLBracket.Text;
                     this.ReportError(firstTokenAfterLBracket.Extent, ParserStrings.UnexpectedToken, text);
                     TokenKind[] tokenKindArray = new TokenKind[1];
                     tokenKindArray[0] = TokenKind.RBracket;
                     this.SyncOnError(tokenKindArray);
                 }
                 else
                 {
                     int num = 1;
                     token = firstTokenAfterLBracket;
                     do
                     {
                         token1 = token;
                         num++;
                         token = this.NextToken();
                     }
                     while (token.Kind == TokenKind.Comma);
                     if (token.Kind != TokenKind.RBracket)
                     {
                         this.UngetToken(token);
                         this.ReportError(Parser.After(token1), ParserStrings.EndSquareBracketExpectedAtEndOfAttribute, new object[0]);
                     }
                     elementType = new ArrayTypeName(Parser.ExtentOf(elementType.Extent, token.Extent), elementType, num);
                 }
             }
         }
         token = this.PeekToken();
         if (token.Kind != TokenKind.Comma)
         {
             if (token.Kind != TokenKind.LBracket)
             {
                 break;
             }
             this.SkipToken();
             firstTokenAfterLBracket = this.NextToken();
         }
         else
         {
             this.SkipToken();
             string assemblyNameSpec = this._tokenizer.GetAssemblyNameSpec();
             if (!string.IsNullOrEmpty(assemblyNameSpec))
             {
                 typeForAssemblyQualification.AssemblyName = assemblyNameSpec;
                 break;
             }
             else
             {
                 this.ReportError(Parser.After(token), ParserStrings.MissingAssemblyNameSpecification, new object[0]);
                 break;
             }
         }
     }
     return elementType;
 }
Exemple #3
0
        private bool VisitArrayTypeName(ArrayTypeName arrayTypeName)
        {
            bool resolved = DispatchTypeName(arrayTypeName.ElementType, genericArgumentCount: 0, isAttribute: false);
            if (resolved)
            {
                var resolvedType = arrayTypeName.GetReflectionType();
                TypeCache.Add(arrayTypeName, _typeResolutionState, resolvedType);
            }

            return resolved;
        }
Exemple #4
0
        private ITypeName CompleteArrayTypeName(ITypeName elementType, TypeName typeForAssemblyQualification, Token firstTokenAfterLBracket)
        {
            while (true)
            {
                Token token;
                switch (firstTokenAfterLBracket.Kind)
                {
                    case TokenKind.Comma:
                        int dim = 1;
                        token = firstTokenAfterLBracket;
                        Token lastComma;
                        do
                        {
                            lastComma = token;
                            dim += 1;
                            token = NextToken();
                        } while (token.Kind == TokenKind.Comma);

                        if (token.Kind != TokenKind.RBracket)
                        {
                            // ErrorRecovery: just pretend we saw a ']'.

                            UngetToken(token);
                            ReportError(After(lastComma), () => ParserStrings.EndSquareBracketExpectedAtEndOfAttribute);
                        }

                        elementType = new ArrayTypeName(ExtentOf(elementType.Extent, token.Extent), elementType, dim);
                        break;

                    case TokenKind.RBracket:
                        elementType = new ArrayTypeName(ExtentOf(elementType.Extent, firstTokenAfterLBracket.Extent), elementType, 1);
                        break;

                    case TokenKind.EndOfInput:
                        UngetToken(firstTokenAfterLBracket);
                        ReportError(Before(firstTokenAfterLBracket), () => ParserStrings.EndSquareBracketExpectedAtEndOfAttribute);
                        break;

                    default:
                        // ErrorRecovery: sync to ']', and return null to avoid cascading errors.

                        ReportError(firstTokenAfterLBracket.Extent, () => ParserStrings.UnexpectedToken, firstTokenAfterLBracket.Text);
                        SyncOnError(true, TokenKind.RBracket);
                        break;
                }

                token = PeekToken();
                if (token.Kind == TokenKind.Comma)
                {
                    SkipToken();
                    var assemblyName = _tokenizer.GetAssemblyNameSpec();
                    if (string.IsNullOrEmpty(assemblyName))
                    {
                        ReportError(After(token), () => ParserStrings.MissingAssemblyNameSpecification);
                    }
                    else
                    {
                        typeForAssemblyQualification.AssemblyName = assemblyName;
                    }
                    break;
                }

                if (token.Kind != TokenKind.LBracket)
                {
                    break;
                }

                // Jagged array, skip the '[' and keep parsing.
                SkipToken();
                firstTokenAfterLBracket = NextToken();
            }

            return elementType;
        }