static void initModule(ModulePtr m) { if (m->initialized) return; m->initialized = true; vector<ImportPtr>::iterator ii, iend; for (ii = m->imports.begin(), iend = m->imports.end(); ii != iend; ++ii) initModule((*ii)->module); if (m->declaration != NULL) { if (m->moduleName == "") m->moduleName = toKey(m->declaration->name); else if (m->moduleName != toKey(m->declaration->name)) error(m->declaration, "module imported by name " + m->moduleName + " but declared with name " + toKey(m->declaration->name) ); } else if (m->moduleName == "") m->moduleName = "__main__"; verifyAttributes(m); const vector<TopLevelItemPtr> &items = m->topLevelItems; vector<TopLevelItemPtr>::const_iterator ti, tend; for (ti = items.begin(), tend = items.end(); ti != tend; ++ti) { Object *obj = ti->ptr(); switch (obj->objKind) { case OVERLOAD : initOverload((Overload *)obj); break; case INSTANCE : initVariantInstance((Instance *)obj); break; } } if (llvmDIBuilder != NULL) { llvm::DIFile file = m->location == NULL ? llvm::DIFile(NULL) : m->location->source->getDebugInfo(); m->debugInfo = (llvm::MDNode*)llvmDIBuilder->createNameSpace( llvm::DICompileUnit(llvmDIBuilder->getCU()), // scope m->moduleName, // name file, // file 1 // line ); } }
static void initModule(ModulePtr m, llvm::ArrayRef<string> importChain) { if (m->initState == Module::DONE) return; if (m->declaration != NULL) { if (m->moduleName == "") m->moduleName = toKey(m->declaration->name); else if (m->moduleName != toKey(m->declaration->name)) error(m->declaration, "module imported by name " + m->moduleName + " but declared with name " + toKey(m->declaration->name) ); } else if (m->moduleName == "") m->moduleName = "__main__"; if (m->initState == Module::RUNNING && !importChain.empty()) { // allow prelude to import self if (importChain.back() == m->moduleName) { return; } } vector<string> importChainNext = importChain; importChainNext.push_back(m->moduleName); if (m->initState == Module::RUNNING) { circularImportsError(importChainNext); } m->initState = Module::RUNNING; vector<ImportPtr>::iterator ii, iend; for (ii = m->imports.begin(), iend = m->imports.end(); ii != iend; ++ii) initModule((*ii)->module, importChainNext); m->initState = Module::DONE; verifyAttributes(m); llvm::ArrayRef<TopLevelItemPtr> items = m->topLevelItems; TopLevelItemPtr const *ti, *tend; for (ti = items.begin(), tend = items.end(); ti != tend; ++ti) { Object *obj = ti->ptr(); switch (obj->objKind) { case OVERLOAD : initOverload((Overload *)obj); break; case INSTANCE_DECL : initVariantInstance((InstanceDecl *)obj); break; case STATIC_ASSERT_TOP_LEVEL: checkStaticAssert((StaticAssertTopLevel *)obj); break; default: break; } } if (llvmDIBuilder != NULL) { llvm::DIFile file = m->location.ok() ? m->location.source->getDebugInfo() : llvm::DIFile(NULL); m->debugInfo = (llvm::MDNode*)llvmDIBuilder->createNameSpace( llvm::DICompileUnit(llvmDIBuilder->getCU()), // scope m->moduleName, // name file, // file 1 // line ); } }