| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.compiler.index; |
|---|
| 19 | |
|---|
| 20 | import java.util.ArrayList; |
|---|
| 21 | import java.util.Collections; |
|---|
| 22 | import java.util.List; |
|---|
| 23 | |
|---|
| 24 | import com.sun.fortress.nodes.BaseType; |
|---|
| 25 | import com.sun.fortress.nodes.Expr; |
|---|
| 26 | import com.sun.fortress.nodes.Id; |
|---|
| 27 | import com.sun.fortress.nodes.IdOrOpOrAnonymousName; |
|---|
| 28 | import com.sun.fortress.nodes.NodeUpdateVisitor; |
|---|
| 29 | import com.sun.fortress.nodes.Param; |
|---|
| 30 | import com.sun.fortress.nodes.StaticArg; |
|---|
| 31 | import com.sun.fortress.nodes.StaticParam; |
|---|
| 32 | import com.sun.fortress.nodes.Type; |
|---|
| 33 | import com.sun.fortress.nodes.WhereClause; |
|---|
| 34 | import com.sun.fortress.nodes_util.NodeUtil; |
|---|
| 35 | import com.sun.fortress.nodes_util.Span; |
|---|
| 36 | import com.sun.fortress.useful.NI; |
|---|
| 37 | |
|---|
| 38 | import edu.rice.cs.plt.collect.CollectUtil; |
|---|
| 39 | import edu.rice.cs.plt.iter.IterUtil; |
|---|
| 40 | import edu.rice.cs.plt.lambda.Lambda; |
|---|
| 41 | import edu.rice.cs.plt.lambda.Thunk; |
|---|
| 42 | import edu.rice.cs.plt.tuple.Option; |
|---|
| 43 | |
|---|
| 44 | public class Constructor extends Function { |
|---|
| 45 | |
|---|
| 46 | private final Id _declaringTrait; |
|---|
| 47 | private final List<StaticParam> _staticParams; |
|---|
| 48 | private final Option<List<Param>> _params; |
|---|
| 49 | private final Option<List<BaseType>> _throwsClause; |
|---|
| 50 | private final Option<WhereClause> _where; |
|---|
| 51 | |
|---|
| 52 | public Constructor(Id declaringTrait, |
|---|
| 53 | List<StaticParam> staticParams, |
|---|
| 54 | Option<List<Param>> params, |
|---|
| 55 | Option<List<BaseType>> throwsClause, |
|---|
| 56 | Option<WhereClause> where) |
|---|
| 57 | { |
|---|
| 58 | _declaringTrait = declaringTrait; |
|---|
| 59 | _staticParams = staticParams; |
|---|
| 60 | _params = params; |
|---|
| 61 | _throwsClause = throwsClause; |
|---|
| 62 | _where = where; |
|---|
| 63 | putThunk(new Thunk<Option<Type>>() { |
|---|
| 64 | @Override public Option<Type> value() { |
|---|
| 65 | return NI.nyi(); |
|---|
| 66 | } |
|---|
| 67 | }); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | @Override |
|---|
| 71 | public Span getSpan() { return NodeUtil.getSpan(_declaringTrait); } |
|---|
| 72 | |
|---|
| 73 | public Id declaringTrait() { return _declaringTrait; } |
|---|
| 74 | |
|---|
| 75 | protected String mandatoryToString() { |
|---|
| 76 | return "constructor " + declaringTrait().toString(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | @Override |
|---|
| 80 | protected IdOrOpOrAnonymousName mandatoryToUndecoratedName() { |
|---|
| 81 | |
|---|
| 82 | return declaringTrait(); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | public Option<WhereClause> where() { return _where; } |
|---|
| 91 | |
|---|
| 92 | @Override |
|---|
| 93 | public Option<Expr> body() { |
|---|
| 94 | return Option.none(); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | @Override |
|---|
| 98 | public List<Param> parameters() { |
|---|
| 99 | if( _params.isNone() ) |
|---|
| 100 | return Collections.emptyList(); |
|---|
| 101 | else |
|---|
| 102 | return Collections.unmodifiableList(_params.unwrap()); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | @Override |
|---|
| 106 | public List<StaticParam> staticParameters() { |
|---|
| 107 | return Collections.unmodifiableList(_staticParams); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | @Override |
|---|
| 111 | public List<BaseType> thrownTypes() { |
|---|
| 112 | if( _throwsClause.isNone() ) |
|---|
| 113 | return Collections.emptyList(); |
|---|
| 114 | else |
|---|
| 115 | return Collections.unmodifiableList(_throwsClause.unwrap()); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | @Override |
|---|
| 119 | public Functional instantiate(List<StaticParam> params, List<StaticArg> args) { |
|---|
| 120 | |
|---|
| 121 | return NI.nyi(); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | @Override |
|---|
| 125 | public Functional acceptNodeUpdateVisitor(final NodeUpdateVisitor v) { |
|---|
| 126 | |
|---|
| 127 | Option<List<Param>> new_params; |
|---|
| 128 | if( _params.isSome() ) { |
|---|
| 129 | List<Param> new_params_ = new ArrayList<Param>(_params.unwrap().size()); |
|---|
| 130 | for( Param p : _params.unwrap() ) { |
|---|
| 131 | new_params_.add((Param)p.accept(v)); |
|---|
| 132 | } |
|---|
| 133 | new_params = Option.some(new_params_); |
|---|
| 134 | } |
|---|
| 135 | else { |
|---|
| 136 | new_params = Option.none(); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | Option<List<BaseType>> new_throws; |
|---|
| 140 | if( _throwsClause.isSome() ) { |
|---|
| 141 | List<BaseType> new_throws_ = new ArrayList<BaseType>(_throwsClause.unwrap().size()); |
|---|
| 142 | for( BaseType p : _throwsClause.unwrap() ) { |
|---|
| 143 | new_throws_.add((BaseType)p.accept(v)); |
|---|
| 144 | } |
|---|
| 145 | new_throws = Option.some(new_throws_); |
|---|
| 146 | } |
|---|
| 147 | else { |
|---|
| 148 | new_throws = Option.none(); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | List<StaticParam> new_static_params = |
|---|
| 152 | CollectUtil.makeList(IterUtil.map(_staticParams, new Lambda<StaticParam,StaticParam>(){ |
|---|
| 153 | public StaticParam value(StaticParam arg0) { |
|---|
| 154 | return (StaticParam)arg0.accept(v); |
|---|
| 155 | }})); |
|---|
| 156 | |
|---|
| 157 | Option<WhereClause> new_where; |
|---|
| 158 | if ( _where.isSome() ) { |
|---|
| 159 | new_where = Option.some((WhereClause)_where.unwrap().accept(v)); |
|---|
| 160 | } else { |
|---|
| 161 | new_where = Option.<WhereClause>none(); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | return |
|---|
| 165 | new Constructor(_declaringTrait, |
|---|
| 166 | new_static_params, |
|---|
| 167 | new_params, |
|---|
| 168 | new_throws, |
|---|
| 169 | new_where); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | } |
|---|