aboutsummaryrefslogtreecommitdiffstats
path: root/abstractmetabuilder.h
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-08-17 17:32:08 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-08-17 17:32:08 -0300
commit9732e0c744e45a67094fc6ce08bdadb1f9a08d4a (patch)
tree566e389f406515b040317bffa075f4e5021020f7 /abstractmetabuilder.h
The genesis...
Diffstat (limited to 'abstractmetabuilder.h')
-rw-r--r--abstractmetabuilder.h225
1 files changed, 225 insertions, 0 deletions
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 <contact@pyside.org>
+ *
+ * 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 <QtCore/QSet>
+
+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<AbstractMetaClass *> *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<QString> &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<AbstractMetaType *> &templateTypes, AbstractMetaType *metaType, bool *ok = 0);
+
+ bool isQObject(const QString &qualifiedName);
+ bool isEnum(const QStringList &qualifiedName);
+
+ void fixQObjectForScope(TypeDatabase *types,
+ NamespaceModelItem item);
+
+ // QtScript
+ QSet<QString> 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<const TypeEntry *> m_usedTypes;
+
+ QMap<QString, RejectReason> m_rejectedClasses;
+ QMap<QString, RejectReason> m_rejectedEnums;
+ QMap<QString, RejectReason> m_rejectedFunctions;
+ QMap<QString, RejectReason> m_rejectedFields;
+
+ QList<AbstractMetaEnum *> m_enums;
+
+ QList<QPair<AbstractMetaArgument *, AbstractMetaFunction *> > m_enumDefaultArguments;
+
+ QHash<QString, AbstractMetaEnumValue *> m_enumValues;
+
+ AbstractMetaClass *m_currentClass;
+ QList<ScopeModelItem> m_scopes;
+ QString m_namespacePrefix;
+
+ QSet<AbstractMetaClass *> m_setupInheritanceDone;
+
+ // QtScript
+ QSet<QString> m_qmetatypeDeclaredTypenames;
+};
+
+#endif // ABSTRACTMETBUILDER_H