internal static void VerifyAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index)
        {
            FunctionIndexKinds allowedIndexes = kind.GetAllowedIndexes( );

            switch (index)
            {
            case FunctionAttributeIndex.Function:
                if (!allowedIndexes.HasFlag(FunctionIndexKinds.Function))
                {
                    throw new ArgumentException( );
                }

                break;

            case FunctionAttributeIndex.ReturnType:
                if (!allowedIndexes.HasFlag(FunctionIndexKinds.Return))
                {
                    throw new ArgumentException( );
                }

                break;

            // case FunctionAttributeIndex.Parameter0:
            default:
                if (!allowedIndexes.HasFlag(FunctionIndexKinds.Parameter))
                {
                    throw new ArgumentException( );
                }

                break;
            }
        }
Beispiel #2
0
        internal static void VerifyAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index)
        {
            kind.ValidateDefined(nameof(kind));

            FunctionIndexKinds allowedIndexes = kind.GetAllowedIndexes( );

            switch (index)
            {
            case FunctionAttributeIndex.Function:
                if (!allowedIndexes.HasFlag(FunctionIndexKinds.Function))
                {
                    throw new ArgumentException(Resources.Attribute_not_allowed_on_functions, nameof(index));
                }

                break;

            case FunctionAttributeIndex.ReturnType:
                if (!allowedIndexes.HasFlag(FunctionIndexKinds.Return))
                {
                    throw new ArgumentException(Resources.Attribute_not_allowed_on_function_Return, nameof(index));
                }

                break;

            // case FunctionAttributeIndex.Parameter0:
            default:
                if (!allowedIndexes.HasFlag(FunctionIndexKinds.Parameter))
                {
                    throw new ArgumentException(Resources.Attribute_not_allowed_on_function_parameter, nameof(index));
                }

                break;
            }
        }
Beispiel #3
0
        internal static void VerifyAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index)
        {
            Debug.Assert(kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds);
            FunctionIndexKinds allowedindices = kind.GetAllowedIndexes( );

            switch (index)
            {
            case FunctionAttributeIndex.Function:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Function))
                {
                    throw new ArgumentException("Attribute not allowed on functions", nameof(index));
                }

                break;

            case FunctionAttributeIndex.ReturnType:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Return))
                {
                    throw new ArgumentException("Attribute not allowed on function Return", nameof(index));
                }

                break;

            // case FunctionAttributeIndex.Parameter0:
            default:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Parameter))
                {
                    throw new ArgumentException("Attribute not allowed on function parameter", nameof(index));
                }

                break;
            }
        }
Beispiel #4
0
        internal static bool CheckAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index, Value value)
        {
            FunctionIndexKinds allowedindices = kind.GetAllowedIndexes();

            switch (index)
            {
            case FunctionAttributeIndex.Function:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Function))
                {
                    return(false);
                }

                break;

            case FunctionAttributeIndex.ReturnType:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Return))
                {
                    return(false);
                }

                break;

            // case FunctionAttributeIndex.Parameter0:
            default:
            {
                if (value == default)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                if (!allowedindices.HasFlag(FunctionIndexKinds.Parameter))
                {
                    return(false);
                }

                IrFunction?function = value switch
                {
                    IrFunction f => f,
                    CallInstruction call => call.TargetFunction,
                    Argument arg => arg.ContainingFunction,
                          _ => default,
                };
                int paramIndex = index - FunctionAttributeIndex.Parameter0;
                if (paramIndex >= (function?.Parameters.Count ?? 0))
                {
                    return(false);
                }
            }
Beispiel #5
0
        internal static bool CheckAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index, Value value)
        {
            kind.ValidateDefined(nameof(kind));

            FunctionIndexKinds allowedindices = kind.GetAllowedIndexes( );

            switch (index)
            {
            case FunctionAttributeIndex.Function:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Function))
                {
                    return(false);
                }

                break;

            case FunctionAttributeIndex.ReturnType:
                if (!allowedindices.HasFlag(FunctionIndexKinds.Return))
                {
                    return(false);
                }

                break;

            // case FunctionAttributeIndex.Parameter0:
            default:
            {
                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                if (!allowedindices.HasFlag(FunctionIndexKinds.Parameter))
                {
                    return(false);
                }

                IrFunction function;
                switch (value)
                {
                case IrFunction f:
                    function = f;
                    break;

                case Invoke inv:
                    function = inv.TargetFunction;
                    break;

                case CallInstruction call:
                    function = call.TargetFunction;
                    break;

                case Argument arg:
                    function = arg.ContainingFunction;
                    if (index != FunctionAttributeIndex.Parameter0 + ( int )arg.Index)
                    {
                        return(false);
                    }

                    break;

                default:
                    function = null;
                    break;
                }

                int paramIndex = index - FunctionAttributeIndex.Parameter0;
                if (paramIndex >= (function?.Parameters.Count ?? 0))
                {
                    return(false);
                }
            }

            break;
            }

            return(true);
        }