[Nice-commit] Nice/src/bossa/syntax Pattern.java,1.39,1.40
Brought to you by:
bonniot
From: <ar...@us...> - 2003-02-25 12:31:35
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv9231/F:/nice/src/bossa/syntax Modified Files: Pattern.java Log Message: Added dispatch on integer and character literals. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Pattern.java 20 Feb 2003 15:09:34 -0000 1.39 --- Pattern.java 25 Feb 2003 12:30:56 -0000 1.40 *************** *** 67,70 **** --- 67,71 ---- this.exactlyAt = exactlyAt; this.location = location; + if (tc != null) { *************** *** 83,86 **** --- 84,117 ---- } } + else if (atValue != null && atValue instanceof ConstantExp) + { + this.atIntValue = true; + String typeName = ""; + Object val = ((ConstantExp)atValue).value; + + if (val instanceof Byte) { + this.value = ((Byte)val).byteValue(); + typeName = "byte"; + } + else if (val instanceof Short) { + this.value = ((Short)val).shortValue(); + typeName = "short"; + } + else if (val instanceof Character) { + this.value = ((Character)val).charValue(); + typeName = "char"; + } + else if (val instanceof Integer) { + this.value = ((Integer)val).intValue(); + typeName = "int"; + } + else if (val instanceof Long) { + this.value = ((Long)val).longValue(); + typeName = "long"; + } + this.typeConstructor = + new TypeIdent(new LocatedString(typeName,location)); + } + } *************** *** 102,105 **** --- 133,145 ---- } + Pattern(TypeConstructor tc, Expression atValue, long value) + { + this.tc = tc; + this.atValue = atValue; + this.value = value; + this.atIntValue = true; + } + + final mlsub.typing.Monotype getType() { *************** *** 283,286 **** --- 323,329 ---- return that.tc == PrimitiveType.boolTC; + if (that.atIntValue) + return this.atIntValue && (this.value == that.value); + if (this.tc == that.tc) return this.exactlyAt || ! that.exactlyAt; *************** *** 301,304 **** --- 344,350 ---- return false; + if (atIntValue) + return false; + if (tag == PrimitiveType.trueBoolTC) { *************** *** 321,324 **** --- 367,379 ---- } + public boolean matchesValue(long val) + { + if (atAny()) + return true; + if (atIntValue) + return this.value == val; + return atPrimTypeFitting(val); + } + /**************************************************************** * Printing *************** *** 331,335 **** if (atAny()) return "@_"; ! if (atBool()) return "@" + atValue.toString(); StringBuffer res = new StringBuffer(); --- 386,390 ---- if (atAny()) return "@_"; ! if (atBool() || atIntValue) return "@" + atValue.toString(); StringBuffer res = new StringBuffer(); *************** *** 369,372 **** --- 424,433 ---- return "@" + atValue.toString(); + if (atIntValue) + if (tc == PrimitiveType.charTC) + return "@" + atValue.toString(); + else + return "@" + (value >= 0 ? "+" : "") + Long.toString(value); + return (exactlyAt ? "#" : "@") *************** *** 406,409 **** --- 467,492 ---- Expression atValue = null; + if (name.length() > 1) + { + if (name.charAt(0) == '\'') + { + atValue = ConstantExp.makeChar(new LocatedString(name.substring(1,name.length()-1),Location.nowhere())); + return new Pattern(PrimitiveType.charTC, atValue, ((Character)((ConstantExp)atValue).value).charValue()); + } + if (name.charAt(0) == '+' || name.charAt(0) == '-') + { + if (name.charAt(0) == '+') + name = name.substring(1); + Object val = ((ConstantExp)ConstantExp.makeNumber(new LocatedString(name,Location.nowhere()))).value; + if (val instanceof Byte) + return new Pattern(PrimitiveType.byteTC, null, ((Byte)val).byteValue()); + if (val instanceof Short) + return new Pattern(PrimitiveType.shortTC, null, ((Short)val).shortValue()); + if (val instanceof Integer) + return new Pattern(PrimitiveType.intTC, null, ((Integer)val).intValue()); + return new Pattern(PrimitiveType.longTC, null, ((Long)val).longValue()); + } + } + if (name.equals("_")) tc = null; *************** *** 451,454 **** --- 534,542 ---- } + if (atIntValue) + return Inline.inline(nice.lang.inline.CompOp.create("lEq"), + new gnu.expr.QuoteExp(new Long(value), gnu.bytecode.Type.long_type), + parameter); + gnu.bytecode.Type ct = nice.tools.code.Types.javaType(tc); *************** *** 488,491 **** --- 576,582 ---- private Location location; + public long value; + public boolean atIntValue = false; + public boolean atNull() { return atValue == NullExp.instance; } public boolean atAny() { return atValue == null && tc == null; } *************** *** 499,501 **** --- 590,600 ---- return atBool() && atValue.toString().equals("false"); } + public boolean atPrimTypeFitting(long val){ + return ( tc == PrimitiveType.longTC ) || + (tc == PrimitiveType.intTC && val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE) || + (tc == PrimitiveType.shortTC && val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) || + (tc == PrimitiveType.charTC && val >= Character.MIN_VALUE && val <= Character.MAX_VALUE) || + (tc == PrimitiveType.byteTC && val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE); + } + } |