From c34bbe7de7fc970d4e225252d521d4bdafde8296 Mon Sep 17 00:00:00 2001 From: Piotr Fusik Date: Mon, 6 Nov 2023 22:06:56 +0100 Subject: [PATCH] [main] Fix args indexing in C++. #73 --- GenCpp.fu | 3 +++ libfut.cpp | 3 +++ libfut.cs | 3 +++ libfut.js | 3 +++ test/MainArgs.fu | 2 +- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/GenCpp.fu b/GenCpp.fu index eda6b636..e9d5c3f8 100644 --- a/GenCpp.fu +++ b/GenCpp.fu @@ -459,7 +459,10 @@ public class GenCpp : GenCCpp switch (klass.Class.Id) { case FuId.ArrayStorageClass: if (klass.Id == FuId.MainArgsType) { + Include("string_view"); + Write("std::string_view("); WriteArgsIndexing(expr.Right); + WriteChar(')'); return; } break; diff --git a/libfut.cpp b/libfut.cpp index 6c928601..f854168a 100644 --- a/libfut.cpp +++ b/libfut.cpp @@ -13020,7 +13020,10 @@ void GenCpp::writeIndexingExpr(const FuBinaryExpr * expr, FuPriority parent) switch (klass->class_->id) { case FuId::arrayStorageClass: if (klass->id == FuId::mainArgsType) { + include("string_view"); + write("std::string_view("); writeArgsIndexing(expr->right.get()); + writeChar(')'); return; } break; diff --git a/libfut.cs b/libfut.cs index eaa3f800..e59623dc 100644 --- a/libfut.cs +++ b/libfut.cs @@ -13384,7 +13384,10 @@ protected override void WriteIndexingExpr(FuBinaryExpr expr, FuPriority parent) switch (klass.Class.Id) { case FuId.ArrayStorageClass: if (klass.Id == FuId.MainArgsType) { + Include("string_view"); + Write("std::string_view("); WriteArgsIndexing(expr.Right); + WriteChar(')'); return; } break; diff --git a/libfut.js b/libfut.js index 9e1d6729..f8a5a148 100644 --- a/libfut.js +++ b/libfut.js @@ -13808,7 +13808,10 @@ export class GenCpp extends GenCCpp switch (klass.class.id) { case FuId.ARRAY_STORAGE_CLASS: if (klass.id == FuId.MAIN_ARGS_TYPE) { + this.include("string_view"); + this.write("std::string_view("); this.writeArgsIndexing(expr.right); + this.writeChar(41); return; } break; diff --git a/test/MainArgs.fu b/test/MainArgs.fu index 167ebb1b..aa9c319f 100644 --- a/test/MainArgs.fu +++ b/test/MainArgs.fu @@ -2,7 +2,7 @@ public static class Runner { public static int Main(string[] args) //FAIL: cl { - if (args.Length == 2 && args[0] == "foo" && args[1] == "bar") { //FAIL: cpp swift TODO + if (args.Length == 2 && args[0] == "foo" && args[1] == "bar") { //FAIL: swift TODO int i = 0; foreach (string arg in args) { if (arg != (i == 0 ? "foo" : "bar"))