| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2014-01-07 13:27:11 +01:00
										 |  |  | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Contact: http://www.qt-project.org/legal
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Digia.  For licensing terms and | 
					
						
							|  |  |  | ** conditions see http://qt.digia.com/licensing.  For further information
 | 
					
						
							|  |  |  | ** use the contact form at http://qt.digia.com/contact-us.
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** In addition, as a special exception, Digia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Digia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QtTest>
 | 
					
						
							| 
									
										
										
										
											2012-08-06 13:42:46 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-27 18:54:03 +01:00
										 |  |  | #include <cplusplus/Control.h>
 | 
					
						
							|  |  |  | #include <cplusplus/Literals.h>
 | 
					
						
							|  |  |  | #include <cplusplus/Parser.h>
 | 
					
						
							|  |  |  | #include <cplusplus/AST.h>
 | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 15:32:04 +10:00
										 |  |  | //TESTED_COMPONENT=src/libs/cplusplus
 | 
					
						
							| 
									
										
										
										
											2009-10-20 11:21:25 +02:00
										 |  |  | using namespace CPlusPlus; | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class tst_AST: public QObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Control control; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     TranslationUnit *parse(const QByteArray &source, | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |                            TranslationUnit::ParseMode mode, | 
					
						
							| 
									
										
										
										
											2010-02-06 14:32:25 +01:00
										 |  |  |                            bool blockErrors = false, | 
					
						
							|  |  |  |                            bool qtMocRun = false) | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-08-11 15:48:21 +02:00
										 |  |  |         const StringLiteral *fileId = control.stringLiteral("<stdin>"); | 
					
						
							| 
									
										
										
										
											2013-10-06 02:41:22 +02:00
										 |  |  |         LanguageFeatures features; | 
					
						
							|  |  |  |         features.objCEnabled = true; | 
					
						
							|  |  |  |         features.qtEnabled = qtMocRun; | 
					
						
							|  |  |  |         features.qtKeywordsEnabled = qtMocRun; | 
					
						
							|  |  |  |         features.qtMocRunEnabled = qtMocRun; | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  |         TranslationUnit *unit = new TranslationUnit(&control, fileId); | 
					
						
							| 
									
										
										
										
											2013-10-06 02:41:22 +02:00
										 |  |  |         unit->setLanguageFeatures(features); | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  |         unit->setSource(source.constData(), source.length()); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         unit->blockErrors(blockErrors); | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  |         unit->parse(mode); | 
					
						
							|  |  |  |         return unit; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-06 14:32:25 +01:00
										 |  |  |     TranslationUnit *parseDeclaration(const QByteArray &source, bool blockErrors = false, bool qtMocRun = false) | 
					
						
							|  |  |  |     { return parse(source, TranslationUnit::ParseDeclaration, blockErrors, qtMocRun); } | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  |     TranslationUnit *parseExpression(const QByteArray &source) | 
					
						
							|  |  |  |     { return parse(source, TranslationUnit::ParseExpression); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  |     TranslationUnit *parseStatement(const QByteArray &source) | 
					
						
							|  |  |  |     { return parse(source, TranslationUnit::ParseStatement); } | 
					
						
							| 
									
										
										
										
											2014-05-16 12:59:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-17 16:07:47 +01:00
										 |  |  |     class Diagnostic: public DiagnosticClient { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         int errorCount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Diagnostic() | 
					
						
							|  |  |  |             : errorCount(0) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void report(int /*level*/, | 
					
						
							|  |  |  |                             const StringLiteral *fileName, | 
					
						
							|  |  |  |                             unsigned line, unsigned column, | 
					
						
							|  |  |  |                             const char *format, va_list ap) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ++errorCount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             qDebug() << fileName->chars()<<':'<<line<<':'<<column<<' '<<QString().vsprintf(format, ap); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 12:59:39 +03:00
										 |  |  |     Diagnostic diag; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							| 
									
										
										
										
											2011-02-17 16:07:47 +01:00
										 |  |  |     void initTestCase(); | 
					
						
							| 
									
										
										
										
											2013-08-21 15:46:30 +02:00
										 |  |  |     void cleanup(); | 
					
						
							| 
									
										
										
										
											2013-07-12 12:35:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // line/column positions
 | 
					
						
							|  |  |  |     void line_and_column_1(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 15:16:02 +01:00
										 |  |  |     // declarations
 | 
					
						
							|  |  |  |     void gcc_attributes_1(); | 
					
						
							| 
									
										
										
										
											2012-02-24 13:06:21 +01:00
										 |  |  |     void gcc_attributes_2(); | 
					
						
							|  |  |  |     void gcc_attributes_3(); | 
					
						
							| 
									
										
										
										
											2012-03-28 13:34:31 +02:00
										 |  |  |     void crash_test_1(); | 
					
						
							| 
									
										
										
										
											2013-11-24 18:25:32 +02:00
										 |  |  |     void thread_local_1(); | 
					
						
							| 
									
										
										
										
											2009-01-14 15:16:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  |     // expressions
 | 
					
						
							| 
									
										
										
										
											2009-10-20 15:29:58 +02:00
										 |  |  |     void simple_name_1(); | 
					
						
							|  |  |  |     void template_id_1(); | 
					
						
							| 
									
										
										
										
											2009-02-10 14:43:19 +01:00
										 |  |  |     void new_expression_1(); | 
					
						
							|  |  |  |     void new_expression_2(); | 
					
						
							| 
									
										
										
										
											2009-06-19 11:23:30 +02:00
										 |  |  |     void condition_1(); | 
					
						
							| 
									
										
										
										
											2009-06-19 12:39:11 +02:00
										 |  |  |     void init_1(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  |     void conditional_1(); | 
					
						
							| 
									
										
										
										
											2010-02-02 15:38:21 +01:00
										 |  |  |     void throw_1(); | 
					
						
							| 
									
										
										
										
											2012-02-16 10:54:44 +01:00
										 |  |  |     void templated_dtor_1(); | 
					
						
							|  |  |  |     void templated_dtor_2(); | 
					
						
							|  |  |  |     void templated_dtor_3(); | 
					
						
							|  |  |  |     void templated_dtor_4(); | 
					
						
							|  |  |  |     void templated_dtor_5(); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-16 11:30:39 +02:00
										 |  |  |     // possible declaration-or-expression statements
 | 
					
						
							|  |  |  |     void call_call_1(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  |     // statements
 | 
					
						
							| 
									
										
										
										
											2009-10-20 15:29:58 +02:00
										 |  |  |     void if_statement_1(); | 
					
						
							|  |  |  |     void if_statement_2(); | 
					
						
							|  |  |  |     void if_statement_3(); | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  |     void if_else_statement(); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  |     void while_statement(); | 
					
						
							|  |  |  |     void while_condition_statement(); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:29:59 +01:00
										 |  |  |     void for_statement(); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     void cpp_initializer_or_function_declaration(); | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |     void simple_declaration_1(); | 
					
						
							|  |  |  |     void function_call_1(); | 
					
						
							|  |  |  |     void function_call_2(); | 
					
						
							|  |  |  |     void function_call_3(); | 
					
						
							| 
									
										
										
										
											2009-10-20 11:26:58 +02:00
										 |  |  |     void function_call_4(); | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |     void nested_deref_expression(); | 
					
						
							|  |  |  |     void assignment_1(); | 
					
						
							| 
									
										
										
										
											2009-10-20 11:26:58 +02:00
										 |  |  |     void assignment_2(); | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-04 10:55:44 +01:00
										 |  |  |     // constructor declarations
 | 
					
						
							|  |  |  |     void cpp_constructor_one_unamed_arg(); | 
					
						
							|  |  |  |     void cpp_constructor_one_unamed_arg_namespace(); | 
					
						
							|  |  |  |     void cpp_constructor_one_knowntype_arg(); | 
					
						
							|  |  |  |     void cpp_constructor_one_const_arg(); | 
					
						
							|  |  |  |     void cpp_constructor_one_ref_arg(); | 
					
						
							|  |  |  |     void cpp_constructor_one_named_arg(); | 
					
						
							|  |  |  |     void cpp_constructor_no_arg(); | 
					
						
							|  |  |  |     void cpp_constructor_multiple_args(); | 
					
						
							| 
									
										
										
										
											2013-04-03 23:33:44 +04:00
										 |  |  |     void cpp_constructor_function_try_catch(); | 
					
						
							| 
									
										
										
										
											2013-01-04 10:55:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-08 13:42:39 +02:00
										 |  |  |     // Q_PROPERTY
 | 
					
						
							|  |  |  |     void cpp_qproperty(); | 
					
						
							|  |  |  |     void cpp_qproperty_data(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  |     // objc++
 | 
					
						
							| 
									
										
										
										
											2009-11-11 09:21:06 +01:00
										 |  |  |     void objc_simple_class(); | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  |     void objc_attributes_followed_by_at_keyword(); | 
					
						
							|  |  |  |     void objc_protocol_forward_declaration_1(); | 
					
						
							|  |  |  |     void objc_protocol_definition_1(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:03:37 +01:00
										 |  |  |     void objc_method_attributes_1(); | 
					
						
							| 
									
										
										
										
											2010-10-06 16:26:48 +02:00
										 |  |  |     void objc_selector_error_recovery_1(); | 
					
						
							|  |  |  |     void objc_selector_error_recovery_2(); | 
					
						
							| 
									
										
										
										
											2013-07-18 10:04:28 +02:00
										 |  |  |     void objc_try_statement_1(); | 
					
						
							|  |  |  |     void objc_try_statement_2(); | 
					
						
							|  |  |  |     void objc_try_statement_3(); | 
					
						
							| 
									
										
										
										
											2013-07-18 10:25:19 +02:00
										 |  |  |     void objc_throw_statement(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // expressions with (square) brackets
 | 
					
						
							|  |  |  |     void normal_array_access(); | 
					
						
							|  |  |  |     void array_access_with_nested_expression(); | 
					
						
							|  |  |  |     void objc_msg_send_expression(); | 
					
						
							|  |  |  |     void objc_msg_send_expression_without_selector(); | 
					
						
							| 
									
										
										
										
											2010-02-06 14:32:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Qt "keywords"
 | 
					
						
							|  |  |  |     void q_enum_1(); | 
					
						
							| 
									
										
										
										
											2013-10-22 11:24:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void incomplete_ast(); | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 15:16:02 +01:00
										 |  |  | void tst_AST::gcc_attributes_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  | "static inline void *__attribute__((__always_inline__)) _mm_malloc(size_t size, size_t align);" | 
					
						
							| 
									
										
										
										
											2012-02-24 13:06:21 +01:00
										 |  |  |                                                           )); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::gcc_attributes_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration( | 
					
						
							|  |  |  |                                              "\nnamespace std __attribute__ ((__visibility__ (\"default\"))) {\n}\n" | 
					
						
							|  |  |  |                                              )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     NamespaceAST* ns = ast->asNamespace(); | 
					
						
							|  |  |  |     QVERIFY(ns); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(ns->identifier_token), "std"); | 
					
						
							|  |  |  |     QVERIFY(ns->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(!ns->attribute_list->next); | 
					
						
							|  |  |  |     QVERIFY(ns->attribute_list->value); | 
					
						
							|  |  |  |     AttributeSpecifierAST *attrSpec = ns->attribute_list->value->asAttributeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(attrSpec); | 
					
						
							|  |  |  |     QVERIFY(attrSpec->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(!attrSpec->attribute_list->next); | 
					
						
							|  |  |  |     QVERIFY(attrSpec->attribute_list->value); | 
					
						
							|  |  |  |     AttributeAST *attr = attrSpec->attribute_list->value->asAttribute(); | 
					
						
							|  |  |  |     QVERIFY(attr); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(attr->identifier_token), "__visibility__"); | 
					
						
							|  |  |  |     QVERIFY(attr->expression_list); | 
					
						
							|  |  |  |     QVERIFY(!attr->expression_list->next); | 
					
						
							|  |  |  |     QVERIFY(attr->expression_list->value); | 
					
						
							|  |  |  |     StringLiteralAST *e = attr->expression_list->value->asStringLiteral(); | 
					
						
							|  |  |  |     QVERIFY(e); | 
					
						
							|  |  |  |     QVERIFY(!e->next); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(e->literal_token), "default"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::gcc_attributes_3() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const char *inp = "\nnamespace std X {\n}\n"; | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration(inp)); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     NamespaceAST* ns = ast->asNamespace(); | 
					
						
							|  |  |  |     QVERIFY(ns); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(ns->identifier_token), "std"); | 
					
						
							|  |  |  |     QVERIFY(!ns->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(ns->linkage_body); | 
					
						
							|  |  |  |     LinkageBodyAST *link = ns->linkage_body->asLinkageBody(); | 
					
						
							|  |  |  |     QVERIFY(link); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(link->lbrace_token), (int) T_LBRACE); | 
					
						
							|  |  |  |     QVERIFY(!link->declaration_list); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(link->rbrace_token), (int) T_RBRACE); | 
					
						
							| 
									
										
										
										
											2009-01-14 15:16:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-28 13:34:31 +02:00
										 |  |  | void tst_AST::crash_test_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("decltype auto\n")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-24 18:25:32 +02:00
										 |  |  | void tst_AST::thread_local_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("__thread int i;\n")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     QCOMPARE(diag.errorCount, 0); | 
					
						
							|  |  |  |     QCOMPARE(Token::name(T_THREAD_LOCAL), "thread_local"); | 
					
						
							|  |  |  |     QCOMPARE(Token::name(T___THREAD), "__thread"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  | void tst_AST::simple_declaration_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("\n" | 
					
						
							|  |  |  | "a * b = 10;" | 
					
						
							|  |  |  |     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DeclarationStatementAST *declStmt = ast->asDeclarationStatement(); | 
					
						
							|  |  |  |     QVERIFY(declStmt); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 15:29:58 +02:00
										 |  |  | void tst_AST::simple_name_1() | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseExpression("a")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     QVERIFY(ast->asIdExpression()->name->asSimpleName() != 0); | 
					
						
							|  |  |  |     QCOMPARE(ast->asIdExpression()->name->asSimpleName()->identifier_token, 1U); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 15:29:58 +02:00
										 |  |  | void tst_AST::template_id_1() | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseExpression("list<10>")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     QVERIFY(ast->asIdExpression()->name->asTemplateId() != 0); | 
					
						
							|  |  |  |     QCOMPARE(ast->asIdExpression()->name->asTemplateId()->identifier_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(ast->asIdExpression()->name->asTemplateId()->less_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(ast->asIdExpression()->name->asTemplateId()->template_argument_list != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asIdExpression()->name->asTemplateId()->template_argument_list->value != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asIdExpression()->name->asTemplateId()->template_argument_list->value->asNumericLiteral() != 0); | 
					
						
							|  |  |  |     QCOMPARE(ast->asIdExpression()->name->asTemplateId()->template_argument_list->value->asNumericLiteral()->literal_token, 3U); | 
					
						
							|  |  |  |     QVERIFY(ast->asIdExpression()->name->asTemplateId()->template_argument_list->next == 0); | 
					
						
							|  |  |  |     QCOMPARE(ast->asIdExpression()->name->asTemplateId()->greater_token, 4U); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:37:10 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-10 14:43:19 +01:00
										 |  |  | void tst_AST::new_expression_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseExpression("\n" | 
					
						
							|  |  |  | "new char" | 
					
						
							|  |  |  |     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NewExpressionAST *expr = ast->asNewExpression(); | 
					
						
							|  |  |  |     QVERIFY(expr != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QCOMPARE(expr->scope_token, 0U); | 
					
						
							|  |  |  |     QCOMPARE(expr->new_token, 1U); | 
					
						
							|  |  |  |     QVERIFY(expr->new_placement == 0); | 
					
						
							|  |  |  |     QCOMPARE(expr->lparen_token, 0U); | 
					
						
							|  |  |  |     QVERIFY(expr->type_id == 0); | 
					
						
							|  |  |  |     QCOMPARE(expr->rparen_token, 0U); | 
					
						
							|  |  |  |     QVERIFY(expr->new_type_id != 0); | 
					
						
							|  |  |  |     QVERIFY(expr->new_initializer == 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(expr->new_type_id->type_specifier_list != 0); | 
					
						
							|  |  |  |     QVERIFY(expr->new_type_id->ptr_operator_list == 0); | 
					
						
							|  |  |  |     QVERIFY(expr->new_type_id->new_array_declarator_list == 0); | 
					
						
							| 
									
										
										
										
											2009-02-10 14:43:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::new_expression_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("\n" | 
					
						
							|  |  |  | "::new(__p) _Tp(__val);" | 
					
						
							|  |  |  |     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ExpressionStatementAST *stmt = ast->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  |     QVERIFY(stmt->expression != 0); | 
					
						
							|  |  |  |     QVERIFY(stmt->semicolon_token != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NewExpressionAST *expr = stmt->expression->asNewExpression(); | 
					
						
							|  |  |  |     QVERIFY(expr != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QCOMPARE(expr->scope_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(expr->new_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(expr->new_placement != 0); | 
					
						
							|  |  |  |     QCOMPARE(expr->lparen_token, 0U); | 
					
						
							|  |  |  |     QVERIFY(expr->type_id == 0); | 
					
						
							|  |  |  |     QCOMPARE(expr->rparen_token, 0U); | 
					
						
							|  |  |  |     QVERIFY(expr->new_type_id != 0); | 
					
						
							|  |  |  |     QVERIFY(expr->new_initializer != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-19 11:23:30 +02:00
										 |  |  | void tst_AST::condition_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseExpression("\n" | 
					
						
							| 
									
										
										
										
											2010-01-28 15:21:57 +01:00
										 |  |  |                                                          "(x < 0 && y > (int) a)" | 
					
						
							| 
									
										
										
										
											2009-06-19 11:23:30 +02:00
										 |  |  |     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							| 
									
										
										
										
											2010-01-28 15:21:57 +01:00
										 |  |  |     NestedExpressionAST *nestedExpr = ast->asNestedExpression(); | 
					
						
							|  |  |  |     QVERIFY(nestedExpr); | 
					
						
							|  |  |  |     QVERIFY(nestedExpr->expression); | 
					
						
							|  |  |  |     BinaryExpressionAST *andExpr = nestedExpr->expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(andExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(andExpr->binary_op_token), (int) T_AMPER_AMPER); | 
					
						
							|  |  |  |     QVERIFY(andExpr->left_expression); | 
					
						
							|  |  |  |     QVERIFY(andExpr->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *ltExpr = andExpr->left_expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(ltExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(ltExpr->binary_op_token), (int) T_LESS); | 
					
						
							|  |  |  |     QVERIFY(ltExpr->left_expression); | 
					
						
							|  |  |  |     QVERIFY(ltExpr->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *x = ltExpr->left_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-01-28 15:21:57 +01:00
										 |  |  |     QVERIFY(x); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(x->identifier_token), "x"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NumericLiteralAST *zero = ltExpr->right_expression->asNumericLiteral(); | 
					
						
							|  |  |  |     QVERIFY(zero); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(zero->literal_token), "0"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *gtExpr = andExpr->right_expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(gtExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(gtExpr->binary_op_token), (int) T_GREATER); | 
					
						
							|  |  |  |     QVERIFY(gtExpr->left_expression); | 
					
						
							|  |  |  |     QVERIFY(gtExpr->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *y = gtExpr->left_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-01-28 15:21:57 +01:00
										 |  |  |     QVERIFY(y); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(y->identifier_token), "y"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CastExpressionAST *cast = gtExpr->right_expression->asCastExpression(); | 
					
						
							|  |  |  |     QVERIFY(cast); | 
					
						
							|  |  |  |     QVERIFY(cast->type_id); | 
					
						
							|  |  |  |     QVERIFY(cast->expression); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TypeIdAST *intType = cast->type_id->asTypeId(); | 
					
						
							|  |  |  |     QVERIFY(intType); | 
					
						
							|  |  |  |     // ### here we could check if the type is an actual int
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *a = cast->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-01-28 15:21:57 +01:00
										 |  |  |     QVERIFY(a); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(a->identifier_token), "a"); | 
					
						
							| 
									
										
										
										
											2009-06-19 11:23:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-19 12:39:11 +02:00
										 |  |  | void tst_AST::init_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "x y[] = { X<10>, y };" | 
					
						
							|  |  |  |     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  | void tst_AST::conditional_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseExpression("\n" | 
					
						
							|  |  |  |                                                          "(x < 0 && y > (int) a) ? x == 1 : y = 1" | 
					
						
							|  |  |  |     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ConditionalExpressionAST *conditional = ast->asConditionalExpression(); | 
					
						
							|  |  |  |     QVERIFY(conditional); | 
					
						
							|  |  |  |     QVERIFY(conditional->condition); | 
					
						
							|  |  |  |     QVERIFY(conditional->left_expression); | 
					
						
							|  |  |  |     QVERIFY(conditional->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NestedExpressionAST *nestedExpr = conditional->condition->asNestedExpression(); | 
					
						
							|  |  |  |     QVERIFY(nestedExpr); | 
					
						
							|  |  |  |     QVERIFY(nestedExpr->expression); | 
					
						
							|  |  |  |     BinaryExpressionAST *andExpr = nestedExpr->expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(andExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(andExpr->binary_op_token), (int) T_AMPER_AMPER); | 
					
						
							|  |  |  |     QVERIFY(andExpr->left_expression); | 
					
						
							|  |  |  |     QVERIFY(andExpr->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *ltExpr = andExpr->left_expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(ltExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(ltExpr->binary_op_token), (int) T_LESS); | 
					
						
							|  |  |  |     QVERIFY(ltExpr->left_expression); | 
					
						
							|  |  |  |     QVERIFY(ltExpr->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *x = ltExpr->left_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  |     QVERIFY(x); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(x->identifier_token), "x"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NumericLiteralAST *zero = ltExpr->right_expression->asNumericLiteral(); | 
					
						
							|  |  |  |     QVERIFY(zero); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(zero->literal_token), "0"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *gtExpr = andExpr->right_expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(gtExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(gtExpr->binary_op_token), (int) T_GREATER); | 
					
						
							|  |  |  |     QVERIFY(gtExpr->left_expression); | 
					
						
							|  |  |  |     QVERIFY(gtExpr->right_expression); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *y = gtExpr->left_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  |     QVERIFY(y); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(y->identifier_token), "y"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CastExpressionAST *cast = gtExpr->right_expression->asCastExpression(); | 
					
						
							|  |  |  |     QVERIFY(cast); | 
					
						
							|  |  |  |     QVERIFY(cast->type_id); | 
					
						
							|  |  |  |     QVERIFY(cast->expression); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     TypeIdAST *intType = cast->type_id->asTypeId(); | 
					
						
							|  |  |  |     QVERIFY(intType); | 
					
						
							|  |  |  |     QVERIFY(! (intType->declarator)); | 
					
						
							|  |  |  |     QVERIFY(intType->type_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(! (intType->type_specifier_list->next)); | 
					
						
							|  |  |  |     QVERIFY(intType->type_specifier_list->value); | 
					
						
							|  |  |  |     SimpleSpecifierAST *intSpec = intType->type_specifier_list->value->asSimpleSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(intSpec); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(intSpec->specifier_token), "int"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *a = cast->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  |     QVERIFY(a); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(a->identifier_token), "a"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *equals = conditional->left_expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(equals); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(equals->binary_op_token), (int) T_EQUAL_EQUAL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     x = equals->left_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  |     QVERIFY(x); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(x->identifier_token), "x"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NumericLiteralAST *one = equals->right_expression->asNumericLiteral(); | 
					
						
							|  |  |  |     QVERIFY(one); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(one->literal_token), "1"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *assignment = conditional->right_expression->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(assignment); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(assignment->binary_op_token), (int) T_EQUAL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     y = assignment->left_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:08:01 +01:00
										 |  |  |     QVERIFY(y); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(y->identifier_token), "y"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     one = assignment->right_expression->asNumericLiteral(); | 
					
						
							|  |  |  |     QVERIFY(one); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(one->literal_token), "1"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-02 15:38:21 +01:00
										 |  |  | void tst_AST::throw_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("throw 1;")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-16 10:54:44 +01:00
										 |  |  | void tst_AST::templated_dtor_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement( | 
					
						
							|  |  |  |                                              "\n" | 
					
						
							|  |  |  |                                              "a.b::~b<c>();" | 
					
						
							|  |  |  |                                              )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     ExpressionStatementAST *e = ast->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(e); | 
					
						
							|  |  |  |     QVERIFY(e->expression); | 
					
						
							|  |  |  |     CallAST *call = e->expression->asCall(); | 
					
						
							|  |  |  |     QVERIFY(call); | 
					
						
							|  |  |  |     QVERIFY(!call->expression_list); | 
					
						
							|  |  |  |     QVERIFY(call->base_expression); | 
					
						
							|  |  |  |     MemberAccessAST *mem = call->base_expression->asMemberAccess(); | 
					
						
							|  |  |  |     QVERIFY(mem); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(mem->base_expression->asIdExpression()->name->asSimpleName()->identifier_token), "a"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QualifiedNameAST *qName = mem->member_name->asQualifiedName(); | 
					
						
							|  |  |  |     QVERIFY(qName); | 
					
						
							|  |  |  |     QVERIFY(qName->nested_name_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(!qName->nested_name_specifier_list->next); | 
					
						
							|  |  |  |     QVERIFY(qName->nested_name_specifier_list->value); | 
					
						
							|  |  |  |     QVERIFY(qName->nested_name_specifier_list->value->class_or_namespace_name); | 
					
						
							|  |  |  |     SimpleNameAST *bName = qName->nested_name_specifier_list->value->class_or_namespace_name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(bName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(bName->identifier_token), "b"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(qName->unqualified_name); | 
					
						
							|  |  |  |     DestructorNameAST *dtor = qName->unqualified_name->asDestructorName(); | 
					
						
							|  |  |  |     QVERIFY(dtor); | 
					
						
							|  |  |  |     QVERIFY(dtor->unqualified_name); | 
					
						
							|  |  |  |     TemplateIdAST *tid = dtor->unqualified_name->asTemplateId(); | 
					
						
							|  |  |  |     QVERIFY(tid); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(tid->identifier_token), "b"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list); | 
					
						
							|  |  |  |     QVERIFY(!tid->template_argument_list->next); | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list->value); | 
					
						
							|  |  |  |     TypeIdAST *typeId = tid->template_argument_list->value->asTypeId(); | 
					
						
							|  |  |  |     QVERIFY(typeId); | 
					
						
							|  |  |  |     QVERIFY(!typeId->declarator); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(!typeId->type_specifier_list->next); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list->value); | 
					
						
							|  |  |  |     NamedTypeSpecifierAST *nts = typeId->type_specifier_list->value->asNamedTypeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(nts); | 
					
						
							|  |  |  |     QVERIFY(nts->name); | 
					
						
							|  |  |  |     SimpleNameAST *cName = nts->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(cName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(cName->identifier_token), "c"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::templated_dtor_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement( | 
					
						
							|  |  |  |                                              "\n" | 
					
						
							|  |  |  |                                              "a.~b<c>();" | 
					
						
							|  |  |  |                                              )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     ExpressionStatementAST *e = ast->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(e); | 
					
						
							|  |  |  |     QVERIFY(e->expression); | 
					
						
							|  |  |  |     CallAST *call = e->expression->asCall(); | 
					
						
							|  |  |  |     QVERIFY(call); | 
					
						
							|  |  |  |     QVERIFY(!call->expression_list); | 
					
						
							|  |  |  |     QVERIFY(call->base_expression); | 
					
						
							|  |  |  |     MemberAccessAST *mem = call->base_expression->asMemberAccess(); | 
					
						
							|  |  |  |     QVERIFY(mem); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(mem->base_expression->asIdExpression()->name->asSimpleName()->identifier_token), "a"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(mem->member_name); | 
					
						
							|  |  |  |     DestructorNameAST *dtor = mem->member_name->asDestructorName(); | 
					
						
							|  |  |  |     QVERIFY(dtor); | 
					
						
							|  |  |  |     QVERIFY(dtor->unqualified_name); | 
					
						
							|  |  |  |     TemplateIdAST *tid = dtor->unqualified_name->asTemplateId(); | 
					
						
							|  |  |  |     QVERIFY(tid); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(tid->identifier_token), "b"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list); | 
					
						
							|  |  |  |     QVERIFY(!tid->template_argument_list->next); | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list->value); | 
					
						
							|  |  |  |     TypeIdAST *typeId = tid->template_argument_list->value->asTypeId(); | 
					
						
							|  |  |  |     QVERIFY(typeId); | 
					
						
							|  |  |  |     QVERIFY(!typeId->declarator); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(!typeId->type_specifier_list->next); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list->value); | 
					
						
							|  |  |  |     NamedTypeSpecifierAST *nts = typeId->type_specifier_list->value->asNamedTypeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(nts); | 
					
						
							|  |  |  |     QVERIFY(nts->name); | 
					
						
							|  |  |  |     SimpleNameAST *cName = nts->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(cName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(cName->identifier_token), "c"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::templated_dtor_3() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement( | 
					
						
							|  |  |  |                                              "\n" | 
					
						
							|  |  |  |                                              "a::~b<c>();" | 
					
						
							|  |  |  |                                              )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     ExpressionStatementAST *e = ast->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(e); | 
					
						
							|  |  |  |     QVERIFY(e->expression); | 
					
						
							|  |  |  |     CallAST *call = e->expression->asCall(); | 
					
						
							|  |  |  |     QVERIFY(call); | 
					
						
							|  |  |  |     QVERIFY(!call->expression_list); | 
					
						
							|  |  |  |     QVERIFY(call->base_expression); | 
					
						
							|  |  |  |     IdExpressionAST *idExpr = call->base_expression->asIdExpression(); | 
					
						
							|  |  |  |     QVERIFY(idExpr); | 
					
						
							|  |  |  |     QVERIFY(idExpr->name); | 
					
						
							|  |  |  |     QualifiedNameAST *qName = idExpr->name->asQualifiedName(); | 
					
						
							|  |  |  |     QVERIFY(qName); | 
					
						
							|  |  |  |     QVERIFY(qName->nested_name_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(!qName->nested_name_specifier_list->next); | 
					
						
							|  |  |  |     QVERIFY(qName->nested_name_specifier_list->value); | 
					
						
							|  |  |  |     QVERIFY(qName->nested_name_specifier_list->value->class_or_namespace_name); | 
					
						
							|  |  |  |     SimpleNameAST *bName = qName->nested_name_specifier_list->value->class_or_namespace_name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(bName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(bName->identifier_token), "a"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(qName->unqualified_name); | 
					
						
							|  |  |  |     DestructorNameAST *dtor = qName->unqualified_name->asDestructorName(); | 
					
						
							|  |  |  |     QVERIFY(dtor); | 
					
						
							|  |  |  |     QVERIFY(dtor->unqualified_name); | 
					
						
							|  |  |  |     TemplateIdAST *tid = dtor->unqualified_name->asTemplateId(); | 
					
						
							|  |  |  |     QVERIFY(tid); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(tid->identifier_token), "b"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list); | 
					
						
							|  |  |  |     QVERIFY(!tid->template_argument_list->next); | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list->value); | 
					
						
							|  |  |  |     TypeIdAST *typeId = tid->template_argument_list->value->asTypeId(); | 
					
						
							|  |  |  |     QVERIFY(typeId); | 
					
						
							|  |  |  |     QVERIFY(!typeId->declarator); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(!typeId->type_specifier_list->next); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list->value); | 
					
						
							|  |  |  |     NamedTypeSpecifierAST *nts = typeId->type_specifier_list->value->asNamedTypeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(nts); | 
					
						
							|  |  |  |     QVERIFY(nts->name); | 
					
						
							|  |  |  |     SimpleNameAST *cName = nts->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(cName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(cName->identifier_token), "c"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::templated_dtor_4() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement( | 
					
						
							|  |  |  |                                              "\n" | 
					
						
							|  |  |  |                                              "~b<c>();" | 
					
						
							|  |  |  |                                              )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     ExpressionStatementAST *e = ast->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(e); | 
					
						
							|  |  |  |     QVERIFY(e->expression); | 
					
						
							|  |  |  |     UnaryExpressionAST *u = e->expression->asUnaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(u); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(u->unary_op_token), (int) T_TILDE); | 
					
						
							|  |  |  |     QVERIFY(u->expression); | 
					
						
							|  |  |  |     CallAST *call = u->expression->asCall(); | 
					
						
							|  |  |  |     QVERIFY(call); | 
					
						
							|  |  |  |     QVERIFY(call->base_expression); | 
					
						
							|  |  |  |     IdExpressionAST *idExpr = call->base_expression->asIdExpression(); | 
					
						
							|  |  |  |     QVERIFY(idExpr); | 
					
						
							|  |  |  |     QVERIFY(idExpr->name); | 
					
						
							|  |  |  |     TemplateIdAST *tid = idExpr->name->asTemplateId(); | 
					
						
							|  |  |  |     QVERIFY(tid); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(tid->identifier_token), "b"); | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list); | 
					
						
							|  |  |  |     QVERIFY(!tid->template_argument_list->next); | 
					
						
							|  |  |  |     QVERIFY(tid->template_argument_list->value); | 
					
						
							|  |  |  |     TypeIdAST *typeId = tid->template_argument_list->value->asTypeId(); | 
					
						
							|  |  |  |     QVERIFY(typeId); | 
					
						
							|  |  |  |     QVERIFY(!typeId->declarator); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(!typeId->type_specifier_list->next); | 
					
						
							|  |  |  |     QVERIFY(typeId->type_specifier_list->value); | 
					
						
							|  |  |  |     NamedTypeSpecifierAST *nts = typeId->type_specifier_list->value->asNamedTypeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(nts); | 
					
						
							|  |  |  |     QVERIFY(nts->name); | 
					
						
							|  |  |  |     SimpleNameAST *cName = nts->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(cName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(cName->identifier_token), "c"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::templated_dtor_5() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseExpression( | 
					
						
							|  |  |  |                                              "\n" | 
					
						
							|  |  |  |                                              "~a < b()" | 
					
						
							|  |  |  |                                              )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BinaryExpressionAST *binExpr = ast->asBinaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(binExpr); | 
					
						
							|  |  |  |     QVERIFY(binExpr->left_expression); | 
					
						
							|  |  |  |     UnaryExpressionAST *notExpr = binExpr->left_expression->asUnaryExpression(); | 
					
						
							|  |  |  |     QVERIFY(notExpr); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(notExpr->unary_op_token), (int) T_TILDE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CallAST *call = binExpr->right_expression->asCall(); | 
					
						
							|  |  |  |     QVERIFY(call->base_expression); | 
					
						
							|  |  |  |     QVERIFY(!call->expression_list); | 
					
						
							|  |  |  |     IdExpressionAST *bExpr = call->base_expression->asIdExpression(); | 
					
						
							|  |  |  |     QVERIFY(bExpr); | 
					
						
							|  |  |  |     SimpleNameAST *bName = bExpr->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(bName); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(bName->identifier_token), "b"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-16 11:30:39 +02:00
										 |  |  | void tst_AST::call_call_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("method()->call();")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ExpressionStatementAST *exprStmt = ast->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(exprStmt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ExpressionAST *expr = exprStmt->expression; | 
					
						
							|  |  |  |     QVERIFY(expr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CallAST *memberCall = expr->asCall(); | 
					
						
							|  |  |  |     QVERIFY(memberCall); | 
					
						
							|  |  |  |     QVERIFY(memberCall->base_expression); | 
					
						
							|  |  |  |     QVERIFY(!memberCall->expression_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MemberAccessAST *member_xs = memberCall->base_expression->asMemberAccess(); | 
					
						
							|  |  |  |     QVERIFY(member_xs); | 
					
						
							|  |  |  |     QVERIFY(member_xs->member_name); | 
					
						
							|  |  |  |     SimpleNameAST *member_name = member_xs->member_name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(member_name); | 
					
						
							|  |  |  |     QVERIFY(member_name->identifier_token); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(member_name->identifier_token), "call"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(member_xs->access_token), (int) T_ARROW); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(member_xs->base_expression); | 
					
						
							|  |  |  |     CallAST *method_call = member_xs->base_expression->asCall(); | 
					
						
							|  |  |  |     QVERIFY(method_call); | 
					
						
							|  |  |  |     QVERIFY(!method_call->expression_list); | 
					
						
							|  |  |  |     QVERIFY(method_call->base_expression); | 
					
						
							|  |  |  |     IdExpressionAST *member_expr = method_call->base_expression->asIdExpression(); | 
					
						
							|  |  |  |     QVERIFY(member_expr); | 
					
						
							|  |  |  |     QVERIFY(member_expr->name); | 
					
						
							|  |  |  |     SimpleNameAST *member_name2 = member_expr->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(member_name2); | 
					
						
							|  |  |  |     QVERIFY(member_name2->identifier_token); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(member_name2->identifier_token), "method"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  | void tst_AST::function_call_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("retranslateUi(blah);")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::function_call_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("retranslateUi(10);")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::function_call_3() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-20 11:26:58 +02:00
										 |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("advance();")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::function_call_4() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("checkPropertyAttribute(attrAst, propAttrs, ReadWrite);")); | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::nested_deref_expression() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("(*blah);")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::assignment_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("a(x) = 3;")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 11:26:58 +02:00
										 |  |  | void tst_AST::assignment_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("(*blah) = 10;")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  |     QVERIFY(ast->asExpressionStatement()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 15:29:58 +02:00
										 |  |  | void tst_AST::if_statement_1() | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b;")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IfStatementAST *stmt = ast->asIfStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->if_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(stmt->lparen_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(stmt->condition != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->rparen_token, 4U); | 
					
						
							|  |  |  |     QVERIFY(stmt->statement != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->else_token, 0U); | 
					
						
							|  |  |  |     QVERIFY(stmt->else_statement == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:24:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |     // check the `then' statement1
 | 
					
						
							| 
									
										
										
										
											2008-12-15 12:24:41 +01:00
										 |  |  |     ExpressionStatementAST *then_stmt = stmt->statement->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(then_stmt != 0); | 
					
						
							|  |  |  |     QVERIFY(then_stmt->expression != 0); | 
					
						
							|  |  |  |     QCOMPARE(then_stmt->semicolon_token, 6U); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *id_expr = then_stmt->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:24:41 +01:00
										 |  |  |     QVERIFY(id_expr != 0); | 
					
						
							|  |  |  |     QCOMPARE(id_expr->identifier_token, 5U); | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 15:29:58 +02:00
										 |  |  | void tst_AST::if_statement_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("if (x<0 && y>a);")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IfStatementAST *stmt = ast->asIfStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(stmt->condition); | 
					
						
							|  |  |  |     QVERIFY(stmt->condition->asBinaryExpression()); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(stmt->condition->asBinaryExpression()->binary_op_token), int(T_AMPER_AMPER)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::if_statement_3() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("if (x<0 && x<0 && x<0 && x<0 && x<0 && x<0 && x<0);")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IfStatementAST *stmt = ast->asIfStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(stmt->condition); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | void tst_AST::if_else_statement() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b; else c;")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IfStatementAST *stmt = ast->asIfStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->if_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(stmt->lparen_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(stmt->condition != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->rparen_token, 4U); | 
					
						
							|  |  |  |     QVERIFY(stmt->statement != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->else_token, 7U); | 
					
						
							|  |  |  |     QVERIFY(stmt->else_statement != 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // check the `then' statement
 | 
					
						
							|  |  |  |     ExpressionStatementAST *then_stmt = stmt->statement->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(then_stmt != 0); | 
					
						
							|  |  |  |     QVERIFY(then_stmt->expression != 0); | 
					
						
							|  |  |  |     QCOMPARE(then_stmt->semicolon_token, 6U); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *a_id_expr = then_stmt->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QVERIFY(a_id_expr != 0); | 
					
						
							|  |  |  |     QCOMPARE(a_id_expr->identifier_token, 5U); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check the `then' statement
 | 
					
						
							|  |  |  |     ExpressionStatementAST *else_stmt = stmt->else_statement->asExpressionStatement(); | 
					
						
							|  |  |  |     QVERIFY(else_stmt != 0); | 
					
						
							|  |  |  |     QVERIFY(else_stmt->expression != 0); | 
					
						
							|  |  |  |     QCOMPARE(else_stmt->semicolon_token, 9U); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     SimpleNameAST *b_id_expr = else_stmt->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QVERIFY(b_id_expr != 0); | 
					
						
							|  |  |  |     QCOMPARE(b_id_expr->identifier_token, 8U); | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  | void tst_AST::while_statement() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("while (a) { }")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WhileStatementAST *stmt = ast->asWhileStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->while_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(stmt->lparen_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(stmt->condition != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->rparen_token, 4U); | 
					
						
							|  |  |  |     QVERIFY(stmt->statement != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check condition
 | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     QVERIFY(stmt->condition->asIdExpression()->name->asSimpleName() != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->condition->asIdExpression()->name->asSimpleName()->identifier_token, 3U); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // check the `body' statement
 | 
					
						
							|  |  |  |     CompoundStatementAST *body_stmt = stmt->statement->asCompoundStatement(); | 
					
						
							|  |  |  |     QVERIFY(body_stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(body_stmt->lbrace_token, 5U); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(body_stmt->statement_list == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  |     QCOMPARE(body_stmt->rbrace_token, 6U); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::while_condition_statement() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("while (int a = foo) { }")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WhileStatementAST *stmt = ast->asWhileStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->while_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(stmt->lparen_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(stmt->condition != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->rparen_token, 7U); | 
					
						
							|  |  |  |     QVERIFY(stmt->statement != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check condition
 | 
					
						
							|  |  |  |     ConditionAST *condition = stmt->condition->asCondition(); | 
					
						
							|  |  |  |     QVERIFY(condition != 0); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(condition->type_specifier_list != 0); | 
					
						
							|  |  |  |     QVERIFY(condition->type_specifier_list->value->asSimpleSpecifier() != 0); | 
					
						
							|  |  |  |     QCOMPARE(condition->type_specifier_list->value->asSimpleSpecifier()->specifier_token, 3U); | 
					
						
							|  |  |  |     QVERIFY(condition->type_specifier_list->next == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  |     QVERIFY(condition->declarator != 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:08:21 +01:00
										 |  |  |     QVERIFY(condition->declarator->core_declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(condition->declarator->core_declarator->asDeclaratorId() != 0); | 
					
						
							|  |  |  |     QVERIFY(condition->declarator->core_declarator->asDeclaratorId()->name != 0); | 
					
						
							|  |  |  |     QVERIFY(condition->declarator->core_declarator->asDeclaratorId()->name->asSimpleName() != 0); | 
					
						
							|  |  |  |     QCOMPARE(condition->declarator->core_declarator->asDeclaratorId()->name->asSimpleName()->identifier_token, 4U); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(condition->declarator->postfix_declarator_list == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  |     QVERIFY(condition->declarator->initializer != 0); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |     QVERIFY(condition->declarator->initializer->asIdExpression()->name->asSimpleName() != 0); | 
					
						
							|  |  |  |     QCOMPARE(condition->declarator->initializer->asIdExpression()->name->asSimpleName()->identifier_token, 6U); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // check the `body' statement
 | 
					
						
							|  |  |  |     CompoundStatementAST *body_stmt = stmt->statement->asCompoundStatement(); | 
					
						
							|  |  |  |     QVERIFY(body_stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(body_stmt->lbrace_token, 8U); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(body_stmt->statement_list == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:05:02 +01:00
										 |  |  |     QCOMPARE(body_stmt->rbrace_token, 9U); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 13:29:59 +01:00
										 |  |  | void tst_AST::for_statement() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("for (;;) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ForStatementAST *stmt = ast->asForStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->for_token, 1U); | 
					
						
							|  |  |  |     QCOMPARE(stmt->lparen_token, 2U); | 
					
						
							|  |  |  |     QVERIFY(stmt->initializer != 0); | 
					
						
							|  |  |  |     QVERIFY(stmt->initializer->asExpressionStatement() != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->initializer->asExpressionStatement()->semicolon_token, 3U); | 
					
						
							|  |  |  |     QVERIFY(stmt->condition == 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->semicolon_token, 4U); | 
					
						
							|  |  |  |     QVERIFY(stmt->expression == 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->rparen_token, 5U); | 
					
						
							|  |  |  |     QVERIFY(stmt->statement != 0); | 
					
						
							|  |  |  |     QVERIFY(stmt->statement->asCompoundStatement() != 0); | 
					
						
							|  |  |  |     QCOMPARE(stmt->statement->asCompoundStatement()->lbrace_token, 6U); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(stmt->statement->asCompoundStatement()->statement_list == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 13:29:59 +01:00
										 |  |  |     QCOMPARE(stmt->statement->asCompoundStatement()->rbrace_token, 7U); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  | void tst_AST::cpp_initializer_or_function_declaration() | 
					
						
							| 
									
										
										
										
											2008-12-15 12:24:41 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("QFileInfo fileInfo(foo);")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DeclarationStatementAST *stmt = ast->asDeclarationStatement(); | 
					
						
							|  |  |  |     QVERIFY(stmt != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(stmt->declaration != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SimpleDeclarationAST *simple_decl = stmt->declaration->asSimpleDeclaration(); | 
					
						
							|  |  |  |     QVERIFY(simple_decl != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(simple_decl->decl_specifier_list != 0); | 
					
						
							|  |  |  |     QVERIFY(simple_decl->decl_specifier_list->next == 0); | 
					
						
							|  |  |  |     QVERIFY(simple_decl->declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(simple_decl->declarator_list->next == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QCOMPARE(simple_decl->semicolon_token, 6U); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     NamedTypeSpecifierAST *named_ty = simple_decl->decl_specifier_list->value->asNamedTypeSpecifier(); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QVERIFY(named_ty != 0); | 
					
						
							|  |  |  |     QVERIFY(named_ty->name != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SimpleNameAST *simple_named_ty = named_ty->name->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(simple_named_ty != 0); | 
					
						
							|  |  |  |     QCOMPARE(simple_named_ty->identifier_token, 1U); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     DeclaratorAST *declarator = simple_decl->declarator_list->value; | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QVERIFY(declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(declarator->core_declarator != 0); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(declarator->postfix_declarator_list->next == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QVERIFY(declarator->initializer == 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DeclaratorIdAST *decl_id = declarator->core_declarator->asDeclaratorId(); | 
					
						
							|  |  |  |     QVERIFY(decl_id != 0); | 
					
						
							|  |  |  |     QVERIFY(decl_id->name != 0); | 
					
						
							|  |  |  |     QVERIFY(decl_id->name->asSimpleName() != 0); | 
					
						
							|  |  |  |     QCOMPARE(decl_id->name->asSimpleName()->identifier_token, 2U); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     FunctionDeclaratorAST *fun_declarator = declarator->postfix_declarator_list->value->asFunctionDeclarator(); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QVERIFY(fun_declarator != 0); | 
					
						
							|  |  |  |     QCOMPARE(fun_declarator->lparen_token, 3U); | 
					
						
							| 
									
										
										
										
											2010-08-26 15:55:31 +02:00
										 |  |  |     QVERIFY(fun_declarator->parameter_declaration_clause != 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QCOMPARE(fun_declarator->rparen_token, 5U); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check the formal arguments
 | 
					
						
							| 
									
										
										
										
											2010-08-26 15:55:31 +02:00
										 |  |  |     ParameterDeclarationClauseAST *param_clause = fun_declarator->parameter_declaration_clause; | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(param_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  |     QVERIFY(param_clause->parameter_declaration_list->next == 0); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:50:21 +01:00
										 |  |  |     QCOMPARE(param_clause->dot_dot_dot_token, 0U); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // check the parameter
 | 
					
						
							| 
									
										
										
										
											2010-08-26 15:55:31 +02:00
										 |  |  |     ParameterDeclarationListAST *declarations = param_clause->parameter_declaration_list; | 
					
						
							| 
									
										
										
										
											2009-06-19 11:19:41 +02:00
										 |  |  |     QVERIFY(declarations); | 
					
						
							| 
									
										
										
										
											2009-11-10 11:23:35 +01:00
										 |  |  |     QVERIFY(declarations->value); | 
					
						
							| 
									
										
										
										
											2009-06-19 11:19:41 +02:00
										 |  |  |     QVERIFY(! declarations->next); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 11:23:35 +01:00
										 |  |  |     ParameterDeclarationAST *param = declarations->value->asParameterDeclaration(); | 
					
						
							| 
									
										
										
										
											2009-06-19 11:19:41 +02:00
										 |  |  |     QVERIFY(param); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     QVERIFY(param->type_specifier_list != 0); | 
					
						
							|  |  |  |     QVERIFY(param->type_specifier_list->next == 0); | 
					
						
							|  |  |  |     QVERIFY(param->type_specifier_list->value->asNamedTypeSpecifier() != 0); | 
					
						
							|  |  |  |     QVERIFY(param->type_specifier_list->value->asNamedTypeSpecifier()->name != 0); | 
					
						
							|  |  |  |     QVERIFY(param->type_specifier_list->value->asNamedTypeSpecifier()->name->asSimpleName() != 0); | 
					
						
							|  |  |  |     QCOMPARE(param->type_specifier_list->value->asNamedTypeSpecifier()->name->asSimpleName()->identifier_token, 4U); | 
					
						
							| 
									
										
										
										
											2008-12-15 12:24:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-04 10:55:44 +01:00
										 |  |  | void tst_AST::cpp_constructor_one_unamed_arg() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString /*name*/) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_one_unamed_arg_namespace() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("Foo::QFileInfo::QFileInfo(QString /*name*/) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_one_named_arg() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString name) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_one_knowntype_arg() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(int /*name*/) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_one_const_arg() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(const QString /*name*/) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_one_ref_arg() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString & /*name*/) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_no_arg() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo() {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause == 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_constructor_multiple_args() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString /*name*/, QString /*type*/) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-03 23:33:44 +04:00
										 |  |  | void tst_AST::cpp_constructor_function_try_catch() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString name, QString type)" | 
					
						
							|  |  |  |                                                           "    try : m_name(name), m_type(type) {}" | 
					
						
							|  |  |  |                                                           "    catch (...) {}")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(funDef != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->ctor_initializer != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list != 0); | 
					
						
							|  |  |  |     QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); | 
					
						
							|  |  |  |     QVERIFY(funDecl != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause != 0); | 
					
						
							|  |  |  |     QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-08 13:42:39 +02:00
										 |  |  | void tst_AST::cpp_qproperty() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QFETCH(QByteArray, source); | 
					
						
							|  |  |  |     QVERIFY(!source.isEmpty()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QByteArray sourceWithinClass = "class C { " + source + " };"; | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration(sourceWithinClass, false, true)); | 
					
						
							|  |  |  |     QVERIFY(unit->ast()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QCOMPARE(diag.errorCount, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::cpp_qproperty_data() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTest::addColumn<QByteArray>("source"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QTest::newRow("read-final") | 
					
						
							|  |  |  |         << QByteArray("Q_PROPERTY(bool focus READ hasFocus FINAL)"); | 
					
						
							|  |  |  |     QTest::newRow("read-write-final") | 
					
						
							|  |  |  |         << QByteArray("Q_PROPERTY(bool focus READ hasFocus WRITE setFocus FINAL)"); | 
					
						
							|  |  |  |     QTest::newRow("member-final") | 
					
						
							|  |  |  |         << QByteArray("Q_PROPERTY(bool focus MEMBER m_focus FINAL)"); | 
					
						
							|  |  |  |     QTest::newRow("member-read-final") | 
					
						
							|  |  |  |         << QByteArray("Q_PROPERTY(bool focus MEMBER m_focus READ m_focus FINAL)"); | 
					
						
							|  |  |  |     QTest::newRow("member-read-write-final") | 
					
						
							|  |  |  |         << QByteArray("Q_PROPERTY(bool focus MEMBER m_focus READ hasFocus WRITE setFocus FINAL)"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QTest::newRow("all") | 
					
						
							|  |  |  |         << QByteArray("Q_PROPERTY(bool focus MEMBER m_focus READ hasFocus WRITE setFocus" | 
					
						
							|  |  |  |                       " RESET resetFocus NOTIFY focusChanged REVISION 1 DESIGNABLE true" | 
					
						
							|  |  |  |                       " SCRIPTABLE true STORED true USER true CONSTANT FINAL)"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-11 09:21:06 +01:00
										 |  |  | void tst_AST::objc_simple_class() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "@interface Zoo {} +(id)alloc;-(id)init;@end\n" | 
					
						
							|  |  |  |                                                           "@implementation Zoo\n" | 
					
						
							|  |  |  |                                                           "+(id)alloc{}\n" | 
					
						
							|  |  |  |                                                           "-(id)init{}\n" | 
					
						
							|  |  |  |                                                           "@end\n" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  | void tst_AST::objc_attributes_followed_by_at_keyword() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  | "__attribute__((deprecated)) @interface foo <bar>\n" | 
					
						
							|  |  |  | "{\n" | 
					
						
							|  |  |  | " int a, b;\n" | 
					
						
							|  |  |  | "}\n" | 
					
						
							|  |  |  | "+ (id) init;\n" | 
					
						
							|  |  |  | "- (id) init:(int)a foo:(int)b, c;\n" | 
					
						
							|  |  |  | "@end\n" | 
					
						
							|  |  |  |     )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:03:37 +01:00
										 |  |  |     QVERIFY(ast); | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_protocol_forward_declaration_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n@protocol foo;")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:03:37 +01:00
										 |  |  |     QVERIFY(ast); | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_protocol_definition_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n@protocol foo <ciao, bar> @end")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:03:37 +01:00
										 |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_method_attributes_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "@interface Zoo\n" | 
					
						
							|  |  |  |                                                           "- (void) foo __attribute__((deprecated));\n" | 
					
						
							|  |  |  |                                                           "+ (void) bar __attribute__((unavailable));\n" | 
					
						
							|  |  |  |                                                           "@end\n" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     ObjCClassDeclarationAST *zoo = ast->asObjCClassDeclaration(); | 
					
						
							|  |  |  |     QVERIFY(zoo); | 
					
						
							|  |  |  |     QVERIFY(zoo->interface_token); QVERIFY(! (zoo->implementation_token)); | 
					
						
							|  |  |  |     QVERIFY(zoo->class_name); QVERIFY(zoo->class_name->asSimpleName()); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(zoo->class_name->asSimpleName()->identifier_token), "Zoo"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DeclarationListAST *decls = zoo->member_declaration_list; | 
					
						
							|  |  |  |     QVERIFY(decls->value); | 
					
						
							|  |  |  |     QVERIFY(decls->next); | 
					
						
							|  |  |  |     QVERIFY(decls->next->value); | 
					
						
							|  |  |  |     QVERIFY(! (decls->next->next)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjCMethodDeclarationAST *fooDecl = decls->value->asObjCMethodDeclaration(); | 
					
						
							|  |  |  |     QVERIFY(fooDecl); | 
					
						
							|  |  |  |     QVERIFY(! (fooDecl->function_body)); | 
					
						
							|  |  |  |     QVERIFY(fooDecl->semicolon_token); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjCMethodPrototypeAST *foo = fooDecl->method_prototype; | 
					
						
							|  |  |  |     QVERIFY(foo); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(foo->method_type_token), (int) T_MINUS); | 
					
						
							|  |  |  |     QVERIFY(foo->type_name); | 
					
						
							|  |  |  |     QVERIFY(foo->selector); | 
					
						
							| 
									
										
										
										
											2010-02-23 17:43:40 +01:00
										 |  |  |     QVERIFY(foo->selector->selector_argument_list->value); | 
					
						
							|  |  |  |     QVERIFY(!foo->selector->selector_argument_list->next); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(foo->selector->selector_argument_list->value->name_token), "foo"); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:03:37 +01:00
										 |  |  |     QVERIFY(foo->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(foo->attribute_list->value); | 
					
						
							|  |  |  |     QVERIFY(! (foo->attribute_list->next)); | 
					
						
							|  |  |  |     AttributeSpecifierAST *deprecatedSpec = foo->attribute_list->value->asAttributeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(deprecatedSpec); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(deprecatedSpec->attribute_token), (int) T___ATTRIBUTE__); | 
					
						
							|  |  |  |     QVERIFY(deprecatedSpec->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(deprecatedSpec->attribute_list->value); | 
					
						
							|  |  |  |     QVERIFY(! (deprecatedSpec->attribute_list->next)); | 
					
						
							|  |  |  |     AttributeAST *deprecatedAttr = deprecatedSpec->attribute_list->value->asAttribute(); | 
					
						
							|  |  |  |     QVERIFY(deprecatedAttr); | 
					
						
							|  |  |  |     QVERIFY(! deprecatedAttr->expression_list); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(deprecatedAttr->identifier_token), "deprecated"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjCMethodDeclarationAST *barDecl = decls->next->value->asObjCMethodDeclaration(); | 
					
						
							|  |  |  |     QVERIFY(barDecl); | 
					
						
							|  |  |  |     QVERIFY(! (barDecl->function_body)); | 
					
						
							|  |  |  |     QVERIFY(barDecl->semicolon_token); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjCMethodPrototypeAST *bar = barDecl->method_prototype; | 
					
						
							|  |  |  |     QVERIFY(bar); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(bar->method_type_token), (int) T_PLUS); | 
					
						
							|  |  |  |     QVERIFY(bar->type_name); | 
					
						
							|  |  |  |     QVERIFY(bar->selector); | 
					
						
							| 
									
										
										
										
											2010-02-23 17:43:40 +01:00
										 |  |  |     QVERIFY(bar->selector->selector_argument_list); | 
					
						
							|  |  |  |     QVERIFY(bar->selector->selector_argument_list->value); | 
					
						
							|  |  |  |     QVERIFY(!bar->selector->selector_argument_list->next); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(bar->selector->selector_argument_list->value->name_token), "bar"); | 
					
						
							| 
									
										
										
										
											2010-02-02 12:03:37 +01:00
										 |  |  |     QVERIFY(bar->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(bar->attribute_list->value); | 
					
						
							|  |  |  |     QVERIFY(! (bar->attribute_list->next)); | 
					
						
							|  |  |  |     AttributeSpecifierAST *unavailableSpec = bar->attribute_list->value->asAttributeSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(unavailableSpec); | 
					
						
							|  |  |  |     QCOMPARE(unit->tokenKind(unavailableSpec->attribute_token), (int) T___ATTRIBUTE__); | 
					
						
							|  |  |  |     QVERIFY(unavailableSpec->attribute_list); | 
					
						
							|  |  |  |     QVERIFY(unavailableSpec->attribute_list->value); | 
					
						
							|  |  |  |     QVERIFY(! (unavailableSpec->attribute_list->next)); | 
					
						
							|  |  |  |     AttributeAST *unavailableAttr = unavailableSpec->attribute_list->value->asAttribute(); | 
					
						
							|  |  |  |     QVERIFY(unavailableAttr); | 
					
						
							|  |  |  |     QVERIFY(! unavailableAttr->expression_list); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(unavailableAttr->identifier_token), "unavailable"); | 
					
						
							| 
									
										
										
										
											2009-01-12 14:55:33 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-15 12:24:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-06 16:26:48 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |   @selector(foo) | 
					
						
							|  |  |  |   @selector(foo:) | 
					
						
							|  |  |  |   @selector(foo:bar:) | 
					
						
							|  |  |  |   ... | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void tst_AST::objc_selector_error_recovery_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "void tst() {\n" | 
					
						
							|  |  |  |                                                           "    @selector(foo:\n" | 
					
						
							|  |  |  |                                                           "    int i = 1;\n" | 
					
						
							|  |  |  |                                                           "}\n" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_selector_error_recovery_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "void tst() {\n" | 
					
						
							|  |  |  |                                                           "    @selector(foo:bar);\n" | 
					
						
							|  |  |  |                                                           "}\n" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-18 10:04:28 +02:00
										 |  |  | void tst_AST::objc_try_statement_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit( | 
					
						
							|  |  |  |                 parseDeclaration( | 
					
						
							|  |  |  |                     "\n" | 
					
						
							|  |  |  |                     "void tst() {\n" | 
					
						
							|  |  |  |                     "    @try {\n" | 
					
						
							|  |  |  |                     "        something();\n" | 
					
						
							|  |  |  |                     "    }\n" | 
					
						
							|  |  |  |                     "}\n" | 
					
						
							|  |  |  |                     )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     QCOMPARE(diag.errorCount, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_try_statement_2() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit( | 
					
						
							|  |  |  |                 parseDeclaration( | 
					
						
							|  |  |  |                     "void tst() {\n" | 
					
						
							|  |  |  |                     "    @try {\n" | 
					
						
							|  |  |  |                     "        something();\n" | 
					
						
							|  |  |  |                     "    } @catch (NSException *e) {\n" | 
					
						
							|  |  |  |                     "        another_thing();\n" | 
					
						
							|  |  |  |                     "    } @catch (UIException *e) { \n" | 
					
						
							|  |  |  |                     "        one_more_thing();\n" | 
					
						
							|  |  |  |                     "    } @finally {\n" | 
					
						
							|  |  |  |                     "        nothing();\n" | 
					
						
							|  |  |  |                     "    }\n" | 
					
						
							|  |  |  |                     "}\n" | 
					
						
							|  |  |  |                     )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     QCOMPARE(diag.errorCount, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_try_statement_3() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit( | 
					
						
							|  |  |  |                 parseDeclaration( | 
					
						
							|  |  |  |                     "void tst() {\n" | 
					
						
							|  |  |  |                     "    @try {\n" | 
					
						
							|  |  |  |                     "        get_banana();\n" | 
					
						
							|  |  |  |                     "    } @catch (...) {\n" | 
					
						
							|  |  |  |                     "        printf(\"Oek?\");\n" | 
					
						
							|  |  |  |                     "    }\n" | 
					
						
							|  |  |  |                     "}\n" | 
					
						
							|  |  |  |                     )); | 
					
						
							| 
									
										
										
										
											2013-07-18 10:25:19 +02:00
										 |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     QCOMPARE(diag.errorCount, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_throw_statement() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit( | 
					
						
							|  |  |  |                 parseDeclaration( | 
					
						
							|  |  |  |                     "void tst() {\n" | 
					
						
							|  |  |  |                     "    NSException *up = [NSException exceptionWithName:@\"NoException\"\n" | 
					
						
							|  |  |  |                     "                                              reason:@\"No Reason :-)\"\n" | 
					
						
							|  |  |  |                     "                                            userInfo:nil];\n" | 
					
						
							|  |  |  |                     "    @throw up;\n" | 
					
						
							|  |  |  |                     "}\n" | 
					
						
							|  |  |  |                     )); | 
					
						
							| 
									
										
										
										
											2013-07-18 10:04:28 +02:00
										 |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  |     QCOMPARE(diag.errorCount, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | void tst_AST::normal_array_access() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "int f() {\n" | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |                                                           "  int a[10];\n" | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |                                                           "  int b = 1;\n" | 
					
						
							|  |  |  |                                                           "  return a[b];\n" | 
					
						
							|  |  |  |                                                           "}" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *func = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(func); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statement_list; | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |     QVERIFY(bodyStatements); | 
					
						
							|  |  |  |     QVERIFY(bodyStatements->next); | 
					
						
							|  |  |  |     QVERIFY(bodyStatements->next->next); | 
					
						
							| 
									
										
										
										
											2009-11-10 11:27:56 +01:00
										 |  |  |     QVERIFY(bodyStatements->next->next->value); | 
					
						
							|  |  |  |     ExpressionAST *expr = bodyStatements->next->next->value->asReturnStatement()->expression; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |     QVERIFY(expr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 13:19:47 +02:00
										 |  |  |     ArrayAccessAST *arrayExpr = expr->asArrayAccess(); | 
					
						
							|  |  |  |     QVERIFY(arrayExpr); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 13:19:47 +02:00
										 |  |  |     { // check the left-hand side:
 | 
					
						
							|  |  |  |         ExpressionAST *lhs = arrayExpr->base_expression; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(lhs); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |         SimpleNameAST *a = lhs->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(a); | 
					
						
							|  |  |  |         QCOMPARE(QLatin1String(unit->identifier(a->identifier_token)->chars()), QLatin1String("a")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 13:19:47 +02:00
										 |  |  |     { // check the right-hand side:
 | 
					
						
							|  |  |  |         QVERIFY(arrayExpr->expression); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |         SimpleNameAST *b = arrayExpr->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(b); | 
					
						
							|  |  |  |         QCOMPARE(QLatin1String(unit->identifier(b->identifier_token)->chars()), QLatin1String("b")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::array_access_with_nested_expression() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "int f() {\n" | 
					
						
							|  |  |  |                                                           "  int a[15];\n" | 
					
						
							|  |  |  |                                                           "  int b = 1;\n" | 
					
						
							|  |  |  |                                                           "  return (a)[b];\n" | 
					
						
							|  |  |  |                                                           "}" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *func = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(func); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statement_list; | 
					
						
							| 
									
										
										
										
											2009-11-10 11:27:56 +01:00
										 |  |  |     QVERIFY(bodyStatements && bodyStatements->next && bodyStatements->next->next && bodyStatements->next->next->value); | 
					
						
							|  |  |  |     ExpressionAST *expr = bodyStatements->next->next->value->asReturnStatement()->expression; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |     QVERIFY(expr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CastExpressionAST *castExpr = expr->asCastExpression(); | 
					
						
							|  |  |  |     QVERIFY(!castExpr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 13:19:47 +02:00
										 |  |  |     ArrayAccessAST *arrayExpr = expr->asArrayAccess(); | 
					
						
							|  |  |  |     QVERIFY(arrayExpr); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 13:19:47 +02:00
										 |  |  |     { // check the LHS:
 | 
					
						
							|  |  |  |         ExpressionAST *lhs = arrayExpr->base_expression; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(lhs); | 
					
						
							|  |  |  |         NestedExpressionAST *nested_a = lhs->asNestedExpression(); | 
					
						
							|  |  |  |         QVERIFY(nested_a && nested_a->expression); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |         SimpleNameAST *a = nested_a->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(a); | 
					
						
							|  |  |  |         QCOMPARE(QLatin1String(unit->identifier(a->identifier_token)->chars()), QLatin1String("a")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-25 13:19:47 +02:00
										 |  |  |     { // check the RHS:
 | 
					
						
							|  |  |  |         QVERIFY(arrayExpr->expression); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |         SimpleNameAST *b = arrayExpr->expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(b); | 
					
						
							|  |  |  |         QCOMPARE(QLatin1String(unit->identifier(b->identifier_token)->chars()), QLatin1String("b")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_msg_send_expression() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "int f() {\n" | 
					
						
							|  |  |  |                                                           "  NSObject *obj = [[[NSObject alloc] init] autorelease];\n" | 
					
						
							|  |  |  |                                                           "  return [obj description];\n" | 
					
						
							|  |  |  |                                                           "}" | 
					
						
							|  |  |  |                                                           )); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *func = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(func); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statement_list; | 
					
						
							| 
									
										
										
										
											2009-11-10 11:27:56 +01:00
										 |  |  |     QVERIFY(bodyStatements && bodyStatements->next && !bodyStatements->next->next && bodyStatements->next->value); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     {// check the NSObject declaration
 | 
					
						
							| 
									
										
										
										
											2009-11-10 11:27:56 +01:00
										 |  |  |         DeclarationStatementAST *firstStatement = bodyStatements->value->asDeclarationStatement(); | 
					
						
							| 
									
										
										
										
											2009-10-19 17:47:49 +02:00
										 |  |  |         QVERIFY(firstStatement); | 
					
						
							|  |  |  |         DeclarationAST *objDecl = firstStatement->declaration; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(objDecl); | 
					
						
							|  |  |  |         SimpleDeclarationAST *simpleDecl = objDecl->asSimpleDeclaration(); | 
					
						
							|  |  |  |         QVERIFY(simpleDecl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         {// check the type (NSObject)
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |             QVERIFY(simpleDecl->decl_specifier_list && !simpleDecl->decl_specifier_list->next); | 
					
						
							|  |  |  |             NamedTypeSpecifierAST *namedType = simpleDecl->decl_specifier_list->value->asNamedTypeSpecifier(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |             QVERIFY(namedType && namedType->name); | 
					
						
							|  |  |  |             SimpleNameAST *typeName = namedType->name->asSimpleName(); | 
					
						
							|  |  |  |             QVERIFY(typeName); | 
					
						
							|  |  |  |             QCOMPARE(QLatin1String(unit->identifier(typeName->identifier_token)->chars()), QLatin1String("NSObject")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         {// check the assignment
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |             QVERIFY(simpleDecl->declarator_list && !simpleDecl->declarator_list->next); | 
					
						
							|  |  |  |             DeclaratorAST *declarator = simpleDecl->declarator_list->value; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |             QVERIFY(declarator); | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |             QVERIFY(!declarator->attribute_list); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |             QVERIFY(declarator->ptr_operator_list && !declarator->ptr_operator_list->next | 
					
						
							|  |  |  |                     &&   declarator->ptr_operator_list->value->asPointer() | 
					
						
							|  |  |  |                     && ! declarator->ptr_operator_list->value->asPointer()->cv_qualifier_list); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             QVERIFY(declarator->core_declarator && declarator->core_declarator->asDeclaratorId()); | 
					
						
							|  |  |  |             NameAST *objNameId = declarator->core_declarator->asDeclaratorId()->name; | 
					
						
							|  |  |  |             QVERIFY(objNameId && objNameId->asSimpleName()); | 
					
						
							|  |  |  |             QCOMPARE(QLatin1String(unit->identifier(objNameId->asSimpleName()->identifier_token)->chars()), QLatin1String("obj")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |             QVERIFY(!declarator->postfix_declarator_list); | 
					
						
							|  |  |  |             QVERIFY(!declarator->post_attribute_list); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |             ExpressionAST *initializer = declarator->initializer; | 
					
						
							|  |  |  |             QVERIFY(initializer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ObjCMessageExpressionAST *expr1 = initializer->asObjCMessageExpression(); | 
					
						
							|  |  |  |             QVERIFY(expr1 && expr1->receiver_expression && expr1->selector && !expr1->argument_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ObjCMessageExpressionAST *expr2 = expr1->receiver_expression->asObjCMessageExpression(); | 
					
						
							|  |  |  |             QVERIFY(expr2 && expr2->receiver_expression && expr2->selector && !expr2->argument_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ObjCMessageExpressionAST *expr3 = expr2->receiver_expression->asObjCMessageExpression(); | 
					
						
							|  |  |  |             QVERIFY(expr3 && expr3->receiver_expression && expr3->selector && !expr3->argument_list); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     {// check the return statement
 | 
					
						
							| 
									
										
										
										
											2009-11-10 11:27:56 +01:00
										 |  |  |         ExpressionAST *expr = bodyStatements->next->value->asReturnStatement()->expression; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(expr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ObjCMessageExpressionAST *msgExpr = expr->asObjCMessageExpression(); | 
					
						
							|  |  |  |         QVERIFY(msgExpr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QVERIFY(msgExpr->receiver_expression); | 
					
						
							| 
									
										
										
										
											2010-08-02 12:04:59 +02:00
										 |  |  |         SimpleNameAST *receiver = msgExpr->receiver_expression->asIdExpression()->name->asSimpleName(); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |         QVERIFY(receiver); | 
					
						
							|  |  |  |         QCOMPARE(QLatin1String(unit->identifier(receiver->identifier_token)->chars()), QLatin1String("obj")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QVERIFY(msgExpr->argument_list == 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QVERIFY(msgExpr->selector); | 
					
						
							| 
									
										
										
										
											2010-02-23 17:43:40 +01:00
										 |  |  |         ObjCSelectorArgumentListAST *args = msgExpr->selector->selector_argument_list; | 
					
						
							|  |  |  |         QVERIFY(args); | 
					
						
							|  |  |  |         QVERIFY(args->value); | 
					
						
							|  |  |  |         QVERIFY(! args->next); | 
					
						
							|  |  |  |         QCOMPARE(QLatin1String(unit->identifier(args->value->name_token)->chars()), QLatin1String("description")); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tst_AST::objc_msg_send_expression_without_selector() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // This test is to verify that no ObjCMessageExpressionAST element is created as the expression for the return statement.
 | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "int f() {\n" | 
					
						
							|  |  |  |                                                           "  NSObject *obj = [[[NSObject alloc] init] autorelease];\n" | 
					
						
							|  |  |  |                                                           "  return [obj];\n" | 
					
						
							| 
									
										
										
										
											2010-02-15 12:23:28 +01:00
										 |  |  |                                                           "}", | 
					
						
							|  |  |  |                                                           true)); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FunctionDefinitionAST *func = ast->asFunctionDefinition(); | 
					
						
							|  |  |  |     QVERIFY(func); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:47:16 +01:00
										 |  |  |     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statement_list; | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  |     QVERIFY(bodyStatements && bodyStatements->next); | 
					
						
							| 
									
										
										
										
											2009-11-10 11:27:56 +01:00
										 |  |  |     QVERIFY(bodyStatements->next->value); | 
					
						
							|  |  |  |     QVERIFY(bodyStatements->next->value->asReturnStatement()); | 
					
						
							|  |  |  |     QVERIFY(!bodyStatements->next->value->asReturnStatement()->expression); | 
					
						
							| 
									
										
										
										
											2009-10-19 14:49:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-06 14:32:25 +01:00
										 |  |  | void tst_AST::q_enum_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "class Tst {\n" | 
					
						
							|  |  |  |                                                           "Q_ENUMS(e)\n" | 
					
						
							|  |  |  |                                                           "public:\n" | 
					
						
							|  |  |  |                                                           "enum e { x, y };\n" | 
					
						
							|  |  |  |                                                           "};\n", | 
					
						
							|  |  |  |                                                           false, true)); | 
					
						
							|  |  |  |     QVERIFY(unit->ast()); | 
					
						
							|  |  |  |     SimpleDeclarationAST *tstDecl = unit->ast()->asSimpleDeclaration(); | 
					
						
							|  |  |  |     QVERIFY(tstDecl); | 
					
						
							|  |  |  |     QVERIFY(! tstDecl->declarator_list); | 
					
						
							|  |  |  |     QVERIFY(tstDecl->decl_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(tstDecl->decl_specifier_list->value); | 
					
						
							|  |  |  |     QVERIFY(! tstDecl->decl_specifier_list->next); | 
					
						
							|  |  |  |     ClassSpecifierAST *tst = tstDecl->decl_specifier_list->value->asClassSpecifier(); | 
					
						
							|  |  |  |     QVERIFY(tst); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVERIFY(tst->member_specifier_list); | 
					
						
							|  |  |  |     QVERIFY(tst->member_specifier_list->value); | 
					
						
							|  |  |  |     QtEnumDeclarationAST *qtEnum = tst->member_specifier_list->value->asQtEnumDeclaration(); | 
					
						
							|  |  |  |     QVERIFY(qtEnum); | 
					
						
							|  |  |  |     QVERIFY(qtEnum->enumerator_list); | 
					
						
							|  |  |  |     QVERIFY(qtEnum->enumerator_list->value); | 
					
						
							|  |  |  |     QVERIFY(! qtEnum->enumerator_list->next); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SimpleNameAST *e = qtEnum->enumerator_list->value->asSimpleName(); | 
					
						
							|  |  |  |     QVERIFY(e); | 
					
						
							|  |  |  |     QCOMPARE(unit->spell(e->identifier_token), "e"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-22 11:24:29 +02:00
										 |  |  | void tst_AST::incomplete_ast() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseStatement("class A { virtual void a() =\n")); | 
					
						
							|  |  |  |     AST *ast = unit->ast(); | 
					
						
							|  |  |  |     QVERIFY(ast); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-17 16:07:47 +01:00
										 |  |  | void tst_AST::initTestCase() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     control.setDiagnosticClient(&diag); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-21 15:46:30 +02:00
										 |  |  | void tst_AST::cleanup() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     diag.errorCount = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-12 12:35:49 +02:00
										 |  |  | void tst_AST::line_and_column_1() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" | 
					
						
							|  |  |  |                                                           "int i;\n", | 
					
						
							|  |  |  |                                                           false, true)); | 
					
						
							|  |  |  |     unsigned line, column = 0; | 
					
						
							|  |  |  |     QVERIFY(unit->ast()); | 
					
						
							|  |  |  |     QVERIFY(unit->tokenAt(1).is(T_INT)); | 
					
						
							|  |  |  |     unit->getTokenPosition(1, &line, &column); | 
					
						
							|  |  |  |     QEXPECT_FAIL("", "See QTCREATORBUG-9799.", Continue); | 
					
						
							|  |  |  |     QCOMPARE(line, 2U); | 
					
						
							|  |  |  |     QCOMPARE(column, 1U); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-15 11:35:38 +01:00
										 |  |  | QTEST_APPLESS_MAIN(tst_AST) | 
					
						
							|  |  |  | #include "tst_ast.moc"
 |