1 | /*
|
---|
2 | * TOPPERS Software
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
4 | *
|
---|
5 | * Copyright (C) 2010 by Meika Sugimoto
|
---|
6 | *
|
---|
7 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
8 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
9 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
10 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
11 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
12 | * XR[hÉÜÜêĢ鱯D
|
---|
13 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
14 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
15 | gip
|
---|
16 | * Ò}j
|
---|
17 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
18 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
19 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
20 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
21 | * ÆD
|
---|
22 | * (a) Äzzɺ¤hL
|
---|
23 | gipÒ}j
|
---|
24 | AÈÇjÉCãLÌ
|
---|
25 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
26 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
27 | * ñ·é±ÆD
|
---|
28 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
29 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
30 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
31 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
32 | * ÆÓ·é±ÆD
|
---|
33 | *
|
---|
34 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
35 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
36 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
37 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
38 | * ÌÓCðíÈ¢D
|
---|
39 | *
|
---|
40 | */
|
---|
41 |
|
---|
42 | #include <string>
|
---|
43 | #include <iostream>
|
---|
44 |
|
---|
45 | #include "toppers/oil/oil_parser.hpp"
|
---|
46 | #include "toppers/diagnostics.hpp"
|
---|
47 |
|
---|
48 | using namespace std;
|
---|
49 | using namespace boost::spirit;
|
---|
50 | using namespace toppers::oil;
|
---|
51 | using namespace toppers::oil::oil_implementation;
|
---|
52 | using namespace toppers::oil::oil_definition;
|
---|
53 |
|
---|
54 |
|
---|
55 | int oil_parser::do_parse(oil_impl **impl , oil_def **def)
|
---|
56 | {
|
---|
57 | oil_grammer grammer(this);
|
---|
58 | parse_info<> info;
|
---|
59 |
|
---|
60 | info = parse(description->c_str() , grammer , space_p);
|
---|
61 | if(info.hit)
|
---|
62 | {
|
---|
63 | *impl = &impl_list;
|
---|
64 | *def = &def_list;
|
---|
65 | return 0;
|
---|
66 | }
|
---|
67 | else
|
---|
68 | {
|
---|
69 | return -1;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | void eval_tree(tree_match<char const *>::tree_iterator const &iter, int nest) {
|
---|
74 | int size; // m[hÌqÌÂ
|
---|
75 |
|
---|
76 | size = iter->children.size(); // m[hÌqÌÂðæèo·
|
---|
77 | for(int i=0; i<nest; i++)
|
---|
78 | {
|
---|
79 | cout << " "; // Xy[XQªCfg
|
---|
80 | }
|
---|
81 | cout << "Node = '" << string(iter->value.begin(), iter->value.end()) << "'";
|
---|
82 | if (size > 0)
|
---|
83 | {
|
---|
84 | cout << " Child Size = " << size << endl; // qÌÂð\¦
|
---|
85 | } else
|
---|
86 | {
|
---|
87 | cout << endl; // qª³¯êÎÂ\¦µÈ¢
|
---|
88 | }
|
---|
89 | for(int j=0; j<size; j++)
|
---|
90 | {
|
---|
91 | eval_tree(iter->children.begin()+j, nest+1); // q̪ÄAÄÑoµ
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | int oil_parser::start_objimpl_analysis(std::string object_name)
|
---|
96 | {
|
---|
97 | int result = 0;
|
---|
98 |
|
---|
99 | try
|
---|
100 | {
|
---|
101 | // \¬ÌIuWFNgÀðÛ¶
|
---|
102 | current_impl = new oil_object_impl(object_name);
|
---|
103 | }
|
---|
104 | catch( ... )
|
---|
105 | {
|
---|
106 | result = -1;
|
---|
107 | }
|
---|
108 |
|
---|
109 | return result;
|
---|
110 | }
|
---|
111 |
|
---|
112 | int oil_parser::set_nextparam_name(std::string name)
|
---|
113 | {
|
---|
114 | if(param_addable == true)
|
---|
115 | {
|
---|
116 | next_param_name = name;
|
---|
117 | }
|
---|
118 |
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | int oil_parser::add_parameter_objimpl(std::string parameter)
|
---|
123 | {
|
---|
124 | // p[^ðÍAÇÁ
|
---|
125 | if(param_addable)
|
---|
126 | {
|
---|
127 | current_impl->add_parameter(next_param_name , parameter);
|
---|
128 | }
|
---|
129 |
|
---|
130 | return 0;
|
---|
131 | }
|
---|
132 |
|
---|
133 | int oil_parser::start_objdef_analysis(std::string object_name_type)
|
---|
134 | {
|
---|
135 | int result = 0;
|
---|
136 |
|
---|
137 | try
|
---|
138 | {
|
---|
139 | // \¬ÌIuWFNgÀðÛ¶
|
---|
140 | current_def = new object_definition(object_name_type);
|
---|
141 | }
|
---|
142 | catch( ... )
|
---|
143 | {
|
---|
144 | result = -1;
|
---|
145 | }
|
---|
146 | return result;
|
---|
147 | }
|
---|
148 |
|
---|
149 | int oil_parser::end_objimpl_analysis(void)
|
---|
150 | {
|
---|
151 | // \¬®¹Ao^
|
---|
152 | impl_list.push_back(current_impl);
|
---|
153 |
|
---|
154 | return 0;
|
---|
155 | }
|
---|
156 |
|
---|
157 | void oil_parser::enable_addparam(bool enabled)
|
---|
158 | {
|
---|
159 | param_addable = enabled;
|
---|
160 | }
|
---|
161 |
|
---|
162 | int oil_parser::end_objdef_analysis(void)
|
---|
163 | {
|
---|
164 | static std::vector<std::string> defined_object_name;
|
---|
165 | std::string obj_name = current_def->get_name();
|
---|
166 |
|
---|
167 | // ùɯ¶IuWFNgªÈ¢©`FbN
|
---|
168 | if(find(defined_object_name.begin() , defined_object_name.end() , obj_name)
|
---|
169 | == defined_object_name.end())
|
---|
170 | {
|
---|
171 | // \¬®¹Ao^
|
---|
172 | def_list.push_back(current_def);
|
---|
173 | // IuWFNg¼ðÇÁCo^ÏÝÉ·é
|
---|
174 | defined_object_name.push_back(obj_name);
|
---|
175 | }
|
---|
176 | else
|
---|
177 | {
|
---|
178 | // ¯¼ÌIuWFNg¼ª¶Ý·é½ßCG[
|
---|
179 | toppers::error("Object %1% redefined." , obj_name);
|
---|
180 | }
|
---|
181 |
|
---|
182 | return 0;
|
---|
183 | }
|
---|
184 |
|
---|
185 | int oil_parser::add_attr_value(string str)
|
---|
186 | {
|
---|
187 | attr_description = str;
|
---|
188 |
|
---|
189 | if(param_addable == true)
|
---|
190 | {
|
---|
191 | current_def->add_parameter(next_param_name , attr_description);
|
---|
192 | }
|
---|
193 |
|
---|
194 | return 0;
|
---|
195 | }
|
---|
196 |
|
---|
197 | void oil_parser::set_error(int position , std::string message)
|
---|
198 | {
|
---|
199 | error_position = position;
|
---|
200 | error_message = message;
|
---|
201 | }
|
---|
202 |
|
---|
203 | void oil_parser::get_error(int *position , std::string *message)
|
---|
204 | {
|
---|
205 | *position = error_position;
|
---|
206 | *message = error_message;
|
---|
207 | }
|
---|
208 |
|
---|
209 | void oil_parser::dump_implementation(void)
|
---|
210 | {
|
---|
211 | std::vector<oil_object_impl*>::iterator p;
|
---|
212 |
|
---|
213 | for(p = impl_list.begin(); p != impl_list.end() ; p++)
|
---|
214 | {
|
---|
215 | (*p)->display_implementation();
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | void oil_parser::dump_definition(void)
|
---|
220 | {
|
---|
221 | std::vector<object_definition*>::iterator p;
|
---|
222 |
|
---|
223 | cout << "************** Object Defition **************" << endl;
|
---|
224 | for(p = def_list.begin(); p != def_list.end() ; p++)
|
---|
225 | {
|
---|
226 | (*p)->display_definition();
|
---|
227 | }
|
---|
228 | cout << "************** Object Defition End **************" << endl;
|
---|
229 | }
|
---|