summaryrefslogtreecommitdiff
path: root/src/bin/eolian/docs_generator.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-07-07 17:19:13 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-07-07 17:19:13 +0100
commite9688e63a5ac0b08766b9c861ddb2ddd91944e98 (patch)
tree273222363316d449f0ba70071e20134a0d2ae178 /src/bin/eolian/docs_generator.c
parent70b70437317fbefd19270eb5fb11ca09dd90c92b (diff)
eolian/generator: add proper generation of references
Adds proper generation of automatic references in docs. For now events are missing. @feature
Diffstat (limited to '')
-rw-r--r--src/bin/eolian/docs_generator.c106
1 files changed, 103 insertions, 3 deletions
diff --git a/src/bin/eolian/docs_generator.c b/src/bin/eolian/docs_generator.c
index 5446f40049..201648891b 100644
--- a/src/bin/eolian/docs_generator.c
+++ b/src/bin/eolian/docs_generator.c
@@ -22,6 +22,98 @@ _indent_line(Eina_Strbuf *buf, int ind)
22#define DOC_LIMIT(ind) ((ind > DOC_LINE_TEST) ? (ind + DOC_LINE_OVER) \ 22#define DOC_LIMIT(ind) ((ind > DOC_LINE_TEST) ? (ind + DOC_LINE_OVER) \
23 : DOC_LINE_LIMIT) 23 : DOC_LINE_LIMIT)
24 24
25static void
26_generate_ref(const char *refn, Eina_Strbuf *wbuf)
27{
28 const Eolian_Declaration *decl = eolian_declaration_get_by_name(refn);
29 if (decl)
30 {
31 char *n = strdup(eolian_declaration_name_get(decl));
32 char *p = n;
33 while ((p = strchr(p, '.'))) *p = '_';
34 eina_strbuf_append(wbuf, n);
35 free(n);
36 return;
37 }
38
39 /* not a plain declaration, so it must be struct/enum field or func */
40 const char *sfx = strrchr(refn, '.');
41 if (!sfx) goto noref;
42
43 Eina_Stringshare *bname = eina_stringshare_add_length(refn, sfx - refn);
44
45 const Eolian_Type *tp = eolian_type_struct_get_by_name(bname);
46 if (tp)
47 {
48 if (!eolian_type_struct_field_get(tp, sfx + 1)) goto noref;
49 _generate_ref(bname, wbuf);
50 eina_strbuf_append(wbuf, sfx);
51 eina_stringshare_del(bname);
52 return;
53 }
54
55 tp = eolian_type_enum_get_by_name(bname);
56 if (tp)
57 {
58 const Eolian_Enum_Type_Field *efl = eolian_type_enum_field_get(tp, sfx + 1);
59 if (!efl) goto noref;
60 _generate_ref(bname, wbuf);
61 Eina_Stringshare *str = eolian_type_enum_field_c_name_get(efl);
62 eina_strbuf_append_char(wbuf, '.');
63 eina_strbuf_append(wbuf, str);
64 eina_stringshare_del(str);
65 eina_stringshare_del(bname);
66 return;
67 }
68
69 const Eolian_Class *cl = eolian_class_get_by_name(bname);
70 const Eolian_Function *fn = NULL;
71 Eolian_Function_Type ftype = EOLIAN_UNRESOLVED;
72 if (!cl)
73 {
74 const char *mname;
75 if (!strcmp(sfx, ".get")) ftype = EOLIAN_PROP_GET;
76 else if (!strcmp(sfx, ".set")) ftype = EOLIAN_PROP_SET;
77 if (ftype != EOLIAN_UNRESOLVED)
78 {
79 eina_stringshare_del(bname);
80 mname = sfx - 1;
81 while ((mname != refn) && (*mname != '.')) --mname;
82 if (mname == refn) goto noref;
83 bname = eina_stringshare_add_length(refn, mname - refn);
84 cl = eolian_class_get_by_name(bname);
85 eina_stringshare_del(bname);
86 }
87 if (cl)
88 {
89 char *meth = strndup(mname + 1, sfx - mname - 1);
90 fn = eolian_class_function_get_by_name(cl, meth, ftype);
91 if (ftype == EOLIAN_UNRESOLVED)
92 ftype = eolian_function_type_get(fn);
93 free(meth);
94 }
95 }
96 else
97 {
98 fn = eolian_class_function_get_by_name(cl, sfx + 1, ftype);
99 ftype = eolian_function_type_get(fn);
100 }
101
102 if (!fn) goto noref;
103
104 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fn);
105 eina_strbuf_append(wbuf, fcn);
106 eina_stringshare_del(fcn);
107 if ((ftype == EOLIAN_PROP_GET) || (ftype == EOLIAN_PROPERTY))
108 eina_strbuf_append(wbuf, "_get");
109 else if (ftype == EOLIAN_PROP_SET)
110 eina_strbuf_append(wbuf, "_set");
111
112 return;
113noref:
114 eina_strbuf_append(wbuf, refn);
115}
116
25int 117int
26_append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf, 118_append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf,
27 Eina_Strbuf *wbuf) 119 Eina_Strbuf *wbuf)
@@ -40,9 +132,17 @@ _append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf,
40 } 132 }
41 else if (*desc == '@') 133 else if (*desc == '@')
42 { 134 {
43 desc++; 135 const char *ref = ++desc;
44 if (isalpha(*desc)) 136 if (isalpha(*desc) || (*desc == '_'))
45 eina_strbuf_append(wbuf, "@ref "); 137 {
138 eina_strbuf_append(wbuf, "@ref ");
139 while (isalnum(*desc) || (*desc == '.') || (*desc == '_'))
140 ++desc;
141 if (*(desc - 1) == '.') --desc;
142 Eina_Stringshare *refn = eina_stringshare_add_length(ref, desc - ref);
143 _generate_ref(refn, wbuf);
144 eina_stringshare_del(refn);
145 }
46 else 146 else
47 eina_strbuf_append_char(wbuf, '@'); 147 eina_strbuf_append_char(wbuf, '@');
48 } 148 }