Wilhelm, R., Seidl, H. (2010). Compiler Design: virtualmachines. Page 173. Problem 1, 2, 3
(This question is spread over three images in chronologicalorder as shown)
The following extract of a C++ class library of graphics objects is used as a runnin example for the exercises in this section.
1. Methods. Compile the method ellipse :: translate. 2. Virtual Method Tables. Determine for all classes, the relative addresses of virtual methods within the respective virtual method table. Translate a method call of the form c.dist (p) where c is a circle and p is a point. 3. Subtypes. The new definition of a class should not affect the existing class structure. Based on the subtyping rule, methods of already existing classes must also be able to work with objects of the new class. Through overloading of methods of parent classes, their view onto new objects can become inconsistent. Thus, redefinitions should be handled with caution. Three different aspects must be considered. - The meaning (semantics) of members: each attribute and each method has a meaning which should not be affected by overloading. Thus, for instance, the method scale is meant to scale a graphics object. A redefinition should implement the same function, both at the current level of abstraction as well as at the level of the parent class. - Restrictions through the type system: Redefinitions should not lead to type inconsistencies. - Restrictions of the compilation schemes: Redefinitions can invalidate the assumptions made at compile-time and, then, should not be permitted. Although the first aspect is essential, a compiler normally does not have the required specifications for verifying semantical properties. In this exercise, we consider restrictions imposed by the type system.
Casting a type into a subtype is called type tightening, casting a type into a supertype is called type loosening. A prototype (of a method) is tightened if the types of the return value are tightened and the types of the input parameters are loosened. a) Argue that from the point of view of the type system, tightening of the prototype of a redefined method can be allowed. Show through examples that the prototypes of virtual methods can at most be tightened; any other modification may lead to type errors at calls that were previously correct. Argue that a non-tightened modification of the prototype for a redefined private method is also only acceptable under restricted assumptions. For a modification to be admissable, properties of the parent class are required, beyond the types of its attributes and the prototypes of its methods - which properties? b) The language EIFFEL allows a derived class to tighten the type of an inherited attribute. Explain why attributes can then only be read by a foreign class. Show through an example that tightening the type of an attribute is only allowed under restricted assumptions. For a modification to be admissable, properties of the parent class are required, beyond the types of its attributes and the prototypes of its methods - which properties?
Wilhelm, R., Seidl, H. (2010). Compiler Design: virtual machines. Page 173. Problem 1, 2, 3 (This question is spread o
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Wilhelm, R., Seidl, H. (2010). Compiler Design: virtual machines. Page 173. Problem 1, 2, 3 (This question is spread o
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!