gcc config
[prop.git] / prop-src / constraint.ph
blob4feaae02899ffb8715e357b0280fda8ce012dfbc
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file describes the interface of the constraint compiler.
4 //
5 ///////////////////////////////////////////////////////////////////////////////
6 #ifndef constraint_compiler_h
7 #define constraint_compiler_h
9 #include "basics.ph"
10 #include "codegen.h"
11 #include "matchcom.h"
13 ///////////////////////////////////////////////////////////////////////////////
15 //  Forward datatype declarations
17 ///////////////////////////////////////////////////////////////////////////////
18 datatype Ty          //  Type expressions
19      and Pat         //  Patterns
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
28 class HashTable;
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
49                            }
51 and      ConstraintBody    : Loc =
52             CONSTRAINTnone
53          |  CONSTRAINTcut    
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
93 protected:
95    ConstraintCompilerInternal * internal;  // internal implementation
97 public:
98    ////////////////////////////////////////////////////////////////////////////
99    //
100    //  Constructor and destructor
101    //
102    ////////////////////////////////////////////////////////////////////////////
103             ConstraintCompiler();
104    virtual ~ConstraintCompiler();
105    
106    ////////////////////////////////////////////////////////////////////////////
107    //
108    //  Methods for compiling a set of constraint rules.
109    //
110    ////////////////////////////////////////////////////////////////////////////
111    void compile_ruleset   (Id class_name, ConstraintSet rule_set);
113 private:
114    ////////////////////////////////////////////////////////////////////////////
115    //
116    //  Private implementation methods.
117    //
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);
126 #endif