Done with: Erik Verbruggen
This commit is contained in:
Roberto Raggi
2009-11-09 15:10:03 +01:00
parent e0b27ef72e
commit 56a677e0b6

View File

@@ -4,6 +4,7 @@
#include <QTextDocument> #include <QTextDocument>
#include <QTextCursor> #include <QTextCursor>
#include <QTextBlock> #include <QTextBlock>
#include <QDir>
#include <QDebug> #include <QDebug>
#include <Control.h> #include <Control.h>
@@ -163,32 +164,24 @@ private:
Overview oo; Overview oo;
}; };
int main(int argc, char *argv[]) void generateAST_H(const Snapshot &snapshot, const QDir &cplusplusDir)
{ {
QCoreApplication app(argc, argv); QFileInfo fileAST_h(cplusplusDir, QLatin1String("AST.h"));
QStringList files = app.arguments(); Q_ASSERT(fileAST_h.exists());
files.removeFirst();
if (files.isEmpty()) { const QString fileName = fileAST_h.absoluteFilePath();
std::cerr << "Usage: cplusplus AST.h" << std::endl;
return EXIT_FAILURE;
}
Snapshot snapshot;
//const QString configuration = QLatin1String("#define CPLUSPLUS_EXPORT\n");
foreach (const QString &fileName, files) {
QFile file(fileName); QFile file(fileName);
if (! file.open(QFile::ReadOnly)) if (! file.open(QFile::ReadOnly))
continue; return;
const QString source = QTextStream(&file).readAll(); const QString source = QTextStream(&file).readAll();
file.close();
QTextDocument document; QTextDocument document;
document.setPlainText(source); document.setPlainText(source);
Document::Ptr doc = Document::create(fileName); Document::Ptr doc = Document::create(fileName);
//doc->control()->setDiagnosticClient(0);
const QByteArray preprocessedCode = snapshot.preprocessedCode(source, fileName); const QByteArray preprocessedCode = snapshot.preprocessedCode(source, fileName);
doc->setSource(preprocessedCode); doc->setSource(preprocessedCode);
doc->check(); doc->check();
@@ -210,7 +203,7 @@ int main(int argc, char *argv[])
const QString className = oo(classAST->symbol->name()); const QString className = oo(classAST->symbol->name());
const QString methodName = QLatin1String("as") + className.mid(0, className.length() - 3); const QString methodName = QLatin1String("as") + className.mid(0, className.length() - 3);
replacementCastMethods[classAST] = QString(" virtual %1 *%2() { return this; }\n").arg(className, methodName); replacementCastMethods[classAST] = QString(" virtual %1 *%2() { return this; }\n").arg(className, methodName);
castMethods.append(QString(" virtual %1 *%2() { return 0; }").arg(className, methodName)); castMethods.append(QString(" virtual %1 *%2() { return 0; }\n").arg(className, methodName));
} }
if (! baseCastMethodCursors.isEmpty()) { if (! baseCastMethodCursors.isEmpty()) {
@@ -219,7 +212,7 @@ int main(int argc, char *argv[])
baseCastMethodCursors[i].removeSelectedText(); baseCastMethodCursors[i].removeSelectedText();
} }
baseCastMethodCursors.first().insertText(castMethods.join(QLatin1String("\n"))); baseCastMethodCursors.first().insertText(castMethods.join(QLatin1String("")));
} }
for (int classIndex = 0; classIndex < astNodes.deriveds.size(); ++classIndex) { for (int classIndex = 0; classIndex < astNodes.deriveds.size(); ++classIndex) {
@@ -234,6 +227,25 @@ int main(int argc, char *argv[])
astNodes.endOfPublicClassSpecifiers[classIndex].insertText(replacementCastMethods.value(classAST)); astNodes.endOfPublicClassSpecifiers[classIndex].insertText(replacementCastMethods.value(classAST));
} }
std::cout << qPrintable(document.toPlainText()); if (file.open(QFile::WriteOnly)) {
QTextStream out(&file);
out << document.toPlainText();
} }
} }
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QStringList files = app.arguments();
files.removeFirst();
if (files.isEmpty()) {
std::cerr << "Usage: cplusplus [path to C++ front-end]" << std::endl;
return EXIT_FAILURE;
}
QDir cplusplusDir(files.first());
Snapshot snapshot;
generateAST_H(snapshot, cplusplusDir);
}