001: package gnu.expr;
002:
003: /** Class for doing a tree-walk over an Expression tree. */
004:
005: public class ExpWalker {
006: protected Expression walkExpression(Expression exp) {
007: exp.walkChildren(this );
008: return exp;
009: }
010:
011: protected Expression walkApplyExp(ApplyExp exp) {
012: return walkExpression(exp);
013: }
014:
015: protected Expression walkIfExp(IfExp exp) {
016: return walkExpression(exp);
017: }
018:
019: protected Expression walkScopeExp(ScopeExp exp) {
020: return walkExpression(exp);
021: }
022:
023: protected Expression walkLetExp(LetExp exp) {
024: return walkScopeExp(exp);
025: }
026:
027: protected Expression walkLambdaExp(LambdaExp exp) {
028: return walkScopeExp(exp);
029: }
030:
031: protected Expression walkClassExp(ClassExp exp) {
032: return walkLambdaExp(exp);
033: }
034:
035: protected Expression walkObjectExp(ObjectExp exp) {
036: return walkClassExp(exp);
037: }
038:
039: protected Expression walkModuleExp(ModuleExp exp) {
040: return walkLambdaExp(exp);
041: }
042:
043: protected Expression walkSetExp(SetExp exp) {
044: return walkExpression(exp);
045: }
046:
047: protected Expression walkIncrementExp(IncrementExp exp) {
048: return walkExpression(exp);
049: }
050:
051: //protected Expression walkSwitchExp (SwitchExp exp) { return walkExpression(exp); }
052: protected Expression walkTryExp(TryExp exp) {
053: return walkExpression(exp);
054: }
055:
056: protected Expression walkBeginExp(BeginExp exp) {
057: return walkExpression(exp);
058: }
059:
060: protected Expression walkQuoteExp(QuoteExp exp) {
061: return walkExpression(exp);
062: }
063:
064: protected Expression walkReferenceExp(ReferenceExp exp) {
065: return walkExpression(exp);
066: }
067:
068: protected Expression walkThisExp(ThisExp exp) {
069: return walkReferenceExp(exp);
070: }
071:
072: protected Expression walkSynchronizedExp(SynchronizedExp exp) {
073: return walkExpression(exp);
074: }
075:
076: protected Expression walkBlockExp(BlockExp exp) {
077: return walkExpression(exp);
078: }
079:
080: protected Expression walkExitExp(ExitExp exp) {
081: return walkExpression(exp);
082: }
083:
084: protected Expression walkFluidLetExp(FluidLetExp exp) {
085: return walkLetExp(exp);
086: }
087:
088: LambdaExp currentLambda = null;
089:
090: /** If exitValue is set to non-null, the walk stops. */
091: Object exitValue = null;
092:
093: public final LambdaExp getCurrentLambda() {
094: return currentLambda;
095: }
096:
097: public Expression[] walkExps(Expression[] exps) {
098: return walkExps(exps, exps.length);
099: }
100:
101: public Expression[] walkExps(Expression[] exps, int n) {
102: for (int i = 0; i < n && exitValue == null; i++)
103: exps[i] = (Expression) exps[i].walk(this );
104: return exps;
105: }
106:
107: public void walkDefaultArgs(LambdaExp exp) {
108: if (exp.defaultArgs != null)
109: exp.defaultArgs = walkExps(exp.defaultArgs);
110: }
111: }
|