示例#1
0
        /// <summary>
        /// Loads the <see cref="ShaderClassType" />.
        /// </summary>
        /// <param name="shaderClassSource">The shader class source.</param>
        /// <param name="shaderMacros">The shader macros.</param>
        /// <param name="log">The log to output error logs.</param>
        /// <param name="modifiedShaders">The list of modified shaders.</param>
        /// <returns>A ShaderClassType or null if there was some errors.</returns>
        /// <exception cref="System.ArgumentNullException">shaderClassSource</exception>
        public ShaderClassType LoadClassSource(ShaderClassSource shaderClassSource, SiliconStudio.Shaders.Parser.ShaderMacro[] shaderMacros, LoggerResult log, HashSet <string> modifiedShaders = null)
        {
            if (shaderClassSource == null)
            {
                throw new ArgumentNullException("shaderClassSource");
            }

            string generics = null;

            if (shaderClassSource.GenericArguments != null)
            {
                generics = "";
                foreach (var gen in shaderClassSource.GenericArguments)
                {
                    generics += "___" + gen.ToString();
                }
            }
            var shaderClassType = LoadShaderClass(shaderClassSource.ClassName, generics, log, shaderMacros, modifiedShaders);

            if (shaderClassType == null)
            {
                return(null);
            }

            // Instantiate generic class
            if (shaderClassSource.GenericArguments != null)
            {
                if (shaderClassType.IsInstanciated)
                {
                    return(shaderClassType);
                }

                if (shaderClassSource.GenericArguments.Length != shaderClassType.ShaderGenerics.Count)
                {
                    log.Error(ParadoxMessageCode.WrongGenericNumber, shaderClassType.Span, shaderClassSource.ClassName);
                    return(null);
                }

                // check the name of the generics
                foreach (var generic in shaderClassType.ShaderGenerics)
                {
                    foreach (var genericCompare in shaderClassType.ShaderGenerics.Where(x => x != generic))
                    {
                        if (generic.Name.Text == genericCompare.Name.Text)
                        {
                            log.Error(ParadoxMessageCode.SameNameGenerics, generic.Span, generic, genericCompare, shaderClassSource.ClassName);
                        }
                    }
                }

                if (log.HasErrors)
                {
                    return(null);
                }

                var className = GenerateGenericClassName(shaderClassSource);
                shaderClassType.Name = new Identifier(className);
                var genericAssociation = CreateGenericAssociation(shaderClassType.ShaderGenerics, shaderClassSource.GenericArguments);
                var identifierGenerics = GenerateIdentifierFromGenerics(genericAssociation);
                var expressionGenerics = GenerateGenericsExpressionValues(shaderClassType.ShaderGenerics, shaderClassSource.GenericArguments);
                ParadoxClassInstanciator.Instanciate(shaderClassType, expressionGenerics, identifierGenerics, log);
                shaderClassType.ShaderGenerics.Clear();
                shaderClassType.IsInstanciated = true;
            }
            return(shaderClassType);
        }
        public static void Instanciate(ShaderClassType classType, Dictionary <string, Expression> expressions, Dictionary <string, Identifier> identifiers, LoggerResult log)
        {
            var instanciator = new ParadoxClassInstanciator(classType, expressions, identifiers, log);

            instanciator.Run();
        }