[Nice-commit] Nice/src/bossa/syntax ConstantExp.java,1.54,1.55 constant.nice,1.3,1.4 pattern.nice,1.
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-12-08 20:01:09
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6059/F:/nice/src/bossa/syntax Modified Files: ConstantExp.java constant.nice pattern.nice Log Message: Converted char and boolean ConstantExp. Index: constant.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/constant.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** constant.nice 1 Dec 2004 02:00:32 -0000 1.3 --- constant.nice 8 Dec 2004 20:00:58 -0000 1.4 *************** *** 45,48 **** --- 45,84 ---- } + class BooleanConstantExp extends ConstantExp + { + private gnu.expr.QuoteExp compiledValue; + + isFalse() = compiledValue == gnu.expr.QuoteExp.falseExp; + isTrue() = compiledValue == gnu.expr.QuoteExp.trueExp; + + compile() = compiledValue; + } + + public ConstantExp createBooleanConstant(boolean value, Location location) + { + return new BooleanConstantExp(nice.tools.typing.PrimitiveType.boolTC, + value, value ? "true" : "false", location, + compiledValue: notNull(value ? gnu.expr.QuoteExp.trueExp : gnu.expr.QuoteExp.falseExp)); + } + + class CharConstantExp extends ConstantExp + { + longValue() + { + Character val = cast(this.value); + return int(val.charValue()); + } + } + + public ConstantExp createCharConstant(LocatedString value) + { + let s = unescapeLiteral(value.toString()); + if (s.length() != 1) + User.error(value, "Invalid character constant: " + value); + + return new CharConstantExp(nice.tools.typing.PrimitiveType.charTC, + s[0], "'" + s + "'", value.location()); + } + /** The void constant. Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** pattern.nice 1 Dec 2004 02:00:32 -0000 1.10 --- pattern.nice 8 Dec 2004 20:00:58 -0000 1.11 *************** *** 150,155 **** addValues(values) { ! values.add(ConstantExp.makeBoolean(true, this.location)); ! values.add(ConstantExp.makeBoolean(false, this.location)); } --- 150,155 ---- addValues(values) { ! values.add(createBooleanConstant(true, this.location)); ! values.add(createBooleanConstant(false, this.location)); } *************** *** 598,603 **** { if (name[0] == '\'') ! return createPattern(new ConstantExp(nice.tools.typing.PrimitiveType.charTC, ! new Character(name[1]), name, loc)); if (name[0] == '-') --- 598,603 ---- { if (name[0] == '\'') ! return createPattern(new CharConstantExp(nice.tools.typing.PrimitiveType.charTC, ! name[1], name, loc)); if (name[0] == '-') *************** *** 632,636 **** if (name.equals("true") || name.equals("false") ) ! return createPattern(ConstantExp.makeBoolean(name.equals("true"), loc)); ?TypeSymbol sym = Node.getGlobalTypeScope().lookup(name); --- 632,636 ---- if (name.equals("true") || name.equals("false") ) ! return createPattern(createBooleanConstant(name.equals("true"), loc)); ?TypeSymbol sym = Node.getGlobalTypeScope().lookup(name); Index: ConstantExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ConstantExp.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** ConstantExp.java 1 Dec 2004 02:00:31 -0000 1.54 --- ConstantExp.java 8 Dec 2004 20:00:58 -0000 1.55 *************** *** 68,72 **** public boolean isNumber() { ! return this.value instanceof Number && !(this.value instanceof Character); } --- 68,72 ---- public boolean isNumber() { ! return this.value instanceof Number; } *************** *** 105,155 **** ****************************************************************/ - public static ConstantExp makeChar(LocatedString value) - { - String s = value.toString(); - char c; - - findChar: - if (s.length() != 0 && s.charAt(0) == '\\') - // \ escape sequence. See JLS 3.10.6 - { - if (s.length() == 2) - { - char c2 = s.charAt(1); - switch(c2) - { - case 'b' : c = '\b'; break findChar; - case 't' : c = '\t'; break findChar; - case 'n' : c = '\n'; break findChar; - case 'f' : c = '\f'; break findChar; - case 'r' : c = '\r'; break findChar; - case '\"': c = '\"'; break findChar; - case '\'': c = '\''; break findChar; - case '\\': c = '\\'; break findChar; - } - } - - try{ - int code = Integer.parseInt(s.substring(1), 8); - if(code<0 || code>255) - throw new NumberFormatException(); - c = (char) code; - } - catch(NumberFormatException e){ - throw User.error(value, "Invalid escape sequence: " + value); - } - } - else - { - if(s.length()!=1) - User.error(value, "Invalid character constant: " + value); - - c = s.charAt(0); - } - - return new ConstantExp(PrimitiveType.charTC, new Character(c), - "'" + s + "'", value.location()); - } - private static ConstantExp makeInt(long value, boolean isLong, Location location) --- 105,108 ---- *************** *** 285,334 **** } - /**************************************************************** - * Booleans - ****************************************************************/ - - public static ConstantExp makeBoolean(boolean value, Location location) - { - return new ConstantExp.Boolean(value, location); - } - - private static class Boolean extends ConstantExp - { - Boolean(boolean value, Location location) - { - super(PrimitiveType.boolTC, value ? "true" : "false", location); - compiledValue = value ? QuoteExp.trueExp : QuoteExp.falseExp; - } - - boolean isFalse() - { - return compiledValue == QuoteExp.falseExp; - } - - boolean isTrue() - { - return compiledValue == QuoteExp.trueExp; - } - - protected gnu.expr.Expression compile() - { - return compiledValue; - } - - public boolean equals(Object other) - { - return other instanceof ConstantExp.Boolean && - (isTrue() == ((ConstantExp.Boolean)other).isTrue()); - } - - private QuoteExp compiledValue; - } - public long longValue() { - if (value instanceof Character) - return ((Character)value).charValue(); - return ((Number)value).longValue(); } --- 238,243 ---- *************** *** 336,342 **** public boolean equals(Object other) { - if (other instanceof ConstantExp.Boolean) - return false; - return other instanceof ConstantExp && value.equals(((ConstantExp)other).value); --- 245,248 ---- |