예제 #1
0
파일: Typer.cs 프로젝트: Daouki/wire
        public IType VisitSubscriptExpression(SubscriptExpression subscriptExpression)
        {
            var maybeArrayType = GetExpressionType(subscriptExpression.Operand);

            if (maybeArrayType is ArrayType arrayType)
            {
                return(arrayType.UnderlyingType);
            }
            return(null);
        }
예제 #2
0
 public override void Visit(SubscriptExpression exp)
 {
     exp.AddressExp.AcceptVisitor(this);
     foreach (var index in exp.Indices)
     {
         cb.Write('[');
         index.AcceptVisitor(this);
         cb.Write(']');
     }
 }
예제 #3
0
        public virtual void Visit(SubscriptExpression exp)
        {
            exp.AddressExp.AcceptVisitor(this);

            if (exp.Indices != null)
            {
                foreach (var index in exp.Indices)
                {
                    index.AcceptVisitor(this);
                }
            }
        }
예제 #4
0
        public bool VisitSubscriptExpression(SubscriptExpression subscriptExpression)
        {
            if (!IsExpressionValid(subscriptExpression.Operand) ||
                !IsExpressionValid(subscriptExpression.Index))
            {
                return(false);
            }

            var operandType = Typer.GetExpressionType(
                _context,
                _environment,
                subscriptExpression.Operand);

            if (operandType == null)
            {
                return(false);
            }
            if (!(operandType is ArrayType))
            {
                _context.Error(
                    subscriptExpression.Span,
                    $"cannot index into a non-array type \"{operandType}\"");
                return(false);
            }

            var indexType = Typer.GetExpressionType(
                _context,
                _environment,
                subscriptExpression.Index);

            if (indexType == null)
            {
                return(false);
            }
            if (!(indexType is IntegerType))
            {
                _context.Error(
                    subscriptExpression.Span,
                    $"type \"{operandType}\" cannot be indexed by type \"{indexType}\"");
                return(false);
            }

            return(true);
        }