1 /********************************************************************/
2 /*                                                                  */
3 /*  s7   Seed7 interpreter                                          */
4 /*  Copyright (C) 1990 - 2008  Thomas Mertes                        */
5 /*                                                                  */
6 /*  This program is free software; you can redistribute it and/or   */
7 /*  modify it under the terms of the GNU General Public License as  */
8 /*  published by the Free Software Foundation; either version 2 of  */
9 /*  the License, or (at your option) any later version.             */
10 /*                                                                  */
11 /*  This program is distributed in the hope that it will be useful, */
12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of  */
13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   */
14 /*  GNU General Public License for more details.                    */
15 /*                                                                  */
16 /*  You should have received a copy of the GNU General Public       */
17 /*  License along with this program; if not, write to the           */
18 /*  Free Software Foundation, Inc., 51 Franklin Street,             */
19 /*  Fifth Floor, Boston, MA  02110-1301, USA.                       */
20 /*                                                                  */
21 /*  Module: Reflection                                              */
22 /*  File: seed7/src/datautl.c                                       */
23 /*  Changes: 1991, 1992, 1993, 1994  Thomas Mertes                  */
24 /*  Content: Procedures to maintain objects of type identType.      */
25 /*                                                                  */
26 /********************************************************************/
27 
28 #include "version.h"
29 
30 #include "stdlib.h"
31 #include "stdio.h"
32 #include "string.h"
33 
34 #include "common.h"
35 #include "data.h"
36 
37 #undef EXTERN
38 #define EXTERN
39 #include "datautl.h"
40 
41 
42 static const const_cstriType category_name[] = {
43     "SYMBOLOBJECT",      /* pos (file, line) - Symbol object        */
44                          /*                    created by read_atom */
45                          /*                    and read_name        */
46     "DECLAREDOBJECT",    /* NO VALUE -         Object declared and  */
47                          /*                    not initialized      */
48     "FORWARDOBJECT",     /* NO VALUE -         Object declared      */
49                          /*                    forward              */
50     "FWDREFOBJECT",      /* objValue -    Reference to Object which */
51                          /*               was declared forward      */
52     "BLOCKOBJECT",       /* blockValue - Procedure possibly with    */
53                          /*              parameters, declared       */
54                          /*              result or local variables  */
55     "CALLOBJECT",        /* listValue - Subroutine call:            */
56                          /*             First element is subroutine */
57                          /*             Rest of list is parameters  */
58     "MATCHOBJECT",       /* listValue - Don't exec subroutine call: */
59                          /*             First element is subroutine */
60                          /*             Rest of list is parameters  */
61     "TYPEOBJECT",        /* typeValue -   type                      */
62     "FORMPARAMOBJECT",   /* objValue -    Reference to formal param */
63     "INTOBJECT",         /* intValue -    integer                   */
64     "BIGINTOBJECT",      /* bigIntValue - bigInteger                */
65     "CHAROBJECT",        /* charValue -   char                      */
66     "STRIOBJECT",        /* striValue -   string                    */
67     "BSTRIOBJECT",       /* bstriValue -  byte string               */
68     "ARRAYOBJECT",       /* arrayValue -  array                     */
69     "HASHOBJECT",        /* hashValue -   hash                      */
70     "STRUCTOBJECT",      /* structValue - struct                    */
71     "CLASSOBJECT",       /* structValue - struct                    */
72     "INTERFACEOBJECT",   /* objValue -    Dynamic Object            */
73     "SETOBJECT",         /* setValue -    set                       */
74     "FILEOBJECT",        /* fileValue -   file                      */
75     "FILEDESOBJECT",     /* fileDesValue - file descriptor          */
76     "SOCKETOBJECT",      /* socketValue - socket                    */
77     "POLLOBJECT",        /* pollValue -   poll list                 */
78     "LISTOBJECT",        /* listValue -   list                      */
79     "FLOATOBJECT",       /* floatValue -  float                     */
80     "WINOBJECT",         /* winValue -    Window                    */
81     "PROCESSOBJECT",     /* processValue - Process                  */
82     "ENUMLITERALOBJECT", /* objValue -    Enumeration literal       */
83     "CONSTENUMOBJECT",   /* objValue -    Constant enumeration obj  */
84     "VARENUMOBJECT",     /* objValue -    Variable enumeration obj  */
85     "REFOBJECT",         /* objValue -    reference                 */
86     "REFLISTOBJECT",     /* listValue -   ref_list                  */
87     "EXPROBJECT",        /* listValue -   expression                */
88     "ACTOBJECT",         /* actValue -    Action                    */
89     "VALUEPARAMOBJECT",  /* objValue -    Formal value parameter    */
90     "REFPARAMOBJECT",    /* objValue -    Formal ref parameter      */
91     "RESULTOBJECT",      /* objValue -    Result of procedure       */
92     "LOCALVOBJECT",      /* objValue -    Local variable            */
93     "DATABASEOBJECT",    /* databaseValue - Database                */
94     "SQLSTMTOBJECT",     /* sqlStmtValue -  SQL statement           */
95     "PROGOBJECT"         /* progValue -   Program                   */
96   };
97 
98 
99 
100 /**
101  *  Get the C string representation of a 'category'.
102  *  @param aCategory Category to be converted.
103  *  @return the string result of the conversion.
104  */
category_cstri(objectCategory aCategory)105 const_cstriType category_cstri (objectCategory aCategory)
106 
107   {
108     const_cstriType result;
109 
110   /* category_cstri */
111     if (aCategory >= SYMBOLOBJECT && aCategory <= PROGOBJECT) {
112       result = category_name[(int) aCategory];
113     } else {
114       result = "*UNKNOWN*";
115     } /* if */
116     return result;
117   } /* category_cstri */
118 
119 
120 
121 /**
122  *  Convert a C string to a 'category'.
123  *  @param catName Name of a category to be converted.
124  *  @return the 'category' result of the conversion, or
125  *          -1 if no 'category' was found.
126  */
category_value(const const_cstriType catName)127 intType category_value (const const_cstriType catName)
128 
129   {
130     intType category;
131 
132   /* category_value */
133     for (category = SYMBOLOBJECT; category <= PROGOBJECT; category++) {
134       if (strcmp(catName, category_name[category]) == 0) {
135         return category;
136       } /* if */
137     } /* for */
138     return -1;
139   } /* category_value */
140 
141 
142 
id_string(const_identType actual_ident)143 const_cstriType id_string (const_identType actual_ident)
144 
145   {
146     const_cstriType result;
147 
148   /* id_string */
149     if (actual_ident == NULL) {
150       result = " *NULL_IDENT* ";
151     } else if (actual_ident->name == NULL) {
152       result = " *NULL_NAME_IDENT* ";
153     } else if (actual_ident->name[0] == '\0') {
154       result = " *NULL_STRING_IDENT* ";
155     } else if (memchr((cstriType) actual_ident->name, '\0', 51) == NULL) {
156       result = " *GARBAGE_IDENT* ";
157     } else {
158       result = (const_cstriType) actual_ident->name;
159     } /* if */
160     return result;
161   } /* id_string */
162 
163 
164 
id_string2(const_identType actual_ident)165 const_cstriType id_string2 (const_identType actual_ident)
166 
167   {
168     const_cstriType result;
169 
170   /* id_string2 */
171     if (actual_ident == NULL) {
172       result = " *NULL_IDENT* ";
173     } else if (actual_ident->name == NULL) {
174       result = " *NULL_NAME_IDENT* ";
175     } else {
176       result = (const_cstriType) actual_ident->name;
177     } /* if */
178     return result;
179   } /* id_string2 */
180