Add CFCC_link_text

Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/7f1d8051
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/7f1d8051
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/7f1d8051

Branch: refs/heads/master
Commit: 7f1d805159e03bb86d71e92d50f0e09b1be0ee49
Parents: 4ccff24
Author: Nick Wellnhofer <[email protected]>
Authored: Wed Dec 24 14:24:10 2014 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Wed Dec 24 16:02:03 2014 +0100

----------------------------------------------------------------------
 compiler/src/CFCC.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
 compiler/src/CFCC.h |  5 +++
 2 files changed, 85 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7f1d8051/compiler/src/CFCC.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCC.c b/compiler/src/CFCC.c
index 9c924cc..d1ae4dc 100644
--- a/compiler/src/CFCC.c
+++ b/compiler/src/CFCC.c
@@ -26,6 +26,7 @@
 #include "CFCClass.h"
 #include "CFCHierarchy.h"
 #include "CFCMethod.h"
+#include "CFCUri.h"
 #include "CFCUtil.h"
 
 struct CFCC {
@@ -227,4 +228,83 @@ CFCC_write_hostdefs(CFCC *self) {
     FREEMEM(content);
 }
 
+char*
+CFCC_link_text(CFCUri *uri_obj, CFCClass *klass) {
+    char *link_text = NULL;
+    int   type      = CFCUri_get_type(uri_obj);
+
+    switch (type) {
+        case CFC_URI_CLASS: {
+            if (strcmp(CFCUri_get_prefix(uri_obj),
+                       CFCClass_get_prefix(klass)) == 0
+            ) {
+                // Same parcel.
+                const char *struct_sym = CFCUri_get_struct_sym(uri_obj);
+                link_text = CFCUtil_strdup(struct_sym);
+            }
+            else {
+                // Other parcel.
+                const char *full_struct_sym = CFCUri_full_struct_sym(uri_obj);
+                CFCClass *uri_class
+                    = CFCClass_fetch_by_struct_sym(full_struct_sym);
+                if (!uri_class) {
+                    CFCUtil_warn("URI class not found: %s", full_struct_sym);
+                }
+                else {
+                    const char *class_name
+                        = CFCClass_get_class_name(uri_class);
+                    link_text = CFCUtil_strdup(class_name);
+                }
+            }
+
+            break;
+        }
+
+        case CFC_URI_FUNCTION:
+        case CFC_URI_METHOD: {
+#if 1
+            const char *func_sym = CFCUri_get_func_sym(uri_obj);
+            link_text = CFCUtil_sprintf("%s()", func_sym);
+#else
+            // Full function sym.
+            const char *full_struct_sym = CFCUri_full_struct_sym(uri_obj);
+            const char *func_sym        = CFCUri_get_func_sym(uri_obj);
+
+            if (strcmp(full_struct_sym,
+                       CFCClass_full_struct_sym(klass)) == 0
+            ) {
+                // Same class.
+                link_text = CFCUtil_sprintf("%s()", func_sym);
+            }
+            else {
+                CFCClass *uri_class
+                    = CFCClass_fetch_by_struct_sym(full_struct_sym);
+
+                if (!uri_class) {
+                    CFCUtil_warn("URI class not found: %s", full_struct_sym);
+                    link_text = CFCUtil_sprintf("%s()", func_sym);
+                }
+                else {
+                    const char *prefix   = CFCUri_get_prefix(uri_obj);
+                    const char *nickname = CFCClass_get_nickname(uri_class);
+
+                    if (strcmp(prefix, CFCClass_get_prefix(klass)) == 0) {
+                        // Same parcel.
+                        link_text = CFCUtil_sprintf("%s_%s()", nickname,
+                                                    func_sym);
+                    }
+                    else {
+                        // Other parcel.
+                        link_text = CFCUtil_sprintf("%s%s_%s()", prefix,
+                                                    nickname, func_sym);
+                    }
+                }
+            }
+#endif
+            break;
+        }
+    }
+
+    return link_text;
+}
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7f1d8051/compiler/src/CFCC.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCC.h b/compiler/src/CFCC.h
index 6f665ed..f4501ec 100644
--- a/compiler/src/CFCC.h
+++ b/compiler/src/CFCC.h
@@ -24,7 +24,9 @@ extern "C" {
 #endif
 
 typedef struct CFCC CFCC;
+struct CFCClass;
 struct CFCHierarchy;
+struct CFCUri;
 
 /**
  * @param hierarchy A L<Clownfish::CFC::Model::Hierarchy>.
@@ -59,6 +61,9 @@ CFCC_write_hostdefs(CFCC *self);
 void
 CFCC_write_man_pages(CFCC *self);
 
+char*
+CFCC_link_text(struct CFCUri *uri_obj, struct CFCClass *klass);
+
 #ifdef __cplusplus
 }
 #endif

Reply via email to