summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-09-01 15:02:58 +0000
committerburaq <buraq@epfl.ch>2003-09-01 15:02:58 +0000
commit2d1a404d9a9ac56fcb323960cc8605557c87816b (patch)
tree734977d21152b30fbf82ad4316ce18d1431ad838 /sources
parent3c896b4d739a5bc2de49f9554263050720aa81bf (diff)
downloadscala-2d1a404d9a9ac56fcb323960cc8605557c87816b.tar.gz
scala-2d1a404d9a9ac56fcb323960cc8605557c87816b.tar.bz2
scala-2d1a404d9a9ac56fcb323960cc8605557c87816b.zip
CodeFactory now creates trees with correct posi...
CodeFactory now creates trees with correct positions
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/transformer/matching/CodeFactory.java42
-rw-r--r--sources/scalac/transformer/matching/SequenceMatcher.java10
2 files changed, 27 insertions, 25 deletions
diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java
index 25d6af5fa4..b702932b86 100644
--- a/sources/scalac/transformer/matching/CodeFactory.java
+++ b/sources/scalac/transformer/matching/CodeFactory.java
@@ -103,8 +103,9 @@ class CodeFactory extends PatternTool {
}
- public CodeFactory( Unit unit, Infer infer ) {
+ public CodeFactory( Unit unit, Infer infer, int pos ) {
super( unit, infer );
+ this.pos = pos;
}
// --------- these are new
@@ -112,11 +113,6 @@ class CodeFactory extends PatternTool {
/** If ... pos, type is copied from thenBody
*/
Tree If( Tree cond, Tree thenBody, Tree elseBody ) {
- //assert( thenBody.type().equals( elseBody.type() )
- // || thenBody.type().isSubType( elseBody.type() )
- // /*|| elseBody.type().isSubType( thenBody.type() BUG */)
- // : "you try to construct a naughty if "
- // + "thenBody: "+thenBody.type+" elseBody:"+elseBody.type;
assert cond != null:"cond is null";
assert thenBody != null:"thenBody is null";
assert elseBody != null:"elseBody is null";
@@ -126,6 +122,8 @@ class CodeFactory extends PatternTool {
elseBody ).setType( elseBody.type() );
}
+ /** a faked switch statement
+ */
Tree Switch( Tree selector,
Tree condition[],
Tree body[],
@@ -145,6 +143,8 @@ class CodeFactory extends PatternTool {
return result ;
}
+ /** code for a real switch statement
+ */
Tree Switch(Tree selector,
int[] tags,
Tree[] bodies,
@@ -180,7 +180,7 @@ class CodeFactory extends PatternTool {
/** returns `<seqObj.elements>' */
Tree newIterator( Tree seqObj, Type elemType ) {
Symbol newIterSym = newIterSym();
- Tree t1 = gen.Select( Position.FIRSTPOS, seqObj, newIterSym)
+ Tree t1 = gen.Select( pos, seqObj, newIterSym)
.setType( Type.MethodType(new Symbol[] {},_seqIterType( elemType )));
Tree theIterator = gen.Apply(seqObj.pos,
@@ -203,29 +203,29 @@ class CodeFactory extends PatternTool {
*/
Tree ignoreValue( Type asType ) {
if( asType.isSameAs(defs.BYTE_TYPE ))
- return make.Literal(Position.FIRSTPOS, new Integer( 0 ))
+ return make.Literal(pos, new Integer( 0 ))
.setType( defs.INT_TYPE );
else if( asType.isSameAs( defs.CHAR_TYPE ))
- return make.Literal(Position.FIRSTPOS, new Character( 'a' ))
+ return make.Literal(pos, new Character( 'a' ))
.setType( defs.CHAR_TYPE );
else if( asType.isSameAs(defs.SHORT_TYPE ))
- return make.Literal(Position.FIRSTPOS, new Integer/*Short?*/( 0 ))
+ return make.Literal(pos, new Integer/*Short?*/( 0 ))
.setType( defs.SHORT_TYPE );
else if( asType.isSameAs(defs.INT_TYPE ))
return Int( 0 );
else if( asType.isSameAs(defs.LONG_TYPE ))
- return make.Literal(Position.FIRSTPOS, new Long( 0 ))
+ return make.Literal(pos, new Long( 0 ))
.setType( defs.LONG_TYPE );
else if( asType.isSameAs(defs.FLOAT_TYPE ))
- return make.Literal(Position.FIRSTPOS, new Float( 0 ))
+ return make.Literal(pos, new Float( 0 ))
.setType( defs.FLOAT_TYPE );
else if( asType.isSameAs(defs.DOUBLE_TYPE ))
- return make.Literal(Position.FIRSTPOS, new Double( 0 ))
+ return make.Literal(pos, new Double( 0 ))
.setType( defs.DOUBLE_TYPE );
else if( asType.isSameAs(defs.BOOLEAN_TYPE ))
- return gen.mkBooleanLit(Position.FIRSTPOS, false);
+ return gen.mkBooleanLit(pos, false);
else if( asType.isSameAs(defs.STRING_TYPE ))
- return make.Literal(Position.FIRSTPOS, "")
+ return make.Literal(pos, "")
.setType( defs.STRING_TYPE );
/** FIX ME FOR THE NEW VERSION*/
else
@@ -243,7 +243,7 @@ class CodeFactory extends PatternTool {
// the caller needs to set the type !
Tree _applyNone( Tree arg ) {
- return make.Apply(Position.FIRSTPOS, arg, Tree.EMPTY_ARRAY );
+ return make.Apply(pos, arg, Tree.EMPTY_ARRAY );
}
/** code `Nil'
@@ -261,7 +261,7 @@ class CodeFactory extends PatternTool {
}
Tree Int( Integer valI ) {
- return make.Literal( Position.FIRSTPOS, valI )
+ return make.Literal( pos, valI )
.setType( defs.INT_TYPE );
}
@@ -281,19 +281,19 @@ class CodeFactory extends PatternTool {
}
Tree newSeqNil( Type tpe ) {
- return gen.Select(gen.Ident(Position.FIRSTPOS, defs.SCALA), Names.Nil/*seqNilSym()*/);
+ return gen.Select(gen.Ident(pos, defs.SCALA), Names.Nil/*seqNilSym()*/);
}
// EXPERIMENTAL
Tree newRef( Tree init ) {
//System.out.println( "hello:"+refSym().type() );
- return gen.New( Position.FIRSTPOS, defs.SCALA_TYPE, refSym(),
+ return gen.New( pos, defs.SCALA_TYPE, refSym(),
new Type[] { init.type() },
new Tree[] { init } );
}
Tree newSeqCons( Tree head, Tree tail ) {
- return gen.New( Position.FIRSTPOS, defs.SCALA_TYPE, seqConsSym(),
+ return gen.New( pos, defs.SCALA_TYPE, seqConsSym(),
new Type[] { head.type() },
new Tree[] { head, tail });
}
@@ -585,7 +585,7 @@ class CodeFactory extends PatternTool {
}
Tree newPair( Tree left, Tree right ) {
- return gen.New( Position.FIRSTPOS, defs.SCALA_TYPE, tuple2Sym(),
+ return gen.New( pos, defs.SCALA_TYPE, tuple2Sym(),
new Type[] { left.type(), right.type() },
new Tree[] { left, right });
diff --git a/sources/scalac/transformer/matching/SequenceMatcher.java b/sources/scalac/transformer/matching/SequenceMatcher.java
index 2151d95dd8..c85ec7589a 100644
--- a/sources/scalac/transformer/matching/SequenceMatcher.java
+++ b/sources/scalac/transformer/matching/SequenceMatcher.java
@@ -227,7 +227,7 @@ public class SequenceMatcher extends PatternTool {
assert body.length == pat.length;
this._m = _m;
- this.cf = new CodeFactory( unit, infer /*, _m.pos*/ );
+ this.cf = new CodeFactory( unit, infer, _m.pos );
Type seqType = pat[ 0 ].type();
@@ -264,10 +264,12 @@ public class SequenceMatcher extends PatternTool {
Tree newbody[] = doBinding ? addBindersToBodies( body ): body;
+ // FIXME - CODE FOR TESTING TUPLE STUFF
+
_m.tree = scalaAut.getMatcherSwitch( _m.selector,
- defaultCase,
- newbody,
- _m.resultType );
+ defaultCase,
+ newbody,
+ _m.resultType );
} // construct (Matcher, Tree[], Tree[], Tree, boolean )
/** constructor, invoked by AlgebraicMatcher