Esempio n. 1
0
        /// <summary>Verifies the attribute is valid for a <see cref="Value"/> on a given <see cref="FunctionAttributeIndex"/></summary>
        /// <param name="index">Index to verify</param>
        /// <param name="value">Value to check this attribute on</param>
        /// <exception cref="ArgumentException">The attribute is not valid on <paramref name="value"/> for the <paramref name="index"/></exception>
        public void VerifyValidOn(FunctionAttributeIndex index, Value value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            // TODO: Attributes on globals??
            if (!(value.IsCallSite || value.IsFunction))
            {
                throw new ArgumentException("Attributes only allowed on functions and call sites");
            }

            // for now all string attributes are valid everywhere as they are target dependent
            // (e.g. no way to verify the validity of an arbitrary attribute without knowing the target)
            if (IsString)
            {
                return;
            }

            Kind.VerifyAttributeUsage(index, value);
        }
 // To prevent native asserts or crashes - validates parameters before passing down to native code
 internal static void VerifyAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index, ulong value)
 {
     kind.VerifyAttributeUsage(index);
     kind.RangeCheckValue(value);
 }