The part of the compiler covered by this assignment deals with disambiguation of names, linking of the uses of local variables, fields, methods and constructors to their definitions, finding the types of all expressions, checking that the program is type correct and performing various normalising transformations on the AST. It encompasses the two phases Disambiguation and TypeChecking. You must hand in two files disambiguation.ml and typechecking.ml that extend the skeleton. Throughout this text, the term local variable covers both of the terms local variable and parameter as used in the JLS.

Field and method lookup in these phases is done using the lookup_field and lookup_method functions provided by the Hierarchy phase.

Constructor lookup is done by traversing the list of class members and only looking at constructors.

The rules for method and constructor overloading are very different for Joos 1 and Joos 2.

Any strategy in the spectrum between these two is acceptable. That is, anything that accepts all legal Joos 1 programs and rejects any program that is not a legal Joos 2 program is fine.

Disambiguation

The Disambiguation phase performs disambiguation of all ambiguous names and invokes.

Transformations

The disambiguation process is described in Section 6.5.2 of the JLS. The recipe of how this is done in a Joos compiler is described on slides 43, 44 and 45 of the Scopes and Environments lecture.

Checks

Check that all ambiguous names and invokes can be disambiguated properly, i.e.: Subsequent fields accesses and method invokes are not checked at this point.

Furthermore, this phase must check for illegal forward references:

This requirement is described in Section 8.3.2.3 of the JLS. Note however that this section is confusing in several ways: First, it is not evident that the phrase "before it is used" does not include the declaration containing the initializer that uses the variable. Second, the last sentence "A compile-time error occurs if any of the three requirements above are not met." does not make sense, since the three requirements condition a requirement that must be satisfied for the problem to be valid, and thus if the condition is not fulfilled, the requirement is not in effect.

TypeChecking

The TypeChecking phase determines the types of all expressions, checks that the program is type correct, resolves all non-static field accesses and all method and constructor invocations, and performs some transformations on the AST based on the types.

Implementations

Transformations

Decorations

Checks

Documentation

You must post an entry in your group blog that explains how your code works and which problems you have encountered and solved in the process.

Furthermore for the documentation:

You may also consider the following: