]> andersk Git - splint.git/blob - src/lclctypes.c
48535eb7e7e55b7ade807abbba430c7014998ae6
[splint.git] / src / lclctypes.c
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 **         Massachusetts Institute of Technology
5 **
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
10 ** 
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ** General Public License for more details.
15 ** 
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
19 **
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
23 */
24 /*
25 ** lclctypes.c
26 **
27 ** This contains definitions used in processing C builtin types.
28 **
29 ** WARNING: there is a different file ctype.c for handling types
30 **          in the C checking of splint.  This is only for handling
31 **          C builtin types in LCL files.
32 **
33 **  AUTHORS:
34 **
35 **      Gary Feldman, Technical Languages and Environements, DECspec project
36 **      Joe Wild, Technical Languages and Environements, DECspec project
37 **
38 */
39
40 # include "splintMacros.nf"
41 # include "llbasic.h"
42
43 typedef struct
44 {
45   bits pt;
46   TypeSpec ts;
47 } Lclctype2sortType;
48
49 static Lclctype2sortType lclctype2type[] =
50 {
51   { fixBits (TS_VOID, 0), TYS_VOID},
52   { fixBits (TS_UNKNOWN, 0), TYS_NONE},
53   { fixBits (TS_CHAR, 0), TYS_CHAR},
54   { fixBits (TS_SIGNED, fixBits (TS_CHAR, 0)), TYS_SCHAR},
55   { fixBits (TS_UNSIGNED, fixBits (TS_CHAR, 0)), TYS_UCHAR},
56
57   { fixBits (TS_SIGNED, fixBits (TS_SHORT, fixBits (TS_INT, 0))), TYS_SSINT},
58   { fixBits (TS_SIGNED, fixBits (TS_SHORT, 0)), TYS_SSINT},
59   { fixBits (TS_SHORT, fixBits (TS_INT, 0)), TYS_SSINT},
60   { fixBits (TS_SHORT, 0), TYS_SSINT},
61
62   { fixBits (TS_UNSIGNED, fixBits (TS_SHORT, fixBits (TS_INT, 0))), TYS_USINT},
63   { fixBits (TS_UNSIGNED, fixBits (TS_SHORT, 0)), TYS_USINT},
64
65   { fixBits (TS_SIGNED, fixBits (TS_INT, 0)), TYS_SINT},
66   { fixBits (TS_SIGNED, 0), TYS_SINT},
67
68   { fixBits (TS_INT, 0), TYS_INT},
69   { 0, TYS_INT},
70
71   { fixBits (TS_UNSIGNED, fixBits (TS_INT, 0)), TYS_UINT},
72   { fixBits (TS_UNSIGNED, 0), TYS_UINT},
73
74   { fixBits (TS_SIGNED, fixBits (TS_LONG, fixBits (TS_INT, 0))), TYS_SLINT},
75   { fixBits (TS_SIGNED, fixBits (TS_LONG, 0)), TYS_SLINT},
76   { fixBits (TS_LONG, fixBits (TS_INT, 0)), TYS_SLINT},
77   { fixBits (TS_LONG, 0), TYS_SLINT},
78
79   { fixBits (TS_UNSIGNED, fixBits (TS_LONG, fixBits (TS_INT, 0))), TYS_ULINT},
80   { fixBits (TS_UNSIGNED, fixBits (TS_LONG, 0)), TYS_ULINT},
81
82   { fixBits (TS_FLOAT, 0), TYS_FLOAT},
83   { fixBits (TS_DOUBLE, 0), TYS_DOUBLE},
84   { fixBits (TS_LONG, fixBits (TS_DOUBLE, 0)), TYS_LDOUBLE},
85
86   { fixBits (TS_STRUCT, 0), TYS_STRUCT},
87   { fixBits (TS_UNION, 0), TYS_UNION},
88   { fixBits (TS_ENUM, 0), TYS_ENUM},
89   { fixBits (TS_TYPEDEF, 0), TYS_TYPENAME}
90 };
91
92 lsymbol
93 lclctype_toSortDebug (bits t)
94 {
95   int i;
96   int lsize;
97   static ob_mstring OLD_Type2sortName[] =
98     {
99       "error",                  /* TYS_NONE     */
100       "void",                   /* TYS_VOID     */
101       "char",                   /* TYS_CHAR     */
102       "signed_char",            /* TYS_SCHAR    */
103       "char",                   /* TYS_UCHAR    */
104       "short_int",              /* TYS_SSINT    */
105       "unsigned_short_int",     /* TYS_USINT    */
106       "int",                    /* TYS_INT        */
107       "int",                    /* TYS_SINT     */
108       "unsigned_int",           /* TYS_UINT     */
109       "long_int",               /* TYS_SLINT    */
110       "unsigned_long_int",      /* TYS_ULINT    */
111       "float",                  /* TYS_FLOAT    */
112       "double",                 /* TYS_DOUBLE   */
113       "long_double",            /* TYS_LDOUBLE  */
114       "error",                  /* TYS_ENUM     */
115       "error",                  /* TYS_STRUCT   */
116       "error",                  /* TYS_UNION    */
117       "error"                   /* TYS_TYPENAME */
118       };
119
120   lsize = size_toInt (sizeof (lclctype2type) / sizeof (lclctype2type[0]));
121
122   for (i = 0; i < lsize; i++)
123     {
124       if (lclctype2type[i].pt == t)
125         {
126           return lsymbol_fromChars (OLD_Type2sortName[(int)lclctype2type[i].ts]);
127         }
128     }
129   return lsymbol_fromChars ("_error");
130 }
131
132
133 lsymbol
134 lclctype_toSort (bits t)
135 {
136   int i;
137   static ob_mstring Type2sortName[] =
138     {
139       /* _error must have underscore, LSL/LCL interface convention */
140       "_error",                 /* TYS_NONE     */
141       "void",                   /* TYS_VOID     */
142       "char",                   /* TYS_CHAR     */
143       "char",                   /* TYS_SCHAR    */
144       "char",                   /* TYS_UCHAR    */
145       "int",                    /* TYS_SSINT    */
146       "int",                    /* TYS_USINT    */
147       "int",                    /* TYS_INT      */
148       "int",                    /* TYS_SINT     */
149       "int",                    /* TYS_UINT     */
150       "int",                    /* TYS_SLINT    */
151       "int",                    /* TYS_ULINT    */
152       "double",                 /* TYS_FLOAT    */
153       "double",                 /* TYS_DOUBLE   */
154       "double",                 /* TYS_LDOUBLE  */
155       "error",                  /* TYS_ENUM     */
156       "error",                  /* TYS_STRUCT   */
157       "error",                  /* TYS_UNION    */
158       "error"                   /* TYS_TYPENAME         */
159       };
160
161   int lsize = size_toInt (sizeof (lclctype2type) / sizeof (lclctype2type[0]));
162
163   for (i = 0; i < lsize; i++)
164     {
165       if (lclctype2type[i].pt == t)
166         {
167           return lsymbol_fromChars (Type2sortName[(int)lclctype2type[i].ts]);
168         }
169     }
170
171   return lsymbol_fromChars ("_error");
172 }
This page took 0.037723 seconds and 3 git commands to generate.