diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /buildtools/lib/parsers/qmake/tests | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'buildtools/lib/parsers/qmake/tests')
-rw-r--r-- | buildtools/lib/parsers/qmake/tests/Makefile.am | 21 | ||||
-rw-r--r-- | buildtools/lib/parsers/qmake/tests/runner.cpp | 169 | ||||
-rw-r--r-- | buildtools/lib/parsers/qmake/tests/viewer.cpp | 182 | ||||
-rw-r--r-- | buildtools/lib/parsers/qmake/tests/viewer.h | 48 | ||||
-rw-r--r-- | buildtools/lib/parsers/qmake/tests/viewer_main.cpp | 33 | ||||
-rw-r--r-- | buildtools/lib/parsers/qmake/tests/viewerbase.ui | 250 |
6 files changed, 703 insertions, 0 deletions
diff --git a/buildtools/lib/parsers/qmake/tests/Makefile.am b/buildtools/lib/parsers/qmake/tests/Makefile.am new file mode 100644 index 00000000..a73f8f4e --- /dev/null +++ b/buildtools/lib/parsers/qmake/tests/Makefile.am @@ -0,0 +1,21 @@ +# This directory collects some classes related to +# project management for the sole purpose that they +# can be shared between parts. + +INCLUDES = -I$(top_srcdir)/lib/interfaces \ + -I$(top_srcdir)/lib/interfaces/extensions -I$(top_srcdir)/lib/util -I$(top_srcdir)/lib/widgets/propeditor \ + -I$(top_srcdir)/buildtools/lib/parsers/qmake \ + -I$(top_builddir)/buildtools/lib/parsers/qmake/tests \ + $(all_includes) + +METASOURCES = AUTO + +noinst_PROGRAMS = runner viewer + +runner_LDFLAGS = $(all_libraries) $(LIB_KDECORE) $(KDE_RPATH) +runner_LDADD = $(top_builddir)/buildtools/lib/parsers/qmake/libkdevqmakeparser.la +runner_SOURCES = runner.cpp + +viewer_LDFLAGS = --no-undefined $(all_libraries) $(LIB_KDECORE) $(KDE_RPATH) +viewer_LDADD = $(top_builddir)/buildtools/lib/parsers/qmake/libkdevqmakeparser.la +viewer_SOURCES = viewer.cpp viewer_main.cpp viewerbase.ui diff --git a/buildtools/lib/parsers/qmake/tests/runner.cpp b/buildtools/lib/parsers/qmake/tests/runner.cpp new file mode 100644 index 00000000..b01284f1 --- /dev/null +++ b/buildtools/lib/parsers/qmake/tests/runner.cpp @@ -0,0 +1,169 @@ +/*************************************************************************** + * Copyright (C) 2005 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <cstdlib> +#include <iostream> +#include <stdio.h> +#include "qmakedriver.h" +#include "qmakeastvisitor.h" + +#include <qstring.h> + +#include <kdebug.h> +#include <kcmdlineargs.h> +#include <kurl.h> + +static const KCmdLineOptions options[] = +{ + {"silent", "Enable Parser debug output", 0}, + {"!debug", "Disable output of the generated AST", 0}, + {"!+files", "QMake project files", 0} +}; + + +class PrintAST : QMake::ASTVisitor +{ +public: + PrintAST() : QMake::ASTVisitor() + { + indent = 0; + } + + virtual void processProject( QMake::ProjectAST* p ) + { + QMake::ASTVisitor::processProject(p); + } +private: + virtual void enterRealProject( QMake::ProjectAST* p ) + { + kdDebug(9024) << getIndent() << "--------- Entering Project: " << replaceWs(p->fileName()) << "| LineEnding:" << p->lineEnding() << " --------------" << endl; + indent += 4; + QMake::ASTVisitor::enterRealProject(p); + } + + virtual void leaveRealProject( QMake::ProjectAST* p ) + { + indent -= 4; + kdDebug(9024) << getIndent() << "--------- Leaving Project: " << replaceWs(p->fileName()) << " --------------" << endl; + QMake::ASTVisitor::leaveRealProject(p); + } + + virtual void enterScope( QMake::ProjectAST* p ) + { + kdDebug(9024) << getIndent() << "--------- Entering Scope: " << replaceWs(p->scopedID) << " --------------" << endl; + indent += 4; + QMake::ASTVisitor::enterScope(p); + } + + virtual void leaveScope( QMake::ProjectAST* p ) + { + indent -= 4; + kdDebug(9024) << getIndent() << "--------- Leaving Scope: " << replaceWs(p->scopedID) << " --------------" << endl; + QMake::ASTVisitor::leaveScope(p); + } + + virtual void enterFunctionScope( QMake::ProjectAST* p ) + { + kdDebug(9024) << getIndent() << "--------- Entering FunctionScope: " << replaceWs(p->scopedID) << "(" << replaceWs(p->args) << ")"<< " --------------" << endl; + indent += 4; + QMake::ASTVisitor::enterFunctionScope(p); + } + + virtual void leaveFunctionScope( QMake::ProjectAST* p ) + { + indent -= 4; + kdDebug(9024) << getIndent() << "--------- Leaving FunctionScope: " << replaceWs(p->scopedID) << "(" << replaceWs(p->args) << ")"<< " --------------" << endl; + QMake::ASTVisitor::leaveFunctionScope(p); + } + + QString replaceWs(QString s) + { + return s.replace("\n", "%nl").replace("\t", "%tab").replace(" ", "%spc"); + } + + virtual void processAssignment( QMake::AssignmentAST* a) + { + kdDebug(9024) << getIndent() << "Assignment(" << replaceWs(a->indent) << "):" << replaceWs(a->scopedID) << " " << replaceWs(a->op) << " " << replaceWs(a->values.join("|")) << endl; + QMake::ASTVisitor::processAssignment(a); + } + + virtual void processNewLine( QMake::NewLineAST* n) + { + kdDebug(9024) << getIndent() << "Newline " << endl; + QMake::ASTVisitor::processNewLine(n); + } + + virtual void processComment( QMake::CommentAST* a) + { + kdDebug(9024) << getIndent() << "Comment: " << replaceWs(a->comment) << endl; + QMake::ASTVisitor::processComment(a); + } + + virtual void processInclude( QMake::IncludeAST* a) + { + kdDebug(9024) << getIndent() << "Include: " << replaceWs(a->projectName) << endl; + QMake::ASTVisitor::processInclude(a); + } + + QString getIndent() + { + QString ind; + for( int i = 0 ; i < indent ; i++) + ind += " "; + return ind; + } + int indent; +}; +int main(int argc, char *argv[]) +{ + KCmdLineArgs::init( argc, argv, "QMake Parser", "qmake-parser", "Parse QMake project files", "1.0.0"); + KCmdLineArgs::addCmdLineOptions(options); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + if( args->count() < 1 ) + { + KCmdLineArgs::usage(0); + } + + int debug = 0; + bool silent = false; + + if( args->isSet("silent") ) + silent = true; + if( args->isSet("debug") ) + debug = 1; + for( int i = 0 ; i < args->count() ; i++ ) + { + QMake::ProjectAST *projectAST; + int ret = QMake::Driver::parseFile(args->url(i).path(), &projectAST, debug); + PrintAST pa; + if ( ret == 0 ) + if ( !silent ) + { + pa.processProject(projectAST); + QString profile; + projectAST->writeBack(profile); + kdDebug(9024) << "QMake file written back:\n" << profile << endl; + } + return ret; + } + return 0; +} diff --git a/buildtools/lib/parsers/qmake/tests/viewer.cpp b/buildtools/lib/parsers/qmake/tests/viewer.cpp new file mode 100644 index 00000000..dba2b7fb --- /dev/null +++ b/buildtools/lib/parsers/qmake/tests/viewer.cpp @@ -0,0 +1,182 @@ +/*************************************************************************** + * Copyright (C) 2005 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "viewer.h" + +#include <qdir.h> +#include <qlineedit.h> +#include <qlistbox.h> +#include <qfiledialog.h> +#include <qtextedit.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qlistview.h> +#include <qtabwidget.h> + +#include <qmakeast.h> +#include <qmakedriver.h> +#include <qmakeastvisitor.h> + +using namespace QMake; + +Viewer::Viewer(QWidget *parent, const char *name) + :ViewerBase(parent, name), projectAST(0) +{ + if (QFile::exists(QDir::currentDirPath() + "/" + "qtlist")) + { + QFile f(QDir::currentDirPath() + "/" + "qtlist"); + f.open(IO_ReadOnly); + QTextStream str(&f); + while (!str.eof()) + files->insertItem(str.readLine()); + } + ast->setSorting(-1); +// parentProject.push((QListViewItem*)0); +} + +void Viewer::addAll_clicked() +{ + if (allLocation->text().isEmpty()) + return; + QDir d(allLocation->text()); + QStringList l = d.entryList("*.pro *.pri"); + for (QStringList::iterator it = l.begin(); it != l.end(); ++it) + (*it) = QDir::cleanDirPath(allLocation->text() + "/" + (*it)); + files->insertStringList(l); +} + +void Viewer::choose_clicked() +{ + QString fileName = QFileDialog::getOpenFileName(QDir::currentDirPath(), "*.pro *.pri", this); + if (!fileName.isEmpty()) + files->insertItem(fileName); +} + +void Viewer::files_currentChanged(QListBoxItem* item) +{ + ast->clear(); + + QFile f(item->text()); + f.open(IO_ReadOnly); + QTextStream str(&f); + source->setText(str.read()); + f.close(); + + int result = QMake::Driver::parseFile(item->text().ascii(), &projectAST, 0); + if (projectAST && (result == 0)) + { + processAST(projectAST); + } + if (tabWidget2->currentPageIndex() == 1) + tabWidget2_selected("Source to be written back"); +} + +void Viewer::tabWidget2_selected(const QString& text) +{ + if ((text == "Source to Be Written Back") && projectAST) + { + QString buffer; + projectAST->writeBack(buffer); + writeBack->setText(buffer); + } +} + +class ViewerVisitor: public ASTVisitor { +public: + ViewerVisitor(Viewer *v): ASTVisitor() + { + this->v = v; + parentProject.push((QListViewItem*)0); + } + + virtual void processProject(ProjectAST *project) + { + ASTVisitor::processProject(project); + } + + virtual void enterRealProject(ProjectAST *project) + { + QListViewItem *projectIt; + if (!parentProject.top()) + { + projectIt = new QListViewItem(v->ast, "Project"); + projectIt->setOpen(true); + parentProject.push(projectIt); + } + + ASTVisitor::enterRealProject(project); + } + virtual void enterScope(ProjectAST *scope) + { + QListViewItem *projectIt = new QListViewItem(parentProject.top(), scope->scopedID, "scope"); + parentProject.push(projectIt); + ASTVisitor::enterScope(scope); + } + virtual void leaveScope(ProjectAST *scope) + { + parentProject.pop(); + } + virtual void enterFunctionScope(ProjectAST *fscope) + { + QListViewItem *projectIt = new QListViewItem(parentProject.top(), + fscope->scopedID + "(" + fscope->args + ")", "function scope"); + parentProject.push(projectIt); + ASTVisitor::enterFunctionScope(fscope); + } + virtual void leaveFunctionScope(ProjectAST *fscope) + { + parentProject.pop(); + } + virtual void processAssignment(AssignmentAST *assignment) + { + QListViewItem *item = new QListViewItem(parentProject.top(), + assignment->scopedID, assignment->op, assignment->values.join("|"), + "assignment"); + item->setMultiLinesEnabled(true); + + ASTVisitor::processAssignment(assignment); + } + virtual void processNewLine(NewLineAST *newline) + { + new QListViewItem(parentProject.top(), "<newline>"); + ASTVisitor::processNewLine(newline); + } + virtual void processComment(CommentAST *comment) + { + new QListViewItem(parentProject.top(), "<comment>"); + ASTVisitor::processComment(comment); + } + virtual void processInclude(IncludeAST *include) + { + new QListViewItem(parentProject.top(), "<include>", include->projectName); + QMake::ASTVisitor::processInclude(include); + } + + Viewer *v; + QValueStack<QListViewItem *> parentProject; +}; + + +void Viewer::processAST(QMake::ProjectAST *projectAST, QListViewItem *globAfter) +{ + ViewerVisitor visitor(this); + visitor.processProject(projectAST); +} + +#include "viewer.moc" diff --git a/buildtools/lib/parsers/qmake/tests/viewer.h b/buildtools/lib/parsers/qmake/tests/viewer.h new file mode 100644 index 00000000..8d0da49f --- /dev/null +++ b/buildtools/lib/parsers/qmake/tests/viewer.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (C) 2005 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef VIEWER_H +#define VIEWER_H + +#include <qvaluestack.h> + +#include "viewerbase.h" + +namespace QMake { +class ProjectAST; +} + +class QListViewItem; + +class Viewer: public ViewerBase { +Q_OBJECT +public: + Viewer(QWidget *parent = 0, const char *name = 0); + void processAST(QMake::ProjectAST *projectAST, QListViewItem *globAfter = 0); +public slots: + virtual void tabWidget2_selected(const QString&); + virtual void files_currentChanged(QListBoxItem*); + virtual void choose_clicked(); + virtual void addAll_clicked(); +private: + QMake::ProjectAST *projectAST; + friend class ViewerVisitor; +}; + +#endif diff --git a/buildtools/lib/parsers/qmake/tests/viewer_main.cpp b/buildtools/lib/parsers/qmake/tests/viewer_main.cpp new file mode 100644 index 00000000..8fdbc910 --- /dev/null +++ b/buildtools/lib/parsers/qmake/tests/viewer_main.cpp @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (C) 2005 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include <qapplication.h> +#include "viewer.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + Viewer viewer; + app.setMainWidget(&viewer); + viewer.show(); + viewer.setWindowState(viewer.windowState() | Qt::WindowMaximized); + + return app.exec(); +} diff --git a/buildtools/lib/parsers/qmake/tests/viewerbase.ui b/buildtools/lib/parsers/qmake/tests/viewerbase.ui new file mode 100644 index 00000000..976d4d0f --- /dev/null +++ b/buildtools/lib/parsers/qmake/tests/viewerbase.ui @@ -0,0 +1,250 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ViewerBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ViewerBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>Viewer</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QSplitter" row="0" column="0"> + <property name="name"> + <cstring>splitter5</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLineEdit"> + <property name="name"> + <cstring>allLocation</cstring> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>32767</height> + </size> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>addAll</cstring> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>32767</height> + </size> + </property> + <property name="text"> + <string>Add All From Directory</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>choose</cstring> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>32767</height> + </size> + </property> + <property name="text"> + <string>Choose File to Add...</string> + </property> + </widget> + <widget class="QListBox"> + <property name="name"> + <cstring>files</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>32767</height> + </size> + </property> + <property name="hScrollBarMode"> + <enum>Auto</enum> + </property> + </widget> + </vbox> + </widget> + <widget class="QSplitter"> + <property name="name"> + <cstring>splitter2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <widget class="QTextEdit"> + <property name="name"> + <cstring>source</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QTabWidget"> + <property name="name"> + <cstring>tabWidget2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>2</verstretch> + </sizepolicy> + </property> + <widget class="QWidget"> + <property name="name"> + <cstring>tab</cstring> + </property> + <attribute name="title"> + <string>Parse Tree</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QListView" row="0" column="0"> + <column> + <property name="text"> + <string>Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Value 1</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Value 2</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Value 3</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>ast</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>tab</cstring> + </property> + <attribute name="title"> + <string>Source to Be Written Back</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QTextEdit" row="0" column="0"> + <property name="name"> + <cstring>writeBack</cstring> + </property> + </widget> + </grid> + </widget> + </widget> + </widget> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>addAll</sender> + <signal>clicked()</signal> + <receiver>ViewerBase</receiver> + <slot>addAll_clicked()</slot> + </connection> + <connection> + <sender>choose</sender> + <signal>clicked()</signal> + <receiver>ViewerBase</receiver> + <slot>choose_clicked()</slot> + </connection> + <connection> + <sender>files</sender> + <signal>currentChanged(QListBoxItem*)</signal> + <receiver>ViewerBase</receiver> + <slot>files_currentChanged(QListBoxItem*)</slot> + </connection> + <connection> + <sender>tabWidget2</sender> + <signal>selected(const QString&)</signal> + <receiver>ViewerBase</receiver> + <slot>tabWidget2_selected(const QString&)</slot> + </connection> +</connections> +<slots> + <slot>addAll_clicked()</slot> + <slot>choose_clicked()</slot> + <slot>files_currentChanged( QListBoxItem * )</slot> + <slot>tabWidget2_selected( const QString & )</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> |