[m-dev.] diff: add test case for keywords as module names

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 8 00:50:35 AEDT 2001


Estimated hours taken: 0.25

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/class.m:
tests/hard_coded/sub-modules/class.exp:
	Add a test case that uses `class', `int', and `char' as module names.
	This test case is testing that module names which have the
	same syntax as keywords in the target language get properly
	mangled/escaped.

Workspace: /home/venus/fjh/ws-venus2/mercury
Index: tests/hard_coded/sub-modules/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/sub-modules/Mmakefile,v
retrieving revision 1.2
diff -u -d -r1.2 Mmakefile
--- tests/hard_coded/sub-modules/Mmakefile	2000/04/05 06:12:04	1.2
+++ tests/hard_coded/sub-modules/Mmakefile	2001/02/07 13:46:31
@@ -23,6 +23,7 @@
 	nested \
 	nested2 \
 	nested3 \
+	class \
 	nested_intermod_main
 
 MCFLAGS-nested_intermod	=	--intermodule-optimization
Index: tests/hard_coded/sub-modules/class.exp
===================================================================
RCS file: class.exp
diff -N class.exp
--- /dev/null	Fri Feb  2 11:58:58 2001
+++ class.exp	Thu Feb  8 00:45:46 2001
@@ -0,0 +1,15 @@
+class:char:hello
+class:char:hello
+class:char:hello
+class:int:hello
+class:int:hello
+t1 = class:char:foo
+t2 = class:char:foo
+t3 = class:char:foo
+t4 = class:int:foo
+t5 = class:int:foo
+has_type_t1 = bar
+has_type_t2 = bar
+has_type_t3 = bar
+has_type_t4 = bar
+has_type_t5 = bar
Index: tests/hard_coded/sub-modules/class.m
===================================================================
RCS file: class.m
diff -N class.m
--- /dev/null	Fri Feb  2 11:58:58 2001
+++ class.m	Thu Feb  8 00:44:58 2001
@@ -0,0 +1,92 @@
+% This test case tests the use of module names that are C/C++/Java
+% keywords, namely `int', `char', and `class'.  These might cause
+% problems for back-ends targetting C/Java.
+
+:- module class.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+%-----------------------------------------------------------------------------%
+
+:- module class:char.
+:- interface.
+:- import_module io.
+
+:- type foo ---> bar ; baz(int).
+
+:- pred hello(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+hello --> io__write_string("class:char:hello\n").
+
+:- end_module class:char.
+
+%-----------------------------------------------------------------------------%
+
+:- module class:int.
+:- interface.
+:- import_module io.
+
+:- type foo ---> bar ; baz(int).
+
+:- pred hello(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+hello --> io__write_string("class:int:hello\n").
+
+:- end_module class:int.
+
+%-----------------------------------------------------------------------------%
+
+% now we're back in the parent module.
+
+:- import_module class:char.
+:- use_module class:int.
+:- import_module std_util, require.
+
+:- type t1 == class:char:foo.
+:- type t2 == char:foo.
+:- type t3 == foo.
+:- type t4 == class:int:foo.
+:- type t5 == int:foo.
+
+main -->
+	class:char:hello,
+	char:hello,
+	hello,
+	class:int:hello,
+	int:hello,
+
+	print("t1 = "), print(type_of(has_type_t1)), nl,
+	print("t2 = "), print(type_of(has_type_t2)), nl,
+	print("t3 = "), print(type_of(has_type_t3)), nl,
+	print("t4 = "), print(type_of(has_type_t4)), nl,
+	print("t5 = "), print(type_of(has_type_t5)), nl,
+
+	print("has_type_t1 = "), print(has_type_t1), nl,
+	print("has_type_t2 = "), print(has_type_t2), nl,
+	print("has_type_t3 = "), print(has_type_t3), nl,
+	print("has_type_t4 = "), print(has_type_t4), nl,
+	print("has_type_t5 = "), print(has_type_t5), nl,
+
+	{ true }.
+
+:- func has_type_t1 = t1.
+:- func has_type_t2 = t2.
+:- func has_type_t3 = t3.
+:- func has_type_t4 = t4.
+:- func has_type_t5 = t5.
+
+has_type_t1 = class:char:bar.
+has_type_t2 = char:bar.
+has_type_t3 = bar.
+has_type_t4 = class:int:bar.
+has_type_t5 = int:bar.
+
+:- end_module class.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list