source: branches/1.0.x/abcl/src/org/armedbear/lisp/SlotClass.java

Last change on this file was 13541, checked in by Mark Evenson, 14 years ago

Convert docstrings and primitives to standard conventions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1/*
2 * SlotClass.java
3 *
4 * Copyright (C) 2003-2005 Peter Graves
5 * $Id: SlotClass.java 13541 2011-08-27 23:23:24Z mevenson $
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 *
21 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36import static org.armedbear.lisp.Lisp.*;
37
38public class SlotClass extends LispClass
39{
40    private LispObject directSlotDefinitions = NIL;
41    private LispObject slotDefinitions = NIL;
42    private LispObject directDefaultInitargs = NIL;
43    private LispObject defaultInitargs = NIL;
44
45    public SlotClass(Layout layout)
46    {
47      super(layout);
48    }
49
50    public SlotClass(Symbol symbol, LispObject directSuperclasses)
51
52
53    {
54        this(null, symbol, directSuperclasses);
55    }
56
57    public SlotClass(Layout layout,
58                     Symbol symbol, LispObject directSuperclasses)
59    {
60        super(layout, symbol, directSuperclasses);
61    }
62
63    @Override
64    public LispObject getParts()
65    {
66        LispObject result = super.getParts().nreverse();
67        result = result.push(new Cons("DIRECT-SLOTS",
68                                      getDirectSlotDefinitions()));
69        result = result.push(new Cons("SLOTS", getSlotDefinitions()));
70        result = result.push(new Cons("DIRECT-DEFAULT-INITARGS",
71                                      getDirectDefaultInitargs()));
72        result = result.push(new Cons("DEFAULT-INITARGS",
73                                      getDefaultInitargs()));
74        return result.nreverse();
75    }
76
77    @Override
78    public LispObject typep(LispObject type)
79    {
80        return super.typep(type);
81    }
82
83    public LispObject getDirectSlotDefinitions()
84    {
85        return directSlotDefinitions;
86    }
87
88    public void setDirectSlotDefinitions(LispObject directSlotDefinitions)
89    {
90        this.directSlotDefinitions = directSlotDefinitions;
91    }
92
93    public LispObject getSlotDefinitions()
94    {
95        return slotDefinitions;
96    }
97
98    public void setSlotDefinitions(LispObject slotDefinitions)
99    {
100        this.slotDefinitions = slotDefinitions;
101    }
102
103    public LispObject getDirectDefaultInitargs()
104    {
105        return directDefaultInitargs;
106    }
107
108    public void setDirectDefaultInitargs(LispObject directDefaultInitargs)
109    {
110        this.directDefaultInitargs = directDefaultInitargs;
111    }
112
113    public LispObject getDefaultInitargs()
114    {
115        return defaultInitargs;
116    }
117
118    public void setDefaultInitargs(LispObject defaultInitargs)
119    {
120        this.defaultInitargs = defaultInitargs;
121    }
122
123    LispObject computeDefaultInitargs()
124    {
125        LispObject result = NIL;
126        LispObject cpl = getCPL();
127        while (cpl != NIL) {
128            LispClass c = (LispClass) cpl.car();
129            if (c instanceof StandardClass) {
130                LispObject obj = ((StandardClass)c).getDirectDefaultInitargs();
131                if (obj != NIL)
132                    result = Symbol.APPEND.execute(result, obj);
133            }
134            cpl = cpl.cdr();
135        }
136        return result;
137    }
138
139    public void finalizeClass()
140    {
141        if (isFinalized())
142            return;
143
144        LispObject defs = getSlotDefinitions();
145        Debug.assertTrue(defs == NIL);
146        LispObject cpl = getCPL();
147        Debug.assertTrue(cpl != null);
148        Debug.assertTrue(cpl.listp());
149        cpl = cpl.reverse();
150        while (cpl != NIL) {
151            LispObject car = cpl.car();
152            if (car instanceof StandardClass) {
153                StandardClass cls = (StandardClass) car;
154                LispObject directDefs = cls.getDirectSlotDefinitions();
155                Debug.assertTrue(directDefs != null);
156                Debug.assertTrue(directDefs.listp());
157                while (directDefs != NIL) {
158                    defs = defs.push(directDefs.car());
159                    directDefs = directDefs.cdr();
160                }
161            }
162            cpl = cpl.cdr();
163        }
164        setSlotDefinitions(defs.nreverse());
165        LispObject[] instanceSlotNames = new LispObject[defs.length()];
166        int i = 0;
167        LispObject tail = getSlotDefinitions();
168        while (tail != NIL) {
169            SlotDefinition slotDefinition = (SlotDefinition) tail.car();
170            slotDefinition.setLocation(i);
171            instanceSlotNames[i++] = slotDefinition.getName();
172            tail = tail.cdr();
173        }
174        setClassLayout(new Layout(this, instanceSlotNames, NIL));
175        setDefaultInitargs(computeDefaultInitargs());
176        setFinalized(true);
177    }
178
179    @DocString(name="%class-direct-slots")
180    private static final Primitive CLASS_DIRECT_SLOTS
181        = new pf__class_direct_slots();
182    private static final class pf__class_direct_slots extends Primitive
183    {
184        pf__class_direct_slots() 
185        {
186            super("%class-direct-slots", PACKAGE_SYS, true);
187        }
188        @Override
189        public LispObject execute(LispObject arg)
190
191        {
192            if (arg instanceof SlotClass)
193                return ((SlotClass)arg).getDirectSlotDefinitions();
194            if (arg instanceof BuiltInClass)
195                return NIL;
196            return type_error(arg, Symbol.STANDARD_CLASS);
197        }
198    };
199
200    @DocString(name="%set-class-direct-slots")
201    private static final Primitive _SET_CLASS_DIRECT_SLOT
202        = new pf__set_class_direct_slots();
203    private static final class pf__set_class_direct_slots extends Primitive
204    {
205        pf__set_class_direct_slots() 
206        {
207            super("%set-class-direct-slots", PACKAGE_SYS, true);
208        }
209
210        @Override
211        public LispObject execute(LispObject first, LispObject second)
212        {
213            if (second instanceof SlotClass) {
214                  ((SlotClass)second).setDirectSlotDefinitions(first);
215                return first;
216            } else {
217                return type_error(second, Symbol.STANDARD_CLASS);
218            }
219        }
220    };
221
222    @DocString(name="%class-slots",
223               args="class")
224    private static final Primitive _CLASS_SLOTS
225        = new pf__class_slots();
226    private static final class pf__class_slots extends Primitive
227    {
228        pf__class_slots() 
229        {
230            super(Symbol._CLASS_SLOTS, "class");
231        }
232
233        @Override
234        public LispObject execute(LispObject arg)
235        {
236            if (arg instanceof SlotClass)
237                return ((SlotClass)arg).getSlotDefinitions();
238            if (arg instanceof BuiltInClass)
239                return NIL;
240            return type_error(arg, Symbol.STANDARD_CLASS);
241        }
242    };
243
244    @DocString(name="%set-class-slots",
245               args="class slot-definitions")
246    private static final Primitive _SET_CLASS_SLOTS
247        = new pf__set_class_slots();
248    private static final class pf__set_class_slots extends Primitive
249    {
250        pf__set_class_slots()
251        {
252            super(Symbol._SET_CLASS_SLOTS, "class slot-definitions");
253        }
254        @Override
255        public LispObject execute(LispObject first, LispObject second)
256        {
257            if (second instanceof SlotClass) {
258              ((SlotClass)second).setSlotDefinitions(first);
259              return first;
260            } else {
261              return type_error(second, Symbol.STANDARD_CLASS);
262            }
263        }
264    };
265
266    @DocString(name="%class-direct-default-initargs")
267    private static final Primitive CLASS_DIRECT_DEFAULT_INITARGS
268        = new pf__class_direct_default_initargs();
269    private static final class pf__class_direct_default_initargs extends Primitive
270    {
271        pf__class_direct_default_initargs() 
272        {
273            super("%class-direct-default-initargs", PACKAGE_SYS, true);
274        }
275        @Override
276        public LispObject execute(LispObject arg)
277        {
278            if (arg instanceof SlotClass)
279                return ((SlotClass)arg).getDirectDefaultInitargs();
280            if (arg instanceof BuiltInClass)
281                return NIL;
282            return type_error(arg, Symbol.STANDARD_CLASS);
283        }
284    };
285
286    @DocString(name="%set-class-direct-default-initargs")
287    private static final Primitive _SET_CLASS_DIRECT_DEFAULT_INITARGS
288        = new pf__set_class_direct_default_initargs();
289    private static final class pf__set_class_direct_default_initargs extends Primitive
290    {
291        pf__set_class_direct_default_initargs()
292        {
293            super("%set-class-direct-default-initargs", PACKAGE_SYS, true);
294        }
295        @Override
296        public LispObject execute(LispObject first, LispObject second)
297        {
298            if (second instanceof SlotClass) {
299                ((SlotClass)second).setDirectDefaultInitargs(first);
300                return first;
301            }
302            return type_error(second, Symbol.STANDARD_CLASS);
303        }
304    };
305
306    @DocString(name="%class-default-initargs")
307    private static final Primitive CLASS_DEFAULT_INITARGS
308        = new pf__class_default_initargs();
309    private static final class pf__class_default_initargs extends Primitive
310    {
311        pf__class_default_initargs() 
312        {
313            super("%class-default-initargs", PACKAGE_SYS, true);
314        }
315        @Override
316        public LispObject execute(LispObject arg)
317        {
318            if (arg instanceof SlotClass)
319                return ((SlotClass)arg).getDefaultInitargs();
320            if (arg instanceof BuiltInClass)
321                return NIL;
322            return type_error(arg, Symbol.STANDARD_CLASS);
323        }
324    };
325
326    @DocString(name="%set-class-default-initargs")
327    private static final Primitive _SET_CLASS_DEFAULT_INITARGS
328        = new pf__set_class_default_initargs();
329
330    private static final class pf__set_class_default_initargs extends Primitive
331    {
332        pf__set_class_default_initargs()
333        {
334            super("%set-class-default-initargs", PACKAGE_SYS, true);
335        }
336        @Override
337        public LispObject execute(LispObject first, LispObject second)
338        {
339            if (second instanceof SlotClass) {
340                ((SlotClass)second).setDefaultInitargs(first);
341                return first;
342            }
343            return type_error(second, Symbol.STANDARD_CLASS);
344        }
345    };
346}
Note: See TracBrowser for help on using the repository browser.