edu.rice.cs.javalanglevels
Class ExpressionTypeChecker

java.lang.Object
  extended by edu.rice.cs.javalanglevels.tree.JExpressionIFDepthFirstVisitor<TypeData>
      extended by edu.rice.cs.javalanglevels.TypeChecker
          extended by edu.rice.cs.javalanglevels.SpecialTypeChecker
              extended by edu.rice.cs.javalanglevels.ExpressionTypeChecker
All Implemented Interfaces:
JExpressionIFVisitor<TypeData>

public class ExpressionTypeChecker
extends SpecialTypeChecker

This is a TypeChecker for all Expressions used in the students files. It is used with every LanguageLevel.


Nested Class Summary
static class ExpressionTypeChecker.ExpressionTypeCheckerTest
          Test class for the methods defined in the above (enclosing) class.
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
SpecialTypeChecker.BobTest
 
Nested classes/interfaces inherited from class edu.rice.cs.javalanglevels.TypeChecker
TypeChecker.TypeCheckerTest
 
Field Summary
static JavaVersion JAVA_VERSION
           
static NullLiteral NULL_LITERAL
           
 
Fields inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
_data, _thrown, _vars, thingsThatHaveBeenAssigned
 
Fields inherited from class edu.rice.cs.javalanglevels.TypeChecker
_abstractMav, _finalMav, _finalPublicMav, _log, _packageMav, _privateMav, _protectedMav, _publicAbstractMav, _publicMav, _publicStaticMav, NONE
 
Constructor Summary
ExpressionTypeChecker(Data data, java.io.File file, java.lang.String packageName, java.util.LinkedList<java.lang.String> importedFiles, java.util.LinkedList<java.lang.String> importedPackages, java.util.LinkedList<VariableData> vars, java.util.LinkedList<Pair<SymbolData,JExpression>> thrown)
          Simply pass the necessary information on to superclass constructor.
 
Method Summary
protected  SymbolData _getLeastRestrictiveType(SymbolData sd1, SymbolData sd2)
          Returns the least restrictive numerical type.
protected  boolean canBeAssigned(VariableData vd)
          A variable data can be assigned to if it is not final or it does not have a value.
 InstanceData classInstantiationHelper(ClassInstantiation that, SymbolData classToInstantiate)
          Visit the ClassInstantiation's arguments.
 TypeData forArrayAccessOnly(ArrayAccess that, TypeData lhs, TypeData index)
          Make sure the lhs is actually an array type and that the index is an int.
 TypeData forArrayInitializer(ArrayInitializer that)
          The array initializer needs the type of the array to ensure it is properly handled.
 TypeData forBitwiseAssignmentExpressionOnly(BitwiseAssignmentExpression that, TypeData nameRes, TypeData valueRes)
          Not currently supported.
 TypeData forBitwiseBinaryExpressionOnly(BitwiseBinaryExpression that, TypeData left_result, TypeData right_result)
          Not currently supported.
 TypeData forBitwiseNotExpressionOnly(BitwiseNotExpression that, TypeData valueRes)
          Not Currently Supported.
 TypeData forBooleanExpressionOnly(BooleanExpression that, TypeData left_result, TypeData right_result)
          Checks if this BooleanExpression is well-formed, i.e., that left and right arguments are well-formed boolean expressions.
 TypeData forBooleanLiteralOnly(BooleanLiteral that)
           
 TypeData forBracedBody(BracedBody that)
          Delegate to forBody
 TypeData forCastExpression(CastExpression that)
          Try to look up the type of the cast, and visit the expression that is being cast.
 TypeData forCastExpressionOnly(CastExpression that, TypeData typeRes, TypeData valueRes)
          Checks to see if this CastExpression is okay.
 TypeData forCharLiteralOnly(CharLiteral that)
           
 TypeData forClassLiteralOnly(ClassLiteral that)
           
 TypeData forComparisonExpressionOnly(ComparisonExpression that, TypeData left_result, TypeData right_result)
          Verify that both the left and right of this comparison expression are number types and InstanceDatas.
 TypeData forComplexAnonymousClassInstantiation(ComplexAnonymousClassInstantiation that)
          Resolve the type of this anonymous class.
 TypeData forComplexInitializedArrayInstantiation(ComplexInitializedArrayInstantiation that)
          This is not legal java--should have been caught before the TypeChecker.
 TypeData forComplexMethodInvocation(ComplexMethodInvocation that)
          Tries to match this method invocation to a method in the context.
 TypeData forComplexNamedClassInstantiation(ComplexNamedClassInstantiation that)
          Handles this complex named class instantiation.
 TypeData forComplexNameReference(ComplexNameReference that)
          To resolve this ComplexNameReference, first visit the lhs with an instance of this visitor in order to get its type.
 TypeData forComplexSuperReferenceOnly(ComplexSuperReference that, TypeData enclosing_result)
          Makes sure that the enclosing result is not null--if it is, return null.
 TypeData forComplexThisConstructorInvocation(ComplexThisConstructorInvocation that)
          ComplexThisConstructorInvocations are not ever allowed.
 TypeData forComplexThisReferenceOnly(ComplexThisReference that, TypeData enclosing_result)
          Check to make sure that the enclosing result could be resolved and that it a type name.
 TypeData forComplexUninitializedArrayInstantiation(ComplexUninitializedArrayInstantiation that)
          This is not legal java--should have been caught before the TypeChecker.
 TypeData forConditionalExpression(ConditionalExpression that)
          Throw runtime exception, since conditional expressions are not allowed, and this should have been caught before the TypeChecker.
 TypeData forConditionalExpressionOnly(ConditionalExpression that, TypeData condition_result, TypeData forTrue_result, TypeData forFalse_result)
          Not currently supported
 TypeData forDivideAssignmentExpression(DivideAssignmentExpression that)
          Delegate to method for super class.
 TypeData forDoubleLiteralOnly(DoubleLiteral that)
           
 TypeData forEmptyExpressionOnly(EmptyExpression that)
          Gives a Runtime Exception, because the fact that there is an EmptyExpression here should have been caught before the TypeChecker pass.
 TypeData forEmptyForCondition(EmptyForCondition that)
          Process an instance of EmptyForCondition.
 TypeData forEqualityExpressionOnly(EqualityExpression that, TypeData left_result, TypeData right_result)
          This EqualityExpression is badly formed if left_result and right_result have incompatible types.
 TypeData forFloatLiteralOnly(FloatLiteral that)
           
 TypeData forIncrementExpression(IncrementExpression that)
          Visit the value of this increment expression with the LValueWithValueTypeChecker, since whatever it represents should already have a value before we try to increment it.
 TypeData forIncrementExpressionOnly(IncrementExpression that, TypeData valueRes)
          An IncrementExpression is badly formatted if the thing being incremented is a type (valueRes is not an InstanceData) or if the value being incremented cannot be assigned to.
 TypeData forInnerClassDef(InnerClassDef that)
          Look up the SymbolData for this InnerClass within the enclosing data, check for cyclic inheritance, and then visit everything inside the inner class.
 TypeData forInstanceofExpression(InstanceofExpression that)
          Try to look up the type of the instanceof, and visit the expression that is being tested.
 TypeData forInstanceofExpressionOnly(InstanceofExpression that, TypeData typeRes, TypeData valueRes)
          Checks to see if this InstanceofExpression is okay.
 TypeData forIntegerLiteralOnly(IntegerLiteral that)
           
 TypeData forLongLiteralOnly(LongLiteral that)
           
 TypeData forMinusAssignmentExpression(MinusAssignmentExpression that)
          Delegate to method for super class.
 TypeData forModAssignmentExpression(ModAssignmentExpression that)
          Delegate to method for super class.
 TypeData forMultiplyAssignmentExpression(MultiplyAssignmentExpression that)
          Delegate to method for super class.
 TypeData forNegativePostfixIncrementExpression(NegativePostfixIncrementExpression that)
          Process an instance of NegativePostfixIncrementExpression.
 TypeData forNegativePrefixIncrementExpression(NegativePrefixIncrementExpression that)
          Process an instance of NegativePrefixIncrementExpression.
 TypeData forNoOpExpressionOnly(NoOpExpression that, TypeData left_result, TypeData right_result)
          This should have been caught in the first pass.
 TypeData forNotExpressionOnly(NotExpression that, TypeData valueRes)
          A NotExpression is illformed if its argument is not an instance type or its argument is not of type boolean.
 TypeData forNullLiteralOnly(NullLiteral that)
           
 TypeData forNumericAssignmentExpression(NumericAssignmentExpression that)
          Visit the lhs of this assignment with the LValueWithValueTypeChecker, which does extra checking for the lhs, because it needs to be able to be assigned to and already have a value.
 TypeData forNumericAssignmentExpressionOnly(NumericAssignmentExpression that, TypeData nameRes, TypeData valueRes)
          A NumericAssignmentExpression is okay if both the lhs and the rhs are instances, both are numbers, and the rhs is assignable to the lhs.
 TypeData forNumericBinaryExpressionOnly(NumericBinaryExpression that, TypeData left_result, TypeData right_result)
          Check if this NumericBinaryExpression was okay.
 TypeData forNumericUnaryExpressionOnly(NumericUnaryExpression that, TypeData valueRes)
          A NumericUnaryExpression was well-formed if its valueRes is an instance type and if its valueRes's symbol data is a number type (to which a double can be assigned).
 TypeData forParenthesizedOnly(Parenthesized that, TypeData valueRes)
          Check a few constraints on this Parenthesized
 TypeData forPlusAssignmentExpression(PlusAssignmentExpression that)
          Visit the lhs of this assignment with LValueWithValueTypeChecker, which does extra checking.
 TypeData forPlusAssignmentExpressionOnly(PlusAssignmentExpression that, TypeData nameRes, TypeData valueRes)
          A PlusAssignmentExpression is okay if the lhs and rhs are both instances.
 TypeData forPlusExpressionOnly(PlusExpression that, TypeData left_result, TypeData right_result)
          A plus operator can either be used on a string and any other type of object or on two numbers.
 TypeData forPositivePostfixIncrementExpression(PositivePostfixIncrementExpression that)
          Process an instance of PositivePostfixIncrementExpression.
 TypeData forPositivePrefixIncrementExpression(PositivePrefixIncrementExpression that)
          For these concrete instantiations of IncrementExpression, delegate to abstract method
 TypeData forShiftAssignmentExpressionOnly(ShiftAssignmentExpression that, TypeData nameRes, TypeData valueRes)
          Not currently supported.
 TypeData forShiftBinaryExpressionOnly(ShiftBinaryExpression that, TypeData left_result, TypeData right_result)
          Not currently supported
 TypeData forSimpleAnonymousClassInstantiation(SimpleAnonymousClassInstantiation that)
          Resolve the type of this anonymous class.
 TypeData forSimpleAssignmentExpression(SimpleAssignmentExpression that)
          Visit the lhs of this assignment with LValueTypeChecker, which does extra checking.
 TypeData forSimpleAssignmentExpressionOnly(SimpleAssignmentExpression that, TypeData nameRes, TypeData valueRes)
          A SimpleAssignmentExpression is okay if both lhs and rhs are instances, and rhs is assignable to lhs.
 TypeData forSimpleInitializedArrayInstantiation(SimpleInitializedArrayInstantiation that)
          Lookup the type of the array instantiation, and if there are any errors with it, give them.
 TypeData forSimpleMethodInvocation(SimpleMethodInvocation that)
          Tries to match this method invocation to a method in the context.
 TypeData forSimpleNamedClassInstantiation(SimpleNamedClassInstantiation that)
          Handles a simple class instantiation.
 TypeData forSimpleNameReference(SimpleNameReference that)
          Try to resolve this SimpleNameReference.
 TypeData forSimpleSuperReference(SimpleSuperReference that)
          All classes should have a super class, which is java.lang.Object by default.
 TypeData forSimpleThisConstructorInvocation(SimpleThisConstructorInvocation that)
          SimpleThisConstructorInvocations are not allowed outside of the first line of a constructor.
 TypeData forSimpleThisReference(SimpleThisReference that)
          Make sure we are in a non-static context.
 TypeData forSimpleUninitializedArrayInstantiation(SimpleUninitializedArrayInstantiation that)
          Resolve the type of the array and visit its dimensions.
 TypeData forStringLiteralOnly(StringLiteral that)
           
 TypeData forUninitializedArrayInstantiationOnly(UninitializedArrayInstantiation that, TypeData typeRes, TypeData[] dimensions_result)
          Make sure the dimensions of the array instantiation are all instances and subtypes of int, and then return an instance of the array.
 SymbolData handleAnonymousClassInstantiation(AnonymousClassInstantiation that, SymbolData superC)
          Do the work that is shared between SimpleAnonymousClassInstantiation and ComplexAnonymousClassInstantiation.
 void handleUncheckedException(SymbolData sd, JExpression j)
          Throw the appropriate error, based on the type of the JExpression where the exception was unchecked
 boolean isCheckedException(SymbolData sd, JExpression that)
          Returns whether the sd is a checked exception, i.e.
 boolean isUncaughtCheckedException(SymbolData sd, JExpression that)
          Return true if the Exception is a checked exception yet is not caught or declared to be thrown, and false otherwise.
 TypeData methodInvocationHelper(MethodInvocation that, TypeData context)
          Look up the method called in the method invocation within the context of the context TypeData.
 
Methods inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
_getData, findClassReference, forArrayInitializerHelper, forBody, forExpressionStatement, forFormalParameter, forInitializedVariableDeclarator, forInitializedVariableDeclaratorOnly, forInnerInterfaceDef, forInstanceInitializer, forLabeledStatement, forStaticInitializer, forSynchronizedStatement, forThrowStatement, forThrowStatementOnly, forUnbracedBody, forUninitializedVariableDeclarator, forVariableDeclaration, getArgTypesForInvocation, handleMethodInvocation, inStaticMethod
 
Methods inherited from class edu.rice.cs.javalanglevels.TypeChecker
_addError, _checkAbstractMethods, _getMatchingMethods, _isAssignableFrom, _isAssignableFromWithoutAutoboxing, _lookupMethod, _lookupMethodHelper, _lookupMethodHelper, assertFound, assertInstanceType, checkAccess, checkAccess, checkAccess, checkForCyclicInheritance, cloneVariableDataList, defaultCase, defineTestCaseClass, forBlockOnly, forBreakStatementOnly, forClassDef, forClassDefOnly, forClassImportStatement, forConcreteMethodDefOnly, forContinueStatementOnly, forExpressionStatementOnly, forInnerClassDefOnly, forInnerInterfaceDefOnly, forInstanceInitializerOnly, forInterfaceDef, forInterfaceDefOnly, forLabeledStatementOnly, forMethodDefOnly, forPackageStatement, forPrimitiveType, forReturnStatementOnly, forStaticInitializerOnly, forSwitchStatementOnly, forTryCatchStatementOnly, getCommonSuperTypeBaseCase, getFieldOrVariable, getFieldOrVariable, getFieldOrVariable, getFieldOrVariable, getQualifiedClassName, getSymbolData, getSymbolData, getSymbolData, getSymbolData, makeArrayOfRetType, notRightPackage
 
Methods inherited from class edu.rice.cs.javalanglevels.tree.JExpressionIFDepthFirstVisitor
forAbstractMethodDef, forAbstractMethodDefOnly, forAndExpression, forAndExpressionOnly, forAnonymousClassInstantiationOnly, forArrayAccess, forArrayInitializerOnly, forArrayInstantiationOnly, forArrayType, forArrayTypeOnly, forAssignmentExpressionOnly, forBinaryExpressionOnly, forBitwiseAndAssignmentExpression, forBitwiseAndAssignmentExpressionOnly, forBitwiseAndExpression, forBitwiseAndExpressionOnly, forBitwiseNotExpression, forBitwiseOrAssignmentExpression, forBitwiseOrAssignmentExpressionOnly, forBitwiseOrExpression, forBitwiseOrExpressionOnly, forBitwiseXorAssignmentExpression, forBitwiseXorAssignmentExpressionOnly, forBitwiseXorExpression, forBitwiseXorExpressionOnly, forBlock, forBlockOnly, forBodyOnly, forBooleanLiteral, forBracedBodyOnly, forCatchBlock, forCatchBlockOnly, forCharLiteral, forClassImportStatementOnly, forClassInstantiationOnly, forClassLiteral, forClassLiteralOnly, forClassOrInterfaceType, forClassOrInterfaceTypeOnly, forComplexAnonymousClassInstantiationOnly, forComplexInitializedArrayInstantiationOnly, forComplexMethodInvocationOnly, forComplexNamedClassInstantiationOnly, forComplexNameReferenceOnly, forComplexSuperConstructorInvocation, forComplexSuperConstructorInvocationOnly, forComplexSuperReference, forComplexThisConstructorInvocationOnly, forComplexThisReference, forComplexUninitializedArrayInstantiationOnly, forCompoundWord, forCompoundWordOnly, forConcreteMethodDef, forConcreteMethodDefOnly, forConstructorDef, forConstructorDefOnly, forDefaultCase, forDefaultCaseOnly, forDimensionExpressionList, forDimensionExpressionListOnly, forDivideAssignmentExpressionOnly, forDivideExpression, forDivideExpressionOnly, forDoStatement, forDoStatementOnly, forDoubleLiteral, forEmptyExpression, forEmptyForConditionOnly, forEmptyStatement, forEmptyStatementOnly, forEqualsExpression, forEqualsExpressionOnly, forExpressionListOnly, forExpressionOnly, forFloatLiteral, forFormalParameterOnly, forForStatement, forForStatementOnly, forFunctionInvocationOnly, forGreaterThanExpression, forGreaterThanExpressionOnly, forGreaterThanOrEqualExpression, forGreaterThanOrEqualExpressionOnly, forIfThenElseStatement, forIfThenElseStatementOnly, forIfThenStatement, forIfThenStatementOnly, forImportStatementOnly, forInitializedArrayInstantiationOnly, forInitializerOnly, forInstantiationOnly, forIntegerLiteral, forJExpressionOnly, forLabeledBreakStatement, forLabeledBreakStatementOnly, forLabeledCase, forLabeledCaseOnly, forLabeledContinueStatement, forLabeledContinueStatementOnly, forLabeledStatementOnly, forLeftShiftAssignmentExpression, forLeftShiftAssignmentExpressionOnly, forLeftShiftExpression, forLeftShiftExpressionOnly, forLessThanExpression, forLessThanExpressionOnly, forLessThanOrEqualExpression, forLessThanOrEqualExpressionOnly, forLexicalLiteralOnly, forLongLiteral, forMemberType, forMemberTypeOnly, forMethodDefOnly, forMethodInvocationOnly, forMinusAssignmentExpressionOnly, forMinusExpression, forMinusExpressionOnly, forModAssignmentExpressionOnly, forModExpression, forModExpressionOnly, forModifiersAndVisibility, forModifiersAndVisibilityOnly, forMultiplyAssignmentExpressionOnly, forMultiplyExpression, forMultiplyExpressionOnly, forNamedClassInstantiationOnly, forNameReferenceOnly, forNegativeExpression, forNegativeExpressionOnly, forNegativePostfixIncrementExpressionOnly, forNegativePrefixIncrementExpressionOnly, forNoOpExpression, forNormalTryCatchStatement, forNormalTryCatchStatementOnly, forNotEqualExpression, forNotEqualExpressionOnly, forNotExpression, forNullLiteral, forOrExpression, forOrExpressionOnly, forPackageImportStatement, forPackageImportStatementOnly, forPackageStatementOnly, forParenthesized, forParenthesizedExpressionList, forParenthesizedExpressionListOnly, forPlusExpression, forPositiveExpression, forPositiveExpressionOnly, forPositivePostfixIncrementExpressionOnly, forPositivePrefixIncrementExpressionOnly, forPostfixIncrementExpressionOnly, forPrefixIncrementExpressionOnly, forPrimaryOnly, forPrimitiveTypeOnly, forReferenceTypeOnly, forRightSignedShiftAssignmentExpression, forRightSignedShiftAssignmentExpressionOnly, forRightSignedShiftExpression, forRightSignedShiftExpressionOnly, forRightUnsignedShiftAssignmentExpression, forRightUnsignedShiftAssignmentExpressionOnly, forRightUnsignedShiftExpression, forRightUnsignedShiftExpressionOnly, forSimpleAnonymousClassInstantiationOnly, forSimpleInitializedArrayInstantiationOnly, forSimpleMethodInvocationOnly, forSimpleNamedClassInstantiationOnly, forSimpleNameReferenceOnly, forSimpleSuperConstructorInvocation, forSimpleSuperConstructorInvocationOnly, forSimpleSuperReferenceOnly, forSimpleThisConstructorInvocationOnly, forSimpleThisReferenceOnly, forSimpleUninitializedArrayInstantiationOnly, forSourceFile, forSourceFileOnly, forStatementOnly, forStringLiteral, forSuperConstructorInvocationOnly, forSuperReferenceOnly, forSwitchCaseOnly, forSwitchStatement, forSynchronizedStatementOnly, forThisConstructorInvocationOnly, forThisReferenceOnly, forTryCatchFinallyStatement, forTryCatchFinallyStatementOnly, forTypeDefBaseOnly, forTypeOnly, forTypeParameter, forTypeParameterOnly, forTypeVariable, forTypeVariableOnly, forUnaryExpressionOnly, forUnbracedBodyOnly, forUninitializedArrayInstantiationOnly, forUninitializedVariableDeclaratorOnly, forUnlabeledBreakStatement, forUnlabeledBreakStatementOnly, forUnlabeledContinueStatement, forUnlabeledContinueStatementOnly, forUnparenthesizedExpressionList, forUnparenthesizedExpressionListOnly, forValueReturnStatement, forValueReturnStatementOnly, forVariableDeclarationOnly, forVariableDeclaratorOnly, forVariableReferenceOnly, forVoidReturn, forVoidReturnOnly, forVoidReturnStatement, forVoidReturnStatementOnly, forWhileStatement, forWhileStatementOnly, forWord, forWordOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.rice.cs.javalanglevels.tree.JExpressionIFVisitor
forAbstractMethodDef, forAndExpression, forArrayAccess, forArrayType, forBitwiseAndAssignmentExpression, forBitwiseAndExpression, forBitwiseNotExpression, forBitwiseOrAssignmentExpression, forBitwiseOrExpression, forBitwiseXorAssignmentExpression, forBitwiseXorExpression, forBlock, forBooleanLiteral, forCatchBlock, forCharLiteral, forClassLiteral, forClassOrInterfaceType, forComplexSuperConstructorInvocation, forComplexSuperReference, forComplexThisReference, forCompoundWord, forConcreteMethodDef, forConstructorDef, forDefaultCase, forDimensionExpressionList, forDivideExpression, forDoStatement, forDoubleLiteral, forEmptyExpression, forEmptyStatement, forEqualsExpression, forFloatLiteral, forForStatement, forGreaterThanExpression, forGreaterThanOrEqualExpression, forIfThenElseStatement, forIfThenStatement, forIntegerLiteral, forLabeledBreakStatement, forLabeledCase, forLabeledContinueStatement, forLeftShiftAssignmentExpression, forLeftShiftExpression, forLessThanExpression, forLessThanOrEqualExpression, forLongLiteral, forMemberType, forMinusExpression, forModExpression, forModifiersAndVisibility, forMultiplyExpression, forNegativeExpression, forNoOpExpression, forNormalTryCatchStatement, forNotEqualExpression, forNotExpression, forNullLiteral, forOrExpression, forPackageImportStatement, forParenthesized, forParenthesizedExpressionList, forPlusExpression, forPositiveExpression, forRightSignedShiftAssignmentExpression, forRightSignedShiftExpression, forRightUnsignedShiftAssignmentExpression, forRightUnsignedShiftExpression, forSimpleSuperConstructorInvocation, forSourceFile, forStringLiteral, forSwitchStatement, forTryCatchFinallyStatement, forTypeParameter, forTypeVariable, forUnlabeledBreakStatement, forUnlabeledContinueStatement, forUnparenthesizedExpressionList, forValueReturnStatement, forVoidReturn, forVoidReturnStatement, forWhileStatement, forWord
 

Field Detail

JAVA_VERSION

public static final JavaVersion JAVA_VERSION

NULL_LITERAL

public static final NullLiteral NULL_LITERAL
Constructor Detail

ExpressionTypeChecker

public ExpressionTypeChecker(Data data,
                             java.io.File file,
                             java.lang.String packageName,
                             java.util.LinkedList<java.lang.String> importedFiles,
                             java.util.LinkedList<java.lang.String> importedPackages,
                             java.util.LinkedList<VariableData> vars,
                             java.util.LinkedList<Pair<SymbolData,JExpression>> thrown)
Simply pass the necessary information on to superclass constructor.

Parameters:
data - The data that represents the context. TODO: What classes can it be?
file - The file that corresponds to the source file
packageName - The string representing the package name
importedFiles - The list of file names that have been specifically imported
importedPackages - The list of package names that have been specifically imported
vars - The list of fields that have been assigned up to the point where SpecialTypeChecker is called.
thrown - The list of exceptions that the context is declared to throw
Method Detail

forSimpleAssignmentExpression

public TypeData forSimpleAssignmentExpression(SimpleAssignmentExpression that)
Visit the lhs of this assignment with LValueTypeChecker, which does extra checking. Visit the rhs of this assignment with the regular expression type checker, since anything normal expression can appear on the right.

Specified by:
forSimpleAssignmentExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleAssignmentExpression in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleAssignmentExpression to type check
Returns:
The result of the assignment.

forSimpleAssignmentExpressionOnly

public TypeData forSimpleAssignmentExpressionOnly(SimpleAssignmentExpression that,
                                                  TypeData nameRes,
                                                  TypeData valueRes)
A SimpleAssignmentExpression is okay if both lhs and rhs are instances, and rhs is assignable to lhs. Give an error if these constraints are not met. Return an instance of the lhs or null if the left or right could not be resolved.

Overrides:
forSimpleAssignmentExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleAssignmentExpression being typechecked
nameRes - The TypeData representing the lhs of the assignment
valueRes - The TypeData representing the rhs of the assignment

forPlusAssignmentExpression

public TypeData forPlusAssignmentExpression(PlusAssignmentExpression that)
Visit the lhs of this assignment with LValueWithValueTypeChecker, which does extra checking. Visit the rhs of this assignment with regular expression type checker, since anything regular expression can appear on the right.

Specified by:
forPlusAssignmentExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forPlusAssignmentExpression in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The PlusAssignmentExpression to type check
Returns:
The result of the assignment.

forPlusAssignmentExpressionOnly

public TypeData forPlusAssignmentExpressionOnly(PlusAssignmentExpression that,
                                                TypeData nameRes,
                                                TypeData valueRes)
A PlusAssignmentExpression is okay if the lhs and rhs are both instances. If the lhs is a string, the rhs can be anything. If the rhs is a string, the lhs had better be a string too. If neither of them is a string, they should both be numbers, and the rhs should be assignable to the lhs.

Overrides:
forPlusAssignmentExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The PlusAssignmentExpression we are typechecking
nameRes - The TypeData representing the lhs
valueRes - The TypeData representing the rhs
Returns:
An instance of the result of the lhs, or null if either the right or the left could not be resolved.

forNumericAssignmentExpression

public TypeData forNumericAssignmentExpression(NumericAssignmentExpression that)
Visit the lhs of this assignment with the LValueWithValueTypeChecker, which does extra checking for the lhs, because it needs to be able to be assigned to and already have a value. Visit the rhs of this assignment with the regular expression type checker, since any regular expression can appear on the right.

Parameters:
that - The NumericAssignmentExpression to type check
Returns:
The result of the assignment.

forMinusAssignmentExpression

public TypeData forMinusAssignmentExpression(MinusAssignmentExpression that)
Delegate to method for super class.

Specified by:
forMinusAssignmentExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forMinusAssignmentExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forMultiplyAssignmentExpression

public TypeData forMultiplyAssignmentExpression(MultiplyAssignmentExpression that)
Delegate to method for super class.

Specified by:
forMultiplyAssignmentExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forMultiplyAssignmentExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forDivideAssignmentExpression

public TypeData forDivideAssignmentExpression(DivideAssignmentExpression that)
Delegate to method for super class.

Specified by:
forDivideAssignmentExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forDivideAssignmentExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forModAssignmentExpression

public TypeData forModAssignmentExpression(ModAssignmentExpression that)
Delegate to method for super class.

Specified by:
forModAssignmentExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forModAssignmentExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forNumericAssignmentExpressionOnly

public TypeData forNumericAssignmentExpressionOnly(NumericAssignmentExpression that,
                                                   TypeData nameRes,
                                                   TypeData valueRes)
A NumericAssignmentExpression is okay if both the lhs and the rhs are instances, both are numbers, and the rhs is assignable to the lhs. Return the lhs, or null

Overrides:
forNumericAssignmentExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleAssignmentExpression being typechecked
nameRes - The TypeData representing the lhs of the assignment
valueRes - The TypeData representing the rhs of the assignment
Returns:
An instance of the lhs, or null if the lhs or rhs could not be resolved.

forShiftAssignmentExpressionOnly

public TypeData forShiftAssignmentExpressionOnly(ShiftAssignmentExpression that,
                                                 TypeData nameRes,
                                                 TypeData valueRes)
Not currently supported.

Overrides:
forShiftAssignmentExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forBitwiseAssignmentExpressionOnly

public TypeData forBitwiseAssignmentExpressionOnly(BitwiseAssignmentExpression that,
                                                   TypeData nameRes,
                                                   TypeData valueRes)
Not currently supported.

Overrides:
forBitwiseAssignmentExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forBooleanExpressionOnly

public TypeData forBooleanExpressionOnly(BooleanExpression that,
                                         TypeData left_result,
                                         TypeData right_result)
Checks if this BooleanExpression is well-formed, i.e., that left and right arguments are well-formed boolean expressions. Throws an appropriate error if ill-formed. Always returns the boolean instance type.

Overrides:
forBooleanExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The BooleanExpression being checked
left_result - The result from visiting the left side of the BooleanExpression
right_result - The result from visiting the right side of the BooleanExpression
Returns:
The boolean instance type

forBitwiseBinaryExpressionOnly

public TypeData forBitwiseBinaryExpressionOnly(BitwiseBinaryExpression that,
                                               TypeData left_result,
                                               TypeData right_result)
Not currently supported.

Overrides:
forBitwiseBinaryExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forEqualityExpressionOnly

public TypeData forEqualityExpressionOnly(EqualityExpression that,
                                          TypeData left_result,
                                          TypeData right_result)
This EqualityExpression is badly formed if left_result and right_result have incompatible types. Both left and the right should be instance datas. Throws an error if ill-formed. Returns the InstanceData corresponding to boolean, the return type from an equality check.

Overrides:
forEqualityExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The EqualityExpression being checked
left_result - The result of visiting the left side of the expression
right_result - The result of visiting the right side of the expression
Returns:
SymbolData.BOOLEAN_TYPE.getInstanceData()

forComparisonExpressionOnly

public TypeData forComparisonExpressionOnly(ComparisonExpression that,
                                            TypeData left_result,
                                            TypeData right_result)
Verify that both the left and right of this comparison expression are number types and InstanceDatas. Give an error if this is not the case. Return the InstanceData for boolean, since that is the result of a comparison expression.

Overrides:
forComparisonExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The Comparison expression being type-checked
left_result - The result of visiting the left side of the expression
right_result - The result of visiting the right side of the expression
Returns:
SymbolData.BOOLEAN_TYPE.getInstanceData()

forShiftBinaryExpressionOnly

public TypeData forShiftBinaryExpressionOnly(ShiftBinaryExpression that,
                                             TypeData left_result,
                                             TypeData right_result)
Not currently supported

Overrides:
forShiftBinaryExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forPlusExpressionOnly

public TypeData forPlusExpressionOnly(PlusExpression that,
                                      TypeData left_result,
                                      TypeData right_result)
A plus operator can either be used on a string and any other type of object or on two numbers. If one of the arguments is of String type, check to make sure that both types are InstanceDatas and then return an InstanceData for String. If neither of the arguments are a String type, verify that they are both number types and both InstanceDatas, and return the Instance Data corresponding to their least restrictive type.

Overrides:
forPlusExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The PlusExpression being type-checked.
left_result - The result of visiting the left side of this plus expression
right_result - The result of visiting the right side of this plus expression

forNumericBinaryExpressionOnly

public TypeData forNumericBinaryExpressionOnly(NumericBinaryExpression that,
                                               TypeData left_result,
                                               TypeData right_result)
Check if this NumericBinaryExpression was okay. It is not okay if either the left or the right result are not number types or if they are not instance datas. Throw an appropriate error if any of these is the case. Always return the least restrictive subtype of the left and the right.

Overrides:
forNumericBinaryExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The NumericBinaryExpression being checked
left_result - The result from visiting the left side of the NumericBinaryExpression
right_result - The result from visiting the right side of the NumericBinaryExpression
Returns:
An InstanceData of the least restrictive type of the left and right sides.

forNoOpExpressionOnly

public TypeData forNoOpExpressionOnly(NoOpExpression that,
                                      TypeData left_result,
                                      TypeData right_result)
This should have been caught in the first pass. Throw a RuntimeException.

Overrides:
forNoOpExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forIncrementExpression

public TypeData forIncrementExpression(IncrementExpression that)
Visit the value of this increment expression with the LValueWithValueTypeChecker, since whatever it represents should already have a value before we try to increment it.


forPositivePrefixIncrementExpression

public TypeData forPositivePrefixIncrementExpression(PositivePrefixIncrementExpression that)
For these concrete instantiations of IncrementExpression, delegate to abstract method

Specified by:
forPositivePrefixIncrementExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forPositivePrefixIncrementExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forNegativePrefixIncrementExpression

public TypeData forNegativePrefixIncrementExpression(NegativePrefixIncrementExpression that)
Description copied from interface: JExpressionIFVisitor
Process an instance of NegativePrefixIncrementExpression.

Specified by:
forNegativePrefixIncrementExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forNegativePrefixIncrementExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forPositivePostfixIncrementExpression

public TypeData forPositivePostfixIncrementExpression(PositivePostfixIncrementExpression that)
Description copied from interface: JExpressionIFVisitor
Process an instance of PositivePostfixIncrementExpression.

Specified by:
forPositivePostfixIncrementExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forPositivePostfixIncrementExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forNegativePostfixIncrementExpression

public TypeData forNegativePostfixIncrementExpression(NegativePostfixIncrementExpression that)
Description copied from interface: JExpressionIFVisitor
Process an instance of NegativePostfixIncrementExpression.

Specified by:
forNegativePostfixIncrementExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forNegativePostfixIncrementExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forIncrementExpressionOnly

public TypeData forIncrementExpressionOnly(IncrementExpression that,
                                           TypeData valueRes)
An IncrementExpression is badly formatted if the thing being incremented is a type (valueRes is not an InstanceData) or if the value being incremented cannot be assigned to. Throw an error in either of these cases.

Overrides:
forIncrementExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The IncrementExpression that is being type checked.
valueRes - The result of evaluating the argument to the increment expression.
Returns:
The type of what is being incremented.

forNumericUnaryExpressionOnly

public TypeData forNumericUnaryExpressionOnly(NumericUnaryExpression that,
                                              TypeData valueRes)
A NumericUnaryExpression was well-formed if its valueRes is an instance type and if its valueRes's symbol data is a number type (to which a double can be assigned). If this numeric unary expression was not well formed, throw an error.

Overrides:
forNumericUnaryExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The NumericUnaryExpression being evaluated
valueRes - The result of evaluating the argument to this expression.
Returns:
The new result of this expression.

forBitwiseNotExpressionOnly

public TypeData forBitwiseNotExpressionOnly(BitwiseNotExpression that,
                                            TypeData valueRes)
Not Currently Supported.

Overrides:
forBitwiseNotExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forNotExpressionOnly

public TypeData forNotExpressionOnly(NotExpression that,
                                     TypeData valueRes)
A NotExpression is illformed if its argument is not an instance type or its argument is not of type boolean. Give an error if this is the case. Always return SymbolData.BOOLEAN_TYPE.getInstanceData() since this is the correct type for this expression.

Overrides:
forNotExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The NotExpression being type-checked
valueRes - The type of the argument to the NotExpression
Returns:
SymbolData.BOOLEAN_TYPE.getInstanceData()

forConditionalExpressionOnly

public TypeData forConditionalExpressionOnly(ConditionalExpression that,
                                             TypeData condition_result,
                                             TypeData forTrue_result,
                                             TypeData forFalse_result)
Not currently supported

Overrides:
forConditionalExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forInstanceofExpressionOnly

public TypeData forInstanceofExpressionOnly(InstanceofExpression that,
                                            TypeData typeRes,
                                            TypeData valueRes)
Checks to see if this InstanceofExpression is okay. It is not okay if typeRes is not a SymbolData, valueRes is not an InstanceData, or if valueRes cannot be cast to typeRes. If any of these are true, give an appropriate error message. Return an instance data corresponding to typeRes.

Overrides:
forInstanceofExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The CastExpression being examined.
typeRes - The type to be checked
valueRes - The instance type of what is being checked
Returns:
typeRes's instance data.

forCastExpressionOnly

public TypeData forCastExpressionOnly(CastExpression that,
                                      TypeData typeRes,
                                      TypeData valueRes)
Checks to see if this CastExpression is okay. It is not okay if typeRes is not a SymbolData, valueRes is not an InstanceData, or if valueRes cannot be cast to typeRes. If any of these are the case, give an appropriate error message. Return an instance data corresponding to typeRes.

Overrides:
forCastExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The CastExpression being examined.
typeRes - The type of the cast expression
valueRes - The instance type of what is being cast
Returns:
typeRes's instance data.

forEmptyExpressionOnly

public TypeData forEmptyExpressionOnly(EmptyExpression that)
Gives a Runtime Exception, because the fact that there is an EmptyExpression here should have been caught before the TypeChecker pass.

Overrides:
forEmptyExpressionOnly in class JExpressionIFDepthFirstVisitor<TypeData>

classInstantiationHelper

public InstanceData classInstantiationHelper(ClassInstantiation that,
                                             SymbolData classToInstantiate)
Visit the ClassInstantiation's arguments. Lookup the required constructor matching the ClassInstantiation's argument types. Check accessibility of the constructor. In all cases, returns classToInstantiate.getInstanceData.


forSimpleNamedClassInstantiation

public TypeData forSimpleNamedClassInstantiation(SimpleNamedClassInstantiation that)
Handles a simple class instantiation. If the type of the instantiation is not resolved, returns null because an error has already been thrown. Also checks to see if the class being instantiated is non-static, is not a top level class, and the name used has a dot in it. If so, then a non-static inner class is being referenced like a static inner class, and an error is thrown. After performing these checks, delegates to the class Instantion helper, which will resolve the type of the class.

Specified by:
forSimpleNamedClassInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleNamedClassInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
The InstanceData corresponding to the instantiation

forComplexNamedClassInstantiation

public TypeData forComplexNamedClassInstantiation(ComplexNamedClassInstantiation that)
Handles this complex named class instantiation. First, visit the lhs and get the enclosing type. If the enclosing type is null, or a PackageData, return null, because an error has already been thrown. Otherwise, call the classInstantiationHelper to get a new instance of the rhs, from the context of the lhs. It is an error if the class being instantiated is non-static, but it is called from a static context. It is an error if the class being instantiated is static but it is being called as a.new B();

Specified by:
forComplexNamedClassInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexNamedClassInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The ComplexNamedClassInstantiation being created
Returns:
An InstanceData corresponding to the instantiation

handleAnonymousClassInstantiation

public SymbolData handleAnonymousClassInstantiation(AnonymousClassInstantiation that,
                                                    SymbolData superC)
Do the work that is shared between SimpleAnonymousClassInstantiation and ComplexAnonymousClassInstantiation. Basically, update the anonymous inner class corresponding to the enclosing data and the superC with superC and accessors, if necessary.

Parameters:
that - The AnonymousClassInstantiation being processed.
superC - The SymbolData corresponding to the super class of this instantiation (the type being created)

forSimpleAnonymousClassInstantiation

public TypeData forSimpleAnonymousClassInstantiation(SimpleAnonymousClassInstantiation that)
Resolve the type of this anonymous class. Look it up in the enclosing data, check that it is using a valid constructor through the classInstantiationHelper and visit the body. Make sure that all abstract methods are overwritten.

Specified by:
forSimpleAnonymousClassInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleAnonymousClassInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleAnonymousClassInstantiation being type-checked
Returns:
The result of type checking the class instantiation.

forComplexAnonymousClassInstantiation

public TypeData forComplexAnonymousClassInstantiation(ComplexAnonymousClassInstantiation that)
Resolve the type of this anonymous class. Look it up in enclosing data, check that it is using a valid constructor through the classInstantiationHelper and visit the body. Make sure that all abstract methods are overwritten. The enclosing data is found by first resolving the enclosing data. Make sure that if this is an inner class it is being called from the appropriate static/non-static context (see ComplexNamedClassInstantiation for more details).

Specified by:
forComplexAnonymousClassInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexAnonymousClassInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleAnonymousClassInstantiation being type-checked
Returns:
The result of type checking the class instantiation.

forSimpleThisConstructorInvocation

public TypeData forSimpleThisConstructorInvocation(SimpleThisConstructorInvocation that)
SimpleThisConstructorInvocations are not allowed outside of the first line of a constructor.

Specified by:
forSimpleThisConstructorInvocation in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleThisConstructorInvocation in class JExpressionIFDepthFirstVisitor<TypeData>

forComplexThisConstructorInvocation

public TypeData forComplexThisConstructorInvocation(ComplexThisConstructorInvocation that)
ComplexThisConstructorInvocations are not ever allowed.

Specified by:
forComplexThisConstructorInvocation in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexThisConstructorInvocation in class JExpressionIFDepthFirstVisitor<TypeData>

forSimpleNameReference

public TypeData forSimpleNameReference(SimpleNameReference that)
Try to resolve this SimpleNameReference. It is either: 1. a field or variable reference (return the instance type of the field/variable) 2. a class or interface name reference (return the type of the class or interface) 3. part of a package reference or an error (return a new package data corresponding to the reference. No need to call forSimpleNameReference only, since all the checking is done here.

Specified by:
forSimpleNameReference in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleNameReference in class JExpressionIFDepthFirstVisitor<TypeData>

forComplexNameReference

public TypeData forComplexNameReference(ComplexNameReference that)
To resolve this ComplexNameReference, first visit the lhs with an instance of this visitor in order to get its type. Then, try to figure out how the name reference on the right fits with the type on the left. 1. If the lhs is a package data, then either the rhs is a class reference, or the whole thing is another PackageData. 2. If the rhs is a variable or field visible from the context of the lhs, it must be static if the lhs is a SymbolData, and regardless, it must have a value to be referenced here. 3. If the rhs references an inner class of the lhs, the lhs must be a SymbolData if the rhs is a static inner class, and the rhs must be static if the lhs is a SymbolData. 4. Otherwise, give an error because we couldn't resolve the symbol.

Specified by:
forComplexNameReference in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexNameReference in class JExpressionIFDepthFirstVisitor<TypeData>

forSimpleThisReference

public TypeData forSimpleThisReference(SimpleThisReference that)
Make sure we are in a non-static context.

Specified by:
forSimpleThisReference in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleThisReference in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
an instance data corresponding to the enclosing class of this context.

forComplexThisReferenceOnly

public TypeData forComplexThisReferenceOnly(ComplexThisReference that,
                                            TypeData enclosing_result)
Check to make sure that the enclosing result could be resolved and that it a type name. Insure that an enclosing instance of that name exists in the current (non-static) context. Return the instance data corresponding to its "this" field.

Overrides:
forComplexThisReferenceOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The ComplexThisReference we are type-checking
enclosing_result - The TypeData whose this field is being referenced
Returns:
An InstanceData corresponding to the enclosing_result.

forSimpleSuperReference

public TypeData forSimpleSuperReference(SimpleSuperReference that)
All classes should have a super class, which is java.lang.Object by default. Looks up this class's super class. If it is null, generates an error (this should never happen). Otherwise, returns the instance data corresponding to the super class.

Specified by:
forSimpleSuperReference in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleSuperReference in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleSuperReference we are resolving.
Returns:
InstanceData corresponding to the super class

forComplexSuperReferenceOnly

public TypeData forComplexSuperReferenceOnly(ComplexSuperReference that,
                                             TypeData enclosing_result)
Makes sure that the enclosing result is not null--if it is, return null. Insure that an enclosing instance of that name exists in the current (non-static) context. Give an error if the enclosing_result is not an instance type. Get its super class, and return an instance data corresponding to it.

Overrides:
forComplexSuperReferenceOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The ComplexSuperReference being typechecked
enclosing_result - The type of the left hand side of this reference.
Returns:
An InstanceData corresponding to the super class of enclosing_result.

forArrayAccessOnly

public TypeData forArrayAccessOnly(ArrayAccess that,
                                   TypeData lhs,
                                   TypeData index)
Make sure the lhs is actually an array type and that the index is an int.

Overrides:
forArrayAccessOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forStringLiteralOnly

public TypeData forStringLiteralOnly(StringLiteral that)
Overrides:
forStringLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forIntegerLiteralOnly

public TypeData forIntegerLiteralOnly(IntegerLiteral that)
Overrides:
forIntegerLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forLongLiteralOnly

public TypeData forLongLiteralOnly(LongLiteral that)
Overrides:
forLongLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forFloatLiteralOnly

public TypeData forFloatLiteralOnly(FloatLiteral that)
Overrides:
forFloatLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forDoubleLiteralOnly

public TypeData forDoubleLiteralOnly(DoubleLiteral that)
Overrides:
forDoubleLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forCharLiteralOnly

public TypeData forCharLiteralOnly(CharLiteral that)
Overrides:
forCharLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forBooleanLiteralOnly

public TypeData forBooleanLiteralOnly(BooleanLiteral that)
Overrides:
forBooleanLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forNullLiteralOnly

public TypeData forNullLiteralOnly(NullLiteral that)
Overrides:
forNullLiteralOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forClassLiteralOnly

public TypeData forClassLiteralOnly(ClassLiteral that)

forParenthesizedOnly

public TypeData forParenthesizedOnly(Parenthesized that,
                                     TypeData valueRes)
Check a few constraints on this Parenthesized

Overrides:
forParenthesizedOnly in class JExpressionIFDepthFirstVisitor<TypeData>

methodInvocationHelper

public TypeData methodInvocationHelper(MethodInvocation that,
                                       TypeData context)
Look up the method called in the method invocation within the context of the context TypeData. Resolve all arguments to the method, and make sure they are instance datas. If an argument is a type, the method cannot be found, or the method is called from a static context but is not static, give appropriate error. If the method is declared to throw any exceptions, add them to the thrown list.

Parameters:
that - The MethodInvocation we are type checking
context - The TypeData that should contain the method being invoked.

forSimpleMethodInvocation

public TypeData forSimpleMethodInvocation(SimpleMethodInvocation that)
Tries to match this method invocation to a method in the context. Here, the context is the enclosing data for where this is being invoked.

Specified by:
forSimpleMethodInvocation in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleMethodInvocation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - SimpleMethodInvocation we are typechecking
Returns:
The return type of the method, or null if method cannot be seen or found.

forComplexMethodInvocation

public TypeData forComplexMethodInvocation(ComplexMethodInvocation that)
Tries to match this method invocation to a method in the context. Here, the context is the enclosing field of the method invocation.

Specified by:
forComplexMethodInvocation in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexMethodInvocation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - ComplexMethodInvocation we are typechecking
Returns:
The return type of the method, or null if method cannot be seen or found.

canBeAssigned

protected boolean canBeAssigned(VariableData vd)
A variable data can be assigned to if it is not final or it does not have a value. (in other words, only final variables that have already been assigned are the only type that cannot be given a value.

Overrides:
canBeAssigned in class SpecialTypeChecker
Parameters:
vd - The VariableData to check.

_getLeastRestrictiveType

protected SymbolData _getLeastRestrictiveType(SymbolData sd1,
                                              SymbolData sd2)
Returns the least restrictive numerical type. According to the JLS: "If an integer operator other than a shift operator has at least one operand of type long, then the operation is carried out using 64-bit precision, and the result of the numerical operator is of type long. If the other operand is not long, it is first widened (??5.1.4) to type long by numeric promotion (??5.6). Otherwise, the operation is carried out using 32-bit precision, and the result of the numerical operator is of type int. If either operand is not an int, it is first widened to type int by numeric promotion." So, check to see if one fo the SymboLDatas is a type less restrictive than int. If so, return that type, otherwise return INT_TYPE.


forConditionalExpression

public TypeData forConditionalExpression(ConditionalExpression that)
Throw runtime exception, since conditional expressions are not allowed, and this should have been caught before the TypeChecker.

Specified by:
forConditionalExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forConditionalExpression in class JExpressionIFDepthFirstVisitor<TypeData>

forInstanceofExpression

public TypeData forInstanceofExpression(InstanceofExpression that)
Try to look up the type of the instanceof, and visit the expression that is being tested. If the type of the instanceof is null, add an error, and return null. If what is being tested cannot be resolved, just return the type boolean to allow further type checking. If everything is okay, call forInstanceofExpressionOnly to do other checks.

Specified by:
forInstanceofExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forInstanceofExpression in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The InstanceofExpression being typeChecked
Returns:
The TypeData for boolean, or null

forCastExpression

public TypeData forCastExpression(CastExpression that)
Try to look up the type of the cast, and visit the expression that is being cast. If the type being cast to is null, add an error, and return null. If what is being cast cannot be resolved, just return the expected result of the cast, to allow type checking. If everything is okay, call forCastExpressionOnly to do other checks.

Specified by:
forCastExpression in interface JExpressionIFVisitor<TypeData>
Overrides:
forCastExpression in class TypeChecker
Parameters:
that - The CastExpression being typeChecked
Returns:
The TypeData result of the cast, or null

forUninitializedArrayInstantiationOnly

public TypeData forUninitializedArrayInstantiationOnly(UninitializedArrayInstantiation that,
                                                       TypeData typeRes,
                                                       TypeData[] dimensions_result)
Make sure the dimensions of the array instantiation are all instances and subtypes of int, and then return an instance of the array.

Parameters:
that - The UninitializedArrayInstantiation being type checked
typeRes - The type of the array
dimensions_result - The array of the result of type-checking all the dimensions of this array.
Returns:
an instance of the array.

forSimpleUninitializedArrayInstantiation

public TypeData forSimpleUninitializedArrayInstantiation(SimpleUninitializedArrayInstantiation that)
Resolve the type of the array and visit its dimensions. Call Only method to check instances in dimensions.

Specified by:
forSimpleUninitializedArrayInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleUninitializedArrayInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleUninitializedArrayInstantiation being type-checked.
Returns:
The type of the array, or null if there was an error.

forComplexUninitializedArrayInstantiation

public TypeData forComplexUninitializedArrayInstantiation(ComplexUninitializedArrayInstantiation that)
This is not legal java--should have been caught before the TypeChecker. Give a runtime exception

Specified by:
forComplexUninitializedArrayInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexUninitializedArrayInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>

forArrayInitializer

public TypeData forArrayInitializer(ArrayInitializer that)
The array initializer needs the type of the array to ensure it is properly handled. Because of this, we use a helper instead of calling this method directly.

Specified by:
forArrayInitializer in interface JExpressionIFVisitor<TypeData>
Overrides:
forArrayInitializer in class JExpressionIFDepthFirstVisitor<TypeData>

forSimpleInitializedArrayInstantiation

public TypeData forSimpleInitializedArrayInstantiation(SimpleInitializedArrayInstantiation that)
Lookup the type of the array instantiation, and if there are any errors with it, give them. Then, check the array initializer.

Specified by:
forSimpleInitializedArrayInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forSimpleInitializedArrayInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The SimpleInitializedArrayAllocationInstantiation that is being type-checked
Returns:
An instance of the array

forComplexInitializedArrayInstantiation

public TypeData forComplexInitializedArrayInstantiation(ComplexInitializedArrayInstantiation that)
This is not legal java--should have been caught before the TypeChecker. Give a runtime exception

Specified by:
forComplexInitializedArrayInstantiation in interface JExpressionIFVisitor<TypeData>
Overrides:
forComplexInitializedArrayInstantiation in class JExpressionIFDepthFirstVisitor<TypeData>

forInnerClassDef

public TypeData forInnerClassDef(InnerClassDef that)
Description copied from class: SpecialTypeChecker
Look up the SymbolData for this InnerClass within the enclosing data, check for cyclic inheritance, and then visit everything inside the inner class.

Specified by:
forInnerClassDef in interface JExpressionIFVisitor<TypeData>
Overrides:
forInnerClassDef in class SpecialTypeChecker
Parameters:
that - The InnerClassDef we're visiting

handleUncheckedException

public void handleUncheckedException(SymbolData sd,
                                     JExpression j)
Throw the appropriate error, based on the type of the JExpression where the exception was unchecked

Overrides:
handleUncheckedException in class SpecialTypeChecker
Parameters:
sd - The SymbolData corresponding to the exception that is thrown
j - The JExpression corresponding to the context of where the exception is thrown from.

isCheckedException

public boolean isCheckedException(SymbolData sd,
                                  JExpression that)
Returns whether the sd is a checked exception, i.e. one that needs to be caught or declared to be thrown. This is defined as all subclasses of java.lang.Throwable except for subclasses of java.lang.RuntimeException

Overrides:
isCheckedException in class SpecialTypeChecker

isUncaughtCheckedException

public boolean isUncaughtCheckedException(SymbolData sd,
                                          JExpression that)
Return true if the Exception is a checked exception yet is not caught or declared to be thrown, and false otherwise. An exception is a checked if it does not extend either java.lang.RuntimeException or java.lang.Error, and is not declared to be thrown by the enclosing method.

Overrides:
isUncaughtCheckedException in class SpecialTypeChecker
Parameters:
sd - The SymbolData of the Exception we are checking.
that - The JExpression passed to getSymbolData for error purposes.

forBracedBody

public TypeData forBracedBody(BracedBody that)
Description copied from class: SpecialTypeChecker
Delegate to forBody

Specified by:
forBracedBody in interface JExpressionIFVisitor<TypeData>
Overrides:
forBracedBody in class SpecialTypeChecker

forEmptyForCondition

public TypeData forEmptyForCondition(EmptyForCondition that)
Description copied from interface: JExpressionIFVisitor
Process an instance of EmptyForCondition.

Specified by:
forEmptyForCondition in interface JExpressionIFVisitor<TypeData>
Overrides:
forEmptyForCondition in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
true type by default.