1 ///////////////////////////////////////////////////////////////////////////////
3 // This file describes the interface of the constraint compiler.
5 ///////////////////////////////////////////////////////////////////////////////
6 #ifndef constraint_compiler_h
7 #define constraint_compiler_h
13 ///////////////////////////////////////////////////////////////////////////////
15 // Forward datatype declarations
17 ///////////////////////////////////////////////////////////////////////////////
18 datatype Ty // Type expressions
20 and Exp // Expressions
21 and Decl // Prop declarations
22 and Def // Definitions
23 and Stmt // Statements
24 and Instness // Instantiatedness
25 and Determinism // Determinism of a predicate
30 ///////////////////////////////////////////////////////////////////////////////
32 // The grammar of the constraint rules is defined as follows:
34 ///////////////////////////////////////////////////////////////////////////////
35 datatype ConstraintSet : Loc =
36 CONSTRAINTset (ConstraintDefs)
38 and ConstraintDef : Loc =
39 CONSTRAINTruledef ConstraintRule // rule definition
40 | CONSTRAINTtype (Id, Ty) // type constraint
41 | CONSTRAINTinstness (Id, Pat) // instness definition
42 | CONSTRAINTdet (Id, Pats, Determinism) // determinism const.
44 and ConstraintRule : Loc =
45 CONSTRAINTrule { id : Id, // the functor name
46 pat : Pat, // pattern argument
47 body : ConstraintBody, // clause body
48 ty : Ty = NOty // optional type
51 and ConstraintBody : Loc =
54 | CONSTRAINTand (ConstraintBody, ConstraintBody)
55 | CONSTRAINTif (ConstraintBody, ConstraintBody, ConstraintBody)
56 | CONSTRAINTbody (List<Decl>)
57 | CONSTRAINTcall (Exp)
59 where type ConstraintDefs = List<ConstraintDef>
60 and ConstraintRules = List<ConstraintRule>
63 ///////////////////////////////////////////////////////////////////////////////
65 // Pretty printing routines.
67 ///////////////////////////////////////////////////////////////////////////////
68 extern std::ostream& operator << (std::ostream&, ConstraintSet);
69 extern std::ostream& operator << (std::ostream&, ConstraintDef);
70 extern std::ostream& operator << (std::ostream&, ConstraintDefs);
71 extern std::ostream& operator << (std::ostream&, ConstraintRule);
72 extern std::ostream& operator << (std::ostream&, ConstraintRules);
73 extern std::ostream& operator << (std::ostream&, ConstraintBody);
75 ///////////////////////////////////////////////////////////////////////////////
77 // Forward declaration.
79 ///////////////////////////////////////////////////////////////////////////////
80 class ConstraintCompilerInternal;
82 ///////////////////////////////////////////////////////////////////////////////
84 // The constraint compiler is inherited from the code generator.
86 ///////////////////////////////////////////////////////////////////////////////
87 class ConstraintCompiler : virtual public CodeGen,
88 virtual public MatchCompiler {
90 ConstraintCompiler(const ConstraintCompiler&); // no copy constructor
91 void operator = (const ConstraintCompiler&); // no assignment
95 ConstraintCompilerInternal * internal; // internal implementation
98 ////////////////////////////////////////////////////////////////////////////
100 // Constructor and destructor
102 ////////////////////////////////////////////////////////////////////////////
103 ConstraintCompiler();
104 virtual ~ConstraintCompiler();
106 ////////////////////////////////////////////////////////////////////////////
108 // Methods for compiling a set of constraint rules.
110 ////////////////////////////////////////////////////////////////////////////
111 void compile_ruleset (Id class_name, ConstraintSet rule_set);
114 ////////////////////////////////////////////////////////////////////////////
116 // Private implementation methods.
118 ////////////////////////////////////////////////////////////////////////////
119 void process_typing_rules (Id, List<.[Id,Ty]>);
120 void process_ruleset (Id, ConstraintRules);
121 void add_predicate_type (Id, Ty);
122 void analyze_rule (ConstraintBody);