@@ -519,12 +519,80 @@ class c_loader_closure_value
519519class c_loader_pointer_type : public c_loader_type_impl
520520{
521521protected:
522- loader_impl impl;
523522 CXType cx_type;
524523
525524public:
526- c_loader_pointer_type (loader_impl impl, CXType cx_type) :
527- impl (impl), cx_type(cx_type) {}
525+ c_loader_pointer_type (CXType cx_type) :
526+ cx_type (cx_type) {}
527+
528+ void *to_value (void *arg_ptr)
529+ {
530+ // TODO: This may be too tricky to implement because it is impossible to reconstruct the pointer from the type
531+ // easily, as C does not mantain the true memory layout, pointers can be arrays or single elements and we cannot know
532+ // We should review this carefully
533+ #if 0
534+ CXType type_iterator = cx_type;
535+ value prev_value = value_create_ptr(NULL);
536+ void *current_ptr = arg_ptr;
537+
538+ while (type_iterator.kind == CXType_Pointer)
539+ {
540+ value new_value = value_create_ptr(NULL);
541+
542+ if (prev_value != NULL)
543+ {
544+ value_from_ptr(prev_value, )
545+ }
546+
547+ type_iterator = clang_getPointeeType(type_iterator);
548+ prev_ptr = current_ptr;
549+ }
550+
551+ std::vector<enum CXTypeKind> type_info;
552+ std::vector<void *> ptr_info;
553+ void *arg_it_ptr = arg_ptr;
554+ void *result = NULL;
555+
556+ while (type_iterator.kind == CXType_Pointer)
557+ {
558+ type_info.push_back(type_iterator.kind);
559+ ptr_info.push_back(arg_it_ptr);
560+ type_iterator = clang_getPointeeType(type_iterator);
561+ arg_it_ptr = *(static_cast<void **>(arg_it_ptr));
562+ }
563+
564+ type_info.push_back(type_iterator.kind);
565+ ptr_info.push_back(arg_it_ptr); // TODO: is this safe?
566+
567+ for (auto type_iterator = type_info.rbegin(); type_iterator != type_info.rend(); ++type_iterator)
568+ {
569+ switch (*type_iterator)
570+ {
571+ case CXType_Pointer:
572+ {
573+ break;
574+ }
575+
576+ case CXType_String:
577+ {
578+ break;
579+ }
580+
581+ #if 0
582+ if (pointee_type.kind == CXType_Char_S || pointee_type.kind == CXType_SChar ||
583+ pointee_type.kind == CXType_Char_U || pointee_type.kind == CXType_UChar)
584+ {
585+ return TYPE_STRING;
586+ }
587+ /* Support for function pointers */
588+ else if (pointee_type.kind == CXType_FunctionProto || pointee_type.kind == CXType_FunctionNoProto)
589+ #endif
590+ }
591+ }
592+ #endif
593+
594+ return NULL ;
595+ }
528596
529597 ~c_loader_pointer_type () {}
530598};
@@ -780,7 +848,15 @@ function_return function_c_interface_invoke(function func, function_impl impl, f
780848 */
781849 if (id == TYPE_PTR && impl_type != nullptr )
782850 {
783- // TODO: Reconstruct the pointer value from the type info
851+ // TODO: This may be too tricky to implement because it is impossible to reconstruct the pointer from the type
852+ // easily, as C does not mantain the true memory layout, pointers can be arrays or single elements and we cannot know
853+ // We should review this carefully
854+ #if 0
855+ /* Reconstruct the pointer value from the type info */
856+ c_loader_pointer_type *pointer_type = static_cast<c_loader_pointer_type *>(impl_type);
857+
858+ void *arg_value = pointer_type->to_value(value_to_ptr(c_function->values[args_count]));
859+ #endif
784860
785861 value_type_destroy (c_function->values [args_count]);
786862 }
@@ -1022,7 +1098,7 @@ static type_id c_loader_impl_clang_type(loader_impl impl, CXCursor cursor, CXTyp
10221098 /* Check for pointers to pointers, in this case we need the type info for reconstructing the data */
10231099 else if (pointee_type.kind == CXType_Pointer)
10241100 {
1025- c_loader_pointer_type *pointer_type = new c_loader_pointer_type (impl, cx_type);
1101+ c_loader_pointer_type *pointer_type = new c_loader_pointer_type (cx_type);
10261102
10271103 *impl_type = static_cast <c_loader_pointer_type *>(pointer_type);
10281104 }
0 commit comments