Typed intermediate language support for languages with multiple inheritance
AssigneeMicrosoft Corporation
InventorJuan Chen
Life of this patent
Estimating the term…
Abstract
A typed intermediate representation of source code written in a language that supports multiple inheritance is presented. The typed intermediate representation uses paths to represent objects embedded in other objects. For each class, an exact record type represents layout of complete objects of that class. An approximated record type describes layout of inner objects when the runtime types of the objects are statically unknown. Address arithmetic is represented by special instructions and type-checked to ensure proper pointer adjustment. Types are also given to “this” pointers of methods within classes. These “this” pointer types refer to the paths associated with the object.
Claims15
A computer implemented method comprising:
- receiving source code in an object-oriented language, wherein the source code defines a class hierarchy having an inner object defined in the class hierarchy as inherited, directly or indirectly, by an outermost object of the class hierarchy, and wherein the outermost object implements multiple inheritance;
- determining, in a computer, a complete class inheritance path from the outermost object to a runtime type of the inner object;
- and
- during type checking, in an intermediate representation of the source code, using a path type to represent a type of the inner object within the outermost object, wherein the path type comprises the complete class inheritance path from the outermost object to the runtime type the inner object;
- wherein the path type comprises an existential type if the runtime type of the inner object is not known;
- and
- wherein the existential type comprises a complete class inheritance path from the outermost object to each possible inner object.
A computer system for using an intermediately compiled source code program, the computer system comprising:
- a computer comprising at least one processor and memory, wherein the computer is configured to implement:
- a path assigner which assigns a first path to a first object of a first class, the first object being an inner object of an outermost, second object of a second class, the first path comprising an offset from the outermost, second object to the first object;
- a path checker which ensures that a method of the first object only accepts objects with a type of the first path;
- an offset locator which locates an offset between the first class and the second class by looking at a record in the second class which stores the offset between the first class and the second class when the first class is a direct virtual base of the second class, and
- a “this” pointer adjuster which casts the first object to the outermost, second object by subtracting from the first object the offset between the first class and the second class located by the offset locator when a virtual method defined in the first class but overridden in the second class is called on the first object.
A computer-readable storage medium tangibly embodying computer-executable instructions for performing a method comprising:
- receiving source code in an object-oriented language, wherein the source code defines a class hierarchy having an inner object defined in the class hierarchy as inherited, directly or indirectly, by an outermost object of the class hierarchy, and the outermost object implements multiple inheritance;
- determining, in a computer, a complete class inheritance path from the outermost object to a runtime type of the inner object;
- during type checking, in an intermediate representation of the source code, using a path type to represent a type of the inner object within the outermost object, wherein the path type comprises the complete class inheritance path from the outermost object to the runtime type of the inner object;
- wherein the runtime type of the inner object is not known at compile time;
- the path type comprises an existential type when the runtime type of the inner object is not known;
- for an inner object of a class (C), the existential type comprises:
- ∃α<<C.∃ρ:(α,C] Path(ρ, α);
- wherein α comprises a type variable identifying a runtime type of the outermost object, which comprises C or a subclass of C;
- and
- ρ abstracts a path from the outermost object to the inner object.
Dependencies are inferred from the claim text.