From 71c174cece832f7835b5ea73898e18c20487d1d4 Mon Sep 17 00:00:00 2001 From: Mauro Iazzi Date: Thu, 21 Feb 2008 01:06:01 +0100 Subject: [PATCH] changed copyright notice preprocessor of cpptoxml supports config files --- LICENSE | 2 +- binder.lua | 2 +- event.lua | 2 +- generate_function.lua | 2 +- lqt_common.cpp | 2 +- lqt_common.hpp | 2 +- lqt_qt_utils.cpp | 2 +- lqt_qt_utils.hpp | 2 +- main.cpp | 2 +- new/cpptoxml/main.cpp | 94 ++++++++++++++++++++++++++------ new/cpptoxml/parser/rpp/preprocessor.cpp | 25 +++++++++ new/cpptoxml/parser/rpp/preprocessor.h | 3 +- qt_generator.lua | 2 +- tutorial.lua | 2 +- xml.lua | 2 +- 15 files changed, 115 insertions(+), 31 deletions(-) diff --git a/LICENSE b/LICENSE index 53a1b0a..9b67c66 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/binder.lua b/binder.lua index 3237383..afb3054 100644 --- a/binder.lua +++ b/binder.lua @@ -2,7 +2,7 @@ --[[ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/event.lua b/event.lua index c420230..4497ab7 100644 --- a/event.lua +++ b/event.lua @@ -2,7 +2,7 @@ --[[ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/generate_function.lua b/generate_function.lua index 031ffbc..ea93ee6 100644 --- a/generate_function.lua +++ b/generate_function.lua @@ -2,7 +2,7 @@ --[[ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/lqt_common.cpp b/lqt_common.cpp index 4f164e9..345538f 100644 --- a/lqt_common.cpp +++ b/lqt_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Mauro Iazzi + * Copyright (c) 2007-2008 Mauro Iazzi * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lqt_common.hpp b/lqt_common.hpp index 029da68..3c9ce31 100644 --- a/lqt_common.hpp +++ b/lqt_common.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Mauro Iazzi + * Copyright (c) 2007-2008 Mauro Iazzi * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lqt_qt_utils.cpp b/lqt_qt_utils.cpp index d4249b7..a48ebe0 100644 --- a/lqt_qt_utils.cpp +++ b/lqt_qt_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Mauro Iazzi + * Copyright (c) 2007-2008 Mauro Iazzi * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/lqt_qt_utils.hpp b/lqt_qt_utils.hpp index 23122fe..5c24476 100644 --- a/lqt_qt_utils.hpp +++ b/lqt_qt_utils.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Mauro Iazzi + * Copyright (c) 2007-2008 Mauro Iazzi * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/main.cpp b/main.cpp index d25b730..fcee14a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Mauro Iazzi + * Copyright (c) 2007-2008 Mauro Iazzi * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation diff --git a/new/cpptoxml/main.cpp b/new/cpptoxml/main.cpp index 035e4b2..abb62fb 100644 --- a/new/cpptoxml/main.cpp +++ b/new/cpptoxml/main.cpp @@ -31,6 +31,7 @@ #include "codemodel.h" #include "control.h" #include "parser.h" +#include "preprocessor.h" #include #include @@ -38,6 +39,7 @@ #include #include +#include #include @@ -327,33 +329,89 @@ QString XMLVisitor::visit(NamespaceModelItem n) { } */ int main (int argc, char **argv) { - if (argc<2) {} + bool onlyPreprocess = false; + QString configName; + QString sourceName; - QFile file(argv[1]); + QStringList options; + for (int i=1;i i+1) { + configName = options.at(i+1); + options.removeAt(i+1); + } + options.removeAt(i); + } + if ((i=options.indexOf("-P"))!=-1) { + onlyPreprocess = true; + options.removeAt(i); + } + if (options.count()>1) return 37; + sourceName = options.at(0); - if (!file.open(QFile::ReadOnly)) - return false; + QByteArray contents; + if (0) { + QFile file(argv[1]); - QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); - QByteArray contents = stream.readAll().toUtf8(); - file.close(); + if (!file.open(QFile::ReadOnly)) + return false; + QTextStream stream(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); + contents = stream.readAll().toUtf8(); + file.close(); + } else { + Preprocessor pp; + QStringList inclist; - Control control; - Parser p(&control); - pool __pool; + QString qtdir = getenv ("QTDIR"); + if (qtdir.isEmpty()) { + fprintf(stderr, "Generator requires QTDIR to be set\n"); + return false; + } - TranslationUnitAST *ast = p.parse(contents, contents.size(), &__pool); + qtdir += "/include"; - CodeModel model; - Binder binder(&model, p.location()); - FileModelItem f_model = binder.run(ast); + QString currentDir = QDir::current().absolutePath(); + QFileInfo sourceInfo(sourceName); + //QDir::setCurrent(sourceInfo.absolutePath()); - XMLVisitor visitor; - QTextStream(stdout) << visitor.visit(model_static_cast(f_model)); + inclist << (sourceInfo.absolutePath()); + inclist << (QDir::convertSeparators(qtdir)); + inclist << (QDir::convertSeparators(qtdir + "/QtXml")); + inclist << (QDir::convertSeparators(qtdir + "/QtNetwork")); + inclist << (QDir::convertSeparators(qtdir + "/QtCore")); + inclist << (QDir::convertSeparators(qtdir + "/QtGui")); + inclist << (QDir::convertSeparators(qtdir + "/QtOpenGL")); + //qDebug() << inclist; - return 0; + pp.addIncludePaths(inclist); + pp.processFile(sourceName, configName); + //qDebug() << pp.macroNames(); + contents = pp.result(); + //qDebug() << contents; + //QTextStream(stdout) << contents; + } + + if (onlyPreprocess) { + QTextStream(stdout) << contents; + } else { + Control control; + Parser p(&control); + pool __pool; + + TranslationUnitAST *ast = p.parse(contents, contents.size(), &__pool); + + CodeModel model; + Binder binder(&model, p.location()); + FileModelItem f_model = binder.run(ast); + + XMLVisitor visitor; + QTextStream(stdout) << visitor.visit(model_static_cast(f_model)); + } + + return 0; } diff --git a/new/cpptoxml/parser/rpp/preprocessor.cpp b/new/cpptoxml/parser/rpp/preprocessor.cpp index 806135b..112fffa 100644 --- a/new/cpptoxml/parser/rpp/preprocessor.cpp +++ b/new/cpptoxml/parser/rpp/preprocessor.cpp @@ -88,6 +88,30 @@ Preprocessor::~Preprocessor() delete d; } +void Preprocessor::processFile(const QString &fileName, const QString& configName) +{ + pp proc(d->env); + d->initPP(proc); + + QFile configFile(configName); + if (configFile.exists()) { + if (!configFile.open(QFile::ReadOnly)) { + // ERROR! + return; + } + QByteArray ba = configFile.readAll(); + configFile.close(); + proc.operator() (ba.constData(), ba.constData() + ba.size(), rpp::pp_null_output_iterator()); + } else { + } + + d->result.reserve(d->result.size() + 20 * 1024); + + d->result += "# 1 \"" + fileName.toLatin1() + "\"\n"; // ### REMOVE ME + proc.file(fileName.toLocal8Bit().constData(), std::back_inserter(d->result)); +} + +/* void Preprocessor::processFile(const QString &fileName) { pp proc(d->env); @@ -98,6 +122,7 @@ void Preprocessor::processFile(const QString &fileName) d->result += "# 1 \"" + fileName.toLatin1() + "\"\n"; // ### REMOVE ME proc.file(fileName.toLocal8Bit().constData(), std::back_inserter(d->result)); } +*/ void Preprocessor::processString(const QByteArray &str) { diff --git a/new/cpptoxml/parser/rpp/preprocessor.h b/new/cpptoxml/parser/rpp/preprocessor.h index 373bf90..1ba6ae3 100644 --- a/new/cpptoxml/parser/rpp/preprocessor.h +++ b/new/cpptoxml/parser/rpp/preprocessor.h @@ -58,7 +58,8 @@ public: Preprocessor(); ~Preprocessor(); - void processFile(const QString &fileName); + void processFile(const QString &fileName, const QString& configName = QString()); + //void processFile(const QString &fileName); void processString(const QByteArray &str); void addIncludePaths(const QStringList &includePaths); diff --git a/qt_generator.lua b/qt_generator.lua index 0f3a405..84a32d7 100644 --- a/qt_generator.lua +++ b/qt_generator.lua @@ -1,7 +1,7 @@ #!/usr/bin/lua --[[ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/tutorial.lua b/tutorial.lua index d12282e..db771c4 100644 --- a/tutorial.lua +++ b/tutorial.lua @@ -1,7 +1,7 @@ #!/usr/bin/lua --[[ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/xml.lua b/xml.lua index b701583..df74d67 100644 --- a/xml.lua +++ b/xml.lua @@ -1,7 +1,7 @@ #!/usr/bin/lua --[[ -Copyright (c) 2007 Mauro Iazzi +Copyright (c) 2007-2008 Mauro Iazzi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation -- 2.11.4.GIT