summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-10-27 13:07:05 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-10-27 13:07:05 -0200
commit470dc8e272cb18a3f6a1aa54afacfa456fa40eb7 (patch)
treeb3e94f8f91b6b6e2c101f2742a43247c7b44d992
parentf3831d9d85972f39b22fb0260ed8b7dda2b96441 (diff)
mono: Refactor executable
-rw-r--r--src/bin/eolian_mono/eolian_mono.cc94
1 files changed, 32 insertions, 62 deletions
diff --git a/src/bin/eolian_mono/eolian_mono.cc b/src/bin/eolian_mono/eolian_mono.cc
index e945b2c1ef..5463787e30 100644
--- a/src/bin/eolian_mono/eolian_mono.cc
+++ b/src/bin/eolian_mono/eolian_mono.cc
@@ -45,54 +45,14 @@ opts_check(eolian_mono::options_type const& opts)
45 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) 45 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
46 << "Nothing to generate?" << std::endl; 46 << "Nothing to generate?" << std::endl;
47 } 47 }
48 else 48 else if (opts.out_file.empty())
49 {
50 return true; // valid.
51 }
52 return false;
53}
54
55static bool
56generate(const Eolian_Typedecl* enum_obj, eolian_mono::options_type const& opts)
57{
58 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) << "would be generating enum";
59 return EINA_TRUE;
60}
61
62static bool
63generate(const Eolian_Class* klass, eolian_mono::options_type const& opts)
64{
65 std::string class_file_name = opts.out_file.empty()
66 ? (::eolian_class_file_get(klass) + std::string(".cs")) : opts.out_file;
67
68 efl::eolian::grammar::attributes::klass_def klass_def(klass);
69 std::vector<efl::eolian::grammar::attributes::klass_def> klasses{klass_def};
70
71 if(opts.out_file == "-")
72 { 49 {
73 std::ostream_iterator<char> iterator(std::cout); 50 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
74 51 << "Nowhere to generate?" << std::endl;
75 eolian_mono::klass.generate
76 (iterator, klass_def, efl::eolian::grammar::context_null());
77 std::endl(std::cout);
78 } 52 }
79 else 53 else
80 { 54 return true; // valid.
81 std::ofstream class_def; 55 return false;
82 class_def.open(class_file_name);
83 if (!class_def.good())
84 {
85 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
86 << "Can't open output file: " << class_file_name << std::endl;
87 return false;
88 }
89
90 eolian_mono::klass.generate
91 (std::ostream_iterator<char>(class_def), klass_def, efl::eolian::grammar::context_null());
92
93 class_def.close();
94 }
95 return true;
96} 56}
97 57
98static void 58static void
@@ -103,34 +63,44 @@ run(options_type const& opts)
103 char* base = basename(dup); 63 char* base = basename(dup);
104 klass = ::eolian_class_get_by_file(base); 64 klass = ::eolian_class_get_by_file(base);
105 free(dup); 65 free(dup);
66
67 std::string class_file_name = opts.out_file;
68
69 std::ofstream output_file;
70 std::ostream_iterator<char> iterator
71 {[&]
72 {
73 if(opts.out_file == "-")
74 return std::ostream_iterator<char>(std::cout);
75 else
76 {
77 output_file.open(class_file_name);
78 if (!output_file.good())
79 {
80 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
81 << "Can't open output file: " << class_file_name << std::endl;
82 throw std::runtime_error("");
83 }
84 return std::ostream_iterator<char>(output_file);
85 }
86 }()};
87
106 if (klass) 88 if (klass)
107 { 89 {
108 if (!generate(klass, opts)) 90 efl::eolian::grammar::attributes::klass_def klass_def(klass);
109 goto err; 91 std::vector<efl::eolian::grammar::attributes::klass_def> klasses{klass_def};
92
93 eolian_mono::klass.generate(iterator, klass_def, efl::eolian::grammar::context_null());
110 } 94 }
111 else 95 else
112 { 96 {
113 for (efl::eina::iterator<const Eolian_Typedecl> enum_iterator(::eolian_typedecl_enums_get_by_file(opts.in_file.c_str())) 97 for (efl::eina::iterator<const Eolian_Typedecl> enum_iterator(::eolian_typedecl_enums_get_by_file(opts.in_file.c_str()))
114 , enum_last; enum_iterator != enum_last; ++enum_iterator) 98 , enum_last; enum_iterator != enum_last; ++enum_iterator)
115 { 99 {
116 if (!generate(&*enum_iterator, opts)) 100 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) << "would be generating enum";
117 goto err;
118 } 101 }
119
120 // for(
121
122 // EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
123 // << "is this a type file?"
124 // << std::endl;
125 // //std::abort();
126 // goto err;
127 } 102 }
128 return; 103 return;
129 err:
130 EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
131 << "Error generating: " << ::eolian_class_name_get(klass)
132 << std::endl;
133 assert(false && "error generating class");
134} 104}
135 105
136static void 106static void