]> git.saurik.com Git - cycript.git/commitdiff
Allow users to tab complete struct and enum names.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 4 Jan 2016 03:29:47 +0000 (19:29 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 4 Jan 2016 03:29:47 +0000 (19:29 -0800)
Analyze.cpp
Complete.cpp
Driver.hpp
Parser.ypp.in
Replace.cpp

index 0f46cb43cd1e1ec5309e1c192e0ea996c4f42ba9..f5195a0b2d2b39e157e6162c5f2825ea60a33823 100644 (file)
@@ -524,7 +524,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
             CYTypeExpression(&typed).Output(out, CYNoBFC);
 
             value << ".withName(\"" << name << "\")";
-            name += "$cye";
+            name = "$cye" + name;
             flags = CYBridgeType;
 
             // the enum constants are implemented separately *also*
@@ -603,7 +603,7 @@ static CXChildVisitResult CYChildVisit(CXCursor cursor, CXCursor parent, CXClien
             CYTypeExpression(&typed).Output(out, CYNoBFC);
 
             value << ".withName(\"" << name << "\")";
-            name += "$cys";
+            name = "$cys" + name;
             flags = CYBridgeType;
         } break;
 
index 8240068428fc4e060dd5308415bf7868e93c173b..820895c9c91776af12b040caace6244758274367 100644 (file)
@@ -93,6 +93,16 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
             expression = $M(driver.context_, $S("$cyr"));
         break;
 
+        case CYDriver::AutoStruct:
+            expression = $ CYThis();
+            prefix << "$cys";
+        break;
+
+        case CYDriver::AutoEnum:
+            expression = $ CYThis();
+            prefix << "$cye";
+        break;
+
         default:
             _assert(false);
     }
@@ -108,7 +118,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
     "       if (false) {\n"
     "           for (var name in object)\n"
     "               if (name.substring(0, entire) == prefix)\n"
-    "                   names.push(name.substr(before));\n"
+    "                   names.push(name);\n"
     "       } else do {\n"
     "           if (object.hasOwnProperty(\"cy$complete\")) {\n"
     "               names = names.concat(object.cy$complete(prefix));\n"
@@ -121,7 +131,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
     "           }\n"
     "           for (var name of local)\n"
     "               if (name.substring(0, entire) == prefix)\n"
-    "                   names.push(name.substr(before));\n"
+    "                   names.push(name);\n"
     "       } while (object = typeof object === 'object' ? Object.getPrototypeOf(object) : object.__proto__);\n"
     "       return names;\n"
     "   }\n"
@@ -168,9 +178,11 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
         else
             continue;
 
+        completion.data += begin.size();
+        completion.size -= begin.size();
+
         if (CYStartsWith(completion, "$cy"))
             continue;
-
         completions.push_back(completion);
 
         if (!rest) {
index a653d0a41af3774afb8d5a94fb7701ec168b5048..07188ce3c5c22d43b96af6235f9ab843c5604d63 100644 (file)
@@ -114,6 +114,8 @@ class _visible CYDriver {
         AutoIndirect,
         AutoMessage,
         AutoResolve,
+        AutoStruct,
+        AutoEnum,
     } mode_;
 
   private:
index 19e235fca3fb5b539357c59052b8d6301a7e94b2..4b7751d6576bf4ac85cc3431b9482dc00ad9a5a6 100644 (file)
@@ -2147,6 +2147,8 @@ PrimitiveReference
     : PrimitiveType[pass] { $$ = $pass; }
     | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); }
     | "enum" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceEnum, $name); }
+    | "struct" AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; }
+    | "enum" AutoComplete { driver.mode_ = CYDriver::AutoEnum; YYACCEPT; }
     ;
 
 TypedIdentifierMaybe
@@ -2440,6 +2442,7 @@ Statement__
 
 PrimaryExpression
     : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); $$ = CYNew CYTypeExpression($typed); }
+    | "(" LexOf "struct" NewLineOpt AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; }
     ;
 /* }}} */
 /* Cycript (C): Type Definitions {{{ */
index 65d8236459baebc6b08340752f01f2c87cba03e2..103f6f8dc011d2cc266b1d2b6b623365beb147ea 100644 (file)
@@ -1288,14 +1288,14 @@ CYTarget *CYTypePointerTo::Replace_(CYContext &context, CYTarget *type) {
 }
 
 CYTarget *CYTypeReference::Replace(CYContext &context) {
-    const char *suffix;
+    const char *prefix;
     switch (kind_) {
-        case CYTypeReferenceStruct: suffix = "$cys"; break;
-        case CYTypeReferenceEnum: suffix = "$cye"; break;
+        case CYTypeReferenceStruct: prefix = "$cys"; break;
+        case CYTypeReferenceEnum: prefix = "$cye"; break;
         default: _assert(false);
     }
 
-    return $V($pool.strcat(name_->Word(), suffix, NULL));
+    return $V($pool.strcat(prefix, name_->Word(), NULL));
 }
 
 CYTarget *CYTypeStruct::Replace(CYContext &context) {