source: cfg_itronx+oil_gcc/toppers/oil/oil_parse.cpp@ 54

Last change on this file since 54 was 54, checked in by ertl-ishikawa, 12 years ago

cfg+oil対応コンフィギュレータを追加

File size: 5.4 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 * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
8 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
9 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
10 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
11 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
12 * スコード中に含まれていること.
13 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
14 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
15 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
16 * の無保証規定を掲載すること.
17 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
18 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
19 * と.
20 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
21 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
22 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
23 * 報告すること.
24 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
25 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
26 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
27 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
28 * 免責すること.
29 *
30 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
31 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
32 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
33 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
34 * の責任を負わない.
35 *
36 */
37
38#include <string>
39#include <iostream>
40
41#include "toppers/oil/oil_parser.hpp"
42#include "toppers/diagnostics.hpp"
43
44using namespace std;
45using namespace boost::spirit::classic;
46using namespace toppers::oil;
47using namespace toppers::oil::oil_implementation;
48using namespace toppers::oil::oil_definition;
49
50
51int oil_parser::do_parse(oil_impl **impl , oil_def **def)
52{
53 oil_grammer grammer(this);
54 parse_info<> info;
55
56 info = parse(description->c_str() , grammer , space_p);
57 if(info.hit)
58 {
59 *impl = &impl_list;
60 *def = &def_list;
61 return 0;
62 }
63 else
64 {
65 return -1;
66 }
67}
68
69void eval_tree(tree_match<char const *>::tree_iterator const &iter, int nest) {
70 int size; // ノードの子の個数
71
72 size = iter->children.size(); // ノードの子の個数を取り出す
73 for(int i=0; i<nest; i++)
74 {
75 cout << " "; // スペース2個分インデント
76 }
77 cout << "Node = '" << string(iter->value.begin(), iter->value.end()) << "'";
78 if (size > 0)
79 {
80 cout << " Child Size = " << size << endl; // 子の個数を表示
81 } else
82 {
83 cout << endl; // 子が無ければ個数表示しない
84 }
85 for(int j=0; j<size; j++)
86 {
87 eval_tree(iter->children.begin()+j, nest+1); // 子の個数分再帰呼び出し
88 }
89}
90
91int oil_parser::start_objimpl_analysis(std::string object_name)
92{
93 int result = 0;
94
95 try
96 {
97 // 構成中のオブジェクト実装部を保存
98 current_impl = new oil_object_impl(object_name);
99 }
100 catch( ... )
101 {
102 result = -1;
103 }
104
105 return result;
106}
107
108int oil_parser::set_nextparam_name(std::string name)
109{
110 if(param_addable == true)
111 {
112 next_param_name = name;
113 }
114
115 return 0;
116}
117
118int oil_parser::add_parameter_objimpl(std::string parameter)
119{
120 // パラメータ解析、追加
121 if(param_addable)
122 {
123 current_impl->add_parameter(next_param_name , parameter);
124 }
125
126 return 0;
127}
128
129int oil_parser::start_objdef_analysis(std::string object_name_type)
130{
131 int result = 0;
132
133 try
134 {
135 // 構成中のオブジェクト実装部を保存
136 current_def = new object_definition(object_name_type);
137 }
138 catch( ... )
139 {
140 result = -1;
141 }
142 return result;
143}
144
145int oil_parser::end_objimpl_analysis(void)
146{
147 // 構成完了、登録
148 impl_list.push_back(current_impl);
149
150 return 0;
151}
152
153void oil_parser::enable_addparam(bool enabled)
154{
155 param_addable = enabled;
156}
157
158int oil_parser::end_objdef_analysis(void)
159{
160 static std::vector<std::string> defined_object_name;
161 std::string obj_name = current_def->get_name();
162
163 // 既に同じオブジェクトがないかチェック
164 if(find(defined_object_name.begin() , defined_object_name.end() , obj_name)
165 == defined_object_name.end())
166 {
167 // 構成完了、登録
168 def_list.push_back(current_def);
169 // オブジェクト名を追加,登録済みにする
170 defined_object_name.push_back(obj_name);
171 }
172 else
173 {
174 // 同名のオブジェクト名が存在するため,エラー
175 toppers::error("Object %1% redefined." , obj_name);
176 }
177
178 return 0;
179}
180
181int oil_parser::add_attr_value(string str)
182{
183 attr_description = str;
184
185 if(param_addable == true)
186 {
187 current_def->add_parameter(next_param_name , attr_description);
188 }
189
190 return 0;
191}
192
193void oil_parser::set_error(int position , std::string message)
194{
195 error_position = position;
196 error_message = message;
197}
198
199void oil_parser::get_error(int *position , std::string *message)
200{
201 *position = error_position;
202 *message = error_message;
203}
204
205void oil_parser::dump_implementation(void)
206{
207 std::vector<oil_object_impl*>::iterator p;
208
209 for(p = impl_list.begin(); p != impl_list.end() ; p++)
210 {
211 (*p)->display_implementation();
212 }
213}
214
215void oil_parser::dump_definition(void)
216{
217 std::vector<object_definition*>::iterator p;
218
219 cout << "************** Object Defition **************" << endl;
220 for(p = def_list.begin(); p != def_list.end() ; p++)
221 {
222 (*p)->display_definition();
223 }
224 cout << "************** Object Defition End **************" << endl;
225}
Note: See TracBrowser for help on using the repository browser.