1
/****************************************************************************
3
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4
** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
6
** This file is part of the Qt Script Generator project on Trolltech Labs.
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"
36
DeclaratorCompiler::DeclaratorCompiler(Binder *binder)
37
: _M_binder (binder), _M_token_stream (binder->tokenStream ())
41
void DeclaratorCompiler::run(DeclaratorAST *node)
44
_M_parameters.clear();
53
NameCompiler name_cc(_M_binder);
55
DeclaratorAST *decl = node;
56
while (decl && decl->sub_declarator)
57
decl = decl->sub_declarator;
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)
67
visitNodes(this, node->ptr_ops);
68
visit(node->parameter_declaration_clause);
70
if (const ListNode<ExpressionAST*> *it = node->array_dimensions)
73
const ListNode<ExpressionAST*> *end = it;
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);
96
void DeclaratorCompiler::visitPtrOperator(PtrOperatorAST *node)
98
std::size_t op = _M_token_stream->kind(node->op);
115
#if defined(__GNUC__)
116
#warning "ptr to mem -- not implemented"
121
void DeclaratorCompiler::visitParameterDeclaration(ParameterDeclarationAST *node)
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;