00001 #ifndef TYPECLASS_HXX
00002 #define TYPECLASS_HXX
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdlib.h>
00042 #include <dirent.h>
00043 #include <fstream>
00044 #include <iostream>
00045 #include <string>
00046 #include <set>
00047
00048 #include "AST.hxx"
00049 #include "Type.hxx"
00050
00051 struct TypeScheme;
00052 struct TCConstraints;
00053
00054 typedef Type Typeclass;
00055 typedef Typeclass Constraint;
00056 typedef TCConstraints Constraints;
00057
00058 typedef TypeSet TypeclassSet;
00059 typedef TypeSet ConstraintSet;
00060
00061 struct Instance {
00062 boost::shared_ptr<TypeScheme> ts;
00063 boost::shared_ptr<AST> ast;
00064
00065 Instance(boost::shared_ptr<TypeScheme> _ts, boost::shared_ptr<AST>_ins)
00066 {
00067 ts = _ts;
00068 ast = _ins;
00069 }
00070
00071 static inline boost::shared_ptr<Instance>
00072 make(boost::shared_ptr<TypeScheme> _ts, boost::shared_ptr<AST>_ins) {
00073 Instance *tmp = new Instance(_ts, _ins);
00074 return boost::shared_ptr<Instance>(tmp);
00075 }
00076
00077 bool equals(boost::shared_ptr<Instance> ins,
00078 boost::shared_ptr<const InstEnvironment > instEnv) const;
00079 bool overlaps(boost::shared_ptr<Instance> ins) const;
00080 bool satisfies(boost::shared_ptr<Typeclass> pred,
00081 boost::shared_ptr<const InstEnvironment > instEnv) const;
00082 std::string asString() const;
00083
00084 std::string asXML();
00085 void asXML(sherpa::INOstream &out);
00086
00087 int operator<(const struct Instance& rhs) const {
00088 return (asString() < rhs.asString());
00089 }
00090 };
00091
00092
00093
00094
00095 static int operator<(const boost::shared_ptr<Instance>& lhs,
00096 const boost::shared_ptr<Instance>& rhs)
00097 {
00098 return (*lhs) < (*rhs);
00099 }
00100
00101
00102
00103
00104
00105 struct TCConstraints {
00106
00107 TypeSet pred;
00108 typedef TypeSet::iterator iterator;
00109
00110 TCConstraints()
00111 {
00112 }
00113
00114 bool empty() const {
00115 return pred.empty();
00116 }
00117
00118 size_t size() const {
00119 return pred.size();
00120 }
00121
00122 void addPred(boost::shared_ptr<Typeclass> tc);
00123 void clearPred(boost::shared_ptr<Constraint> ct);
00124
00125 void normalize();
00126
00127 bool contains(boost::shared_ptr<Typeclass> tc);
00128
00129 void collectAllFnDeps(TypeSet& fnDeps);
00130
00131
00132
00133 static void close(TypeSet& closure,
00134 const TypeSet& fnDeps);
00135 void clearHintsOnPreds(boost::shared_ptr<Trail> trail);
00136
00137 iterator begin() {
00138 return pred.begin();
00139 }
00140 iterator end() {
00141 return pred.end();
00142 }
00143
00144 static inline boost::shared_ptr<TCConstraints>
00145 make() {
00146 TCConstraints *tmp = new TCConstraints();
00147 return boost::shared_ptr<TCConstraints>(tmp);
00148 }
00149 };
00150
00151
00152 #endif
00153