From 2bde64168dbe2a4d9ce0309f137d296c2d224744 Mon Sep 17 00:00:00 2001 From: buraq Date: Wed, 26 Jan 2005 12:06:10 +0000 Subject: translated to scala --- sources/scalac/transformer/matching/CaseEnv.java | 89 ------- .../scalac/transformer/matching/CodeFactory.java | 279 --------------------- .../matching/CollectVariableTraverser.java | 45 ---- .../matching/FreshVariableTraverser.java | 80 ------ .../matching/NoSeqVariableTraverser.java | 42 ---- .../transformer/matching/PartialMatcher.java | 53 ---- .../scalac/transformer/matching/PatternNode.java | 198 --------------- .../transformer/matching/PatternNodeCreator.java | 113 --------- .../scalac/transformer/matching/PatternTool.java | 48 ---- .../transformer/matching/VariableTraverser.java | 61 ----- 10 files changed, 1008 deletions(-) delete mode 100644 sources/scalac/transformer/matching/CaseEnv.java delete mode 100644 sources/scalac/transformer/matching/CodeFactory.java delete mode 100644 sources/scalac/transformer/matching/CollectVariableTraverser.java delete mode 100644 sources/scalac/transformer/matching/FreshVariableTraverser.java delete mode 100644 sources/scalac/transformer/matching/NoSeqVariableTraverser.java delete mode 100644 sources/scalac/transformer/matching/PartialMatcher.java delete mode 100644 sources/scalac/transformer/matching/PatternNode.java delete mode 100644 sources/scalac/transformer/matching/PatternNodeCreator.java delete mode 100644 sources/scalac/transformer/matching/PatternTool.java delete mode 100644 sources/scalac/transformer/matching/VariableTraverser.java (limited to 'sources/scalac/transformer/matching') diff --git a/sources/scalac/transformer/matching/CaseEnv.java b/sources/scalac/transformer/matching/CaseEnv.java deleted file mode 100644 index ec2f5ffcf1..0000000000 --- a/sources/scalac/transformer/matching/CaseEnv.java +++ /dev/null @@ -1,89 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -** ** -** $Id$ -\* */ - -package scalac.transformer.matching; - -import scalac.*; -import scalac.ast.*; -import scalac.util.*; -import scalac.symtab.*; -import Tree.ValDef; - -/** the environment for a body of a case - */ - -public class CaseEnv { - - /** the owner of the variables created here - */ - Symbol owner; - - /** the global definitions component - */ - Definitions defs; - - /** the global tree generation component - */ - TreeGen gen; - - /** constructor - */ - public CaseEnv( Symbol owner, CompilationUnit unit ) { - this.owner = owner; - this.defs = unit.global.definitions; - this.gen = unit.global.treeGen; - } - - protected ValDef[] boundVars = new ValDef[4]; - protected int numVars = 0; - - /** substitutes a symbol on the right hand side of a ValDef - */ - public void substitute( Symbol oldSym, Tree newInit ) { - int i = 0; - while( i < numVars) { - if( boundVars[ i ].rhs.symbol() == oldSym ) { - boundVars[ i ].rhs = newInit; - return; - } - i++ ; - } - } - - public void newBoundVar(Symbol sym, Type type, Tree init) { - sym.setOwner( owner ); // FIXME should be corrected earlier - if (numVars == boundVars.length) { - ValDef[] newVars = new ValDef[numVars * 2]; - System.arraycopy(boundVars, 0, newVars, 0, numVars); - boundVars = newVars; - } - sym.setType(type); - boundVars[numVars++] = gen.ValDef(sym, init.duplicate()); - } - - public ValDef[] boundVars() { - ValDef[] newVars = new ValDef[numVars]; - System.arraycopy(boundVars, 0, newVars, 0, numVars); - return newVars; - } - - public boolean equals(Object obj) { - if (!(obj instanceof CaseEnv)) - return false; - CaseEnv env = (CaseEnv)obj; - if (env.numVars != numVars) - return false; - for (int i = 0; i < numVars; i++) - if ((boundVars[i].name != env.boundVars[i].name) || - !boundVars[i].tpe.type.isSameAs(env.boundVars[i].tpe.type) || - (boundVars[i].rhs != env.boundVars[i].rhs)) - return false; - return true; - } - -} // class CaseEnv diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java deleted file mode 100644 index f136b3da3e..0000000000 --- a/sources/scalac/transformer/matching/CodeFactory.java +++ /dev/null @@ -1,279 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -** ** -** $Id$ -\* */ - -package scalac.transformer.matching; - -import scala.tools.util.Position; - -import scalac.*; -import scalac.ast.*; -import scalac.atree.AConstant.*; -import scalac.util.*; -import scalac.symtab.*; -import PatternNode.*; -import Tree.*; - -public class CodeFactory extends PatternTool { - - public int pos = Position.FIRSTPOS ; - - public CodeFactory( CompilationUnit unit, int pos ) { - super( unit ); - this.pos = pos; - } - - // --------- these are new - - /** a faked switch statement - */ - public Tree Switch( Tree condition[], - Tree body[], - Tree defaultBody ) { - assert condition != null:"cond is null"; - assert body != null:"body is null"; - assert defaultBody != null:"defaultBody is null"; - Tree result = defaultBody; - - for( int i = condition.length-1; i >= 0; i-- ) - result = gen.If(condition[i], body[i], result); - - return result ; - } - - /** returns `List[ Tuple2[ scala.Int, ] ]' */ - public Type SeqTraceType( Type elemType ) { - return defs.LIST_TYPE(pairType(defs.int_TYPE(), elemType)); - } - - /** returns `Iterator[ elemType ]' */ - public Type _seqIterType( Type elemType ) { - return defs.ITERATOR_TYPE(elemType); - } - - /** returns `' */ - public Tree newIterator( Tree seqObj, Type elemType ) { - return gen.mkApply__(gen.Select(seqObj, defs.ITERABLE_ELEMENTS())); - } - - /** returns code `.elements' - * the parameter needs to have type attribute `Sequence[]' - */ - public Tree newIterator( Tree seqObj ) { - return newIterator( seqObj, getElemType_Sequence( seqObj.getType() )); - } - - // EXPERIMENTAL - Tree newRef( Tree init ) { - //System.out.println( "hello:"+refSym().type() ); - return gen.New( gen.mkApplyTV( gen.mkPrimaryConstructorGlobalRef( pos, defs.REF_CLASS), - new Type[] { init.getType() }, - new Tree[] { init } )); - } - - /** returns A for T <: Sequence[ A ] - */ - public Type getElemType_Sequence( Type tpe ) { - //System.err.println("getElemType_Sequence("+tpe.widen()+")"); - Type tpe1 = tpe.widen().baseType( defs.SEQ_CLASS ); - - if( tpe1 == Type.NoType ) - throw new ApplicationError("arg "+tpe+" not subtype of Seq[ A ]"); - - return tpe1.typeArgs()[ 0 ]; - } - - /** returns A for T <: Iterator[ A ] - */ - Type getElemType_Iterator( Type tpe ) { - //System.err.println("getElemType_Iterator("+tpe+")"); - - Type tpe1 = tpe.widen().baseType( defs.ITERATOR_CLASS ); - - switch( tpe1 ) { - case TypeRef(_,_,Type[] args): - return args[ 0 ]; - default: - throw new ApplicationError("arg "+tpe+" not subtype of Iterator[ A ]"); - } - - } - - /** `it.next()' - */ - public Tree _next( Tree iter ) { - return gen.mkApply__(gen.Select(iter, defs.ITERATOR_NEXT())); - } - - /** `it.hasNext()' - */ - public Tree _hasNext( Tree iter ) { - return gen.mkApply__(gen.Select(iter, defs.ITERATOR_HASNEXT())); - } - - /** `!it.hasCur()' - */ - public Tree _not_hasNext( Tree iter ) { - return gen.mkApply__(gen.Select(_hasNext(iter), defs.BOOLEAN_NOT())); - } - - /** `trace.isEmpty' - */ - public Tree isEmpty( Tree iter ) { - return gen.mkApply__(gen.Select(iter, defs.LIST_ISEMPTY())); - } - - public Tree SeqTrace_headElem( Tree arg ) { // REMOVE SeqTrace - Tree t = gen.mkApply__(gen.Select(arg, defs.LIST_HEAD())); - return gen.mkApply__(gen.Select(t, defs.TUPLE_FIELD(2, 2))); - } - - public Tree SeqTrace_headState( Tree arg ) { // REMOVE SeqTrace - Tree t = gen.mkApply__(gen.Select(arg, defs.LIST_HEAD())); - return gen.mkApply__(gen.Select(t, defs.TUPLE_FIELD(2, 1))); - - } - - public Tree SeqTrace_tail( Tree arg ) { // REMOVE SeqTrace - return gen.mkApply__(gen.Select(arg, defs.LIST_TAIL())); - } - - /** `.head()' - */ - public Tree SeqList_head( Tree arg ) { - return gen.mkApply__(gen.Select(arg, defs.LIST_HEAD())); - } - - // unused - public Tree Negate(Tree tree) { - switch (tree) { - case Literal(BOOLEAN(boolean value)): - return gen.mkBooleanLit(tree.pos, !value); - } - return gen.mkApply__(gen.Select(tree, defs.BOOLEAN_NOT())); - } - - /*protected*/ public Tree And(Tree left, Tree right) { - switch (left) { - case Literal(BOOLEAN(boolean value)): - return value ? right : left; - } - switch (right) { - case Literal(BOOLEAN(boolean value)): - if (value) return left; - } - return gen.mkApply_V(gen.Select(left, defs.BOOLEAN_AND()), new Tree[]{right}); - } - - /*protected*/ public Tree Or(Tree left, Tree right) { - switch (left) { - case Literal(BOOLEAN(boolean value)): - return value ? left : right; - } - switch (right) { - case Literal(BOOLEAN(boolean value)): - if (!value) return left; - } - return gen.mkApply_V(gen.Select(left, defs.BOOLEAN_OR()), new Tree[]{right}); - } - - // used by Equals - private Symbol getCoerceToInt(Type left) { - Symbol sym = left.lookupNonPrivate(Names.coerce); - assert sym != Symbol.NONE : Debug.show(left); - Symbol[] syms = sym.alternativeSymbols(); - for (int i = 0; i < syms.length; i++) { - switch (syms[i].info()) { - case MethodType(Symbol[] vparams, Type restpe): - if (vparams.length == 0 && restpe.isSameAs(defs.INT_TYPE())) - return syms[i]; - } - } - assert false : Debug.show(left); - return null; - } - - // used by Equals - private Symbol getEqEq(Type left, Type right) { - Symbol sym = left.lookupNonPrivate(Names.EQEQ); - assert sym != Symbol.NONE - : Debug.show(left) + "::" + Debug.show(left.members()); - Symbol fun = null; - Type ftype = defs.ANY_TYPE(); - Symbol[] syms = sym.alternativeSymbols(); - for (int i = 0; i < syms.length; i++) { - Symbol[] vparams = syms[i].valueParams(); - if (vparams.length == 1) { - Type vptype = vparams[0].info(); - if (right.isSubType(vptype) && vptype.isSubType(ftype)) { - fun = syms[i]; - ftype = vptype; - } - } - } - assert fun != null : Debug.show(sym.info()); - return fun; - } - - /*protected*/ public Tree Equals(Tree left, Tree right) { - Type ltype = left.type.widen(), rtype = right.type.widen(); - if (ltype.isSameAs(rtype) - && (ltype.isSameAs(defs.CHAR_TYPE()) - || ltype.isSameAs(defs.BYTE_TYPE()) - || ltype.isSameAs(defs.SHORT_TYPE()))) - { - right = gen.mkApply__(gen.Select(right, getCoerceToInt(rtype))); - rtype = defs.INT_TYPE(); - } - Symbol eqsym = getEqEq(ltype, rtype); - return gen.mkApply_V(gen.Select(left, eqsym), new Tree[]{right}); - } - - /*protected*/ public Tree ThrowMatchError(int pos, Type type) { - return gen.mkApplyTV( - gen.mkGlobalRef(pos, defs.MATCHERROR_FAIL()), - new Tree[]{gen.mkType(pos, type)}, - new Tree[]{ - gen.mkStringLit(pos, unit.toString()), - gen.mkIntLit(pos, Position.line(pos)) - }); - } - - /*protected*/ public Tree ThrowMatchError(int pos, Type type, Tree tree) { - return gen.mkApplyTV( - gen.mkGlobalRef(pos, defs.MATCHERROR_REPORT()), - new Tree[]{gen.mkType(pos, type)}, - new Tree[]{ - gen.mkStringLit(pos, unit.toString()), - gen.mkIntLit(pos, Position.line(pos)), - tree - }); - } - - /*protected*/ public Tree Error(int pos, Type type) { - return gen.mkApplyTV( - gen.mkGlobalRef(pos, defs.MATCHERROR_FAIL()), - new Tree[]{gen.mkType(pos, type)}, - new Tree[]{ - gen.mkStringLit(pos, unit.toString()), - gen.mkIntLit(pos, Position.line(pos)) - }); - } - - - public Type pairType( Type left, Type right ) { - return defs.TUPLE_TYPE(new Type[] { left, right } ); - } - - public Tree newPair( Tree left, Tree right ) { - return gen.New(gen.mkApplyTV( gen.mkPrimaryConstructorGlobalRef( pos, defs.TUPLE_CLASS[2]), - new Type[] { left.getType(), right.getType() }, - new Tree[] { left, right })); - - } - -} diff --git a/sources/scalac/transformer/matching/CollectVariableTraverser.java b/sources/scalac/transformer/matching/CollectVariableTraverser.java deleted file mode 100644 index d030733924..0000000000 --- a/sources/scalac/transformer/matching/CollectVariableTraverser.java +++ /dev/null @@ -1,45 +0,0 @@ -package scalac.transformer.matching ; - -import scalac.util.Name ; -import scalac.ast.Tree ; -import scalac.symtab.Symbol ; - - -import java.util.HashSet; - -public class CollectVariableTraverser extends VariableTraverser { - - protected HashSet nogeneratedVars; - protected HashSet vars; - /* - boolean isVariableName( Name name ) { - return ( name.toString().indexOf("$") == -1 ) - && super.isVariableName( name ); - } - */ - void handleVariableSymbol( Symbol sym ) { - vars.add( sym ); - if( sym.name.toString().indexOf("$") == -1 ) { - nogeneratedVars.add( sym ); - } - } - - public CollectVariableTraverser() { - this.vars = new HashSet(); - this.nogeneratedVars = new HashSet(); - } - - public boolean containsBinding( Tree pat ) { - - CollectVariableTraverser cvt = new CollectVariableTraverser(); - cvt.traverse( pat ); - return !cvt.nogeneratedVars.isEmpty(); - - } - - public HashSet collectVars( Tree pat ) { - traverse( pat ); - return vars; - } - -} diff --git a/sources/scalac/transformer/matching/FreshVariableTraverser.java b/sources/scalac/transformer/matching/FreshVariableTraverser.java deleted file mode 100644 index 04f9a8a684..0000000000 --- a/sources/scalac/transformer/matching/FreshVariableTraverser.java +++ /dev/null @@ -1,80 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - - -package scalac.transformer.matching; - -import scalac.ast.Traverser; - -import scalac.ast.Tree; -import Tree.Ident; -import Tree.Bind; - -import scalac.util.Name; -import scalac.util.FreshNameCreator; - -import scalac.symtab.*; - -import java.util.HashMap; -import java.util.Vector; - - -/** A tree traverser for handling fresh variables - * todo: access method instead of - * @author Burak Emir - * @version 1.0 - */ -class FreshVariableTraverser extends VariableTraverser { - - int pos; - Symbol owner; - FreshNameCreator fresh; - - /** - */ - private HashMap helpMap; - - /** - * @param pos - * @param owner - * @param fresh - */ - public FreshVariableTraverser(int pos, - Symbol owner, - FreshNameCreator fresh) { - this.pos = pos; - this.owner = owner; - this.fresh = fresh; - - helpMap = new HashMap(); - } - - public HashMap getHelpMap() { - return helpMap; - } - - /** - * @param sym - */ - void handleVariableSymbol(Symbol sym) { - Symbol helpVar = - owner.newVariable(pos, - 0, - fresh.newName(sym.name.toString())); - helpVar.setType(sym.type()); - - helpMap.put(sym, helpVar); - } - - public static HashMap getVars( Tree t, Symbol owner, FreshNameCreator fresh ) { - FreshVariableTraverser fvt = new FreshVariableTraverser( t.pos, owner, fresh ); - fvt.traverse( t ); - return fvt.helpMap; - } - -} diff --git a/sources/scalac/transformer/matching/NoSeqVariableTraverser.java b/sources/scalac/transformer/matching/NoSeqVariableTraverser.java deleted file mode 100644 index 9dc226ab2f..0000000000 --- a/sources/scalac/transformer/matching/NoSeqVariableTraverser.java +++ /dev/null @@ -1,42 +0,0 @@ -package scalac.transformer.matching ; - -import scalac.util.Name ; -import scalac.ast.Tree ; -import scalac.ast.Traverser ; -import scalac.symtab.Symbol ; - -import java.util.HashSet; - -class NoSeqVariableTraverser extends CollectVariableTraverser { - - public void traverse(Tree tree) { - switch (tree) { - case Sequence(_): - return ; - default: - super.traverse( tree ); - } - } - - public NoSeqVariableTraverser() { - super(); - } - - static HashSet varsNoSeq( Tree pat ) { - - NoSeqVariableTraverser nvt = new NoSeqVariableTraverser(); - nvt.traverse( pat ); - return nvt.vars; - - } - - static HashSet varsNoSeq( Tree[] pats ) { - - NoSeqVariableTraverser nvt = new NoSeqVariableTraverser(); - for(int i = 0; i < pats.length; i++) - nvt.traverse( pats[ i ] ); - return nvt.vars; - - } - -} diff --git a/sources/scalac/transformer/matching/PartialMatcher.java b/sources/scalac/transformer/matching/PartialMatcher.java deleted file mode 100644 index c7b5c9230e..0000000000 --- a/sources/scalac/transformer/matching/PartialMatcher.java +++ /dev/null @@ -1,53 +0,0 @@ -package scalac.transformer.matching; - -import scalac.ast.Tree; -import scalac.symtab.Symbol; -import scalac.symtab.Type; -import java.util.HashMap ; - -/** container. classes AlgebraicMatcher and SequenceMatcher get input and store their results in here. - * resembles the 'Memento' design pattern, could also be named 'Liaison' - */ -public class PartialMatcher { - - /** owner of the code we create (input) - */ - public Symbol owner; - - /** the selector value (input) - */ - public Tree selector; - - /** type of the result of the whole match (input) - */ - public Type resultType; - - /** tree representing the matcher (output) - */ - public Tree tree; - - public int pos; - - //public HashMap varMap; // needed in LeftTracerInScala - //public Tree[] stms; // needed in LeftTracerInScala - - public PartialMatcher(Symbol owner, - Tree root, - Type resultType) { - - assert( owner != null ) : "owner is null"; - assert owner != Symbol.NONE ; - this.owner = owner; - - assert root != null; - assert root.type != null; - this.selector = root; - - assert this.resultType != Type.NoType; - this.resultType = resultType; - - this.pos = root.pos; // for convenience only - - } - -} diff --git a/sources/scalac/transformer/matching/PatternNode.java b/sources/scalac/transformer/matching/PatternNode.java deleted file mode 100644 index 7f08e04eb9..0000000000 --- a/sources/scalac/transformer/matching/PatternNode.java +++ /dev/null @@ -1,198 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -** ** -** $Id$ -\* */ - -package scalac.transformer.matching; - -import scala.tools.util.Position; -import scalac.*; -import scalac.ast.*; -import scalac.atree.AConstant; -import scalac.symtab.*; -import scalac.typechecker.*; - - -/** Intermediate data structure for algebraic + pattern matcher - */ -public class PatternNode { - public int pos = Position.FIRSTPOS; - public Type type; - public PatternNode or; - public PatternNode and; - - public Type getType() { - return type; - } - - public case Header(Tree selector, Header next) ; - public case Body(Tree.ValDef[][] bound, Tree[] guard, Tree[] body); - public case DefaultPat(); - public case ConstrPat(Symbol casted); - public case ConstantPat(AConstant value); - public case VariablePat(Tree tree); - public case AltPat(Header subheader); - public case SequencePat(Symbol casted, int len); // only used in PatternMatcher - public case SeqContainerPat(Symbol casted, Tree seqpat); // in AlgebraicMatcher - - public PatternNode dup() { - PatternNode res; - switch (this) { - case Header(Tree selector, Header next): - res = Header(selector, next); - break; - case Body(Tree.ValDef[][] bound, Tree[] guard, Tree[] body): - res = Body(bound, guard, body); - break; - case DefaultPat(): - res = DefaultPat(); - break; - case ConstrPat(Symbol casted): - res = ConstrPat(casted); - break; - case SequencePat(Symbol casted, int len): - res = SequencePat(casted, len); - break; - case SeqContainerPat(Symbol casted, Tree seqpat): - res = SeqContainerPat(casted, seqpat); - break; - case ConstantPat(AConstant value): - res = ConstantPat(value); - break; - case VariablePat(Tree tree): - res = VariablePat(tree); - break; - case AltPat(Header subheader): - res = AltPat(subheader); - break; - default: - throw new ApplicationError(); - } - res.pos = pos; - res.type = type; - res.or = or; - res.and = and; - return res; - } - - public Symbol symbol() { - switch (this) { - case ConstrPat(Symbol casted): - return casted; - case SequencePat(Symbol casted, _): - return casted; - case SeqContainerPat(Symbol casted, _): - return casted; - default: - return Symbol.NONE; - } - } - - public PatternNode next() { - switch (this) { - case Header(_, Header next): - return next; - default: - return null; - } - } - - public boolean isDefaultPat() { - switch(this) { - case DefaultPat(): - return true; - default: - return false; - } - } - - /** returns true if - * p and q are equal (constructor | sequence) type tests, or - * "q matches" => "p matches" - */ - public boolean isSameAs(PatternNode q) { - switch( this ) { - case ConstrPat(_): - switch (q) { - case ConstrPat(_): - return q.type.isSameAs(this.type); - } - return false; - case SequencePat(_, int plen): - switch (q) { - case SequencePat(_, int qlen): - return (plen == qlen) && q.type.isSameAs(this.type); - } - return false; - default: - return subsumes(q); - } - } - - /** returns true if "q matches" => "p matches" - */ - public boolean subsumes(PatternNode q) { - switch (this) { - case DefaultPat(): - switch (q) { - case DefaultPat(): - return true; - } - return false; - case ConstrPat(_): - switch (q) { - case ConstrPat(_): - return q.type.isSubType(this.type); - } - return false; - case SequencePat(_, int plen): - switch (q) { - case SequencePat(_, int qlen): - return (plen == qlen) && q.type.isSubType(this.type); - } - return false; - case ConstantPat(AConstant pval): - switch (q) { - case ConstantPat(AConstant qval): - return pval.equals(qval); - } - return false; - case VariablePat(Tree tree): - switch (q) { - case VariablePat(Tree other): - return (tree.symbol() != null) && - (!tree.symbol().isNone()) && - (!tree.symbol().isError()) && - (tree.symbol() == other.symbol()); - } - return false; - } - return false; - } - - public String toString() { - switch (this) { - case Header(Tree selector, Header next): - return "Header(" + selector + ")"; - case Body( _, _, _ ): - return "Body"; - case DefaultPat(): - return "DefaultPat"; - case ConstrPat(Symbol casted): - return "ConstrPat(" + casted + ")"; - case SequencePat(Symbol casted, int len): - return "SequencePat(" + casted + ", " + len + "...)"; - case SeqContainerPat(Symbol casted, Tree seqpat): - return "SeqContainerPat(" + casted + ", " + seqpat + ")"; - case ConstantPat(AConstant value): - return "ConstantPat(" + value + ")"; - case VariablePat(Tree tree): - return "VariablePat"; - default: - return ""; - } - } -} diff --git a/sources/scalac/transformer/matching/PatternNodeCreator.java b/sources/scalac/transformer/matching/PatternNodeCreator.java deleted file mode 100644 index 68f5c97639..0000000000 --- a/sources/scalac/transformer/matching/PatternNodeCreator.java +++ /dev/null @@ -1,113 +0,0 @@ -package scalac.transformer.matching; - -import scala.tools.util.Position; - -import scalac.*; -import scalac.ast.*; -import scalac.atree.AConstant; -import scalac.util.*; -import scalac.symtab.*; -import PatternNode.*; -import Tree.*; - -import java.util.Vector ; - -/** PatternNode factory. - * we inherit the globals from PatternTool. - */ - -public class PatternNodeCreator extends PatternTool { - - /** the owner of the variable symbols that might be created */ - Symbol owner; - - public PatternNodeCreator(CompilationUnit unit, Symbol owner) { - super(unit); - assert owner != null; - this.owner = owner; - } - - public SequencePat SequencePat(int pos, Type type, int len) { - Symbol sym = newVar(Position.FIRSTPOS, type); - SequencePat node = new SequencePat(sym, len); - node.pos = pos; - node.type = type; - return node; - } - - public SeqContainerPat SeqContainerPat(int pos, Type type, Tree seqpat) { - Symbol sym = newVar(Position.NOPOS, type); - SeqContainerPat node = new SeqContainerPat(sym, seqpat); - node.pos = pos; - node.type = type; - return node; - } - - public DefaultPat DefaultPat(int pos, Type type) { - DefaultPat node = new DefaultPat(); - node.pos = pos; - node.type = type; - return node; - } - - public ConstrPat ConstrPat(int pos, Type type) { - ConstrPat node = new ConstrPat(newVar(pos, type)); - node.pos = pos; - node.type = type; - return node; - } - - public ConstantPat ConstantPat(int pos, Type type, AConstant value) { - ConstantPat node = new ConstantPat( value ); - node.pos = pos; - node.type = type; - return node; - } - - public VariablePat VariablePat(int pos, Tree tree) { - VariablePat node = new VariablePat( tree ); - node.pos = pos; - node.type = tree.type; - return node; - } - - public AltPat AltPat(int pos, Header header) { - AltPat node = new AltPat(header); - node.pos = pos; - node.type = header.type; - return node; - } - - // factories - - public Header Header(int pos, Type type, Tree selector) { - Header node = new Header(selector, null); - node.pos = pos; - node.type = type; - return node; - } - - public Body Body(int pos) { - Body node = new Body(new ValDef[0][], new Tree[0], new Tree[0]); - node.pos = pos; - return node; - } - - public Body Body(int pos, ValDef[] bound, Tree guard, Tree body) { - Body node = new Body(new ValDef[][]{bound}, new Tree[]{guard}, new Tree[]{body}); - node.pos = pos; - return node; - } - - public Symbol newVar(int pos, Name name, Type type) { - Symbol sym = owner.newVariable(pos, 0, name); - sym.setType(type); - //System.out.println("PatternNodeCreator::newVar creates symbol "+sym); - //System.out.println("owner: "+sym.owner()); - return sym; - } - - public Symbol newVar(int pos, Type type) { - return newVar(pos, fresh.newName("temp"), type); - } -} diff --git a/sources/scalac/transformer/matching/PatternTool.java b/sources/scalac/transformer/matching/PatternTool.java deleted file mode 100644 index e5f9ff5cc7..0000000000 --- a/sources/scalac/transformer/matching/PatternTool.java +++ /dev/null @@ -1,48 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -** ** -** $Id$ -\* */ - -package scalac.transformer.matching; - - -import scalac.CompilationUnit; -import scalac.ast.TreeGen; -import scalac.util.*; -import scalac.symtab.*; - -/** this class takes care of tedious stuff which has nothing to do with - * matching - */ -public abstract class PatternTool { - - public static final Name RESULT_N = Name.fromString("$result"); - - /** the current compilation unit - */ - public final CompilationUnit unit; - - /** the global fresh name creator - */ - public final FreshNameCreator fresh; - - /** the global definitions component - */ - public final Definitions defs; - - /** the global tree generation component - */ - public final TreeGen gen; - - // constructor - public PatternTool( CompilationUnit unit ) { - this.unit = unit; - this.fresh = unit.fresh; - this.gen = unit.global.treeGen; - this.defs = unit.global.definitions; - } - -} // class PatternTool diff --git a/sources/scalac/transformer/matching/VariableTraverser.java b/sources/scalac/transformer/matching/VariableTraverser.java deleted file mode 100644 index d03e2a05e2..0000000000 --- a/sources/scalac/transformer/matching/VariableTraverser.java +++ /dev/null @@ -1,61 +0,0 @@ -package scalac.transformer.matching ; - - -import scalac.ast.Tree; -import scalac.util.Name; -import scalac.symtab.Symbol ; -import scalac.ast.Traverser ; - -import Tree.Ident; -import Tree.Bind; - - -abstract class VariableTraverser extends Traverser { - - boolean isVariableName( Name name ) { - return ( name.isVariable() ) && ( name != Name.fromString("_") ) ; - - } - - boolean isVariableSymbol( Symbol sym ) { - return ( sym != null )&&( !sym.isPrimaryConstructor() ); - } - - abstract void handleVariableSymbol( Symbol sym ) ; - - public VariableTraverser() { - super(); - } - - - public void traverse(Tree tree) { - switch (tree) { - case Ident(Name name): - Symbol sym; - - if( isVariableName( name ) - && isVariableSymbol( sym = tree.symbol() ) ) - handleVariableSymbol( sym ); - - return; - - case Bind(Name name, Tree subtree): - Symbol sym; - - if( isVariableName( name ) - && isVariableSymbol( sym = tree.symbol() )) - handleVariableSymbol( sym ); - - traverse( subtree ); - - return; - - case Select(_,_): - return; - default: - super.traverse( tree ); - } - } - - -} -- cgit v1.2.3