Support for enums and static variables
Assumptions:
- There are no circular dependencies in initialization of static variables.
- Enums are immutable.
- The initialization is done before the main method is executed.
Current errors in the pipeline:
-
There is a sanity check test to force all interprocedural arcs to be either input xor output. The newly introduced connection between static trees and formal-in trees breaks this assumption.
Missing elements:
-
A connection from the usage to the initialization, and in the case of objects and enum constants, their corresponding constructor.
Theory
Enums:
- They are classes with a limited number of instances, specified in the source code.
- They are
final
(can't be extended) and they themselves extend fromEnum
. - Despite the previous point, the explicit constructor call
super()
is illegal, and will result in a compilation error. - An enum's instances are called its constants. They are
public static final
variables of the enum's type. - If no parenthesis are specified next to the constant, the default constructor is used. Otherwise, the constructor that matches the arguments is used.
- Enums are initialized when the enum class file is loaded into the JVM (the first time that it is referenced in the execution of a program). More details.
Design
- Each class and enum is represented as a single node in the SDG. In its object tree, its static fields are represented. In the case of enums, the constants are also placed here.
- Each static object tree is connected interprocedurally to every formal-in node that represents that class.
Edited by Carlos Galindo