Example #1
0
 public void Add(ArmadaRValue rvalue)
 {
     if (rvalue != null)
     {
         crashAvoidance.Add(rvalue.UndefinedBehaviorAvoidance);
         vals.Add(rvalue.Val);
     }
     else
     {
         vals.Add(null);
     }
 }
Example #2
0
 public abstract ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type ty);
Example #3
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type ty)
        {
            var me = GetValueInLValueState(context);
            var sz = AH.MakeCardinalityExpr(me);

            var newUndefinedBehaviorAvoidance = GetUndefinedBehaviorAvoidanceConstraint() + idx1.UndefinedBehaviorAvoidance;

            var idx1val = AH.ConvertToIntIfNotInt(idx1.Val);

            if (type is SizedArrayType)
            {
                SizedArrayType st = (SizedArrayType)type;
                if (!AH.TypesMatch(st.Range, ty))
                {
                    context.Fail(i_tok, $"Element of type {st.Range} used as type {ty}");
                    return(null);
                }

                newUndefinedBehaviorAvoidance.Add(AH.MakeLeExpr(AH.MakeZero(), idx1val));
                newUndefinedBehaviorAvoidance.Add(AH.MakeLtExpr(idx1val, sz));
            }
            else if (type is SeqType)
            {
                newUndefinedBehaviorAvoidance.Add(AH.MakeLeExpr(AH.MakeZero(), idx1val));
                newUndefinedBehaviorAvoidance.Add(AH.MakeLtExpr(idx1val, sz));
            }
            else if (type is MapType)
            {
                newUndefinedBehaviorAvoidance.Add(AH.MakeInExpr(idx1val, me));
            }
            else
            {
                context.Fail(i_tok, $"Attempt to index into something that isn't an array, seq, or map");
                return(null);
            }

            return(new UnaddressableIndexArmadaLValue(i_tok, ty, this, newUndefinedBehaviorAvoidance, idx1val));
        }
Example #4
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type ty)
        {
            if (!(type is SizedArrayType))
            {
                context.Fail(i_tok, "Attempt to obtain element of non-array type");
                return(null);
            }
            SizedArrayType st = (SizedArrayType)type;

            if (!AH.TypesMatch(st.Range, ty))
            {
                context.Fail(i_tok, $"Element of type {st.Range} used as type {ty}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance + idx1.UndefinedBehaviorAvoidance;

            var s    = context.GetLValueState();
            var mem  = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var h    = AH.MakeExprDotName(mem, "heap", "Armada_Heap");
            var tree = AH.MakeExprDotName(h, "tree", "Armada_Tree");

            crashAvoidance.Add(AH.MakeInExpr(address.Val, tree));

            var node        = AH.MakeSeqSelectExpr(tree, address.Val, "Armada_Node");
            var children    = AH.MakeExprDotName(node, "children", AH.MakeChildrenType());
            var idx1_as_int = AH.ConvertToIntIfNotInt(idx1.Val);
            var field       = AH.MakeApply1("Armada_FieldArrayIndex", idx1_as_int, "Armada_Field");
            var child       = AH.MakeSeqSelectExpr(children, field, new PointerType(st.Range));

            crashAvoidance.Add(AH.MakeInExpr(field, children));

            return(new AddressableArmadaLValue(i_tok, st.Range, new ArmadaRValue(crashAvoidance, child)));
        }
Example #5
0
 public AddressableArmadaLValue(IToken i_tok, Type i_type, ArmadaRValue i_address)
     : base(i_tok, i_type)
 {
     address = i_address;
 }
Example #6
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type indexType, Type exprType)
        {
            var me = GetValueInLValueState(context);
            var sz = $"|{me}|";

            var newUndefinedBehaviorAvoidance = GetUndefinedBehaviorAvoidanceConstraint() + idx1.UndefinedBehaviorAvoidance;

            var idx1val = AH.ConvertToIntIfNotInt(idx1.Val, indexType);

            if (type is SizedArrayType)
            {
                SizedArrayType st = (SizedArrayType)type;
                if (!AH.TypesMatch(st.Range, exprType))
                {
                    context.Fail(i_tok, $"Element of type {st.Range} used as type {exprType}");
                    return(null);
                }

                newUndefinedBehaviorAvoidance.Add($"0 <= {idx1val} < {sz}");
            }
            else if (type is SeqType)
            {
                newUndefinedBehaviorAvoidance.Add($"0 <= {idx1val} < {sz}");
            }
            else if (type is MapType)
            {
                // There's no need to consider it undefined behavior if idx1.Val isn't in this map, since we're just
                // using it as an lvalue.  It's fine to update an element of a map that isn't yet in its domain.
                // So we don't need to do:
                //   newUndefinedBehaviorAvoidance.Add($"({idx1.Val}) in ({me})");
                return(new UnaddressableIndexArmadaLValue(i_tok, exprType, this, newUndefinedBehaviorAvoidance, idx1.Val));
            }
            else
            {
                context.Fail(i_tok, $"Attempt to index into something that isn't an array, seq, or map");
                return(null);
            }

            return(new UnaddressableIndexArmadaLValue(i_tok, exprType, this, newUndefinedBehaviorAvoidance, idx1val));
        }
Example #7
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type indexType, Type exprType)
        {
            if (!(type is SizedArrayType))
            {
                context.Fail(i_tok, "Attempt to obtain element of non-array type");
                return(null);
            }
            SizedArrayType st = (SizedArrayType)type;

            if (!AH.TypesMatch(st.Range, exprType))
            {
                context.Fail(i_tok, $"Element of type {st.Range} used as type {exprType}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance + idx1.UndefinedBehaviorAvoidance;

            var s           = context.GetLValueState();
            var h           = $"({s}).mem.heap";
            var idx1_as_int = AH.ConvertToIntIfNotInt(idx1.Val, indexType);

            crashAvoidance.Add($"{address.Val} in {h}.tree");
            crashAvoidance.Add($"0 <= {idx1_as_int} < |{h}.tree[{address.Val}].children|");

            var child = $"{h}.tree[{address.Val}].children[{idx1_as_int}]";

            return(new AddressableArmadaLValue(i_tok, st.Range, new ArmadaRValue(crashAvoidance, child)));
        }