public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Include("format"); Write("std::format(\""); foreach (CiInterpolatedPart part in expr.Parts) { foreach (char c in part.Prefix) { if (c == '{') { Write("{{"); } else { WriteEscapedChar(c); } } if (part.Argument != null) { Write("{}"); } } Write('"'); WriteArgs(expr); Write(')'); return(expr); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Write("$\""); foreach (CiInterpolatedPart part in expr.Parts) { WriteEscapingBrace(part.Prefix); Write('{'); part.Argument.Accept(this, CiPriority.Statement); if (part.WidthExpr != null) { Write(','); Write(part.Width); } if (part.Format != ' ') { Write(':'); Write(part.Format); if (part.Precision >= 0) { Write(part.Precision); } } Write('}'); } WriteEscapingBrace(expr.Suffix); Write('"'); return(expr); }
protected void WriteArgs(CiInterpolatedString expr) { foreach (CiInterpolatedPart part in expr.Parts) { Write(", "); part.Argument.Accept(this, CiPriority.Statement); } }
protected void WriteArgs(CiInterpolatedString expr) { foreach (CiInterpolatedPart part in expr.Parts) { Write(", "); WriteInterpolatedStringArg(part.Argument); } }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Include("format"); Write("std::format(\""); foreach (CiInterpolatedPart part in expr.Parts) { WriteEscapingBrace(part.Prefix); Write("{}"); } WriteEscapingBrace(expr.Suffix); Write('"'); WriteArgs(expr); Write(')'); return(expr); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Write("f\""); foreach (CiInterpolatedPart part in expr.Parts) { WriteEscapingBrace(part.Prefix); Write('{'); part.Argument.Accept(this, CiPriority.Statement); if (part.WidthExpr != null || part.Precision >= 0 || (part.Format != ' ' && part.Format != 'D')) { Write(':'); } if (part.WidthExpr != null) { if (part.Width >= 0) { if (!(part.Argument.Type is CiNumericType)) { Write('>'); } Write(part.Width); } else { Write('<'); Write(-part.Width); } } if (part.Precision >= 0) { Write(part.Argument.Type is CiIntegerType ? '0' : '.'); Write(part.Precision); } if (part.Format != ' ' && part.Format != 'D') { Write(part.Format); } Write('}'); } WriteEscapingBrace(expr.Suffix); Write('"'); return(expr); }
protected void WritePrintf(CiInterpolatedString expr, bool newLine) { Write('"'); foreach (CiInterpolatedPart part in expr.Parts) { WritePrintfLiteral(part.Prefix); Write('%'); WritePrintfWidth(part); Write(GetPrintfFormat(part.Argument.Type, part.Format)); } WritePrintfLiteral(expr.Suffix); if (newLine) { Write("\\n"); } Write('"'); WriteArgs(expr); Write(')'); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { if (expr.Suffix.Length == 0 && expr.Parts.Length == 1 && expr.Parts[0].Prefix.Length == 0 && expr.Parts[0].WidthExpr == null && expr.Parts[0].Format == ' ') { CiExpr arg = expr.Parts[0].Argument; if (arg.Type == CiSystem.LongType) { Write("Long"); } else if (arg.Type == CiSystem.DoubleType || arg.Type == CiSystem.FloatIntType) { Write("Double"); } else if (arg.Type == CiSystem.FloatType) { Write("Float"); } else if (arg.Type is CiStringType) { arg.Accept(this, parent); return(expr); } else { Write("Integer"); } Write(".toString("); arg.Accept(this, CiPriority.Statement); Write(')'); } else { Write("String.format("); WritePrintf(expr, false); } return(expr); }
protected void WritePrintf(CiInterpolatedString expr, bool newLine) { Write('"'); foreach (CiInterpolatedPart part in expr.Parts) { foreach (char c in part.Prefix) { if (c == '%') { Write("%%"); } else { WriteEscapedChar(c); } } if (part.Argument != null) { Write('%'); if (part.WidthExpr != null) { Write(part.Width); } if (part.Format != ' ') { Write(part.Format); } else { Write(GetPrintfFormat(part.Argument.Type)); } } } if (newLine) { Write("\\n"); } Write('"'); WriteArgs(expr); Write(')'); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Write("$\""); foreach (CiInterpolatedPart part in expr.Parts) { foreach (char c in part.Prefix) { if (c == '{') { Write("{{"); } else { WriteEscapedChar(c); } } if (part.Argument != null) { Write('{'); part.Argument.Accept(this, CiPriority.Statement); if (part.WidthExpr != null) { Write(','); Write(part.Width); } if (part.Format != ' ') { Write(':'); Write(part.Format); } Write('}'); } } Write('"'); return(expr); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Write('`'); foreach (CiInterpolatedPart part in expr.Parts) { WriteInterpolatedLiteral(part.Prefix); Write("${"); if (part.Width != 0 || part.Format != ' ') { part.Argument.Accept(this, CiPriority.Primary); if (part.Argument.Type is CiNumericType) { switch (part.Format) { case 'E': Write(".toExponential("); if (part.Precision >= 0) { VisitLiteralLong(part.Precision); } Write(").toUpperCase()"); break; case 'e': Write(".toExponential("); if (part.Precision >= 0) { VisitLiteralLong(part.Precision); } Write(')'); break; case 'F': case 'f': Write(".toFixed("); if (part.Precision >= 0) { VisitLiteralLong(part.Precision); } Write(')'); break; case 'X': Write(".toString(16).toUpperCase()"); break; case 'x': Write(".toString(16)"); break; default: Write(".toString()"); break; } if (part.Precision >= 0 && "DdXx".IndexOf(part.Format) >= 0) { Write(".padStart("); VisitLiteralLong(part.Precision); Write(", \"0\")"); } } if (part.Width > 0) { Write(".padStart("); VisitLiteralLong(part.Width); Write(')'); } else if (part.Width < 0) { Write(".padEnd("); VisitLiteralLong(-part.Width); Write(')'); } } else { part.Argument.Accept(this, CiPriority.Argument); } Write('}'); } WriteInterpolatedLiteral(expr.Suffix); Write('`'); return(expr); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { throw new NotImplementedException("Interpolated strings not supported in OpenCL C"); }
public override CiExpr Visit(CiInterpolatedString expr, CiPriority parent) { Write('`'); foreach (CiInterpolatedPart part in expr.Parts) { string s = part.Prefix; for (int i = 0; i < s.Length; i++) { char c = s[i]; if (c == '`' || (c == '$' && i + 1 < s.Length && s[i + 1] == '{')) { Write('\\'); } WriteEscapedChar(c); } if (part.Argument != null) { Write("${"); if (part.Width != 0 || part.Format != ' ') { part.Argument.Accept(this, CiPriority.Primary); if (part.Argument.Type is CiNumericType) { switch (part.Format) { case 'x': Write(".toString(16)"); break; case 'X': Write(".toString(16).toUpperCase()"); break; default: Write(".toString()"); break; } } if (part.Width > 0) { Write(".padStart("); Write(part.Width); Write(')'); } else if (part.Width < 0) { Write(".padEnd("); Write(-part.Width); Write(')'); } } else { part.Argument.Accept(this, CiPriority.Statement); } Write('}'); } } Write('`'); return(expr); }
public abstract CiExpr Visit(CiInterpolatedString expr, CiPriority parent);