source: cfg_oil/trunk/toppers/oil/oil_parse.cpp@ 8

Last change on this file since 8 was 8, checked in by msugi, 13 years ago

ディレクトリ構造の作成,ソース一式とReleaseビルドのコミット.

File size: 5.6 KB
Line 
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–{ƒ\ƒtƒgƒEƒF
8 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
9 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
10 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
11 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
12 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
13 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
14 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
15ƒƒ“ƒgi—˜—p
16 * ŽÒƒ}ƒjƒ…
17ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
18 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
19 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
20 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
21 * ‚ƁD
22 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
23ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
24ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
25 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
26 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
27 * •ñ‚·‚邱‚ƁD
28 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
29 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
30 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
31 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
32 * –Ɛӂ·‚邱‚ƁD
33 *
34 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
35 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
36 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
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
48using namespace std;
49using namespace boost::spirit;
50using namespace toppers::oil;
51using namespace toppers::oil::oil_implementation;
52using namespace toppers::oil::oil_definition;
53
54
55int 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
73void 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 << " "; // ƒXƒy[ƒX‚QŒÂ•ªƒCƒ“ƒfƒ“ƒg
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
95int oil_parser::start_objimpl_analysis(std::string object_name)
96{
97 int result = 0;
98
99 try
100 {
101 // \¬’†‚̃IƒuƒWƒFƒNƒgŽÀ‘••”‚ð•Û‘¶
102 current_impl = new oil_object_impl(object_name);
103 }
104 catch( ... )
105 {
106 result = -1;
107 }
108
109 return result;
110}
111
112int 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
122int oil_parser::add_parameter_objimpl(std::string parameter)
123{
124 // ƒpƒ‰ƒ[ƒ^‰ðÍA’ljÁ
125 if(param_addable)
126 {
127 current_impl->add_parameter(next_param_name , parameter);
128 }
129
130 return 0;
131}
132
133int oil_parser::start_objdef_analysis(std::string object_name_type)
134{
135 int result = 0;
136
137 try
138 {
139 // \¬’†‚̃IƒuƒWƒFƒNƒgŽÀ‘••”‚ð•Û‘¶
140 current_def = new object_definition(object_name_type);
141 }
142 catch( ... )
143 {
144 result = -1;
145 }
146 return result;
147}
148
149int oil_parser::end_objimpl_analysis(void)
150{
151 // \¬Š®—¹A“o˜^
152 impl_list.push_back(current_impl);
153
154 return 0;
155}
156
157void oil_parser::enable_addparam(bool enabled)
158{
159 param_addable = enabled;
160}
161
162int 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 // Šù‚É“¯‚¶ƒIƒuƒWƒFƒNƒg‚ª‚È‚¢‚©ƒ`ƒFƒbƒN
168 if(find(defined_object_name.begin() , defined_object_name.end() , obj_name)
169 == defined_object_name.end())
170 {
171 // \¬Š®—¹A“o˜^
172 def_list.push_back(current_def);
173 // ƒIƒuƒWƒFƒNƒg–¼‚ð’ljÁC“o˜^Ï‚Ý‚É‚·‚é
174 defined_object_name.push_back(obj_name);
175 }
176 else
177 {
178 // “¯–¼‚̃IƒuƒWƒFƒNƒg–¼‚ª‘¶Ý‚·‚邽‚߁CƒGƒ‰[
179 toppers::error("Object %1% redefined." , obj_name);
180 }
181
182 return 0;
183}
184
185int 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
197void oil_parser::set_error(int position , std::string message)
198{
199 error_position = position;
200 error_message = message;
201}
202
203void oil_parser::get_error(int *position , std::string *message)
204{
205 *position = error_position;
206 *message = error_message;
207}
208
209void 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
219void 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}
Note: See TracBrowser for help on using the repository browser.