Beispiel #1
0
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            if (IsNameOfOperator(node))
            {
                _output.TrivialWrite('"');
                this.Visit(node.ArgumentList);
                _output.TrivialWrite('"');
                return(node);
            }

            if (IsPartOfDynamic(node.Expression))
            {
                _output.Write(node.Expression, node.Expression.GetText().ToString().Trim());//Note: Dynamic, output without change
                this.AppendCompileIssue(node, IssueType.Warning, IssueId.DynamicType);
            }
            else
            {
                var symbol = this.GetSymbolOrOverloadSymbol(node.Expression);
                if (symbol.IsOperator())
                {
                    OperatorDefination def = symbol.GetOperatorDefination();
                    switch (def.Type)
                    {
                    case OperatorType.Unary:
                        if (def.Prefix)
                        {
                            _output.Write(node.Expression, def.Token);
                            this.MakeArgumentsList(node.ArgumentList.Arguments);
                        }
                        else
                        {
                            this.MakeArgumentsList(node.ArgumentList.Arguments);
                            _output.Write(node.Expression, def.Token);
                        }
                        break;

                    case OperatorType.Binary:
                        this.Visit(node.ArgumentList.Arguments[0]);
                        _output.Write(node.Expression, def.Token);
                        this.Visit(node.ArgumentList.Arguments[1]);
                        break;

                    case OperatorType.Unsupported:
                        this.AppendCompileIssue(node, IssueType.Error, IssueId.OnlyUnaryOrBinary, symbol.Name);
                        break;
                    }
                    return(node);
                }
                else
                {
                    this.VisitExpression(node.Expression);
                }
            }
            _output.TrivialWrite('(');
            this.MakeArgumentsList(node.ArgumentList.Arguments);
            _output.TrivialWrite(')');

            return(node);
        }
Beispiel #2
0
        public static OperatorDefination GetOperatorDefination(this ISymbol symbol)
        {
            OperatorDefination def = new OperatorDefination();
            var attrs = symbol.GetAttributes();

            foreach (var attr in attrs)
            {
                if (attr.AttributeClass.IsSameType(nameof(JavaScript), nameof(OperatorAttribute)))
                {
                    def.Token = (string)attr.ConstructorArguments[0].Value;
                    if (attr.ConstructorArguments.Length > 1)
                    {
                        switch ((int)attr.ConstructorArguments[1].Value)
                        {
                        case 1:
                            def.Type = OperatorType.Unary;
                            break;

                        case 2:
                            def.Type = OperatorType.Binary;
                            break;

                        default:
                            def.Type = OperatorType.Unsupported;
                            break;
                        }
                    }
                    else//Note: Default is Binary
                    {
                        def.Type = OperatorType.Binary;
                    }

                    if (attr.ConstructorArguments.Length > 2)
                    {
                        def.Prefix = (bool)attr.ConstructorArguments[2].Value;
                    }
                }
            }
            return(def);
        }
Beispiel #3
0
        public static OperatorDefination GetOperatorDefination(this ISymbol symbol)
        {
            OperatorDefination def = new OperatorDefination();
            var attrs = symbol.GetAttributes();
            foreach (var attr in attrs)
            {
                if (attr.AttributeClass.IsSameType(nameof(JavaScript), nameof(OperatorAttribute)))
                {
                    def.Token = (string)attr.ConstructorArguments[0].Value;
                    if (attr.ConstructorArguments.Length > 1)
                    {
                        switch ((int)attr.ConstructorArguments[1].Value)
                        {
                            case 1:
                                def.Type = OperatorType.Unary;
                                break;

                            case 2:
                                def.Type = OperatorType.Binary;
                                break;

                            default:
                                def.Type = OperatorType.Unsupported;
                                break;
                        }
                    }
                    else//Note: Default is Binary
                    {
                        def.Type = OperatorType.Binary;
                    }

                    if (attr.ConstructorArguments.Length > 2)
                    {
                        def.Prefix = (bool)attr.ConstructorArguments[2].Value;
                    }
                }
            }
            return def;
        }