[m-rev.] diff: avoid some contextual keywords in C#
Julien Fischer
jfischer at opturion.com
Sat Jan 13 03:01:50 AEDT 2024
Avoid some contextual keywords in C#.
Using some of C#'s contextual keywords as Mercury names results in us
generating invalid C# code with recent versions of C# (e.g. "file" as a module
name). Escape such contextual keywords as we do the reserved keywords.
compiler/java_names.m:
Add some contextual keywords that cause problems in the generated C# to the
list of C# keywords we need to make safe.
library/io.file.m:
Conform to the above change.
Julien.
diff --git a/compiler/java_names.m b/compiler/java_names.m
index 42c2f3a..e8bfd09 100644
--- a/compiler/java_names.m
+++ b/compiler/java_names.m
@@ -262,6 +262,7 @@ make_valid_csharp_symbol_name(SymName) = ValidSymName :-
ValidSymName = SymName
).
+% This list is the reserved keywords in C#.
is_csharp_keyword("abstract").
is_csharp_keyword("as").
is_csharp_keyword("base").
@@ -340,6 +341,12 @@ is_csharp_keyword("volatile").
is_csharp_keyword("void").
is_csharp_keyword("while").
+% This is a partial list of contextual keywords in C# that we
+% may need to make safe.
+is_csharp_keyword("args").
+is_csharp_keyword("file").
+is_csharp_keyword("record").
+
csharp_mercury_runtime_package_name =
qualified(unqualified("mercury"), "runtime").
diff --git a/library/io.file.m b/library/io.file.m
index 3bf535c..cb0c408 100644
--- a/library/io.file.m
+++ b/library/io.file.m
@@ -988,18 +988,18 @@ file_type(FollowSymLinks, FileName, Result, !IO) :-
if ((attrs & System.IO.FileAttributes.Directory) ==
System.IO.FileAttributes.Directory)
{
- FileType = mercury.io__file.ML_FILE_TYPE_DIRECTORY;
+ FileType = mercury.io__mr_file.ML_FILE_TYPE_DIRECTORY;
}
else if ((attrs & System.IO.FileAttributes.Device) ==
System.IO.FileAttributes.Device)
{
// XXX It may be a block device, but .NET doesn't
// distinguish between character and block devices.
- FileType = mercury.io__file.ML_FILE_TYPE_CHARACTER_DEVICE;
+ FileType = mercury.io__mr_file.ML_FILE_TYPE_CHARACTER_DEVICE;
}
else
{
- FileType = mercury.io__file.ML_FILE_TYPE_REGULAR_FILE;
+ FileType = mercury.io__mr_file.ML_FILE_TYPE_REGULAR_FILE;
}
Error = null;
} catch (System.Exception e) {
More information about the reviews
mailing list