1 package gnu.expr;
2 import gnu.bytecode.*;
3 
4 /** An expression that evaluated to an instance of an anonymous class.
5  * It's conceptually questionable that this inherits from ClassExp
6  * - it should perhaps inherit from ApplyExp.
7  */
8 
9 public class ObjectExp extends ClassExp
10 {
ObjectExp()11   public ObjectExp ()
12   {
13     super(true, new ClassType());
14   }
15 
calculateType()16   protected Type calculateType() { return compiledType; }
17 
visit(ExpVisitor<R,D> visitor, D d)18   protected <R,D> R visit (ExpVisitor<R,D> visitor, D d)
19   {
20     return visitor.visitObjectExp(this, d);
21   }
22 
compile(Compilation comp, Target target)23   public void compile (Compilation comp, Target target)
24   {
25     CodeAttr code = comp.getCode();
26     code.emitNew(compiledType);
27     code.emitDup(1);
28     Method init = Compilation.getConstructor(compiledType, this);
29     if (closureEnvField != null)
30       {
31 	LambdaExp caller = outerLambda();
32         if (! comp.usingCallContext())
33            getOwningLambda().loadHeapFrame(comp);
34         else {
35             Variable closureEnv = caller.heapFrame != null ? caller.heapFrame
36                 : caller.closureEnv;
37             if (closureEnv == null)
38                 code.emitPushThis();
39             else
40                 code.emitLoad(closureEnv);
41         }
42       }
43     code.emitInvokeSpecial(init);
44 
45     target.compileFromStack(comp, getCompiledClassType(comp));
46   }
47 
48 }
49