Mercurial > projects > qtd
annotate generator/parser/type_compiler.cpp @ 380:beb04f46ef4a
fix NULL default values
author | Eldar Insafutdinov |
---|---|
date | Sat, 10 Jul 2010 22:32:16 +0100 |
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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
45 | |
46 | |
47 #include "type_compiler.h" | |
48 #include "name_compiler.h" | |
49 #include "lexer.h" | |
50 #include "symbol.h" | |
51 #include "tokens.h" | |
52 #include "binder.h" | |
53 | |
54 #include <QtCore/QString> | |
55 | |
56 TypeCompiler::TypeCompiler(Binder *binder) | |
57 : _M_binder (binder), _M_token_stream(binder->tokenStream ()) | |
58 { | |
59 } | |
60 | |
61 void TypeCompiler::run(TypeSpecifierAST *node) | |
62 { | |
63 _M_type.clear(); | |
64 _M_cv.clear(); | |
65 | |
66 visit(node); | |
67 | |
68 if (node && node->cv) | |
69 { | |
70 const ListNode<std::size_t> *it = node->cv->toFront(); | |
71 const ListNode<std::size_t> *end = it; | |
72 do | |
73 { | |
74 int kind = _M_token_stream->kind(it->element); | |
75 if (! _M_cv.contains(kind)) | |
76 _M_cv.append(kind); | |
77 | |
78 it = it->next; | |
79 } | |
80 while (it != end); | |
81 } | |
82 } | |
83 | |
84 void TypeCompiler::visitClassSpecifier(ClassSpecifierAST *node) | |
85 { | |
86 visit(node->name); | |
87 } | |
88 | |
89 void TypeCompiler::visitEnumSpecifier(EnumSpecifierAST *node) | |
90 { | |
91 visit(node->name); | |
92 } | |
93 | |
94 void TypeCompiler::visitElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST *node) | |
95 { | |
96 visit(node->name); | |
97 } | |
98 | |
99 void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node) | |
100 { | |
101 if (const ListNode<std::size_t> *it = node->integrals) | |
102 { | |
103 it = it->toFront(); | |
104 const ListNode<std::size_t> *end = it; | |
105 QString current_item; | |
106 do | |
107 { | |
108 std::size_t token = it->element; | |
109 current_item += token_name(_M_token_stream->kind(token)); | |
110 current_item += " "; | |
111 it = it->next; | |
112 } | |
113 while (it != end); | |
114 _M_type += current_item.trimmed(); | |
115 } | |
116 else if (node->type_of) | |
117 { | |
118 // ### implement me | |
119 _M_type += QLatin1String("typeof<...>"); | |
120 } | |
121 | |
122 visit(node->name); | |
123 } | |
124 | |
125 void TypeCompiler::visitName(NameAST *node) | |
126 { | |
127 NameCompiler name_cc(_M_binder); | |
128 name_cc.run(node); | |
129 _M_type = name_cc.qualifiedName(); | |
130 } | |
131 | |
132 QStringList TypeCompiler::cvString() const | |
133 { | |
134 QStringList lst; | |
135 | |
136 foreach (int q, cv()) | |
137 { | |
138 if (q == Token_const) | |
139 lst.append(QLatin1String("const")); | |
140 else if (q == Token_volatile) | |
141 lst.append(QLatin1String("volatile")); | |
142 } | |
143 | |
144 return lst; | |
145 } | |
146 | |
147 bool TypeCompiler::isConstant() const | |
148 { | |
149 return _M_cv.contains(Token_const); | |
150 } | |
151 | |
152 bool TypeCompiler::isVolatile() const | |
153 { | |
154 return _M_cv.contains(Token_volatile); | |
155 } | |
156 | |
157 // kate: space-indent on; indent-width 2; replace-tabs on; |