From dd7f06be4d8687cd4ed45a41aac674ec50e645ed Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Thu, 15 Apr 2010 11:29:12 -0300 Subject: TypeDatabase class moved to its own header/cpp. --- typesystem.h | 266 ----------------------------------------------------------- 1 file changed, 266 deletions(-) (limited to 'typesystem.h') diff --git a/typesystem.h b/typesystem.h index 662cb53e1..34f60b0d5 100644 --- a/typesystem.h +++ b/typesystem.h @@ -1758,272 +1758,6 @@ struct TypeRejection QString enum_name; }; -class APIEXTRACTOR_API TypeDatabase -{ - TypeDatabase(); - TypeDatabase(const TypeDatabase&); - TypeDatabase& operator=(const TypeDatabase&); -public: - - /** - * Return the type system instance. - * \param newInstance This parameter is usefull just for unit testing, because singletons causes - * too many side effects on unit testing. - */ - static TypeDatabase *instance(bool newInstance = false); - - static QString normalizedSignature(const char* signature); - - QStringList requiredTargetImports() - { - return m_requiredTargetImports; - } - - void addRequiredTargetImport(const QString &moduleName) - { - if (!m_requiredTargetImports.contains(moduleName)) - m_requiredTargetImports << moduleName; - } - - QStringList typesystemPaths() - { - return m_typesystemPaths; - } - void addTypesystemPath(const QString &typesystem_paths) - { -#if defined(Q_OS_WIN32) - char *path_splitter = const_cast(";"); -#else - char *path_splitter = const_cast(":"); -#endif - m_typesystemPaths += typesystem_paths.split(path_splitter); - } - - IncludeList extraIncludes(const QString &className); - - inline PrimitiveTypeEntry *findPrimitiveType(const QString &name); - inline ComplexTypeEntry *findComplexType(const QString &name); - inline ObjectTypeEntry *findObjectType(const QString &name); - inline NamespaceTypeEntry *findNamespaceType(const QString &name); - ContainerTypeEntry *findContainerType(const QString &name); - FunctionTypeEntry* findFunctionType(const QString& name); - - TypeEntry *findType(const QString &name) const - { - QList entries = findTypes(name); - foreach (TypeEntry *entry, entries) { - if (entry && - (!entry->isPrimitive() || static_cast(entry)->preferredTargetLangType())) { - return entry; - } - } - return 0; - } - QList findTypes(const QString &name) const - { - return m_entries.value(name); - } - TypeEntryHash allEntries() - { - return m_entries; - } - - SingleTypeEntryHash entries() - { - TypeEntryHash entries = allEntries(); - - SingleTypeEntryHash returned; - QList keys = entries.keys(); - - foreach (QString key, keys) - returned[key] = findType(key); - - return returned; - } - - PrimitiveTypeEntry *findTargetLangPrimitiveType(const QString &targetLangName); - - QList primitiveTypes() { - TypeEntryHash entries = allEntries(); - QList returned; - foreach(QString key, entries.keys()) { - foreach(const TypeEntry* typeEntry, entries[key]) { - if (typeEntry->isPrimitive()) - returned.append((PrimitiveTypeEntry*) typeEntry); - } - } - return returned; - } - QList containerTypes() { - TypeEntryHash entries = allEntries(); - QList returned; - foreach(QString key, entries.keys()) { - foreach(const TypeEntry* typeEntry, entries[key]) { - if (typeEntry->isContainer()) - returned.append((ContainerTypeEntry*) typeEntry); - } - } - return returned; - } - - void addRejection(const QString &class_name, const QString &function_name, - const QString &field_name, const QString &enum_name); - bool isClassRejected(const QString &class_name); - bool isFunctionRejected(const QString &class_name, const QString &function_name); - bool isFieldRejected(const QString &class_name, const QString &field_name); - bool isEnumRejected(const QString &class_name, const QString &enum_name); - - void addType(TypeEntry *e) - { - m_entries[e->qualifiedCppName()].append(e); - } - - SingleTypeEntryHash flagsEntries() const - { - return m_flagsEntries; - } - FlagsTypeEntry *findFlagsType(const QString &name) const; - void addFlagsType(FlagsTypeEntry *fte) - { - m_flagsEntries[fte->originalName()] = fte; - } - - TemplateEntry *findTemplate(const QString &name) - { - return m_templates[name]; - } - void addTemplate(TemplateEntry *t) - { - m_templates[t->name()] = t; - } - - AddedFunctionList globalUserFunctions() const - { - return m_globalUserFunctions; - } - void addGlobalUserFunctions(const AddedFunctionList& functions) - { - m_globalUserFunctions << functions; - } - AddedFunctionList findGlobalUserFunctions(const QString& name) const; - - void addGlobalUserFunctionModifications(const FunctionModificationList& functionModifications) - { - m_functionMods << functionModifications; - } - void addGlobalUserFunctionModification(const FunctionModification& functionModification) - { - m_functionMods << functionModification; - } - FunctionModificationList functionModifications(const QString& signature) const; - - void setSuppressWarnings(bool on) - { - m_suppressWarnings = on; - } - void addSuppressedWarning(const QString &s) - { - m_suppressedWarnings.append(s); - } - - bool isSuppressedWarning(const QString &s) - { - if (!m_suppressWarnings) - return false; - - foreach (const QString &_warning, m_suppressedWarnings) { - QString warning(QString(_warning).replace("\\*", "&place_holder_for_asterisk;")); - - QStringList segs = warning.split("*", QString::SkipEmptyParts); - if (!segs.size()) - continue; - - int i = 0; - int pos = s.indexOf(QString(segs.at(i++)).replace("&place_holder_for_asterisk;", "*")); - //qDebug() << "s == " << s << ", warning == " << segs; - while (pos != -1) { - if (i == segs.size()) - return true; - pos = s.indexOf(QString(segs.at(i++)).replace("&place_holder_for_asterisk;", "*"), pos); - } - } - - return false; - } - - void setRebuildClasses(const QStringList &cls) - { - m_rebuildClasses = cls; - } - - static QString globalNamespaceClassName(const TypeEntry *te); - QString filename() const - { - return "typesystem.txt"; - } - - QString modifiedTypesystemFilepath(const QString &ts_file); - bool parseFile(const QString &filename, bool generate = true); - bool parseFile(QIODevice* device, bool generate = true); - -private: - bool m_suppressWarnings; - TypeEntryHash m_entries; - SingleTypeEntryHash m_flagsEntries; - TemplateEntryHash m_templates; - QStringList m_suppressedWarnings; - - AddedFunctionList m_globalUserFunctions; - FunctionModificationList m_functionMods; - - QStringList m_requiredTargetImports; - - QStringList m_typesystemPaths; - QHash m_parsedTypesystemFiles; - - QList m_rejections; - QStringList m_rebuildClasses; -}; - -inline PrimitiveTypeEntry *TypeDatabase::findPrimitiveType(const QString &name) -{ - QList entries = findTypes(name); - - foreach (TypeEntry *entry, entries) { - if (entry && entry->isPrimitive() && static_cast(entry)->preferredTargetLangType()) - return static_cast(entry); - } - - return 0; -} - -inline ComplexTypeEntry *TypeDatabase::findComplexType(const QString &name) -{ - TypeEntry *entry = findType(name); - if (entry && entry->isComplex()) - return static_cast(entry); - else - return 0; -} - -inline ObjectTypeEntry *TypeDatabase::findObjectType(const QString &name) -{ - TypeEntry *entry = findType(name); - if (entry && entry->isObject()) - return static_cast(entry); - else - return 0; -} - -inline NamespaceTypeEntry *TypeDatabase::findNamespaceType(const QString &name) -{ - TypeEntry *entry = findType(name); - if (entry && entry->isNamespace()) - return static_cast(entry); - else - return 0; -} - QString fixCppTypeName(const QString &name); #endif // TYPESYSTEM_H -- cgit v1.2.3