initial
[prop.git] / tools / misc / ty_setl.pcc
blob0fc71ea86365d520a890b0c543b901ce7718ce1e
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the 
5 // public domain.   The author(s) of this software reserve no copyrights on 
6 // the source code and any code generated using the tools.  You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are welcomed to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that 
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in 
15 // your programs, and that this notice be preserved intact in all the source 
16 // code.
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
21 // Allen Leung 
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 //////////////////////////////////////////////////////////////////////////////
26 //  This file implements the type analysis methods for the SETL sublanguage.
27 //  Type analysis is used to:
28 //     (a) Check for valid typing of the soruce program.
29 //     (b) Select implementations of the set-theoretic data structures.
31 //  For details, see Paige, Schwartz, Cai, et al.
32 //////////////////////////////////////////////////////////////////////////////
34 #include "irdef.ph"  //  intermediate representations
35 #include "setl.ph"   //  SETL abstract syntax
37 //////////////////////////////////////////////////////////////////////////////
38 // Method to infer the type a SETL expression when given an expression
39 // and an type binding environment.
40 //////////////////////////////////////////////////////////////////////////////
41 TY InferSETL::infer(EXPR e, Map<ID,TY>& env)
42 {  match (e) {
43       case om_exp:               return var_ty(no_ty);
44       case typed_exp    (e, ty):
45       case ident_exp    id:      return env[id];
46       case int_exp      _:       return Infer::integer_ty;
47       case real_exp     _:       return Infer::real_ty;
48       case string_exp   _:       return Infer::string_ty;
49       case char_exp     _:       return Infer::character_ty;
50       case app_exp      (e1,e2):  
51       case set_exp      es:      return set_ty(infer(es,env));
52       case multiset_exp es:      return multiset_ty(infer(es,env));
53       case tuple_exp    es:      return tuple_ty(infer(es,env));
54       case map_exp      es:      return map_ty(infer(es,env));
55       case multimap_exp es:      return multimap_ty(infer(es,env));
56       case record_exp   es:      return record_ty(infer(es,env));
57       case c_exp        _:       return var_ty(no_ty);
58    }