KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > lang > TemplateScope


1 package kawa.lang;
2 import gnu.expr.*;
3 import java.io.*;
4
5 /** A scope created when expanding a SyntaxTemplate.
6  * This is used to ensure proper "hygiene". */

7
8 public class TemplateScope extends LetExp implements Externalizable
9 {
10   /** The module instance containing the defining macro.
11    * If we're expanding a macro imported from some external module,
12    * the macro's template(s) may expand to references to declarations in
13    * that external module. If the module is non-static, we may need a
14    * context instance to access those declarations; we inherit the context
15    * instance from the declaration bound to the imported macro.
16    * This is used to setContextDecl() of such references. */

17   Declaration macroContext;
18
19   public TemplateScope ()
20   {
21     super(null);
22   }
23
24   public TemplateScope (ScopeExp outer)
25   {
26     super(null);
27     this.outer = outer;
28   }
29
30   public static TemplateScope make ()
31   {
32     return make((Translator) Compilation.getCurrent());
33   }
34
35   public static TemplateScope make (Translator tr)
36   {
37     TemplateScope templateScope = new TemplateScope();
38     Syntax curSyntax = tr.getCurrentSyntax();
39     if (curSyntax instanceof Macro)
40       {
41         templateScope.outer = ((Macro) curSyntax).getCapturedScope();
42         templateScope.macroContext = tr.macroContext;
43       }
44     return templateScope;
45   }
46
47   public void writeExternal(ObjectOutput out) throws IOException
48   {
49     out.writeObject(outer);
50   }
51
52   public void readExternal(ObjectInput in)
53     throws IOException, ClassNotFoundException JavaDoc
54   {
55     outer = (ScopeExp) in.readObject();
56   }
57 }
58
Popular Tags