public IType VisitSubscriptExpression(SubscriptExpression subscriptExpression) { var maybeArrayType = GetExpressionType(subscriptExpression.Operand); if (maybeArrayType is ArrayType arrayType) { return(arrayType.UnderlyingType); } return(null); }
public override void Visit(SubscriptExpression exp) { exp.AddressExp.AcceptVisitor(this); foreach (var index in exp.Indices) { cb.Write('['); index.AcceptVisitor(this); cb.Write(']'); } }
public virtual void Visit(SubscriptExpression exp) { exp.AddressExp.AcceptVisitor(this); if (exp.Indices != null) { foreach (var index in exp.Indices) { index.AcceptVisitor(this); } } }
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); }