[Nice-commit] Nice/src/bossa/syntax Pattern.java,1.86,1.87
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-08-03 10:16:25
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21010/F:/nice/src/bossa/syntax Modified Files: Pattern.java Log Message: Added a fast coverage test that can check the correctness of a part of the methods avoiding the long test. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** Pattern.java 5 Jul 2004 08:22:25 -0000 1.86 --- Pattern.java 3 Aug 2004 10:16:13 -0000 1.87 *************** *** 448,451 **** --- 448,505 ---- } + /** + returns true when the patterns can't match the same values. + May return false if it can't be determined easily. + */ + public boolean disjoint(Pattern that) + { + if (this.atAny() || that.atAny()) + return false; + + if (this.atNull() ^ that.atNull()) + return true; + + if (this.atBool() && that.atBool()) + return this.atTrue() ^ that.atTrue(); + + if (this.atReference() && that.atReference()) + return ! this.atValue.equals(that.atValue); + + if (this.atString() && that.atString()) + return ! this.atValue.equals(that.atValue); + + if (this.atIntCompare() && that.atIntCompare()) + { + if (this.atLess() == that.atLess()) + return false; + + long val = this.atValue.longValue(); + if (this.compareKind == LT) val--; + if (this.compareKind == GT) val++; + + return ! that.matchesCompareValue(val); + } + + if (this.atIntCompare() && that.atIntValue()) + return ! this.matchesCompareValue(that.atValue.longValue()); + + if (this.atIntValue() && that.atIntCompare()) + return ! that.matchesCompareValue(this.atValue.longValue()); + + if (this.atIntValue() && that.atIntValue()) + return ! this.atValue.equals(that.atValue); + + if (this.exactlyAt && that.exactlyAt) + return this.tc != that.tc; + + if (TypeConstructors.isClass(this.tc) && TypeConstructors.isClass(that.tc)) + return (! Typing.testRigidLeq(this.tc, that.tc)) && + (! Typing.testRigidLeq(that.tc, this.tc)); + + //TODO: check disjoints for all tc's with a <T | T <: TC_PA, T <: TC_PB> constraint + + return false; + } + public boolean matches(TypeConstructor tag) { |