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 "name_compiler.h"
27 #include "type_compiler.h"
28 #include "declarator_compiler.h"
33 #include <QtCore/qdebug.h>
35 NameCompiler::NameCompiler(Binder
*binder
)
36 : _M_binder (binder
), _M_token_stream (binder
->tokenStream ())
40 QString
NameCompiler::decode_operator(std::size_t index
) const
42 const Token
&tk
= _M_token_stream
->token((int) index
);
43 return QString::fromUtf8(&tk
.text
[tk
.position
], (int) tk
.size
);
46 QString
NameCompiler::internal_run(AST
*node
)
53 void NameCompiler::visitUnqualifiedName(UnqualifiedNameAST
*node
)
58 tmp_name
+= QLatin1String("~");
61 tmp_name
+= _M_token_stream
->symbol(node
->id
)->as_string();
63 if (OperatorFunctionIdAST
*op_id
= node
->operator_id
)
66 #warning "NameCompiler::visitUnqualifiedName() -- implement me"
69 if (op_id
->op
&& op_id
->op
->op
)
71 tmp_name
+= QLatin1String("operator");
72 tmp_name
+= decode_operator(op_id
->op
->op
);
74 tmp_name
+= decode_operator(op_id
->op
->close
);
76 else if (op_id
->type_specifier
)
79 #warning "don't use an hardcoded string as cast' name"
81 Token
const &tk
= _M_token_stream
->token ((int) op_id
->start_token
);
82 Token
const &end_tk
= _M_token_stream
->token ((int) op_id
->end_token
);
83 tmp_name
+= QString::fromLatin1 (&tk
.text
[tk
.position
],
84 (int) (end_tk
.position
- tk
.position
)).trimmed ();
89 if (node
->template_arguments
)
92 _M_name
.last() += QLatin1String("<");
93 visitNodes(this, node
->template_arguments
);
94 _M_name
.last().truncate(_M_name
.last().count() - 1); // remove the last ','
95 _M_name
.last() += QLatin1String(">");
100 void NameCompiler::visitTemplateArgument(TemplateArgumentAST
*node
)
102 if (node
->type_id
&& node
->type_id
->type_specifier
)
104 TypeCompiler
type_cc(_M_binder
);
105 type_cc
.run(node
->type_id
->type_specifier
);
107 DeclaratorCompiler
decl_cc(_M_binder
);
108 decl_cc
.run(node
->type_id
->declarator
);
110 if (type_cc
.isConstant())
111 _M_name
.last() += "const ";
113 QStringList q
= type_cc
.qualifiedName ();
117 #if defined (RXX_RESOLVE_TYPEDEF) // ### it'll break :(
119 tp
.setQualifiedName (q
);
120 tp
= TypeInfo::resolveType (tp
, _M_binder
->currentScope ()->toItem ());
121 q
= tp
.qualifiedName ();
124 if (CodeModelItem item
= _M_binder
->model ()->findItem (q
, _M_binder
->currentScope ()->toItem ()))
126 if (item
->name () == q
.last ())
127 q
= item
->qualifiedName ();
131 _M_name
.last() += q
.join("::");
133 if (decl_cc
.isReference())
134 _M_name
.last() += "&";
135 if (decl_cc
.indirection())
136 _M_name
.last() += QString(decl_cc
.indirection(), '*');
138 _M_name
.last() += QLatin1String(",");
142 // kate: space-indent on; indent-width 2; replace-tabs on;