[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [smokegen] generators/smoke: Removed repeating in each module static functions of their core depende
From: Arno Rehn <arno () arnorehn ! de>
Date: 2013-06-01 15:01:39
Message-ID: 20130601150139.DFFB5A6067 () git ! kde ! org
[Download RAW message or body]
Git commit 2ef3cf12139bb303cf3a63fd97364f514c86f125 by Arno Rehn, on behalf of \
Dimitar Dobrev. Committed on 11/12/2012 at 22:01.
Pushed by arnorehn into branch 'master'.
Removed repeating in each module static functions of their core dependency.
Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
M +1 -1 generators/smoke/CMakeLists.txt
M +79 -1 generators/smoke/helpers.cpp
http://commits.kde.org/smokegen/2ef3cf12139bb303cf3a63fd97364f514c86f125
diff --git a/generators/smoke/CMakeLists.txt b/generators/smoke/CMakeLists.txt
index a49573a..b83628f 100644
--- a/generators/smoke/CMakeLists.txt
+++ b/generators/smoke/CMakeLists.txt
@@ -7,7 +7,7 @@ set(generator_smoke_SRC
helpers.cpp)
add_library(generator_smoke MODULE ${generator_smoke_SRC})
-target_link_libraries(generator_smoke ${QT_QTCORE_LIBRARY} ${QT_QTXML_LIBRARY} \
smokegen) +target_link_libraries(generator_smoke smokebase ${QT_QTCORE_LIBRARY} \
${QT_QTXML_LIBRARY} smokegen) set_target_properties(generator_smoke PROPERTIES \
PREFIX "")
if (WIN32)
diff --git a/generators/smoke/helpers.cpp b/generators/smoke/helpers.cpp
index 43c6844..90d73fc 100644
--- a/generators/smoke/helpers.cpp
+++ b/generators/smoke/helpers.cpp
@@ -17,15 +17,20 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <QFileInfo>
#include <QHash>
#include <QList>
+#include <QLibrary>
#include <QStack>
#include <type.h>
+#include <smoke.h>
#include "globals.h"
#include "../../options.h"
+typedef void (*InitSmokeFn)();
+
QHash<QString, QString> Util::typeMap;
QHash<const Method*, const Function*> Util::globalFunctionMap;
QHash<const Method*, const Field*> Util::fieldAccessors;
@@ -92,13 +97,79 @@ bool operator==(const EnumMember& lhs, const EnumMember& rhs)
return (lhs.name() == rhs.name() && lhs.declaringType() == rhs.declaringType() \
&& lhs.type() == rhs.type()); }
+static Smoke* loadSmokeModule(QString moduleName) {
+#if defined(Q_OS_WIN32)
+ QFileInfo file(QString("smoke") + moduleName);
+#else
+ QFileInfo file(QString("libsmoke") + moduleName);
+#endif
+ QLibrary lib(file.filePath());
+
+ QString init_name = "init_" + moduleName + "_Smoke";
+ InitSmokeFn init = (InitSmokeFn) lib.resolve(init_name.toLatin1());
+
+ if (!init)
+ qFatal("Couldn't resolve %s: %s", qPrintable(init_name), \
qPrintable(lib.errorString())); +
+ (*init)();
+
+ QString smoke_name = moduleName + "_Smoke";
+ Smoke** smoke = (Smoke**) lib.resolve(smoke_name.toLatin1());
+ if (!smoke)
+ qFatal("Couldn't resolve %s: %s", qPrintable(smoke_name), \
qPrintable(lib.errorString())); +
+ return *smoke;
+}
+
+static bool compareArgs(const Method& method, const Smoke::Method& smokeMethod, \
Smoke* smoke) { + if (method.parameters().count() != smokeMethod.numArgs) {
+ return false;
+ }
+ for (int i = 0; i < method.parameters().count(); i++) {
+ Parameter p = method.parameters()[i];
+ if (p.type()->toString() != \
smoke->types[smoke->argumentList[smokeMethod.args + i]].name) { + return \
false; + }
+ }
+ return true;
+}
+
+static bool isRepeating(const QList<Smoke*>& parentModules, const char* className, \
const Method& method) { + const char* mungedName = \
Util::mungedName(method).toLatin1(); + foreach (Smoke* smoke, parentModules) {
+ Smoke::ModuleIndex methodIndex = smoke->findMethod(className, mungedName);
+ if (methodIndex.index) {
+ Smoke::Index index = smoke->methodMaps[methodIndex.index].method;
+ if (index >= 0) {
+ if (compareArgs(method, smoke->methods[index], smoke)) {
+ return true;
+ }
+ continue;
+ }
+ index = -index;
+ Smoke::Index i;
+ while ((i = smoke->ambiguousMethodList[index++]) != 0) {
+ if (compareArgs(method, smoke->methods[i], smoke)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
void Util::preparse(QSet<Type*> *usedTypes, QSet<const Class*> *superClasses, const \
QList<QString>& keys) {
Class& globalSpace = classes["QGlobalSpace"];
globalSpace.setName("QGlobalSpace");
globalSpace.setKind(Class::Kind_Class);
globalSpace.setIsNameSpace(true);
-
+
+ QList<Smoke*> parentModules;
+ foreach (QString module, Options::parentModules) {
+ parentModules << loadSmokeModule(module);
+ }
+
// add all functions as methods to a class called 'QGlobalSpace' or a class that \
represents a namespace
for (QHash<QString, Function>::const_iterator it = functions.constBegin(); it != \
functions.constEnd(); it++) { const Function& fn = it.value();
@@ -127,6 +198,9 @@ void Util::preparse(QSet<Type*> *usedTypes, QSet<const Class*> \
*superClasses, co
Method meth = Method(parent, fn.name(), fn.type(), Access_public, \
fn.parameters()); meth.setFlag(Method::Static);
+ if (isRepeating(parentModules, parent->name().toLatin1(), meth)) {
+ continue;
+ }
parent->appendMethod(meth);
// map this method to the function, so we can later retrieve the header it \
was defined in globalFunctionMap[&parent->methods().last()] = &fn;
@@ -141,6 +215,10 @@ void Util::preparse(QSet<Type*> *usedTypes, QSet<const Class*> \
*superClasses, co foreach (const Parameter& param, meth.parameters())
(*usedTypes) << param.type();
}
+
+ foreach (Smoke* smoke, parentModules) {
+ delete smoke;
+ }
// all enums that don't have a parent are put under QGlobalSpace, too
for (QHash<QString, Enum>::iterator it = enums.begin(); it != enums.end(); it++) \
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic