int ConstantList::checkDup(const char* name, ConstantList& committed, ConstantList& other, ConstantList& otherPend, bool priv, const char* cname) { if (inList(name)) { parse_error("%s constant \"%s\" is already pending in class \"%s\"", privpub(priv), name, cname); return -1; } // see if constant already exists in committed list if (committed.inList(name)) { parse_error("%s constant \"%s\" has already been added to class \"%s\"", privpub(priv), name, cname); return -1; } // see if constant is in the other pending list if (otherPend.inList(name)) { parse_error("%s constant \"%s\" is already pending in class \"%s\" as a %s constant", privpub(priv), name, cname, privpub(!priv)); return -1; } // see if constant is in the other committed list if (other.inList(name)) { parse_error("%s constant \"%s\" has already been added to class \"%s\" as a %s constant", privpub(priv), name, cname, privpub(!priv)); return -1; } return 0; }
ConstantList getConstantPool() const { ConstantList Constants; Constants.reserve(Pool.size()); // TODO: replace the loop with std::transform + lambdas. for (typename ContainerType::const_iterator I = Pool.begin(), E = Pool.end(); I != E; ++I) { Constants.push_back(I->second); } return Constants; }
void ConstantList::assimilate(ConstantList& n, ConstantList& committed, ConstantList& other, ConstantList& otherPend, bool priv, const char* cname) { for (cnemap_t::iterator i = n.cnemap.begin(), e = n.cnemap.end(); i != e; ++i) { if (!checkDup(i->first, committed, other, otherPend, priv, cname)) { cnemap[i->first] = i->second; i->second = 0; } } n.parseDeleteAll(); }
// duplicate checking is done here void ConstantList::assimilate(ConstantList& n, ConstantList& otherlist, const char* name) { // assimilate target list for (cnemap_t::iterator i = n.cnemap.begin(), e = n.cnemap.end(); i != e; ++i) { if (inList(i->first)) { parse_error("constant \"%s\" is already pending in namespace \"%s\"", i->first, name); continue; } if (otherlist.inList(i->first)) { parse_error("constant \"%s\" has already been defined in namespace \"%s\"", i->first, name); continue; } cnemap[i->first] = i->second; i->second = 0; } n.parseDeleteAll(); }
// no duplicate checking is done here void ConstantList::assimilate(ConstantList& n) { for (cnemap_t::iterator i = n.cnemap.begin(), e = n.cnemap.end(); i != e; ++i) { assert(!inList(i->first)); // "move" data to new list cnemap[i->first] = i->second; i->second = 0; } n.parseDeleteAll(); }
void KConstantEditor::updateConstantsList( ) { m_widget->constantList->blockSignals( true ); // This assumes that constants have only been added or their value changed. // (since constants can only be removed via this dialog) ConstantList constants = XParser::self()->constants()->list( Constant::All ); for ( ConstantList::iterator it = constants.begin(); it != constants.end(); ++it ) { QList<QTreeWidgetItem *> list = m_widget->constantList->findItems( it.key(), Qt::MatchExactly ); if ( !list.isEmpty() ) init( list.first(), it.key(), it.value() ); else { QTreeWidgetItem * item = new QTreeWidgetItem( m_widget->constantList ); init( item, it.key(), it.value() ); } } m_widget->constantList->blockSignals( false ); }
bool ReflectorPass::runOnModule(Module & module) { using llvm::Module; Module::GlobalListType & globals = module.getGlobalList(); for (Module::GlobalListType::iterator it = globals.begin(); it != globals.end(); ++it) { if (GlobalVariable * globalVar = dyn_cast<GlobalVariable>(it)) { if (globalVar->getName().startswith(".module")) { // errs() << globalVar->getName() << "\n"; modules_[globalVar->getName()] = globalVar; } else if (globalVar->getName().startswith(".package")) { // errs() << globalVar->getName() << "\n"; std::string packageName(globalVar->getName()); packageName.erase(0, 9); // remove ".package." /*Package * p =*/ getOrCreatePackage(packageName, globalVar); } } } if (!packages_.empty()) { Type * packageType = requireType("tart.reflect.Package", module); Type * moduleArrayType = requireType("tart.reflect.Module[]", module); Type * packageArrayType = requireType("tart.reflect.Package[]", module); Type * stringType = requireType("tart.core.String", module); Type * moduleType = requireType("tart.reflect.Module", module); Constant * emptyModuleArray = requireGlobal("tart.reflect.Module[].emptyArray", module); Constant * emptyPackageArray = requireGlobal("tart.reflect.Package[].emptyArray", module); Constant * packageTypeInfo = requireGlobal("tart.reflect.Package.TIB", module); Constant * packageArrayTypeInfo = requireGlobal("tart.reflect.Package[].TIB", module); Constant * moduleArrayTypeInfo = requireGlobal("tart.reflect.Module[].TIB", module); Constant * stringTypeInfo = requireGlobal("tart.core.String.TIB", module); for (GlobalVarMap::iterator it = modules_.begin(); it != modules_.end(); ++it) { GlobalVariable * moduleVar = it->second; std::string packageName(moduleVar->getName()); // remove everything after the last '.' packageName.erase(packageName.rfind('.'), packageName.npos); packageName.erase(0, 8); // remove ".module." Package * p = getOrCreateSubPackage(packageName, &module); if (p != NULL) { //errs() << "Package " << packageName << " found for module " << moduleVar->getName() << "\n"; p->addModule(moduleVar); } } for (PackageMap::iterator it = packages_.begin(); it != packages_.end(); ++it) { Package * p = it->second; // Start construction of the updated package structure. ConstantBuilder cb(module); cb.addObjectHeader(packageTypeInfo); // Object header if (p->global()->hasInitializer()) { ConstantRef packageConst = p->global()->getInitializer(); cb.addField(packageConst.operand(1)); // Package name } else { cb.addField(createString(module, stringTypeInfo, stringType, p->name())); } // List of modules in package if (!p->modules().empty()) { Type * modulePtrType = moduleType->getPointerTo(); ConstantList modules; std::sort(p->modules().begin(), p->modules().end(), ModuleNameComparator()); for (GlobalVarList::iterator m = p->modules().begin(); m != p->modules().end(); ++m) { modules.push_back(ConstantExpr::getPointerCast(*m, modulePtrType)); } cb.addField(createArray(module, modules, moduleArrayTypeInfo, moduleArrayType, ".modules." + p->name())); } else { cb.addField(emptyModuleArray); } // List of subpackages in package if (!p->subpackages().empty()) { ConstantList subpackages; std::sort(p->subpackages().begin(), p->subpackages().end(), PackageNameComparator()); for (PackageList::iterator m = p->subpackages().begin(); m != p->subpackages().end(); ++m) { Package * subPackage = *m; assert(subPackage->global() != NULL); subpackages.push_back(subPackage->global()); } cb.addField(createArray(module, subpackages, packageArrayTypeInfo, packageArrayType, ".subpackages." + p->name())); } else { cb.addField(emptyPackageArray); } p->global()->setInitializer(cb.buildStruct(packageType)); } } return false; }