001 002 aspect NameResolution { 003 004 eq MethodUse.decl() = lookupMethod(getName(), getArgList()); 005 006 inh Decl MethodUse.lookupMethod(String name, List argList); 007 inh Decl Block.lookupMethod(String name, List argList); 008 inh Decl ClassDecl.lookupMethod(String name, List argList); 009 010 eq Block.getBlockStmt(int index).lookupMethod(String name, List argList) { 011 if (!localLookupMethod(name, argList).isUnknown()) 012 return localLookupMethod(name, argList); 013 return lookupMethod(name, argList); 014 } 015 016 eq ClassDecl.getChild().lookupMethod(String name, List argList) { 017 ClassDecl superClass = superClass(); 018 if (superClass != null) { 019 Decl remoteDecl = ((TypeDecl)superClass).remoteLookupMethod(name, argList); 020 if (remoteDecl != null && !remoteDecl.isUnknown()) { 021 return remoteDecl; 022 } 023 } 024 return lookupMethod(name, argList); 025 } 026 eq Program.getChild().lookupMethod(String name, List argList) = unknownDecl(); 027 eq MethodUse.getArg(int index).lookupMethod(String name, List argList) = lookupMethod(name, argList); 028 eq Dot.getIdUse().lookupMethod(String name, List argList) = 029 // Do a remote lookup on the object's type. 030 getObjectReference().decl().type().remoteLookupMethod(name, argList); 031 032 033 034 syn lazy Decl Block.localLookupMethod(String name, List argList) { 035 for (int k = 0; k < getNumBlockStmt(); k++) { 036 Decl d = getBlockStmt(k).declarationOf(name, argList); 037 if (d != null) return d; 038 } 039 return unknownDecl(); 040 } 041 042 043 syn Decl TypeDecl.remoteLookupMethod(String name, List argList) = unknownDecl(); 044 eq ClassDecl.remoteLookupMethod(String name, List argList) { 045 // First, look in local declarations 046 if (!getBody().localLookupMethod(name, argList).isUnknown()) 047 return getBody().localLookupMethod(name, argList); 048 // Then, look in the superclass chain 049 if (superClass() != null && 050 superClass().remoteLookupMethod(name, argList) != null && 051 !superClass().remoteLookupMethod(name, argList).isUnknown()) 052 return superClass().remoteLookupMethod(name, argList); 053 return unknownDecl(); 054 } 055 056 057 syn lazy Decl BlockStmt.declarationOf(String name, List argList) = null; 058 eq MethodDecl.declarationOf(String name, List argList) { 059 if (!getName().equals(name) || 060 getNumParamDecl() != argList.getNumChild()) { 061 return null; 062 } 063 for (int i = 0; i < getNumParamDecl(); i++) { 064 if (getParamDecl(i).type() != ((Exp)argList.getChild(i)).type()) { 065 return null; 066 } 067 } 068 return this; 069 } 070 071 }