|
||||||||||
| 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
public class TypeChecker
Does Type Checking that is not dependent on the enclosing body. Also does top level type checking. Common to all langauge levels.
| Nested Class Summary | |
|---|---|
static class |
TypeChecker.TypeCheckerTest
Test the methods defined in the above class. |
| Field Summary | |
|---|---|
static ModifiersAndVisibility |
_abstractMav
|
static ModifiersAndVisibility |
_finalMav
|
static ModifiersAndVisibility |
_finalPublicMav
|
protected static Log |
_log
|
static ModifiersAndVisibility |
_packageMav
|
static ModifiersAndVisibility |
_privateMav
|
static ModifiersAndVisibility |
_protectedMav
|
static ModifiersAndVisibility |
_publicAbstractMav
|
static ModifiersAndVisibility |
_publicMav
|
static ModifiersAndVisibility |
_publicStaticMav
|
static SourceInfo |
NONE
|
static NullLiteral |
NULL_LITERAL
|
| Constructor Summary | |
|---|---|
TypeChecker(java.io.File file,
java.lang.String packageName,
java.util.LinkedList<Pair<java.lang.String,JExpressionIF>> errors,
Symboltable symbolTable,
java.util.LinkedList<java.lang.String> importedFiles,
java.util.LinkedList<java.lang.String> importedPackages)
The normal constructor. |
|
TypeChecker(java.io.File file,
java.lang.String packageName,
java.util.LinkedList<java.lang.String> importedFiles,
java.util.LinkedList<java.lang.String> importedPackages)
Called by the subclasses. |
|
| Method Summary | |
|---|---|
protected static void |
_addError(java.lang.String message,
JExpressionIF that)
Adds an error pair consisting of the specified String message and JExpression. |
protected void |
_checkAbstractMethods(SymbolData sd,
JExpression classDef)
The method will add an error for each abstract method in the current SymbolData's inheritance hierarchy that does not have a concrete implementation. |
protected Data |
_getData()
The top level type checker does not have a data |
protected Pair<java.util.LinkedList<MethodData>,java.util.LinkedList<MethodData>> |
_getMatchingMethods(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
boolean isConstructor,
SymbolData thisSD)
Finds and returns all matching methods. |
protected static boolean |
_isAssignableFrom(SymbolData sdLeft,
SymbolData sdRight)
Return whether the value on the right can be assigned to the value on the left. |
protected boolean |
_isAssignableFromWithoutAutoboxing(SymbolData sdLeft,
SymbolData sdRight)
Return whether the value on the right can be assigned to the value on the left. |
protected MethodData |
_lookupMethod(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
java.lang.String errorMsg,
boolean isConstructor,
SymbolData thisSD)
Finds which SymbolData this method is in, beginning at this SymbolData and recursively visiting super classes. |
protected MethodData |
_lookupMethodHelper(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
boolean isConstructor,
SymbolData thisSD)
Pass a default value |
protected MethodData |
_lookupMethodHelper(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
boolean isConstructor,
SymbolData thisSD,
java.util.LinkedList<MethodData> matchingMethods)
Finds which SymbolData this method is in, beginning at this SymbolData and recursively visiting super classes. |
boolean |
assertFound(TypeData type,
JExpressionIF expression)
If type is a PackageData, then it could not be resolved. |
boolean |
assertInstanceType(TypeData type,
java.lang.String errorMsg,
JExpression expression)
Return true iff type is an instance type. |
static boolean |
checkAccess(JExpression piece,
ModifiersAndVisibility mav,
java.lang.String name,
SymbolData enclosingSD,
SymbolData thisSD,
java.lang.String dataType)
Checks that the method is accessible given the SymbolData it's in and the current SymbolData. |
static boolean |
checkAccess(JExpression piece,
ModifiersAndVisibility mav,
java.lang.String name,
SymbolData enclosingSD,
SymbolData thisSD,
java.lang.String dataType,
boolean addError)
Determines if thisSD can reference specified name defined in enclosingSD. |
static boolean |
checkAccess(ModifiersAndVisibility mav,
SymbolData enclosingSD,
SymbolData thisSD)
Call this version when you don't want to add an error--only take in what is necessary to do the check, give default values for anything that will not be used. |
protected boolean |
checkForCyclicInheritance(SymbolData sd,
java.util.LinkedList<SymbolData> hierarchy,
TypeDefBase tdb)
Checks for cyclic inheritance by traversing sd's list of superclasses and interfaces and checking if we've seen them before. |
java.util.LinkedList<VariableData> |
cloneVariableDataList(java.util.LinkedList<VariableData> vars)
Create a clone of the linked list of Variable Data. |
protected TypeData |
defaultCase(JExpressionIF that)
This method is called by default from cases that do not override forCASEOnly. |
protected static SymbolData |
defineTestCaseClass()
Adds an appropriate definition of junit.framework.TestCase to symbolTable. |
TypeData |
forBlockOnly(Block that,
TypeData[] statementsRes)
|
TypeData |
forBreakStatementOnly(BreakStatement that)
|
TypeData |
forCastExpression(CastExpression that)
Visit the type of the cast expression as well as the value being cast |
TypeData |
forClassDef(ClassDef that)
Do what is necessary to handle a class def |
TypeData |
forClassDefOnly(ClassDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParametersRes,
TypeData superRes,
TypeData[] interfacesRes,
TypeData bodyRes)
|
TypeData |
forClassImportStatement(ClassImportStatement that)
Retrieve the class being imported from the Symbol table, and make sure it is public. |
TypeData |
forConcreteMethodDefOnly(ConcreteMethodDef that,
TypeData mavRes,
TypeData[] typeParamsRes,
TypeData resRes,
TypeData nameRes,
TypeData paramsRes,
TypeData[] throwsRes,
TypeData bodyRes)
|
TypeData |
forContinueStatementOnly(ContinueStatement that)
|
TypeData |
forExpressionStatementOnly(ExpressionStatement that,
TypeData exprRes)
|
TypeData |
forInnerClassDefOnly(InnerClassDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParamRes,
TypeData superClassRes,
TypeData[] interfacesRes,
TypeData bodyRes)
|
TypeData |
forInnerInterfaceDefOnly(InnerInterfaceDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParamRes,
TypeData[] superinterfacesRes,
TypeData bodyRes)
|
TypeData |
forInstanceInitializerOnly(InstanceInitializer that,
TypeData codeRes)
|
TypeData |
forInterfaceDef(InterfaceDef that)
Do everything necessary to handle an interface |
TypeData |
forInterfaceDefOnly(InterfaceDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParamRes,
TypeData[] superinterfacesRes,
TypeData bodyRes)
|
TypeData |
forLabeledStatementOnly(LabeledStatement that,
TypeData statementRes)
|
TypeData |
forMethodDefOnly(MethodDef that,
TypeData mavRes,
TypeData[] typeParamsRes,
TypeData resRes,
TypeData nameRes,
TypeData paramsRes,
TypeData[] throwsRes)
|
TypeData |
forPackageStatement(PackageStatement that)
Make sure that the package being imported does not conflict with another class in the symbol table, since we will not allow a package to be imported if it has the same name as a class. |
TypeData |
forPrimitiveType(PrimitiveType that)
Process an instance of PrimitiveType. |
TypeData |
forReturnStatementOnly(ReturnStatement that)
|
TypeData |
forStaticInitializerOnly(StaticInitializer that,
TypeData codeRes)
|
TypeData |
forSwitchStatementOnly(SwitchStatement that,
TypeData testRes,
TypeData[] casesRes)
|
TypeData |
forTryCatchStatementOnly(TryCatchStatement that,
TypeData tryBlockRes,
TypeData[] catchBlocksRes)
|
protected SymbolData |
getCommonSuperTypeBaseCase(SymbolData sdLeft,
SymbolData sdRight)
Returns the common super type of the two types provided. |
static VariableData |
getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece)
Return the field or variable with the name text inside of data. |
static VariableData |
getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece,
java.util.LinkedList<VariableData> vars)
|
static VariableData |
getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece,
java.util.LinkedList<VariableData> vars,
boolean shouldRecur)
|
static VariableData |
getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece,
java.util.LinkedList<VariableData> vars,
boolean shouldRecur,
boolean addError)
This method checks if the identifier called text is a field or variable visible from the context of the param "data" and is accessible from the context of thisSD. |
protected java.lang.String |
getQualifiedClassName(java.lang.String className)
The Qualified Class Name is the package, followed by a dot, followed by the rest of the class name. |
SymbolData |
getSymbolData(boolean giveAmbigException,
java.lang.String className,
Data enclosingData,
JExpression jexpr,
boolean giveException)
Returns the SymbolData corresponding to the name className. |
SymbolData |
getSymbolData(java.lang.String className,
Data enclosingData,
JExpression jexpr)
Returns the SymbolData corresponding to the name className. |
SymbolData |
getSymbolData(java.lang.String className,
Data enclosingData,
JExpression jexpr,
boolean giveException)
Call the next version of GetSymbolData, but pass it giveException as the flag for whether or not to give ambigException. |
SymbolData |
getSymbolData(java.lang.String className,
JExpression jexpr,
boolean giveException,
boolean runnableNotOkay)
Returns the SymbolData corresponding to the name className, assuming that className does not refer to an unqualified or partially-qualified inner class. |
protected TypeData[] |
makeArrayOfRetType(int len)
Return a TypeData array of the specified size. |
protected boolean |
notRightPackage(SymbolData sd)
Return false if the symbolData is in the wrong package. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final SourceInfo NONE
public static final NullLiteral NULL_LITERAL
public static final ModifiersAndVisibility _packageMav
public static final ModifiersAndVisibility _publicMav
public static final ModifiersAndVisibility _protectedMav
public static final ModifiersAndVisibility _privateMav
public static final ModifiersAndVisibility _abstractMav
public static final ModifiersAndVisibility _finalMav
public static final ModifiersAndVisibility _finalPublicMav
public static final ModifiersAndVisibility _publicAbstractMav
public static final ModifiersAndVisibility _publicStaticMav
protected static final Log _log
| Constructor Detail |
|---|
public TypeChecker(java.io.File file,
java.lang.String packageName,
java.util.LinkedList<Pair<java.lang.String,JExpressionIF>> errors,
Symboltable symbolTable,
java.util.LinkedList<java.lang.String> importedFiles,
java.util.LinkedList<java.lang.String> importedPackages)
file - The source file being type checkedpackageName - The name of the package of the source fileerrors - The list of errors that are encountered during type checkingimportedFiles - The specific classes imported in the source fileimportedPackages - The list of package names that are imported
public TypeChecker(java.io.File file,
java.lang.String packageName,
java.util.LinkedList<java.lang.String> importedFiles,
java.util.LinkedList<java.lang.String> importedPackages)
file - The Source File being checkedpackageName - The package the source file is inimportedFiles - The specific classes imported in the source fileimportedPackages - The list of package names that are imported| Method Detail |
|---|
protected Data _getData()
protected static SymbolData defineTestCaseClass()
public SymbolData getSymbolData(java.lang.String className,
Data enclosingData,
JExpression jexpr)
className - The class name to look up which may or may not be fully qualified.enclosingData - The enclosing data -- either a MethodData or a ClassData for this referencejexpr - The AST of the phrase containing the reference.
public SymbolData getSymbolData(java.lang.String className,
Data enclosingData,
JExpression jexpr,
boolean giveException)
public SymbolData getSymbolData(boolean giveAmbigException,
java.lang.String className,
Data enclosingData,
JExpression jexpr,
boolean giveException)
public SymbolData getSymbolData(java.lang.String className,
JExpression jexpr,
boolean giveException,
boolean runnableNotOkay)
protected boolean notRightPackage(SymbolData sd)
sd - The SymbolData to check.public java.util.LinkedList<VariableData> cloneVariableDataList(java.util.LinkedList<VariableData> vars)
protected java.lang.String getQualifiedClassName(java.lang.String className)
className - The className to qualify.
protected MethodData _lookupMethodHelper(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
boolean isConstructor,
SymbolData thisSD)
protected Pair<java.util.LinkedList<MethodData>,java.util.LinkedList<MethodData>> _getMatchingMethods(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
boolean isConstructor,
SymbolData thisSD)
methodName - The name of the method.enclosingSD - The SymbolData we're currently searching for the method.arguments - The types of the arguments to the method.jexpr - The JExpression for the method invocation used in the error message.isConstructor - True if this method is a constructor. If so, we know it must be in the initial SymbolData.thisSD - The SymbolData whence the method is invoked.
protected MethodData _lookupMethodHelper(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
boolean isConstructor,
SymbolData thisSD,
java.util.LinkedList<MethodData> matchingMethods)
methodName - The name of the method.enclosingSD - The SymbolData we're currently searching for the method.arguments - The types of the arguments to the method.jexpr - The JExpression for the method invocation used in the error message.isConstructor - Tells us if this method is a constructor. If so, we know it must be in the initial SymbolData.
We assume that the correct SymbolData was passed in.thisSD - The SymbolData whence the method is invoked.
protected MethodData _lookupMethod(java.lang.String methodName,
SymbolData enclosingSD,
InstanceData[] arguments,
JExpression jexpr,
java.lang.String errorMsg,
boolean isConstructor,
SymbolData thisSD)
methodName - The name of the method.enclosingSD - The SymbolData we're currently searching for the method.arguments - The instance types of the arguments to the method.jexpr - The JExpression for the method invocation used in the error message.errorMsg - The error to be displayed if the method cannot be found.isConstructor - True if this method is a constructor. If so, we know it must be in the initial SymbolData.
We assume that the correct SymbolData was passed in.thisSD - The SymbolData of the initial SymbolData.
public static boolean checkAccess(JExpression piece,
ModifiersAndVisibility mav,
java.lang.String name,
SymbolData enclosingSD,
SymbolData thisSD,
java.lang.String dataType)
mav - The modifiers and visibility of the thing we're checkingname - The name of the thing we're checkingenclosingSD - The SymbolData which encloses namethisSD - The SymbolData that is being type checked (from which we're referencing name)dataType - The String that tells us whether name is a field, method, or class.
public static boolean checkAccess(ModifiersAndVisibility mav,
SymbolData enclosingSD,
SymbolData thisSD)
public static boolean checkAccess(JExpression piece,
ModifiersAndVisibility mav,
java.lang.String name,
SymbolData enclosingSD,
SymbolData thisSD,
java.lang.String dataType,
boolean addError)
mav - ??
public static VariableData getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece)
public static VariableData getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece,
java.util.LinkedList<VariableData> vars)
public static VariableData getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece,
java.util.LinkedList<VariableData> vars,
boolean shouldRecur)
public static VariableData getFieldOrVariable(java.lang.String text,
Data data,
SymbolData thisSD,
JExpression piece,
java.util.LinkedList<VariableData> vars,
boolean shouldRecur,
boolean addError)
public boolean assertInstanceType(TypeData type,
java.lang.String errorMsg,
JExpression expression)
public boolean assertFound(TypeData type,
JExpressionIF expression)
protected static void _addError(java.lang.String message,
JExpressionIF that)
message - Error messagethat - The JExpression corresponding to where the error is.protected TypeData[] makeArrayOfRetType(int len)
makeArrayOfRetType in class JExpressionIFDepthFirstVisitor<TypeData>protected TypeData defaultCase(JExpressionIF that)
defaultCase in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forClassDefOnly(ClassDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParametersRes,
TypeData superRes,
TypeData[] interfacesRes,
TypeData bodyRes)
forClassDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forInnerClassDefOnly(InnerClassDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParamRes,
TypeData superClassRes,
TypeData[] interfacesRes,
TypeData bodyRes)
forInnerClassDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forInterfaceDefOnly(InterfaceDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParamRes,
TypeData[] superinterfacesRes,
TypeData bodyRes)
forInterfaceDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forInnerInterfaceDefOnly(InnerInterfaceDef that,
TypeData mavRes,
TypeData nameRes,
TypeData[] typeParamRes,
TypeData[] superinterfacesRes,
TypeData bodyRes)
forInnerInterfaceDefOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forInstanceInitializerOnly(InstanceInitializer that,
TypeData codeRes)
forInstanceInitializerOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forStaticInitializerOnly(StaticInitializer that,
TypeData codeRes)
forStaticInitializerOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forLabeledStatementOnly(LabeledStatement that,
TypeData statementRes)
public TypeData forBlockOnly(Block that,
TypeData[] statementsRes)
public TypeData forExpressionStatementOnly(ExpressionStatement that,
TypeData exprRes)
forExpressionStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forSwitchStatementOnly(SwitchStatement that,
TypeData testRes,
TypeData[] casesRes)
forSwitchStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forBreakStatementOnly(BreakStatement that)
forBreakStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forContinueStatementOnly(ContinueStatement that)
forContinueStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forReturnStatementOnly(ReturnStatement that)
forReturnStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forTryCatchStatementOnly(TryCatchStatement that,
TypeData tryBlockRes,
TypeData[] catchBlocksRes)
forTryCatchStatementOnly in class JExpressionIFDepthFirstVisitor<TypeData>
public TypeData forMethodDefOnly(MethodDef that,
TypeData mavRes,
TypeData[] typeParamsRes,
TypeData resRes,
TypeData nameRes,
TypeData paramsRes,
TypeData[] throwsRes)
public TypeData forConcreteMethodDefOnly(ConcreteMethodDef that,
TypeData mavRes,
TypeData[] typeParamsRes,
TypeData resRes,
TypeData nameRes,
TypeData paramsRes,
TypeData[] throwsRes,
TypeData bodyRes)
protected SymbolData getCommonSuperTypeBaseCase(SymbolData sdLeft,
SymbolData sdRight)
protected static boolean _isAssignableFrom(SymbolData sdLeft,
SymbolData sdRight)
protected boolean _isAssignableFromWithoutAutoboxing(SymbolData sdLeft,
SymbolData sdRight)
protected void _checkAbstractMethods(SymbolData sd,
JExpression classDef)
sd - The SymbolData for the current class definitionclassDef - The current ClassDef
protected boolean checkForCyclicInheritance(SymbolData sd,
java.util.LinkedList<SymbolData> hierarchy,
TypeDefBase tdb)
sd - The SymbolData we're currently checkinghierarchy - The list of classes and interfaces we've seen before.
public TypeData forClassDef(ClassDef that)
forClassDef in interface JExpressionIFVisitor<TypeData>forClassDef in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forInterfaceDef(InterfaceDef that)
forInterfaceDef in interface JExpressionIFVisitor<TypeData>forInterfaceDef in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forClassImportStatement(ClassImportStatement that)
forClassImportStatement in interface JExpressionIFVisitor<TypeData>forClassImportStatement in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forPackageStatement(PackageStatement that)
forPackageStatement in interface JExpressionIFVisitor<TypeData>forPackageStatement in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forPrimitiveType(PrimitiveType that)
JExpressionIFVisitor
forPrimitiveType in interface JExpressionIFVisitor<TypeData>forPrimitiveType in class JExpressionIFDepthFirstVisitor<TypeData>public TypeData forCastExpression(CastExpression that)
forCastExpression in interface JExpressionIFVisitor<TypeData>forCastExpression in class JExpressionIFDepthFirstVisitor<TypeData>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||