Beispiel #1
0
        public override IExpression VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            var o = this.semanticModel.GetTypeInfo(node);

            switch (node.CSharpKind())
            {
            case SyntaxKind.NumericLiteralExpression:
            case SyntaxKind.CharacterLiteralExpression:
            case SyntaxKind.FalseLiteralExpression:
            case SyntaxKind.StringLiteralExpression:
            case SyntaxKind.TrueLiteralExpression:
                return(new CompileTimeConstant()
                {
                    Type = mapper.Map(o.Type), Value = node.Token.Value,
                });

            case SyntaxKind.NullLiteralExpression:
                return(new CompileTimeConstant()
                {
                    Type = this.host.PlatformType.SystemObject, Value = null,
                });

            default:
                throw new InvalidDataException("VisitPrimaryExpression passed an unknown node kind: " + node.CSharpKind());
            }
        }
Beispiel #2
0
        public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            if (node.CSharpKind() != SyntaxKind.StringLiteralExpression)
            {
                return(node);
            }

            var pos    = node.GetLocation().GetMappedLineSpan();
            var result = OnRewrite(pos.StartLinePosition.Line + 1, pos.StartLinePosition.Character + 1, Utils.EscapeString(node.Token.ValueText));

            if (result == null)
            {
                return(node);
            }

            ExpressionSyntax newNode = null;

            foreach (var name in result.Split('.'))
            {
                if (newNode == null)
                {
                    newNode = SyntaxFactory.IdentifierName(name);
                }
                else
                {
                    newNode = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, newNode, SyntaxFactory.IdentifierName(name));
                }
            }

            return(newNode.WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()));
        }
Beispiel #3
0
        public static string LiteralExpression(LiteralExpressionSyntax node)
        {
            switch (node.CSharpKind())
            {
            case SyntaxKind.CharacterLiteralExpression:
                //this is sketch, probably shouldn't use char literals o.o
                return('"' + node.Token.ValueText.Replace("\\'", "'").Replace("\"", "\\\"") + '"');

            default:
                return(node.ToString());
            }
        }
        public static string LiteralExpression(LiteralExpressionSyntax expression)
        {
            switch (expression.CSharpKind())
            {
            //Swift doesn't use the same 'c' character literal syntax, instead you create a String and type annotate it as a Character
            case SyntaxKind.CharacterLiteralExpression:
                //this is sketch, probably shouldn't use char literals o.o
                return('"' + expression.Token.ValueText.Replace("\\'", "'").Replace("\"", "\\\"") + '"');

            default:
                return(expression.ToString());
            }
        }
Beispiel #5
0
        public override SyntaxNode VisitLiteralExpression(LiteralExpressionSyntax node)
        {
            if (node.CSharpKind() != SyntaxKind.StringLiteralExpression) return node;

            var pos = node.GetLocation().GetMappedLineSpan();
            var result = OnRewrite(pos.StartLinePosition.Line + 1, pos.StartLinePosition.Character + 1, Source.Lines[pos.StartLinePosition.Line].ToString(), node.Token.ValueText);
            if (result == null) return node;

            var names = result.Split('.');
            ExpressionSyntax newNode = SyntaxFactory.IdentifierName(names.First());
            foreach (var name in names.Skip(1))
            {
                newNode = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, newNode, SyntaxFactory.IdentifierName(name));
            }

            return newNode.WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia());
        }
 public static string LiteralExpression(LiteralExpressionSyntax expression)
 {
     switch (expression.CSharpKind())
     {
         //Swift doesn't use the same 'c' character literal syntax, instead you create a String and type annotate it as a Character
         case SyntaxKind.CharacterLiteralExpression:
             //this is sketch, probably shouldn't use char literals o.o
             return '"' + expression.Token.ValueText.Replace("\\'", "'").Replace("\"", "\\\"") + '"';
         default:
             return expression.ToString();
     }
 }
Beispiel #7
0
 public static bool Qualifies(LiteralExpressionSyntax node)
 {
     return node.CSharpKind() == SyntaxKind.StringLiteralExpression;
 }