bool* arguments can be used by wrappers
[lqt.git] / cpptoxml / parser / type_compiler.cpp
blob7f83afb80fa2d530fd32705e13780f4d512cc917
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
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 ****************************************************************************/
25 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
28 #include "type_compiler.h"
29 #include "name_compiler.h"
30 #include "lexer.h"
31 #include "symbol.h"
32 #include "tokens.h"
33 #include "binder.h"
35 #include <QtCore/QString>
37 TypeCompiler::TypeCompiler(Binder *binder)
38 : _M_binder (binder), _M_token_stream(binder->tokenStream ())
42 void TypeCompiler::run(TypeSpecifierAST *node)
44 _M_type.clear();
45 _M_cv.clear();
47 visit(node);
49 if (node && node->cv)
51 const ListNode<std::size_t> *it = node->cv->toFront();
52 const ListNode<std::size_t> *end = it;
55 int kind = _M_token_stream->kind(it->element);
56 if (! _M_cv.contains(kind))
57 _M_cv.append(kind);
59 it = it->next;
61 while (it != end);
65 void TypeCompiler::visitClassSpecifier(ClassSpecifierAST *node)
67 visit(node->name);
70 void TypeCompiler::visitEnumSpecifier(EnumSpecifierAST *node)
72 visit(node->name);
75 void TypeCompiler::visitElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST *node)
77 visit(node->name);
80 void TypeCompiler::visitSimpleTypeSpecifier(SimpleTypeSpecifierAST *node)
82 if (const ListNode<std::size_t> *it = node->integrals)
84 it = it->toFront();
85 const ListNode<std::size_t> *end = it;
86 QString current_item;
89 std::size_t token = it->element;
90 current_item += token_name(_M_token_stream->kind(token));
91 current_item += " ";
92 it = it->next;
94 while (it != end);
95 _M_type += current_item.trimmed();
97 else if (node->type_of)
99 // ### implement me
100 _M_type += QLatin1String("typeof<...>");
103 visit(node->name);
106 void TypeCompiler::visitName(NameAST *node)
108 NameCompiler name_cc(_M_binder);
109 name_cc.run(node);
110 _M_type = name_cc.qualifiedName();
113 QStringList TypeCompiler::cvString() const
115 QStringList lst;
117 foreach (int q, cv())
119 if (q == Token_const)
120 lst.append(QLatin1String("const"));
121 else if (q == Token_volatile)
122 lst.append(QLatin1String("volatile"));
125 return lst;
128 bool TypeCompiler::isConstant() const
130 return _M_cv.contains(Token_const);
133 bool TypeCompiler::isVolatile() const
135 return _M_cv.contains(Token_volatile);
138 // kate: space-indent on; indent-width 2; replace-tabs on;