| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.interpreter.evaluator; |
|---|
| 19 | |
|---|
| 20 | import com.sun.fortress.interpreter.evaluator.types.FType; |
|---|
| 21 | import com.sun.fortress.interpreter.evaluator.values.*; |
|---|
| 22 | import com.sun.fortress.nodes.*; |
|---|
| 23 | import com.sun.fortress.nodes_util.NodeUtil; |
|---|
| 24 | |
|---|
| 25 | import java.util.List; |
|---|
| 26 | import java.util.Set; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | public class BuildTraitEnvironment extends BuildEnvironments { |
|---|
| 30 | |
|---|
| 31 | Set<String> fields; |
|---|
| 32 | |
|---|
| 33 | Environment methodEnvironment; |
|---|
| 34 | |
|---|
| 35 | FType definer; |
|---|
| 36 | |
|---|
| 37 | public BuildTraitEnvironment(Environment within, Environment methodEnvironment, FType definer, Set<String> fields) { |
|---|
| 38 | super(within); |
|---|
| 39 | this.definer = definer; |
|---|
| 40 | this.fields = fields; |
|---|
| 41 | this.methodEnvironment = methodEnvironment; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | protected Simple_fcn newClosure(Environment e, Applicable x) { |
|---|
| 45 | return new TraitMethod(containing, methodEnvironment, x, definer); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | protected GenericMethod newGenericClosure(Environment e, FnDecl x) { |
|---|
| 49 | return new GenericMethod(containing, methodEnvironment, x, definer, true); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | protected void putValue(Environment e, String name, FValue value, FType ft) { |
|---|
| 61 | e.putValueRaw(name, value, ft); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | protected void putValue(Environment e, String name, FValue value) { |
|---|
| 68 | e.putValueRaw(name, value); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public Boolean forVarDecl(VarDecl x) { |
|---|
| 72 | if (fields != null) { |
|---|
| 73 | List<LValue> lhs = x.getLhs(); |
|---|
| 74 | for (LValue lvb : lhs) { |
|---|
| 75 | Id name = lvb.getName(); |
|---|
| 76 | String s = NodeUtil.nameString(name); |
|---|
| 77 | fields.add(s); |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | return null; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | @Override |
|---|
| 89 | public Boolean forFnDecl(FnDecl x) { |
|---|
| 90 | |
|---|
| 91 | switch (getPass()) { |
|---|
| 92 | case 1: |
|---|
| 93 | forFnDecl1(x); |
|---|
| 94 | break; |
|---|
| 95 | case 2: |
|---|
| 96 | forFnDecl2(x); |
|---|
| 97 | break; |
|---|
| 98 | case 3: |
|---|
| 99 | forFnDecl3(x); |
|---|
| 100 | break; |
|---|
| 101 | case 4: |
|---|
| 102 | forFnDecl4(x); |
|---|
| 103 | break; |
|---|
| 104 | } |
|---|
| 105 | return null; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | private void forFnDecl1(FnDecl x) { |
|---|
| 109 | List<StaticParam> optStaticParams = NodeUtil.getStaticParams(x); |
|---|
| 110 | String fname = NodeUtil.nameAsMethod(x); |
|---|
| 111 | |
|---|
| 112 | if (!optStaticParams.isEmpty()) { |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | FValue cl = newGenericClosure(containing, x); |
|---|
| 117 | |
|---|
| 118 | bindInto.putValue(fname, cl); |
|---|
| 119 | |
|---|
| 120 | } else { |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | Simple_fcn cl = newClosure(containing, x); |
|---|
| 124 | |
|---|
| 125 | bindInto.putValue(fname, cl); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | private void forFnDecl2(FnDecl x) { |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | protected void forFnDecl3(FnDecl x) { |
|---|
| 133 | List<StaticParam> staticParams = NodeUtil.getStaticParams(x); |
|---|
| 134 | String fname = NodeUtil.nameAsMethod(x); |
|---|
| 135 | if (!staticParams.isEmpty()) { |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | } else { |
|---|
| 151 | |
|---|
| 152 | { |
|---|
| 153 | Fcn fcn = (Fcn) containing.getLeafValue(fname); |
|---|
| 154 | fcn.finishInitializing(); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | private void forFnDecl4(FnDecl x) { |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | } |
|---|