Esempio n. 1
0
        //
        // Parses a type name without any assembly name qualification.
        //
        private NonQualifiedTypeName ParseNonQualifiedTypeName()
        {
            // Parse the named type or constructed generic type part first.
            NonQualifiedTypeName typeName = ParseNamedOrConstructedGenericTypeName();

            // Iterate through any "has-element" qualifiers ([], &, *).
            for (;;)
            {
                TokenType token = _lexer.Peek;
                if (token == TokenType.End)
                    break;
                if (token == TokenType.Asterisk)
                {
                    _lexer.Skip();
                    typeName = new PointerTypeName(typeName);
                }
                else if (token == TokenType.Ampersand)
                {
                    _lexer.Skip();
                    typeName = new ByRefTypeName(typeName);
                }
                else if (token == TokenType.OpenSqBracket)
                {
                    _lexer.Skip();
                    token = _lexer.GetNextToken();
                    if (token == TokenType.Asterisk)
                    {
                        typeName = new MultiDimArrayTypeName(typeName, 1);
                        token = _lexer.GetNextToken();
                    }
                    else
                    {
                        int rank = 1;
                        while (token == TokenType.Comma)
                        {
                            token = _lexer.GetNextToken();
                            rank++;
                        }
                        if (rank == 1)
                            typeName = new ArrayTypeName(typeName);
                        else
                            typeName = new MultiDimArrayTypeName(typeName, rank);
                    }
                    if (token != TokenType.CloseSqBracket)
                        throw new ArgumentException();
                }
                else
                {
                    break;
                }
            }
            return typeName;
        }
        //
        // Parses a type name without any assembly name qualification.
        //
        private NonQualifiedTypeName ParseNonQualifiedTypeName()
        {
            // Parse the named type or constructed generic type part first.
            NonQualifiedTypeName typeName = ParseNamedOrConstructedGenericTypeName();

            // Iterate through any "has-element" qualifiers ([], &, *).
            for (;;)
            {
                TokenType token = _lexer.Peek;
                if (token == TokenType.End)
                {
                    break;
                }
                if (token == TokenType.Asterisk)
                {
                    _lexer.Skip();
                    typeName = new PointerTypeName(typeName);
                }
                else if (token == TokenType.Ampersand)
                {
                    _lexer.Skip();
                    typeName = new ByRefTypeName(typeName);
                }
                else if (token == TokenType.OpenSqBracket)
                {
                    _lexer.Skip();
                    token = _lexer.GetNextToken();
                    if (token == TokenType.Asterisk)
                    {
                        typeName = new MultiDimArrayTypeName(typeName, 1);
                        token    = _lexer.GetNextToken();
                    }
                    else
                    {
                        int rank = 1;
                        while (token == TokenType.Comma)
                        {
                            token = _lexer.GetNextToken();
                            rank++;
                        }
                        if (rank == 1)
                        {
                            typeName = new ArrayTypeName(typeName);
                        }
                        else
                        {
                            typeName = new MultiDimArrayTypeName(typeName, rank);
                        }
                    }
                    if (token != TokenType.CloseSqBracket)
                    {
                        throw new ArgumentException();
                    }
                }
                else
                {
                    break;
                }
            }
            return(typeName);
        }