]> git.saurik.com Git - cycript.git/blobdiff - Analyze.cpp
Add extern "C" expression, for Functor's toCYON().
[cycript.git] / Analyze.cpp
index 1eac8a0d57f25ee0b44c3e982ddc51f199588788..4f84e03e2fa1faa6d4df5bb1889325550a03e9b1 100644 (file)
@@ -1,5 +1,5 @@
-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015  Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016  Jay Freeman (saurik)
 */
 
 /* GNU Affero General Public License, Version 3 {{{ */
@@ -127,6 +127,8 @@ std::ostream &operator <<(std::ostream &out, const CYCXPosition<clang_get_Locati
 }
 
 struct CYKey {
+    unsigned priority_ = 0;
+
     std::string code_;
     unsigned flags_;
 };
@@ -293,6 +295,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
     CYCXString spelling(cursor);
     std::string name(spelling);
     std::ostringstream value;
+    unsigned priority(2);
     unsigned flags(0);
 
     /*CXSourceLocation location(clang_getCursorLocation(cursor));
@@ -364,10 +367,10 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
         } break;
 
         case CXCursor_StructDecl: {
-            if (!clang_isCursorDefinition(cursor))
-                goto skip;
             if (spelling[0] == '\0')
                 goto skip;
+            if (!clang_isCursorDefinition(cursor))
+                priority = 1;
 
             std::ostringstream types;
             std::ostringstream names;
@@ -380,8 +383,8 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
                 }
             }));
 
+            value << "new Type([" << types.str() << "],[" << names.str() << "]).withName(\"" << name << "\")";
             name += "$cy";
-            value << "new Type([" << types.str() << "],[" << names.str() << "])";
         } break;
 
         case CXCursor_TypedefDecl: {
@@ -453,8 +456,11 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
 
     {
         CYKey &key(baton.keys[name]);
-        key.code_ = value.str();
-        key.flags_ = flags;
+        if (key.priority_ < priority) {
+            key.priority_ = priority;
+            key.code_ = value.str();
+            key.flags_ = flags;
+        }
     }
 
   skip: