private Attribute(Context cx, AttributeData attributeData, IEntity entity, AttributeKind kind) : base(cx, attributeData) { this.attributeSyntax = attributeData.ApplicationSyntaxReference?.GetSyntax() as AttributeSyntax; this.entity = entity; this.kind = kind; }
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; } }
internal static void VerifyAttributeUsage(this AttributeKind kind, FunctionAttributeIndex index, Value value) { VerifyAttributeUsage(kind, index); if (index >= FunctionAttributeIndex.Parameter0) { IrFunction function; switch (value) { case IrFunction f: function = f; break; case CallInstruction call: function = call.TargetFunction; break; case Argument arg: function = arg.ContainingFunction; break; default: function = default; break; } int paramIndex = index - FunctionAttributeIndex.Parameter0; if (paramIndex > ((function?.Parameters.Count ?? 0) - 1)) { throw new ArgumentException( ); } } }
internal static void RangeCheckValue(this AttributeKind kind, ulong value) { // To prevent native asserts or crashes - validate parameters before passing down to native code switch (kind) { case AttributeKind.Alignment: if (value > UInt32.MaxValue) { throw new ArgumentOutOfRangeException( ); } break; case AttributeKind.StackAlignment: if (value > UInt32.MaxValue) { throw new ArgumentOutOfRangeException( ); } if (value != 0 && !IsPowerOfTwo(value)) { throw new ArgumentException( ); } break; case AttributeKind.Dereferenceable: case AttributeKind.DereferenceableOrNull: break; default: throw new ArgumentException( ); } }
/// <summary> /// Returns the domain ID for the given attribute type. /// </summary> /// <param name="kind">The attribute kind</param> /// <param name="enumAttrType">For enums, enumAttrType must be valid. Otherwise it may be null.</param> /// <returns></returns> protected String GetDomainID(AttributeKind kind, EnumAttributeType enumAttrType) { switch (kind) { case AttributeKind.BooleanAttr: return("DM_bool"); case AttributeKind.DoubleAttr: return("DM_double"); case AttributeKind.FloatAttr: return("DM_float"); case AttributeKind.ByteAttr: return("DM_byte"); case AttributeKind.ShortAttr: return("DM_short"); case AttributeKind.IntegerAttr: return("DM_int"); case AttributeKind.LongAttr: return("DM_long"); case AttributeKind.StringAttr: return("DM_string"); case AttributeKind.EnumAttr: return("DM_enum_" + enumAttrType.Name); default: throw new Exception("Unsupported attribute value type: \"" + kind + "\""); } }
/// <summary> /// Returns the name of the given basic attribute kind (enum,container not supported) /// </summary> /// <param name="attrKind">The AttributeKind value</param> /// <returns>The name of the attribute kind</returns> private static String GetKindName(AttributeKind attrKind) { switch (attrKind) { case AttributeKind.ByteAttr: return("byte"); case AttributeKind.ShortAttr: return("short"); case AttributeKind.IntegerAttr: return("int"); case AttributeKind.LongAttr: return("long"); case AttributeKind.BooleanAttr: return("boolean"); case AttributeKind.StringAttr: return("string"); case AttributeKind.FloatAttr: return("float"); case AttributeKind.DoubleAttr: return("double"); case AttributeKind.ObjectAttr: return("object"); case AttributeKind.GraphAttr: return("graph"); } return("<INVALID>"); }
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; } }
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; } }
private void RecordNewSeenOrThrow(ref AttributeKind seenAttributes, AttributeKind newAttribute) { if ((seenAttributes & newAttribute) != 0) { ThrowInvalidAssemblyName(); } seenAttributes |= newAttribute; }
/// <summary>Adds an attribute to an <see cref="Argument"/></summary> /// <param name="kind"><see cref="AttributeKind"/> to add</param> /// <returns> /// This Argument for Fluent access /// </returns> public Argument AddAttribute(AttributeKind kind) { kind.ValidateDefined(nameof(kind)); Attributes.Add(Context.CreateAttribute(kind)); return(this); }
/// <summary>Creates a simple boolean attribute</summary> /// <param name="kind">Kind of attribute</param> public AttributeValue CreateAttribute(AttributeKind kind) { if (kind.RequiresIntValue( )) { throw new ArgumentException($"Attribute {kind} requires a value", nameof(kind)); } return(CreateAttribute(kind, 0ul)); }
/// <summary>Creates an attribute with an integer value parameter</summary> /// <param name="kind">The kind of attribute</param> /// <param name="value">Value for the attribute</param> /// <remarks> /// <para>Not all attributes support a value and those that do don't all support /// a full 64bit value. The following table provides the kinds of attributes /// accepting a value and the allowed size of the values.</para> /// <list type="table"> /// <listheader><term><see cref="AttributeKind"/></term><term>Bit Length</term></listheader> /// <item><term><see cref="AttributeKind.Alignment"/></term><term>32</term></item> /// <item><term><see cref="AttributeKind.StackAlignment"/></term><term>32</term></item> /// <item><term><see cref="AttributeKind.Dereferenceable"/></term><term>64</term></item> /// <item><term><see cref="AttributeKind.DereferenceableOrNull"/></term><term>64</term></item> /// </list> /// </remarks> public AttributeValue CreateAttribute(AttributeKind kind, UInt64 value) { var handle = NativeMethods.CreateEnumAttribute(ContextHandle , kind.GetEnumAttributeId( ) , value ); return(AttributeValue.FromHandle(this, handle)); }
/// <summary>Adds an attribute to an <see cref="Argument"/></summary> /// <param name="self">The <see cref="Argument"/> to add attributes to</param> /// <param name="kind"><see cref="AttributeKind"/> to add</param> /// <returns> /// <paramref name="self"/> for Fluent access /// </returns> public static Argument AddAttribute([ValidatedNotNull] this Argument self, AttributeKind kind) { self.ValidateNotNull(nameof(self)); kind.ValidateDefined(nameof(self)); self.Attributes.Add(self.Context.CreateAttribute(kind)); return(self); }
internal static uint GetEnumAttributeId(this AttributeKind kind) { if (KindToAttribIdMap.Value.TryGetValue(kind, out uint retVal)) { return(retVal); } return(0); }
/// <summary>Removes an <see cref="AttributeKind"/> from an <see cref="Argument"/></summary> /// <param name="kind"><see cref="AttributeKind"/> to remove</param> /// <returns>This Argument for fluent usage</returns> public Argument RemoveAttribute(AttributeKind kind) { kind.ValidateDefined(nameof(kind)); if (kind == AttributeKind.None) { return(this); } return(RemoveAttribute(kind.GetAttributeName( ))); }
public override bool TryGetNumericAttribute(AttributeKind attribute, out Rational value) { if (attribute == AttributeKind.Raw && CnstKind == CnstKind.Numeric) { value = (Rational)Raw; return(true); } value = Rational.Zero; return(false); }
private void RecordNewSeenOrThrow(ref AttributeKind seenAttributes, AttributeKind newAttribute) { if ((seenAttributes & newAttribute) != 0) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } else { seenAttributes |= newAttribute; } }
public override bool TryGetStringAttribute(AttributeKind attribute, out string value) { if (attribute == AttributeKind.Raw && CnstKind == CnstKind.String) { value = (string)Raw; return(true); } value = null; return(false); }
public override bool TryGetStringAttribute(AttributeKind attribute, out string value) { if (attribute == AttributeKind.Name) { value = Name; return(true); } value = null; return(false); }
public override bool TryGetKindAttribute(AttributeKind attribute, out object value) { if (attribute == AttributeKind.Op) { value = Op; return(true); } value = null; return(false); }
public override bool TryGetNumericAttribute(AttributeKind attribute, out Rational value) { if (attribute == AttributeKind.Cardinality) { value = new Rational(Cardinality); return(true); } value = Rational.Zero; return(false); }
public override bool TryGetBooleanAttribute(AttributeKind attribute, out bool value) { if (attribute == AttributeKind.IsPartial) { value = IsPartial; return(true); } value = false; return(false); }
/// <summary>Gets a value indicating whether the attribute requires an integer parameter value</summary> /// <param name="kind"><see cref="AttributeKind"/> to check</param> /// <returns><see langword="true"/> if the attribute requires an integer value</returns> public static bool RequiresIntValue(this AttributeKind kind) { switch (kind) { case AttributeKind.Alignment: case AttributeKind.StackAlignment: case AttributeKind.Dereferenceable: case AttributeKind.DereferenceableOrNull: return(true); default: return(false); } }
public static bool RequiresIntValue(this AttributeKind kind) { Debug.Assert(kind >= AttributeKind.None && kind < AttributeKind.EndAttrKinds); switch (kind) { case AttributeKind.Alignment: case AttributeKind.StackAlignment: case AttributeKind.Dereferenceable: case AttributeKind.DereferenceableOrNull: return(true); default: return(false); } }
/// <summary> /// Initializes an AttributeType instance. /// </summary> /// <param name="name">The name for the attribute.</param> /// <param name="ownerType">The owner model type.</param> /// <param name="kind">The kind of the attribute.</param> /// <param name="enumType">The enum type description, if Kind == AttributeKind.EnumAttr, otherwise null.</param> /// <param name="valueType">The attribute type of the value of the set, if Kind == AttributeKind.SetAttr; the attribute type of the value of the map, if Kind == AttributeKind.MapAttr; the attribute type of the value of the array, if Kind == AttributeKind.ArrayAttr; the attribute type of the value of the deque, if Kind == AttributeKind.DequeAttr; otherwise null. </param> /// <param name="keyType">The attribute type of the key of the map, if Kind == AttributeKind.MapAttr; otherwise null.</param> /// <param name="typeName">The name of the attribute type, if Kind == AttributeKind.NodeAttr || Kind == AttributeKind.EdgeAttr; otherwise null.</param> /// <param name="package">The package name if this is a node or edge type that is contained in a package, otherwise null.</param> /// <param name="packagePrefixedTypeName">The name of the attribute type with the package as prefix if it is contained in a package, if Kind == AttributeKind.NodeAttr || Kind == AttributeKind.EdgeAttr.</param> /// <param name="type">The type of the attribute type.</param> public AttributeType(String name, InheritanceType ownerType, AttributeKind kind, EnumAttributeType enumType, AttributeType valueType, AttributeType keyType, String typeName, String package, String packagePrefixedTypeName, Type type) { Name = name; OwnerType = ownerType; Kind = kind; EnumType = enumType; ValueType = valueType; KeyType = keyType; TypeName = typeName; Package = package; PackagePrefixedTypeName = packagePrefixedTypeName; Type = type; }
/// <summary>Creates an attribute with an integer value parameter</summary> /// <param name="kind">The kind of attribute</param> /// <param name="value">Value for the attribute</param> /// <remarks> /// <para>Not all attributes support a value and those that do don't all support /// a full 64bit value. The following table provides the kinds of attributes /// accepting a value and the allowed size of the values.</para> /// <list type="table"> /// <listheader><term><see cref="AttributeKind"/></term><term>Bit Length</term></listheader> /// <item><term><see cref="AttributeKind.Alignment"/></term><term>32</term></item> /// <item><term><see cref="AttributeKind.StackAlignment"/></term><term>32</term></item> /// <item><term><see cref="AttributeKind.Dereferenceable"/></term><term>64</term></item> /// <item><term><see cref="AttributeKind.DereferenceableOrNull"/></term><term>64</term></item> /// </list> /// </remarks> /// <returns><see cref="AttributeValue"/> with the specified kind and value</returns> public AttributeValue CreateAttribute(AttributeKind kind, UInt64 value) { kind.ValidateDefined(nameof(kind)); if (!kind.RequiresIntValue( )) { throw new ArgumentException($"Attribute {kind} does not support a value", nameof(kind)); } var handle = LLVMCreateEnumAttribute(ContextHandle , kind.GetEnumAttributeId( ) , value ); return(AttributeValue.FromHandle(this, handle)); }
/// <summary>Creates an attribute with an integer value parameter</summary> /// <param name="kind">The kind of attribute</param> /// <param name="value">Value for the attribute</param> /// <remarks> /// <para>Not all attributes support a value and those that do don't all support /// a full 64bit value. The following table provides the kinds of attributes /// accepting a value and the allowed size of the values.</para> /// <list type="table"> /// <listheader><term><see cref="AttributeKind"/></term><term>Bit Length</term></listheader> /// <item><term><see cref="AttributeKind.Alignment"/></term><term>32</term></item> /// <item><term><see cref="AttributeKind.StackAlignment"/></term><term>32</term></item> /// <item><term><see cref="AttributeKind.Dereferenceable"/></term><term>64</term></item> /// <item><term><see cref="AttributeKind.DereferenceableOrNull"/></term><term>64</term></item> /// </list> /// </remarks> /// <returns><see cref="AttributeValue"/> with the specified kind and value</returns> public AttributeValue CreateAttribute(AttributeKind kind, UInt64 value) { kind.ValidateDefined(nameof(kind)); if (!kind.RequiresIntValue( )) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Attribute_0_does_not_support_a_value, kind), nameof(kind)); } var handle = LLVMCreateEnumAttribute(ContextHandle , kind.GetEnumAttributeId( ) , value ); return(AttributeValue.FromHandle(this, handle)); }
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); } }
/// <summary>Adds a single <see cref="AttributeKind"/> to an <see cref="IAttributeContainer"/>.</summary> /// <typeparam name="T">Container type.</typeparam> /// <param name="self">Container to add the attribute to.</param> /// <param name="index"><see cref="FunctionAttributeIndex"/> to add the attribute to.</param> /// <param name="kind">Attribute to add to the container.</param> /// <returns><paramref name="self"/> for fluent use.</returns> public static T AddAttribute <T>(this T self, FunctionAttributeIndex index, AttributeKind kind) where T : class, IAttributeContainer { AttributeValue attrib = self.Context.CreateAttribute(kind); if (self is IAttributeAccessor container) { container.AddAttributeAtIndex(index, attrib); } else { self.Attributes[index].Add(self.Context.CreateAttribute(kind)); } return(self); }
public override bool TryGetBooleanAttribute(AttributeKind attribute, out bool value) { if (attribute == AttributeKind.IsNew) { value = IsNew; return(true); } else if (attribute == AttributeKind.IsSub) { value = IsSub; return(true); } value = false; return(false); }
protected String GetDomainID(AttributeKind kind) { return GetDomainID(kind, null); }
/// <summary> /// Returns the domain ID for the given attribute type. /// </summary> /// <param name="kind">The attribute kind</param> /// <param name="enumAttrType">For enums, enumAttrType must be valid. Otherwise it may be null.</param> /// <returns></returns> protected String GetDomainID(AttributeKind kind, EnumAttributeType enumAttrType) { switch(kind) { case AttributeKind.BooleanAttr: return "DM_bool"; case AttributeKind.DoubleAttr: return "DM_double"; case AttributeKind.FloatAttr: return "DM_float"; case AttributeKind.ByteAttr: return "DM_byte"; case AttributeKind.ShortAttr: return "DM_short"; case AttributeKind.IntegerAttr: return "DM_int"; case AttributeKind.LongAttr: return "DM_long"; case AttributeKind.StringAttr: return "DM_string"; case AttributeKind.EnumAttr: return "DM_enum_" + enumAttrType.Name; default: throw new Exception("Unsupported attribute value type: \"" + kind + "\""); } }