01: package kawa.lang;
02:
03: import gnu.expr.*;
04: import java.io.*;
05:
06: /** A scope created when expanding a SyntaxTemplate.
07: * This is used to ensure proper "hygiene". */
08:
09: public class TemplateScope extends LetExp implements Externalizable {
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: super (null);
21: }
22:
23: public TemplateScope(ScopeExp outer) {
24: super (null);
25: this .outer = outer;
26: }
27:
28: public static TemplateScope make() {
29: return make((Translator) Compilation.getCurrent());
30: }
31:
32: public static TemplateScope make(Translator tr) {
33: TemplateScope templateScope = new TemplateScope();
34: Syntax curSyntax = tr.getCurrentSyntax();
35: if (curSyntax instanceof Macro) {
36: templateScope.outer = ((Macro) curSyntax)
37: .getCapturedScope();
38: templateScope.macroContext = tr.macroContext;
39: }
40: return templateScope;
41: }
42:
43: public void writeExternal(ObjectOutput out) throws IOException {
44: out.writeObject(outer);
45: }
46:
47: public void readExternal(ObjectInput in) throws IOException,
48: ClassNotFoundException {
49: outer = (ScopeExp) in.readObject();
50: }
51: }
|