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()); } }
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())); }
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()); } }
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(); } }
public static bool Qualifies(LiteralExpressionSyntax node) { return node.CSharpKind() == SyntaxKind.StringLiteralExpression; }