1
/****************************************************************************
3
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
5
** This file is part of the Qt Script Generator project on Trolltech Labs.
7
** This file may be used under the terms of the GNU General Public
8
** License version 2.0 as published by the Free Software Foundation
9
** and appearing in the file LICENSE.GPL included in the packaging of
10
** this file. Please review the following information to ensure GNU
11
** General Public Licensing requirements will be met:
12
** http://www.trolltech.com/products/qt/opensource.html
14
** If you are unsure which license is appropriate for your use, please
15
** review the following information:
16
** http://www.trolltech.com/products/qt/licensing.html or contact the
17
** sales department at sales@trolltech.com.
19
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22
****************************************************************************/
30
#include <QXmlStreamWriter>
31
#include <QTextStream>
35
void astToXML(QString name) {
38
if (!file.open(QFile::ReadOnly))
41
QTextStream stream(&file);
42
stream.setCodec(QTextCodec::codecForName("UTF-8"));
43
QByteArray contents = stream.readAll().toUtf8();
50
TranslationUnitAST *ast = p.parse(contents, contents.size(), &__pool);
53
Binder binder(&model, p.location());
54
FileModelItem dom = binder.run(ast);
57
if (!outputFile.open(stdout, QIODevice::WriteOnly))
62
QXmlStreamWriter s( &outputFile);
63
s.setAutoFormatting( true );
65
s.writeStartElement("code");
67
QHash<QString, NamespaceModelItem> namespaceMap = dom->namespaceMap();
68
foreach (NamespaceModelItem item, namespaceMap.values()) {
69
writeOutNamespace(s, item);
72
QHash<QString, ClassModelItem> typeMap = dom->classMap();
73
foreach (ClassModelItem item, typeMap.values()) {
74
writeOutClass(s, item);
80
void writeOutNamespace(QXmlStreamWriter &s, NamespaceModelItem &item) {
81
s.writeStartElement("namespace");
82
s.writeAttribute("name", item->name());
84
QHash<QString, NamespaceModelItem> namespaceMap = item->namespaceMap();
85
foreach (NamespaceModelItem namespaceItem, namespaceMap.values()) {
86
writeOutNamespace(s, namespaceItem);
89
QHash<QString, ClassModelItem> typeMap = item->classMap();
90
foreach (ClassModelItem classItem, typeMap.values()) {
91
writeOutClass(s, classItem);
94
QHash<QString, EnumModelItem> enumMap = item->enumMap();
95
foreach (EnumModelItem enumItem, enumMap.values()) {
96
writeOutEnum(s, enumItem);
102
void writeOutEnum(QXmlStreamWriter &s, EnumModelItem &item) {
103
QString qualified_name = item->qualifiedName().join("::");
104
s.writeStartElement("enum");
105
s.writeAttribute("name", qualified_name);
107
EnumeratorList enumList = item->enumerators();
108
for(int i=0; i < enumList.size() ; i++) {
109
s.writeStartElement("enumerator");
110
if( !enumList[i]->value().isEmpty() )
111
s.writeAttribute("value", enumList[i]->value());
112
s.writeCharacters(enumList[i]->name());
119
void writeOutFunction(QXmlStreamWriter &s, FunctionModelItem &item) {
120
QString qualified_name = item->qualifiedName().join("::");
121
s.writeStartElement("function");
122
s.writeAttribute("name", qualified_name);
124
ArgumentList arguments = item->arguments();
125
for(int i=0; i < arguments.size() ; i++) {
126
s.writeStartElement("argument");
127
s.writeAttribute("type", arguments[i]->type().qualifiedName().join("::"));
133
void writeOutClass(QXmlStreamWriter &s, ClassModelItem &item) {
134
QString qualified_name = item->qualifiedName().join("::");
135
s.writeStartElement("class");
136
s.writeAttribute("name", qualified_name);
138
QHash<QString, EnumModelItem> enumMap = item->enumMap();
139
foreach (EnumModelItem enumItem, enumMap.values()) {
140
writeOutEnum(s, enumItem);
143
QHash<QString, FunctionModelItem> functionMap = item->functionMap();
144
foreach (FunctionModelItem funcItem, functionMap.values()) {
145
writeOutFunction(s, funcItem);
148
QHash<QString, ClassModelItem> typeMap = item->classMap();
149
foreach (ClassModelItem classItem, typeMap.values()) {
150
writeOutClass(s, classItem);