Fix tools/cplusplus* build with Qt6

Replace endl with Qt::endl (available since Qt 5.14)

Task-number: QTCREATORBUG-24098
Change-Id: I1a9ff2692259174c9d90612d063ca04a56285175
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2020-09-17 11:41:03 +02:00
parent 6400aab190
commit 897ee0e76b
2 changed files with 155 additions and 174 deletions

View File

@@ -39,13 +39,13 @@ void executeCommand(const QString &command, const QStringList &arguments, const
{ {
QTextStream out(stderr); QTextStream out(stderr);
if (command.isEmpty()) { if (command.isEmpty()) {
out << "Error: " << Q_FUNC_INFO << "Got empty command to execute." << endl; out << "Error: " << Q_FUNC_INFO << "Got empty command to execute." << Qt::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
const QString fullCommand = command + QLatin1Char(' ') + arguments.join(QLatin1Char(' ')); const QString fullCommand = command + QLatin1Char(' ') + arguments.join(QLatin1Char(' '));
if (verbose) if (verbose)
out << "Executing: " << fullCommand << endl; out << "Executing: " << fullCommand << Qt::endl;
QProcess process; QProcess process;
if (!outputFile.isEmpty()) if (!outputFile.isEmpty())
@@ -53,23 +53,23 @@ void executeCommand(const QString &command, const QStringList &arguments, const
process.start(command, arguments); process.start(command, arguments);
if (!process.waitForStarted()) { if (!process.waitForStarted()) {
out << QString::fromLatin1("Error: Process \"%1\" did not start within timeout: %2.") out << QString::fromLatin1("Error: Process \"%1\" did not start within timeout: %2.")
.arg(fullCommand, process.errorString()) .arg(fullCommand, process.errorString())
<< endl; << Qt::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!process.waitForFinished() && process.state() == QProcess::Running) { if (!process.waitForFinished() && process.state() == QProcess::Running) {
if (!verbose) if (!verbose)
out << process.readAll() << endl; out << process.readAll() << Qt::endl;
out << QString::fromLatin1("Error: Process \"%1\" did not finish within timeout.") out << QString::fromLatin1("Error: Process \"%1\" did not finish within timeout.").arg(fullCommand)
.arg(fullCommand) << Qt::endl;
<< endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
const int exitCode = process.exitCode(); const int exitCode = process.exitCode();
if (exitCode != 0) { if (exitCode != 0) {
out << process.readAllStandardError() << endl; out << process.readAllStandardError() << Qt::endl;
out << QString::fromLatin1("Error: Process \"%1\" finished with non zero exit value %2") out << QString::fromLatin1("Error: Process \"%1\" finished with non zero exit value %2")
.arg(fullCommand, exitCode) << endl; .arg(fullCommand, exitCode)
<< Qt::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@@ -100,15 +100,15 @@ void SystemPreprocessor::check() const
QTextStream out(stderr); QTextStream out(stderr);
if (!QFile::exists(QLatin1String(PATH_PREPROCESSOR_CONFIG))) { if (!QFile::exists(QLatin1String(PATH_PREPROCESSOR_CONFIG))) {
out << QString::fromLatin1("Error: File \"%1\" does not exist.") out << QString::fromLatin1("Error: File \"%1\" does not exist.")
.arg(QLatin1String(PATH_PREPROCESSOR_CONFIG)) .arg(QLatin1String(PATH_PREPROCESSOR_CONFIG))
<< endl; << Qt::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (m_compiler.isEmpty()) { if (m_compiler.isEmpty()) {
const QString triedCompilers const QString triedCompilers
= QStringList(m_knownCompilers.keys()).join(QLatin1String(", ")); = QStringList(m_knownCompilers.keys()).join(QLatin1String(", "));
out << QString::fromLatin1("Error: No compiler found. Tried %1.").arg(triedCompilers) out << QString::fromLatin1("Error: No compiler found. Tried %1.").arg(triedCompilers)
<< endl; << Qt::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@@ -118,7 +118,7 @@ void SystemPreprocessor::preprocessFile(const QString &inputFile, const QString
check(); check();
if (!QFile::exists(inputFile)) { if (!QFile::exists(inputFile)) {
QTextStream out(stderr); QTextStream out(stderr);
out << QString::fromLatin1("Error: File \"%1\" does not exist.").arg(inputFile) << endl; out << QString::fromLatin1("Error: File \"%1\" does not exist.").arg(inputFile) << Qt::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
const QStringList arguments = QStringList(m_compilerArguments) const QStringList arguments = QStringList(m_compilerArguments)

View File

@@ -105,7 +105,7 @@ static void closeBufferAndWriteIfChanged(QBuffer& textBuffer, const QString& fil
currentTextBuffer.open(QIODevice::WriteOnly | QIODevice::Text); currentTextBuffer.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream currentTextBufferWriter(&currentTextBuffer); QTextStream currentTextBufferWriter(&currentTextBuffer);
while (!fileReader.atEnd()) { while (!fileReader.atEnd()) {
currentTextBufferWriter << fileReader.readLine() << endl; currentTextBufferWriter << fileReader.readLine() << Qt::endl;
} }
file.close(); file.close();
currentTextBuffer.close(); currentTextBuffer.close();
@@ -251,12 +251,13 @@ public:
QTextStream output(&buffer); QTextStream output(&buffer);
out = &output; out = &output;
*out << copyrightHeader << generatedHeader << *out << copyrightHeader << generatedHeader
"\n" << "\n"
"#include \"AST.h\"\n" "#include \"AST.h\"\n"
"#include \"ASTVisitor.h\"\n" "#include \"ASTVisitor.h\"\n"
"\n" "\n"
"using namespace CPlusPlus;\n" << endl; "using namespace CPlusPlus;\n"
<< Qt::endl;
accept(ast); accept(ast);
@@ -280,7 +281,7 @@ protected:
void visitMembers(Class *klass) void visitMembers(Class *klass)
{ {
// *out << " // visit " << className.constData() << endl; // *out << " // visit " << className.constData() << Qt::endl;
for (int i = 0; i < klass->memberCount(); ++i) { for (int i = 0; i < klass->memberCount(); ++i) {
Symbol *member = klass->memberAt(i); Symbol *member = klass->memberAt(i);
if (! member->name()) if (! member->name())
@@ -301,7 +302,8 @@ protected:
QByteArray typeName = namedTy->name()->identifier()->chars(); QByteArray typeName = namedTy->name()->identifier()->chars();
if (typeName.endsWith("AST") && memberName != "next") if (typeName.endsWith("AST") && memberName != "next")
*out << " accept(" << memberName.constData() << ", visitor);" << endl; *out << " accept(" << memberName.constData() << ", visitor);"
<< Qt::endl;
} }
} }
} }
@@ -350,18 +352,16 @@ protected:
classMap.insert(className, ast); classMap.insert(className, ast);
*out *out << "void " << className.constData() << "::accept0(ASTVisitor *visitor)" << Qt::endl
<< "void " << className.constData() << "::accept0(ASTVisitor *visitor)" << endl << "{" << Qt::endl
<< "{" << endl << " if (visitor->visit(this)) {" << Qt::endl;
<< " if (visitor->visit(this)) {" << endl;
visitMembers(klass); visitMembers(klass);
*out *out << " }" << Qt::endl
<< " }" << endl << " visitor->endVisit(this);" << Qt::endl
<< " visitor->endVisit(this);" << endl << "}" << Qt::endl
<< "}" << endl << Qt::endl;
<< endl;
return true; return true;
} }
@@ -385,12 +385,13 @@ public:
buffer.open(openFlags); buffer.open(openFlags);
QTextStream output(&buffer); QTextStream output(&buffer);
out = &output; out = &output;
*out << copyrightHeader << generatedHeader << *out << copyrightHeader << generatedHeader
"\n" << "\n"
"#include \"AST.h\"\n" "#include \"AST.h\"\n"
"#include \"ASTMatcher.h\"\n" "#include \"ASTMatcher.h\"\n"
"\n" "\n"
"using namespace CPlusPlus;\n" << endl; "using namespace CPlusPlus;\n"
<< Qt::endl;
accept(ast); accept(ast);
@@ -417,11 +418,12 @@ protected:
Overview oo; Overview oo;
const QString className = oo(klass->name()); const QString className = oo(klass->name());
*out << " if (" << className << " *_other = pattern->as" << className.left(className.length() - 3) << "())" << endl; *out << " if (" << className << " *_other = pattern->as"
<< className.left(className.length() - 3) << "())" << Qt::endl;
*out << " return matcher->match(this, _other);" << endl; *out << " return matcher->match(this, _other);" << Qt::endl;
*out << endl; *out << Qt::endl;
} }
bool checkMethod(Symbol *accept0Method) const bool checkMethod(Symbol *accept0Method) const
@@ -460,16 +462,13 @@ protected:
classMap.insert(className, ast); classMap.insert(className, ast);
*out *out << "bool " << className.constData() << "::match0(AST *pattern, ASTMatcher *matcher)"
<< "bool " << className.constData() << "::match0(AST *pattern, ASTMatcher *matcher)" << endl << Qt::endl
<< "{" << endl; << "{" << Qt::endl;
visitMembers(klass); visitMembers(klass);
*out *out << " return false;" << Qt::endl << "}" << Qt::endl << Qt::endl;
<< " return false;" << endl
<< "}" << endl
<< endl;
return true; return true;
} }
@@ -495,19 +494,18 @@ public:
QTextStream output(&buffer); QTextStream output(&buffer);
out = &output; out = &output;
*out << copyrightHeader << endl *out << copyrightHeader << Qt::endl
<< generatedHeader << generatedHeader << "#include \"AST.h\"" << Qt::endl
<< "#include \"AST.h\"" << endl << "#include \"ASTMatcher.h\"" << Qt::endl
<< "#include \"ASTMatcher.h\"" << endl << Qt::endl
<< endl << "using namespace CPlusPlus;" << Qt::endl
<< "using namespace CPlusPlus;" << endl << Qt::endl
<< endl << "ASTMatcher::ASTMatcher()" << Qt::endl
<< "ASTMatcher::ASTMatcher()" << endl << "{ }" << Qt::endl
<< "{ }" << endl << Qt::endl
<< endl << "ASTMatcher::~ASTMatcher()" << Qt::endl
<< "ASTMatcher::~ASTMatcher()" << endl << "{ }" << Qt::endl
<< "{ }" << endl << Qt::endl;
<< endl;
accept(ast); accept(ast);
@@ -543,10 +541,8 @@ protected:
const QByteArray memberName = QByteArray::fromRawData(id->chars(), id->size()); const QByteArray memberName = QByteArray::fromRawData(id->chars(), id->size());
if (member->type()->isIntegerType() && memberName.endsWith("_token")) { if (member->type()->isIntegerType() && memberName.endsWith("_token")) {
*out << " pattern->" << memberName << " = node->" << memberName << ";" << Qt::endl
*out << Qt::endl;
<< " pattern->" << memberName << " = node->" << memberName << ";" << endl
<< endl;
} else if (PointerType *ptrTy = member->type()->asPointerType()) { } else if (PointerType *ptrTy = member->type()->asPointerType()) {
@@ -554,12 +550,13 @@ protected:
QByteArray typeName = namedTy->name()->identifier()->chars(); QByteArray typeName = namedTy->name()->identifier()->chars();
if (typeName.endsWith("AST")) { if (typeName.endsWith("AST")) {
*out *out << " if (! pattern->" << memberName << ")" << Qt::endl
<< " if (! pattern->" << memberName << ")" << endl << " pattern->" << memberName << " = node->" << memberName
<< " pattern->" << memberName << " = node->" << memberName << ";" << endl << ";" << Qt::endl
<< " else if (! AST::match(node->" << memberName << ", pattern->" << memberName << ", this))" << endl << " else if (! AST::match(node->" << memberName << ", pattern->"
<< " return false;" << endl << memberName << ", this))" << Qt::endl
<< endl; << " return false;" << Qt::endl
<< Qt::endl;
} }
} }
} }
@@ -609,19 +606,16 @@ protected:
classMap.insert(className, ast); classMap.insert(className, ast);
*out *out << "bool ASTMatcher::match(" << className.constData() << " *node, "
<< "bool ASTMatcher::match(" << className.constData() << " *node, " << className.constData() << " *pattern)" << endl << className.constData() << " *pattern)" << Qt::endl
<< "{" << endl << "{" << Qt::endl
<< " (void) node;" << endl << " (void) node;" << Qt::endl
<< " (void) pattern;" << endl << " (void) pattern;" << Qt::endl
<< endl; << Qt::endl;
visitMembers(klass); visitMembers(klass);
*out *out << " return true;" << Qt::endl << "}" << Qt::endl << Qt::endl;
<< " return true;" << endl
<< "}" << endl
<< endl;
return true; return true;
} }
@@ -646,13 +640,11 @@ public:
QTextStream output(&buffer); QTextStream output(&buffer);
out = &output; out = &output;
*out << copyrightHeader *out << copyrightHeader << generatedHeader << "#include \"AST.h\"" << Qt::endl
<< generatedHeader << "#include \"MemoryPool.h\"" << Qt::endl
<< "#include \"AST.h\"" << endl << Qt::endl
<< "#include \"MemoryPool.h\"" << endl << "using namespace CPlusPlus;" << Qt::endl
<< endl << Qt::endl;
<< "using namespace CPlusPlus;" << endl
<< endl;
accept(ast); accept(ast);
@@ -688,18 +680,22 @@ protected:
const QByteArray memberName = QByteArray::fromRawData(id->chars(), id->size()); const QByteArray memberName = QByteArray::fromRawData(id->chars(), id->size());
if (member->type()->isIntegerType() && memberName.endsWith("_token")) { if (member->type()->isIntegerType() && memberName.endsWith("_token")) {
*out << " ast->" << memberName << " = " << memberName << ";" << endl; *out << " ast->" << memberName << " = " << memberName << ";" << Qt::endl;
} else if (PointerType *ptrTy = member->type()->asPointerType()) { } else if (PointerType *ptrTy = member->type()->asPointerType()) {
if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) { if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) {
QByteArray typeName = namedTy->name()->identifier()->chars(); QByteArray typeName = namedTy->name()->identifier()->chars();
if (typeName.endsWith("ListAST")) { if (typeName.endsWith("ListAST")) {
*out << " for (" << typeName << " *iter = " << memberName << ", **ast_iter = &ast->" << memberName << ";" << endl *out << " for (" << typeName << " *iter = " << memberName
<< " iter; iter = iter->next, ast_iter = &(*ast_iter)->next)" << endl << ", **ast_iter = &ast->" << memberName << ";" << Qt::endl
<< " *ast_iter = new (pool) " << typeName << "((iter->value) ? iter->value->clone(pool) : nullptr);" << endl; << " iter; iter = iter->next, ast_iter = &(*ast_iter)->next)"
<< Qt::endl
<< " *ast_iter = new (pool) " << typeName
<< "((iter->value) ? iter->value->clone(pool) : nullptr);" << Qt::endl;
} else if (typeName.endsWith("AST")) { } else if (typeName.endsWith("AST")) {
*out << " if (" << memberName << ")" << endl *out << " if (" << memberName << ")" << Qt::endl
<< " ast->" << memberName << " = " << memberName << "->clone(pool);" << endl; << " ast->" << memberName << " = " << memberName
<< "->clone(pool);" << Qt::endl;
} }
} }
} }
@@ -751,14 +747,15 @@ protected:
classMap.insert(className, ast); classMap.insert(className, ast);
*out << className.constData() << " *" << className.constData() << "::" << "clone(MemoryPool *pool) const" << endl *out << className.constData() << " *" << className.constData() << "::"
<< "{" << endl << "clone(MemoryPool *pool) const" << Qt::endl
<< " " << className.constData() << " *ast = new (pool) " << className.constData() << ";" << endl; << "{" << Qt::endl
<< " " << className.constData() << " *ast = new (pool) " << className.constData()
<< ";" << Qt::endl;
visitMembers(klass); visitMembers(klass);
*out << " return ast;" << endl *out << " return ast;" << Qt::endl << "}" << Qt::endl << Qt::endl;
<< "}" << endl << endl;
return false; return false;
} }
@@ -779,10 +776,7 @@ public:
buffer.open(openFlags); buffer.open(openFlags);
GenerateDumpers d(&buffer, unit); GenerateDumpers d(&buffer, unit);
d.out << copyrightHeader d.out << copyrightHeader << generatedHeader << Qt::endl;
<< generatedHeader
<< endl;
d.accept(unit->ast()); d.accept(unit->ast());
@@ -818,17 +812,18 @@ protected:
const QByteArray memberName = QByteArray::fromRawData(id->chars(), id->size()); const QByteArray memberName = QByteArray::fromRawData(id->chars(), id->size());
if (member->type()->isIntegerType() && memberName.endsWith("_token")) { if (member->type()->isIntegerType() && memberName.endsWith("_token")) {
out << " if (ast->" << memberName << ")" << endl; out << " if (ast->" << memberName << ")" << Qt::endl;
out << " terminal(ast->" << memberName << ", ast);" << endl; out << " terminal(ast->" << memberName << ", ast);" << Qt::endl;
} else if (PointerType *ptrTy = member->type()->asPointerType()) { } else if (PointerType *ptrTy = member->type()->asPointerType()) {
if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) { if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) {
QByteArray typeName = namedTy->name()->identifier()->chars(); QByteArray typeName = namedTy->name()->identifier()->chars();
if (typeName.endsWith("ListAST")) { if (typeName.endsWith("ListAST")) {
out << " for (" << typeName << " *iter = ast->" << memberName << "; iter; iter = iter->next)" << endl out << " for (" << typeName << " *iter = ast->" << memberName
<< " nonterminal(iter->value);" << endl; << "; iter; iter = iter->next)" << Qt::endl
<< " nonterminal(iter->value);" << Qt::endl;
} else if (typeName.endsWith("AST")) { } else if (typeName.endsWith("AST")) {
out << " nonterminal(ast->" << memberName << ");" << endl; out << " nonterminal(ast->" << memberName << ");" << Qt::endl;
} }
} }
} }
@@ -880,13 +875,12 @@ protected:
classMap.insert(className, ast); classMap.insert(className, ast);
out << "virtual bool visit(" << className.constData() << " *ast)" << endl out << "virtual bool visit(" << className.constData() << " *ast)" << Qt::endl
<< "{" << endl; << "{" << Qt::endl;
visitMembers(klass); visitMembers(klass);
out << " return false;" << endl out << " return false;" << Qt::endl << "}" << Qt::endl << Qt::endl;
<< "}" << endl << endl;
return false; return false;
} }
@@ -980,43 +974,42 @@ struct GenInfo
void generateFirstToken(QTextStream &os, const QString &className, const QStringList &fields) void generateFirstToken(QTextStream &os, const QString &className, const QStringList &fields)
{ {
os << "int " << className << "::firstToken() const" << endl << "{" << endl; os << "int " << className << "::firstToken() const" << Qt::endl << "{" << Qt::endl;
for (const QString &field : fields) { for (const QString &field : fields) {
os << " if (" << field << ")" << endl; os << " if (" << field << ")" << Qt::endl;
if (field.endsWith(QLatin1String("_token"))) { if (field.endsWith(QLatin1String("_token"))) {
os << " return " << field << ";" << endl; os << " return " << field << ";" << Qt::endl;
} else { } else {
os << " if (int candidate = " << field << "->firstToken())" << endl; os << " if (int candidate = " << field << "->firstToken())" << Qt::endl;
os << " return candidate;" << endl; os << " return candidate;" << Qt::endl;
} }
} }
os << " return 0;" << endl; os << " return 0;" << Qt::endl;
os << "}" << endl << endl; os << "}" << Qt::endl << Qt::endl;
} }
void generateLastToken(QTextStream &os, const QString &className, const QStringList &fields) void generateLastToken(QTextStream &os, const QString &className, const QStringList &fields)
{ {
os << "int "<< className << "::lastToken() const" << endl os << "int " << className << "::lastToken() const" << Qt::endl << "{" << Qt::endl;
<< "{" << endl;
for (int i = fields.size() - 1; i >= 0; --i) { for (int i = fields.size() - 1; i >= 0; --i) {
const QString field = fields.at(i); const QString field = fields.at(i);
os << " if (" << field << ")" << endl; os << " if (" << field << ")" << Qt::endl;
if (field.endsWith(QLatin1String("_token"))) { if (field.endsWith(QLatin1String("_token"))) {
os << " return " << field << " + 1;" << endl; os << " return " << field << " + 1;" << Qt::endl;
} else { } else {
os << " if (int candidate = " << field << "->lastToken())" << endl; os << " if (int candidate = " << field << "->lastToken())" << Qt::endl;
os << " return candidate;" << endl; os << " return candidate;" << Qt::endl;
} }
} }
os << " return 1;" << endl; os << " return 1;" << Qt::endl;
os << "}" << endl << endl; os << "}" << Qt::endl << Qt::endl;
} }
void generateAST_cpp(const Snapshot &snapshot, const QDir &cplusplusDir) void generateAST_cpp(const Snapshot &snapshot, const QDir &cplusplusDir)
@@ -1173,18 +1166,18 @@ void generateAST_cpp(const Snapshot &snapshot, const QDir &cplusplusDir)
for (StringClassSpecifierASTMapConstIt it = classesNeedingFirstToken.constBegin(); it != cfend; ++it) { for (StringClassSpecifierASTMapConstIt it = classesNeedingFirstToken.constBegin(); it != cfend; ++it) {
const QString &className = it.key(); const QString &className = it.key();
const QStringList fields = collectFieldNames(it.value(), true); const QStringList fields = collectFieldNames(it.value(), true);
os << "/** \\generated */" << endl; os << "/** \\generated */" << Qt::endl;
generateFirstToken(os, className, fields); generateFirstToken(os, className, fields);
if (ClassSpecifierAST *classAST = classesNeedingLastToken.value(className, nullptr)) { if (ClassSpecifierAST *classAST = classesNeedingLastToken.value(className, nullptr)) {
const QStringList fields = collectFieldNames(classAST, true); const QStringList fields = collectFieldNames(classAST, true);
os << "/** \\generated */" << endl; os << "/** \\generated */" << Qt::endl;
generateLastToken(os, className, fields); generateLastToken(os, className, fields);
classesNeedingLastToken.remove(className); classesNeedingLastToken.remove(className);
} }
} }
const StringClassSpecifierASTMapConstIt clend = classesNeedingLastToken.constEnd(); const StringClassSpecifierASTMapConstIt clend = classesNeedingLastToken.constEnd();
for (StringClassSpecifierASTMapConstIt it = classesNeedingLastToken.constBegin(); it != clend; ++it) { for (StringClassSpecifierASTMapConstIt it = classesNeedingLastToken.constBegin(); it != clend; ++it) {
os << "/** \\generated */" << endl; os << "/** \\generated */" << Qt::endl;
generateLastToken(os, it.key(), collectFieldNames(it.value(), true)); generateLastToken(os, it.key(), collectFieldNames(it.value(), true));
} }
tc.setPosition(documentEnd); tc.setPosition(documentEnd);
@@ -1493,26 +1486,23 @@ void generateASTPatternBuilder_h(const QDir &cplusplusDir)
buffer.open(openFlags); buffer.open(openFlags);
QTextStream out(&buffer); QTextStream out(&buffer);
out out << copyrightHeader << generatedHeader << "#pragma once" << Qt::endl
<< copyrightHeader << Qt::endl
<< generatedHeader << "#include \"CPlusPlusForwardDeclarations.h\"" << Qt::endl
<< "#pragma once" << endl << "#include \"AST.h\"" << Qt::endl
<< endl << "#include \"MemoryPool.h\"" << Qt::endl
<< "#include \"CPlusPlusForwardDeclarations.h\"" << endl << Qt::endl
<< "#include \"AST.h\"" << endl << "namespace CPlusPlus {" << Qt::endl
<< "#include \"MemoryPool.h\"" << endl << Qt::endl
<< endl << "class CPLUSPLUS_EXPORT ASTPatternBuilder" << Qt::endl
<< "namespace CPlusPlus {" << endl << "{" << Qt::endl
<< endl << " MemoryPool pool;" << Qt::endl
<< "class CPLUSPLUS_EXPORT ASTPatternBuilder" << endl << Qt::endl
<< "{" << endl << "public:" << Qt::endl
<< " MemoryPool pool;" << endl << " ASTPatternBuilder() {}" << Qt::endl
<< endl << Qt::endl
<< "public:" << endl << " void reset() { pool.reset(); }" << Qt::endl
<< " ASTPatternBuilder() {}" << endl << Qt::endl;
<< endl
<< " void reset() { pool.reset(); }" << endl
<< endl;
Control *control = AST_h_document->control(); Control *control = AST_h_document->control();
QSet<QString> classesSet; QSet<QString> classesSet;
@@ -1568,19 +1558,14 @@ void generateASTPatternBuilder_h(const QDir &cplusplusDir)
} }
} }
out out << ")" << Qt::endl
<< ")" << endl << " {" << Qt::endl
<< " {" << endl << " " << className << " *ast = new (&pool) " << className << ';' << Qt::endl;
<< " " << className << " *ast = new (&pool) " << className << ';' << endl;
for (const StringPair &p : qAsConst(args)) for (const StringPair &p : qAsConst(args))
out << " ast->" << p.second << " = " << p.second << ';' << endl; out << " ast->" << p.second << " = " << p.second << ';' << Qt::endl;
out out << " return ast;" << Qt::endl << " }" << Qt::endl << Qt::endl;
<< " return ast;" << endl
<< " }" << endl
<< endl;
} }
QStringList classesList = Utils::toList(classesSet); QStringList classesList = Utils::toList(classesSet);
@@ -1588,22 +1573,18 @@ void generateASTPatternBuilder_h(const QDir &cplusplusDir)
for (const QString &className : qAsConst(classesList)) { for (const QString &className : qAsConst(classesList)) {
const QString methodName = className.left(className.length() - 3); const QString methodName = className.left(className.length() - 3);
const QString elementName = className.left(className.length() - 7) + QLatin1String("AST"); const QString elementName = className.left(className.length() - 7) + QLatin1String("AST");
out out << " " << className << " *" << methodName << "(" << elementName << " *value, "
<< " " << className << " *" << methodName << "(" << className << " *next = nullptr)" << Qt::endl
<< elementName << " *value, " << className << " *next = nullptr)" << endl << " {" << Qt::endl
<< " {" << endl << " " << className << " *list = new (&pool) " << className << ";" << Qt::endl
<< " " << className << " *list = new (&pool) " << className << ";" << endl << " list->next = next;" << Qt::endl
<< " list->next = next;" << endl << " list->value = value;" << Qt::endl
<< " list->value = value;" << endl << " return list;" << Qt::endl
<< " return list;" << endl << " }" << Qt::endl
<< " }" << endl << Qt::endl;
<< endl;
} }
out out << "};" << Qt::endl << Qt::endl << "} // end of namespace CPlusPlus" << Qt::endl;
<< "};" << endl
<< endl
<< "} // end of namespace CPlusPlus" << endl;
closeBufferAndWriteIfChanged(buffer, fileInfo.absoluteFilePath()); closeBufferAndWriteIfChanged(buffer, fileInfo.absoluteFilePath());
} }