1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved.
|
|
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
|
|
5 **
|
|
6 ** This file is part of Qt Jambi.
|
|
7 **
|
|
8 ** * Commercial Usage
|
|
9 * Licensees holding valid Qt Commercial licenses may use this file in
|
|
10 * accordance with the Qt Commercial License Agreement provided with the
|
|
11 * Software or, alternatively, in accordance with the terms contained in
|
|
12 * a written agreement between you and Nokia.
|
|
13 *
|
|
14 *
|
|
15 * GNU General Public License Usage
|
|
16 * Alternatively, this file may be used under the terms of the GNU
|
|
17 * General Public License versions 2.0 or 3.0 as published by the Free
|
|
18 * Software Foundation and appearing in the file LICENSE.GPL included in
|
|
19 * the packaging of this file. Please review the following information
|
|
20 * to ensure GNU General Public Licensing requirements will be met:
|
|
21 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
22 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
23 * exception, Nokia gives you certain additional rights. These rights
|
|
24 * are described in the Nokia Qt GPL Exception version 1.2, included in
|
|
25 * the file GPL_EXCEPTION.txt in this package.
|
|
26 *
|
|
27 * Qt for Windows(R) Licensees
|
|
28 * As a special exception, Nokia, as the sole copyright holder for Qt
|
|
29 * Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
30 * right for the Qt/Eclipse Integration to link to functionality
|
|
31 * provided by Qt Designer and its related libraries.
|
|
32 *
|
|
33 *
|
|
34 * If you are unsure which license is appropriate for your use, please
|
|
35 * contact the sales department at qt-sales@nokia.com.
|
|
36
|
|
37 **
|
|
38 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
39 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
40 **
|
|
41 ****************************************************************************/
|
|
42
|
|
43
|
|
44 #include "name_compiler.h"
|
|
45 #include "type_compiler.h"
|
|
46 #include "declarator_compiler.h"
|
|
47 #include "lexer.h"
|
|
48 #include "symbol.h"
|
|
49 #include "binder.h"
|
|
50
|
|
51 #include <QtCore/qdebug.h>
|
|
52
|
|
53 NameCompiler::NameCompiler(Binder *binder)
|
|
54 : _M_binder (binder), _M_token_stream (binder->tokenStream ())
|
|
55 {
|
|
56 }
|
|
57
|
|
58 QString NameCompiler::decode_operator(std::size_t index) const
|
|
59 {
|
|
60 const Token &tk = _M_token_stream->token((int) index);
|
|
61 return QString::fromUtf8(&tk.text[tk.position], (int) tk.size);
|
|
62 }
|
|
63
|
|
64 QString NameCompiler::internal_run(AST *node)
|
|
65 {
|
|
66 _M_name.clear();
|
|
67 visit(node);
|
|
68 return name();
|
|
69 }
|
|
70
|
|
71 void NameCompiler::visitUnqualifiedName(UnqualifiedNameAST *node)
|
|
72 {
|
|
73 QString tmp_name;
|
|
74
|
|
75 if (node->tilde)
|
|
76 tmp_name += QLatin1String("~");
|
|
77
|
|
78 if (node->id)
|
|
79 tmp_name += _M_token_stream->symbol(node->id)->as_string();
|
|
80
|
|
81 if (OperatorFunctionIdAST *op_id = node->operator_id)
|
|
82 {
|
|
83 #if defined(__GNUC__)
|
|
84 #warning "NameCompiler::visitUnqualifiedName() -- implement me"
|
|
85 #endif
|
|
86
|
|
87 if (op_id->op && op_id->op->op)
|
|
88 {
|
|
89 tmp_name += QLatin1String("operator");
|
|
90 tmp_name += decode_operator(op_id->op->op);
|
|
91 if (op_id->op->close)
|
|
92 tmp_name += decode_operator(op_id->op->close);
|
|
93 }
|
|
94 else if (op_id->type_specifier)
|
|
95 {
|
|
96 #if defined(__GNUC__)
|
|
97 #warning "don't use an hardcoded string as cast' name"
|
|
98 #endif
|
|
99 Token const &tk = _M_token_stream->token ((int) op_id->start_token);
|
|
100 Token const &end_tk = _M_token_stream->token ((int) op_id->end_token);
|
|
101 tmp_name += QString::fromLatin1 (&tk.text[tk.position],
|
|
102 (int) (end_tk.position - tk.position)).trimmed ();
|
|
103 }
|
|
104 }
|
|
105
|
|
106 _M_name += tmp_name;
|
|
107 if (node->template_arguments)
|
|
108 {
|
|
109 // ### cleanup
|
|
110 _M_name.last() += QLatin1String("<");
|
|
111 visitNodes(this, node->template_arguments);
|
|
112 _M_name.last().truncate(_M_name.last().count() - 1); // remove the last ','
|
|
113 _M_name.last() += QLatin1String(">");
|
|
114 }
|
|
115
|
|
116 }
|
|
117
|
|
118 void NameCompiler::visitTemplateArgument(TemplateArgumentAST *node)
|
|
119 {
|
|
120 if (node->type_id && node->type_id->type_specifier)
|
|
121 {
|
|
122 TypeCompiler type_cc(_M_binder);
|
|
123 type_cc.run(node->type_id->type_specifier);
|
|
124
|
|
125 DeclaratorCompiler decl_cc(_M_binder);
|
|
126 decl_cc.run(node->type_id->declarator);
|
|
127
|
|
128 if (type_cc.isConstant())
|
|
129 _M_name.last() += "const ";
|
|
130
|
|
131 QStringList q = type_cc.qualifiedName ();
|
|
132
|
|
133 if (q.count () == 1)
|
|
134 {
|
|
135 #if defined (RXX_RESOLVE_TYPEDEF) // ### it'll break :(
|
|
136 TypeInfo tp;
|
|
137 tp.setQualifiedName (q);
|
|
138 tp = TypeInfo::resolveType (tp, _M_binder->currentScope ()->toItem ());
|
|
139 q = tp.qualifiedName ();
|
|
140 #endif
|
|
141
|
|
142 if (CodeModelItem item = _M_binder->model ()->findItem (q, _M_binder->currentScope ()->toItem ()))
|
|
143 {
|
|
144 if (item->name () == q.last ())
|
|
145 q = item->qualifiedName ();
|
|
146 }
|
|
147 }
|
|
148
|
|
149 _M_name.last() += q.join("::");
|
|
150
|
|
151 if (decl_cc.isReference())
|
|
152 _M_name.last() += "&";
|
|
153 if (decl_cc.indirection())
|
|
154 _M_name.last() += QString(decl_cc.indirection(), '*');
|
|
155
|
|
156 _M_name.last() += QLatin1String(",");
|
|
157 }
|
|
158 }
|
|
159
|
|
160 // kate: space-indent on; indent-width 2; replace-tabs on;
|