source: cfg_oil/trunk/toppers/cpp.hpp@ 8

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

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

File size: 5.9 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
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 * \file toppers/cpp.hpp
43 * \brief CƒvƒŠƒvƒƒZƒbƒT‘ã‘Ö‹@”\‚ÉŠÖ‚·‚ééŒ¾’è‹`
44 */
45#ifndef TOPPERS_CPP_HPP_
46#define TOPPERS_CPP_HPP_
47
48#include "toppers/codeset.hpp"
49#include <boost/utility.hpp>
50#include <boost/filesystem/path.hpp>
51#include <boost/filesystem/operations.hpp>
52#include <boost/filesystem/exception.hpp>
53
54namespace toppers
55{
56
57 /*!
58 * \brief ƒRƒƒ“ƒg‚̏œ‹Ž
59 * \param[in] first “ü—ÍŒ³‚̐擪ˆÊ’u
60 * \param[in] last “ü—ÍŒ³‚̏I’[ˆÊ’u‚ÌŽŸ
61 * \param[out] result Œ‹‰Ê‚̏o—͐æ
62 * \param[in] codeset •¶ŽšƒR[ƒh
63 * \return ˆ—Š®—¹Œã‚Ì result ‚Ì’l
64 *
65 * CƒXƒ^ƒCƒ‹‚̃uƒƒbƒNƒRƒƒ“ƒg‚ÆC++ƒXƒ^ƒCƒ‹‚̍sƒRƒƒ“ƒg‚ðŽæ‚菜‚«‚Ü‚·B
66 * sƒRƒƒ“ƒg‚́As––‚Ì \\ ‚ª‚ ‚Á‚Ä‚àŽŸ‚̍s‚É‚Í‘±‚«‚Ü‚¹‚ñB
67 */
68 template < class ForwardIterator, class OutputIterator >
69 OutputIterator remove_comment( ForwardIterator first, ForwardIterator last, OutputIterator result, codeset_t codeset = ascii )
70 {
71 enum { none, line_comment, block_comment, single_quote, double_quote } state = none;
72 char prev = '\0';
73
74 for ( ; first != last; ++first, ++result )
75 {
76 char c = *first;
77 ForwardIterator next_iter = boost::next( first );
78 char next = ( next_iter != last ? *next_iter : '\0' );
79
80 switch ( state )
81 {
82 case line_comment:
83 if ( c == '\n' )
84 {
85 state = none;
86 *result = c;
87 }
88 break;
89 case block_comment:
90 if ( c == '*' && next == '/' )
91 {
92 state = none;
93 ++first;
94 }
95 else if ( c == '\n' )
96 {
97 *result = c;
98 }
99 break;
100 case single_quote:
101 if ( c == '\\'
102 && !( codeset == shift_jis && is_lead< shift_jis >( prev ) )
103 && next == '\'' ) // '`\'` ‚̏ꍇ
104 {
105 *result++ = *first++;
106 }
107 else if ( c == '\'' )
108 {
109 state = none;
110 }
111 *result = *first;
112 break;
113 case double_quote:
114 if ( c == '\\'
115 && !( codeset == shift_jis && is_lead< shift_jis >( prev ) )
116 && next == '\"' ) // "`\"` ‚̏ꍇ
117 {
118 *result++ = *first++;
119 }
120 else if ( c == '\"' )
121 {
122 state = none;
123 }
124 *result = *first;
125 break;
126 default:
127 switch ( c )
128 {
129 case '/': // ƒRƒƒ“ƒgŠJŽn‚ÌŒŸo
130 if ( next == '*' )
131 {
132 state = block_comment;
133 ++first;
134 }
135 else if ( next == '/' )
136 {
137 state = line_comment;
138 ++first;
139 }
140 else
141 {
142 *result = *first;
143 }
144 break;
145 case '\'':
146 state = single_quote;
147 *result = c;
148 break;
149 case '\"':
150 state = double_quote;
151 *result = c;
152 break;
153 default:
154 *result = c;
155 break;
156 }
157 }
158 prev = *first;
159 }
160 return result;
161 }
162
163 /*!
164 * \brief ƒCƒ“ƒNƒ‹[ƒhƒpƒX‚Ì’Tõ
165 * \param[in] first ’Tõ‘ΏۃfƒBƒŒƒNƒgƒŠ—ñ‚̐擪ˆÊ’u
166 * \param[in] last ’Tõ‘ΏۃfƒBƒŒƒNƒgƒŠ—ñ‚̏I’[ˆÊ’u‚ÌŽŸ
167 * \param[in] headername ’Tõ‘Ώۂ̃wƒbƒ_–¼
168 * \return ’Tõ‚ɐ¬Œ÷‚·‚ê‚΃wƒbƒ_‚Ö‚Ì‘Š‘΂܂½‚̓tƒ‹ƒpƒX‚ð•Ô‚·BŽ¸”s‚µ‚½ê‡‚͋󕶎š—ñ‚ð•Ô‚·B
169 */
170 template < class InputIterator >
171 std::string search_include_file( InputIterator first, InputIterator last, std::string const& headername )
172 {
173 namespace fs = boost::filesystem;
174 fs::path filename( headername, fs::native );
175
176 if ( fs::exists( filename ) && !fs::is_directory( filename ) )
177 {
178 return headername;
179 }
180 while ( first != last )
181 {
182 fs::path pathname = fs::path( *first, fs::native )/filename;
183 if ( fs::exists( pathname ) && !fs::is_directory( pathname ) )
184 {
185 return pathname.native_file_string();
186 }
187 ++first;
188 }
189 return std::string();
190 }
191
192 std::string expand_quote( std::string const& str );
193 std::string quote_string( std::string const& str );
194
195}
196
197#endif // ! TOPPERS_CPP_HPP_
Note: See TracBrowser for help on using the repository browser.