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