[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [smokegen/smokev4] /: move some stuff from smokeutils.h in an implementation file,
From:       Arno Rehn <arno () arnorehn ! de>
Date:       2012-10-12 14:03:19
Message-ID: 20121012140319.01052A60E0 () git ! kde ! org
[Download RAW message or body]

Git commit f55cc51199c12b81bc89cd08d03c915680bf0555 by Arno Rehn.
Committed on 18/09/2012 at 17:27.
Pushed by arnorehn into branch 'smokev4'.

move some stuff from smokeutils.h in an implementation file,
add SmokeClass::unqualifiedName().

A  +152  -0    smokeutils.cpp     [License: LGPL (v3+)]
M  +13   -137  smokeutils.h

http://commits.kde.org/smokegen/f55cc51199c12b81bc89cd08d03c915680bf0555

diff --git a/smokeutils.cpp b/smokeutils.cpp
new file mode 100644
index 0000000..74953c9
--- /dev/null
+++ b/smokeutils.cpp
@@ -0,0 +1,152 @@
+/*
+    Copyright (C) 2003-2011  Richard Dale <Richard_Dale@tipitina.demon.co.uk>
+    Copyright (C) 2012  Arno Rehn <arno@arnorehn.de>
+
+    Based on the PerlQt marshalling code by Ashley Winters
+
+    This library is free software; you can redistribute and/or modify them under
+    the terms of the GNU Lesser General Public License as published by the
+    Free Software Foundation; either version 3 of the License, or (at your option)
+    any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "smokeutils.h"
+#include "smokemanager.h"
+
+bool SmokeType::isUnsigned() const {
+    if (!typeId()) return false;
+    if (_unsigned > -1) return _unsigned;
+
+    switch (elem()) {
+        case Smoke::t_uchar:
+        case Smoke::t_ushort:
+        case Smoke::t_uint:
+        case Smoke::t_ulong:
+            return true;
+    }
+
+    _unsigned = (!strncmp(isConst() ? name() + static_strlen("const ") : name(), \
"unsigned ", static_strlen("unsigned "))); +    return _unsigned;
+}
+
+char SmokeType::pointerDepth() const {
+    if (!typeId()) return 0;
+    if (_pointerDepth > -1) return _pointerDepth;
+
+    const char *n = name();
+    signed char depth = 0;
+    signed char templateDepth = 0;
+
+    while (*n) {
+        if (*n == '<') {
+            ++templateDepth;
+            depth = 0;
+        }
+        if (*n == '>')
+            --templateDepth;
+        if (templateDepth == 0 && *n == '*')
+            ++depth;
+        ++n;
+    }
+    _pointerDepth = depth;
+    return _pointerDepth;
+}
+
+std::string SmokeType::plainName() const {
+    if (!typeId()) return "void";
+    if (isClass())
+        return smoke()->classes[classId()].className;
+    if (!_plainName.empty()) return _plainName;
+
+    char offset = 0;
+    if (isConst()) offset += static_strlen("const ");
+    if (isUnsigned()) offset += static_strlen("unsigned ");
+
+    const char *start = name() + offset;
+    const char *n = start;
+
+    signed char templateDepth = 0;
+
+    while (*n) {
+        if (*n == '<')
+            ++templateDepth;
+        if (*n == '>')
+            --templateDepth;
+        if (templateDepth == 0 && (*n == '*' || *n == '&')) {
+            _plainName = std::string(start, static_cast<std::size_t>(n - start));
+            return _plainName;
+        }
+        ++n;
+    }
+
+    _plainName = std::string(start);
+    return _plainName;
+}
+
+// not cached, expensive
+std::vector<SmokeType> SmokeType::templateArguments() const {
+    std::vector<SmokeType> ret;
+    if (!typeId()) return ret;
+
+    int depth = 0;
+
+    const char *begin = 0;
+    const char *n = name();
+
+    while (*n) {
+        if (*n == '<') {
+            if (depth == 0) {
+                ret.clear();
+                begin = n + 1;
+            }
+
+            ++depth;
+        }
+
+        if (depth == 1 && (*n == '>' || *n == ',')) {
+            assert(begin);
+            std::string str(begin, static_cast<std::size_t>((*(n-1) == ' ' ? n-1 : \
n)  - begin)); +
+            Smoke::Index typeId = smoke()->idType(str.c_str());
+            assert(typeId);
+            ret.push_back(SmokeType(smoke(), typeId));
+
+            begin = *n == ',' ? n + 1 : 0;
+        }
+
+        if (*n == '>')
+            --depth;
+
+        ++n;
+    }
+
+    return ret;
+}
+
+bool SmokeClass::resolve() {
+    if (!isExternal()) return false;
+    Smoke::ModuleIndex newId = SmokeManager::self()->findClass(_c->className);
+    if (!newId) return false;
+    set(newId);
+    return true;
+}
+
+std::string SmokeClass::unqualifiedName() const
+{
+    std::string name = className();
+    int pos = name.find_last_of("::");
+
+    if (pos != name.npos)
+        name = name.substr(pos + static_strlen("::") - 1);
+
+    return name;
+}
diff --git a/smokeutils.h b/smokeutils.h
index f228a19..fa1ba8d 100644
--- a/smokeutils.h
+++ b/smokeutils.h
@@ -80,18 +80,6 @@ public:
         set(Smoke::ModuleIndex(s, i));
     }
 
-    void preparse() {
-        if (!typeId()) {
-            return;
-        }
-
-        isUnsigned();
-        pointerDepth();
-
-        if (!isClass())
-            plainName();
-    }
-
     // accessors
     Smoke *smoke() const { return _mi.smoke; }
     Smoke::Index typeId() const { return _mi.index; }
@@ -102,6 +90,12 @@ public:
     const char *name() const { return _t->name ? _t->name : "void"; }
     Smoke::Index classId() const { return _t->classId; }
 
+    char pointerDepth() const;
+    std::string plainName() const;
+
+    // not cached, expensive
+    std::vector<SmokeType> templateArguments() const;
+
     // tests
     operator bool() const { return _mi.smoke; }
 
@@ -109,119 +103,9 @@ public:
     bool isPtr() const { return ((flags() & Smoke::tf_ref) == Smoke::tf_ptr); }
     bool isRef() const { return ((flags() & Smoke::tf_ref) == Smoke::tf_ref); }
     bool isConst() const { return (flags() & Smoke::tf_const); }
-    bool isClass() const { return classId() ? true : false; }
-
+    bool isClass() const { return classId(); }
     bool isVoid() const { return !typeId(); }
-
-    bool isUnsigned() const {
-        if (!typeId()) return false;
-        if (_unsigned > -1) return _unsigned;
-
-        switch (elem()) {
-            case Smoke::t_uchar:
-            case Smoke::t_ushort:
-            case Smoke::t_uint:
-            case Smoke::t_ulong:
-                return true;
-        }
-
-        _unsigned = (!strncmp(isConst() ? name() + static_strlen("const ") : name(), \
                "unsigned ", static_strlen("unsigned ")));
-        return _unsigned;
-    }
-
-    char pointerDepth() const {
-        if (!typeId()) return 0;
-        if (_pointerDepth > -1) return _pointerDepth;
-
-        const char *n = name();
-        signed char depth = 0;
-        signed char templateDepth = 0;
-
-        while (*n) {
-            if (*n == '<') {
-                ++templateDepth;
-                depth = 0;
-            }
-            if (*n == '>')
-                --templateDepth;
-            if (templateDepth == 0 && *n == '*')
-                ++depth;
-            ++n;
-        }
-        _pointerDepth = depth;
-        return _pointerDepth;
-    }
-
-    std::string plainName() const {
-        if (!typeId()) return "void";
-        if (isClass())
-            return smoke()->classes[classId()].className;
-        if (!_plainName.empty()) return _plainName;
-
-        char offset = 0;
-        if (isConst()) offset += static_strlen("const ");
-        if (isUnsigned()) offset += static_strlen("unsigned ");
-
-        const char *start = name() + offset;
-        const char *n = start;
-
-        signed char templateDepth = 0;
-
-        while (*n) {
-            if (*n == '<')
-                ++templateDepth;
-            if (*n == '>')
-                --templateDepth;
-            if (templateDepth == 0 && (*n == '*' || *n == '&')) {
-                _plainName = std::string(start, static_cast<std::size_t>(n - \
                start));
-                return _plainName;
-            }
-            ++n;
-        }
-
-        _plainName = std::string(start);
-        return _plainName;
-    }
-
-    // not cached, expensive
-    std::vector<SmokeType> templateArguments() const {
-        std::vector<SmokeType> ret;
-        if (!typeId()) return ret;
-
-        int depth = 0;
-
-        const char *begin = 0;
-        const char *n = name();
-
-        while (*n) {
-            if (*n == '<') {
-                if (depth == 0) {
-                    ret.clear();
-                    begin = n + 1;
-                }
-
-                ++depth;
-            }
-
-            if (depth == 1 && (*n == '>' || *n == ',')) {
-                assert(begin);
-                std::string str(begin, static_cast<std::size_t>((*(n-1) == ' ' ? n-1 \
                : n)  - begin));
-
-                Smoke::Index typeId = smoke()->idType(str.c_str());
-                assert(typeId);
-                ret.push_back(SmokeType(smoke(), typeId));
-
-                begin = *n == ',' ? n + 1 : 0;
-            }
-
-            if (*n == '>')
-                --depth;
-
-            ++n;
-        }
-
-        return ret;
-    }
+    bool isUnsigned() const;
 
     bool operator ==(const SmokeType &b) const {
         const SmokeType &a = *this;
@@ -267,13 +151,8 @@ public:
         set(Smoke::ModuleIndex(s, id));
     }
 
-    // resolves external classes
-    void resolve() {
-        if (!isExternal()) return;
-        Smoke::ModuleIndex newId = SmokeManager::self()->findClass(_c->className);
-        if (!newId) return;
-        set(newId);
-    }
+    // resolves external classes, returns true on success
+    bool resolve();
 
     void setBindingForObject(void *obj, SmokeBinding *binding) const {
         Smoke::StackItem stack[2];
@@ -288,6 +167,7 @@ public:
     const Smoke::Class &c() const { return *_c; }
     Smoke::Index classId() const { return _mi.index; }
     const char *className() const { return _c->className; }
+    std::string unqualifiedName() const;
     Smoke::ClassFn classFn() const { return _c->classFn; }
     Smoke::EnumFn enumFn() const { return _c->enumFn; }
     bool operator ==(const SmokeClass &b) const {
@@ -317,7 +197,7 @@ public:
     } \
     return false;
 
-    // need both overloads, otherwise lambdas might caus a compilation
+    // need both overloads, otherwise lambdas might cause a compilation
     // error
     template <typename Func>
     bool iterateParents(const Func& func) const { iterateParentsImpl }
@@ -329,15 +209,11 @@ public:
     std::vector<SmokeClass> parents() const {
         struct Collector {
             std::vector<SmokeClass> val;
-
             bool operator()(const SmokeClass& klass) {
                 val.push_back(klass);
             }
         };
-        Collector c;
-
-        iterateParents(c);
-
+        Collector c; iterateParents(c);
         return c.val;
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic