Exemplo n.º 1
0
        /// <summary>
        /// Check for any inline "out" variable declarations in this statement - i.e. MyFunc(out var result) -
        /// and declare those variables now.
        /// </summary>
        private string DeclareInlineOutVariables(StatementSyntax statement)
        {
            StringBuilder sb = new StringBuilder();

            IEnumerable <SyntaxNode> declarationExpressionNodes = statement
                                                                  .DescendantNodes(x => !x.IsKind(SyntaxKind.Block)) // Don't descend into child blocks
                                                                  .Where(x => x.IsKind(SyntaxKind.DeclarationExpression));

            foreach (DeclarationExpressionSyntax declarationExpressionNode in declarationExpressionNodes)
            {
                string varType    = _compilation.GetSemanticModel(declarationExpressionNode.Type.SyntaxTree).GetFullTypeName(declarationExpressionNode.Type);
                string mappedType = _backend.CSharpToShaderType(varType);

                sb.Append("    ");
                sb.Append(mappedType);
                sb.Append(' ');

                switch (declarationExpressionNode.Designation)
                {
                case SingleVariableDesignationSyntax svds:
                    string identifier = _backend.CorrectIdentifier(svds.Identifier.Text);
                    sb.Append(identifier);
                    sb.Append(';');
                    sb.AppendLine();
                    break;

                default:
                    throw new NotImplementedException($"{declarationExpressionNode.Designation.GetType()} designations are not implemented.");
                }
            }

            return(sb.ToString());
        }
        protected virtual string GetFunctionDeclStr()
        {
            string returnType   = _backend.CSharpToShaderType(_shaderFunction.ReturnType.Name);
            string fullDeclType = _backend.CSharpToShaderType(_shaderFunction.DeclaringType);
            string funcName     = _shaderFunction.IsEntryPoint
                ? _shaderFunction.Name
                : fullDeclType + "_" + _shaderFunction.Name;

            return($"{returnType} {funcName}({GetParameterDeclList()})");
        }