package cd.frontend.semantic; /** * Thrown by the semantic checker when a semantic error is detected * in the user's program. */ public class SemanticFailure extends RuntimeException { private static final long serialVersionUID = 5375946759285719123L; public enum Cause { /** * Caused by an assignment to either a final field, {@code this}, * or some other kind of expression which cannot be assigned to. * Not used for type errors in assignments, which fall * under {@link #TYPE_ERROR}. */ NOT_ASSIGNABLE, /** * Two variables, fields, methods, or classes with the same name * were declared in the same scope */ DOUBLE_DECLARATION, /** * A field was accessed that does not exist */ NO_SUCH_FIELD, /** * A method was called that does not exist */ NO_SUCH_METHOD, /** * A variable or other identifier was used in a method * body which has no corresponding declaration */ NO_SUCH_VARIABLE, /** * A method with a return type is missing a return statement among one of its paths */ MISSING_RETURN, /** * Can occur in many contents: * */ TYPE_ERROR, /** * A class is its own super class */ CIRCULAR_INHERITANCE, /** * One of the following: * */ INVALID_START_POINT, /** * A class {@code Object} was defined. This class is implicitly * defined and cannot be defined explicitly. */ OBJECT_CLASS_DEFINED, /** * A type name was found for which no class declaration exists. * This can occur in many contexts: * */ NO_SUCH_TYPE, /** * The parameters of an overridden method have different types * from the base method, there is a different * number of parameters, or the return value is different. */ INVALID_OVERRIDE, /** * A method was called with the wrong number of arguments */ WRONG_NUMBER_OF_ARGUMENTS, /** * Indicates the use of a local variable that may not have been * initialized (ACD only). */ POSSIBLY_UNINITIALIZED, } public final Cause cause; public SemanticFailure(Cause cause) { super(cause.name()); this.cause = cause; } public SemanticFailure(Cause cause, String format, Object... args) { super(String.format(format, args)); this.cause = cause; } }