Ejemplo n.º 1
0
        public override string VisitIdentifierName(IdentifierNameSyntax node)
        {
            SymbolInfo symbolInfo         = GetModel(node).GetSymbolInfo(node);
            ISymbol    symbol             = symbolInfo.Symbol;
            string     containingTypeName = Utilities.GetFullName(symbolInfo.Symbol.ContainingType);

            if (containingTypeName == "ShaderGen.ShaderBuiltins")
            {
                TryRecognizeBuiltInVariable(symbolInfo);
            }
            if (symbol.Kind == SymbolKind.Field && containingTypeName == _containingTypeName)
            {
                string             symbolName         = symbol.Name;
                ResourceDefinition referencedResource = _backend.GetContext(_setName).Resources.Single(rd => rd.Name == symbolName);
                _resourcesUsed.Add(referencedResource);
                _shaderFunction.UsesTexture2DMS |= referencedResource.ValueType.Name == "ShaderGen.Texture2DMSResource";

                return(_backend.CorrectFieldAccess(symbolInfo));
            }
            else if (symbol.Kind == SymbolKind.Property)
            {
                return(_backend.FormatInvocation(_setName, containingTypeName, symbol.Name, Array.Empty <InvocationParameterInfo>()));
            }

            string mapped = _backend.CSharpToShaderIdentifierName(symbolInfo);

            return(_backend.CorrectIdentifier(mapped));
        }
Ejemplo n.º 2
0
        public override string VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
        {
            SymbolInfo exprSymbol = GetModel(node).GetSymbolInfo(node.Expression);

            if (exprSymbol.Symbol?.Kind == SymbolKind.NamedType)
            {
                SymbolInfo symbolInfo = GetModel(node).GetSymbolInfo(node);
                ISymbol    symbol     = symbolInfo.Symbol;

                // Enum field
                INamedTypeSymbol namedTypeSymbol = (INamedTypeSymbol)exprSymbol.Symbol;
                if (namedTypeSymbol.TypeKind == TypeKind.Enum)
                {
                    IFieldSymbol enumFieldSymbol     = (IFieldSymbol)symbol;
                    string       constantValueString = enumFieldSymbol.ConstantValue.ToString();
                    if (namedTypeSymbol.EnumUnderlyingType.SpecialType == SpecialType.System_UInt32)
                    {
                        // TODO: We need to do this for literal values too, if they don't already have this suffix,
                        // so this should be refactored.
                        constantValueString += "u";
                    }
                    return(constantValueString);
                }

                // Static member access
                if (symbol.Kind == SymbolKind.Property || symbol.Kind == SymbolKind.Field)
                {
                    return(Visit(node.Name));
                }

                string typeName   = Utilities.GetFullMetadataName(exprSymbol.Symbol);
                string targetName = Visit(node.Name);
                return(_backend.FormatInvocation(_setName, typeName, targetName, Array.Empty <InvocationParameterInfo>()));
            }
            else if (exprSymbol.Symbol is IFieldSymbol field)
            {
                var context = _backend.GetContext(_setName);
                if (context.Resources.Any(r => r.Name == field.Name && r.ResourceKind == ShaderResourceKind.Emit))
                {
                    return("out_" + Visit(node.Name));
                }
            }

            // Other accesses
            bool isIndexerAccess = (node.Expression is ElementAccessExpressionSyntax) ||
                                   _backend.IsIndexerAccess(GetModel(node).GetSymbolInfo(node.Name));

            string expr = Visit(node.Expression);
            string name = Visit(node.Name);

            return(expr + node.OperatorToken.ToFullString() + name);
        }