00001
00002
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 #include "AST.hxx"
00039 #include "Options.hxx"
00040 #include "UocInfo.hxx"
00041 #include "Type.hxx"
00042 #include "TypeScheme.hxx"
00043 #include "TypeMut.hxx"
00044 #include "Typeclass.hxx"
00045 #include "Trail.hxx"
00046 #include "inter-pass.hxx"
00047 #include "TypeInferCommon.hxx"
00048
00049
00050
00051
00052 bool
00053 typeInfer(std::ostream& errStream, GCPtr<AST> ast,
00054 GCPtr<Environment<TypeScheme> > gamma,
00055 GCPtr<Environment< CVector<GCPtr<Instance> > > > instEnv,
00056 GCPtr< CVector<GCPtr<Type> > >impTypes,
00057 bool isVP,
00058 GCPtr<TCConstraints> tcc,
00059 unsigned long uflags,
00060 GCPtr<Trail> trail,
00061 int mode,
00062 unsigned flags);
00063
00064 bool
00065 typeEqInfer(std::ostream& errStream, GCPtr<AST> ast,
00066 GCPtr<Environment<TypeScheme> > gamma,
00067 GCPtr<Environment< CVector<GCPtr<Instance> > > > instEnv,
00068 GCPtr< CVector<GCPtr<Type> > >impTypes,
00069 bool isVP,
00070 GCPtr<TCConstraints> tcc,
00071 unsigned long uflags,
00072 GCPtr<Trail> trail,
00073 int mode,
00074 unsigned flags);
00075
00076 std::string
00077 ctypeAsString(GCPtr<Type> t, GCPtr<Constraints> cset,
00078 bool showAllCts=false);
00079
00080
00081
00082
00083
00084 bool
00085 UocInfo::fe_typeCheck(std::ostream& errStream,
00086 bool init, unsigned long flags)
00087 {
00088
00089
00090
00091 #ifdef VERBOSE
00092 errStream << "Now Processing " << ifName;
00093 errStream << " ast = " << ast->astTypeName();
00094 errStream << std::endl;
00095 #endif
00096
00097 GCPtr<CVector<GCPtr<Type> > > impTypes = new CVector<GCPtr<Type> >;
00098 GCPtr<Trail> trail = new Trail;
00099 bool errFree = true;
00100
00101
00102 if(Options::inferenceAlgorithm == inf_eq)
00103 flags |= TYP_NO_PRELUDE;
00104
00105 if(init) {
00106
00107 if(flags & INF_REINIT) {
00108 assert(gamma);
00109 assert(gamma->parent);
00110 gamma = gamma->parent->newDefScope();
00111
00112 assert(instEnv);
00113 assert(instEnv->parent);
00114 instEnv = instEnv->parent->newDefScope();
00115 }
00116 else {
00117 gamma = new Environment<TypeScheme>(this->uocName);
00118 instEnv = new Environment< CVector<GCPtr<Instance> > >(this->uocName);
00119 }
00120 if((flags & TYP_NO_PRELUDE) == 0)
00121 CHKERR(errFree, initGamma(std::cerr, gamma, instEnv, ast, flags));
00122
00123 if(!errFree)
00124 return false;
00125 }
00126
00127 switch(Options::inferenceAlgorithm) {
00128 case inf_hm:
00129 {
00130 CHKERR(errFree, typeInfer(errStream, ast, gamma, instEnv,
00131 impTypes, false,
00132 new TCConstraints, flags, trail,
00133 USE_MODE, TI_NONE));
00134 break;
00135 }
00136 case inf_eq:
00137 {
00138 CHKERR(errFree, typeEqInfer(errStream, ast, gamma, instEnv,
00139 impTypes, false,
00140 new TCConstraints, flags, trail,
00141 USE_MODE, TI_NONE));
00142
00143
00144 errStream << "- - - - - - - - - - - - - - - - - - - - - - - " << endl;
00145 GCPtr<AST> mod = ast->child(0);
00146 for(size_t i=0; i < mod->children->size(); i++) {
00147 GCPtr<AST> ast = mod->child(i);
00148 errStream << ast->atKwd() << std::endl;
00149 if(ast->astType == at_define) {
00150 GCPtr<AST> id = ast->child(0)->child(0);
00151 errStream << id->asString() << ": "
00152 << ctypeAsString(id->scheme->tau, id->scheme->tcc)
00153 << std::endl;
00154 }
00155 }
00156 break;
00157 }
00158 }
00159
00160 CHKERR(errFree, checkImpreciseTypes(errStream, gamma, impTypes));
00161
00162 #ifdef VERBOSE
00163 errStream << "________________________________________" << std::endl;
00164 #endif
00165
00166 return errFree;
00167 }
00168