[Nice-commit] Nice/src/bossa/syntax Arguments.java,1.14,1.15 Block.java,1.53,1.54 Constructor.java,1
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv14862/F:/nice/src/bossa/syntax
Modified Files:
Arguments.java Block.java Constructor.java
FormalParameters.java FunSymbol.java MethodDeclaration.java
OverloadedSymbolExp.java
Log Message:
Error messages caused by mistyping the name of a named argument give more usefull information. And changed a few cosmetic things.
Index: Arguments.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Arguments.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** Arguments.java 27 Nov 2002 16:59:48 -0000 1.14
--- Arguments.java 23 Mar 2003 23:03:01 -0000 1.15
***************
*** 13,16 ****
--- 13,17 ----
package bossa.syntax;
+ import java.util.*;
import bossa.util.*;
***************
*** 185,191 ****
--- 186,194 ----
if (arguments.length != arity)
return false;
+
for (int i = 0; i<arguments.length; i++)
if (arguments[i].name != null)
return false;
+
applicationExpressions.put(symbol, inOrder());
return true;
***************
*** 221,233 ****
}
! String explainNoMatch()
{
for (int i = 0; i < arguments.length; i++)
if (arguments[i].name != null)
! return " has compatible named arguments";
return " has " + arguments.length + " arguments";
}
!
Argument[] arguments;
}
--- 224,267 ----
}
! 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();)
+ {
+ Object noMatch = i.next();
+ if (noMatch instanceof FunSymbol)
+ {
+ argnames.retainAll(noMatchByName(((FunSymbol)noMatch).parameters));
+ User.warning(Util.map("", ", ", "", noMatchByName(((FunSymbol)noMatch).parameters)));
+ }
+ }
+ if (!argnames.isEmpty())
+ return " has an argument named " + argnames.get(0);
+
+ return " has compatible named arguments";
+ }
return " has " + arguments.length + " arguments";
}
!
! 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.hasMatchFor(s))
! res.add(s);
! }
!
! return res;
! }
!
Argument[] arguments;
}
Index: Block.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Block.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** Block.java 6 Mar 2003 01:47:23 -0000 1.53
--- Block.java 23 Mar 2003 23:03:02 -0000 1.54
***************
*** 196,200 ****
FunSymbol symbol = new FunSymbol(name,
Constraint.True, parameters,
! returnType, parameters.size);
symbol.syntacticType.getMonotype().nullness = Monotype.sure;
return new LocalFunction(symbol, value, parameters);
--- 196,200 ----
FunSymbol symbol = new FunSymbol(name,
Constraint.True, parameters,
! returnType);
symbol.syntacticType.getMonotype().nullness = Monotype.sure;
return new LocalFunction(symbol, value, parameters);
Index: Constructor.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constructor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Constructor.java 2 Sep 2002 11:46:51 -0000 1.1
--- Constructor.java 23 Mar 2003 23:03:02 -0000 1.2
***************
*** 13,16 ****
--- 13,17 ----
package bossa.syntax;
+ import java.util.*;
import bossa.util.*;
import bossa.util.Location;
***************
*** 98,116 ****
{
String name = classe.getName();
!
StringBuffer res = new StringBuffer();
res.append("Class ").append(name);
if (parameters.size == 0)
! {
! res.append(" has no fields. Therefore its constructor takes no arguments.");
! return res.toString();
! }
! res.append(" has the following fields:\n").append(parameters);
! res.append('\n');
! res.append("Please provide values for the fields, ")
! .append("at least for those with no default value.\n")
! .append("The syntax is:\n")
! .append("new " + name + "(field1: value1, ..., fieldN: valueN)");
return res.toString();
--- 99,125 ----
{
String name = classe.getName();
!
StringBuffer res = new StringBuffer();
res.append("Class ").append(name);
if (parameters.size == 0)
! {
! res.append(" has no fields. Therefore its constructor takes no arguments.");
! return res.toString();
! }
! List nonmatching = arguments.noMatchByName(parameters);
! if (!nonmatching.isEmpty())
! {
! res.append(" has no field named "+nonmatching.get(0));
! return res.toString();
! }
!
! res.append(" has the following fields:\n")
! .append(parameters)
! .append('\n')
! .append("Please provide values for the fields, ")
! .append("at least for those with no default value.\n")
! .append("The syntax is:\n")
! .append("new " + name + "(field1: value1, ..., fieldN: valueN)");
return res.toString();
Index: FormalParameters.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/FormalParameters.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** FormalParameters.java 27 Nov 2002 17:56:08 -0000 1.20
--- FormalParameters.java 23 Mar 2003 23:03:03 -0000 1.21
***************
*** 316,319 ****
--- 316,320 ----
for (int i = 0; i < size; i++)
res[i] = parameters[i].type;
+
return res;
}
***************
*** 326,329 ****
--- 327,331 ----
for (int i = 0; i < size; i++)
res[i] = parameters[i].getSymbol();
+
return res;
}
***************
*** 398,401 ****
--- 400,404 ----
else
exps[i] = args.getExp(map[i] - 1);
+
args.applicationExpressions.put(symbol, exps);
args.usedArguments.put(symbol, map);
***************
*** 411,419 ****
if (i == map.length)
return true;
! else
! {
! map[i] = num + 1;
! return false;
! }
}
--- 414,420 ----
if (i == map.length)
return true;
!
! map[i] = num + 1;
! return false;
}
***************
*** 426,436 ****
if (i == map.length)
return true;
! else
! {
! map[i] = num + 1;
! return false;
! }
}
/****************************************************************
* Misc.
--- 427,444 ----
if (i == map.length)
return true;
!
! map[i] = num + 1;
! return false;
}
+ public boolean hasMatchFor(String s)
+ {
+ for (int i = 0; i<parameters.length; i++)
+ if (parameters[i].match(s))
+ return true;
+
+ return false;
+ }
+
/****************************************************************
* Misc.
Index: FunSymbol.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/FunSymbol.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** FunSymbol.java 25 Sep 2002 16:40:26 -0000 1.6
--- FunSymbol.java 23 Mar 2003 23:03:03 -0000 1.7
***************
*** 13,16 ****
--- 13,17 ----
package bossa.syntax;
+ import java.util.*;
import nice.tools.code.Types;
***************
*** 19,23 ****
FunSymbol(LocatedString name,
Constraint constraint, FormalParameters parameters,
! Monotype returnType, int arity)
{
super(name,
--- 20,24 ----
FunSymbol(LocatedString name,
Constraint constraint, FormalParameters parameters,
! Monotype returnType)
{
super(name,
***************
*** 25,29 ****
new FunType(parameters.types(), returnType)));
this.parameters = parameters;
! this.arity = arity;
}
--- 26,30 ----
new FunType(parameters.types(), returnType)));
this.parameters = parameters;
! this.arity = parameters.size;
}
***************
*** 67,79 ****
{
if (parameters == null)
// true for constructors, for instance. case might be removed
if (!arguments.plainApplication(arity, this))
return 0;
! else
! return 2;
else if (!parameters.match(arguments, this))
return 0;
! else
! return 2;
}
--- 68,80 ----
{
if (parameters == null)
+ {
// true for constructors, for instance. case might be removed
if (!arguments.plainApplication(arity, this))
return 0;
! }
else if (!parameters.match(arguments, this))
return 0;
!
! return 2;
}
Index: MethodDeclaration.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodDeclaration.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** MethodDeclaration.java 10 Dec 2002 19:10:52 -0000 1.36
--- MethodDeclaration.java 23 Mar 2003 23:03:03 -0000 1.37
***************
*** 244,249 ****
super(name, constraint,
MethodDeclaration.this.formalParameters(),
! returnType,
! MethodDeclaration.this.arity);
}
--- 244,248 ----
super(name, constraint,
MethodDeclaration.this.formalParameters(),
! returnType);
}
Index: OverloadedSymbolExp.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/OverloadedSymbolExp.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** OverloadedSymbolExp.java 1 Mar 2003 00:58:28 -0000 1.49
--- OverloadedSymbolExp.java 23 Mar 2003 23:03:03 -0000 1.50
***************
*** 399,404 ****
if (symbols.size() <= 1)
return "[" + Util.map("", "\n|", "", symbols) + "]";
! else
! return "\n[" + Util.map("", "\n|", "", symbols) + "]";
}
--- 399,404 ----
if (symbols.size() <= 1)
return "[" + Util.map("", "\n|", "", symbols) + "]";
!
! return "\n[" + Util.map("", "\n|", "", symbols) + "]";
}
***************
*** 423,427 ****
default:
! return "No method with name " + ident + arguments.explainNoMatch();
}
}
--- 423,428 ----
default:
! return "No method with name " + ident +
! arguments.explainNoMatch(removed);
}
}
|