KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > expr > ChainLambdas


1 package gnu.expr;
2
3 /** Sets up the firstChild/nextSibling links of each LambdaExp.
4  * Setup 'outer' links of ScopeExp and its sub-classes.
5  * Also generates a class name for each ClassExp and registers each class.
6  * Also, if lambda is bound to a unique declaration, make that its name.
7  */

8
9 public class ChainLambdas extends ExpWalker
10 {
11   ScopeExp currentScope;
12
13   public static void chainLambdas (Expression exp, Compilation comp)
14   {
15     ChainLambdas walker = new ChainLambdas();
16     walker.setContext(comp);
17     walker.walk(exp);
18   }
19
20   protected Expression walkScopeExp (ScopeExp exp)
21   {
22     ScopeExp saveScope = currentScope;
23     try
24       {
25     exp.outer = currentScope;
26     currentScope = exp;
27     exp.walkChildren(this);
28         exp.setIndexes();
29         if (exp.mustCompile())
30           comp.mustCompileHere();
31     return exp;
32       }
33     finally
34       {
35     currentScope = saveScope;
36       }
37   }
38
39   protected Expression walkLambdaExp (LambdaExp exp)
40   {
41     LambdaExp parent = currentLambda;
42     if (parent != null && ! (parent instanceof ClassExp))
43       {
44     exp.nextSibling = parent.firstChild;
45     parent.firstChild = exp;
46       }
47
48     ScopeExp saveScope = currentScope;
49     try
50       {
51     exp.outer = currentScope;
52         exp.firstChild = null;
53     currentScope = exp;
54     exp.walkChildrenOnly(this);
55       }
56     finally
57       {
58     currentScope = saveScope;
59       }
60     exp.walkProperties(this);
61
62     // Put list of children in proper order.
63
LambdaExp prev = null, child = exp.firstChild;
64     while (child != null)
65       {
66     LambdaExp next = child.nextSibling;
67     child.nextSibling = prev;
68     prev = child;
69     child = next;
70       }
71     exp.firstChild = prev;
72
73     if (exp.getName() == null && exp.nameDecl != null)
74       exp.setName(exp.nameDecl.getName());
75     exp.setIndexes();
76     if (exp.mustCompile())
77       comp.mustCompileHere();
78     return exp;
79   }
80
81   protected Expression walkClassExp (ClassExp exp)
82   {
83     LambdaExp parent = currentLambda;
84     if (parent != null && ! (parent instanceof ClassExp))
85       {
86     exp.nextSibling = parent.firstChild;
87     parent.firstChild = exp;
88       }
89
90     walkScopeExp(exp);
91
92     return exp;
93   }
94 }
95
Popular Tags