]> git.saurik.com Git - cycript.git/commitdiff
Make Functor/struct output fancy type definitions.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 3 Jan 2016 11:24:05 +0000 (03:24 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 3 Jan 2016 11:24:05 +0000 (03:24 -0800)
Analyze.cpp
Execute.cpp
Output.cpp
Syntax.hpp
sig/copy.cpp

index 7b3e2caf1cdcf4b7a5cb39270e10a2e321258da4..4f84e03e2fa1faa6d4df5bb1889325550a03e9b1 100644 (file)
@@ -383,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: {
index fc19fbabbb3dcca41b9200cde5b5369cd0a84c56..7d14b10df54bb75ae1673cc103f8da1352019a86 100644 (file)
@@ -1605,18 +1605,34 @@ static JSValueRef Functor_callAsFunction_valueOf(JSContextRef context, JSObjectR
 static JSValueRef Functor_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
     cy::Functor *internal(reinterpret_cast<cy::Functor *>(JSObjectGetPrivate(_this)));
     uint8_t *value(reinterpret_cast<uint8_t *>(internal->value_));
-    std::ostringstream str;
-    Dl_info info;
-    if (internal->value_ == NULL)
-        str << "NULL";
-    else if (dladdr(value, &info) == 0)
-        str << internal->value_;
-    else {
-        str << info.dli_sname;
-        off_t offset(value - reinterpret_cast<uint8_t *>(info.dli_saddr));
-        if (offset != 0)
-            str << "+0x" << std::hex << offset;
+
+    CYLocalPool pool;
+
+    sig::Function function(internal->variadic_);
+    sig::Copy(pool, function.signature, internal->signature_);
+
+    auto typed(CYDecodeType(pool, &function)); {
+        std::ostringstream str;
+        Dl_info info;
+        if (internal->value_ == NULL)
+            str << "NULL";
+        else if (dladdr(value, &info) == 0)
+            str << internal->value_;
+        else {
+            str << info.dli_sname;
+            off_t offset(value - reinterpret_cast<uint8_t *>(info.dli_saddr));
+            if (offset != 0)
+                str << "+0x" << std::hex << offset;
+        }
+
+        typed->identifier_ = new(pool) CYIdentifier(pool.strdup(str.str().c_str()));
     }
+
+    std::ostringstream str;
+    CYOptions options;
+    CYOutput output(*str.rdbuf(), options);
+    output.pretty_ = true;
+    (new(pool) CYExternal(new(pool) CYString("C"), typed))->Output(output, CYNoFlags);
     return CYCastJSValue(context, CYJSString(str.str()));
 } CYCatch(NULL) }
 
@@ -1725,7 +1741,7 @@ static JSValueRef Type_callAsFunction_toCYON(JSContextRef context, JSObjectRef o
     std::stringbuf out;
     CYOptions options;
     CYOutput output(out, options);
-    (new(pool) CYTypeExpression(CYDecodeType(pool, internal->type_)))->Output(output, CYNoFlags);
+    (new(pool) CYTypeExpression(CYDecodeType(pool, internal->type_->Copy(pool, ""))))->Output(output, CYNoFlags);
     return CYCastJSValue(context, CYJSString(out.str().c_str()));
 } CYCatch(NULL) }
 
index dc1f7f997f92b90231ea10d0cf0faaa752872d0b..0bc11727f29c47ed99bc86ce772bc51c2357d1b7 100644 (file)
@@ -458,7 +458,7 @@ void CYExtend::Output(CYOutput &out, CYFlags flags) const {
 }
 
 void CYExternal::Output(CYOutput &out, CYFlags flags) const {
-    out << "extern" << abi_ << typed_;
+    out << "extern" << ' ' << abi_ << ' ' << typed_;
     out.Terminate();
 }
 
@@ -665,7 +665,7 @@ void CYTemplate::Output(CYOutput &out, CYFlags flags) const {
 }
 
 void CYTypeArrayOf::Output(CYOutput &out, CYIdentifier *identifier) const {
-    next_->Output(out, Precedence(), identifier);
+    next_->Output(out, Precedence(), identifier, false);
     out << '[';
     out << size_;
     out << ']';
@@ -673,17 +673,17 @@ void CYTypeArrayOf::Output(CYOutput &out, CYIdentifier *identifier) const {
 
 void CYTypeBlockWith::Output(CYOutput &out, CYIdentifier *identifier) const {
     out << '(' << '^';
-    next_->Output(out, Precedence(), identifier);
+    next_->Output(out, Precedence(), identifier, false);
     out << ')' << '(' << parameters_ << ')';
 }
 
 void CYTypeConstant::Output(CYOutput &out, CYIdentifier *identifier) const {
-    out << "const" << ' ';
-    next_->Output(out, Precedence(), identifier);
+    out << "const";
+    next_->Output(out, Precedence(), identifier, false);
 }
 
 void CYTypeFunctionWith::Output(CYOutput &out, CYIdentifier *identifier) const {
-    next_->Output(out, Precedence(), identifier);
+    next_->Output(out, Precedence(), identifier, false);
     out << '(' << parameters_;
     if (variadic_) {
         if (parameters_ != NULL)
@@ -695,15 +695,20 @@ void CYTypeFunctionWith::Output(CYOutput &out, CYIdentifier *identifier) const {
 
 void CYTypePointerTo::Output(CYOutput &out, CYIdentifier *identifier) const {
     out << '*';
-    next_->Output(out, Precedence(), identifier);
+    next_->Output(out, Precedence(), identifier, false);
 }
 
 void CYTypeVolatile::Output(CYOutput &out, CYIdentifier *identifier) const {
     out << "volatile";
-    next_->Output(out, Precedence(), identifier);
+    next_->Output(out, Precedence(), identifier, true);
 }
 
-void CYTypeModifier::Output(CYOutput &out, int precedence, CYIdentifier *identifier) const {
+void CYTypeModifier::Output(CYOutput &out, int precedence, CYIdentifier *identifier, bool space) const {
+    if (this == NULL && identifier == NULL)
+        return;
+    else if (space)
+        out << ' ';
+
     if (this == NULL) {
         out << identifier;
         return;
@@ -720,7 +725,7 @@ void CYTypeModifier::Output(CYOutput &out, int precedence, CYIdentifier *identif
 
 void CYTypedIdentifier::Output(CYOutput &out) const {
     specifier_->Output(out);
-    modifier_->Output(out, 0, identifier_);
+    modifier_->Output(out, 0, identifier_, true);
 }
 
 void CYEncodedType::Output(CYOutput &out, CYFlags flags) const {
@@ -990,7 +995,7 @@ void CYStructTail::Output(CYOutput &out) const {
         out << '\n';
     }
     --out.indent_;
-    out << '}';
+    out << '\t' << '}';
 }
 
 void CYSuperAccess::Output(CYOutput &out, CYFlags flags) const {
index a204f5834d80f4f7b180f8db6319d98c123f767f..e67031fa907cea4ac7c439b6f31122b7100142cc 100644 (file)
@@ -2175,7 +2175,7 @@ struct CYTypeModifier :
     CYTarget *Replace(CYContext &context, CYTarget *type);
 
     virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
-    void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
+    void Output(CYOutput &out, int precedence, CYIdentifier *identifier, bool space) const;
 
     virtual CYTypeFunctionWith *Function() { return NULL; }
 };
index 664039f7f35507f0767fc479bd33787f4f280018..63b72fe25ed4e7dfd8bb2d60be881906e73cd7d1 100644 (file)
@@ -86,7 +86,11 @@ Object *Object::Copy(CYPool &pool, const char *rename) const {
 #endif
 
 Aggregate *Aggregate::Copy(CYPool &pool, const char *rename) const {
-    Aggregate *copy(new(pool) Aggregate(overlap, rename ?: pool.strdup(name)));
+    if (rename == NULL)
+        rename = pool.strdup(name);
+    else if (rename[0] == '\0')
+        rename = NULL;
+    Aggregate *copy(new(pool) Aggregate(overlap, rename));
     sig::Copy(pool, copy->signature, signature);
     return copy;
 }