[m-rev.] pragma foreign_decl #line fix

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 5 21:46:54 AEDT 2004


Estimated hours taken: 2
Branches: main

Generate correct line number directives for pragma foreign_decl,
and fix up the test suite to test this properly.

compiler/export.m:
	When outputting pragma foreign_decl declarations in .mh files,
	make sure that we generate appropriate #line directives.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/foreign_decl_line_number.m:
tests/invalid/foreign_type_line_number.m:
	Don't test "pragma foreign_type" using #error in
	foreign_decl_line_number.m, since #error isn't allowed in pragma
	foreign_type, and since using it there leads to a different error
	(C preprocessor directive inside macro invocation) on a different
	line.  Instead, move those tests to a different test case
	foreign_type_line_number.m.  Enable the foreign_decl_line_number.m
	test case, since we now pass it.

tests/invalid/foreign_decl_line_number.err_exp:
	Adjust to reflect changes to foreign_decl_line_number.m.

tests/invalid/foreign_decl_line_number.err_exp2:
	New file to reflect the output from GCC 3.2 and greater.
	This is the same as the .err_exp file, except that it also
	contains column numbers.

Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: compiler/export.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/export.m,v
retrieving revision 1.71
diff -u -d -r1.71 export.m
--- compiler/export.m	1 Dec 2003 15:55:33 -0000	1.71
+++ compiler/export.m	5 Jan 2004 10:09:02 -0000
@@ -75,6 +75,7 @@
 :- import_module backend_libs__foreign.
 :- import_module backend_libs__name_mangle.
 :- import_module backend_libs__proc_label.
+:- import_module backend_libs__c_util.
 :- import_module check_hlds__type_util.
 :- import_module hlds__error_util.
 :- import_module hlds__hlds_pred.
@@ -704,10 +705,14 @@
 
 :- pred output_foreign_decl(foreign_decl_code::in, io::di, io::uo) is det.
 
-export__output_foreign_decl(foreign_decl_code(Lang, Code, _Context)) -->
+export__output_foreign_decl(foreign_decl_code(Lang, Code, Context)) -->
 	( { Lang = c } ->
+		{ term__context_file(Context, File) },
+		{ term__context_line(Context, Line) },
+		c_util__set_line_num(File, Line),
 		io__write_string(Code),
-		io__nl
+		io__nl,
+		c_util__reset_line_num
 	;
 		[]
 	).
Index: tests/invalid/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mercury.options,v
retrieving revision 1.6
diff -u -d -r1.6 Mercury.options
--- tests/invalid/Mercury.options	12 Jun 2003 03:46:46 -0000	1.6
+++ tests/invalid/Mercury.options	5 Jan 2004 10:33:52 -0000
@@ -32,6 +32,7 @@
 MCFLAGS-exported_unify3 =	--no-intermodule-optimization \
 				--no-automatic-intermodule-optimization
 MCFLAGS-foreign_decl_line_number = --no-errorcheck-only --line-numbers --compile-only
+MCFLAGS-foreign_type_line_number = --no-errorcheck-only --line-numbers --compile-only
 MCFLAGS-foreign_singleton =	--halt-at-warn
 MCFLAGS-foreign_type =		--compile-only
 MCFLAGS-foreign_type_2 =	--no-intermodule-optimization \
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.145
diff -u -d -r1.145 Mmakefile
--- tests/invalid/Mmakefile	23 Dec 2003 03:33:39 -0000	1.145
+++ tests/invalid/Mmakefile	5 Jan 2004 10:31:58 -0000
@@ -65,6 +65,7 @@
 	ext_type_bug \
 	exported_mode \
 	field_syntax_error \
+	foreign_decl_line_number \
 	foreign_singleton \
 	foreign_type_2 \
 	foreign_type_visibility \
@@ -175,8 +176,10 @@
 
 
 # XXX we do not yet pass the following tests:
-#	foreign_decl_line_number (due to some errors being reported in .c
-#		files and .mh files rather than in .m files)
+#	foreign_type_line_number (due to some errors being reported in .c
+#		files and .mh files rather than in .m files,
+#		or being reported in .m files but at the line number of
+#		the pragma foreign_proc rather than the pragma foreign_type)
 #	duplicate_instance_3 (the error is only detected when doing
 #		normal static linking; the error goes undetected
 #		when doing dynamic linking, or when the library
@@ -234,6 +237,7 @@
 # We also pipe it through sed to remove "Mercury/cs/"; this
 # avoids spurious failures with --use-subdirs.
 foreign_decl_line_number.err: foreign_decl_line_number.m
+	rm -f foreign_decl_line_number.err
 	if $(MC) --errorcheck-only $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) \
 		foreign_decl_line_number.m \
 		> foreign_decl_line_number.err.orig 2>&1; \
@@ -241,6 +245,19 @@
 	grep '#error' foreign_decl_line_number.err.orig | \
 		sed 's at Mercury/cs/@@g' | sort -u \
 		> foreign_decl_line_number.err
+
+# Similarly for foreign_type_line_number, although in this case we
+# use "long short int" rather than #error, so we need to grep for that
+# instead.
+foreign_type_line_number.err: foreign_type_line_number.m
+	rm -f foreign_type_line_number.err
+	if $(MC) --errorcheck-only $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) \
+		foreign_type_line_number.m \
+		> foreign_type_line_number.err.orig 2>&1; \
+	then false; else true; fi
+	grep 'long.*short' foreign_type_line_number.err.orig | \
+		sed 's at Mercury/cs/@@g' | sort -u \
+		> foreign_type_line_number.err
 
 # For duplicate_instance_{1,2}, the error is only caught at link time.
 # So we need to use a different rule for that.
Index: tests/invalid/foreign_decl_line_number.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/foreign_decl_line_number.err_exp,v
retrieving revision 1.2
diff -u -d -r1.2 foreign_decl_line_number.err_exp
--- tests/invalid/foreign_decl_line_number.err_exp	4 Sep 2002 08:45:33 -0000	1.2
+++ tests/invalid/foreign_decl_line_number.err_exp	5 Jan 2004 09:31:42 -0000
@@ -1,4 +1,3 @@
-foreign_decl_line_number.m:14: #error Error in foreign decl
-foreign_decl_line_number.m:18: #error Error in foreign code
-foreign_decl_line_number.m:23: #error Error in foreign type
-foreign_decl_line_number.m:34: #error Error in foreign proc
+foreign_decl_line_number.m:19: #error Error in foreign decl
+foreign_decl_line_number.m:23: #error Error in foreign code
+foreign_decl_line_number.m:37: #error Error in foreign proc
Index: tests/invalid/foreign_decl_line_number.err_exp2
===================================================================
RCS file: tests/invalid/foreign_decl_line_number.err_exp2
diff -N tests/invalid/foreign_decl_line_number.err_exp2
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/foreign_decl_line_number.err_exp2	5 Jan 2004 09:32:39 -0000
@@ -0,0 +1,3 @@
+foreign_decl_line_number.m:19:2: #error Error in foreign decl
+foreign_decl_line_number.m:23:2: #error Error in foreign code
+foreign_decl_line_number.m:37:2: #error Error in foreign proc
Index: tests/invalid/foreign_decl_line_number.m
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/foreign_decl_line_number.m,v
retrieving revision 1.2
diff -u -d -r1.2 foreign_decl_line_number.m
--- tests/invalid/foreign_decl_line_number.m	4 Sep 2002 08:45:33 -0000	1.2
+++ tests/invalid/foreign_decl_line_number.m	5 Jan 2004 10:35:54 -0000
@@ -1,5 +1,10 @@
-% Check that we report the correct line number for the error in
-% foreign_decl.
+% Check that we report the correct line number for errors in
+% pragma foreign_decl, pragma foreign_code, and pragma foreign_proc.
+%
+% Note that we can't use #error in pragma foreign_type,
+% since C preprocessor declarations are not permitted there. 
+% So that case is tested separately in foreign_type_line_number.m.
+
 :- module foreign_decl_line_number.
 :- interface.
 
@@ -19,9 +24,7 @@
 ").
 
 :- type my_foreign_type.
-:- pragma foreign_type("C", my_foreign_type, "
-#error Error in foreign type
-").
+:- pragma foreign_type("C", my_foreign_type, "int").
 
 :- pragma export(bar(out,di,uo), "bar").
 :- pred bar(my_foreign_type::out, io::di,io::uo) is det.
Index: tests/invalid/foreign_type_line_number.m
===================================================================
RCS file: tests/invalid/foreign_type_line_number.m
diff -N tests/invalid/foreign_type_line_number.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/foreign_type_line_number.m	5 Jan 2004 10:35:54 -0000
@@ -0,0 +1,29 @@
+% Check that we report the correct line number for the error in
+% foreign_type.
+:- module foreign_type_line_number.
+:- interface.
+
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main --> foo(_).
+
+:- type my_foreign_type.
+:- pragma foreign_type("C", my_foreign_type, "
+/* We can't use #error here, since C preprocessor directives are
+   not permitted in pragma foreign_type.  So instead we just use
+   an invalid type name. */
+long short int
+").
+
+:- pragma export(bar(out,di,uo), "bar").
+:- pred bar(my_foreign_type::out, io::di,io::uo) is det.
+bar(X) --> foo(X).
+
+:- pred foo(my_foreign_type::out, io::di,io::uo) is det.
+:- pragma foreign_proc("C", foo(_output::out, _io0::di, _io::uo),
+	[will_not_call_mercury, promise_pure, thread_safe],
+"
+").

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list