use separate slot implementation for each module
[lqt.git] / cpptoxml / parser / declarator_compiler.cpp
blob2127c57a27f6514f111060eec994a42ff57d5732
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.trolltech.com/products/qt/opensource.html
15 ** If you are unsure which license is appropriate for your use, please
16 ** review the following information:
17 ** http://www.trolltech.com/products/qt/licensing.html or contact the
18 ** sales department at sales@trolltech.com.
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 ****************************************************************************/
26 #include "declarator_compiler.h"
27 #include "name_compiler.h"
28 #include "type_compiler.h"
29 #include "compiler_utils.h"
30 #include "lexer.h"
31 #include "binder.h"
32 #include "tokens.h"
34 #include <qdebug.h>
36 DeclaratorCompiler::DeclaratorCompiler(Binder *binder)
37 : _M_binder (binder), _M_token_stream (binder->tokenStream ())
41 void DeclaratorCompiler::run(DeclaratorAST *node)
43 _M_id.clear();
44 _M_parameters.clear();
45 _M_array.clear();
46 _M_function = false;
47 _M_reference = false;
48 _M_variadics = false;
49 _M_indirection = 0;
51 if (node)
53 NameCompiler name_cc(_M_binder);
55 DeclaratorAST *decl = node;
56 while (decl && decl->sub_declarator)
57 decl = decl->sub_declarator;
59 Q_ASSERT (decl != 0);
61 name_cc.run(decl->id);
62 _M_id = name_cc.name();
63 _M_function = (node->parameter_declaration_clause != 0);
64 if (node->parameter_declaration_clause && node->parameter_declaration_clause->ellipsis)
65 _M_variadics = true;
67 visitNodes(this, node->ptr_ops);
68 visit(node->parameter_declaration_clause);
70 if (const ListNode<ExpressionAST*> *it = node->array_dimensions)
72 it->toFront();
73 const ListNode<ExpressionAST*> *end = it;
77 QString elt;
78 if (ExpressionAST *expr = it->element)
80 const Token &start_token = _M_token_stream->token((int) expr->start_token);
81 const Token &end_token = _M_token_stream->token((int) expr->end_token);
83 elt += QString::fromUtf8(&start_token.text[start_token.position],
84 (int) (end_token.position - start_token.position)).trimmed();
87 _M_array.append (elt);
89 it = it->next;
91 while (it != end);
96 void DeclaratorCompiler::visitPtrOperator(PtrOperatorAST *node)
98 std::size_t op = _M_token_stream->kind(node->op);
100 switch (op)
102 case '&':
103 _M_reference = true;
104 break;
105 case '*':
106 ++_M_indirection;
107 break;
109 default:
110 break;
113 if (node->mem_ptr)
115 #if defined(__GNUC__)
116 #warning "ptr to mem -- not implemented"
117 #endif
121 void DeclaratorCompiler::visitParameterDeclaration(ParameterDeclarationAST *node)
123 Parameter p;
125 TypeCompiler type_cc(_M_binder);
126 DeclaratorCompiler decl_cc(_M_binder);
128 decl_cc.run(node->declarator);
130 p.name = decl_cc.id();
131 p.type = CompilerUtils::typeDescription(node->type_specifier, node->declarator, _M_binder);
132 if (node->expression != 0)
134 const Token &start = _M_token_stream->token((int) node->expression->start_token);
135 const Token &end = _M_token_stream->token((int) node->expression->end_token);
136 int length = (int) (end.position - start.position);
138 p.defaultValueExpression = QString();
139 QString source = QString::fromUtf8(&start.text[start.position], length).trimmed();
140 QStringList list = source.split("\n");
143 for (int i=0; i<list.size(); ++i) {
144 if (!list.at(i).startsWith("#"))
145 p.defaultValueExpression += list.at(i).trimmed();
148 p.defaultValue = p.defaultValueExpression.size() > 0;
152 _M_parameters.append(p);
155 // kate: space-indent on; indent-width 2; replace-tabs on;