| 1 |
/******************************************************************************* |
|---|
| 2 |
Copyright 2008 Sun Microsystems, Inc., |
|---|
| 3 |
4150 Network Circle, Santa Clara, California 95054, U.S.A. |
|---|
| 4 |
All rights reserved. |
|---|
| 5 |
|
|---|
| 6 |
U.S. Government Rights - Commercial software. |
|---|
| 7 |
Government users are subject to the Sun Microsystems, Inc. standard |
|---|
| 8 |
license agreement and applicable provisions of the FAR and its supplements. |
|---|
| 9 |
|
|---|
| 10 |
Use is subject to license terms. |
|---|
| 11 |
|
|---|
| 12 |
This distribution may include materials developed by third parties. |
|---|
| 13 |
|
|---|
| 14 |
Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered |
|---|
| 15 |
trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|---|
| 16 |
******************************************************************************/ |
|---|
| 17 |
|
|---|
| 18 |
package com.sun.fortress.interpreter.evaluator; |
|---|
| 19 |
|
|---|
| 20 |
import java.util.List; |
|---|
| 21 |
import java.util.Set; |
|---|
| 22 |
|
|---|
| 23 |
import com.sun.fortress.interpreter.evaluator.types.FType; |
|---|
| 24 |
import com.sun.fortress.interpreter.evaluator.values.FValue; |
|---|
| 25 |
import com.sun.fortress.interpreter.evaluator.values.Fcn; |
|---|
| 26 |
import com.sun.fortress.interpreter.evaluator.values.GenericMethod; |
|---|
| 27 |
import com.sun.fortress.interpreter.evaluator.values.TraitMethod; |
|---|
| 28 |
import com.sun.fortress.interpreter.evaluator.values.Simple_fcn; |
|---|
| 29 |
import com.sun.fortress.nodes.FnDef; |
|---|
| 30 |
import com.sun.fortress.nodes.FnAbsDeclOrDecl; |
|---|
| 31 |
import com.sun.fortress.nodes.Id; |
|---|
| 32 |
import com.sun.fortress.nodes.LValueBind; |
|---|
| 33 |
import com.sun.fortress.nodes.StaticParam; |
|---|
| 34 |
import com.sun.fortress.nodes.VarDecl; |
|---|
| 35 |
import com.sun.fortress.nodes_util.Applicable; |
|---|
| 36 |
import com.sun.fortress.nodes_util.NodeUtil; |
|---|
| 37 |
import com.sun.fortress.useful.Voidoid; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
public class BuildTraitEnvironment extends BuildEnvironments { |
|---|
| 41 |
|
|---|
| 42 |
Set<String> fields; |
|---|
| 43 |
|
|---|
| 44 |
Environment methodEnvironment; |
|---|
| 45 |
|
|---|
| 46 |
FType definer; |
|---|
| 47 |
|
|---|
| 48 |
public BuildTraitEnvironment(Environment within, Environment methodEnvironment, |
|---|
| 49 |
FType definer, Set<String> fields) { |
|---|
| 50 |
super(within); |
|---|
| 51 |
this.definer = definer; |
|---|
| 52 |
this.fields = fields; |
|---|
| 53 |
this.methodEnvironment = methodEnvironment; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
protected Simple_fcn newClosure(Environment e, Applicable x) { |
|---|
| 57 |
return new TraitMethod(containing, methodEnvironment, x, definer); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
protected GenericMethod newGenericClosure(Environment e, FnAbsDeclOrDecl x) { |
|---|
| 61 |
return new GenericMethod(containing, methodEnvironment, x, definer, true); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
/** |
|---|
| 65 |
* Put a value, perhaps unconditionally depending on subtype's choice |
|---|
| 66 |
* |
|---|
| 67 |
* @param e |
|---|
| 68 |
* @param name |
|---|
| 69 |
* @param value |
|---|
| 70 |
* @param ft |
|---|
| 71 |
*/ |
|---|
| 72 |
protected void putValue(Environment e, String name, FValue value, FType ft) { |
|---|
| 73 |
e.putValueRaw(name, value, ft); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
/** |
|---|
| 77 |
* Put a value, perhaps unconditionally depending on subtype's choice |
|---|
| 78 |
*/ |
|---|
| 79 |
protected void putValue(Environment e, String name, FValue value) { |
|---|
| 80 |
e.putValueRaw(name, value); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
public Boolean forVarDecl(VarDecl x) { |
|---|
| 84 |
if (fields != null) { |
|---|
| 85 |
List<LValueBind> lhs = x.getLhs(); |
|---|
| 86 |
for (LValueBind lvb : lhs) { |
|---|
| 87 |
Id name = lvb.getName(); |
|---|
| 88 |
String s = NodeUtil.nameString(name); |
|---|
| 89 |
fields.add(s); |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
return null; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
protected void forFnDef3(FnDef x) { |
|---|
| 96 |
List<StaticParam> staticParams = x.getStaticParams(); |
|---|
| 97 |
String fname = NodeUtil.nameAsMethod(x); |
|---|
| 98 |
if (!staticParams.isEmpty()) { |
|---|
| 99 |
// GENERIC |
|---|
| 100 |
// This blows up because the type is not instantiated. |
|---|
| 101 |
// { |
|---|
| 102 |
// // Why isn't this the right thing to do? |
|---|
| 103 |
// // FGenericFunction is (currently) excluded from this treatment. |
|---|
| 104 |
// FValue fcn = containing.getValue(fname); |
|---|
| 105 |
// |
|---|
| 106 |
// if (fcn instanceof OverloadedFunction) { |
|---|
| 107 |
// OverloadedFunction og = (OverloadedFunction) fcn; |
|---|
| 108 |
// og.finishInitializing(); |
|---|
| 109 |
// |
|---|
| 110 |
// } |
|---|
| 111 |
// } |
|---|
| 112 |
|
|---|
| 113 |
} else { |
|---|
| 114 |
// NOT GENERIC |
|---|
| 115 |
{ |
|---|
| 116 |
Fcn fcn = (Fcn) containing.getValue(fname); |
|---|
| 117 |
fcn.finishInitializing(); |
|---|
| 118 |
} |
|---|
| 119 |
} |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
} |
|---|