Hi,
please see below for comments.
BR
Stephan
>
Original Message
> From: ext xdji [This email address is being protected from spambots. You need JavaScript enabled to view it.]
> Sent: 11. September 2003 04:37
> To: This email address is being protected from spambots. You need JavaScript enabled to view it.
> Subject: Parameterization of modified templates
>
>
> Hi all,
> I have some questions about parameterization of modified
> templates,please give me some help.
>
> 1. Clause 14.6.1 says the derived template should contain
> all parameters defined in the base templates. Should these
> parameters must be defined in derived template with the same
> types, names and sequence in base template? For example:
Same names, same types, same order.
>
> template MyRecord T1 (integer par1,charstring par2) :=
> {
> field1 := par1,
> field2 := par2
> }
> template MyRecord T2 (charsring par2, integer par1)
> modifies T1 :=
> {...}
Incorrect - changed order of parameters.
>
> template MyRecord T3 (integer MyPar1, charstring
> MyPar2) modifies T1 :=
> {...}
Incorrect - different names.
The first restriction is really more for compiler convenience - as long as the parameters are there with the same names and the same types, order is not so relevant. Semantically, it would still make sense. On the order hand, order is really not relevant so one might as well require the same order for both templates.
The different names are a different story: Consider this example:
type record Rec {
integer a,
integer b
}
template Rec temp1(integer p_a, integer p_b) := { a := p_a, b := p_b };
template Rec temp2(integer p_A, integer b_B) modifies temp1 := { a := p_A };
When resolving the 'modifies' in temp2, we get
template Rec temp2(integer p_A, integer b_B) modifies temp1 := { a := p_A, b := p_b };
p_b is an undefined name in temp2, due to the changed of names. Enforcing the same parameter names stops this problem.
> 2. Subclause b of 14.6.1 says :" base template fields
> containing parameterized templates shall not be modified or
> explicitly omitted in a modified template." What does it mean?
It means that, if you are modifying a template, you may not overwrite those fields that contain parameterized templates:
template a_int(integer x) := 2*x;
template Rec temp3(integer x) := { a := x, b := a_int(x) };
template Rec temp4(integer x) modified temp3 := { b := 1 };
The definition of temp4 modifies field b of the base template, which contains a parameterized template -> this is not allowed.
When implementing the whole 'modifies' stuff in our compiler, I found that all of these restrictions for 'modifies' did make sense, but I have forgotten why this particular restriction was there.
>
> Thanks a lot!
>
>
>
> Ji XiangDong
> Univ. of Science & Technology of China
> 86-551-3606124
> This email address is being protected from spambots. You need JavaScript enabled to view it.
> 2003-09-11 10:19:07
>