public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            var propertySymbol = GetDeclaredSymbol(node) as IPropertySymbol;
            var attributes     = mFrontEnd.ParseAttributes(propertySymbol);

            foreach (var fieldAttribute in propertySymbol.GetAttributes())
            {
                var attributeName = TypeAliases.GetFullTypeName(fieldAttribute.AttributeClass);
                var processor     = SpecialResolvers.FieldProcessors.GetValueOrDefault(attributeName);
                processor?.Invoke(mFrontEnd, propertySymbol.ContainingType, propertySymbol, fieldAttribute);
            }
        }
 public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
 {
     foreach (var variable in node.Declaration.Variables)
     {
         var fieldSymbol = GetDeclaredSymbol(variable) as IFieldSymbol;
         var attributes  = mFrontEnd.ParseAttributes(fieldSymbol);
         foreach (var fieldAttribute in fieldSymbol.GetAttributes())
         {
             var attributeName = TypeAliases.GetFullTypeName(fieldAttribute.AttributeClass);
             var processor     = SpecialResolvers.FieldProcessors.GetValueOrDefault(attributeName);
             processor?.Invoke(mFrontEnd, fieldSymbol.ContainingType, fieldSymbol, fieldAttribute);
         }
     }
 }
예제 #3
0
 public bool TryProcessIntrinsicMethod(FrontEndTranslator translator, IMethodSymbol methodSymbol)
 {
     foreach (var fieldAttribute in methodSymbol.GetAttributes())
     {
         var attributeName = TypeAliases.GetFullTypeName(fieldAttribute.AttributeClass);
         var processor     = MethodProcessors.GetValueOrDefault(attributeName);
         if (processor != null)
         {
             processor?.Invoke(translator, methodSymbol.ContainingType, methodSymbol, fieldAttribute);
             return(true);
         }
     }
     return(false);
 }
        public ShaderType CreatePrimitiveShaderType(INamedTypeSymbol typeSymbol, ShaderAttributes attributes)
        {
            ShaderType shaderType = null;

            // If there's a special resolver for this type then use that to get the shader type
            foreach (var attribute in typeSymbol.GetAttributes())
            {
                var attributeName = TypeAliases.GetFullTypeName(attribute.AttributeClass);
                var processor     = SpecialResolvers.SpecialTypeCreationAttributeProcessors.GetValueOrDefault(attributeName);
                shaderType = processor?.Invoke(mFrontEnd, typeSymbol, attribute);
                if (shaderType != null)
                {
                    return(shaderType);
                }
            }
            throw new Exception("Failed to create primitive");
        }
        public override void VisitStructDeclaration(StructDeclarationSyntax node)
        {
            var structSymbol = GetDeclaredSymbol(node) as INamedTypeSymbol;
            var attributes   = mFrontEnd.ParseAttributes(structSymbol);

            // If the type has a special primitive attribute then queue it up for processing
            foreach (var attribute in structSymbol.GetAttributes())
            {
                int priority      = 0;
                var attributeName = TypeAliases.GetFullTypeName(attribute.AttributeClass);
                if (PrimitiveAttributePriorities.TryGetValue(attributeName, out priority))
                {
                    var data = new PrimitiveData();
                    data.Priority     = priority;
                    data.Node         = node;
                    data.StructSymbol = structSymbol;
                    PrimitivesToProcess.Add(data);
                }
            }
        }
예제 #6
0
 public SpecialResolvers()
 {
     // Setup a few special processing functors here
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.IntegerPrimitive>(), IntegerResolvers.ProcessIntegerType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.FloatPrimitive>(), FloatResolvers.ProcessFloatType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.VectorPrimitive>(), VectorResolvers.ProcessVectorType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.MatrixPrimitive>(), MatrixResolvers.ProcessMatrixType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.FixedArrayPrimitive>(), FixedArrayResolver.ProcessFixedArrayType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Shader.SamplerPrimitive>(), SamplerResolvers.ProcessSamplerType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Shader.ImagePrimitive>(), ImageResolvers.ProcessImageType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Shader.SampledImagePrimitive>(), SampledSamplerResolvers.ProcessSampledImageType);
     FieldProcessors.Add(TypeAliases.GetFullTypeName <Math.Swizzle>(), VectorResolvers.ProcessVectorSwizzle);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.SimpleIntrinsicFunction>(), CreateSimpleIntrinsicType);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.ArrayGetIntrinsic>(), CreateArrayGetType);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.ArraySetIntrinsic>(), CreateArraySetType);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Math.CompositeConstruct>(), CreateCompositeConstructIntrinsic);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.SampledImageIntrinsicFunction>(), SampledImageIntrinsicResolvers.CreateSampledImageIntrinsicFunction);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.ImageIntrinsicFunction>(), ImageIntrinsicResolvers.CreateImageIntrinsicFunction);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.SimpleExtensionIntrinsic>(), ExtensionIntrinsicResolvers.ProcessSimpleExtensionIntrinsic);
 }
예제 #7
0
 public TypeKey(ISymbol symbol)
 {
     mKey = TypeAliases.GetFullTypeName(symbol);
 }
예제 #8
0
 public TypeKey(Type type)
 {
     mKey = TypeAliases.GetFullTypeName(type);
 }
예제 #9
0
        public ShaderAttributes ParseAttributes(ISymbol symbol)
        {
            var shaderAttributes = new ShaderAttributes();

            foreach (var attribute in symbol.GetAttributes())
            {
                var shaderAttribute = new ShaderAttribute();
                shaderAttributes.Add(shaderAttribute);
                shaderAttribute.Name      = TypeAliases.GetTypeName(attribute.AttributeClass);
                shaderAttribute.Attribute = attribute;

                foreach (var argument in attribute.ConstructorArguments)
                {
                    var shaderAttributeParam = new ShaderAttributeParameter();
                    shaderAttribute.Parameters.Add(shaderAttributeParam);
                    if (argument.Kind != TypedConstantKind.Array)
                    {
                        shaderAttributeParam.Value = argument.Value;
                    }
                }
                foreach (var argument in attribute.NamedArguments)
                {
                    var shaderAttributeParam = new ShaderAttributeParameter();
                    shaderAttribute.Parameters.Add(shaderAttributeParam);
                    shaderAttributeParam.Name  = argument.Key;
                    shaderAttributeParam.Value = argument.Value.Value;
                }

                if (TypeAliases.GetFullTypeName(attribute.AttributeClass) == TypeAliases.GetFullTypeName <Shader.Input>())
                {
                    var inputAttributes = new List <TypeName>
                    {
                        TypeAliases.GetTypeName <Shader.FragmentInput>(),
                        TypeAliases.GetTypeName <Shader.StageInput>(),
                        TypeAliases.GetTypeName <Shader.AppBuiltInInput>(),
                        TypeAliases.GetTypeName <Shader.HardwareBuiltInInput>(),
                        TypeAliases.GetTypeName <Shader.PropertyInput>(),
                    };
                    foreach (var inputAttribute in inputAttributes)
                    {
                        var clone = shaderAttribute.Clone();
                        clone.Name = inputAttribute;
                        shaderAttributes.Add(clone);
                    }
                }
                if (TypeAliases.GetFullTypeName(attribute.AttributeClass) == TypeAliases.GetFullTypeName <Shader.Output>())
                {
                    var outputAttributes = new List <TypeName>
                    {
                        TypeAliases.GetTypeName <Shader.FragmentOutput>(),
                        TypeAliases.GetTypeName <Shader.StageOutput>(),
                        TypeAliases.GetTypeName <Shader.HardwareBuiltInOutput>(),
                    };
                    foreach (var outputAttribute in outputAttributes)
                    {
                        var clone = shaderAttribute.Clone();
                        clone.Name = outputAttribute;
                        shaderAttributes.Add(clone);
                    }
                }
            }
            return(shaderAttributes);
        }