From 9732e0c744e45a67094fc6ce08bdadb1f9a08d4a Mon Sep 17 00:00:00 2001 From: Hugo Lima Date: Mon, 17 Aug 2009 17:32:08 -0300 Subject: The genesis... --- abstractmetabuilder.h | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 abstractmetabuilder.h (limited to 'abstractmetabuilder.h') diff --git a/abstractmetabuilder.h b/abstractmetabuilder.h new file mode 100644 index 000000000..3cc5f3cee --- /dev/null +++ b/abstractmetabuilder.h @@ -0,0 +1,225 @@ +/* + * This file is part of the API Extractor project. + * + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifndef ABSTRACTMETABUILDER_H +#define ABSTRACTMETABUILDER_H + +#include "parser/codemodel.h" +#include "abstractmetalang.h" +#include "typesystem.h" +#include "typeparser.h" + +#include + +class AbstractMetaBuilder +{ +public: + enum RejectReason { + NotInTypeSystem, + GenerationDisabled, + RedefinedToNotClass, + UnmatchedArgumentType, + UnmatchedReturnType, + NoReason + }; + + AbstractMetaBuilder(); + virtual ~AbstractMetaBuilder(); + + AbstractMetaClassList classes() const + { + return m_metaClasses; + } + /** + * Sorts a list of classes topologically, if an AbstractMetaClass object + * is passed the list of classes will be its inner classes, otherwise + * the list will be the module global classes. + * \return a list of classes sorted topologically + */ + AbstractMetaClassList classesTopologicalSorted(const AbstractMetaClass* cppClass = 0) const; + + FileModelItem model() const + { + return m_dom; + } + + void setModel(FileModelItem item) + { + m_dom = item; + } + + ScopeModelItem popScope() + { + return m_scopes.takeLast(); + } + + void pushScope(ScopeModelItem item) + { + m_scopes << item; + } + + ScopeModelItem currentScope() const + { + return m_scopes.last(); + } + + void dumpLog(); + + bool build(QIODevice* input); + + void figureOutEnumValuesForClass(AbstractMetaClass *metaClass, QSet *classes); + int figureOutEnumValue(const QString &name, int value, AbstractMetaEnum *meta_enum, AbstractMetaFunction *metaFunction = 0); + void figureOutEnumValues(); + void figureOutDefaultEnumArguments(); + + void addAbstractMetaClass(AbstractMetaClass *cls); + AbstractMetaClass *traverseTypeAlias(TypeAliasModelItem item); + AbstractMetaClass *traverseClass(ClassModelItem item); + bool setupInheritance(AbstractMetaClass *metaClass); + AbstractMetaClass *traverseNamespace(NamespaceModelItem item); + AbstractMetaEnum *traverseEnum(EnumModelItem item, AbstractMetaClass *enclosing, const QSet &enumsDeclarations); + void traverseEnums(ScopeModelItem item, AbstractMetaClass *parent, const QStringList &enumsDeclarations); + void traverseFunctions(ScopeModelItem item, AbstractMetaClass *parent); + void applyFunctionModifications(AbstractMetaFunction* func); + void traverseFields(ScopeModelItem item, AbstractMetaClass *parent); + void traverseStreamOperator(FunctionModelItem functionItem); + void traverseOperatorFunction(FunctionModelItem item); + AbstractMetaFunction *traverseFunction(FunctionModelItem function); + AbstractMetaField *traverseField(VariableModelItem field, const AbstractMetaClass *cls); + void checkFunctionModifications(); + void registerHashFunction(FunctionModelItem functionItem); + void registerToStringCapability(FunctionModelItem functionItem); + + void parseQ_Property(AbstractMetaClass *metaClass, const QStringList &declarations); + void setupEquals(AbstractMetaClass *metaClass); + void setupComparable(AbstractMetaClass *metaClass); + void setupClonable(AbstractMetaClass *cls); + void setupFunctionDefaults(AbstractMetaFunction *metaFunction, AbstractMetaClass *metaClass); + + QString translateDefaultValue(ArgumentModelItem item, AbstractMetaType *type, + AbstractMetaFunction *fnc, AbstractMetaClass *, + int argumentIndex); + AbstractMetaType *translateType(const TypeInfo &type, bool *ok, bool resolveType = true, bool resolveScope = true); + + void decideUsagePattern(AbstractMetaType *type); + + const AbstractMetaFunctionList globalFunctions() const + { + return m_globalFunctions; + } + + const AbstractMetaEnumList globalEnums() const + { + return m_globalEnums; + } + + bool inheritTemplate(AbstractMetaClass *subclass, + const AbstractMetaClass *templateClass, + const TypeParser::Info &info); + AbstractMetaType *inheritTemplateType(const QList &templateTypes, AbstractMetaType *metaType, bool *ok = 0); + + bool isQObject(const QString &qualifiedName); + bool isEnum(const QStringList &qualifiedName); + + void fixQObjectForScope(TypeDatabase *types, + NamespaceModelItem item); + + // QtScript + QSet qtMetaTypeDeclaredTypeNames() const + { + return m_qmetatypeDeclaredTypenames; + } + +protected: + AbstractMetaClass *argumentToClass(ArgumentModelItem); + + virtual AbstractMetaClass *createMetaClass() + { + return new AbstractMetaClass(); + } + + virtual AbstractMetaEnum *createMetaEnum() + { + return new AbstractMetaEnum(); + } + + virtual AbstractMetaEnumValue *createMetaEnumValue() + { + return new AbstractMetaEnumValue(); + } + + virtual AbstractMetaField *createMetaField() + { + return new AbstractMetaField(); + } + + virtual AbstractMetaFunction *createMetaFunction() + { + return new AbstractMetaFunction(); + } + + virtual AbstractMetaArgument *createMetaArgument() + { + return new AbstractMetaArgument(); + } + + virtual AbstractMetaType *createMetaType() + { + return new AbstractMetaType(); + } + + FileModelItem m_dom; + +private: + void sortLists(); + AbstractMetaArgumentList reverseList(const AbstractMetaArgumentList& list); + + AbstractMetaClassList m_metaClasses; + AbstractMetaClassList m_templates; + AbstractMetaFunctionList m_globalFunctions; + AbstractMetaEnumList m_globalEnums; + + QSet m_usedTypes; + + QMap m_rejectedClasses; + QMap m_rejectedEnums; + QMap m_rejectedFunctions; + QMap m_rejectedFields; + + QList m_enums; + + QList > m_enumDefaultArguments; + + QHash m_enumValues; + + AbstractMetaClass *m_currentClass; + QList m_scopes; + QString m_namespacePrefix; + + QSet m_setupInheritanceDone; + + // QtScript + QSet m_qmetatypeDeclaredTypenames; +}; + +#endif // ABSTRACTMETBUILDER_H -- cgit v1.2.3