Mercurial > projects > qtd
annotate generator/parser/declarator_compiler.cpp @ 109:08135aa00cc9
CMake: ldc support option SINGLE_D_OBJECT now.
See http://www.dsource.org/projects/ldc/ticket/309.
author | SokoL_SD |
---|---|
date | Mon, 01 Jun 2009 07:15:52 +0000 |
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 "declarator_compiler.h" | |
46 #include "name_compiler.h" | |
47 #include "type_compiler.h" | |
48 #include "compiler_utils.h" | |
49 #include "lexer.h" | |
50 #include "binder.h" | |
51 #include "tokens.h" | |
52 | |
53 #include <qdebug.h> | |
54 | |
55 DeclaratorCompiler::DeclaratorCompiler(Binder *binder) | |
56 : _M_binder (binder), _M_token_stream (binder->tokenStream ()) | |
57 { | |
58 } | |
59 | |
60 void DeclaratorCompiler::run(DeclaratorAST *node) | |
61 { | |
62 _M_id.clear(); | |
63 _M_parameters.clear(); | |
64 _M_array.clear(); | |
65 _M_function = false; | |
66 _M_reference = false; | |
67 _M_variadics = false; | |
68 _M_indirection = 0; | |
69 | |
70 if (node) | |
71 { | |
72 NameCompiler name_cc(_M_binder); | |
73 | |
74 DeclaratorAST *decl = node; | |
75 while (decl && decl->sub_declarator) | |
76 decl = decl->sub_declarator; | |
77 | |
78 Q_ASSERT (decl != 0); | |
79 | |
80 name_cc.run(decl->id); | |
81 _M_id = name_cc.name(); | |
82 _M_function = (node->parameter_declaration_clause != 0); | |
83 if (node->parameter_declaration_clause && node->parameter_declaration_clause->ellipsis) | |
84 _M_variadics = true; | |
85 | |
86 visitNodes(this, node->ptr_ops); | |
87 visit(node->parameter_declaration_clause); | |
88 | |
89 if (const ListNode<ExpressionAST*> *it = node->array_dimensions) | |
90 { | |
91 it->toFront(); | |
92 const ListNode<ExpressionAST*> *end = it; | |
93 | |
94 do | |
95 { | |
96 QString elt; | |
97 if (ExpressionAST *expr = it->element) | |
98 { | |
99 const Token &start_token = _M_token_stream->token((int) expr->start_token); | |
100 const Token &end_token = _M_token_stream->token((int) expr->end_token); | |
101 | |
102 elt += QString::fromUtf8(&start_token.text[start_token.position], | |
103 (int) (end_token.position - start_token.position)).trimmed(); | |
104 } | |
105 | |
106 _M_array.append (elt); | |
107 | |
108 it = it->next; | |
109 } | |
110 while (it != end); | |
111 } | |
112 } | |
113 } | |
114 | |
115 void DeclaratorCompiler::visitPtrOperator(PtrOperatorAST *node) | |
116 { | |
117 std::size_t op = _M_token_stream->kind(node->op); | |
118 | |
119 switch (op) | |
120 { | |
121 case '&': | |
122 _M_reference = true; | |
123 break; | |
124 case '*': | |
125 ++_M_indirection; | |
126 break; | |
127 | |
128 default: | |
129 break; | |
130 } | |
131 | |
132 if (node->mem_ptr) | |
133 { | |
134 #if defined(__GNUC__) | |
135 #warning "ptr to mem -- not implemented" | |
136 #endif | |
137 } | |
138 } | |
139 | |
140 void DeclaratorCompiler::visitParameterDeclaration(ParameterDeclarationAST *node) | |
141 { | |
142 Parameter p; | |
143 | |
144 TypeCompiler type_cc(_M_binder); | |
145 DeclaratorCompiler decl_cc(_M_binder); | |
146 | |
147 decl_cc.run(node->declarator); | |
148 | |
149 p.name = decl_cc.id(); | |
150 p.type = CompilerUtils::typeDescription(node->type_specifier, node->declarator, _M_binder); | |
151 if (node->expression != 0) | |
152 { | |
153 const Token &start = _M_token_stream->token((int) node->expression->start_token); | |
154 const Token &end = _M_token_stream->token((int) node->expression->end_token); | |
155 int length = (int) (end.position - start.position); | |
156 | |
157 p.defaultValueExpression = QString(); | |
158 QString source = QString::fromUtf8(&start.text[start.position], length).trimmed(); | |
159 QStringList list = source.split("\n"); | |
160 | |
161 | |
162 for (int i=0; i<list.size(); ++i) { | |
163 if (!list.at(i).startsWith("#")) | |
164 p.defaultValueExpression += list.at(i).trimmed(); | |
165 } | |
166 | |
167 p.defaultValue = p.defaultValueExpression.size() > 0; | |
168 | |
169 } | |
170 | |
171 _M_parameters.append(p); | |
172 } | |
173 | |
174 // kate: space-indent on; indent-width 2; replace-tabs on; |