|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.javalanglevels.tree.JExpressionIFDepthFirstVisitor<TypeData>
edu.rice.cs.javalanglevels.TypeChecker
edu.rice.cs.javalanglevels.SpecialTypeChecker
edu.rice.cs.javalanglevels.BodyTypeChecker
public class BodyTypeChecker
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,
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)
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,
java.util.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,
java.io.File file,
java.lang.String pakage,
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)
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,
java.util.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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected BodyData _bodyData
| Constructor Detail |
|---|
public BodyTypeChecker(BodyData bodyData,
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)
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 |
|---|
protected Data _getData()
TypeChecker
_getData in class SpecialTypeCheckerpublic TypeData forSimpleThisReferenceOnly(SimpleThisReference that)
forSimpleThisReferenceOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forSimpleSuperReferenceOnly(SimpleSuperReference that)
forSimpleSuperReferenceOnly in class JExpressionIFDepthFirstVisitor<TypeData>
protected BodyTypeChecker createANewInstanceOfMe(BodyData bodyData,
java.io.File file,
java.lang.String pakage,
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)
public TypeData forInstanceInitializer(InstanceInitializer that)
JExpressionIFVisitor
forInstanceInitializer in interface JExpressionIFVisitor<TypeData>forInstanceInitializer in class SpecialTypeChecker
public TypeData forUninitializedVariableDeclaratorOnly(UninitializedVariableDeclarator that,
TypeData typeRes,
TypeData nameRes)
forUninitializedVariableDeclaratorOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forBodyOnly(Body that,
TypeData[] items_result)
forBodyOnly in class JExpressionIFDepthFirstVisitor<TypeData>that - The Body we were type checkingitems_result - Array of results for each item in the body that was visited.
public TypeData forBracedBodyOnly(BracedBody that,
TypeData[] items_result)
forBracedBodyOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forUnbracedBodyOnly(UnbracedBody that,
TypeData[] items_result)
forUnbracedBodyOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forVoidReturnStatementOnly(VoidReturnStatement that)
forVoidReturnStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forValueReturnStatement(ValueReturnStatement that)
forValueReturnStatement in interface JExpressionIFVisitor<TypeData>forValueReturnStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forValueReturnStatementOnly(ValueReturnStatement that,
TypeData valueRes)
forValueReturnStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forForStatement(ForStatement that)
forForStatement in interface JExpressionIFVisitor<TypeData>forForStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forForStatementOnly(ForStatement that,
TypeData init_result,
TypeData condition_result,
TypeData update_result,
TypeData codeRes)
forForStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forIfThenStatement(IfThenStatement that)
forIfThenStatement in interface JExpressionIFVisitor<TypeData>forIfThenStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forIfThenStatementOnly(IfThenStatement that,
TypeData testExpression_result,
TypeData thenStatement_result)
forIfThenStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forIfThenElseStatement(IfThenElseStatement that)
forIfThenElseStatement in interface JExpressionIFVisitor<TypeData>forIfThenElseStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forIfThenElseStatementOnly(IfThenElseStatement that,
TypeData testExpression_result,
TypeData thenStatement_result,
TypeData elseStatement_result)
forIfThenElseStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forWhileStatement(WhileStatement that)
forWhileStatement in interface JExpressionIFVisitor<TypeData>forWhileStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forWhileStatementOnly(WhileStatement that,
TypeData condition_result,
TypeData codeRes)
forWhileStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forDoStatement(DoStatement that)
forDoStatement in interface JExpressionIFVisitor<TypeData>forDoStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forDoStatementOnly(DoStatement that,
TypeData codeRes,
TypeData condition_result)
forDoStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forSwitchStatement(SwitchStatement that)
JExpressionIFVisitor
forSwitchStatement in interface JExpressionIFVisitor<TypeData>forSwitchStatement in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forSwitchStatementOnly(SwitchStatement that,
TypeData testRes,
TypeData[] cases_result,
boolean sawDefault)
public TypeData forLabeledCase(LabeledCase that)
forLabeledCase in interface JExpressionIFVisitor<TypeData>forLabeledCase in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forDefaultCase(DefaultCase that)
forDefaultCase in interface JExpressionIFVisitor<TypeData>forDefaultCase in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forSwitchCase(SwitchCase that)
public TypeData forBlock(Block that)
JExpressionIFVisitor
forBlock in interface JExpressionIFVisitor<TypeData>forBlock in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forTypeOnly(Type that)
forTypeOnly in class JExpressionIFDepthFirstVisitor<TypeData>protected void checkDuplicateExceptions(TryCatchStatement that)
protected SymbolData getCommonSuperType(SymbolData s1,
SymbolData s2)
protected boolean isException(SymbolData sd)
protected InstanceData tryCatchLeastRestrictiveType(InstanceData tryBlockRes,
InstanceData[] catchBlocksRes,
InstanceData finallyBlock_result)
public boolean isUncaughtCheckedException(SymbolData sd,
JExpression that)
isUncaughtCheckedException in class SpecialTypeCheckersd - The SymbolData of the Exception we are checking.that - The JExpression passed to getSymbolData for error purposes.
protected void makeSureCaughtStuffWasThrown(TryCatchStatement that,
SymbolData[] caught_array,
java.util.LinkedList<Pair<SymbolData,JExpression>> thrown)
protected void compareThrownAndCaught(TryCatchStatement that,
SymbolData[] caught_array,
java.util.LinkedList<Pair<SymbolData,JExpression>> thrown)
that - The TryCatchStatement we are currently working withcaught_array - The SymbolData[] of exceptions that are explicitely caught.thrown - The LinkedList of SymbolData of exceptions that are thrown. This will be modified.
public TypeData forTryCatchFinallyStatementOnly(TryCatchFinallyStatement that,
TypeData tryBlockRes,
TypeData[] catchBlocksRes,
TypeData finallyBlock_result)
forTryCatchFinallyStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forTryCatchFinallyStatement(TryCatchFinallyStatement that)
JExpressionIFVisitor
forTryCatchFinallyStatement in interface JExpressionIFVisitor<TypeData>forTryCatchFinallyStatement in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forCatchBlock(CatchBlock that)
forCatchBlock in interface JExpressionIFVisitor<TypeData>forCatchBlock in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forCatchBlockOnly(CatchBlock that,
SymbolData exception_result,
TypeData block_result)
public TypeData forNormalTryCatchStatementOnly(NormalTryCatchStatement that,
TypeData tryBlockRes,
TypeData[] catchBlocksRes)
forNormalTryCatchStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forNormalTryCatchStatement(NormalTryCatchStatement that)
JExpressionIFVisitor
forNormalTryCatchStatement in interface JExpressionIFVisitor<TypeData>forNormalTryCatchStatement in class JExpressionIFDepthFirstVisitor<TypeData>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||