void MainMenuWindow::fillModules()
	{
		MenuBase* modulesMenu = getMenu("MainMenu/Modules/Menu");

		ModuleMap modules = CoreSubsystem::getSingleton().getAllModules();
		mActiveModule = CoreSubsystem::getSingleton().getActiveAdventureModule();

		for(ModuleMap::iterator modIt = modules.begin();
			modIt != modules.end(); modIt++)
		{
			ContentModule* mod = (*modIt).second;

			if (!mod->isCommon())
			{
				if (mActiveModule == NULL)
					mActiveModule = mod;

				MenuItem* it = static_cast<MenuItem*>(
					CEGUI::WindowManager::getSingleton().createWindow("RastullahLook/MenuItem",
					getNamePrefix()+"MainMenu/Modules/" + mod->getId()));

				if (mod == mActiveModule)
					it->setText(mod->getName() + " *");
				else
					it->setText(mod->getName());
				modulesMenu->addItem(it);

				it->subscribeEvent(
					MenuItem::EventClicked,
					boost::bind(&MainMenuWindow::handleChooseModule, this, it, mod));
			}
		}
	}
Esempio n. 2
0
 void operator()(GlobalStatic<T>& globalStatic) const
 {
   ModuleMap* moduleMap = globalStatic.pointer;
   for (ModuleMap::const_iterator i = moduleMap->begin();
        i != moduleMap->end(); ++i)
   {
     delete i->second;
   }
   DefaultGlobalStaticDeleter<T> defaultDeleter;
   defaultDeleter(globalStatic);
 }
Esempio n. 3
0
void ModuleRegistry::Register(ModuleInfo* info)
{
  static long regCount = 0;
  if (info->id > 0)
  {
    // The module was already registered
    Module* module = 0;
    {
      MutexLocker lock(*modulesLock());
      module = modules()->operator[](info->id);
      assert(module != 0);
    }
    module->Start();
  }
  else
  {
    Module* module = 0;
    // check if the module is reloaded
    {
      MutexLocker lock(*modulesLock());
      ModuleMap* map = modules();
      for (ModuleMap::const_iterator i = map->begin();
           i != map->end(); ++i)
      {
        if (i->second->GetLocation() == info->location)
        {
          module = i->second;
          info->id = module->GetModuleId();
        }
      }
    }

    if (!module)
    {
      module = new Module();
      countLock()->Lock();
      info->id = ++regCount;
      countLock()->Unlock();

      module->Init(coreModuleContext(), info);

      MutexLocker lock(*modulesLock());
      ModuleMap* map = modules();
      map->insert(std::make_pair(info->id, module));
    }
    else
    {
      module->Init(coreModuleContext(), info);
    }

    module->Start();
  }
}
Esempio n. 4
0
void ModuleRegistry::GetModules(std::vector<Module*>& m)
{
  MutexLocker lock(*modulesLock());

  ModuleMap* map = modules();
  ModuleMap::const_iterator iter = map->begin();
  ModuleMap::const_iterator iterEnd = map->end();
  for (; iter != iterEnd; ++iter)
  {
    m.push_back(iter->second);
  }
}
Esempio n. 5
0
std::vector<Module*> ModuleRegistry::GetModules()
{
  MutexLock lock(*modulesLock());

  std::vector<Module*> result;
  ModuleMap* map = modules();
  ModuleMap::const_iterator iter = map->begin();
  ModuleMap::const_iterator iterEnd = map->end();
  for (; iter != iterEnd; ++iter)
  {
    result.push_back(iter->second);
  }
  return result;
}
Esempio n. 6
0
void 
VlgModule::cstTree(VlpHierTreeNode* const parent, const ModuleMap& moduleMap) const
{
   VlpInstance* inst = NULL;
   BaseModule* mn = NULL;
   VlpHierTreeNode* newNode = NULL;

   for (unsigned i = 0; i < getInstSize(); ++i) {
      inst = _instanceAry[i];
      unsigned instID = inst->getModuleID();
      if (moduleMap.getData(instID, mn) == false) {
         Msg(MSG_ERR) << "Error : The sub-module \"" << BaseModule :: getName(instID) 
              << "\" is not defined in the module \"" 
              << parent->getModule()->getModuleName() << "\"" << endl;
         exit(0);
      }
      newNode = inst->genHierTN(mn);
      parent->setChild(newNode);

      //============Handle pos mapping parameter overload===========//
      if (inst->getPOLSize() > 0) {//pos mapping
         assert (mn->isLibrary() == false);
         //pre-consider the parent module paramter overload ==> i.e. parameter propagation
         (static_cast<VlgModule*>(mn))
         ->setPOLMap(inst->getName(), inst->genPOLAry(static_cast<VlgModule*>(mn), parent));
      }
      //============================================================//
      if (!(mn->isBlackBox() || mn->isLibrary()))
         (static_cast<VlgModule*>(mn))->cstTree(newNode, moduleMap);
   }
}
Esempio n. 7
0
/// \brief Collect the set of header includes needed to construct the given
/// module and update the TopHeaders file set of the module.
///
/// \param Module The module we're collecting includes from.
///
/// \param Includes Will be augmented with the set of \#includes or \#imports
/// needed to load all of the named headers.
static void collectModuleHeaderIncludes(const LangOptions &LangOpts,
                                        FileManager &FileMgr,
                                        ModuleMap &ModMap,
                                        clang::Module *Module,
                                        SmallVectorImpl<char> &Includes) {
    // Don't collect any headers for unavailable modules.
    if (!Module->isAvailable())
        return;

    // Add includes for each of these headers.
    for (unsigned I = 0, N = Module->NormalHeaders.size(); I != N; ++I) {
        const FileEntry *Header = Module->NormalHeaders[I];
        Module->addTopHeader(Header);
        addHeaderInclude(Header, Includes, LangOpts);
    }
    // Note that Module->PrivateHeaders will not be a TopHeader.

    if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) {
        Module->addTopHeader(UmbrellaHeader);
        if (Module->Parent) {
            // Include the umbrella header for submodules.
            addHeaderInclude(UmbrellaHeader, Includes, LangOpts);
        }
    } else if (const DirectoryEntry *UmbrellaDir = Module->getUmbrellaDir()) {
        // Add all of the headers we find in this subdirectory.
        llvm::error_code EC;
        SmallString<128> DirNative;
        llvm::sys::path::native(UmbrellaDir->getName(), DirNative);
        for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative.str(), EC),
                DirEnd;
                Dir != DirEnd && !EC; Dir.increment(EC)) {
            // Check whether this entry has an extension typically associated with
            // headers.
            if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
                    .Cases(".h", ".H", ".hh", ".hpp", true)
                    .Default(false))
                continue;

            // If this header is marked 'unavailable' in this module, don't include
            // it.
            if (const FileEntry *Header = FileMgr.getFile(Dir->path())) {
                if (ModMap.isHeaderInUnavailableModule(Header))
                    continue;
                Module->addTopHeader(Header);
            }

            // Include this header umbrella header for submodules.
            addHeaderInclude(Dir->path(), Includes, LangOpts);
        }
    }

    // Recurse into submodules.
    for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
            SubEnd = Module->submodule_end();
            Sub != SubEnd; ++Sub)
        collectModuleHeaderIncludes(LangOpts, FileMgr, ModMap, *Sub, Includes);
}
Esempio n. 8
0
File: qbc.cpp Progetto: zhaobr/qbrt
void load_imported_modules(ModuleMap &modmap, const set< string > &modnames)
{
	set< string >::const_iterator it(modnames.begin());
	map< string, Module * > modules;
	for (; it!=modnames.end(); ++it) {
		if (modmap.find(*it) != modmap.end()) {
			continue;
		}
		Module *mod = read_module(*it);
		if (!mod) {
			compile_module(modmap, *it);
			mod = read_module(*it);
			if (!mod) {
				cerr << "could not load module: "<< (*it) & DIE;
			}
			modmap[*it] = mod;
		}
	}
}
Esempio n. 9
0
int moduleReportList(Report_TYPE type, const Proc_LIST &processList, const wchar_t *TitleIn)
{
    int				iReturnCode=DIAGLIB_OK;
    std::wstring	Title;
    ModuleMap		modules;

    if(TitleIn!=NULL)
        Title=TitleIn;
    else
        Title=L"Module list";

    reportPrintHeader2(type, Title.c_str(), REPORT_PROCESS_SEPARATOR);

    progressInit(processList.size());

    Proc_INFO info;
    Proc_LIST::const_iterator itr;
    for(itr=processList.begin(); itr!=processList.end(); itr++)
    {
        if(DIAGLIB_OK == processGetInfo(*itr,&info))
        {
            for(ModuleSet::const_iterator i=info.modulesLoaded.begin(); i!=info.modulesLoaded.end(); i++)
                modules[*i].insert(info.Name);
        }
        progressIncrement();
    }

    for(ModuleMap::const_iterator i=modules.begin(); i!=modules.end(); i++)
    {
        moduleReportInfo(type,i->first,i->second);
        moduleContributeInfo(i->first,i->second);
    }

    progressRelease();

    return iReturnCode;
}
Esempio n. 10
0
//=======The function handle name mapping parameter overload=========//
void 
VlgModule::NamePOL_Module(const ModuleMap& moduleMap) const
{
   if (_paramNOLMap.getSize() > 0) { //parameter overload (name mapping)
      vector<string> instNameAry;
      vector<POLAry> NPA_vector; //OL Param Array
      _paramNOLMap.dfs_key(instNameAry);
      _paramNOLMap.dfs_data(NPA_vector);
      VlpInstance* instance;
      BaseModule* mn;

      for (unsigned i = 0; i < instNameAry.size(); ++i) {
         instance = getInst(instNameAry[i]);
         if (instance == NULL) {
            Msg(MSG_ERR) << "Error : Instance \"" << instNameAry[i] << "\" doesn't exist in " 
                 << getFileName() << endl;
            exit(0);
         }
         moduleMap.getData(instance->getModuleID(), mn);
         assert (mn->isLibrary() == false);
         (static_cast<VlgModule*>(mn))->setPOLMap( instance->getName(), &(NPA_vector[i]) );
      }
   }
}
Esempio n. 11
0
/// \brief Collect the set of header includes needed to construct the given 
/// module and update the TopHeaders file set of the module.
///
/// \param Module The module we're collecting includes from.
///
/// \param Includes Will be augmented with the set of \#includes or \#imports
/// needed to load all of the named headers.
static std::error_code
collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
                            ModuleMap &ModMap, clang::Module *Module,
                            SmallVectorImpl<char> &Includes) {
  // Don't collect any headers for unavailable modules.
  if (!Module->isAvailable())
    return std::error_code();

  // Add includes for each of these headers.
  for (Module::Header &H : Module->Headers[Module::HK_Normal]) {
    Module->addTopHeader(H.Entry);
    // Use the path as specified in the module map file. We'll look for this
    // file relative to the module build directory (the directory containing
    // the module map file) so this will find the same file that we found
    // while parsing the module map.
    if (std::error_code Err = addHeaderInclude(H.NameAsWritten, Includes,
                                               LangOpts, Module->IsExternC))
      return Err;
  }
  // Note that Module->PrivateHeaders will not be a TopHeader.

  if (const FileEntry *UmbrellaHeader = Module->getUmbrellaHeader()) {
    // FIXME: Track the name as written here.
    Module->addTopHeader(UmbrellaHeader);
    if (Module->Parent) {
      // Include the umbrella header for submodules.
      if (std::error_code Err = addHeaderInclude(UmbrellaHeader, Includes,
                                                 LangOpts, Module->IsExternC))
        return Err;
    }
  } else if (const DirectoryEntry *UmbrellaDir = Module->getUmbrellaDir()) {
    // Add all of the headers we find in this subdirectory.
    std::error_code EC;
    SmallString<128> DirNative;
    llvm::sys::path::native(UmbrellaDir->getName(), DirNative);
    for (llvm::sys::fs::recursive_directory_iterator Dir(DirNative, EC), 
                                                     DirEnd;
         Dir != DirEnd && !EC; Dir.increment(EC)) {
      // Check whether this entry has an extension typically associated with 
      // headers.
      if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
          .Cases(".h", ".H", ".hh", ".hpp", true)
          .Default(false))
        continue;

      const FileEntry *Header = FileMgr.getFile(Dir->path());
      // FIXME: This shouldn't happen unless there is a file system race. Is
      // that worth diagnosing?
      if (!Header)
        continue;

      // If this header is marked 'unavailable' in this module, don't include 
      // it.
      if (ModMap.isHeaderUnavailableInModule(Header, Module))
        continue;

      // Include this header as part of the umbrella directory.
      // FIXME: Track the name as written through to here.
      Module->addTopHeader(Header);
      if (std::error_code Err =
              addHeaderInclude(Header, Includes, LangOpts, Module->IsExternC))
        return Err;
    }

    if (EC)
      return EC;
  }

  // Recurse into submodules.
  for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
                                      SubEnd = Module->submodule_end();
       Sub != SubEnd; ++Sub)
    if (std::error_code Err = collectModuleHeaderIncludes(
            LangOpts, FileMgr, ModMap, *Sub, Includes))
      return Err;

  return std::error_code();
}
Esempio n. 12
0
bool checkModule(string const & name, bool command)
{
	// Cache to avoid slowdown by repated searches
	static set<string> failed[2];

	// Only add the module if the command was actually defined in the LyX preamble
	if (command) {
		if (possible_textclass_commands.find('\\' + name) == possible_textclass_commands.end())
			return false;
	} else {
		if (possible_textclass_environments.find(name) == possible_textclass_environments.end())
			return false;
	}
	if (failed[command].find(name) != failed[command].end())
		return false;

	// Create list of dummy document classes if not already done.
	// This is needed since a module cannot be read on its own, only as
	// part of a document class.
	LayoutFile const & baseClass = LayoutFileList::get()[textclass.name()];
	typedef map<string, DocumentClass *> ModuleMap;
	static ModuleMap modules;
	static bool init = true;
	if (init) {
		baseClass.load();
		DocumentClassBundle & bundle = DocumentClassBundle::get();
		LyXModuleList::const_iterator const end = theModuleList.end();
		LyXModuleList::const_iterator it = theModuleList.begin();
		for (; it != end; it++) {
			string const module = it->getID();
			LayoutModuleList m;
			// FIXME this excludes all modules that depend on another one
			if (!m.moduleCanBeAdded(module, &baseClass))
				continue;
			m.push_back(module);
			modules[module] = &bundle.makeDocumentClass(baseClass, m);
		}
		init = false;
	}

	// Try to find a module that defines the command.
	// Only add it if the definition can be found in the preamble of the
	// style that corresponds to the command. This is a heuristic and
	// different from the way how we parse the builtin commands of the
	// text class (in that case we only compare the name), but it is
	// needed since it is not unlikely that two different modules define a
	// command with the same name.
	ModuleMap::iterator const end = modules.end();
	for (ModuleMap::iterator it = modules.begin(); it != end; it++) {
		string const module = it->first;
		if (!used_modules.moduleCanBeAdded(module, &baseClass))
			continue;
		if (findLayoutWithoutModule(textclass, name, command))
			continue;
		if (findInsetLayoutWithoutModule(textclass, name, command))
			continue;
		DocumentClass const * c = it->second;
		Layout const * layout = findLayoutWithoutModule(*c, name, command);
		InsetLayout const * insetlayout = layout ? 0 :
			findInsetLayoutWithoutModule(*c, name, command);
		docstring preamble;
		if (layout)
			preamble = layout->preamble();
		else if (insetlayout)
			preamble = insetlayout->preamble();
		if (preamble.empty())
			continue;
		bool add = false;
		if (command) {
			FullCommand const & cmd =
				possible_textclass_commands['\\' + name];
			if (preamble.find(cmd.def) != docstring::npos)
				add = true;
		} else {
			FullEnvironment const & env =
				possible_textclass_environments[name];
			if (preamble.find(env.beg) != docstring::npos &&
			    preamble.find(env.end) != docstring::npos)
				add = true;
		}
		if (add) {
			FileName layout_file = libFileSearch("layouts", module, "module");
			if (textclass.read(layout_file, TextClass::MODULE)) {
				used_modules.push_back(module);
				// speed up further searches:
				// the module does not need to be checked anymore.
				modules.erase(it);
				return true;
			}
		}
	}
	failed[command].insert(name);
	return false;
}
Esempio n. 13
0
/// \brief Collect the set of header includes needed to construct the given 
/// module and update the TopHeaders file set of the module.
///
/// \param Module The module we're collecting includes from.
///
/// \param Includes Will be augmented with the set of \#includes or \#imports
/// needed to load all of the named headers.
static std::error_code
collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr,
                            ModuleMap &ModMap, clang::Module *Module,
                            SmallVectorImpl<char> &Includes) {
  // Don't collect any headers for unavailable modules.
  if (!Module->isAvailable())
    return std::error_code();

  // Add includes for each of these headers.
  for (auto HK : {Module::HK_Normal, Module::HK_Private}) {
    for (Module::Header &H : Module->Headers[HK]) {
      Module->addTopHeader(H.Entry);
      // Use the path as specified in the module map file. We'll look for this
      // file relative to the module build directory (the directory containing
      // the module map file) so this will find the same file that we found
      // while parsing the module map.
      addHeaderInclude(H.NameAsWritten, Includes, LangOpts, Module->IsExternC);
    }
  }
  // Note that Module->PrivateHeaders will not be a TopHeader.

  if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) {
    Module->addTopHeader(UmbrellaHeader.Entry);
    if (Module->Parent)
      // Include the umbrella header for submodules.
      addHeaderInclude(UmbrellaHeader.NameAsWritten, Includes, LangOpts,
                       Module->IsExternC);
  } else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) {
    // Add all of the headers we find in this subdirectory.
    std::error_code EC;
    SmallString<128> DirNative;
    llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);

    vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem();
    for (vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End;
         Dir != End && !EC; Dir.increment(EC)) {
      // Check whether this entry has an extension typically associated with 
      // headers.
      if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->getName()))
          .Cases(".h", ".H", ".hh", ".hpp", true)
          .Default(false))
        continue;

      const FileEntry *Header = FileMgr.getFile(Dir->getName());
      // FIXME: This shouldn't happen unless there is a file system race. Is
      // that worth diagnosing?
      if (!Header)
        continue;

      // If this header is marked 'unavailable' in this module, don't include 
      // it.
      if (ModMap.isHeaderUnavailableInModule(Header, Module))
        continue;

      // Compute the relative path from the directory to this file.
      SmallVector<StringRef, 16> Components;
      auto PathIt = llvm::sys::path::rbegin(Dir->getName());
      for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt)
        Components.push_back(*PathIt);
      SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten);
      for (auto It = Components.rbegin(), End = Components.rend(); It != End;
           ++It)
        llvm::sys::path::append(RelativeHeader, *It);

      // Include this header as part of the umbrella directory.
      Module->addTopHeader(Header);
      addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC);
    }

    if (EC)
      return EC;
  }

  // Recurse into submodules.
  for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
                                      SubEnd = Module->submodule_end();
       Sub != SubEnd; ++Sub)
    if (std::error_code Err = collectModuleHeaderIncludes(
            LangOpts, FileMgr, ModMap, *Sub, Includes))
      return Err;

  return std::error_code();
}