Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
6 7u83 2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
6 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
6 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
6 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include "object.h"
63
#include "hash.h"
64
#include "name.h"
65
#include "type.h"
66
#include "utility.h"
67
#include "variable.h"
68
 
69
 
70
/*
71
    CREATE A NEW OBJECT
72
 
73
    This routine creates a new object, with name nm and type t.
74
*/
75
 
6 7u83 76
object *
77
make_object(char *nm, int t)
2 7u83 78
{
6 7u83 79
    object *p;
80
    alloc_variable(p, object, 1000);
81
    p->name = nm;
82
    p->objtype = t;
83
    p->next = null;
84
    p->filename = filename;
85
    p->line_no = line_no;
86
    return(p);
2 7u83 87
}
88
 
89
 
90
/*
91
    JOIN TWO LISTS OF OBJECTS
92
 
93
    This routine joins two lists of objects, returning the result.
94
*/
95
 
6 7u83 96
object *
97
join_object(object *p, object *q)
2 7u83 98
{
6 7u83 99
    object *r = p;
100
    if (p == null) return(q);
101
    if (q == null) return(p);
102
    while (r->next)r = r->next;
103
    r->next = q;
104
    return(p);
2 7u83 105
}
106
 
107
 
108
/*
109
    FIND A SUBSET
110
 
111
    This routine looks up the subset named nm.  The operation for splitting
112
    nm into its components (which should only be called with preprocessed
113
    input) needs to be kept in step with subset_name.
114
*/
115
 
6 7u83 116
object *
117
make_subset(char *nm)
2 7u83 118
{
6 7u83 119
    object *p = search_hash(subsets, nm, no_version);
120
    if (p == null) {
121
	char *api = string_copy(nm);
122
	char *file = null;
123
	char *subset = null;
124
	char *s = strchr(api, ':');
125
	if (s) {
126
	    *s = 0;
127
	    file = s + 1;
128
	    s = strchr(file, ':');
129
	    if (s) {
130
		*s = 0;
131
		subset = s + 1;
2 7u83 132
	    }
6 7u83 133
	    if (*file == 0)file = null;
2 7u83 134
	}
6 7u83 135
	p = make_object(nm, OBJ_SUBSET);
136
	p->u.u_info = make_info(api, file, subset);
137
	p->u.u_info->age = (time_t)0;
138
	IGNORE add_hash(subsets, p, no_version);
2 7u83 139
    }
6 7u83 140
    return(p);
2 7u83 141
}
142
 
143
 
144
/*
145
    CREATE SUBSET INFORMATION
146
 
147
    This routine creates the subset information for the subset
148
    api:file:subset.
149
*/
150
 
6 7u83 151
info *
152
make_info(char *api, char *file, char *subset)
2 7u83 153
{
6 7u83 154
    info *p;
155
    alloc_variable(p, info, 100);
156
    p->api = api;
157
    p->file = file;
158
    p->subset = subset;
159
    p->age = date_stamp(filename);
160
    p->incl = include_name(output_incl_dir, api, file, subset);
161
    p->src = src_name(output_src_dir, api, file, subset);
162
    p->block = block_name(api, file, subset);
163
    p->linkage = "C";
164
    p->nspace = null;
165
    p->method = null;
166
    p->prefix = token_prefix(api, file, subset);
167
    p->protect = macro_name(PROTECT_PREFIX, api, file, subset);
168
    p->version = null;
169
    p->tokens = 0;
170
    p->implemented = 0;
171
    p->elements = null;
172
    return(p);
2 7u83 173
}
174
 
175
 
176
/*
177
    UPDATE A SUBSET DATESTAMP
178
 
179
    This routine updates the datestamp on the subset p from that on the
180
    subset q.
181
*/
182
 
6 7u83 183
void
184
update_time(object *p, object *q)
2 7u83 185
{
6 7u83 186
    if (p && q) {
187
	time_t tp = p->u.u_info->age;
188
	time_t tq = q->u.u_info->age;
189
	if (tp && tq > tp)p->u.u_info->age = tq;
2 7u83 190
    }
6 7u83 191
    return;
2 7u83 192
}
193
 
194
 
195
/*
196
    CREATE A TOKEN
197
 
198
    This routine creates a token called nm (version vers) describing the
199
    object p.  If this is a real token then the tokens field of the
200
    current subset is set.
201
*/
202
 
6 7u83 203
object *
204
make_token(char *nm, int vers, object *p, int objtype)
2 7u83 205
{
6 7u83 206
    object *r = make_object(nm, OBJ_TOKEN);
207
    r->u.u_obj = p;
208
    IGNORE add_hash(tokens, r, vers);
209
    if (crt_object) {
210
	switch (objtype) {
211
	    case OBJ_EXTERN:
212
	    case OBJ_WEAK: {
213
		break;
2 7u83 214
	    }
215
	    default : {
6 7u83 216
		crt_object->u.u_info->tokens = 1;
217
		break;
2 7u83 218
	    }
219
	}
220
    }
6 7u83 221
    return(r);
2 7u83 222
}
223
 
224
 
225
/*
226
    CREATE AN EXPRESSION
227
 
228
    This routine creates and expression object of type t called nm (version
229
    vers).
230
*/
231
 
6 7u83 232
object *
233
make_exp(char *nm, int vers, int t)
2 7u83 234
{
6 7u83 235
    object *r = make_object(nm, t);
236
    IGNORE add_hash(exps, r, vers);
237
    r->u.u_type = null ;
238
    return(r);
2 7u83 239
}