[Nice-commit] Nice/src/bossa/syntax analyse.nice,1.88,1.89
Brought to you by:
bonniot
From: <bo...@us...> - 2003-11-25 10:43:05
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv629/src/bossa/syntax Modified Files: analyse.nice Log Message: Moved the handling of qualified method calls in a separate method to simplify the structure of the code. Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** analyse.nice 24 Nov 2003 20:49:42 -0000 1.88 --- analyse.nice 25 Nov 2003 10:02:31 -0000 1.89 *************** *** 314,367 **** if (e.declaringClass != null) ! { ! ?LocatedString funName = identString(e.function); ! if (funName == null) ! throw notNull(bossa.util.Internal.error ! (e.function, "This is not a valid class member")); ! ! int arity = args.size(); ! ! if ((! e.hasBrackets) && (arity == 0)) ! // This case is like java.lang.Byte.toString: ! // look for a method with that name and any arity, ! // since the method is not called but just referenced. ! { ! List<VarSymbol> possibilities = JavaClasses.findJavaMethods ! (e.declaringClass, funName.toString()); ! ! if (possibilities.size() == 0) ! throw error(e, "Class " + notNull(e.declaringClass).getName() + ! " has no static method or static field named " + ! funName); ! ! /* ! If there is a field access, then we consider this an access ! to the static field. Otherwise, it is a reference to ! the method, not applied. ! */ ! if (possibilities.has(VarSymbol s => s.isFieldAccess())) ! { ! e.function = newOverloadedSymbolExp(possibilities, funName); ! return e; ! } ! else ! return newOverloadedSymbolExp(possibilities, funName); ! } ! ! List<VarSymbol> possibilities = JavaClasses.findJavaMethods ! (e.declaringClass, funName.toString(), arity); ! ! if (possibilities.size() == 0) ! throw error(e, "Class " + notNull(e.declaringClass).getName() + ! (arity == 0 ? " has no static method or static field named " : ! arity == 1 ? " has no method or field named " : ! " has no method named ") + ! funName); ! ! e.function = newOverloadedSymbolExp(possibilities, funName); - return e; - } - ?PackageExp pkg = args.packageExp(); if (pkg != null) --- 314,319 ---- if (e.declaringClass != null) ! return analyseQualifiedCall(e, info); ?PackageExp pkg = args.packageExp(); if (pkg != null) *************** *** 387,390 **** --- 339,395 ---- return e; } + + Expression analyseQualifiedCall(CallExp e, Info info) + { + Arguments args = e.arguments; + + ?LocatedString funName = identString(e.function); + if (funName == null) + throw notNull(bossa.util.Internal.error + (e.function, "This is not a valid class member")); + + int arity = args.size(); + + if ((! e.hasBrackets) && (arity == 0)) + // This case is like java.lang.Byte.toString: + // look for a method with that name and any arity, + // since the method is not called but just referenced. + { + List<VarSymbol> possibilities = JavaClasses.findJavaMethods + (e.declaringClass, funName.toString()); + + if (possibilities.size() == 0) + throw error(e, "Class " + notNull(e.declaringClass).getName() + + " has no static method or static field named " + + funName); + + /* + If there is a field access, then we consider this an access + to the static field. Otherwise, it is a reference to + the method, not applied. + */ + if (possibilities.has(VarSymbol s => s.isFieldAccess())) + { + e.function = newOverloadedSymbolExp(possibilities, funName); + return e; + } + else + return newOverloadedSymbolExp(possibilities, funName); + } + + List<VarSymbol> possibilities = JavaClasses.findJavaMethods + (e.declaringClass, funName.toString(), arity); + + if (possibilities.size() == 0) + throw error(e, "Class " + notNull(e.declaringClass).getName() + + (arity == 0 ? " has no static method or static field named " : + arity == 1 ? " has no method or field named " : + " has no method named ") + + funName); + + e.function = newOverloadedSymbolExp(possibilities, funName); + + return e; + } analyse(e@FunExp, info) |