Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 34... Line 64...
34
 
64
 
35
/*
65
/*
36
    CONSTANT EVALUATION MACROS
66
    CONSTANT EVALUATION MACROS
37
 
67
 
38
    All the calculation routines are based on lists of unsigned int's
68
    All the calculation routines are based on lists of unsigned int's
39
    holding values in the range [0,0xffff].  The type unsigned long is
69
    holding values in the range [0, 0xffff].  The type unsigned long is
40
    guaranteed to contain at least the range [0,0xffffffff].  All
70
    guaranteed to contain at least the range [0, 0xffffffff].  All
41
    calculations are performed in this double precision type to allow for
71
    calculations are performed in this double precision type to allow for
42
    overflows.  The macros LO_HALF, HI_HALF, EXTEND_VALUE and COMBINE_VALUES
72
    overflows.  The macros LO_HALF, HI_HALF, EXTEND_VALUE and COMBINE_VALUES
43
    are used for converting to and from the extended type.
73
    are used for converting to and from the extended type.
44
*/
74
*/
45
 
75
 
46
#define NAT_DIGITS		16
76
#define NAT_DIGITS		16
47
#define NAT_MASK		( ( unsigned ) 0xffff )
77
#define NAT_MASK		((unsigned)0xffff)
48
 
78
 
49
#define LO_HALF( A )		( ( unsigned ) ( ( A ) & NAT_MASK ) )
79
#define LO_HALF(A)		((unsigned)((A) & NAT_MASK))
50
#define HI_HALF( A )		( LO_HALF ( ( A ) >> NAT_DIGITS ) )
80
#define HI_HALF(A)		(LO_HALF((A) >> NAT_DIGITS))
51
 
81
 
52
#define EXTEND_VALUE( A )	( ( unsigned long ) ( A ) )
82
#define EXTEND_VALUE(A)		((unsigned long)(A))
53
#define COMBINE_VALUES( A, B )	( EXTEND_VALUE ( A ) +\
83
#define COMBINE_VALUES(A, B)	(EXTEND_VALUE(A) +\
54
				  ( EXTEND_VALUE ( B ) << NAT_DIGITS ) )
84
				 (EXTEND_VALUE(B) << NAT_DIGITS))
55
#define EXTENDED_MAX		COMBINE_VALUES ( NAT_MASK, NAT_MASK )
85
#define EXTENDED_MAX		COMBINE_VALUES(NAT_MASK, NAT_MASK)
56
 
86
 
57
 
87
 
58
/*
88
/*
59
    CONSTANT EVALUATION DECLARATIONS
89
    CONSTANT EVALUATION DECLARATIONS
60
 
90
 
61
    The routines in this module are concerned with constructing and
91
    The routines in this module are concerned with constructing and
62
    performing calculations with integer constant expressions.
92
    performing calculations with integer constant expressions.
63
*/
93
*/
64
 
94
 
65
extern void init_constant PROTO_S ( ( void ) ) ;
95
extern void init_constant(void);
66
extern void init_float PROTO_S ( ( FLOAT_TYPE ) ) ;
96
extern void init_float(FLOAT_TYPE);
67
extern FLOAT get_float PROTO_S ( ( TYPE, int ) ) ;
97
extern FLOAT get_float(TYPE, int);
68
 
98
 
69
extern NAT make_nat_literal PROTO_S ( ( NAT, unsigned, unsigned ) ) ;
99
extern NAT make_nat_literal(NAT, unsigned, unsigned);
70
extern NAT make_large_nat PROTO_S ( ( LIST ( unsigned ) ) ) ;
100
extern NAT make_large_nat(LIST(unsigned));
71
extern NAT make_nat_value PROTO_S ( ( unsigned long ) ) ;
101
extern NAT make_nat_value(unsigned long);
72
extern NAT make_small_nat PROTO_S ( ( int ) ) ;
102
extern NAT make_small_nat(int);
73
extern unsigned long get_nat_value PROTO_S ( ( NAT ) ) ;
103
extern unsigned long get_nat_value(NAT);
74
extern NAT negate_nat PROTO_S ( ( NAT ) ) ;
104
extern NAT negate_nat(NAT);
75
extern NAT binary_nat_op PROTO_S ( ( unsigned, NAT, NAT ) ) ;
105
extern NAT binary_nat_op(unsigned, NAT, NAT);
76
extern int compare_nat PROTO_S ( ( NAT, NAT ) ) ;
106
extern int compare_nat(NAT, NAT);
77
extern int eq_nat PROTO_S ( ( NAT, NAT ) ) ;
107
extern int eq_nat(NAT, NAT);
78
 
108
 
79
extern int check_nat_range PROTO_S ( ( TYPE, NAT ) ) ;
109
extern int check_nat_range(TYPE, NAT);
80
extern int check_type_size PROTO_S ( ( TYPE, NAT ) ) ;
110
extern int check_type_size(TYPE, NAT);
81
extern NAT max_type_value PROTO_S ( ( TYPE, int ) ) ;
111
extern NAT max_type_value(TYPE, int);
82
extern void check_bounds PROTO_S ( ( int, TYPE, EXP ) ) ;
112
extern void check_bounds(int, TYPE, EXP);
83
extern unsigned eval_const_cond PROTO_S ( ( EXP ) ) ;
113
extern unsigned eval_const_cond(EXP);
84
extern unsigned no_bits PROTO_S ( ( unsigned ) ) ;
114
extern unsigned no_bits(unsigned);
85
extern int divides_nat PROTO_S ( ( EXP, EXP ) ) ;
115
extern int divides_nat(EXP, EXP);
86
extern int is_zero_nat PROTO_S ( ( NAT ) ) ;
116
extern int is_zero_nat(NAT);
87
extern int is_negative_nat PROTO_S ( ( NAT ) ) ;
117
extern int is_negative_nat(NAT);
88
extern int is_error_nat PROTO_S ( ( NAT ) ) ;
118
extern int is_error_nat(NAT);
89
extern int is_calc_nat PROTO_S ( ( NAT ) ) ;
119
extern int is_calc_nat(NAT);
90
extern int is_zero_exp PROTO_S ( ( EXP ) ) ;
120
extern int is_zero_exp(EXP);
91
extern int is_literal PROTO_S ( ( EXP ) ) ;
121
extern int is_literal(EXP);
92
 
122
 
93
 
123
 
94
/*
124
/*
95
    CONSTANT EVALUATION ROUTINES
125
    CONSTANT EVALUATION ROUTINES
96
 
126
 
97
    These routines are concerned with the evaluation of integer constant
127
    These routines are concerned with the evaluation of integer constant
98
    expressions.  They are so designed that the int_lit expressions are
128
    expressions.  They are so designed that the int_lit expressions are
99
    precisely the constant-expressions from the grammar.
129
    precisely the constant-expressions from the grammar.
100
*/
130
*/
101
 
131
 
102
extern EXP make_test_nat PROTO_S ( ( EXP ) ) ;
132
extern EXP make_test_nat(EXP);
103
extern EXP make_unary_nat PROTO_S ( ( unsigned, EXP ) ) ;
133
extern EXP make_unary_nat(unsigned, EXP);
104
extern EXP make_binary_nat PROTO_S ( ( unsigned, EXP, EXP ) ) ;
134
extern EXP make_binary_nat(unsigned, EXP, EXP);
105
extern EXP make_compare_nat PROTO_S ( ( NTEST, EXP, EXP ) ) ;
135
extern EXP make_compare_nat(NTEST, EXP, EXP);
106
extern EXP make_cond_nat PROTO_S ( ( EXP, EXP, EXP ) ) ;
136
extern EXP make_cond_nat(EXP, EXP, EXP);
107
extern EXP make_cast_nat PROTO_S ( ( TYPE, EXP, ERROR *, unsigned ) ) ;
137
extern EXP make_cast_nat(TYPE, EXP, ERROR *, unsigned);
108
extern EXP make_int_exp PROTO_S ( ( TYPE, unsigned, NAT ) ) ;
138
extern EXP make_int_exp(TYPE, unsigned, NAT);
109
extern NAT make_nat_exp PROTO_S ( ( EXP, ERROR * ) ) ;
139
extern NAT make_nat_exp(EXP, ERROR *);
110
extern EXP calc_nat_value PROTO_S ( ( NAT, TYPE ) ) ;
140
extern EXP calc_nat_value(NAT, TYPE);
111
 
141
 
112
#define SMALL_NAT_SIZE		257
142
#define SMALL_NAT_SIZE		257
113
#define SMALL_NAT_ALLOC		17
143
#define SMALL_NAT_ALLOC		17
114
#define SMALL_FLT_SIZE		2
144
#define SMALL_FLT_SIZE		2
115
 
145
 
116
extern NAT small_neg_nat [ SMALL_NAT_SIZE ] ;
146
extern NAT small_neg_nat[SMALL_NAT_SIZE];
117
extern NAT small_nat [ SMALL_NAT_SIZE ] ;
147
extern NAT small_nat[SMALL_NAT_SIZE];
118
extern string small_number [ SMALL_FLT_SIZE ] ;
148
extern string small_number[SMALL_FLT_SIZE];
119
 
149
 
120
 
150
 
121
#endif
151
#endif