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 for generating a typed intermediate representation of a computer program, the computer program supporting virtual inheritance and multiple inheritance, the method comprising:
- receiving a source code representation of the computer program in an object-oriented language, the source code representation comprising code portions related to defining one or more classes, wherein at least one of the one or more classes defined in the source code representation has a plurality of superclasses, and at least one of the plurality of superclasses is inherited at least twice;
- and
- based on the source code representation, generating, in a computer, the typed intermediate representation of the computer program, wherein the generating comprises generating an exact class representation of the at least one of the one or more classes defined in the source code representation, the exact class representation including a unique representation of the plurality of superclasses of the at least one of the one or more classes;
- wherein generating the exact class representation comprises generating a path from the at least one of the one or more classes to a respective superclass, the path uniquely identifying the respective superclass;
- wherein generating the exact class representation comprises representing the at least one of the superclasses inherited at least twice with a single path;
- and wherein generating the exact class representation further comprises generating a layout of the at least one of the one or more classes, wherein the layout maps to a runtime representation of an object of the at least one of the one or more classes.
A computer-readable storage medium having stored thereon a typed intermediate representation of a computer program, the computer program written in a language which allows multiple inheritance and virtual inheritance, the typed intermediate representation comprising:
- an exact record type which comprises a substantially exact representation of a runtime object of at least one of one or more classes defined in a source code representation of the computer program, including at least two distinct inheritance paths from the at least one of the one or more classes to a superclass, the superclass inherited at least twice;
- an approximated record type comprising substantially all inheritance paths from at least one non-virtually inherited superclasses of the at least one of the one or more classes to all superclasses inherited by the at least one non-virtually inherited superclass;
- a layout of the at least one of the one or more classes, wherein the layout maps to a runtime representation of an object of the at least one of the one or more classes;
- wherein the typed intermediate representation comprises a single path representing the superclass inherited at least twice.
A computer system for generating a typed intermediate representation of a computer program, the computer system comprising:
- a computer comprising at least one processor and memory, wherein the computer is configured to implement:
- a compiler operable for generating the typed intermediate representation from a source code representation of the computer program, wherein the source code representation comprises definitions of one or more classes, at least one class including at least one virtually-inherited superclass and a superclass inherited at least twice;
- the compiler further comprising:
- an exact record type generator, which generates a representation of a runtime object of the class, the representation comprising displacements from at least one class which inherits the at least one virtually-inherited superclass and the at least one virtually-inherited superclass;
- an approximated record type generator, which generates a representation of a runtime object of the at least one class when an exact runtime type of the runtime object is not known;
- and
- a path generator configured to generate one single path representing the superclass inherited at least twice, wherein the one single path designates that the one single path begins at an outermost object of a virtual base.
Dependencies are inferred from the claim text.