Beispiel #1
0
 private void Visit(MemberAccessExpr expr)
 {
     Visit((dynamic)expr.AccessedExpr);
     if (expr.MemberId.Equals("size"))
     {
         CurrentMethodIL.Emit(OpCodes.Ldlen);
         ApplyExprSign(expr);
     }
 }
Beispiel #2
0
        private Expression ParseFactor()
        {
            Expression factor;

            if (CurrentToken.Type == TokenType.Identifier)
            {
                factor = ParseCallOrVarExpr();
            }
            else if (Accept(TokenType.IntLiteral))
            {
                factor = new IntLiteralExpr(AcceptedToken);
            }
            else if (Accept(TokenType.StringLiteral))
            {
                factor = new StringLiteralExpr(AcceptedToken);
            }
            else if (Accept(TokenType.RealLiteral))
            {
                factor = new RealLiteralExpr(AcceptedToken);
            }
            else if (Accept(TokenType.LParen))
            {
                Expression expr = ParseExpression();
                Match(TokenType.RParen);
                factor = expr;
            }
            else if (Accept(TokenType.OpNot))
            {
                UnaryExpr expr = new UnaryExpr(AcceptedToken);
                expr.Op   = Operator.Not;
                expr.Expr = ParseFactor();
                factor    = expr;
            }
            else
            {
                throw new Exception(string.Format("Expected a factor, {0} found", CurrentToken.Type));
            }

            if (Accept(TokenType.OpDot))
            {
                MemberAccessExpr expr = new MemberAccessExpr(AcceptedToken);
                expr.AccessedExpr = factor;
                expr.MemberId     = ParseIdentifier();
                return(expr);
            }
            return(factor);
        }
Beispiel #3
0
        private void Visit(MemberAccessExpr memberAccessExpr)
        {
            Visit((dynamic)memberAccessExpr.AccessedExpr);
            TypeInfo accessed = TypeStack.Pop();

            if (IsNotVoid(accessed))
            {
                if (accessed.IsArray && memberAccessExpr.MemberId == "size")
                {
                    TypeStack.Push(TypeInfo.BasicInt);
                    memberAccessExpr.Type = TypeInfo.BasicInt;
                }
                else
                {
                    AddError(string.Format("{0} has no member '{1}'", accessed, memberAccessExpr.MemberId), memberAccessExpr);
                    TypeStack.Push(TypeInfo.BasicVoid);
                }
            }
        }