Exemplo n.º 1
0
        private BoundExpression BindNumericConstructorInvocationExpression(NumericConstructorInvocationExpressionSyntax syntax)
        {
            var boundArguments = BindArgumentList(syntax.ArgumentList);
            var argumentTypes  = boundArguments.Select(a => a.Type).ToImmutableArray();

            var typeSymbol = BindType(syntax.Type, null).TypeSymbol;

            Debug.Assert(typeSymbol.IsError() == false);

            var anyErrorsInArguments = argumentTypes.Any(a => a.IsError());

            if (anyErrorsInArguments)
            {
                return(new BoundNumericConstructorInvocationExpression(syntax, typeSymbol, boundArguments, OverloadResolutionResult <FunctionSymbolSignature> .None));
            }

            var result = LookupNumericConstructor(typeSymbol, argumentTypes);

            if (result.Best == null)
            {
                if (result.Selected == null)
                {
                    Diagnostics.ReportUndeclaredNumericConstructor(syntax, argumentTypes);
                    return(new BoundErrorExpression());
                }

                var symbol1 = result.Selected.Signature.Symbol;
                var symbol2 = result.Candidates.First(c => !c.Signature.Symbol.Equals(symbol1)).Signature.Symbol;
                Diagnostics.ReportAmbiguousInvocation(syntax.GetTextSpanSafe(), symbol1, symbol2, argumentTypes);
            }

            var convertedArguments = boundArguments.Select((a, i) => BindArgument(a, result, i, syntax.ArgumentList.Arguments[i].GetTextSpanSafe())).ToImmutableArray();

            return(new BoundNumericConstructorInvocationExpression(syntax, typeSymbol, convertedArguments, result));
        }
 public BoundNumericConstructorInvocationExpression(NumericConstructorInvocationExpressionSyntax syntax, TypeSymbol type, ImmutableArray<BoundExpression> arguments, OverloadResolutionResult<FunctionSymbolSignature> result)
     : base(BoundNodeKind.NumericConstructorInvocationExpression)
 {
     Syntax = syntax;
     Type = type;
     Arguments = arguments;
     Result = result;
 }
 public BoundNumericConstructorInvocationExpression(NumericConstructorInvocationExpressionSyntax syntax, TypeSymbol type, ImmutableArray <BoundExpression> arguments, OverloadResolutionResult <FunctionSymbolSignature> result)
     : base(BoundNodeKind.NumericConstructorInvocationExpression)
 {
     Syntax    = syntax;
     Type      = type;
     Arguments = arguments;
     Result    = result;
 }
Exemplo n.º 4
0
 public static void ReportUndeclaredNumericConstructor(this ICollection<Diagnostic> diagnostics, NumericConstructorInvocationExpressionSyntax node, IEnumerable<TypeSymbol> argumentTypes)
 {
     var name = node.Type.ToStringIgnoringMacroReferences();
     var argumentTypeList = string.Join(@", ", argumentTypes.Select(t => t.ToDisplayName()));
     diagnostics.Report(node.GetTextSpanSafe(), DiagnosticId.UndeclaredFunction, name, argumentTypeList);
 }
        public static void ReportOverloadResolutionFailure(this ICollection <Diagnostic> diagnostics, NumericConstructorInvocationExpressionSyntax node, int argumentCount)
        {
            var name = node.Type.ToStringIgnoringMacroReferences();

            diagnostics.Report(node.SourceRange, DiagnosticId.FunctionOverloadResolutionFailure, name, argumentCount);
        }
        public static void ReportUndeclaredNumericConstructor(this ICollection <Diagnostic> diagnostics, NumericConstructorInvocationExpressionSyntax node, IEnumerable <TypeSymbol> argumentTypes)
        {
            var name             = node.Type.ToStringIgnoringMacroReferences();
            var argumentTypeList = string.Join(@", ", argumentTypes.Select(t => t.ToDisplayName()));

            diagnostics.Report(node.SourceRange, DiagnosticId.UndeclaredFunction, name, argumentTypeList);
        }
Exemplo n.º 7
0
 public virtual void VisitNumericConstructorInvocation(NumericConstructorInvocationExpressionSyntax node)
 {
     DefaultVisit(node);
 }
Exemplo n.º 8
0
 public virtual void VisitNumericConstructorInvocation(NumericConstructorInvocationExpressionSyntax node)
 {
     DefaultVisit(node);
 }
        private bool ParseVariableDeclarationStatementSyntax(VariableDeclarationStatementSyntax syntax, List <string> registers)
        {
            VariableDeclarationSyntax varDeclaration = syntax.Declaration;

            TypeSyntax type = varDeclaration.Type;

            foreach (VariableDeclaratorSyntax var in varDeclaration.Variables)
            {
                AnnotationFactory.BeginVar();
                AnnotationFactory.SetModifiers(varDeclaration.Modifiers);

                if (AnnotationFactory.IsGroupOpen())
                {
                    AnnotationFactory.SetType(type);
                    AnnotationFactory.SetAnnotations(var.Annotations?.Annotations ?? null);
                    InitializerSyntax initializer = var.Initializer;
                    if (varDeclaration.Variables[0].ArrayRankSpecifiers.Count > 0)
                    {
                        LiteralExpressionSyntax litExpressionSyntax = varDeclaration.Variables[0].ArrayRankSpecifiers[0].Dimension as LiteralExpressionSyntax;
                        AnnotationFactory.SetDimension((int)litExpressionSyntax.Token.Value);
                    }
                    if (initializer != null && initializer is EqualsValueClauseSyntax)
                    {
                        EqualsValueClauseSyntax evcSyntax = (EqualsValueClauseSyntax)initializer;
                        if (evcSyntax.Value is NumericConstructorInvocationExpressionSyntax)
                        {
                            NumericConstructorInvocationExpressionSyntax ncieSyntax = (NumericConstructorInvocationExpressionSyntax)evcSyntax.Value;
                            SeparatedSyntaxList <ExpressionSyntax>       arguments  = ncieSyntax.ArgumentList.Arguments;
                        }
                        else if (evcSyntax.Value is LiteralExpressionSyntax)
                        {
                        }
                    }

                    SyntaxToken name = var.Identifier;
                    AnnotationFactory.SetName(name.ValueText);
                    foreach (var qualifier in var.Qualifiers)
                    {
                        if (qualifier is RegisterLocation)
                        {
                            string register = ((RegisterLocation)qualifier).Register.ValueText;
                            if (registers.Contains(register))
                            {
                                MessageBox.Show($"Register: {register}\nDefined multiple times, ShaderBox can not decides which one needs to be binded.\n\nWill be resolved in a future release.", "Unsupported operation", MessageBoxButton.OK, MessageBoxImage.Error);
                                AnnotationFactory.DestroyGroup();
                                return(false);
                            }
                            AnnotationFactory.SetRegister(register);
                        }
                    }
                    if (string.IsNullOrWhiteSpace(AnnotationFactory.GetRegister()))
                    {
                        AnnotationFactory.DestroyGroup();
                    }
                    else
                    {
                        AnnotationFactory.EndVar();
                    }
                }
            }

            return(true);
        }