1 ///////////////////////////////////////////////////////////////////////////////
2 // Types, type environments and type inference.
3 ///////////////////////////////////////////////////////////////////////////////
11 ///////////////////////////////////////////////////////////////////////////////
13 // Predefined type constants.
15 ///////////////////////////////////////////////////////////////////////////////
16 extern Ty string_ty
, integer_ty
, bool_ty
, real_ty
, character_ty
,
17 quark_ty
, bigint_ty
, void_ty
;
19 ///////////////////////////////////////////////////////////////////////////////
21 // Flags to control printing.
23 ///////////////////////////////////////////////////////////////////////////////
24 extern Bool pretty_print_ty
;
25 extern Bool pretty_print_exp
;
26 extern Bool print_semantic_stack
;
27 extern Bool print_inner_action
;
28 extern Bool print_default_value
;
29 extern Parameter ty_parameter
;
32 ///////////////////////////////////////////////////////////////////////////////
34 // Function to initialize the predefined type constants.
36 ///////////////////////////////////////////////////////////////////////////////
37 extern void initialize_types();
39 ///////////////////////////////////////////////////////////////////////////////
41 // Functions to make a type variable and make a polymorphic type scheme.
43 ///////////////////////////////////////////////////////////////////////////////
45 extern Ty
mkpolyty(Ty
, TyVars
);
46 extern int tag_of(Cons
);
48 ///////////////////////////////////////////////////////////////////////////////
50 // Functions for constructing some common type constructors.
52 ///////////////////////////////////////////////////////////////////////////////
53 extern Ty
mkptrty (Ty
); // create a pointer type
54 extern Ty
mkrefty (Ty
); // create a reference type
55 extern Ty
mkfunty (Ty
, Ty
); // create a function type
56 extern Ty
mkarrayty (Ty
, Exp
); // create an array type
57 extern Ty
mkidty (Id
, Tys
); // create a type id
58 extern Ty
mkidvarty (Id
, TyVars
); // create a type id
59 extern Ty
mktuplety (Tys
); // create a tuple type
60 extern Ty
mktypety (); // create a predicate type
61 extern Ty
extuplety (Tys
); // create a prop tuple type
62 extern Ty
mkrecordty (Ids
, Tys
, Bool
); // create a record type
63 extern Tys
tyvars_to_tys (TyVars
);
64 extern Inherits
add_inherit(Id
, TyVars
,
65 Inherits
, Scope
=PUBLICscope
, TyQual
=QUALnone
);
67 ///////////////////////////////////////////////////////////////////////////////
69 // Functions for constructing some SETL-like type constructors.
71 ///////////////////////////////////////////////////////////////////////////////
72 extern Ty
mklistty (Ty
); // create a list type
73 extern Ty
mksetty (Ty
); // create a set type
74 extern Ty
mkbagty (Ty
); // create a bag type
75 extern Ty
mksetty (Ty
); // create a set type
76 extern Ty
mkmapty (Ty
, Ty
); // create a map type
77 extern Ty
mkmultimapty (Ty
, Ty
); // create a multimap type
78 extern Ty
mkqueuety (Ty
); // create a queue type
79 extern Ty
mkpriqueuety (Ty
); // create a priority queue type
80 extern Ty
mkdequety (Ty
); // create a deque type
82 ///////////////////////////////////////////////////////////////////////////////
84 // Functions for deferencing a type expression.
85 // Unification introduces indirect links which must be explicitly
86 // deferenced by all routines manipulation types.
88 ///////////////////////////////////////////////////////////////////////////////
90 extern Ty
deref_all (Ty
);
92 ///////////////////////////////////////////////////////////////////////////////
94 // Function to extract the default value from a type, if any. If none
95 // is defined then NOexp is returned. This is used to implement
96 // default constructor arguments.
98 ///////////////////////////////////////////////////////////////////////////////
99 extern Exp
default_val (Ty
);
101 ///////////////////////////////////////////////////////////////////////////////
103 // Functions for testing for specific attributes of a type.
105 ///////////////////////////////////////////////////////////////////////////////
106 extern Bool
has_qual (TyQual
, Ty
); // Test for qualifiers
107 extern Bool
is_ground (Ty
); // Is it a ground type?
108 extern Bool
is_ground (Tys
); // Is it a ground type?
109 extern Bool
is_array_ty (Ty
); // Is it an array type?
110 extern Bool
is_datatype (Ty
); // Is it a prop datatype?
111 extern Bool
is_poly_datatype (Ty
); // Is it a polymorphic datatype?
112 extern Bool
is_pointer_ty (Ty
); // Is it a pointer type?
113 extern Bool
is_gc_ty (Ty
); // Is the type garbage collected?
114 extern Bool
is_embeddable_ty (Ty
); // Can it be embedded in a ptr?
115 extern Bool
is_array_constructor (Id
); // Is it an array constructor?
116 extern Bool
is_list_constructor (Id
); // Is it an list constructor?
117 extern Bool
is_list_constructor (Cons
); // Is it an list constructor?
118 extern int arity_of (Ty
); // Arity?
119 extern int boxed_variants (Ty
); // Number of boxed variants?
120 extern int unboxed_variants (Ty
); // Number of unboxed variants?
122 ///////////////////////////////////////////////////////////////////////////////
124 // Instantiation and application of type schemes.
126 ///////////////////////////////////////////////////////////////////////////////
127 extern Ty
inst (Ty
, int, Id
[], Ty
[]);
128 extern Tys
inst (Tys
, int, Id
[], Ty
[]);
130 extern Ty
apply_ty(Ty
, Tys
);
131 extern Ty
component_ty(Ty
, Cons
);
132 extern Ty
component_ty(Ty
, Id
);
133 extern Ty
component_ty(Ty
, int);
135 ///////////////////////////////////////////////////////////////////////////////
137 // Unification routines.
139 ///////////////////////////////////////////////////////////////////////////////
140 extern Bool
unify (TyCon
, TyCon
); // Unify two type constructors
141 extern Bool
unify (Ty
, Ty
); // Unify two types
142 extern Bool
unify (Tys
, Tys
); // Unify two type lists
143 extern Bool
unify (Pat
, Ty
, Ty
); // Unify two type; report error if found.
145 ///////////////////////////////////////////////////////////////////////////////
147 // Type inference methods.
149 ///////////////////////////////////////////////////////////////////////////////
150 extern HashTable
* patvar_typemap
; // additional pattern var type map.
151 extern Ty
type_of (Literal
); // Type of a literal
152 extern Ty
type_of (Pat
); // Type of a pattern
153 extern Tys
type_of (Pats
); // Type of a pattern list
154 extern Tys
type_of (LabPats
); // Type of a labeled pattern list
156 ///////////////////////////////////////////////////////////////////////////////
158 // Function to extract the label list from a labeled pattern list.
160 ///////////////////////////////////////////////////////////////////////////////
161 extern Ids
labels_of (LabPats
);
163 ///////////////////////////////////////////////////////////////////////////////
165 // Function to type check a set of pattern matching rules.
167 ///////////////////////////////////////////////////////////////////////////////
168 extern Ty
type_match_rules (MatchRules
);
170 ///////////////////////////////////////////////////////////////////////////////
172 // Type and constructor environment methods.
173 // These interface with the type, constructor and persistence environments.
175 ///////////////////////////////////////////////////////////////////////////////
176 extern Ty
lookup_ty (Id
);
177 extern Cons
lookup_cons (Id
);
178 extern Cons
lookup_token (Id
);
179 extern Protocols
lookup_rewrite_class (Id
);
180 extern Cons
find_cons (Id
);
182 extern void add_type (Id
, TyVars
, Ty
);
183 extern void add_datatype (const Loc
*, Id
, TyVars
, Inherits
,
184 TyQual
, Exp
, TermDefs
, Decls
);
185 extern void add_rewrite_class (Id
, Protocols
, TyQual
);
186 extern void update_datatype (Id
, TyVars
, Inherits
, TyQual
, Decls
);
187 extern void update_constructor (Id
, Tys
, Inherits
, PrintFormats
, Decls
);
188 extern void update_persistent (Id
, Tys
, Pid
);
190 ///////////////////////////////////////////////////////////////////////////////
192 // Lexeme and regular expression conversions.
193 // These interface with the lexeme environment.
195 ///////////////////////////////////////////////////////////////////////////////
196 extern void update_lexeme (Id
, Ids
, Pat
);
197 extern void update_lexeme_class (Id
, TermDefs
);
198 extern TermDefs
lookup_lexeme_class (Id
);
199 extern Pat
mk_regexp_pat (const char *);
200 extern const char * convert_regexp (const char *, Bool
= true);
201 extern Pat
add_contexts (Conses
, Pat
);
202 extern Pat
expand_lexeme_pat (Pat
, Ty
, int, Cons
[]);
203 extern const char * make_quoted_string (const char *);
205 ///////////////////////////////////////////////////////////////////////////////
207 // Function to mangle a constructor name into a C++ usable name.
209 ///////////////////////////////////////////////////////////////////////////////
210 extern Id
mangle (Id
);
212 ///////////////////////////////////////////////////////////////////////////////
214 // Hashing and equality on qualifier identifiers and types.
215 // These are used in various hashtables and environments.
217 ///////////////////////////////////////////////////////////////////////////////
218 extern Bool
qualid_equal(QualId
, QualId
);
219 extern unsigned int ty_hash (HashTable::Key
);
220 extern Bool
ty_equal (HashTable::Key
, HashTable::Key
);
221 extern unsigned int tys_hash (HashTable::Key
);
222 extern Bool
tys_equal (HashTable::Key
, HashTable::Key
);