[Nice-commit] Nice/src/bossa/syntax Arguments.java,1.29,1.30 constructor.nice,1.2,1.3 overloadedsymb
Brought to you by:
bonniot
|
From: Arjan B. <ar...@us...> - 2005-01-02 21:39:32
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6568/F:/nice/src/bossa/syntax Modified Files: Arguments.java constructor.nice overloadedsymbol.nice tools.nice Log Message: Moved error reporting code out of Arguments. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** tools.nice 2 Jan 2005 02:21:00 -0000 1.88 --- tools.nice 2 Jan 2005 21:39:22 -0000 1.89 *************** *** 209,213 **** ?gnu.bytecode.ClassType staticClass(Arguments) = native gnu.bytecode.ClassType Arguments.staticClass(); ?gnu.bytecode.ClassType staticClass(Expression) = native gnu.bytecode.ClassType Expression.staticClass(); - ?String explainNoMatch(Arguments, List<VarSymbol>) = native String Arguments.explainNoMatch(List); Map<VarSymbol,mlsub.typing.Polytype> types(Arguments) = native Arguments.types; <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); --- 209,212 ---- *************** *** 263,268 **** boolean containsAlike(List<bossa.syntax.Monotype>) = native boolean bossa.syntax.Monotype.containsAlike(List); mlsub.typing.Monotype[] rawResolve(TypeMap,Collection<bossa.syntax.Monotype>) = native mlsub.typing.Monotype[] bossa.syntax.Monotype.rawResolve(TypeMap, Collection); - List<String> noMatchByName(Arguments, FormalParameters) = native List Arguments.noMatchByName(FormalParameters); - List<FormalParameters.Parameter> missingArgs(Arguments, FormalParameters) = native List Arguments.missingArgs(FormalParameters); List<FormalParameters.Parameter> getRequiredParameters(FormalParameters) = native List FormalParameters.getRequiredParameters(); List<FormalParameters.Parameter> asList(FormalParameters) = native List FormalParameters.asList(); --- 262,265 ---- Index: Arguments.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Arguments.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Arguments.java 14 Dec 2004 20:18:05 -0000 1.29 --- Arguments.java 2 Jan 2005 21:39:22 -0000 1.30 *************** *** 212,292 **** } - String explainNoMatch(List /*VarSymbol*/ noMatches) - { - List argnames = new LinkedList(); - for (int i = 0; i < arguments.length; i++) - if (arguments[i].name != null) - argnames.add(arguments[i].name.toString()); - - if (!argnames.isEmpty()) - { - for (Iterator i = noMatches.iterator(); i.hasNext();) - { - VarSymbol noMatch = (VarSymbol)i.next(); - if (noMatch.isFunSymbol()) - argnames.retainAll(noMatchByName(noMatch.getFormalParameters())); - } - if (!argnames.isEmpty()) - return " has an argument named " + argnames.get(0); - } - //fall back to default error message - return null; - } - - List noMatchByName(FormalParameters parameters) - { - List res = new LinkedList(); - for (int i = 0; i < arguments.length; i++) - if (arguments[i].name != null) - { - String s = arguments[i].name.toString(); - if (parameters == null || !parameters.hasMatchFor(s)) - res.add(s); - } - - return res; - } - - List missingArgs(FormalParameters parameters) - { - List missing = new LinkedList(); - Iterator reqParams = parameters.getRequiredParameters().iterator(); - int lastUsedPositional = -1; - while(reqParams.hasNext()) - { - boolean found = false; - FormalParameters.Parameter param = (FormalParameters.Parameter)reqParams.next(); - if (param.value() != null) - continue; - if (param instanceof FormalParameters.NamedParameter) - { - for (int i = 0; i < arguments.length; i++) - if (arguments[i].name != null) - { - String s = arguments[i].name.toString(); - if (param.match(s)) - { - found = true; - break; - } - } - } - else { - for(int i = lastUsedPositional + 1; i < arguments.length; i++) - { - if (arguments[i].name == null) - { - found = true; - lastUsedPositional = i; - break; - } - } - } - if (!found) - missing.add(param); - } - return missing; - } - Argument[] arguments; } --- 212,215 ---- Index: constructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/constructor.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** constructor.nice 2 Jan 2005 02:20:59 -0000 1.2 --- constructor.nice 2 Jan 2005 21:39:22 -0000 1.3 *************** *** 134,136 **** return res.toString(); } ! } \ No newline at end of file --- 134,177 ---- return res.toString(); } ! } ! ! List<FormalParameters.Parameter> missingArgs(Arguments args, FormalParameters parameters) ! { ! List<FormalParameters.Parameter> missing = new LinkedList(); ! Iterator<FormalParameters.Parameter> reqParams = parameters.getRequiredParameters().iterator(); ! int lastUsedPositional = -1; ! while(reqParams.hasNext()) ! { ! boolean found = false; ! let param = reqParams.next(); ! if (param.value() != null) ! continue; ! if (param instanceof FormalParameters.NamedParameter) ! { ! for (int i = 0; i < args.arguments.length; i++) ! if (args.arguments[i].name != null) ! { ! String s = notNull(args.arguments[i].name).toString(); ! if (param.match(s)) ! { ! found = true; ! break; ! } ! } ! } ! else { ! for(int i = lastUsedPositional + 1; i <args.arguments.length; i++) ! { ! if (args.arguments[i].name == null) ! { ! found = true; ! lastUsedPositional = i; ! break; ! } ! } ! } ! if (!found) ! missing.add(param); ! } ! return missing; ! } Index: overloadedsymbol.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/overloadedsymbol.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** overloadedsymbol.nice 2 Jan 2005 02:20:59 -0000 1.9 --- overloadedsymbol.nice 2 Jan 2005 21:39:22 -0000 1.10 *************** *** 645,646 **** --- 645,680 ---- return Arrays.equals(m1.javaArgTypes(), m2.javaArgTypes()); } + + ?String explainNoMatch(Arguments args, List<VarSymbol> noMatches) + { + List<String> argnames = new LinkedList(); + for (int i = 0; i < args.arguments.length; i++) + if (args.arguments[i].name != null) + argnames.add(notNull(args.arguments[i].name).toString()); + + if (!argnames.isEmpty()) + { + for (noMatch : noMatches) + if (noMatch.isFunSymbol()) + argnames.retainAll(args.noMatchByName(noMatch.getFormalParameters())); + + if (!argnames.isEmpty()) + return " has an argument named " + argnames.get(0); + } + //fall back to default error message + return null; + } + + List<String> noMatchByName(Arguments args, ?FormalParameters parameters) + { + List<String> res = new LinkedList(); + for (int i = 0; i < args.arguments.length; i++) + if (args.arguments[i].name != null) + { + String s = notNull(args.arguments[i].name).toString(); + if (parameters == null || !parameters.hasMatchFor(s)) + res.add(s); + } + + return res; + } |