summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-12-15 16:08:27 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-12-15 17:11:11 +0100
commitc8aa30e698fa95cf425c35bb359fbab55cb64110 (patch)
tree3417a7bd3bc6c8e4e089bd59be27df2534482173
parentf05249f30b732fc21a6bbd0a4c290760af340bef (diff)
eolian: make declaration APIs use units
-rw-r--r--src/bin/eolian/docs.c2
-rw-r--r--src/bin/eolian/main.c22
-rw-r--r--src/bin/eolian/types.c10
-rw-r--r--src/bin/eolian/types.h4
-rw-r--r--src/bindings/luajit/eolian.lua24
-rw-r--r--src/lib/eolian/Eolian.h9
-rw-r--r--src/lib/eolian/eolian_database.c8
-rw-r--r--src/tests/eolian/eolian_parsing.c6
8 files changed, 44 insertions, 41 deletions
diff --git a/src/bin/eolian/docs.c b/src/bin/eolian/docs.c
index 9807b727b7..09e63bf9ac 100644
--- a/src/bin/eolian/docs.c
+++ b/src/bin/eolian/docs.c
@@ -22,7 +22,7 @@ static void
22_generate_ref(const Eolian_Unit *src, const char *refn, Eina_Strbuf *wbuf, 22_generate_ref(const Eolian_Unit *src, const char *refn, Eina_Strbuf *wbuf,
23 Eina_Bool use_legacy) 23 Eina_Bool use_legacy)
24{ 24{
25 const Eolian_Declaration *decl = eolian_declaration_get_by_name(refn); 25 const Eolian_Declaration *decl = eolian_declaration_get_by_name(src, refn);
26 if (decl) 26 if (decl)
27 { 27 {
28 char *n = strdup(eolian_declaration_name_get(decl)); 28 char *n = strdup(eolian_declaration_name_get(decl));
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 92643c6f7e..4c51e18d17 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -318,13 +318,14 @@ void eo_gen_class_names_get(const Eolian_Class *cl, char **cname,
318} 318}
319 319
320static Eina_Bool 320static Eina_Bool
321_write_header(const Eolian_Unit *src, const char *ofname, 321_write_header(const Eolian *eos, const Eolian_Unit *src, const char *ofname,
322 const char *ifname, Eina_Bool legacy) 322 const char *ifname, Eina_Bool legacy)
323{ 323{
324 INF("generating header: %s (legacy: %d)", ofname, legacy); 324 INF("generating header: %s (legacy: %d)", ofname, legacy);
325 Eina_Strbuf *buf = eina_strbuf_new(); 325 Eina_Strbuf *buf = eina_strbuf_new();
326 326
327 eo_gen_types_header_gen(src, ifname, buf, EINA_TRUE, legacy); 327 eo_gen_types_header_gen(src, eolian_declarations_get_by_file(eos, ifname),
328 buf, EINA_TRUE, legacy);
328 buf = _include_guard(ifname, "TYPES", buf); 329 buf = _include_guard(ifname, "TYPES", buf);
329 330
330 Eina_Strbuf *cltd = eo_gen_class_typedef_gen(src, ifname); 331 Eina_Strbuf *cltd = eo_gen_class_typedef_gen(src, ifname);
@@ -353,13 +354,14 @@ _write_header(const Eolian_Unit *src, const char *ofname,
353} 354}
354 355
355static Eina_Bool 356static Eina_Bool
356_write_stub_header(const Eolian_Unit *src, const char *ofname, 357_write_stub_header(const Eolian *eos, const Eolian_Unit *src, const char *ofname,
357 const char *ifname) 358 const char *ifname)
358{ 359{
359 INF("generating stub header: %s", ofname); 360 INF("generating stub header: %s", ofname);
360 Eina_Strbuf *buf = eina_strbuf_new(); 361 Eina_Strbuf *buf = eina_strbuf_new();
361 362
362 eo_gen_types_header_gen(src, ifname, buf, EINA_FALSE, EINA_FALSE); 363 eo_gen_types_header_gen(src, eolian_declarations_get_by_file(eos, ifname),
364 buf, EINA_FALSE, EINA_FALSE);
363 365
364 Eina_Strbuf *cltd = eo_gen_class_typedef_gen(src, ifname); 366 Eina_Strbuf *cltd = eo_gen_class_typedef_gen(src, ifname);
365 if (cltd) 367 if (cltd)
@@ -377,14 +379,14 @@ _write_stub_header(const Eolian_Unit *src, const char *ofname,
377} 379}
378 380
379static Eina_Bool 381static Eina_Bool
380_write_source(const Eolian_Unit *src, const char *ofname, 382_write_source(const Eolian *eos, const Eolian_Unit *src, const char *ofname,
381 const char *ifname, Eina_Bool eot) 383 const char *ifname, Eina_Bool eot)
382{ 384{
383 INF("generating source: %s", ofname); 385 INF("generating source: %s", ofname);
384 Eina_Strbuf *buf = eina_strbuf_new(); 386 Eina_Strbuf *buf = eina_strbuf_new();
385 387
386 const Eolian_Class *cl = eolian_class_get_by_file(src, ifname); 388 const Eolian_Class *cl = eolian_class_get_by_file(src, ifname);
387 eo_gen_types_source_gen(src, ifname, buf); 389 eo_gen_types_source_gen(src, eolian_declarations_get_by_file(eos, ifname), buf);
388 eo_gen_source_gen(src, cl, buf); 390 eo_gen_source_gen(src, cl, buf);
389 if (cl || (eot && eina_strbuf_length_get(buf))) 391 if (cl || (eot && eina_strbuf_length_get(buf)))
390 { 392 {
@@ -565,13 +567,13 @@ main(int argc, char **argv)
565 567
566 Eina_Bool succ = EINA_TRUE; 568 Eina_Bool succ = EINA_TRUE;
567 if (gen_what & GEN_H) 569 if (gen_what & GEN_H)
568 succ = _write_header(src, outs[_get_bit_pos(GEN_H)], eobn, EINA_FALSE); 570 succ = _write_header(eos, src, outs[_get_bit_pos(GEN_H)], eobn, EINA_FALSE);
569 if (succ && (gen_what & GEN_H_LEGACY)) 571 if (succ && (gen_what & GEN_H_LEGACY))
570 succ = _write_header(src, outs[_get_bit_pos(GEN_H_LEGACY)], eobn, EINA_TRUE); 572 succ = _write_header(eos, src, outs[_get_bit_pos(GEN_H_LEGACY)], eobn, EINA_TRUE);
571 if (succ && (gen_what & GEN_H_STUB)) 573 if (succ && (gen_what & GEN_H_STUB))
572 succ = _write_stub_header(src, outs[_get_bit_pos(GEN_H_STUB)], eobn); 574 succ = _write_stub_header(eos, src, outs[_get_bit_pos(GEN_H_STUB)], eobn);
573 if (succ && (gen_what & GEN_C)) 575 if (succ && (gen_what & GEN_C))
574 succ = _write_source(src, outs[_get_bit_pos(GEN_C)], eobn, !strcmp(ext, ".eot")); 576 succ = _write_source(eos, src, outs[_get_bit_pos(GEN_C)], eobn, !strcmp(ext, ".eot"));
575 if (succ && (gen_what & GEN_C_IMPL)) 577 if (succ && (gen_what & GEN_C_IMPL))
576 succ = _write_impl(src, outs[_get_bit_pos(GEN_C_IMPL)], eobn); 578 succ = _write_impl(src, outs[_get_bit_pos(GEN_C_IMPL)], eobn);
577 579
diff --git a/src/bin/eolian/types.c b/src/bin/eolian/types.c
index ae4cd72d63..c98791e965 100644
--- a/src/bin/eolian/types.c
+++ b/src/bin/eolian/types.c
@@ -204,12 +204,10 @@ _var_generate(const Eolian_Unit *src, const Eolian_Variable *vr, Eina_Bool legac
204} 204}
205 205
206void eo_gen_types_header_gen(const Eolian_Unit *src, 206void eo_gen_types_header_gen(const Eolian_Unit *src,
207 const char *eof, Eina_Strbuf *buf, 207 Eina_Iterator *itr, Eina_Strbuf *buf,
208 Eina_Bool full, Eina_Bool legacy) 208 Eina_Bool full, Eina_Bool legacy)
209{ 209{
210 const Eolian_Declaration *decl; 210 const Eolian_Declaration *decl;
211
212 Eina_Iterator *itr = eolian_declarations_get_by_file(eof);
213 EINA_ITERATOR_FOREACH(itr, decl) 211 EINA_ITERATOR_FOREACH(itr, decl)
214 { 212 {
215 Eolian_Declaration_Type dt = eolian_declaration_type_get(decl); 213 Eolian_Declaration_Type dt = eolian_declaration_type_get(decl);
@@ -256,14 +254,13 @@ void eo_gen_types_header_gen(const Eolian_Unit *src,
256 eina_strbuf_free(tbuf); 254 eina_strbuf_free(tbuf);
257 } 255 }
258 } 256 }
257 eina_iterator_free(itr);
259} 258}
260 259
261void eo_gen_types_source_gen(const Eolian_Unit *src, 260void eo_gen_types_source_gen(const Eolian_Unit *src,
262 const char *eof, Eina_Strbuf *buf) 261 Eina_Iterator *itr, Eina_Strbuf *buf)
263{ 262{
264 const Eolian_Declaration *decl; 263 const Eolian_Declaration *decl;
265
266 Eina_Iterator *itr = eolian_declarations_get_by_file(eof);
267 EINA_ITERATOR_FOREACH(itr, decl) 264 EINA_ITERATOR_FOREACH(itr, decl)
268 { 265 {
269 Eolian_Declaration_Type dt = eolian_declaration_type_get(decl); 266 Eolian_Declaration_Type dt = eolian_declaration_type_get(decl);
@@ -305,6 +302,7 @@ void eo_gen_types_source_gen(const Eolian_Unit *src,
305 302
306 eina_strbuf_append(buf, "\n"); 303 eina_strbuf_append(buf, "\n");
307 } 304 }
305 eina_iterator_free(itr);
308} 306}
309 307
310Eina_Strbuf *eo_gen_class_typedef_gen(const Eolian_Unit *src, const char *eof) 308Eina_Strbuf *eo_gen_class_typedef_gen(const Eolian_Unit *src, const char *eof)
diff --git a/src/bin/eolian/types.h b/src/bin/eolian/types.h
index 100206f703..7ad56673b9 100644
--- a/src/bin/eolian/types.h
+++ b/src/bin/eolian/types.h
@@ -1,8 +1,8 @@
1#ifndef EOLIAN_GEN_TYPES_H 1#ifndef EOLIAN_GEN_TYPES_H
2#define EOLIAN_GEN_TYPES_H 2#define EOLIAN_GEN_TYPES_H
3 3
4void eo_gen_types_header_gen(const Eolian_Unit *src, const char *eof, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool legacy); 4void eo_gen_types_header_gen(const Eolian_Unit *src, Eina_Iterator *itr, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool legacy);
5void eo_gen_types_source_gen(const Eolian_Unit *src, const char *eof, Eina_Strbuf *buf); 5void eo_gen_types_source_gen(const Eolian_Unit *src, Eina_Iterator *itr, Eina_Strbuf *buf);
6Eina_Strbuf *eo_gen_class_typedef_gen(const Eolian_Unit *src, const char *eof); 6Eina_Strbuf *eo_gen_class_typedef_gen(const Eolian_Unit *src, const char *eof);
7 7
8#endif 8#endif
diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/luajit/eolian.lua
index b7d4d6ec0d..2851df007a 100644
--- a/src/bindings/luajit/eolian.lua
+++ b/src/bindings/luajit/eolian.lua
@@ -454,9 +454,9 @@ ffi.cdef [[
454 const char *eolian_variable_full_name_get(const Eolian_Variable *var); 454 const char *eolian_variable_full_name_get(const Eolian_Variable *var);
455 Eina_Iterator *eolian_variable_namespaces_get(const Eolian_Variable *var); 455 Eina_Iterator *eolian_variable_namespaces_get(const Eolian_Variable *var);
456 Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var); 456 Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
457 const Eolian_Declaration *eolian_declaration_get_by_name(const char *name); 457 const Eolian_Declaration *eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name);
458 Eina_Iterator *eolian_declarations_get_by_file(const char *fname); 458 Eina_Iterator *eolian_declarations_get_by_file(const Eolian *state, const char *fname);
459 Eina_Iterator *eolian_all_declarations_get(void); 459 Eina_Iterator *eolian_all_declarations_get(const Eolian_Unit *unit);
460 Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl); 460 Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl);
461 const char *eolian_declaration_name_get(const Eolian_Declaration *decl); 461 const char *eolian_declaration_name_get(const Eolian_Declaration *decl);
462 const Eolian_Class *eolian_declaration_class_get(const Eolian_Declaration *decl); 462 const Eolian_Class *eolian_declaration_class_get(const Eolian_Declaration *decl);
@@ -554,6 +554,11 @@ ffi.metatype("Eolian", {
554 return iterator.String_Iterator(eolian.eolian_all_eot_files_get(self)) 554 return iterator.String_Iterator(eolian.eolian_all_eot_files_get(self))
555 end, 555 end,
556 556
557 declarations_get_by_file = function(self, fname)
558 return Ptr_Iterator("const Eolian_Declaration*",
559 eolian.eolian_declarations_get_by_file(self, fname))
560 end,
561
557 unit_get = function(self) 562 unit_get = function(self)
558 return ffi.cast("Eolian_Unit *", self) 563 return ffi.cast("Eolian_Unit *", self)
559 end 564 end
@@ -1613,22 +1618,17 @@ M.Variable = ffi.metatype("Eolian_Variable", {
1613 } 1618 }
1614}) 1619})
1615 1620
1616M.declaration_get_by_name = function(name) 1621M.declaration_get_by_name = function(unit, name)
1617 local v = eolian.eolian_declaration_get_by_name(name) 1622 local v = eolian.eolian_declaration_get_by_name(unit, name)
1618 if v == nil then 1623 if v == nil then
1619 return nil 1624 return nil
1620 end 1625 end
1621 return v 1626 return v
1622end 1627end
1623 1628
1624M.declarations_get_by_file = function(fname) 1629M.all_declarations_get = function(unit)
1625 return Ptr_ITerator("const Eolian_Declaration*",
1626 eolian.eolian_declarations_get_by_file(fname))
1627end
1628
1629M.all_declarations_get = function()
1630 return Ptr_Iterator("const Eolian_Declaration *", 1630 return Ptr_Iterator("const Eolian_Declaration *",
1631 eolian.eolian_all_declarations_get()) 1631 eolian.eolian_all_declarations_get(unit))
1632end 1632end
1633 1633
1634M.Declaration = ffi.metatype("Eolian_Declaration", { 1634M.Declaration = ffi.metatype("Eolian_Declaration", {
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index bfb8c5387a..d109ea12a2 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -2398,12 +2398,13 @@ EAPI Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
2398/* 2398/*
2399 * @brief Get a declaration by name. 2399 * @brief Get a declaration by name.
2400 * 2400 *
2401 * @param[in] unit the unit to look in
2401 * @param[in] name the declaration name. 2402 * @param[in] name the declaration name.
2402 * @return the declaration. 2403 * @return the declaration.
2403 * 2404 *
2404 * @ingroup Eolian 2405 * @ingroup Eolian
2405 */ 2406 */
2406EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const char *name); 2407EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name);
2407 2408
2408/* 2409/*
2409 * @brief Get a list of declarations in a file. 2410 * @brief Get a list of declarations in a file.
@@ -2413,23 +2414,25 @@ EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const char *name);
2413 * or a variable. This way you can get them all in the original order they 2414 * or a variable. This way you can get them all in the original order they
2414 * were declared in, which is useful during generation. 2415 * were declared in, which is useful during generation.
2415 * 2416 *
2417 * @param[in] state the state to look in
2416 * @param[in] fname the filename. 2418 * @param[in] fname the filename.
2417 * @return the iterator or NULL. 2419 * @return the iterator or NULL.
2418 * 2420 *
2419 * @ingroup Eolian 2421 * @ingroup Eolian
2420 */ 2422 */
2421EAPI Eina_Iterator *eolian_declarations_get_by_file(const char *fname); 2423EAPI Eina_Iterator *eolian_declarations_get_by_file(const Eolian *state, const char *fname);
2422 2424
2423/* 2425/*
2424 * @brief Get an iterator to all declarations in the Eolian database. 2426 * @brief Get an iterator to all declarations in the Eolian database.
2425 * 2427 *
2428 * @param[in] unit the unit to look in
2426 * @return the iterator or NULL. 2429 * @return the iterator or NULL.
2427 * 2430 *
2428 * Thanks to internal caching this is an O(1) operation. 2431 * Thanks to internal caching this is an O(1) operation.
2429 * 2432 *
2430 * @ingroup Eolian 2433 * @ingroup Eolian
2431 */ 2434 */
2432EAPI Eina_Iterator *eolian_all_declarations_get(void); 2435EAPI Eina_Iterator *eolian_all_declarations_get(const Eolian_Unit *unit);
2433 2436
2434/* 2437/*
2435 * @brief Get the type of a declaration 2438 * @brief Get the type of a declaration
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index bf1cd50c10..0c1513ab8f 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -60,7 +60,7 @@ database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type,
60} 60}
61 61
62EAPI const Eolian_Declaration * 62EAPI const Eolian_Declaration *
63eolian_declaration_get_by_name(const char *name) 63eolian_declaration_get_by_name(const Eolian_Unit *unit EINA_UNUSED, const char *name)
64{ 64{
65 if (!_decls) return NULL; 65 if (!_decls) return NULL;
66 Eina_Stringshare *shr = eina_stringshare_add(name); 66 Eina_Stringshare *shr = eina_stringshare_add(name);
@@ -70,7 +70,7 @@ eolian_declaration_get_by_name(const char *name)
70} 70}
71 71
72EAPI Eina_Iterator * 72EAPI Eina_Iterator *
73eolian_declarations_get_by_file(const char *fname) 73eolian_declarations_get_by_file(const Eolian *state EINA_UNUSED, const char *fname)
74{ 74{
75 if (!_declsf) return NULL; 75 if (!_declsf) return NULL;
76 Eina_Stringshare *shr = eina_stringshare_add(fname); 76 Eina_Stringshare *shr = eina_stringshare_add(fname);
@@ -81,7 +81,7 @@ eolian_declarations_get_by_file(const char *fname)
81} 81}
82 82
83EAPI Eina_Iterator * 83EAPI Eina_Iterator *
84eolian_all_declarations_get(void) 84eolian_all_declarations_get(const Eolian_Unit *unit EINA_UNUSED)
85{ 85{
86 return (_decls ? eina_hash_iterator_data_new(_decls) : NULL); 86 return (_decls ? eina_hash_iterator_data_new(_decls) : NULL);
87} 87}
@@ -448,7 +448,7 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
448 memcpy(name, tok->text, nlen); 448 memcpy(name, tok->text, nlen);
449 name[nlen] = '\0'; 449 name[nlen] = '\0';
450 450
451 const Eolian_Declaration *decl = eolian_declaration_get_by_name(name); 451 const Eolian_Declaration *decl = eolian_declaration_get_by_name(unit, name);
452 if (decl) switch (eolian_declaration_type_get(decl)) 452 if (decl) switch (eolian_declaration_type_get(decl))
453 { 453 {
454 case EOLIAN_DECL_CLASS: 454 case EOLIAN_DECL_CLASS:
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index 788ca774c3..58acf555f1 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -1136,7 +1136,7 @@ START_TEST(eolian_decl)
1136 fail_if(!(unit = eolian_file_parse(eos, PACKAGE_DATA_DIR"/data/decl.eo"))); 1136 fail_if(!(unit = eolian_file_parse(eos, PACKAGE_DATA_DIR"/data/decl.eo")));
1137 fail_if(!(class = eolian_class_get_by_name(unit, "Decl"))); 1137 fail_if(!(class = eolian_class_get_by_name(unit, "Decl")));
1138 1138
1139 fail_if(!(itr = eolian_declarations_get_by_file("decl.eo"))); 1139 fail_if(!(itr = eolian_declarations_get_by_file(eos, "decl.eo")));
1140 1140
1141 fail_if(!eina_iterator_next(itr, (void**)&decl)); 1141 fail_if(!eina_iterator_next(itr, (void**)&decl));
1142 fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT); 1142 fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT);
@@ -1172,10 +1172,10 @@ START_TEST(eolian_decl)
1172 1172
1173 fail_if(eina_iterator_next(itr, (void**)&decl)); 1173 fail_if(eina_iterator_next(itr, (void**)&decl));
1174 1174
1175 fail_if(!(decl = eolian_declaration_get_by_name("pants"))); 1175 fail_if(!(decl = eolian_declaration_get_by_name(unit, "pants")));
1176 fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_VAR); 1176 fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_VAR);
1177 1177
1178 fail_if(!(decl = eolian_declaration_get_by_name("A"))); 1178 fail_if(!(decl = eolian_declaration_get_by_name(unit, "A")));
1179 fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT); 1179 fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT);
1180 1180
1181 eolian_free(eos); 1181 eolian_free(eos);