edu.rice.cs.javalanglevels
Class BodyTypeChecker

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.BodyTypeChecker
All Implemented Interfaces:
JExpressionIFVisitor<TypeData>
Direct Known Subclasses:
ConstructorBodyTypeChecker, TryCatchBodyTypeChecker

public class BodyTypeChecker
extends SpecialTypeChecker

TypeChecks the context of a body, such as a method body. Common to all Language Levels.


Nested Class Summary
static class BodyTypeChecker.BodyTypeCheckerTest
          Test the methods in the above 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
protected  BodyData _bodyData
          The MethodData of this method.
 
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, NULL_LITERAL
 
Constructor Summary
BodyTypeChecker(BodyData bodyData, File file, String packageName, LinkedList<String> importedFiles, LinkedList<String> importedPackages, LinkedList<VariableData> vars, LinkedList<Pair<SymbolData,JExpression>> thrown)
          Constructor for BodyTypeChecker.
 
Method Summary
protected  Data _getData()
          The top level type checker does not have a data
protected  void checkDuplicateExceptions(TryCatchStatement that)
          Makes sure that no super class of any exception is caught before the current exception's catch block.
protected  void compareThrownAndCaught(TryCatchStatement that, SymbolData[] caught_array, LinkedList<Pair<SymbolData,JExpression>> thrown)
          Make sure that every Exception in thrown is either in caught or in the list of what can be thrown from where we are.
protected  BodyTypeChecker createANewInstanceOfMe(BodyData bodyData, File file, String pakage, LinkedList<String> importedFiles, LinkedList<String> importedPackages, LinkedList<VariableData> vars, LinkedList<Pair<SymbolData,JExpression>> thrown)
          Create a new instance of this class for visiting inner bodies.
 TypeData forBlock(Block that)
          Process an instance of Block.
 TypeData forBodyOnly(Body that, TypeData[] items_result)
          Look at the result of each item in the body.
 TypeData forBracedBodyOnly(BracedBody that, TypeData[] items_result)
          Delegates to forBodyOnly.
 TypeData forCatchBlock(CatchBlock that)
          Resolves the type of the exception, and visits the body, making sure the exception variable is in scope.
 TypeData forCatchBlockOnly(CatchBlock that, SymbolData exception_result, TypeData block_result)
           
 TypeData forDefaultCase(DefaultCase that)
          Delegate handling this default case to its superclass.
 TypeData forDoStatement(DoStatement that)
          First, visit the body of the do statement with a body type checker.
 TypeData forDoStatementOnly(DoStatement that, TypeData codeRes, TypeData condition_result)
          Make sure that the condition statement of the while returns type boolean.
 TypeData forForStatement(ForStatement that)
          First, visit the condition expression of the for statement with a special visitor that makes sure no assignment is done.
 TypeData forForStatementOnly(ForStatement that, TypeData init_result, TypeData condition_result, TypeData update_result, TypeData codeRes)
           
 TypeData forIfThenElseStatement(IfThenElseStatement that)
          First, visit the condition expression of the if-then-else statement with a special visitor that makes sure no assignment is done.
 TypeData forIfThenElseStatementOnly(IfThenElseStatement that, TypeData testExpression_result, TypeData thenStatement_result, TypeData elseStatement_result)
          Make sure that the conditional expression has the right type, and if both branches of the if/else return, return a value the common super type of the two return types.
 TypeData forIfThenStatement(IfThenStatement that)
          First, visit the condition expression of the if statement with a special visitor that makes sure no assignment is done.
 TypeData forIfThenStatementOnly(IfThenStatement that, TypeData testExpression_result, TypeData thenStatement_result)
           
 TypeData forInstanceInitializer(InstanceInitializer that)
          Process an instance of InstanceInitializer.
 TypeData forLabeledCase(LabeledCase that)
          Make sure that the label for this LabeledCase is correct.
 TypeData forNormalTryCatchStatement(NormalTryCatchStatement that)
          Process an instance of NormalTryCatchStatement.
 TypeData forNormalTryCatchStatementOnly(NormalTryCatchStatement that, TypeData tryBlockRes, TypeData[] catchBlocksRes)
          Assumes that tryBlockRes, catchBlocksRes, and finallyBlock_result are InstanceDatas
 TypeData forSimpleSuperReferenceOnly(SimpleSuperReference that)
           
 TypeData forSimpleThisReferenceOnly(SimpleThisReference that)
           
 TypeData forSwitchCase(SwitchCase that)
          Visit the Braced Body of this SwitchCase, and return the result.
 TypeData forSwitchStatement(SwitchStatement that)
          Process an instance of SwitchStatement.
 TypeData forSwitchStatementOnly(SwitchStatement that, TypeData testRes, TypeData[] cases_result, boolean sawDefault)
          Here, we follow the following rules for determining what to return: If there is not a default block, the statement does not return.
 TypeData forTryCatchFinallyStatement(TryCatchFinallyStatement that)
          Process an instance of TryCatchFinallyStatement.
 TypeData forTryCatchFinallyStatementOnly(TryCatchFinallyStatement that, TypeData tryBlockRes, TypeData[] catchBlocksRes, TypeData finallyBlock_result)
          Assumes that tryBlockRes, catchBlocksRes, and finallyBlock_result are InstanceDatas.
 TypeData forTypeOnly(Type that)
           
 TypeData forUnbracedBodyOnly(UnbracedBody that, TypeData[] items_result)
          Delegates to forBodyOnly.
 TypeData forUninitializedVariableDeclaratorOnly(UninitializedVariableDeclarator that, TypeData typeRes, TypeData nameRes)
          We need to do this so that expressions (which should only occur in variable initializers and initializer blocks) can know which fields have already been declared.
 TypeData forValueReturnStatement(ValueReturnStatement that)
          Visit the value being returned to determine its type.
 TypeData forValueReturnStatementOnly(ValueReturnStatement that, TypeData valueRes)
          Make sure that the enclosing method is declared to throw the same type as the return statement is trying to return.
 TypeData forVoidReturnStatementOnly(VoidReturnStatement that)
          Make sure the enclosing method data is declared to return void.
 TypeData forWhileStatement(WhileStatement that)
          First, visit the condition expression of the while statement with a special visitor that makes sure no assignment is done.
 TypeData forWhileStatementOnly(WhileStatement that, TypeData condition_result, TypeData codeRes)
          Make sure that the condition statement of the while returns type boolean.
protected  SymbolData getCommonSuperType(SymbolData s1, SymbolData s2)
          Check if the two given SymbolDatas have a common super type.
protected  boolean isException(SymbolData sd)
           
 boolean isUncaughtCheckedException(SymbolData sd, JExpression that)
          Return true if the Exception is unchecked, and false otherwise.
protected  void makeSureCaughtStuffWasThrown(TryCatchStatement that, SymbolData[] caught_array, LinkedList<Pair<SymbolData,JExpression>> thrown)
          Make sure that every exception that is caught could have been thrown in the try statement
protected  InstanceData tryCatchLeastRestrictiveType(InstanceData tryBlockRes, InstanceData[] catchBlocksRes, InstanceData finallyBlock_result)
          Returns the least restrictive type returned by the try block and catch blocks.
 
Methods inherited from class edu.rice.cs.javalanglevels.SpecialTypeChecker
canBeAssigned, findClassReference, forArrayInitializerHelper, forBody, forBracedBody, forExpressionStatement, forFormalParameter, forInitializedVariableDeclarator, forInitializedVariableDeclaratorOnly, forInnerClassDef, forInnerInterfaceDef, forLabeledStatement, forStaticInitializer, forSynchronizedStatement, forThrowStatement, forThrowStatementOnly, forUnbracedBody, forUninitializedVariableDeclarator, forVariableDeclaration, getArgTypesForInvocation, handleMethodInvocation, handleUncheckedException, inStaticMethod, isCheckedException
 
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, forCastExpression, 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, forArrayAccessOnly, forArrayInitializer, forArrayInitializerOnly, forArrayInstantiationOnly, forArrayType, forArrayTypeOnly, forAssignmentExpressionOnly, forBinaryExpressionOnly, forBitwiseAndAssignmentExpression, forBitwiseAndAssignmentExpressionOnly, forBitwiseAndExpression, forBitwiseAndExpressionOnly, forBitwiseAssignmentExpressionOnly, forBitwiseBinaryExpressionOnly, forBitwiseNotExpression, forBitwiseNotExpressionOnly, forBitwiseOrAssignmentExpression, forBitwiseOrAssignmentExpressionOnly, forBitwiseOrExpression, forBitwiseOrExpressionOnly, forBitwiseXorAssignmentExpression, forBitwiseXorAssignmentExpressionOnly, forBitwiseXorExpression, forBitwiseXorExpressionOnly, forBlockOnly, forBooleanExpressionOnly, forBooleanLiteral, forBooleanLiteralOnly, forCastExpressionOnly, forCatchBlockOnly, forCharLiteral, forCharLiteralOnly, forClassImportStatementOnly, forClassInstantiationOnly, forClassLiteral, forClassLiteralOnly, forClassOrInterfaceType, forClassOrInterfaceTypeOnly, forComparisonExpressionOnly, forComplexAnonymousClassInstantiation, forComplexAnonymousClassInstantiationOnly, forComplexInitializedArrayInstantiation, forComplexInitializedArrayInstantiationOnly, forComplexMethodInvocation, forComplexMethodInvocationOnly, forComplexNamedClassInstantiation, forComplexNamedClassInstantiationOnly, forComplexNameReference, forComplexNameReferenceOnly, forComplexSuperConstructorInvocation, forComplexSuperConstructorInvocationOnly, forComplexSuperReference, forComplexSuperReferenceOnly, forComplexThisConstructorInvocation, forComplexThisConstructorInvocationOnly, forComplexThisReference, forComplexThisReferenceOnly, forComplexUninitializedArrayInstantiation, forComplexUninitializedArrayInstantiationOnly, forCompoundWord, forCompoundWordOnly, forConcreteMethodDef, forConcreteMethodDefOnly, forConditionalExpression, forConditionalExpressionOnly, forConstructorDef, forConstructorDefOnly, forDefaultCaseOnly, forDimensionExpressionList, forDimensionExpressionListOnly, forDivideAssignmentExpression, forDivideAssignmentExpressionOnly, forDivideExpression, forDivideExpressionOnly, forDoubleLiteral, forDoubleLiteralOnly, forEmptyExpression, forEmptyExpressionOnly, forEmptyForCondition, forEmptyForConditionOnly, forEmptyStatement, forEmptyStatementOnly, forEqualityExpressionOnly, forEqualsExpression, forEqualsExpressionOnly, forExpressionListOnly, forExpressionOnly, forFloatLiteral, forFloatLiteralOnly, forFormalParameterOnly, forFunctionInvocationOnly, forGreaterThanExpression, forGreaterThanExpressionOnly, forGreaterThanOrEqualExpression, forGreaterThanOrEqualExpressionOnly, forImportStatementOnly, forIncrementExpressionOnly, forInitializedArrayInstantiationOnly, forInitializerOnly, forInstanceofExpression, forInstanceofExpressionOnly, forInstantiationOnly, forIntegerLiteral, forIntegerLiteralOnly, forJExpressionOnly, forLabeledBreakStatement, forLabeledBreakStatementOnly, forLabeledCaseOnly, forLabeledContinueStatement, forLabeledContinueStatementOnly, forLabeledStatementOnly, forLeftShiftAssignmentExpression, forLeftShiftAssignmentExpressionOnly, forLeftShiftExpression, forLeftShiftExpressionOnly, forLessThanExpression, forLessThanExpressionOnly, forLessThanOrEqualExpression, forLessThanOrEqualExpressionOnly, forLexicalLiteralOnly, forLongLiteral, forLongLiteralOnly, forMemberType, forMemberTypeOnly, forMethodDefOnly, forMethodInvocationOnly, forMinusAssignmentExpression, forMinusAssignmentExpressionOnly, forMinusExpression, forMinusExpressionOnly, forModAssignmentExpression, forModAssignmentExpressionOnly, forModExpression, forModExpressionOnly, forModifiersAndVisibility, forModifiersAndVisibilityOnly, forMultiplyAssignmentExpression, forMultiplyAssignmentExpressionOnly, forMultiplyExpression, forMultiplyExpressionOnly, forNamedClassInstantiationOnly, forNameReferenceOnly, forNegativeExpression, forNegativeExpressionOnly, forNegativePostfixIncrementExpression, forNegativePostfixIncrementExpressionOnly, forNegativePrefixIncrementExpression, forNegativePrefixIncrementExpressionOnly, forNoOpExpression, forNoOpExpressionOnly, forNotEqualExpression, forNotEqualExpressionOnly, forNotExpression, forNotExpressionOnly, forNullLiteral, forNullLiteralOnly, forNumericAssignmentExpressionOnly, forNumericBinaryExpressionOnly, forNumericUnaryExpressionOnly, forOrExpression, forOrExpressionOnly, forPackageImportStatement, forPackageImportStatementOnly, forPackageStatementOnly, forParenthesized, forParenthesizedExpressionList, forParenthesizedExpressionListOnly, forParenthesizedOnly, forPlusAssignmentExpression, forPlusAssignmentExpressionOnly, forPlusExpression, forPlusExpressionOnly, forPositiveExpression, forPositiveExpressionOnly, forPositivePostfixIncrementExpression, forPositivePostfixIncrementExpressionOnly, forPositivePrefixIncrementExpression, forPositivePrefixIncrementExpressionOnly, forPostfixIncrementExpressionOnly, forPrefixIncrementExpressionOnly, forPrimaryOnly, forPrimitiveTypeOnly, forReferenceTypeOnly, forRightSignedShiftAssignmentExpression, forRightSignedShiftAssignmentExpressionOnly, forRightSignedShiftExpression, forRightSignedShiftExpressionOnly, forRightUnsignedShiftAssignmentExpression, forRightUnsignedShiftAssignmentExpressionOnly, forRightUnsignedShiftExpression, forRightUnsignedShiftExpressionOnly, forShiftAssignmentExpressionOnly, forShiftBinaryExpressionOnly, forSimpleAnonymousClassInstantiation, forSimpleAnonymousClassInstantiationOnly, forSimpleAssignmentExpression, forSimpleAssignmentExpressionOnly, forSimpleInitializedArrayInstantiation, forSimpleInitializedArrayInstantiationOnly, forSimpleMethodInvocation, forSimpleMethodInvocationOnly, forSimpleNamedClassInstantiation, forSimpleNamedClassInstantiationOnly, forSimpleNameReference, forSimpleNameReferenceOnly, forSimpleSuperConstructorInvocation, forSimpleSuperConstructorInvocationOnly, forSimpleSuperReference, forSimpleThisConstructorInvocation, forSimpleThisConstructorInvocationOnly, forSimpleThisReference, forSimpleUninitializedArrayInstantiation, forSimpleUninitializedArrayInstantiationOnly, forSourceFile, forSourceFileOnly, forStatementOnly, forStringLiteral, forStringLiteralOnly, forSuperConstructorInvocationOnly, forSuperReferenceOnly, forSwitchCaseOnly, forSynchronizedStatementOnly, forThisConstructorInvocationOnly, forThisReferenceOnly, forTypeDefBaseOnly, forTypeParameter, forTypeParameterOnly, forTypeVariable, forTypeVariableOnly, forUnaryExpressionOnly, forUninitializedArrayInstantiationOnly, forUnlabeledBreakStatement, forUnlabeledBreakStatementOnly, forUnlabeledContinueStatement, forUnlabeledContinueStatementOnly, forUnparenthesizedExpressionList, forUnparenthesizedExpressionListOnly, forVariableDeclarationOnly, forVariableDeclaratorOnly, forVariableReferenceOnly, forVoidReturn, forVoidReturnOnly, forVoidReturnStatement, 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, forArrayInitializer, forArrayType, forBitwiseAndAssignmentExpression, forBitwiseAndExpression, forBitwiseNotExpression, forBitwiseOrAssignmentExpression, forBitwiseOrExpression, forBitwiseXorAssignmentExpression, forBitwiseXorExpression, forBooleanLiteral, forCharLiteral, forClassLiteral, forClassOrInterfaceType, forComplexAnonymousClassInstantiation, forComplexInitializedArrayInstantiation, forComplexMethodInvocation, forComplexNamedClassInstantiation, forComplexNameReference, forComplexSuperConstructorInvocation, forComplexSuperReference, forComplexThisConstructorInvocation, forComplexThisReference, forComplexUninitializedArrayInstantiation, forCompoundWord, forConcreteMethodDef, forConditionalExpression, forConstructorDef, forDimensionExpressionList, forDivideAssignmentExpression, forDivideExpression, forDoubleLiteral, forEmptyExpression, forEmptyForCondition, forEmptyStatement, forEqualsExpression, forFloatLiteral, forGreaterThanExpression, forGreaterThanOrEqualExpression, forInstanceofExpression, forIntegerLiteral, forLabeledBreakStatement, forLabeledContinueStatement, forLeftShiftAssignmentExpression, forLeftShiftExpression, forLessThanExpression, forLessThanOrEqualExpression, forLongLiteral, forMemberType, forMinusAssignmentExpression, forMinusExpression, forModAssignmentExpression, forModExpression, forModifiersAndVisibility, forMultiplyAssignmentExpression, forMultiplyExpression, forNegativeExpression, forNegativePostfixIncrementExpression, forNegativePrefixIncrementExpression, forNoOpExpression, forNotEqualExpression, forNotExpression, forNullLiteral, forOrExpression, forPackageImportStatement, forParenthesized, forParenthesizedExpressionList, forPlusAssignmentExpression, forPlusExpression, forPositiveExpression, forPositivePostfixIncrementExpression, forPositivePrefixIncrementExpression, forRightSignedShiftAssignmentExpression, forRightSignedShiftExpression, forRightUnsignedShiftAssignmentExpression, forRightUnsignedShiftExpression, forSimpleAnonymousClassInstantiation, forSimpleAssignmentExpression, forSimpleInitializedArrayInstantiation, forSimpleMethodInvocation, forSimpleNamedClassInstantiation, forSimpleNameReference, forSimpleSuperConstructorInvocation, forSimpleSuperReference, forSimpleThisConstructorInvocation, forSimpleThisReference, forSimpleUninitializedArrayInstantiation, forSourceFile, forStringLiteral, forTypeParameter, forTypeVariable, forUnlabeledBreakStatement, forUnlabeledContinueStatement, forUnparenthesizedExpressionList, forVoidReturn, forVoidReturnStatement, forWord
 

Field Detail

_bodyData

protected BodyData _bodyData
The MethodData of this method.

Constructor Detail

BodyTypeChecker

public BodyTypeChecker(BodyData bodyData,
                       File file,
                       String packageName,
                       LinkedList<String> importedFiles,
                       LinkedList<String> importedPackages,
                       LinkedList<VariableData> vars,
                       LinkedList<Pair<SymbolData,JExpression>> thrown)
Constructor for BodyTypeChecker. Calls the super constructor for everything except bodyData, which we store here in order to have the proper type at compile time. (SpecialTypeChecker stores it as a Data).

Parameters:
bodyData - The enclosing BodyData for the context we are type checking.
file - The File corresponding to the source file.
packageName - The package name from the source file.
importedFiles - The names of the files that are specifically imported (through a class import statement) in the source file.
importedPackages - The names of all the packages that are imported through a package import statement in the source file.
vars - The list of VariableData that have already been defined (used so we can make sure we don't use a variable before it has been defined).
thrown - The list of exceptions thrown in this body
Method Detail

_getData

protected Data _getData()
Description copied from class: TypeChecker
The top level type checker does not have a data

Overrides:
_getData in class SpecialTypeChecker
Returns:
the bodyData (enclosing data) for this context.

forSimpleThisReferenceOnly

public TypeData forSimpleThisReferenceOnly(SimpleThisReference that)
Overrides:
forSimpleThisReferenceOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
the instance data of the class/interface enclosing this body data.

forSimpleSuperReferenceOnly

public TypeData forSimpleSuperReferenceOnly(SimpleSuperReference that)
Overrides:
forSimpleSuperReferenceOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
the instance data of the super class of the class enclosing this body data.

createANewInstanceOfMe

protected BodyTypeChecker createANewInstanceOfMe(BodyData bodyData,
                                                 File file,
                                                 String pakage,
                                                 LinkedList<String> importedFiles,
                                                 LinkedList<String> importedPackages,
                                                 LinkedList<VariableData> vars,
                                                 LinkedList<Pair<SymbolData,JExpression>> thrown)
Create a new instance of this class for visiting inner bodies.


forInstanceInitializer

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

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

forUninitializedVariableDeclaratorOnly

public TypeData forUninitializedVariableDeclaratorOnly(UninitializedVariableDeclarator that,
                                                       TypeData typeRes,
                                                       TypeData nameRes)
We need to do this so that expressions (which should only occur in variable initializers and initializer blocks) can know which fields have already been declared. Add all the variable datas that are declared in this declarator to the list of variables that are visibile from where we are.

Overrides:
forUninitializedVariableDeclaratorOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forBodyOnly

public TypeData forBodyOnly(Body that,
                            TypeData[] items_result)
Look at the result of each item in the body. If one is not null and does not correspond to an Expression Statement, then that means that that statement returns a value. Check to make sure that there are no statements following it. If there are, then those statements are unreachable so give an error.

Overrides:
forBodyOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Parameters:
that - The Body we were type checking
items_result - Array of results for each item in the body that was visited.

forBracedBodyOnly

public TypeData forBracedBodyOnly(BracedBody that,
                                  TypeData[] items_result)
Delegates to forBodyOnly.

Overrides:
forBracedBodyOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forUnbracedBodyOnly

public TypeData forUnbracedBodyOnly(UnbracedBody that,
                                    TypeData[] items_result)
Delegates to forBodyOnly.

Overrides:
forUnbracedBodyOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forVoidReturnStatementOnly

public TypeData forVoidReturnStatementOnly(VoidReturnStatement that)
Make sure the enclosing method data is declared to return void. If it is not, give an error.

Overrides:
forVoidReturnStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>
Returns:
the type the method is declared to return.

forValueReturnStatement

public TypeData forValueReturnStatement(ValueReturnStatement that)
Visit the value being returned to determine its type. Do the necessary bookkeeping and then delegate to forValueReturnStatementOnly.

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

forValueReturnStatementOnly

public TypeData forValueReturnStatementOnly(ValueReturnStatement that,
                                            TypeData valueRes)
Make sure that the enclosing method is declared to throw the same type as the return statement is trying to return. Also make sure that what is being returned is an instance of the type, not the type itself.

Overrides:
forValueReturnStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forForStatement

public TypeData forForStatement(ForStatement that)
First, visit the condition expression of the for statement with a special visitor that makes sure no assignment is done. Then, visit the condition expression with the ExpressionTypeChecker which will do all the normal expression stuff. Then, visit the update and and code (block) of the for statement with this visitor. Be very careful about maintaing the various scopes here.

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

forForStatementOnly

public TypeData forForStatementOnly(ForStatement that,
                                    TypeData init_result,
                                    TypeData condition_result,
                                    TypeData update_result,
                                    TypeData codeRes)
Overrides:
forForStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forIfThenStatement

public TypeData forIfThenStatement(IfThenStatement that)
First, visit the condition expression of the if statement with a special visitor that makes sure no assignment is done. Then, visit the condition expression with the ExpressionTypeChecker which will do all the normal expression stuff. Then, visit the body of the if statement with this visitor. Be very careful about maintaing the various scopes here.

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

forIfThenStatementOnly

public TypeData forIfThenStatementOnly(IfThenStatement that,
                                       TypeData testExpression_result,
                                       TypeData thenStatement_result)
Overrides:
forIfThenStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forIfThenElseStatement

public TypeData forIfThenElseStatement(IfThenElseStatement that)
First, visit the condition expression of the if-then-else statement with a special visitor that makes sure no assignment is done. Then, visit the condition expression with the ExpressionTypeChecker which will do all the normal expression stuff. Then, visit the body of the if statement and the else with this visitor. Be very careful about maintaing the various scopes here.

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

forIfThenElseStatementOnly

public TypeData forIfThenElseStatementOnly(IfThenElseStatement that,
                                           TypeData testExpression_result,
                                           TypeData thenStatement_result,
                                           TypeData elseStatement_result)
Make sure that the conditional expression has the right type, and if both branches of the if/else return, return a value the common super type of the two return types. We assume that thenStatement_result and elseStatement_result are InstanceDatas

Overrides:
forIfThenElseStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forWhileStatement

public TypeData forWhileStatement(WhileStatement that)
First, visit the condition expression of the while statement with a special visitor that makes sure no assignment is done. Then, visit the condition expression with the ExpressionTypeChecker which will do all the normal expression stuff. Then, visit the body with this visitor. Be very careful about maintaing the various scopes here.

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

forWhileStatementOnly

public TypeData forWhileStatementOnly(WhileStatement that,
                                      TypeData condition_result,
                                      TypeData codeRes)
Make sure that the condition statement of the while returns type boolean.

Overrides:
forWhileStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forDoStatement

public TypeData forDoStatement(DoStatement that)
First, visit the body of the do statement with a body type checker. Then, visit the condition expression of the do statement with a special visitor that makes sure no assignment is done. Then, visit the condition expression with the ExpressionTypeChecker which will do all the normal expression stuff. Be very careful about maintaing the various scopes here.

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

forDoStatementOnly

public TypeData forDoStatementOnly(DoStatement that,
                                   TypeData codeRes,
                                   TypeData condition_result)
Make sure that the condition statement of the while returns type boolean.

Overrides:
forDoStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forSwitchStatement

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

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

forSwitchStatementOnly

public TypeData forSwitchStatementOnly(SwitchStatement that,
                                       TypeData testRes,
                                       TypeData[] cases_result,
                                       boolean sawDefault)
Here, we follow the following rules for determining what to return: If there is not a default block, the statement does not return. If the result from any of the blocks is NOT_FOUND, the statement does not return. (NOT_FOUND signifies that a break statement was seen). If the last block does not return, then the statement does not return.


forLabeledCase

public TypeData forLabeledCase(LabeledCase that)
Make sure that the label for this LabeledCase is correct. The label must be a constant expression of type int or char. Then delegate to the super class to handle the braced body of the switch case.

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

forDefaultCase

public TypeData forDefaultCase(DefaultCase that)
Delegate handling this default case to its superclass.

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

forSwitchCase

public TypeData forSwitchCase(SwitchCase that)
Visit the Braced Body of this SwitchCase, and return the result.


forBlock

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

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

forTypeOnly

public TypeData forTypeOnly(Type that)
Overrides:
forTypeOnly in class JExpressionIFDepthFirstVisitor<TypeData>

checkDuplicateExceptions

protected void checkDuplicateExceptions(TryCatchStatement that)
Makes sure that no super class of any exception is caught before the current exception's catch block.


getCommonSuperType

protected SymbolData getCommonSuperType(SymbolData s1,
                                        SymbolData s2)
Check if the two given SymbolDatas have a common super type. If so, return it, else return null.


isException

protected boolean isException(SymbolData sd)
Returns:
true if the symbol data is the generic SymbolData.EXCEPTIOn class or if it extends java.lang.Throwable

tryCatchLeastRestrictiveType

protected InstanceData tryCatchLeastRestrictiveType(InstanceData tryBlockRes,
                                                    InstanceData[] catchBlocksRes,
                                                    InstanceData finallyBlock_result)
Returns the least restrictive type returned by the try block and catch blocks. Returns null if this try-catch statement doesn't necessarily return a value.


isUncaughtCheckedException

public boolean isUncaughtCheckedException(SymbolData sd,
                                          JExpression that)
Return true if the Exception is unchecked, and false otherwise. An exception is unchecked 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.

makeSureCaughtStuffWasThrown

protected void makeSureCaughtStuffWasThrown(TryCatchStatement that,
                                            SymbolData[] caught_array,
                                            LinkedList<Pair<SymbolData,JExpression>> thrown)
Make sure that every exception that is caught could have been thrown in the try statement


compareThrownAndCaught

protected void compareThrownAndCaught(TryCatchStatement that,
                                      SymbolData[] caught_array,
                                      LinkedList<Pair<SymbolData,JExpression>> thrown)
Make sure that every Exception in thrown is either in caught or in the list of what can be thrown from where we are. Also make sure that every Exception that is declared to be thrown or caught is actually thrown.

Parameters:
that - The TryCatchStatement we are currently working with
caught_array - The SymbolData[] of exceptions that are explicitely caught.
thrown - The LinkedList of SymbolData of exceptions that are thrown. This will be modified.

forTryCatchFinallyStatementOnly

public TypeData forTryCatchFinallyStatementOnly(TryCatchFinallyStatement that,
                                                TypeData tryBlockRes,
                                                TypeData[] catchBlocksRes,
                                                TypeData finallyBlock_result)
Assumes that tryBlockRes, catchBlocksRes, and finallyBlock_result are InstanceDatas.

Overrides:
forTryCatchFinallyStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forTryCatchFinallyStatement

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

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

forCatchBlock

public TypeData forCatchBlock(CatchBlock that)
Resolves the type of the exception, and visits the body, making sure the exception variable is in scope.

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

forCatchBlockOnly

public TypeData forCatchBlockOnly(CatchBlock that,
                                  SymbolData exception_result,
                                  TypeData block_result)

forNormalTryCatchStatementOnly

public TypeData forNormalTryCatchStatementOnly(NormalTryCatchStatement that,
                                               TypeData tryBlockRes,
                                               TypeData[] catchBlocksRes)
Assumes that tryBlockRes, catchBlocksRes, and finallyBlock_result are InstanceDatas

Overrides:
forNormalTryCatchStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>

forNormalTryCatchStatement

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

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