1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
35 Permission to use, copy, modify, distribute, and sell this software and its
36 documentation for any purpose is hereby granted without fee, provided that
37 the above copyright notice appear in all copies and that both that
38 copyright notice and this permission notice appear in supporting
41 The above copyright notice and this permission notice shall be included in
42 all copies or substantial portions of the Software.
44 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47 KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
48 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
49 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 #include "pp-scanner.h"
53 #include "pp-cctype.h"
55 using namespace CPlusPlus;
57 const char *pp_skip_blanks::operator () (const char *__first, const char *__last)
61 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
62 if (*__first == '\\') {
63 const char *__begin = __first;
66 if (__begin != __last && *__begin == '\n')
70 } else if (*__first == '\n' || !pp_isspace (*__first))
77 const char *pp_skip_whitespaces::operator () (const char *__first, const char *__last)
81 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
82 if (! pp_isspace (*__first))
89 const char *pp_skip_comment_or_divop::operator () (const char *__first, const char *__last)
98 } state (MAYBE_BEGIN);
102 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
117 else if (*__first == '/')
118 state = IN_CXX_COMMENT;
129 if (*__first == '\n')
136 else if (*__first != '*')
148 const char *pp_skip_identifier::operator () (const char *__first, const char *__last)
152 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
153 if (! pp_isalnum (*__first) && *__first != '_')
160 const char *pp_skip_number::operator () (const char *__first, const char *__last)
164 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
165 if (! pp_isalnum (*__first) && *__first != '.')
172 const char *pp_skip_string_literal::operator () (const char *__first, const char *__last)
183 for (; __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
190 if (*__first != '\"')
196 if (! (*__first != '\n'))
199 if (*__first == '\"')
201 else if (*__first == '\\')
217 const char *pp_skip_char_literal::operator () (const char *__first, const char *__last)
228 for (; state != END && __first != __last; lines += (*__first != '\n' ? 0 : 1), ++__first) {
235 if (*__first != '\'')
241 if (! (*__first != '\n'))
244 if (*__first == '\'')
246 else if (*__first == '\\')
259 const char *pp_skip_argument::operator () (const char *__first, const char *__last)
264 while (__first != __last) {
265 if (!depth && (*__first == ')' || *__first == ','))
267 else if (*__first == '(')
269 else if (*__first == ')')
271 else if (*__first == '\"') {
272 __first = skip_string_literal (__first, __last);
273 lines += skip_string_literal.lines;
274 } else if (*__first == '\'') {
275 __first = skip_char_literal (__first, __last);
276 lines += skip_char_literal.lines;
277 } else if (*__first == '/') {
278 __first = skip_comment_or_divop (__first, __last);
279 lines += skip_comment_or_divop.lines;
280 } else if (pp_isalpha (*__first) || *__first == '_') {
281 __first = skip_identifier (__first, __last);
282 lines += skip_identifier.lines;
283 } else if (pp_isdigit (*__first)) {
284 __first = skip_number (__first, __last);
285 lines += skip_number.lines;
286 } else if (*__first == '\n') {