root/trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Constructor.java @ 3915

Revision 3915, 5.3 KB (checked in by jrhil47, 5 months ago)

[index] Changed all Functional indices to store a thunk to get the return types, since during type checking the return types might need to be lazily evaluated. Also changed Functional indices to yield an Option for return types.
[type checker] Started implementing extraction of bindings from nodes for type environments.

Line 
1/*******************************************************************************
2    Copyright 2009 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
18package com.sun.fortress.compiler.index;
19
20import java.util.ArrayList;
21import java.util.Collections;
22import java.util.List;
23
24import com.sun.fortress.nodes.BaseType;
25import com.sun.fortress.nodes.Expr;
26import com.sun.fortress.nodes.Id;
27import com.sun.fortress.nodes.IdOrOpOrAnonymousName;
28import com.sun.fortress.nodes.NodeUpdateVisitor;
29import com.sun.fortress.nodes.Param;
30import com.sun.fortress.nodes.StaticArg;
31import com.sun.fortress.nodes.StaticParam;
32import com.sun.fortress.nodes.Type;
33import com.sun.fortress.nodes.WhereClause;
34import com.sun.fortress.nodes_util.NodeUtil;
35import com.sun.fortress.nodes_util.Span;
36import com.sun.fortress.useful.NI;
37
38import edu.rice.cs.plt.collect.CollectUtil;
39import edu.rice.cs.plt.iter.IterUtil;
40import edu.rice.cs.plt.lambda.Lambda;
41import edu.rice.cs.plt.lambda.Thunk;
42import edu.rice.cs.plt.tuple.Option;
43
44public 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        // This choice is not tested yet, it could well be the wrong one.
82        return declaringTrait();
83    }
84
85
86   
87//    public List<StaticParam> staticParams() { return _staticParams; }
88//    public Option<List<Param>> params() { return _params; }
89//    public Option<List<BaseType>> throwsClause() { return _throwsClause; }
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                // TODO Auto-generated method stub
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}
Note: See TracBrowser for help on using the browser.