diff options
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 3 | ||||
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 12 | ||||
-rw-r--r-- | sources/scalac/backend/Primitives.java | 3 | ||||
-rw-r--r-- | sources/scalac/backend/jvm/GenJVM.java | 3 | ||||
-rw-r--r-- | sources/scalac/backend/msil/GenMSIL.java | 4 | ||||
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 8 | ||||
-rw-r--r-- | sources/scalac/transformer/PatternMatcher.java | 55 | ||||
-rw-r--r-- | sources/scalac/transformer/matching/PatternMatcher.java | 55 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 1 | ||||
-rw-r--r-- | sources/scalac/util/Names.java | 2 |
10 files changed, 35 insertions, 111 deletions
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 76f9e5c71d..0c9c47eb88 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -153,7 +153,8 @@ public class TreeGen implements Kinds, Modifiers { /** Build a boolean constant tree. */ public Tree mkBoolean(int pos, boolean bool) { - return mkRef(pos, bool ? definitions.TRUE() : definitions.FALSE()); + return make.Literal(pos, bool ? Boolean.TRUE : Boolean.FALSE). + setType(definitions.BOOLEAN_TYPE); } /** Build a tree to be used as a base class constructor for a template. diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 84bfea6689..f525398b3c 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -193,10 +193,6 @@ public class Parser implements Tokens { return make.Select(pos, make.Ident(pos, Names.scala), name); } - Tree scalaBooleanDot(int pos, Name name) { - return make.Select(pos, scalaDot(pos, Names.Boolean), name); - } - /** Create tree for for-comprehension <for (enums) do body> or * <for (enums) yield body> where mapName and flatmapName are chosen * corresponding to whether this is a for-do or a for-yield. @@ -457,10 +453,10 @@ public class Parser implements Tokens { t = make.Literal(s.pos, s.name.toString()); break; case TRUE: - t = scalaBooleanDot(s.pos, Names.True); + t = make.Literal(s.pos, Boolean.TRUE); break; case FALSE: - t = scalaBooleanDot(s.pos, Names.False); + t = make.Literal(s.pos, Boolean.FALSE); break; case NULL: t = make.Ident(s.pos, Names.null_); @@ -962,10 +958,10 @@ public class Parser implements Tokens { new Tree.CaseDef[]{ (CaseDef)make.CaseDef( rhs.pos, pat.duplicate(), Tree.Empty, - scalaBooleanDot(rhs.pos, Names.True)), + make.Literal(s.pos, Boolean.TRUE)), (CaseDef)make.CaseDef( rhs.pos, make.Ident(rhs.pos, Names.WILDCARD), Tree.Empty, - scalaBooleanDot(rhs.pos, Names.False))})}); + make.Literal(s.pos, Boolean.FALSE))})}); return make.PatDef(pos, 0, pat, rhs); } diff --git a/sources/scalac/backend/Primitives.java b/sources/scalac/backend/Primitives.java index 74b4965110..9ea139fe50 100644 --- a/sources/scalac/backend/Primitives.java +++ b/sources/scalac/backend/Primitives.java @@ -516,9 +516,6 @@ public class Primitives { addPrimitive(FARRAY_SET, Primitive.FARRAY_SET); addPrimitive(DARRAY_SET, Primitive.DARRAY_SET); addPrimitive(OARRAY_SET, Primitive.OARRAY_SET); - - // !!! Boolean.True - // !!! Boolean.False } private void addAdd(Symbol clasz, int count) { diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java index e76728903f..4ab9664291 100644 --- a/sources/scalac/backend/jvm/GenJVM.java +++ b/sources/scalac/backend/jvm/GenJVM.java @@ -450,6 +450,9 @@ class JVMGenerator { } else if (value instanceof String) { generatedType = cst.T_OBJECT; currIL.append(new PUSH(currPool, (String)value)); + } else if (value instanceof Boolean) { + generatedType = cst.T_BOOLEAN; + currIL.append(new PUSH(currPool, (Boolean)value)); } else throw global.fail("unknown literal " + value); break; diff --git a/sources/scalac/backend/msil/GenMSIL.java b/sources/scalac/backend/msil/GenMSIL.java index 5d405641d2..c580b06dd5 100644 --- a/sources/scalac/backend/msil/GenMSIL.java +++ b/sources/scalac/backend/msil/GenMSIL.java @@ -553,10 +553,6 @@ public class GenMSIL /*implements Modifiers */ { // break; case Select(Tree qualifier, Name selector): - if (sym == defs.TRUE()) - return TRUE_ITEM; - if (sym == defs.FALSE()) - return FALSE_ITEM; if (sym.isModule()) { //log("gen: Select from a module: " + sym); if (sym.isJava()) diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index a842885d31..de31e34a06 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -139,13 +139,9 @@ public class Definitions { /** members of class Boolean */ - private Symbol TRUE; - private Symbol FALSE; private Symbol BARBAR; private Symbol AMPAMP; - public Symbol TRUE () { loadBooleanMembers(); return TRUE ; } - public Symbol FALSE () { loadBooleanMembers(); return FALSE ; } public Symbol BARBAR() { loadBooleanMembers(); return BARBAR; } public Symbol AMPAMP() { loadBooleanMembers(); return AMPAMP; } @@ -391,10 +387,8 @@ public class Definitions { } private void loadBooleanMembers() { - if (TRUE != null) return; + if (BARBAR != null) return; Symbol booleanStatics = getModule(Names.scala_Boolean); - TRUE = booleanStatics.members().lookup(Names.True); - FALSE = booleanStatics.members().lookup(Names.False); BARBAR = BOOLEAN_TYPE.lookup(Names.BARBAR); AMPAMP = BOOLEAN_TYPE.lookup(Names.AMPAMP); } diff --git a/sources/scalac/transformer/PatternMatcher.java b/sources/scalac/transformer/PatternMatcher.java index 382b24f86e..e1dc0c0503 100644 --- a/sources/scalac/transformer/PatternMatcher.java +++ b/sources/scalac/transformer/PatternMatcher.java @@ -22,8 +22,6 @@ public class PatternMatcher { public static final Name RESULT_N = Name.fromString("$result"); public static final Name SCALA_N = Name.fromString("scala"); public static final Name BOOLEAN_N = Name.fromString("Boolean"); - public static final Name TRUE_N = Name.fromString("True"); - public static final Name FALSE_N = Name.fromString("False"); public static final Name AND_N = Name.fromString("$amp$amp"); public static final Name OR_N = Name.fromString("$bar$bar"); public static final Name NOT_N = Name.fromString("$bang"); @@ -79,14 +77,6 @@ public class PatternMatcher { */ Symbol statics; - /** true symbol - */ - Symbol trueSym; - - /** false symbol - */ - Symbol falseSym; - /** constructor */ @@ -112,8 +102,6 @@ public class PatternMatcher { Modifiers.MUTABLE); this.resultVar.setType(tpe); this.statics = defs.getModule(Names.scala_Boolean); - this.trueSym = defs.TRUE(); - this.falseSym = defs.FALSE(); this.infer = infer; } @@ -792,25 +780,14 @@ public class PatternMatcher { } protected Tree mkBoolean(int pos, boolean bool) { - Name name = bool ? TRUE_N : FALSE_N; - Symbol val = bool ? trueSym : falseSym; - return make.Select( - pos, - make.Select( - pos, - make.Ident(pos, SCALA_N) - .setType(typeOf(defs.SCALA)).setSymbol(defs.SCALA), - BOOLEAN_N).setType(typeOf(statics)).setSymbol(statics), - name).setType(defs.BOOLEAN_TYPE).setSymbol(val); + Boolean val = bool ? Boolean.TRUE : Boolean.FALSE; + return make.Literal(pos, val).setType(defs.BOOLEAN_TYPE); } protected Tree mkNegate(Tree tree) { switch (tree) { - case Select(_, _): - if (tree.symbol() == trueSym) - return mkBoolean(tree.pos, false); - else if (tree.symbol() == falseSym) - return mkBoolean(tree.pos, true); + case Literal(Object value): + return mkBoolean(tree.pos, !((Boolean)value).booleanValue()); } return make.Apply( tree.pos, @@ -820,16 +797,12 @@ public class PatternMatcher { protected Tree mkAnd(Tree left, Tree right) { switch (left) { - case Select(_, _): - if (left.symbol() == trueSym) - return right; - else if (left.symbol() == falseSym) - return left; + case Literal(Object value): + return ((Boolean)value).booleanValue() ? right : left; } switch (right) { - case Select(_, _): - if (right.symbol() == trueSym) - return left; + case Literal(Object value): + if (((Boolean)value).booleanValue()) return left; } Symbol fun = left.type.lookup(AND_N); return make.Apply( @@ -843,16 +816,12 @@ public class PatternMatcher { protected Tree mkOr(Tree left, Tree right) { switch (left) { - case Select(_, _): - if (left.symbol() == trueSym) - return left; - else if (left.symbol() == falseSym) - return right; + case Literal(Object value): + return ((Boolean)value).booleanValue() ? left : right; } switch (right) { - case Select(_, _): - if (right.symbol() == falseSym) - return left; + case Literal(Object value): + if (!((Boolean)value).booleanValue()) return left; } Symbol fun = left.type.lookup(OR_N); return make.Apply( diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java index 382b24f86e..e1dc0c0503 100644 --- a/sources/scalac/transformer/matching/PatternMatcher.java +++ b/sources/scalac/transformer/matching/PatternMatcher.java @@ -22,8 +22,6 @@ public class PatternMatcher { public static final Name RESULT_N = Name.fromString("$result"); public static final Name SCALA_N = Name.fromString("scala"); public static final Name BOOLEAN_N = Name.fromString("Boolean"); - public static final Name TRUE_N = Name.fromString("True"); - public static final Name FALSE_N = Name.fromString("False"); public static final Name AND_N = Name.fromString("$amp$amp"); public static final Name OR_N = Name.fromString("$bar$bar"); public static final Name NOT_N = Name.fromString("$bang"); @@ -79,14 +77,6 @@ public class PatternMatcher { */ Symbol statics; - /** true symbol - */ - Symbol trueSym; - - /** false symbol - */ - Symbol falseSym; - /** constructor */ @@ -112,8 +102,6 @@ public class PatternMatcher { Modifiers.MUTABLE); this.resultVar.setType(tpe); this.statics = defs.getModule(Names.scala_Boolean); - this.trueSym = defs.TRUE(); - this.falseSym = defs.FALSE(); this.infer = infer; } @@ -792,25 +780,14 @@ public class PatternMatcher { } protected Tree mkBoolean(int pos, boolean bool) { - Name name = bool ? TRUE_N : FALSE_N; - Symbol val = bool ? trueSym : falseSym; - return make.Select( - pos, - make.Select( - pos, - make.Ident(pos, SCALA_N) - .setType(typeOf(defs.SCALA)).setSymbol(defs.SCALA), - BOOLEAN_N).setType(typeOf(statics)).setSymbol(statics), - name).setType(defs.BOOLEAN_TYPE).setSymbol(val); + Boolean val = bool ? Boolean.TRUE : Boolean.FALSE; + return make.Literal(pos, val).setType(defs.BOOLEAN_TYPE); } protected Tree mkNegate(Tree tree) { switch (tree) { - case Select(_, _): - if (tree.symbol() == trueSym) - return mkBoolean(tree.pos, false); - else if (tree.symbol() == falseSym) - return mkBoolean(tree.pos, true); + case Literal(Object value): + return mkBoolean(tree.pos, !((Boolean)value).booleanValue()); } return make.Apply( tree.pos, @@ -820,16 +797,12 @@ public class PatternMatcher { protected Tree mkAnd(Tree left, Tree right) { switch (left) { - case Select(_, _): - if (left.symbol() == trueSym) - return right; - else if (left.symbol() == falseSym) - return left; + case Literal(Object value): + return ((Boolean)value).booleanValue() ? right : left; } switch (right) { - case Select(_, _): - if (right.symbol() == trueSym) - return left; + case Literal(Object value): + if (((Boolean)value).booleanValue()) return left; } Symbol fun = left.type.lookup(AND_N); return make.Apply( @@ -843,16 +816,12 @@ public class PatternMatcher { protected Tree mkOr(Tree left, Tree right) { switch (left) { - case Select(_, _): - if (left.symbol() == trueSym) - return left; - else if (left.symbol() == falseSym) - return right; + case Literal(Object value): + return ((Boolean)value).booleanValue() ? left : right; } switch (right) { - case Select(_, _): - if (right.symbol() == falseSym) - return left; + case Literal(Object value): + if (!((Boolean)value).booleanValue()) return left; } Symbol fun = left.type.lookup(OR_N); return make.Apply( diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 7acd13a988..dd90916977 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -159,6 +159,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { else if (value instanceof Float) return Name.fromString("scala.Float"); else if (value instanceof Double) return Name.fromString("scala.Double"); else if (value instanceof String) return Name.fromString("java.lang.String"); + else if (value instanceof Boolean) return Name.fromString("scala.Boolean"); else throw new ApplicationError(); } diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java index 7a39afe3f5..a7bc70d534 100644 --- a/sources/scalac/util/Names.java +++ b/sources/scalac/util/Names.java @@ -35,7 +35,6 @@ public class Names { public static final Name Char = Name.fromString("Char"); public static final Name Boolean = Name.fromString("Boolean"); public static final Name Double = Name.fromString("Double"); - public static final Name False = Name.fromString("False"); public static final Name Float = Name.fromString("Float"); public static final Name Function = Name.fromString("Function"); public static final Name Int = Name.fromString("Int"); @@ -51,7 +50,6 @@ public class Names { public static final Name String = Name.fromString("String"); public static final Name Symbol = Name.fromString("Symbol"); public static final Name Throwable = Name.fromString("Throwable"); - public static final Name True = Name.fromString("True"); public static final Name Tuple = Name.fromString("Tuple"); public static final Name Unit = Name.fromString("Unit"); public static final Name apply = Name.fromString("apply"); |