Beispiel #1
0
 static void StoreMultipleObjectInaFile()
 {
     using (var outputStream = new BinaryWriter(File.Create("data.dat")))
     {
         outputStream.Write(0); //indicates number of demands in the file.
         for (int i = 0; i < 10; i++)
         {
             FlatBufferBuilder fbb = new FlatBufferBuilder(1024);
             var scalarTypeOffset  = Helper.BuildScalarType(fbb);
             fbb.Finish(scalarTypeOffset.Value);
             byte[] serializedData = fbb.SizedByteArray();
             outputStream.Write(serializedData.Length);
             outputStream.Write(serializedData);
         }
         outputStream.Seek(0, SeekOrigin.Begin);
         outputStream.Write(10); //replaces the value written at the top which indicates the number of demands.
     }
     using (var ipStream = new BinaryReader(File.OpenRead("data.dat")))
     {
         var count = ipStream.ReadInt32();
         for (int i = 0; i < count; i++)
         {
             var size        = ipStream.ReadInt32();
             var bytes       = ipStream.ReadBytes(size);
             var byteBuf     = new ByteBuffer(bytes);
             var dScalarType = ScalarType.GetRootAsScalarType(byteBuf);
         }
     }
 }
Beispiel #2
0
        public TypesEntity(RegistryPattern owner)
        {
            this.Entity = owner.CreateEntity(owner.TypesEntityName, owner.TypesEntityPidType);

            ScalarType fullNameType = (ScalarType)owner.Model.Types.GetByName("string");

            fullNameType.TypeDefinition.Length   = 255;
            fullNameType.TypeDefinition.Required = true;
            this.FullNameAttribute = this.Entity.AddAttribute("FullName", fullNameType);
            ScalarType shortNameType = (ScalarType)owner.Model.Types.GetByName("string");

            shortNameType.TypeDefinition.Length  = 64;
            fullNameType.TypeDefinition.Required = true;
            this.ShortNameAttribute = this.Entity.AddAttribute("ShortName", fullNameType);
            ScalarType descriptionType = (ScalarType)owner.Model.Types.GetByName("string");

            descriptionType.TypeDefinition.Length   = 1000;
            descriptionType.TypeDefinition.Required = false;
            this.DescriptionAttribute = this.Entity.AddAttribute("Description", fullNameType);

            UniqueId uid = new UniqueId(this.Entity, this.FullNameAttribute.Name);

            uid.Attributes.Add(this.FullNameAttribute);
            this.Entity.Constraints.UniqueIds.Add(uid);

            owner.Model.Entities.Add(this.Entity);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the type of the binary implicit conversion in case of a multiplication.
        /// </summary>
        /// <param name="left">the left.</param>
        /// <param name="right">the right.</param>
        /// <returns>The implicit conversion between between to two types</returns>
        public static TypeBase GetMultiplyImplicitConversionType(TypeBase left, TypeBase right)
        {
            if ((left is VectorType || left is MatrixType) && right is ScalarType)
            {
                return(GetMultiplyImplicitConversionType(right, left));
            }

            if (left is ScalarType)
            {
                TypeBase componentType = null;
                if (right is VectorType)
                {
                    componentType = (right as VectorType).Type;
                }
                else if (right is MatrixType)
                {
                    componentType = (right as MatrixType).Type;
                }

                if (componentType != null)
                {
                    ScalarType resultComponentType = null;
                    if (left == ScalarType.Double || componentType == ScalarType.Double)
                    {
                        resultComponentType = ScalarType.Double;
                    }
                    else if (left == ScalarType.Float || componentType == ScalarType.Float)
                    {
                        resultComponentType = ScalarType.Float;
                    }
                    else if (left == ScalarType.Half || componentType == ScalarType.Half)
                    {
                        resultComponentType = ScalarType.Half;
                    }
                    else if (left == ScalarType.Int || componentType == ScalarType.Int)
                    {
                        resultComponentType = ScalarType.Int;
                    }
                    else if (left == ScalarType.UInt || componentType == ScalarType.UInt)
                    {
                        resultComponentType = ScalarType.UInt;
                    }

                    if (resultComponentType != null)
                    {
                        if (right is VectorType)
                        {
                            return(new VectorType(resultComponentType, (right as VectorType).Dimension));
                        }

                        if (right is MatrixType)
                        {
                            return(new MatrixType(resultComponentType, (right as MatrixType).RowCount, (right as MatrixType).ColumnCount));
                        }
                    }
                }
            }

            return(GetBinaryImplicitConversionType(left, right, false));
        }
Beispiel #4
0
        public void Parse_custom_scalar()
        {
            /* Given */
            var idl       = @"
                scalar Url

                type Query {
                }
                schema {
                    query: Query
                }
                ";
            var urlScalar = new ScalarType("Url", new StringConverter());
            var document  = Parser.ParseDocument(idl);
            var reader    = new SdlReader(document, new SchemaBuilder()
                                          .Include(urlScalar));


            /* When */
            var actual = reader.Read().Build().GetNamedType <ScalarType>("Url");

            /* Then */
            Assert.Equal("Url", actual.Name);
            Assert.Equal(urlScalar, actual);
        }
        internal static void SerializeScalarField(Stream stream, object data, ScalarType fieldType, List <Tuple <long, string> > sectionProcessList, ref long offset)
        {
            switch (fieldType)
            {
            case ScalarType.Double:
                SerializeDouble(stream, (double)data);
                break;

            case ScalarType.Int64:
                SerializeInt64(stream, (long)data);
                break;

            case ScalarType.UInt64:
                SerializeUInt64(stream, (ulong)data);
                break;

            case ScalarType.String:
            {
                var comeBackPosition          = stream.Position;
                var beginningOfStringPosition = SerializeString(stream, (string)data, ref offset);
                stream.Position = comeBackPosition;
                SerializeInt64(stream, beginningOfStringPosition);
                break;
            }

            case ScalarType.Struct:
                sectionProcessList.Add(new Tuple <long, string>(stream.Position, (string)data));
                SerializeInt64(stream, 0xDEADBEEF);
                break;
            }
        }
Beispiel #6
0
 public static Offset <ScalarType> CreateScalarType(FlatBufferBuilder builder,
                                                    sbyte byteType    = 0,
                                                    byte ubyteType    = 0,
                                                    bool boolType     = false,
                                                    short shortType   = 0,
                                                    ushort ushortType = 0,
                                                    int inttype       = 0,
                                                    uint uintType     = 0,
                                                    float floatType   = 0.0f,
                                                    long longType     = 0,
                                                    ulong ulongType   = 0,
                                                    double doubleType = 0.0)
 {
     builder.StartTable(11);
     ScalarType.AddDoubleType(builder, doubleType);
     ScalarType.AddUlongType(builder, ulongType);
     ScalarType.AddLongType(builder, longType);
     ScalarType.AddFloatType(builder, floatType);
     ScalarType.AddUintType(builder, uintType);
     ScalarType.AddInttype(builder, inttype);
     ScalarType.AddUshortType(builder, ushortType);
     ScalarType.AddShortType(builder, shortType);
     ScalarType.AddBoolType(builder, boolType);
     ScalarType.AddUbyteType(builder, ubyteType);
     ScalarType.AddByteType(builder, byteType);
     return(ScalarType.EndScalarType(builder));
 }
Beispiel #7
0
        public RestEntityProperty(object jsonObject, object jsonRootObject, string name, RestEntityType parent) : base(parent)
        {
            XmlTypeCode xmlType;
            Type        type;

            this.JsonRootObject       = jsonRootObject;
            this.JsonObject           = jsonObject;
            this.PathPrefix           = parent.PathPrefix;
            this.ConfigPrefix         = parent.ConfigPrefix;
            this.ControllerNamePrefix = parent.ControllerNamePrefix;

            this.name   = name;
            this.parent = parent;

            this.JsonRootObject = jsonRootObject;
            this.JsonObject     = jsonObject;
            this.NoUIOrConfig   = parent.NoUIOrConfig;

            id = this.MakeID("Property='" + this.name + "'");

            xmlType = TypeMapper.GetXMLType((string)this.JsonObject.type);
            type    = xmlType.GetDotNetType();

            dataType  = new ScalarType(type, this);
            debugInfo = this.GetDebugInfo();
        }
 protected Field(string name, ScalarType type, bool isRepeated, object value)
 {
     this.Name       = name;
     this.Type       = type;
     this.IsRepeated = isRepeated;
     this.Value      = value;
 }
Beispiel #9
0
 private static void MergeScalarType(SchemaBuilder builder, ScalarType rightType)
 {
     if (!builder.TryGetType <ScalarType>(rightType.Name, out _))
     {
         builder.Include(rightType);
     }
 }
        private static void SerializeScalar(object obj, FieldDescriptor fd, TextWriter textWriter, TranslationContext translationContext)
        {
            // check wether we need quotation marks to surround the value.
            bool       needQuotationMarks = true;
            ScalarType st = fd.ScalarType;

            if (st != null)
            {
                needQuotationMarks = st.NeedsJsonQuotationWrap();
            }

            textWriter.Write('"');
            textWriter.Write(fd.TagName);
            textWriter.Write('"');
            textWriter.Write(':');
            if (needQuotationMarks)
            {
                textWriter.Write('"');
            }
            fd.AppendValue(textWriter, obj, translationContext, Format.Json);
            if (needQuotationMarks)
            {
                textWriter.Write('"');
            }
        }
Beispiel #11
0
        public override void Implement()
        {
            foreach (Entity entity in Model.Entities)
            {
                if (this.AppliedTo(entity))
                {
                    ScalarType actorType = (ScalarType)Model.Types.GetByName("string");
                    actorType.TypeDefinition.Length   = 64;
                    actorType.TypeDefinition.Required = false;
                    ScalarType actionDateType = (ScalarType)Model.Types.GetByName("datetime");
                    actionDateType.TypeDefinition.Required = false;

                    entity.AddAttribute(
                        this.CreatedByAttributeName,
                        actorType);
                    entity.AddAttribute(
                        this.CreatedDateAttributeName,
                        actionDateType);
                    entity.AddAttribute(
                        this.LastModifiedByAttributeName,
                        actorType);
                    entity.AddAttribute(
                        this.LastModifiedDateAttributeName,
                        actionDateType);
                }
            }
        }
        public GetSetPropertyAttribute(MethodInfo method, BaseObject parent) : base(parent)
        {
            this.method       = method;
            this.parent       = parent;
            this.childOrdinal = 3;

            name = this.GenerateName();

            var type = method.GetGetterSetterType();

            modifiers = Modifiers.Unknown;

            if (method.IsGetter())
            {
                modifiers |= Modifiers.CanRead;
            }

            if (method.IsSetter())
            {
                modifiers |= Modifiers.CanWrite;
            }

            if (method.DeclaringType.FullName == ((IElement)parent).DataType.FullyQualifiedName)
            {
                modifiers |= Modifiers.IsLocal;
            }

            id       = this.MakeID("Property='" + this.Name + "'");
            dataType = new ScalarType(type, this);
        }
Beispiel #13
0
 public void SetFieldToScalar(object root, string value, TranslationContext translationContext)
 {
     if (ScalarType != null && !ScalarType.IsMarshallOnly)
     {
         ScalarType.SetField(root, field, value, dataFormat, translationContext);
     }
 }
Beispiel #14
0
        internal static bool IsCast(ScalarType left, ScalarType right)
        {
            if (left == right)
            {
                return(false);
            }

            switch (left)
            {
            case ScalarType.Min12Int:
            case ScalarType.Min16Int:
            case ScalarType.Int:
                switch (right)
                {
                case ScalarType.Min16Uint:
                case ScalarType.Uint:
                    return(false);
                }
                break;

            case ScalarType.Min16Uint:
            case ScalarType.Uint:
                switch (right)
                {
                case ScalarType.Min12Int:
                case ScalarType.Min16Int:
                case ScalarType.Int:
                    return(false);
                }
                break;
            }

            return(true);
        }
Beispiel #15
0
        public void InheritAttributes(MetaMetadataField inheritFrom)
        {
            var classDescriptor = ClassDescriptor.GetClassDescriptor(this);

            foreach (MetaMetadataFieldDescriptor fieldDescriptor in classDescriptor.AllFieldDescriptors)
            {
                if (fieldDescriptor.IsInheritable)
                {
                    ScalarType scalarType = fieldDescriptor.ScalarType;
                    try
                    {
                        if (scalarType != null &&
                            scalarType.IsDefaultValue(fieldDescriptor.Field, this) &&
                            !scalarType.IsDefaultValue(fieldDescriptor.Field, inheritFrom))
                        {
                            Object value = fieldDescriptor.Field.GetValue(inheritFrom);
                            fieldDescriptor.Field.SetValue(this, value);
                            Debug.WriteLine("inherit\t" + this.Name + "." + fieldDescriptor.Name + "\t= " + value);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(inheritFrom.Name + " doesn't have field " + fieldDescriptor.Name + ", ignore it.");
                        //					e.printStackTrace();
                    }
                }
            }
        }
Beispiel #16
0
        public static string UnescapeBlock(string content, ScalarType scalarType)
        {
            if (content.StartsWith("\r\n"))
            {
                content = content.Substring(2);
            }
            else if (content.StartsWith("\n"))
            {
                content = content.Substring(1);
            }
            var indent        = Regex.Match(content, @"^\s+").Value;
            var indentPattern = "^" + indent.Replace(" ", @"\x20").Replace("\t", @"\x09");

            switch (scalarType)
            {
            case ScalarType.BlockFolded:
            case ScalarType.BlockFoldedStrip:
            case ScalarType.BlockFoldedKeep:
            case ScalarType.BlockLiteral:
            case ScalarType.BlockLiteralStrip:
            case ScalarType.BlockLiteralKeep:
                return(Regex.Replace(content, indentPattern, "", RegexOptions.Multiline | RegexOptions.Compiled));

            default: throw new NotSupportedException();
            }
        }
Beispiel #17
0
        internal static bool IsPromotion(ScalarType left, ScalarType right)
        {
            if (left == right)
            {
                return(false);
            }

            switch (right)
            {
            case ScalarType.Half:
                switch (left)
                {
                case ScalarType.Float:
                case ScalarType.Double:
                    return(true);
                }
                break;

            case ScalarType.Float:
                switch (left)
                {
                case ScalarType.Double:
                    return(true);
                }
                break;
            }

            return(false);
        }
        private static EnumType ConvertToEnumType(
            SchemaEnumType somEnumType,
            Dictionary <SchemaElement, GlobalItem> newGlobalItems)
        {
            ScalarType underlyingType    = (ScalarType)somEnumType.UnderlyingType;
            EnumType   enumType          = new EnumType(somEnumType.Name, somEnumType.Namespace, underlyingType.Type, somEnumType.IsFlags, DataSpace.CSpace);
            Type       clrEquivalentType = underlyingType.Type.ClrEquivalentType;

            foreach (SchemaEnumMember enumMember1 in somEnumType.EnumMembers)
            {
                EnumMember enumMember2 = new EnumMember(enumMember1.Name, Convert.ChangeType((object)enumMember1.Value, clrEquivalentType, (IFormatProvider)CultureInfo.InvariantCulture));
                if (enumMember1.Documentation != null)
                {
                    enumMember2.Documentation = Converter.ConvertToDocumentation(enumMember1.Documentation);
                }
                Converter.AddOtherContent((SchemaElement)enumMember1, (MetadataItem)enumMember2);
                enumType.AddMember(enumMember2);
            }
            if (somEnumType.Documentation != null)
            {
                enumType.Documentation = Converter.ConvertToDocumentation(somEnumType.Documentation);
            }
            Converter.AddOtherContent((SchemaElement)somEnumType, (MetadataItem)enumType);
            newGlobalItems.Add((SchemaElement)somEnumType, (GlobalItem)enumType);
            return(enumType);
        }
Beispiel #19
0
        public PropertyAttribute(PropertyInfo property, BaseObject parent) : base(parent)
        {
            this.property     = property;
            this.parent       = parent;
            this.childOrdinal = 3;
            name = property.Name;

            var type = property.PropertyType;

            id = this.MakeID("Property='" + property.Name + "'");

            dataType = new ScalarType(type, this);

            modifiers = Modifiers.Unknown;

            if (property.CanRead)
            {
                modifiers |= Modifiers.CanRead;
            }

            if (property.CanWrite)
            {
                modifiers |= Modifiers.CanWrite;
            }

            if (property.DeclaringType.FullName == ((IElement)parent).DataType.FullyQualifiedName)
            {
                modifiers |= Modifiers.IsLocal;
            }
        }
Beispiel #20
0
 private static void AssertNodeHasTypes(Node node, NodeType nodeType, ScalarType scalarType, NumberType numberType, MapType mapType)
 {
     Assert.AreEqual(nodeType, node.NodeType);
     Assert.AreEqual(scalarType, node.ScalarType);
     Assert.AreEqual(numberType, node.NumberType);
     Assert.AreEqual(mapType, node.MapType);
 }
Beispiel #21
0
 public override nn.Module to(ScalarType dtype)
 {
     foreach (var m in _modules)
     {
         m.to(dtype);
     }
     return(this);
 }
Beispiel #22
0
        public RestNavigationProperty(object jsonRootObject, object jsonObject, object jsonOriginalRootObject, object jsonOriginalObject, string name, RestEntityType parentEntity) : base(parentEntity)
        {
            string _namespace = null;
            string multiplicity;
            var    ancestor         = (IBase)parent;
            var    restEntityParent = (RestEntityBase)parent;
            IEnumerable <IElement> childEntities;

            this.parent = parentEntity;

            this.JsonRootObject         = jsonRootObject;
            this.JsonObject             = jsonObject;
            this.JsonOriginalRootObject = jsonOriginalRootObject;
            this.JsonOriginalObject     = jsonOriginalObject;

            this.NoUIOrConfig         = parentEntity.NoUIOrConfig;
            this.PathPrefix           = parentEntity.PathPrefix;
            this.ConfigPrefix         = parent.ConfigPrefix;
            this.ControllerNamePrefix = parent.ControllerNamePrefix;

            this.name = name;

            id = this.MakeID("Property='" + this.name + "'");

            while (ancestor != null)
            {
                if (ancestor is RestModel)
                {
                    _namespace = ((RestModel)ancestor).Namespace;

                    break;
                }

                ancestor = ancestor.Parent;
            }

            childOrdinal  = 2;
            childEntities = this.ChildElements;

            multiplicity = this.JsonObject.type == "array" ? "*" : "1..1";

            this.ParentMultiplicity    = multiplicity == "*" ? "0..1" : "1..1";
            this.ThisMultiplicity      = multiplicity;
            this.ThisPropertyRefName   = "id";
            this.ParentPropertyRefName = "id";

            if (isCollectionType)
            {
                dataType = new ScalarType(typeof(IEnumerable), this);
                dataType.IsCollectionType = true;
            }
            else
            {
                dataType = new ScalarType(childEntities.Single().GetType(), this);
            }

            this.NoUIOrConfig = parent.NoUIOrConfig;
        }
Beispiel #23
0
        private static object CoerceScalarValue(object value, ScalarType scalarType)
        {
            if (value is GraphQLScalarValue astValue)
            {
                return(scalarType.ParseLiteral(astValue));
            }

            return(scalarType.ParseValue(value));
        }
Beispiel #24
0
        public bool IsDefaultValueFromContext(object context)
        {
            if (context != null)
            {
                return(ScalarType.IsDefaultValue(field, context));
            }

            return(false);
        }
Beispiel #25
0
        public RemoteExecutorBuilder AddScalarType(ScalarType scalarType)
        {
            if (scalarType == null)
            {
                throw new ArgumentNullException(nameof(scalarType));
            }

            _scalarTypeInstances.Add(scalarType);
            return(this);
        }
Beispiel #26
0
        internal static bool IsIntCast(ScalarType left, ScalarType right)
        {
            if (left == right)
            {
                return(false);
            }

            // TODO

            return(true);
        }
 private static ScalarTypeDefinitionNode SerializeScalarType(
     ScalarType scalarType)
 {
     return(new ScalarTypeDefinitionNode
            (
                null,
                new NameNode(scalarType.Name),
                SerializeDescription(scalarType.Description),
                Array.Empty <DirectiveNode>()
            ));
 }
Beispiel #28
0
        public SchemaBuilder Scalar(
            string name,
            out ScalarType scalarType,
            string?description = null,
            IEnumerable <DirectiveInstance>?directives = null)
        {
            scalarType = new ScalarType(name, description, directives);
            Include(scalarType);

            return(this);
        }
        public GraphTypeAttribute(ListType list, ScalarType scalar)
        {
            var scalarType = scalar.ToGraphType();

            this.GraphType = list switch
            {
                ListType.List => typeof(ListGraphType <>).MakeGenericType(scalarType),
                ListType.NonNullList => typeof(NonNullGraphType <>).MakeGenericType(typeof(ListGraphType <>)).MakeGenericType(scalarType),
                _ => scalarType
            };
        }
Beispiel #30
0
        public Statement EmitScalarTypeHandler(ScalarType scalarType, EmitMode mode)
        {
            AttachStatement statement = new AttachStatement();

            statement.MetaData                 = MetaData;
            statement.OperatorName             = _operator.OperatorName;
            statement.EventSourceSpecifier     = new ObjectEventSourceSpecifier(scalarType.Name);
            statement.EventSpecifier           = new EventSpecifier();
            statement.EventSpecifier.EventType = _eventType;
            return(statement);
        }
 internal IntrinsicVectorTypeSymbol(string name, string documentation, ScalarType scalarType, int numComponents)
     : base(SymbolKind.IntrinsicVectorType, name, documentation, scalarType)
 {
     NumComponents = numComponents;
 }
 internal IntrinsicNumericTypeSymbol(SymbolKind kind, string name, string documentation, ScalarType scalarType)
     : base(kind, name, documentation)
 {
     ScalarType = scalarType;
 }
Beispiel #33
0
 private void GetTextureValueAndScalarType(PredefinedObjectTypeSyntax node, out TypeSymbol valueType, out ScalarType scalarType)
 {
     if (node.TemplateArgumentList != null)
     {
         var valueTypeSyntax = (TypeSyntax) node.TemplateArgumentList.Arguments[0];
         valueType = Bind(valueTypeSyntax, x => BindType(x, null)).TypeSymbol;
         switch (valueTypeSyntax.Kind)
         {
             case SyntaxKind.PredefinedScalarType:
                 scalarType = TypeFacts.GetScalarType((ScalarTypeSyntax) valueTypeSyntax);
                 break;
             case SyntaxKind.PredefinedVectorType:
                 scalarType = TypeFacts.GetVectorType(((VectorTypeSyntax) valueTypeSyntax).TypeToken.Kind).Item1;
                 break;
             case SyntaxKind.PredefinedGenericVectorType:
                 scalarType = TypeFacts.GetScalarType(((GenericVectorTypeSyntax) valueTypeSyntax).ScalarType);
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
     else
     {
         valueType = IntrinsicTypes.Float4;
         scalarType = ScalarType.Float;
     }
 }
 internal IntrinsicScalarTypeSymbol(string name, string documentation, ScalarType scalarType)
     : base(SymbolKind.IntrinsicScalarType, name, documentation, scalarType)
 {
     
 }
Beispiel #35
0
 internal static IntrinsicNumericTypeSymbol GetNumericTypeWithScalarType(this IntrinsicNumericTypeSymbol type, ScalarType scalarType)
 {
     switch (type.Kind)
     {
         case SymbolKind.IntrinsicMatrixType:
             var matrixType = (IntrinsicMatrixTypeSymbol) type;
             return IntrinsicTypes.GetMatrixType(scalarType, matrixType.Rows, matrixType.Cols);
         case SymbolKind.IntrinsicScalarType:
             return IntrinsicTypes.GetScalarType(scalarType);
         case SymbolKind.IntrinsicVectorType:
             return IntrinsicTypes.GetVectorType(scalarType, ((IntrinsicVectorTypeSymbol) type).NumComponents);
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
        public static IntrinsicTypeSymbol CreateTextureType(PredefinedObjectType textureType, TypeSymbol valueType, ScalarType scalarType)
        {
            string name, documentation;

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                    name = "Buffer";
                    documentation = "A buffer type";
                    break;
                case PredefinedObjectType.Texture1D:
                    name = "Texture1D";
                    documentation = "A 1D texture type";
                    break;
                case PredefinedObjectType.Texture1DArray:
                    name = "Texture1DArray";
                    documentation = "An array of 1D textures";
                    break;
                case PredefinedObjectType.Texture2D:
                    name = "Texture2D";
                    documentation = "A 2D texture type";
                    break;
                case PredefinedObjectType.Texture2DArray:
                    name = "Texture2DArray";
                    documentation = "An array of 2D textures";
                    break;
                case PredefinedObjectType.Texture3D:
                    name = "Texture3D";
                    documentation = "A 3D texture type";
                    break;
                case PredefinedObjectType.TextureCube:
                    name = "TextureCube";
                    documentation = "A cube texture type";
                    break;
                case PredefinedObjectType.TextureCubeArray:
                    name = "TextureCubeArray";
                    documentation = "An array of cube textures";
                    break;
                case PredefinedObjectType.Texture2DMS:
                    name = "Texture2DMS";
                    documentation = "A 2D multisampled texture type";
                    break;
                case PredefinedObjectType.Texture2DMSArray:
                    name = "Texture2DMSArray";
                    documentation = "An array of 2D multisampled textures";
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return new IntrinsicTypeSymbol(name, documentation, t => CreateTextureMethods(textureType, t, valueType, scalarType));
        }
Beispiel #37
0
        internal static bool IsPromotion(ScalarType left, ScalarType right)
        {
            if (left == right)
                return false;

            switch (right)
            {
                case ScalarType.Half:
                    switch (left)
                    {
                        case ScalarType.Float:
                        case ScalarType.Double:
                            return true;
                    }
                    break;
                case ScalarType.Float:
                    switch (left)
                    {
                        case ScalarType.Double:
                            return true;
                    }
                    break;
            }

            return false;
        }
Beispiel #38
0
        internal static bool IsCast(ScalarType left, ScalarType right)
        {
            if (left == right)
                return false;

            switch (left)
            {
                case ScalarType.Int:
                    switch (right)
                    {
                        case ScalarType.Uint:
                            return false;
                    }
                    break;
                case ScalarType.Uint:
                    switch (right)
                    {
                        case ScalarType.Int:
                            return false;
                    }
                    break;
            }

            return true;
        }
 public static TypeSymbol GetVectorType(ScalarType scalarType, int numComponents)
 {
     return AllVectorTypes[(((int)scalarType - 1) * 4) + numComponents];
 }
 public static TypeSymbol GetMatrixType(ScalarType scalarType, int numRows, int numCols)
 {
     return AllMatrixTypes[(((int)scalarType - 1) * 16) + (numRows * 4) + numCols];
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="metadataScalarTypeClass"></param>
        /// <param name="valueClass"></param>
        protected MetadataScalarType(Type metadataScalarTypeClass, Type valueClass)
            : base(metadataScalarTypeClass, metadataScalarTypeClass.Name, null, null)
        {
            // Get type handles for Test<String> and its field.

            this.valueScalarType = TypeRegistry.ScalarTypes[valueClass];
            valueField = metadataScalarTypeClass.GetRuntimeField(MetadataScalarBase<object>.VALUE_FIELD_NAME);
            if (ValueField == null)
                Debug.WriteLine(metadataScalarTypeClass.Name + " does not have a valueField");
        }
 internal IntrinsicMatrixTypeSymbol(string name, string documentation, ScalarType scalarType, int rows, int cols)
     : base(SymbolKind.IntrinsicMatrixType, name, documentation, scalarType)
 {
     Rows = rows;
     Cols = cols;
 }
Beispiel #43
0
        internal static bool IsIntCast(ScalarType left, ScalarType right)
        {
            if (left == right)
                return false;

            // TODO

            return true;
        }
        private static IEnumerable<MethodDeclarationSymbol> CreateTextureMethods(PredefinedObjectType textureType, TypeSymbol parent, TypeSymbol valueType, ScalarType scalarType)
        {
            TypeSymbol locationType = null;
            switch (textureType)
            {
                case PredefinedObjectType.Texture1D:
                    locationType = Float;
                    break;
                case PredefinedObjectType.Texture1DArray:
                case PredefinedObjectType.Texture2D:
                    locationType = Float2;
                    break;
                case PredefinedObjectType.Texture2DArray:
                case PredefinedObjectType.Texture3D:
                case PredefinedObjectType.TextureCube:
                    locationType = Float3;
                    break;
                case PredefinedObjectType.TextureCubeArray:
                    locationType = Float4;
                    break;
            }

            TypeSymbol offsetType = null;
            switch (textureType)
            {
                case PredefinedObjectType.Texture1D:
                case PredefinedObjectType.Texture1DArray:
                    offsetType = Int;
                    break;
                case PredefinedObjectType.Texture2D:
                case PredefinedObjectType.Texture2DArray:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    offsetType = Int2;
                    break;
                case PredefinedObjectType.Texture3D:
                    offsetType = Int3;
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    break;
                default:
                    TypeSymbol vectorType;
                    switch (textureType)
                    {
                        case PredefinedObjectType.Texture1D:
                        case PredefinedObjectType.Texture1DArray:
                            vectorType = Float1;
                            break;
                        case PredefinedObjectType.Texture2D:
                        case PredefinedObjectType.Texture2DArray:
                            vectorType = Float2;
                            break;
                        case PredefinedObjectType.Texture3D:
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            vectorType = Float3;
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    yield return new MethodDeclarationSymbol("CalculateLevelOfDetail", "Calculates the level of detail.", parent,
                        Float, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                            new ParameterSymbol("x", "The linear interpolation value, which is a floating-point number between 0.0 and 1.0 inclusive.", m, vectorType)
                        });
                    yield return new MethodDeclarationSymbol("CalculateLevelOfDetailUnclamped", "Calculates the LOD without clamping the result.", parent,
                        Float, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                            new ParameterSymbol("x", "The linear interpolation value, which is a floating-point number between 0.0 and 1.0 inclusive.", m, vectorType)
                        });
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Texture2D:
                case PredefinedObjectType.Texture2DArray:
                case PredefinedObjectType.TextureCube:
                case PredefinedObjectType.TextureCubeArray:
                    yield return new MethodDeclarationSymbol("Gather", "Gets the four samples (red component only) that would be used for bilinear interpolation when sampling a texture.", parent,
                        GetVectorType(scalarType, 4), m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType)
                        });
                    if (textureType == PredefinedObjectType.Texture2D || textureType == PredefinedObjectType.Texture2DArray)
                    {
                        yield return new MethodDeclarationSymbol("Gather", "Gets the four samples (red component only) that would be used for bilinear interpolation when sampling a texture.", parent,
                            GetVectorType(scalarType, 4), m => new[]
                            {
                                new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                                new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                new ParameterSymbol("offset", "An optional texture coordinate offset, which can be used for any texture-object types. The offset is applied to the location before sampling.", m, offsetType)
                            });
                    }
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                    yield return new MethodDeclarationSymbol("GetDimensions", "Gets the length of the buffer.", parent,
                        Void, m => new[]
                        {
                            new ParameterSymbol("dim", "The length, in bytes, of the buffer.", m, Uint, ParameterDirection.Out)
                        });
                    break;
                default:
                    yield return CreateTextureGetDimensionsWithMipLevelMethod(parent, textureType, Uint);
                    yield return CreateTextureGetDimensionsWithMipLevelMethod(parent, textureType, Float);
                    yield return CreateTextureGetDimensionsMethod(parent, textureType, Uint);
                    yield return CreateTextureGetDimensionsMethod(parent, textureType, Float);
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    yield return new MethodDeclarationSymbol("GetSamplePosition", "Gets the position of the specified sample.", parent,
                        Float2, m => new[]
                        {
                            new ParameterSymbol("sampleIndex", "The zero-based sample index.", m, Int)
                        });
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.TextureCube:
                case PredefinedObjectType.TextureCubeArray:
                    break;
                default:
                    TypeSymbol intLocationType;
                    switch (textureType)
                    {
                        case PredefinedObjectType.Buffer:
                            intLocationType = Int;
                            break;
                        case PredefinedObjectType.Texture1D:
                        case PredefinedObjectType.Texture2DMS:
                            intLocationType = Int2;
                            break;
                        case PredefinedObjectType.Texture1DArray:
                        case PredefinedObjectType.Texture2D:
                        case PredefinedObjectType.Texture2DMSArray:
                            intLocationType = Int3;
                            break;
                        case PredefinedObjectType.Texture2DArray:
                        case PredefinedObjectType.Texture3D:
                            intLocationType = Int4;
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    yield return new MethodDeclarationSymbol("Load", "Reads texel data without any filtering or sampling.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("location", "The texture coordinates; the last component specifies the mipmap level. This method uses a 0-based coordinate system and not a 0.0-1.0 UV system. ", m, intLocationType)
                        });
                    switch (textureType)
                    {
                        case PredefinedObjectType.Texture2DMS:
                        case PredefinedObjectType.Texture2DMSArray:
                            yield return new MethodDeclarationSymbol("Load", "Reads texel data without any filtering or sampling.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("location", "The texture coordinates; the last component specifies the mipmap level. This method uses a 0-based coordinate system and not a 0.0-1.0 UV system.", m, intLocationType),
                                    new ParameterSymbol("sampleIndex", "A sampling index.", m, Int),
                                    new ParameterSymbol("offset", "An offset applied to the texture coordinates before sampling.", m, offsetType)
                                });
                            break;
                        default:
                            yield return new MethodDeclarationSymbol("Load", "Reads texel data without any filtering or sampling.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("location", "The texture coordinates; the last component specifies the mipmap level. This method uses a 0-based coordinate system and not a 0.0-1.0 UV system.", m, intLocationType),
                                    new ParameterSymbol("offset", "An offset applied to the texture coordinates before sampling.", m, offsetType)
                                });
                            break;
                    }
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    break;
                default:
                    yield return new MethodDeclarationSymbol("Sample", "Samples a texture.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState), 
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType)
                        });
                    switch (textureType)
                    {
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            break;
                        default:
                            yield return new MethodDeclarationSymbol("Sample", "Samples a texture.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                                    new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                    new ParameterSymbol("offset", "A texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware.", m, offsetType)
                                });
                            break;
                    }
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    break;
                default:
                    yield return new MethodDeclarationSymbol("SampleBias", "Samples a texture, after applying the input bias to the mipmap level.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                            new ParameterSymbol("bias", "The bias value, which is a floating-point number between 0.0 and 1.0 inclusive, is applied to a mip level before sampling.", m, Float)
                        });
                    switch (textureType)
                    {
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            break;
                        default:
                            yield return new MethodDeclarationSymbol("SampleBias", "Samples a texture, after applying the input bias to the mipmap level.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                                    new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                    new ParameterSymbol("bias", "The bias value, which is a floating-point number between 0.0 and 1.0 inclusive, is applied to a mip level before sampling.", m, Float),
                                    new ParameterSymbol("offset", "A texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware.", m, offsetType)
                                });
                            break;
                    }
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                case PredefinedObjectType.Texture3D:
                    break;
                default:
                    yield return new MethodDeclarationSymbol("SampleCmp", "Samples a texture and compares a single component against the specified comparison value.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler-comparison state, which is the sampler state plus a comparison state (a comparison function and a comparison filter)", m, SamplerComparisonState),
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                            new ParameterSymbol("compareValue", "A floating-point value to use as a comparison value.", m, Float)
                        });
                    yield return new MethodDeclarationSymbol("SampleCmpLevelZero", "Samples a texture on mipmap level 0 only and compares a single component against the specified comparison value.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler-comparison state, which is the sampler state plus a comparison state (a comparison function and a comparison filter)", m, SamplerComparisonState),
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                            new ParameterSymbol("compareValue", "A floating-point value to use as a comparison value.", m, Float)
                        });
                    switch (textureType)
                    {
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            break;
                        default:
                            yield return new MethodDeclarationSymbol("SampleCmp", "Samples a texture and compares a single component against the specified comparison value.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("samplerState", "A sampler-comparison state, which is the sampler state plus a comparison state (a comparison function and a comparison filter)", m, SamplerComparisonState),
                                    new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                    new ParameterSymbol("compareValue", "A floating-point value to use as a comparison value.", m, Float),
                                    new ParameterSymbol("offset", "A texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware.", m, offsetType)
                                });
                            yield return new MethodDeclarationSymbol("SampleCmpLevelZero", "Samples a texture on mipmap level 0 only and compares a single component against the specified comparison value.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("samplerState", "A sampler-comparison state, which is the sampler state plus a comparison state (a comparison function and a comparison filter)", m, SamplerComparisonState),
                                    new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                    new ParameterSymbol("compareValue", "A floating-point value to use as a comparison value.", m, Float),
                                    new ParameterSymbol("offset", "A texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware.", m, offsetType)
                                });
                            break;
                    }
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    break;
                default:
                    TypeSymbol ddType;
                    switch (textureType)
                    {
                        case PredefinedObjectType.Texture1D:
                        case PredefinedObjectType.Texture1DArray:
                            ddType = Float;
                            break;
                        case PredefinedObjectType.Texture2D:
                        case PredefinedObjectType.Texture2DArray:
                            ddType = Float2;
                            break;
                        case PredefinedObjectType.Texture3D:
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            ddType = Float3;
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    yield return new MethodDeclarationSymbol("SampleGrad", "Samples a texture using a gradient to influence the way the sample location is calculated.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                            new ParameterSymbol("ddx", "The rate of change of the surface geometry in the x direction.", m, ddType),
                            new ParameterSymbol("ddy", "The rate of change of the surface geometry in the y direction.", m, ddType)
                        });
                    switch (textureType)
                    {
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            break;
                        default:
                            yield return new MethodDeclarationSymbol("SampleGrad", "Samples a texture using a gradient to influence the way the sample location is calculated.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                                    new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                    new ParameterSymbol("ddx", "The rate of change of the surface geometry in the x direction.", m, ddType),
                                    new ParameterSymbol("ddy", "The rate of change of the surface geometry in the y direction.", m, ddType),
                                    new ParameterSymbol("offset", "A texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware.", m, offsetType)
                                });
                            break;
                    }
                    break;
            }

            switch (textureType)
            {
                case PredefinedObjectType.Buffer:
                case PredefinedObjectType.Texture2DMS:
                case PredefinedObjectType.Texture2DMSArray:
                    break;
                default:
                    yield return new MethodDeclarationSymbol("SampleLevel", "Samples a texture using a mipmap-level offset.", parent,
                        valueType, m => new[]
                        {
                            new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                            new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                            new ParameterSymbol("lod", "A number that specifies the mipmap level. If the value is ≤ 0, the zero'th (biggest map) is used. The fractional value (if supplied) is used to interpolate between two mipmap levels.", m, Float)
                        });
                    switch (textureType)
                    {
                        case PredefinedObjectType.TextureCube:
                        case PredefinedObjectType.TextureCubeArray:
                            break;
                        default:
                            yield return new MethodDeclarationSymbol("SampleLevel", "Samples a texture using a mipmap-level offset.", parent,
                                valueType, m => new[]
                                {
                                    new ParameterSymbol("samplerState", "A sampler state.", m, SamplerState),
                                    new ParameterSymbol("location", "The texture coordinates.", m, locationType),
                                    new ParameterSymbol("lod", "A number that specifies the mipmap level. If the value is ≤ 0, the zero'th (biggest map) is used. The fractional value (if supplied) is used to interpolate between two mipmap levels.", m, Float),
                                    new ParameterSymbol("offset", "A texture coordinate offset, which can be used for any texture-object type; the offset is applied to the location before sampling. Use an offset only at an integer miplevel; otherwise, you may get results that do not translate well to hardware.", m, offsetType)
                                });
                            break;
                    }
                    break;
            }
        }