1 | /*
|
---|
2 | * TOPPERS Software
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
4 | *
|
---|
5 | * Copyright (C) 2005-2008 by TAKAGI Nobuhisa
|
---|
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 | /*!
|
---|
43 | * \file toppers/c_pp_line.hpp
|
---|
44 | * \brief \#linewßÉÖ·éé¾è`
|
---|
45 | */
|
---|
46 | #ifndef TOPPERS_C_PP_LINE_HPP_
|
---|
47 | #define TOPPERS_C_PP_LINE_HPP_
|
---|
48 |
|
---|
49 | #include "toppers/text_line.hpp"
|
---|
50 | #include "toppers/c_parser.hpp"
|
---|
51 | #include "toppers/workaround.hpp"
|
---|
52 | #include <vector>
|
---|
53 | #include <functional>
|
---|
54 |
|
---|
55 | namespace toppers
|
---|
56 | {
|
---|
57 |
|
---|
58 | namespace detail
|
---|
59 | {
|
---|
60 |
|
---|
61 | //! \#line wßÌ\¶ðÍ
|
---|
62 | struct c_pp_line_parser : boost::spirit::grammar< c_pp_line_parser >
|
---|
63 | {
|
---|
64 | template < class Scanner >
|
---|
65 | struct definition
|
---|
66 | {
|
---|
67 | typedef boost::spirit::rule< Scanner > rule_t;
|
---|
68 | rule_t r;
|
---|
69 | definition( c_pp_line_parser const& self )
|
---|
70 | {
|
---|
71 | using namespace boost::spirit;
|
---|
72 | r = (
|
---|
73 | '#' >> lexeme_d[ str_p( "line" ) >> space_p >> uint_p[ assign_a( self.line_ ) ] ] >>
|
---|
74 | c_strlit_parser( self.codeset_ )[ assign_a( self.file_ ) ]
|
---|
75 | )
|
---|
76 | | (
|
---|
77 | '#' >>
|
---|
78 | uint_p[ assign_a( self.line_ ) ] >>
|
---|
79 | c_strlit_parser( self.codeset_ )[ assign_a( self.file_ ) ] >>
|
---|
80 | *anychar_p
|
---|
81 | );
|
---|
82 | }
|
---|
83 | rule_t const& start() const { return r; }
|
---|
84 | };
|
---|
85 |
|
---|
86 | c_pp_line_parser( long& line, std::string& file, codeset_t codeset = ascii )
|
---|
87 | : line_( line ), file_( file ), codeset_( codeset )
|
---|
88 | {
|
---|
89 | }
|
---|
90 |
|
---|
91 | long& line_;
|
---|
92 | std::string& file_;
|
---|
93 | codeset_t codeset_;
|
---|
94 | };
|
---|
95 |
|
---|
96 | //! \#pragma wßÌ\¶ðÍ
|
---|
97 | struct c_pp_pragma_parser : boost::spirit::grammar< c_pp_pragma_parser >
|
---|
98 | {
|
---|
99 | template < class Scanner >
|
---|
100 | struct definition
|
---|
101 | {
|
---|
102 | typedef boost::spirit::rule< Scanner > rule_t;
|
---|
103 | rule_t r;
|
---|
104 | definition( c_pp_pragma_parser const& self )
|
---|
105 | {
|
---|
106 | using namespace boost::spirit;
|
---|
107 | r = '#' >> lexeme_d[ str_p( "pragma" ) >> space_p >> ( +anychar_p )[ assign_a( self.parameter_ ) ] ];
|
---|
108 | }
|
---|
109 | rule_t const& start() const { return r; }
|
---|
110 | };
|
---|
111 |
|
---|
112 | c_pp_pragma_parser( std::string& parameter ) : parameter_( parameter )
|
---|
113 | {
|
---|
114 | }
|
---|
115 | std::string& parameter_;
|
---|
116 | };
|
---|
117 |
|
---|
118 | }
|
---|
119 |
|
---|
120 | /*!
|
---|
121 | * \class c_pp_line c_pp_line.hpp "toppers/c_pp_line.hpp"
|
---|
122 | * \brief \#linewßð³¹é½ßÌt@N^NX
|
---|
123 | *
|
---|
124 | * ±ÌNXÍ basic_text NXÆgÝí¹ÄgpµÜ·B
|
---|
125 | */
|
---|
126 | template < class Container >
|
---|
127 | class c_pp_line : public std::binary_function< Container, line_buf, void >
|
---|
128 | {
|
---|
129 | public:
|
---|
130 | typedef Container conatiner;
|
---|
131 |
|
---|
132 | /*!
|
---|
133 | * \brief RXgN^
|
---|
134 | * \param codeset ¶R[hwè
|
---|
135 | */
|
---|
136 | explicit c_pp_line( codeset_t codeset = ascii )
|
---|
137 | : codeset_( codeset ), pragmas_( new std::vector< line_buf > )
|
---|
138 | {
|
---|
139 | }
|
---|
140 | /*!
|
---|
141 | * \brief ÊZq
|
---|
142 | * \param cont line_buf ðvfÆ·éRei
|
---|
143 | * \param buf 1sobt@
|
---|
144 | */
|
---|
145 | void operator()( conatiner& cont, line_buf& buf )
|
---|
146 | {
|
---|
147 | using namespace boost::spirit;
|
---|
148 | long line;
|
---|
149 | std::string file;
|
---|
150 | detail::c_pp_line_parser c_pp_line_p( line, file, codeset_ );
|
---|
151 |
|
---|
152 | if ( parse( buf.buf.begin(), buf.buf.end(), c_pp_line_p, space_p ).full ) // #linewßÌ
|
---|
153 | {
|
---|
154 | buf.line.line = line;
|
---|
155 | assert( file.size() >= 2 );
|
---|
156 | buf.line.file = file.substr( 1, file.size()-2 );
|
---|
157 | }
|
---|
158 | else
|
---|
159 | {
|
---|
160 | std::string param;
|
---|
161 | detail::c_pp_pragma_parser c_pp_pragma_p( param );
|
---|
162 |
|
---|
163 | if ( parse( buf.buf.begin(), buf.buf.end(), c_pp_pragma_p, space_p ).full ) // #pragmawßÌ
|
---|
164 | {
|
---|
165 | line_buf t( buf );
|
---|
166 | t.buf = param;
|
---|
167 | pragmas_->push_back( t );
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {
|
---|
171 | std::string::size_type pos = buf.buf.find_first_not_of( " \t" );
|
---|
172 | if ( pos == std::string::npos || buf.buf[pos] != '#' )
|
---|
173 | {
|
---|
174 | cont.push_back( buf );
|
---|
175 | }
|
---|
176 | ++buf.line.line;
|
---|
177 | }
|
---|
178 | }
|
---|
179 | buf.buf.clear();
|
---|
180 | }
|
---|
181 | /*!
|
---|
182 | * \brief \#pragmawßXgÌæ¾
|
---|
183 | * \return \#pragmawßXgðÔ·
|
---|
184 | */
|
---|
185 | std::vector< line_buf > const& pragmas() const { return *pragmas_; }
|
---|
186 | private:
|
---|
187 | codeset_t codeset_;
|
---|
188 | std::tr1::shared_ptr< std::vector< line_buf > > pragmas_;
|
---|
189 | };
|
---|
190 |
|
---|
191 | }
|
---|
192 |
|
---|
193 | #endif // ! TOPPERS_C_PP_LINE_HPP_
|
---|