示例#1
0
        /// <summary>
        /// Helper to Deeply clone values
        /// </summary>
        public static EvaluationResult DeepCloneValue(EvaluationResult value)
        {
            if (value.IsErrorValue)
            {
                return(EvaluationResult.Error);
            }

            if (value.IsUndefined)
            {
                return(value); // Undefined is structurally compared
            }

            switch (value.Value)
            {
            case bool boolean:
            case string str:
            case int number:
            case EnumValue enumValue:
            case PathAtom pathAtomValue:
            case RelativePath relPathValue:
            case AbsolutePath pathValue:
            case FileArtifact fileValue:
            case DirectoryArtifact dirValue:
            case StaticDirectory staticDirValue:
                return(value);    // Intrinsics are structurally compared

            case OrderedMap map:
                return(new EvaluationResult(DeepCloneMap(map)));

            case OrderedSet set:
                return(new EvaluationResult(DeepCloneSet(set)));

            case ArrayLiteral array:
                return(new EvaluationResult(DeepCloneArray(array)));

            case ObjectLiteral obj:
                return(new EvaluationResult(DeepCloneObject(obj)));

            case Closure closure:
                var typeOfKind = RuntimeTypeIdExtensions.ComputeTypeOfKind(value.Value);
                throw new UnsupportedTypeValueObjectException(typeOfKind.ToRuntimeString(), new ErrorContext(pos: 1));

            default:
                throw Contract.AssertFailure("Unexpected runtime value");
            }
        }
示例#2
0
        private static string EvalTypeOf(object value)
        {
            var typeOfKind = RuntimeTypeIdExtensions.ComputeTypeOfKind(value);

            return(typeOfKind.ToRuntimeString());
        }
示例#3
0
        /// <summary>
        /// Attempt to hash the runtime value.
        /// </summary>
        public static bool TryHashValue(EvaluationResult value, HashingHelper helper)
        {
            if (value.IsErrorValue)
            {
                return(false);
            }

            // Always mark the kind
            var valueKind = RuntimeTypeIdExtensions.ComputeTypeOfKind(value.Value);

            helper.Add((byte)valueKind);

            if (value.IsUndefined)
            {
                return(true);
            }

            switch (value.Value)
            {
            case bool boolean:
                helper.Add(boolean ? 1 : 0);
                return(true);

            case string str:
                helper.Add(str);
                return(true);

            case int number:
                helper.Add(number);
                return(true);

            case EnumValue enumValue:
                helper.Add(enumValue.Value);
                helper.Add(enumValue.Name.StringId);
                return(true);

            case OrderedMap map:
                return(TryHashMap(map, helper));

            case OrderedSet set:
                return(TryHashSet(set, helper));

            case ArrayLiteral array:
                return(TryHashArray(array, helper));

            case ObjectLiteral obj:
                return(TryHashObject(obj, helper));

            case PathAtom pathAtomValue:
                helper.Add(pathAtomValue.StringId);
                return(true);

            case RelativePath relPathValue:
                return(TryHashRelativePath(relPathValue, helper));

            case AbsolutePath pathValue:
                helper.Add(pathValue);
                return(true);

            case FileArtifact fileValue:
                helper.Add(fileValue);
                return(true);

            case DirectoryArtifact dirValue:
                return(TryHashDirectoryArtifact(dirValue, helper));

            case StaticDirectory staticDirValue:
                return(TryHashStaticDirectoryArtifact(staticDirValue, helper));

            case Closure closure:
                var typeOfKind = RuntimeTypeIdExtensions.ComputeTypeOfKind(value.Value);
                throw new UnsupportedTypeValueObjectException(typeOfKind.ToRuntimeString(), new ErrorContext(pos: 1));

            default:
                throw Contract.AssertFailure("Unexpected runtime value");
            }
        }