Esempio n. 1
0
        private Expression ProcessTypeofNode(TypeofNode node) {
            TypeSymbol referencedType = _symbolSet.ResolveType(node.TypeReference, _symbolTable, _symbolContext);
            Debug.Assert(referencedType != null);

            if (String.IsNullOrEmpty(referencedType.DependencyName) == false) {
                _options.AddExecutionDependency(referencedType.DependencyName);
            }

            TypeSymbol typeSymbol = _symbolSet.ResolveIntrinsicType(IntrinsicType.Type);
            Debug.Assert(typeSymbol != null);

            return new LiteralExpression(typeSymbol, referencedType);
        }
Esempio n. 2
0
        private ParseNode ParsePrimaryExpression() {
            ParseNode expr;
            switch (PeekType()) {
                case TokenType.Null:
                case TokenType.True:
                case TokenType.False:
                case TokenType.Literal:
                    expr = new LiteralNode(NextToken());
                    break;

                case TokenType.OpenParen:
                    Eat(TokenType.OpenParen);
                    expr = ParseExpression();
                    if (expr is ExpressionNode) {
                        ((ExpressionNode)expr).AddParenthesisHint();
                    }
                    Eat(TokenType.CloseParen);
                    break;

                case TokenType.New:
                    expr = ParseNew();
                    break;

                case TokenType.Typeof: {
                        Token token = NextToken();
                        Eat(TokenType.OpenParen);
                        expr = new TypeofNode(token, ParseReturnType());
                        Eat(TokenType.CloseParen);
                        break;
                    }

                case TokenType.Sizeof: {
                        Token token = NextToken();
                        Eat(TokenType.OpenParen);
                        expr = new SizeofNode(token, ParseType());
                        Eat(TokenType.CloseParen);
                        break;
                    }

                case TokenType.Checked:
                case TokenType.Unchecked: {
                        Token token = NextToken();
                        Eat(TokenType.OpenParen);
                        expr = new UnaryExpressionNode(token, ParseExpression());
                        Eat(TokenType.CloseParen);
                        break;
                    }

                case TokenType.This:
                    expr = new ThisNode(NextToken());
                    break;

                case TokenType.Base:
                    expr = new BaseNode(NextToken());
                    if (PeekType() != TokenType.Dot && PeekType() != TokenType.OpenSquare) {
                        this.ReportError(ParseError.BadBaseExpression);
                    }
                    break;

                case TokenType.Identifier:
                    expr = ParseAliasQualifiedName(true);
                    break;

                case TokenType.Delegate:
                    expr = ParseAnonymousMethod();
                    break;

                default:
                    if (Token.IsPredefinedType(PeekType()) && PeekType() != TokenType.Void) {
                        expr = ParsePredefinedType();
                        CheckType(TokenType.Dot);
                    }
                    else {
                        ReportError(ParseError.ExpressionExpected);
                        expr = ParseIdentifier();
                    }
                    break;
            }

            // postfix operators
            bool foundPostfix = true;
            do {
                Token token = PeekToken();
                switch (PeekType()) {
                    case TokenType.Dot:
                        if (PeekType(1) == TokenType.Default) {
                            expr = new DefaultValueNode(expr);
                            Eat(TokenType.Dot);
                            Eat(TokenType.Default);
                        }
                        else
                            expr = new BinaryExpressionNode(expr, NextToken().Type, ParseSimpleName(true));
                        break;

                    case TokenType.OpenParen:
                        expr = new BinaryExpressionNode(expr, token.Type, ParseParenArgumentList());
                        break;

                    case TokenType.PlusPlus:
                    case TokenType.MinusMinus:
                        expr = new BinaryExpressionNode(expr, NextToken().Type, null);
                        break;

                    case TokenType.OpenSquare:
                        expr = new BinaryExpressionNode(expr, NextToken().Type, ParseExpressionList(TokenType.CloseSquare));
                        Eat(TokenType.CloseSquare);
                        break;

                    case TokenType.Arrow:
                        expr = new BinaryExpressionNode(expr, NextToken().Type, ParseIdentifier());
                        break;

                    default:
                        foundPostfix = false;
                        break;
                }
            } while (foundPostfix);

            return expr;
        }