00001 #ifndef UOCINFO_HXX
00002 #define UOCINFO_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 <set>
00042 #include <string>
00043 #include <ostream>
00044
00045 #include <boost/filesystem/path.hpp>
00046 #include <libsherpa/LexLoc.hxx>
00047
00048 #include "Environment.hxx"
00049 #include "AST.hxx"
00050 #include "TypeScheme.hxx"
00051 #include "Symtab.hxx"
00052 #include "TypeInfer.hxx"
00053 #include "WorkList.hxx"
00054
00055 enum UocFlagValues {
00056 UOC_NO_FLAGS = 0,
00057
00061 UOC_IS_PRELUDE = 0x1u,
00062
00068 UOC_IS_MUTABLE = 0x2u,
00069
00071 UOC_SEEN_BY_INST = 0x4u,
00072 };
00073
00074 typedef sherpa::EnumSet<UocFlagValues> UocFlags;
00075
00076
00077
00078
00079
00080 enum Pass {
00081 #define PASS(nm, short, descrip) pn_##nm,
00082 #include "pass.def"
00083 };
00084
00085 enum OnePass {
00086 #define ONEPASS(nm, short, descrip) op_##nm,
00087 #include "onepass.def"
00088 };
00089
00090 class UocInfo;
00091
00092 struct PassInfo {
00093 const char *name;
00094 bool (UocInfo::* fn)(std::ostream& errStream,
00095 bool init, unsigned long flags);
00096 const char *descrip;
00097 bool printAfter;
00098 bool typesAfter;
00099 bool stopAfter;
00100 };
00101
00102 struct OnePassInfo {
00103 const char *name;
00104 bool (UocInfo::* fn)(std::ostream& errStream,
00105 bool init, unsigned long flags);
00106 const char *descrip;
00107 bool printAfter;
00108 bool typesAfter;
00109 bool stopAfter;
00110 };
00111
00112
00113 class UocInfo;
00114 typedef std::map<std::string, boost::shared_ptr<UocInfo> > UocMap;
00115
00116
00117
00118
00119
00120 class UocInfo : public boost::enable_shared_from_this<UocInfo> {
00121 static boost::filesystem::path resolveInterfacePath(std::string ifName);
00122
00123 public:
00124 std::string uocName;
00125 std::string origin;
00126 UocFlags flags;
00127
00128 Pass lastCompletedPass;
00129
00130 bool fromCommandLine;
00131 boost::shared_ptr<AST> uocAst;
00132 boost::shared_ptr<ASTEnvironment > env;
00133 boost::shared_ptr<TSEnvironment > gamma;
00134 boost::shared_ptr<InstEnvironment > instEnv;
00135
00136 inline bool isSourceUoc() {
00137 return (uocAst->astType == at_module);
00138 }
00139
00140 inline bool isInterfaceUoc() {
00141 return (uocAst->astType == at_interface);
00142 }
00143
00144
00145 UocInfo(const std::string& _uocName, const std::string& _origin,
00146 boost::shared_ptr<AST> _uocAst);
00147 UocInfo(boost::shared_ptr<UocInfo> uoc);
00148
00149 static inline boost::shared_ptr<UocInfo>
00150 make(const std::string& _uocName, const std::string& _origin,
00151 boost::shared_ptr<AST> _uocAst) {
00152 UocInfo *tmp = new UocInfo(_uocName, _origin, _uocAst);
00153 return boost::shared_ptr<UocInfo>(tmp);
00154 }
00155
00156 static inline boost::shared_ptr<UocInfo>
00157 make(boost::shared_ptr<UocInfo> uoc) {
00158 UocInfo *tmp = new UocInfo(uoc);
00159 return boost::shared_ptr<UocInfo>(tmp);
00160 }
00161
00162
00163
00164
00165 static boost::shared_ptr<UocInfo> CreateUnifiedUoC();
00166
00167 static std::vector<boost::filesystem::path> searchPath;
00168
00169
00170
00171
00172
00173
00174 static UocMap ifList;
00175 static UocMap srcList;
00176
00177
00178 static boost::shared_ptr<UocInfo>
00179 findInterface(const std::string& ifName);
00180
00181 static boost::shared_ptr<UocInfo>
00182 importInterface(std::ostream&, const sherpa::LexLoc& loc,
00183 const std::string& ifName);
00184
00185
00186
00187 static std::string
00188 UocNameFromSrcName(const std::string& srcFileName, unsigned ndx);
00189
00190
00191
00192 static bool
00193 CompileFromFile(const boost::filesystem::path& src, bool fromCmdLine);
00194
00195
00196 #define PASS(nm,short,descrip) \
00197 bool fe_##nm(std::ostream& errStream, \
00198 bool init=true, unsigned long flags=0);
00199 #include "pass.def"
00200
00201 #define ONEPASS(nm,short,descrip) \
00202 bool be_##nm(std::ostream& errStream, \
00203 bool init=true, unsigned long flags=0);
00204 #include "onepass.def"
00205
00206 static PassInfo passInfo[];
00207 static OnePassInfo onePassInfo[];
00208
00209 static bool mainIsDefined;
00210 void Compile();
00211 void DoBackend();
00212
00213 void PrettyPrint(std::ostream& out, bool decorate=false);
00214 void ShowTypes(std::ostream& out);
00215
00216
00218
00219
00220
00222 void findDefForms(boost::shared_ptr<AST> start,
00223 boost::shared_ptr<AST> local=boost::GC_NULL,
00224 boost::shared_ptr<AST> top=boost::GC_NULL);
00225 static void findAllDefForms();
00226
00227
00228 static void addAllCandidateEPs();
00229
00230
00231
00232 void wrapEnvs();
00233 void unwrapEnvs();
00234
00235
00236 #define PI_SYM_FLAGS (RSLV_NO_RESOLVE_DECL)
00237 #define PI_TYP_FLAGS (TI_ALL_INSTS_OK)
00238
00239
00240 #define OP_SYM_FLAGS (PI_SYM_FLAGS | RSLV_SYM_NO_PRELUDE)
00241 #define OP_TYP_FLAGS (PI_TYP_FLAGS | TI_NO_PRELUDE)
00242
00243
00244 #define POLY_SYM_FLAGS (OP_SYM_FLAGS)
00245 #define POLY_TYP_FLAGS (OP_TYP_FLAGS | TI_NO_MORE_TC | \
00246 TI_DEF_DECL_NO_MATCH | TI_USING_FQNS)
00247
00248
00249 #define REF_SYM_FLAGS (POLY_SYM_FLAGS | RSLV_INCOMPLETE_NO_CHK)
00250 #define REF_TYP_FLAGS (POLY_TYP_FLAGS)
00251
00252
00253 #define CL_SYM_FLAGS (REF_SYM_FLAGS)
00254 #define CL_TYP_FLAGS (REF_TYP_FLAGS)
00255
00256
00257 bool DoResolve(std::ostream& errStream, bool init,
00258 ResolverFlags rflags);
00259
00260 bool Resolve(std::ostream& errStream, bool init,
00261 ResolverFlags rflags, std::string pre);
00262
00263 bool
00264 DoTypeCheck(std::ostream& errStream, bool init,
00265 TI_Flags ti_flags);
00266
00267 bool
00268 TypeCheck(std::ostream& errStream, bool init,
00269 TI_Flags ti_flags, std::string pre);
00270
00271 bool RandT(std::ostream& errStream,
00272 bool init=false,
00273 ResolverFlags rflags= RSLV_NO_FLAGS,
00274 TI_Flags ti_flags=TI_NO_FLAGS,
00275 std::string pre = "Internal Compiler error :");
00276
00277 bool RandTexpr(std::ostream& errStream,
00278 boost::shared_ptr<AST> ast,
00279 ResolverFlags rflags= RSLV_NO_FLAGS,
00280 TI_Flags ti_flags=TI_NO_FLAGS,
00281 std::string pre = "Internal Compiler error :",
00282 bool keepResults = true,
00283 boost::shared_ptr<EnvSet> altEnvSet=boost::GC_NULL);
00284
00286
00287
00288
00290 static boost::shared_ptr<AST> lookupByFqn(const FQName& fqn,
00291 boost::shared_ptr<UocInfo> &targetUoc);
00292
00293
00294 private:
00295 void addTopLevelForm(boost::shared_ptr<AST> ast);
00296
00297 bool instantiateFQN(std::ostream &errStream,
00298 const FQName& fqn);
00299
00300
00301 boost::shared_ptr<AST> doInstantiate(std::ostream &errStream,
00302 boost::shared_ptr<AST> defAST,
00303 boost::shared_ptr<Type> typ,
00304 bool &errFree,
00305 WorkList<std::string>& worklist);
00306
00307 boost::shared_ptr<AST> recInstantiate(std::ostream &errStream,
00308 boost::shared_ptr<AST> ast,
00309 bool &errFree,
00310 WorkList<std::string>& worklist);
00311
00312
00313 public:
00315 bool instantiate(std::ostream &errStream,
00316 const FQName& fqn);
00317
00319 bool instantiateBatch(std::ostream &errStream,
00320 std::set<FQName>& epName);
00321
00322 };
00323
00324 #endif