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