[m-rev.] diff: IL back-end: fix another bug with nested classes

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Aug 13 13:11:29 AEST 2001


Estimated hours taken: 1
Branches: main

compiler/mlds_to_il.m:
	When generating field references, fix up the class name for nested
	types so that the nested part gets put in the nested classes
	field of structured_name; this is needed to ensure that ilasm.m
	outputs the class qualifiers using the proper "/" qualifiers
	rather than using "." (which is for namespace qualifiers).

	This also required changing get_ilds_type_class_name to handle
	value classes.

Workspace: /home/venus/fjh/ws-venus4/mercury
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.69
diff -u -d -r1.69 mlds_to_il.m
--- compiler/mlds_to_il.m	13 Aug 2001 02:28:35 -0000	1.69
+++ compiler/mlds_to_il.m	13 Aug 2001 03:09:17 -0000
@@ -2698,7 +2698,9 @@
 :- func get_ilds_type_class_name(ilds__type) = ilds__class_name.
 get_ilds_type_class_name(ILType) = ClassName :-
 	( 
-		ILType = ilds__type(_, class(ClassName0))
+		( ILType = ilds__type(_, class(ClassName0))
+		; ILType = ilds__type(_, value_class(ClassName0))
+		)
 	->
 		ClassName = ClassName0
 	;
@@ -3215,7 +3217,12 @@
 	% this in a separate pass.   See defn_to_class_decl which does
 	% the same thing when creating the fields.
 :- func get_fieldref(il_data_rep, field_id, mlds__type, mlds__type) = fieldref.
-get_fieldref(DataRep, FieldNum, FieldType, ClassType) = FieldRef :-
+get_fieldref(DataRep, FieldNum, FieldType, ClassType0) = FieldRef :-
+	( ClassType0 = mlds__ptr_type(ClassType1) ->
+		ClassType = ClassType1
+	;
+		ClassType = ClassType0
+	),
 	FieldILType0 = mlds_type_to_ilds_type(DataRep,
 		FieldType),
 	( FieldILType0 = ilds__type(_, '&'(FieldILType1)) ->
@@ -3225,8 +3232,7 @@
 	),
 	( 
 		FieldNum = offset(OffsetRval),
-		ClassName = mlds_type_to_ilds_class_name(DataRep,
-			ClassType),
+		ClassName = mlds_type_to_ilds_class_name(DataRep, ClassType),
 		( OffsetRval = const(int_const(Num)) ->
 			string__format("f%d", [i(Num)], FieldId)
 		;
@@ -3234,11 +3240,39 @@
 				"offsets for non-int_const rvals")
 		)
 	; 
-		FieldNum = named_field(qual(ModuleName, FieldId),
-			_Type),
-		ClassName = mlds_module_name_to_class_name(ModuleName)
+		FieldNum = named_field(qual(ModuleName, FieldId), _CtorType),
+		% The MLDS doesn't record which qualifiers are class qualifiers
+		% and which are namespace qualifiers... we first generate
+		% a name for the CtorClass as if it wasn't nested, and then
+		% we call fixup_class_qualifiers to make it correct.
+		CtorClassName = mlds_module_name_to_class_name(ModuleName),
+		BaseClassName = mlds_type_to_ilds_class_name(DataRep, ClassType),
+		ClassName = fixup_class_qualifiers(CtorClassName, BaseClassName)
 	),
 	FieldRef = make_fieldref(FieldILType, ClassName, FieldId).
+
+	% The CtorClass will be nested inside the BaseClass.
+	% But when we initially generate the name, we don't
+	% know that it is nested.  This routine fixes up the
+	% CtorClassName by moving the nested parts into the
+	% third field of the structured_name.
+:- func fixup_class_qualifiers(ilds__class_name, ilds__class_name) =
+	ilds__class_name.
+fixup_class_qualifiers(CtorClassName0, BaseClassName) = CtorClassName :-
+	BaseClassName  = structured_name(BaseAssembly, BaseClass, BaseNested),
+	CtorClassName0 = structured_name(CtorAssembly, CtorClass, CtorNested),
+	(
+		list__append(BaseClass, NestedClasses, CtorClass),
+		% some sanity checks
+		BaseAssembly = CtorAssembly,
+		BaseNested = [],
+		CtorNested = []
+	->
+		CtorClassName = structured_name(CtorAssembly, BaseClass,
+			NestedClasses)
+	;
+		unexpected(this_file, "fixup_class_qualifiers")
+	).
 
 %-----------------------------------------------------------------------------%
 
 

-- 
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