summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-12-14 17:18:32 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-12-14 17:31:21 +0100
commit9aaa5cf83915007ed43acabeb8ab3171b8ec23d1 (patch)
tree6b64772d982d6888f117fbf2f452f11caedc76b9 /src/lib
parent2259b6f16fc3f7cd186cc4966fb53efc12761938 (diff)
eolian: remove _cunit and prepare for returning actual units
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eolian/eo_lexer.c11
-rw-r--r--src/lib/eolian/eo_parser.c36
-rw-r--r--src/lib/eolian/eo_parser.h2
-rw-r--r--src/lib/eolian/eolian_database.c63
-rw-r--r--src/lib/eolian/eolian_database.h2
5 files changed, 61 insertions, 53 deletions
diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c
index afe7cc8a4c..80f08eac2c 100644
--- a/src/lib/eolian/eo_lexer.c
+++ b/src/lib/eolian/eo_lexer.c
@@ -1035,6 +1035,12 @@ eo_lexer_set_input(Eo_Lexer *ls, Eolian *state, const char *source)
1035 ls->icolumn = ls->column = -1; 1035 ls->icolumn = ls->column = -1;
1036 ls->decpoint = '.'; 1036 ls->decpoint = '.';
1037 next_char(ls); 1037 next_char(ls);
1038
1039 Eolian_Unit *ncunit = calloc(1, sizeof(Eolian_Unit));
1040 ls->unit = ncunit;
1041 database_unit_init(state, ncunit);
1042 eina_hash_add(state->units, ls->filename, ncunit);
1043
1038 if (ls->current != 0xEF) 1044 if (ls->current != 0xEF)
1039 return; 1045 return;
1040 next_char(ls); 1046 next_char(ls);
@@ -1044,11 +1050,6 @@ eo_lexer_set_input(Eo_Lexer *ls, Eolian *state, const char *source)
1044 if (ls->current != 0xBF) 1050 if (ls->current != 0xBF)
1045 return; 1051 return;
1046 next_char(ls); 1052 next_char(ls);
1047
1048 Eolian_Unit *ncunit = calloc(1, sizeof(Eolian_Unit));
1049 ls->unit = ncunit;
1050 database_unit_init(state, ncunit, ls->filename);
1051 eina_hash_add(state->units, ls->filename, ncunit);
1052} 1053}
1053 1054
1054static void 1055static void
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index e8cecef038..71e1d7ee55 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -683,7 +683,7 @@ _parse_dep(Eo_Lexer *ls, const char *fname, const char *name)
683 if (eina_hash_find(ls->state->parsing, fname)) 683 if (eina_hash_find(ls->state->parsing, fname))
684 return NULL; 684 return NULL;
685 Eolian_Class *cl = NULL; 685 Eolian_Class *cl = NULL;
686 if (!eo_parser_database_fill(ls->state, fname, EINA_FALSE, &cl) || !cl) 686 if (!eo_parser_database_fill(ls->unit, fname, EINA_FALSE, &cl) || !cl)
687 { 687 {
688 char buf[PATH_MAX]; 688 char buf[PATH_MAX];
689 eo_lexer_context_restore(ls); 689 eo_lexer_context_restore(ls);
@@ -2496,19 +2496,30 @@ end:
2496 return ret; 2496 return ret;
2497} 2497}
2498 2498
2499Eina_Bool 2499Eolian_Unit *
2500eo_parser_database_fill(Eolian *state, const char *filename, Eina_Bool eot, Eolian_Class **fcl) 2500eo_parser_database_fill(Eolian_Unit *parent, const char *filename, Eina_Bool eot, Eolian_Class **fcl)
2501{ 2501{
2502 Eolian_Class *cl = eina_hash_find(state->parsed, filename); 2502 Eolian_Class *cl = eina_hash_find(parent->state->parsed, filename);
2503 if (cl) 2503 if (cl)
2504 { 2504 {
2505 if (!eot && fcl) *fcl = cl; 2505 if (!eot && fcl) *fcl = cl;
2506 return EINA_TRUE; 2506 const char *fsl = strrchr(filename, '/');
2507 const char *bsl = strrchr(filename, '\\');
2508 const char *fname = NULL;
2509 if (fsl || bsl)
2510 fname = eina_stringshare_add((fsl > bsl) ? (fsl + 1) : (bsl + 1));
2511 if (fname)
2512 {
2513 Eolian_Unit *ret = eina_hash_find(parent->state->units, fname);
2514 eina_stringshare_del(fname);
2515 return ret;
2516 }
2517 return NULL;
2507 } 2518 }
2508 2519
2509 eina_hash_set(state->parsing, filename, (void *)EINA_TRUE); 2520 eina_hash_set(parent->state->parsing, filename, (void *)EINA_TRUE);
2510 2521
2511 Eo_Lexer *ls = eo_lexer_new(state, filename); 2522 Eo_Lexer *ls = eo_lexer_new(parent->state, filename);
2512 if (!ls) 2523 if (!ls)
2513 { 2524 {
2514 _eolian_log("unable to create lexer for file '%s'", filename); 2525 _eolian_log("unable to create lexer for file '%s'", filename);
@@ -2544,14 +2555,15 @@ eo_parser_database_fill(Eolian *state, const char *filename, Eina_Bool eot, Eoli
2544 if (fcl) *fcl = cl; 2555 if (fcl) *fcl = cl;
2545 2556
2546done: 2557done:
2547 eina_hash_set(state->parsed, filename, eot ? (void *)EINA_TRUE : cl); 2558 eina_hash_set(ls->state->parsed, filename, eot ? (void *)EINA_TRUE : cl);
2548 eina_hash_set(state->parsing, filename, (void *)EINA_FALSE); 2559 eina_hash_set(ls->state->parsing, filename, (void *)EINA_FALSE);
2560 eina_hash_add(parent->children, filename, ls->unit);
2549 2561
2550 eo_lexer_free(ls); 2562 eo_lexer_free(ls);
2551 return EINA_TRUE; 2563 return ls->unit;
2552 2564
2553error: 2565error:
2554 eina_hash_set(state->parsing, filename, (void *)EINA_FALSE); 2566 eina_hash_set(ls->state->parsing, filename, (void *)EINA_FALSE);
2555 eo_lexer_free(ls); 2567 eo_lexer_free(ls);
2556 return EINA_FALSE; 2568 return NULL;
2557} 2569}
diff --git a/src/lib/eolian/eo_parser.h b/src/lib/eolian/eo_parser.h
index 8196c5bf9d..f7422e4704 100644
--- a/src/lib/eolian/eo_parser.h
+++ b/src/lib/eolian/eo_parser.h
@@ -3,6 +3,6 @@
3 3
4#include "eo_lexer.h" 4#include "eo_lexer.h"
5 5
6Eina_Bool eo_parser_database_fill(Eolian *state, const char *filename, Eina_Bool eot, Eolian_Class **cl); 6Eolian_Unit *eo_parser_database_fill(Eolian_Unit *parent, const char *filename, Eina_Bool eot, Eolian_Class **cl);
7 7
8#endif /* __EO_PARSER_H__ */ \ No newline at end of file 8#endif /* __EO_PARSER_H__ */ \ No newline at end of file
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 360d979d77..bf1cd50c10 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -11,8 +11,6 @@
11Eina_Hash *_decls = NULL; 11Eina_Hash *_decls = NULL;
12Eina_Hash *_declsf = NULL; 12Eina_Hash *_declsf = NULL;
13 13
14static Eolian_Unit *_cunit = NULL;
15
16static int _database_init_count = 0; 14static int _database_init_count = 0;
17 15
18static void 16static void
@@ -542,17 +540,10 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
542} 540}
543 541
544void 542void
545database_unit_init(Eolian *state, Eolian_Unit *unit, Eina_Stringshare *fname) 543database_unit_init(Eolian *state, Eolian_Unit *unit)
546{ 544{
547 unit->state = state; 545 unit->state = state;
548 546
549 if (fname)
550 {
551 Eolian_Unit *ocunit = _cunit;
552 if (ocunit)
553 eina_hash_add(ocunit->children, fname, unit);
554 }
555
556 unit->children = eina_hash_stringshared_new(NULL); 547 unit->children = eina_hash_stringshared_new(NULL);
557 unit->classes = eina_hash_stringshared_new(EINA_FREE_CB(database_class_del)); 548 unit->classes = eina_hash_stringshared_new(EINA_FREE_CB(database_class_del));
558 unit->globals = eina_hash_stringshared_new(EINA_FREE_CB(database_var_del)); 549 unit->globals = eina_hash_stringshared_new(EINA_FREE_CB(database_var_del));
@@ -560,9 +551,6 @@ database_unit_init(Eolian *state, Eolian_Unit *unit, Eina_Stringshare *fname)
560 unit->aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 551 unit->aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
561 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 552 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
562 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 553 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
563
564 if (fname)
565 _cunit = unit;
566} 554}
567 555
568void 556void
@@ -586,7 +574,7 @@ eolian_new(void)
586 if (!state) 574 if (!state)
587 return NULL; 575 return NULL;
588 576
589 database_unit_init(state, &state->unit, NULL); 577 database_unit_init(state, &state->unit);
590 578
591 state->filenames_eo = eina_hash_string_small_new(free); 579 state->filenames_eo = eina_hash_string_small_new(free);
592 state->filenames_eot = eina_hash_string_small_new(free); 580 state->filenames_eot = eina_hash_string_small_new(free);
@@ -699,61 +687,62 @@ database_class_to_filename(const char *cname)
699 return ret; 687 return ret;
700} 688}
701 689
702static Eina_Bool 690static Eolian_Unit *
703_eolian_file_parse_nodep(Eolian *state, const char *filepath) 691_eolian_file_parse_nodep(Eolian_Unit *parent, const char *filepath)
704{ 692{
705 Eina_Bool is_eo; 693 Eina_Bool is_eo;
706 const char *eopath; 694 const char *eopath;
707 if (_database_init_count <= 0) 695 if (_database_init_count <= 0)
708 return EINA_FALSE; 696 return NULL;
709 is_eo = eina_str_has_suffix(filepath, EO_SUFFIX); 697 is_eo = eina_str_has_suffix(filepath, EO_SUFFIX);
710 if (!is_eo && !eina_str_has_suffix(filepath, EOT_SUFFIX)) 698 if (!is_eo && !eina_str_has_suffix(filepath, EOT_SUFFIX))
711 { 699 {
712 _eolian_log("file '%s' doesn't have a correct extension", filepath); 700 _eolian_log("file '%s' doesn't have a correct extension", filepath);
713 return EINA_FALSE; 701 return NULL;
714 } 702 }
715 if (!(eopath = eina_hash_find(is_eo ? state->filenames_eo : state->filenames_eot, filepath))) 703 if (!(eopath = eina_hash_find(is_eo ? parent->state->filenames_eo : parent->state->filenames_eot, filepath)))
716 { 704 {
717 char *vpath = eina_file_path_sanitize(filepath); 705 char *vpath = eina_file_path_sanitize(filepath);
718 Eina_Bool ret = eo_parser_database_fill(state, vpath, !is_eo, NULL); 706 Eolian_Unit *ret = eo_parser_database_fill(parent, vpath, !is_eo, NULL);
719 free(vpath); 707 free(vpath);
720 return ret; 708 return ret;
721 } 709 }
722 return eo_parser_database_fill(state, eopath, !is_eo, NULL); 710 return eo_parser_database_fill(parent, eopath, !is_eo, NULL);
723} 711}
724 712
725static Eina_Bool 713static Eina_Bool
726_parse_deferred(Eolian *state) 714_parse_deferred(Eolian_Unit *parent)
727{ 715{
728 Eina_Hash *defer = state->defer; 716 Eina_Hash *defer = parent->state->defer;
729 if (!defer || !eina_hash_population(defer)) 717 if (!defer || !eina_hash_population(defer))
730 return EINA_TRUE; 718 return EINA_TRUE;
731 /* clean room for more deps for later parsing */ 719 /* clean room for more deps for later parsing */
732 state->defer = eina_hash_string_small_new(NULL); 720 parent->state->defer = eina_hash_string_small_new(NULL);
733 Eina_Iterator *itr = eina_hash_iterator_data_new(defer); 721 Eina_Iterator *itr = eina_hash_iterator_data_new(defer);
734 const char *dep; 722 const char *dep;
735 EINA_ITERATOR_FOREACH(itr, dep) 723 EINA_ITERATOR_FOREACH(itr, dep)
736 { 724 {
737 if (!_eolian_file_parse_nodep(state, dep)) 725 Eolian_Unit *pdep = _eolian_file_parse_nodep(parent, dep);
726 if (!pdep || !_parse_deferred(pdep))
738 { 727 {
739 eina_iterator_free(itr); 728 eina_iterator_free(itr);
740 eina_hash_free_buckets(state->defer); 729 eina_hash_free_buckets(parent->state->defer);
741 eina_hash_free(defer); 730 eina_hash_free(defer);
742 return EINA_FALSE; 731 return EINA_FALSE;
743 } 732 }
744 } 733 }
745 eina_iterator_free(itr); 734 eina_iterator_free(itr);
746 eina_hash_free(defer); 735 eina_hash_free(defer);
747 /* in case more deps were queued in, parse them */ 736 return EINA_TRUE;
748 return _parse_deferred(state);
749} 737}
750 738
751EAPI const Eolian_Unit * 739EAPI const Eolian_Unit *
752eolian_file_parse(Eolian *state, const char *filepath) 740eolian_file_parse(Eolian *state, const char *filepath)
753{ 741{
754 if (!_eolian_file_parse_nodep(state, filepath)) 742 Eolian_Unit *ret = _eolian_file_parse_nodep((Eolian_Unit *)state, filepath);
743 if (!ret)
755 return NULL; 744 return NULL;
756 if (!_parse_deferred(state)) 745 if (!_parse_deferred(ret))
757 return NULL; 746 return NULL;
758 /* FIXME: pass unit properly */ 747 /* FIXME: pass unit properly */
759 if (!database_validate(state, &state->unit)) 748 if (!database_validate(state, &state->unit))
@@ -770,8 +759,11 @@ typedef struct _Parse_Data
770static Eina_Bool _tfile_parse(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata) 759static Eina_Bool _tfile_parse(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata)
771{ 760{
772 Parse_Data *pd = fdata; 761 Parse_Data *pd = fdata;
773 if (pd->ret) pd->ret = eo_parser_database_fill(pd->state, data, EINA_TRUE, NULL); 762 Eolian_Unit *unit = NULL;
774 if (pd->ret) pd->ret = _parse_deferred(pd->state); 763 if (pd->ret)
764 unit = eo_parser_database_fill((Eolian_Unit *)pd->state, data, EINA_TRUE, NULL);
765 pd->ret = !!unit;
766 if (pd->ret) pd->ret = _parse_deferred(unit);
775 return pd->ret; 767 return pd->ret;
776} 768}
777 769
@@ -795,8 +787,11 @@ eolian_all_eot_files_parse(Eolian *state)
795static Eina_Bool _file_parse(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata) 787static Eina_Bool _file_parse(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata)
796{ 788{
797 Parse_Data *pd = fdata; 789 Parse_Data *pd = fdata;
798 if (pd->ret) pd->ret = eo_parser_database_fill(pd->state, data, EINA_FALSE, NULL); 790 Eolian_Unit *unit = NULL;
799 if (pd->ret) pd->ret = _parse_deferred(pd->state); 791 if (pd->ret)
792 unit = eo_parser_database_fill((Eolian_Unit *)pd->state, data, EINA_FALSE, NULL);
793 pd->ret = !!unit;
794 if (pd->ret) pd->ret = _parse_deferred(unit);
800 return pd->ret; 795 return pd->ret;
801} 796}
802 797
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 6b4a06b0f7..b2e72907ab 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -327,7 +327,7 @@ void database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type,
327 327
328void database_doc_del(Eolian_Documentation *doc); 328void database_doc_del(Eolian_Documentation *doc);
329 329
330void database_unit_init(Eolian *state, Eolian_Unit *unit, Eina_Stringshare *fname); 330void database_unit_init(Eolian *state, Eolian_Unit *unit);
331void database_unit_del(Eolian_Unit *unit); 331void database_unit_del(Eolian_Unit *unit);
332 332
333/* types */ 333/* types */