blob: b770bce3c618cff5e5164c5341429914b53e89f0 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum6610ad91995-01-04 19:07:38 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025/* Type object implementation */
26
Guido van Rossum3f5da241990-12-20 15:06:42 +000027#include "allobjects.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000028
29/* Type object implementation */
30
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000031static object *
Guido van Rossum29ca26e1995-01-07 11:58:15 +000032type_getattr(t, name)
33 typeobject *t;
34 char *name;
35{
36 if (strcmp(name, "__name__") == 0)
37 return newstringobject(t->tp_name);
38 if (strcmp(name, "__doc__") == 0) {
39 char *doc = t->tp_doc;
40 if (doc != NULL)
41 return newstringobject(doc);
42 INCREF(None);
43 return None;
44 }
45 if (strcmp(name, "__members__") == 0)
46 return mkvalue("[ss]", "__doc__", "__name__");
47 err_setstr(AttributeError, name);
48 return NULL;
49}
50
51static object *
Guido van Rossum3f5da241990-12-20 15:06:42 +000052type_repr(v)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000053 typeobject *v;
54{
55 char buf[100];
56 sprintf(buf, "<type '%.80s'>", v->tp_name);
57 return newstringobject(buf);
58}
59
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000060typeobject Typetype = {
61 OB_HEAD_INIT(&Typetype)
62 0, /* Number of items for varobject */
63 "type", /* Name of this type */
64 sizeof(typeobject), /* Basic object size */
65 0, /* Item size for varobject */
Guido van Rossum3f5da241990-12-20 15:06:42 +000066 0, /*tp_dealloc*/
Guido van Rossum7066dd71992-09-17 17:54:56 +000067 0, /*tp_print*/
Guido van Rossum29ca26e1995-01-07 11:58:15 +000068 (getattrfunc)type_getattr, /*tp_getattr*/
Guido van Rossum3f5da241990-12-20 15:06:42 +000069 0, /*tp_setattr*/
70 0, /*tp_compare*/
Guido van Rossum29ca26e1995-01-07 11:58:15 +000071 (reprfunc)type_repr, /*tp_repr*/
72 0, /*tp_as_number*/
73 0, /*tp_as_sequence*/
74 0, /*tp_as_mapping*/
75 0, /*tp_hash*/
76 0, /*tp_call*/
77 0, /*tp_str*/
78 0, /*tp_xxx1*/
79 0, /*tp_xxx2*/
80 0, /*tp_xxx3*/
81 0, /*tp_xxx4*/
82 "Define the behaviour of a particular type of object.",
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000083};