[m-rev.] diff: add contexts to MC++

Tyson Dowd trd at cs.mu.OZ.AU
Wed Apr 11 19:04:38 AEST 2001


Hi,

Another diff from the DevLab.

===================================================================


Estimated hours taken: 0.5
Branches: main dotnet-foreign

Add context information to Managed C++.

compiler/mlds_to_c.m:
	Export mlds_to_c__output_context.

compiler/mlds_to_ilasm.m:
	Write contexts before writing code.


Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.83.4.1
diff -u -r1.83.4.1 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/04/09 14:08:23	1.83.4.1
+++ compiler/mlds_to_c.m	2001/04/11 08:58:04
@@ -25,6 +25,13 @@
 :- pred mlds_to_c__output_mlds(mlds, io__state, io__state).
 :- mode mlds_to_c__output_mlds(in, di, uo) is det.
 
+	% output an MLDS context in C #line format. 
+	% this is useful for other foreign language interfaces such as
+	% managed extensions for C++.
+:- pred mlds_to_c__output_context(mlds__context, io__state, io__state).
+:- mode mlds_to_c__output_context(in, di, uo) is det.
+
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
@@ -518,7 +525,7 @@
 mlds_output_c_hdr_decl(_Indent, foreign_decl_code(Lang, Code, Context)) -->
 		% only output C code in the C header file.
 	( { Lang = c } ->
-		mlds_output_context(mlds__make_context(Context)),
+		mlds_to_c__output_context(mlds__make_context(Context)),
 		io__write_string(Code)
 	;
 		{ sorry(this_file, "foreign code other than C") }
@@ -549,7 +556,7 @@
 :- mode mlds_output_c_defn(in, in, di, uo) is det.
 
 mlds_output_c_defn(_Indent, user_foreign_code(c, Code, Context)) -->
-	mlds_output_context(mlds__make_context(Context)),
+	mlds_to_c__output_context(mlds__make_context(Context)),
 	io__write_string(Code).
 mlds_output_c_defn(_Indent, user_foreign_code(managed_cplusplus, _, _)) -->
 	{ sorry(this_file, "foreign code other than C") }.
@@ -1866,7 +1873,7 @@
 :- mode mlds_output_statement(in, in, in, di, uo) is det.
 
 mlds_output_statement(Indent, FuncInfo, mlds__statement(Statement, Context)) -->
-	mlds_output_context(Context),
+	mlds_to_c__output_context(Context),
 	mlds_output_stmt(Indent, FuncInfo, Statement, Context).
 
 :- pred mlds_output_stmt(indent, func_info, mlds__stmt, mlds__context,
@@ -2494,28 +2501,28 @@
 mlds_output_target_code_component(Context,
 		user_target_code(CodeString, MaybeUserContext)) -->
 	( { MaybeUserContext = yes(UserContext) } ->
-		mlds_output_context(mlds__make_context(UserContext))
+		mlds_to_c__output_context(mlds__make_context(UserContext))
 	;
-		mlds_output_context(Context)
+		mlds_to_c__output_context(Context)
 	),
 	io__write_string(CodeString),
 	io__write_string("\n").
 mlds_output_target_code_component(Context, raw_target_code(CodeString)) -->
-	mlds_output_context(Context),
+	mlds_to_c__output_context(Context),
 	io__write_string(CodeString).
 mlds_output_target_code_component(Context, target_code_input(Rval)) -->
-	mlds_output_context(Context),
+	mlds_to_c__output_context(Context),
 	mlds_output_rval(Rval),
 	io__write_string("\n").
 mlds_output_target_code_component(Context, target_code_output(Lval)) -->
-	mlds_output_context(Context),
+	mlds_to_c__output_context(Context),
 	mlds_output_lval(Lval),
 	io__write_string("\n").
 mlds_output_target_code_component(_Context, name(Name)) -->
 	% Note: `name(Name)' target_code_components are used to
 	% generate the #define for `MR_PROC_LABEL'.
 	% The fact that they're used in a #define means that we can't do
-	% an mlds_output_context(Context) here, since #line directives
+	% an mlds_to_c__output_context(Context) here, since #line directives
 	% aren't allowed inside #defines.
 	mlds_output_fully_qualified_name(Name),
 	io__write_string("\n").
@@ -3028,11 +3035,8 @@
 % Miscellaneous stuff to handle indentation and generation of
 % source context annotations (#line directives).
 %
-
-:- pred mlds_output_context(mlds__context, io__state, io__state).
-:- mode mlds_output_context(in, di, uo) is det.
 
-mlds_output_context(Context) -->
+mlds_to_c__output_context(Context) -->
 	{ ProgContext = mlds__get_prog_context(Context) },
 	{ term__context_file(ProgContext, FileName) },
 	{ term__context_line(ProgContext, LineNumber) },
@@ -3042,7 +3046,7 @@
 :- mode mlds_indent(in, in, di, uo) is det.
 
 mlds_indent(Context, N) -->
-	mlds_output_context(Context),
+	mlds_to_c__output_context(Context),
 	mlds_indent(N).
 
 % A value of type `indent' records the number of levels
Index: compiler/mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.8
diff -u -r1.8 mlds_to_ilasm.m
--- compiler/mlds_to_ilasm.m	2001/02/20 07:52:19	1.8
+++ compiler/mlds_to_ilasm.m	2001/04/11 08:59:13
@@ -243,9 +243,11 @@
 			_ExportDefns)) -->
 	{ BodyCode = list__reverse(RevBodyCode) },
 	io__write_list(BodyCode, "\n", 
-		(pred(llds__user_foreign_code(Lang, Code, _Context)::in,
+		(pred(llds__user_foreign_code(Lang, Code, Context)::in,
 				di, uo) is det -->
 			( { Lang = managed_cplusplus } ->
+				mlds_to_c__output_context(mlds__make_context(
+					Context)),
 				io__write_string(Code)
 			;
 				{ sorry(this_file, 


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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