summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-11-21 14:12:40 +0000
committerDaniel Kolesa <d.kolesa@samsung.com>2014-11-21 14:12:40 +0000
commit3a8e08f74751a2cc0927b15c1ebf9fc6f56410fc (patch)
treec491aaeaab9ca5165a3331f143ed1e9eda7f7c15 /src
parent423629f81739813f9eaa1ea190c635e9486249d7 (diff)
eolian: one func for filling in namespaces
Diffstat (limited to 'src')
-rw-r--r--src/lib/eolian/eo_parser.c81
1 files changed, 35 insertions, 46 deletions
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index c45e79dcba..e343f73424 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -188,46 +188,30 @@ parse_name_list(Eo_Lexer *ls, Eina_List **out)
188 pop_strbuf(ls); 188 pop_strbuf(ls);
189} 189}
190 190
191#define NAMESPACE_PARSE(def, dname) \
192 char *full_name = strdup(dname); \
193 char *name = full_name, *dot = full_name; \
194 def->full_name = dname; \
195 do \
196 { \
197 dot = strchr(dot, '.'); \
198 if (dot) \
199 { \
200 *dot = '\0'; \
201 def->namespaces = eina_list_append(def->namespaces, \
202 eina_stringshare_add(name)); \
203 ++dot; \
204 name = dot; \
205 } \
206 } \
207 while (dot); \
208 def->name = eina_stringshare_add(name); \
209 free(full_name);
210
211static void
212_fill_type_name(Eolian_Type *tp, const char *type_name)
213{
214 NAMESPACE_PARSE(tp, type_name)
215}
216
217static void
218_fill_variable_name(Eolian_Variable *var, const char *var_name)
219{
220 NAMESPACE_PARSE(var, var_name)
221}
222
223static void 191static void
224_fill_class_name(Eolian_Class *cl, const char *cl_name) 192_fill_name(const char *input, Eina_Stringshare **full_name,
193 Eina_Stringshare **name, Eina_List **namespaces)
225{ 194{
226 NAMESPACE_PARSE(cl, cl_name) 195 char *fname = strdup(input);
196 char *sname = fname, *dot = fname;
197 *full_name = input;
198 do
199 {
200 dot = strchr(dot, '.');
201 if (dot)
202 {
203 *dot = '\0';
204 *namespaces = eina_list_append(*namespaces,
205 eina_stringshare_add(sname));
206 ++dot;
207 sname = dot;
208 }
209 }
210 while (dot);
211 *name = eina_stringshare_add(sname);
212 free(fname);
227} 213}
228 214
229#undef NAMESPACE_PARSE
230
231static Eolian_Expression * 215static Eolian_Expression *
232push_expr(Eo_Lexer *ls) 216push_expr(Eo_Lexer *ls)
233{ 217{
@@ -562,7 +546,7 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
562 int bline = ls->line_number, bcolumn = ls->column; 546 int bline = ls->line_number, bcolumn = ls->column;
563 Eolian_Type *def = push_type(ls); 547 Eolian_Type *def = push_type(ls);
564 def->is_extern = is_extern; 548 def->is_extern = is_extern;
565 if (name) _fill_type_name(def, name); 549 if (name) _fill_name(name, &def->full_name, &def->name, &def->namespaces);
566 def->type = EOLIAN_TYPE_STRUCT; 550 def->type = EOLIAN_TYPE_STRUCT;
567 def->fields = eina_hash_string_small_new(EINA_FREE_CB(_struct_field_free)); 551 def->fields = eina_hash_string_small_new(EINA_FREE_CB(_struct_field_free));
568 def->freefunc = freefunc; 552 def->freefunc = freefunc;
@@ -627,7 +611,7 @@ parse_enum(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
627 int bline = ls->line_number, bcolumn = ls->column; 611 int bline = ls->line_number, bcolumn = ls->column;
628 Eolian_Type *def = push_type(ls); 612 Eolian_Type *def = push_type(ls);
629 def->is_extern = is_extern; 613 def->is_extern = is_extern;
630 _fill_type_name(def, name); 614 _fill_name(name, &def->full_name, &def->name, &def->namespaces);
631 def->type = EOLIAN_TYPE_ENUM; 615 def->type = EOLIAN_TYPE_ENUM;
632 def->fields = eina_hash_string_small_new(EINA_FREE_CB(_enum_field_free)); 616 def->fields = eina_hash_string_small_new(EINA_FREE_CB(_enum_field_free));
633 check_next(ls, '{'); 617 check_next(ls, '{');
@@ -888,7 +872,7 @@ parse_type_named_void(Eo_Lexer *ls, Eina_Bool allow_named)
888 def->base.line = line; 872 def->base.line = line;
889 def->base.column = col; 873 def->base.column = col;
890 pop_str(ls); 874 pop_str(ls);
891 _fill_type_name(def, sname); 875 _fill_name(sname, &def->full_name, &def->name, &def->namespaces);
892 goto parse_ptr; 876 goto parse_ptr;
893 } 877 }
894 case KW_func: 878 case KW_func:
@@ -913,7 +897,8 @@ parse_type_named_void(Eo_Lexer *ls, Eina_Bool allow_named)
913 ctype = eo_lexer_get_c_type(ls->t.kw); 897 ctype = eo_lexer_get_c_type(ls->t.kw);
914 if (ctype) 898 if (ctype)
915 { 899 {
916 _fill_type_name(def, eina_stringshare_ref(ls->t.value.s)); 900 _fill_name(eina_stringshare_ref(ls->t.value.s), &def->full_name,
901 &def->name, &def->namespaces);
917 eo_lexer_get(ls); 902 eo_lexer_get(ls);
918 if (tpid >= KW_accessor) 903 if (tpid >= KW_accessor)
919 { 904 {
@@ -964,7 +949,8 @@ parse_type_named_void(Eo_Lexer *ls, Eina_Bool allow_named)
964 free(fnm); 949 free(fnm);
965 def->type = EOLIAN_TYPE_CLASS; 950 def->type = EOLIAN_TYPE_CLASS;
966 } 951 }
967 _fill_type_name(def, eina_stringshare_add(nm)); 952 _fill_name(eina_stringshare_add(nm), &def->full_name, &def->name,
953 &def->namespaces);
968 pop_strbuf(ls); 954 pop_strbuf(ls);
969 } 955 }
970 } 956 }
@@ -1010,7 +996,8 @@ parse_typedef(Eo_Lexer *ls)
1010 def->base.line = ls->line_number; 996 def->base.line = ls->line_number;
1011 def->base.column = ls->column; 997 def->base.column = ls->column;
1012 parse_name(ls, buf); 998 parse_name(ls, buf);
1013 _fill_type_name(def, eina_stringshare_add(eina_strbuf_string_get(buf))); 999 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
1000 &def->full_name, &def->name, &def->namespaces);
1014 Eolian_Type *tp = (Eolian_Type*)eina_hash_find(_aliases, def->full_name); 1001 Eolian_Type *tp = (Eolian_Type*)eina_hash_find(_aliases, def->full_name);
1015 if (tp) 1002 if (tp)
1016 { 1003 {
@@ -1053,7 +1040,8 @@ parse_variable(Eo_Lexer *ls, Eina_Bool global)
1053 def->base.line = ls->line_number; 1040 def->base.line = ls->line_number;
1054 def->base.column = ls->column; 1041 def->base.column = ls->column;
1055 parse_name(ls, buf); 1042 parse_name(ls, buf);
1056 _fill_variable_name(def, eina_stringshare_add(eina_strbuf_string_get(buf))); 1043 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
1044 &def->full_name, &def->name, &def->namespaces);
1057 check_next(ls, ':'); 1045 check_next(ls, ':');
1058 def->base_type = parse_type(ls); 1046 def->base_type = parse_type(ls);
1059 pop_type(ls); 1047 pop_type(ls);
@@ -1877,8 +1865,9 @@ parse_class(Eo_Lexer *ls, Eolian_Class_Type type)
1877 eo_lexer_syntax_error(ls, "class and file names differ"); 1865 eo_lexer_syntax_error(ls, "class and file names differ");
1878 } 1866 }
1879 eo_lexer_context_pop(ls); 1867 eo_lexer_context_pop(ls);
1880 _fill_class_name(ls->tmp.kls, eina_stringshare_add(eina_strbuf_string_get 1868 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
1881 (buf))); 1869 &ls->tmp.kls->full_name, &ls->tmp.kls->name,
1870 &ls->tmp.kls->namespaces);
1882 pop_strbuf(ls); 1871 pop_strbuf(ls);
1883 if (ls->t.token != '{') 1872 if (ls->t.token != '{')
1884 { 1873 {
@@ -1966,7 +1955,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
1966 def->type = EOLIAN_TYPE_STRUCT_OPAQUE; 1955 def->type = EOLIAN_TYPE_STRUCT_OPAQUE;
1967 def->freefunc = freefunc; 1956 def->freefunc = freefunc;
1968 pop_str(ls); 1957 pop_str(ls);
1969 _fill_type_name(def, name); 1958 _fill_name(name, &def->full_name, &def->name, &def->namespaces);
1970 eo_lexer_get(ls); 1959 eo_lexer_get(ls);
1971 if (ls->t.token == TOK_COMMENT) 1960 if (ls->t.token == TOK_COMMENT)
1972 { 1961 {