From d444bbf110e83c72d0657203896ad3c8a4cb5107 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Wed, 2 Jul 2014 17:43:16 +0100 Subject: glgen: Added support for parsing the new xml spec. The .spec file is no longer updated thus support for gl 4.4 is impossible without an update to parse the new xml spec. The legacy parser can be used with the -l (--legacy) switch. Task-number: QTBUG-33671 Task-number: QTBUG-40090 Change-Id: I83d9380842a16e925f6c07331ee35fe035f6baa9 Reviewed-by: Sean Harmer --- util/glgen/glgen.pro | 5 +- util/glgen/legacyspecparser.cpp | 313 ++++++++++++++++++++++++++++ util/glgen/legacyspecparser.h | 78 +++++++ util/glgen/main.cpp | 33 ++- util/glgen/specparser.cpp | 312 ---------------------------- util/glgen/specparser.h | 90 ++++++-- util/glgen/xmlspecparser.cpp | 440 ++++++++++++++++++++++++++++++++++++++++ util/glgen/xmlspecparser.h | 83 ++++++++ 8 files changed, 1014 insertions(+), 340 deletions(-) create mode 100644 util/glgen/legacyspecparser.cpp create mode 100644 util/glgen/legacyspecparser.h delete mode 100644 util/glgen/specparser.cpp create mode 100644 util/glgen/xmlspecparser.cpp create mode 100644 util/glgen/xmlspecparser.h diff --git a/util/glgen/glgen.pro b/util/glgen/glgen.pro index 9208ba9e8e..11018e942d 100644 --- a/util/glgen/glgen.pro +++ b/util/glgen/glgen.pro @@ -9,11 +9,14 @@ TEMPLATE = app TARGET = glgen SOURCES += main.cpp \ - specparser.cpp \ + xmlspecparser.cpp \ + legacyspecparser.cpp \ codegenerator.cpp HEADERS += \ specparser.h \ + xmlspecparser.h \ + legacyspecparser.h \ codegenerator.h OTHER_FILES += \ diff --git a/util/glgen/legacyspecparser.cpp b/util/glgen/legacyspecparser.cpp new file mode 100644 index 0000000000..84dcd0b200 --- /dev/null +++ b/util/glgen/legacyspecparser.cpp @@ -0,0 +1,313 @@ +/*************************************************************************** +** +** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the utilities of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "legacyspecparser.h" + +#include +#include +#include +#include +#include + +#ifdef SPECPARSER_DEBUG +#define qLegacySpecParserDebug qDebug +#else +#define qLegacySpecParserDebug QT_NO_QDEBUG_MACRO +#endif + +bool LegacySpecParser::parse() +{ + // Get the mapping form generic types to specific types suitable for use in C-headers + if (!parseTypeMap()) + return false; + + // Open up a stream on the actual OpenGL function spec file + QFile file(specFileName()); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Failed to open spec file:" << specFileName() << "Aborting"; + return false; + } + + QTextStream stream(&file); + + // Extract the info that we need + parseFunctions(stream); + return true; +} + +bool LegacySpecParser::parseTypeMap() +{ + QFile file(typeMapFileName()); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Failed to open type file:" << typeMapFileName() << "Aborting"; + return false; + } + + QTextStream stream(&file); + + static QRegExp typeMapRegExp("([^,]+)\\W+([^,]+)"); + + while (!stream.atEnd()) { + QString line = stream.readLine(); + + if (line.startsWith(QStringLiteral("#"))) + continue; + + if (typeMapRegExp.indexIn(line) != -1) { + QString key = typeMapRegExp.cap(1).simplified(); + QString value = typeMapRegExp.cap(2).simplified(); + + // Special case for void + if (value == QStringLiteral("*")) + value = QStringLiteral("void"); + + m_typeMap.insert(key, value); + qLegacySpecParserDebug() << "Found type mapping from" << key << "=>" << value; + } + } + + return true; +} + +void LegacySpecParser::parseEnums() +{ +} + +void LegacySpecParser::parseFunctions(QTextStream &stream) +{ + static QRegExp functionRegExp("^(\\w+)\\(.*\\)"); + static QRegExp returnRegExp("^\\treturn\\s+(\\S+)"); + static QRegExp argumentRegExp("param\\s+(\\S+)\\s+(\\S+) (\\S+) (\\S+)"); + static QRegExp versionRegExp("^\\tversion\\s+(\\S+)"); + static QRegExp deprecatedRegExp("^\\tdeprecated\\s+(\\S+)"); + static QRegExp categoryRegExp("^\\tcategory\\s+(\\S+)"); + static QRegExp categoryVersionRegExp("VERSION_(\\d)_(\\d)"); + static QRegExp extToCoreVersionRegExp("passthru:\\s/\\*\\sOpenGL\\s(\\d)\\.(\\d)\\s.*\\sextensions:"); + static QRegExp extToCoreRegExp("passthru:\\s/\\*\\s(ARB_\\S*)\\s.*\\*/"); + + Function currentFunction; + VersionProfile currentVersionProfile; + QString currentCategory; + bool haveVersionInfo = false; + bool acceptCurrentFunctionInCore = false; + bool acceptCurrentFunctionInExtension = false; + + QHash extensionsNowInCore; + Version extToCoreCurrentVersion; + int functionCount = 0; + + QSet versions; + + while (!stream.atEnd()) { + QString line = stream.readLine(); + if (line.startsWith("#")) + continue; + + if (functionRegExp.indexIn(line) != -1) { + + if (!currentFunction.name.isEmpty()) { + + // NB - Special handling! + // Versions 4.2 and 4.3 (and probably newer) add functionality by + // subsuming extensions such as ARB_texture_storage. However, some extensions + // also include functions to interact with the EXT_direct_state_access + // extension. These functions should be added to the DSA extension rather + // than the core functionality. The core will already contain non-DSA + // versions of these functions. + if (acceptCurrentFunctionInCore && currentFunction.name.endsWith(QStringLiteral("EXT"))) { + acceptCurrentFunctionInCore = false; + acceptCurrentFunctionInExtension = true; + currentCategory = QStringLiteral("EXT_direct_state_access"); + } + + // Finish off previous function (if any) by inserting it into the core + // functionality or extension functionality (or both) + if (acceptCurrentFunctionInCore) { + m_functions.insert(currentVersionProfile, currentFunction); + versions.insert(currentVersionProfile.version); + } + + if (acceptCurrentFunctionInExtension) { + FunctionProfile fp; + fp.profile = currentVersionProfile.profile; + fp.function = currentFunction; + m_extensionFunctions.insert(currentCategory, fp); + } + } + + // Start a new function + ++functionCount; + haveVersionInfo = false; + acceptCurrentFunctionInCore = true; + acceptCurrentFunctionInExtension = false; + currentCategory = QString(); + currentFunction = Function(); + + // We assume a core function unless we find a deprecated flag (see below) + currentVersionProfile = VersionProfile(); + currentVersionProfile.profile = VersionProfile::CoreProfile; + + // Extract the function name + QString functionName = functionRegExp.cap(1); + currentFunction.name = functionName; + qLegacySpecParserDebug() << "Found function:" << functionName; + + } else if (argumentRegExp.indexIn(line) != -1) { + // Extract info about this function argument + Argument arg; + arg.name = argumentRegExp.cap(1); + + QString type = argumentRegExp.cap(2); // Lookup in type map + arg.type = m_typeMap.value(type); + + QString direction = argumentRegExp.cap(3); + if (direction == QStringLiteral("in")) { + arg.direction = Argument::In; + } else if (direction == QStringLiteral("out")) { + arg.direction = Argument::Out; + } else { + qWarning() << "Invalid argument direction found:" << direction; + acceptCurrentFunctionInCore = false; + } + + QString mode = argumentRegExp.cap(4); + if (mode == QStringLiteral("value")) { + arg.mode = Argument::Value; + } else if (mode == QStringLiteral("array")) { + arg.mode = Argument::Array; + } else if (mode == QStringLiteral("reference")) { + arg.mode = Argument::Reference; + } else { + qWarning() << "Invalid argument mode found:" << mode; + acceptCurrentFunctionInCore = false; + } + + qLegacySpecParserDebug() << " argument:" << arg.type << arg.name; + currentFunction.arguments.append(arg); + + } else if (returnRegExp.indexIn(line) != -1) { + // Lookup the return type from the typemap + QString returnTypeKey = returnRegExp.cap(1).simplified(); + if (!m_typeMap.contains(returnTypeKey)) { + qWarning() << "Unknown return type found:" << returnTypeKey; + acceptCurrentFunctionInCore = false; + } + QString returnType = m_typeMap.value(returnTypeKey); + qLegacySpecParserDebug() << " return type:" << returnType; + currentFunction.returnType = returnType; + + } else if (versionRegExp.indexIn(line) != -1 && !haveVersionInfo) { // Only use version line if no other source + // Extract the OpenGL version in which this function was introduced + QString version = versionRegExp.cap(1); + qLegacySpecParserDebug() << " version:" << version; + QStringList parts = version.split(QLatin1Char('.')); + if (parts.size() != 2) { + qWarning() << "Found invalid version number"; + continue; + } + int majorVersion = parts.first().toInt(); + int minorVersion = parts.last().toInt(); + Version v; + v.major = majorVersion; + v.minor = minorVersion; + currentVersionProfile.version = v; + + } else if (deprecatedRegExp.indexIn(line) != -1) { + // Extract the OpenGL version in which this function was deprecated. + // If it is OpenGL 3.1 then it must be a compatibility profile function + QString deprecatedVersion = deprecatedRegExp.cap(1).simplified(); + if (deprecatedVersion == QStringLiteral("3.1") && !inDeprecationException(currentFunction.name)) + currentVersionProfile.profile = VersionProfile::CompatibilityProfile; + + } else if (categoryRegExp.indexIn(line) != -1) { + // Extract the category for this function + QString category = categoryRegExp.cap(1).simplified(); + qLegacySpecParserDebug() << " category:" << category; + + if (categoryVersionRegExp.indexIn(category) != -1) { + // Use the version info in the category in preference to the version + // entry as this is more applicable and consistent + int majorVersion = categoryVersionRegExp.cap(1).toInt(); + int minorVersion = categoryVersionRegExp.cap(2).toInt(); + + Version v; + v.major = majorVersion; + v.minor = minorVersion; + currentVersionProfile.version = v; + haveVersionInfo = true; + + } else { + // Make a note of the extension name and tag this function as being part of an extension + qLegacySpecParserDebug() << "Found category =" << category; + currentCategory = category; + acceptCurrentFunctionInExtension = true; + + // See if this category (extension) is in our set of extensions that + // have now been folded into the core feature set + if (extensionsNowInCore.contains(category)) { + currentVersionProfile.version = extensionsNowInCore.value(category); + haveVersionInfo = true; + } else { + acceptCurrentFunctionInCore = false; + } + } + + } else if (extToCoreVersionRegExp.indexIn(line) != -1) { + qLegacySpecParserDebug() << line; + int majorVersion = extToCoreVersionRegExp.cap(1).toInt(); + int minorVersion = extToCoreVersionRegExp.cap(2).toInt(); + extToCoreCurrentVersion.major = majorVersion; + extToCoreCurrentVersion.minor = minorVersion; + + } else if (extToCoreRegExp.indexIn(line) != -1) { + QString extension = extToCoreRegExp.cap(1); + extensionsNowInCore.insert(extension, extToCoreCurrentVersion); + } + } + + m_versions = versions.toList(); + qSort(m_versions); +} + +bool LegacySpecParser::inDeprecationException(const QString &functionName) const +{ + return (functionName == QStringLiteral("TexImage3D")); +} diff --git a/util/glgen/legacyspecparser.h b/util/glgen/legacyspecparser.h new file mode 100644 index 0000000000..63d9a9f170 --- /dev/null +++ b/util/glgen/legacyspecparser.h @@ -0,0 +1,78 @@ +/*************************************************************************** +** +** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the utilities of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LEGACYSPECPARSER_H +#define LEGACYSPECPARSER_H + +#include "specparser.h" + +#include +#include + +class QTextStream; + +class LegacySpecParser : public SpecParser +{ +public: + virtual QList versions() const {return m_versions;} + + virtual bool parse(); + +protected: + const QMultiHash &versionFunctions() const { return m_functions; } + const QMultiMap &extensionFunctions() const { return m_extensionFunctions; } + +private: + QMap m_typeMap; + QMultiHash m_functions; + + QList m_versions; + + // Extension support + QMultiMap m_extensionFunctions; + + bool parseTypeMap(); + void parseEnums(); + void parseFunctions(QTextStream &stream); + bool inDeprecationException(const QString &functionName) const; +}; + +#endif // LEGACYSPECPARSER_H diff --git a/util/glgen/main.cpp b/util/glgen/main.cpp index 15c311caf3..41d97a6c85 100644 --- a/util/glgen/main.cpp +++ b/util/glgen/main.cpp @@ -40,22 +40,39 @@ ****************************************************************************/ #include "codegenerator.h" -#include "specparser.h" +#include "legacyspecparser.h" +#include "xmlspecparser.h" + +#include int main(int argc, char *argv[]) { - Q_UNUSED(argc); - Q_UNUSED(argv); + QCoreApplication app(argc, argv); + QCommandLineParser cmdParser; + + // flag whether to use legacy or not + QCommandLineOption legacyOption(QStringList() << "l" << "legacy", "Use legacy parser."); + cmdParser.addOption(legacyOption); + cmdParser.process(app); + + SpecParser *parser; + + if (cmdParser.isSet(legacyOption)) { + parser = new LegacySpecParser(); + parser->setTypeMapFileName(QStringLiteral("gl.tm")); + parser->setSpecFileName(QStringLiteral("gl.spec")); + } else { + parser = new XmlSpecParser(); + parser->setSpecFileName(QStringLiteral("gl.xml")); + } - SpecParser parser; - parser.setTypeMapFileName(QStringLiteral("gl.tm")); - parser.setSpecFileName(QStringLiteral("gl.spec")); - parser.parse(); + parser->parse(); CodeGenerator generator; - generator.setParser(&parser); + generator.setParser(parser); generator.generateCoreClasses(QStringLiteral("qopenglversionfunctions")); generator.generateExtensionClasses(QStringLiteral("qopenglextensions")); + delete parser; return 0; } diff --git a/util/glgen/specparser.cpp b/util/glgen/specparser.cpp deleted file mode 100644 index 91a906bca9..0000000000 --- a/util/glgen/specparser.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/*************************************************************************** -** -** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB) -** Contact: http://www.qt-project.org/legal -** -** This file is part of the utilities of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "specparser.h" - -#include -#include -#include -#include -#include - -#ifdef SPECPARSER_DEBUG -#define qSpecParserDebug qDebug -#else -#define qSpecParserDebug QT_NO_QDEBUG_MACRO -#endif - -SpecParser::SpecParser() -{ -} - -void SpecParser::parse() -{ - // Get the mapping form generic types to specific types suitable for use in C-headers - if (!parseTypeMap()) - return; - - // Open up a stream on the actual OpenGL function spec file - QFile file(m_specFileName); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << "Failed to open spec file:" << m_specFileName << "Aborting"; - return; - } - - QTextStream stream(&file); - - // Extract the info that we need - parseFunctions(stream); -} - -bool SpecParser::parseTypeMap() -{ - QFile file(m_typeMapFileName); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qWarning() << "Failed to open spec file:" << m_specFileName << "Aborting"; - return false; - } - - QTextStream stream(&file); - - static QRegExp typeMapRegExp("([^,]+)\\W+([^,]+)"); - - while (!stream.atEnd()) { - QString line = stream.readLine(); - - if (line.startsWith(QStringLiteral("#"))) - continue; - - if (typeMapRegExp.indexIn(line) != -1) { - QString key = typeMapRegExp.cap(1).simplified(); - QString value = typeMapRegExp.cap(2).simplified(); - - // Special case for void - if (value == QStringLiteral("*")) - value = QStringLiteral("void"); - - m_typeMap.insert(key, value); - qSpecParserDebug() << "Found type mapping from" << key << "=>" << value; - } - } - - return true; -} - -void SpecParser::parseEnums() -{ -} - -void SpecParser::parseFunctions(QTextStream &stream) -{ - static QRegExp functionRegExp("^(\\w+)\\(.*\\)"); - static QRegExp returnRegExp("^\\treturn\\s+(\\S+)"); - static QRegExp argumentRegExp("param\\s+(\\S+)\\s+(\\S+) (\\S+) (\\S+)"); - static QRegExp versionRegExp("^\\tversion\\s+(\\S+)"); - static QRegExp deprecatedRegExp("^\\tdeprecated\\s+(\\S+)"); - static QRegExp categoryRegExp("^\\tcategory\\s+(\\S+)"); - static QRegExp categoryVersionRegExp("VERSION_(\\d)_(\\d)"); - static QRegExp extToCoreVersionRegExp("passthru:\\s/\\*\\sOpenGL\\s(\\d)\\.(\\d)\\s.*\\sextensions:"); - static QRegExp extToCoreRegExp("passthru:\\s/\\*\\s(ARB_\\S*)\\s.*\\*/"); - - Function currentFunction; - VersionProfile currentVersionProfile; - QString currentCategory; - bool haveVersionInfo = false; - bool acceptCurrentFunctionInCore = false; - bool acceptCurrentFunctionInExtension = false; - - QHash extensionsNowInCore; - Version extToCoreCurrentVersion; - int functionCount = 0; - - QSet versions; - - while (!stream.atEnd()) { - QString line = stream.readLine(); - if (line.startsWith("#")) - continue; - - if (functionRegExp.indexIn(line) != -1) { - - if (!currentFunction.name.isEmpty()) { - - // NB - Special handling! - // Versions 4.2 and 4.3 (and probably newer) add functionality by - // subsuming extensions such as ARB_texture_storage. However, some extensions - // also include functions to interact with the EXT_direct_state_access - // extension. These functions should be added to the DSA extension rather - // than the core functionality. The core will already contain non-DSA - // versions of these functions. - if (acceptCurrentFunctionInCore && currentFunction.name.endsWith(QStringLiteral("EXT"))) { - acceptCurrentFunctionInCore = false; - acceptCurrentFunctionInExtension = true; - currentCategory = QStringLiteral("EXT_direct_state_access"); - } - - // Finish off previous function (if any) by inserting it into the core - // functionality or extension functionality (or both) - if (acceptCurrentFunctionInCore) { - m_functions.insert(currentVersionProfile, currentFunction); - versions.insert(currentVersionProfile.version); - } - - if (acceptCurrentFunctionInExtension) - m_extensionFunctions.insert(currentCategory, currentFunction); - } - - // Start a new function - ++functionCount; - haveVersionInfo = false; - acceptCurrentFunctionInCore = true; - acceptCurrentFunctionInExtension = false; - currentCategory = QString(); - currentFunction = Function(); - - // We assume a core function unless we find a deprecated flag (see below) - currentVersionProfile = VersionProfile(); - currentVersionProfile.profile = VersionProfile::CoreProfile; - - // Extract the function name - QString functionName = functionRegExp.cap(1); - currentFunction.name = functionName; - qSpecParserDebug() << "Found function:" << functionName; - - } else if (argumentRegExp.indexIn(line) != -1) { - // Extract info about this function argument - Argument arg; - arg.name = argumentRegExp.cap(1); - - QString type = argumentRegExp.cap(2); // Lookup in type map - arg.type = m_typeMap.value(type); - - QString direction = argumentRegExp.cap(3); - if (direction == QStringLiteral("in")) { - arg.direction = Argument::In; - } else if (direction == QStringLiteral("out")) { - arg.direction = Argument::Out; - } else { - qWarning() << "Invalid argument direction found:" << direction; - acceptCurrentFunctionInCore = false; - } - - QString mode = argumentRegExp.cap(4); - if (mode == QStringLiteral("value")) { - arg.mode = Argument::Value; - } else if (mode == QStringLiteral("array")) { - arg.mode = Argument::Array; - } else if (mode == QStringLiteral("reference")) { - arg.mode = Argument::Reference; - } else { - qWarning() << "Invalid argument mode found:" << mode; - acceptCurrentFunctionInCore = false; - } - - qSpecParserDebug() << " argument:" << arg.type << arg.name; - currentFunction.arguments.append(arg); - - } else if (returnRegExp.indexIn(line) != -1) { - // Lookup the return type from the typemap - QString returnTypeKey = returnRegExp.cap(1).simplified(); - if (!m_typeMap.contains(returnTypeKey)) { - qWarning() << "Unknown return type found:" << returnTypeKey; - acceptCurrentFunctionInCore = false; - } - QString returnType = m_typeMap.value(returnTypeKey); - qSpecParserDebug() << " return type:" << returnType; - currentFunction.returnType = returnType; - - } else if (versionRegExp.indexIn(line) != -1 && !haveVersionInfo) { // Only use version line if no other source - // Extract the OpenGL version in which this function was introduced - QString version = versionRegExp.cap(1); - qSpecParserDebug() << " version:" << version; - QStringList parts = version.split(QLatin1Char('.')); - if (parts.size() != 2) { - qWarning() << "Found invalid version number"; - continue; - } - int majorVersion = parts.first().toInt(); - int minorVersion = parts.last().toInt(); - Version v; - v.major = majorVersion; - v.minor = minorVersion; - currentVersionProfile.version = v; - - } else if (deprecatedRegExp.indexIn(line) != -1) { - // Extract the OpenGL version in which this function was deprecated. - // If it is OpenGL 3.1 then it must be a compatibility profile function - QString deprecatedVersion = deprecatedRegExp.cap(1).simplified(); - if (deprecatedVersion == QStringLiteral("3.1") && !inDeprecationException(currentFunction.name)) - currentVersionProfile.profile = VersionProfile::CompatibilityProfile; - - } else if (categoryRegExp.indexIn(line) != -1) { - // Extract the category for this function - QString category = categoryRegExp.cap(1).simplified(); - qSpecParserDebug() << " category:" << category; - - if (categoryVersionRegExp.indexIn(category) != -1) { - // Use the version info in the category in preference to the version - // entry as this is more applicable and consistent - int majorVersion = categoryVersionRegExp.cap(1).toInt(); - int minorVersion = categoryVersionRegExp.cap(2).toInt(); - - Version v; - v.major = majorVersion; - v.minor = minorVersion; - currentVersionProfile.version = v; - haveVersionInfo = true; - - } else { - // Make a note of the extension name and tag this function as being part of an extension - qSpecParserDebug() << "Found category =" << category; - currentCategory = category; - acceptCurrentFunctionInExtension = true; - - // See if this category (extension) is in our set of extensions that - // have now been folded into the core feature set - if (extensionsNowInCore.contains(category)) { - currentVersionProfile.version = extensionsNowInCore.value(category); - haveVersionInfo = true; - } else { - acceptCurrentFunctionInCore = false; - } - } - - } else if (extToCoreVersionRegExp.indexIn(line) != -1) { - qSpecParserDebug() << line; - int majorVersion = extToCoreVersionRegExp.cap(1).toInt(); - int minorVersion = extToCoreVersionRegExp.cap(2).toInt(); - extToCoreCurrentVersion.major = majorVersion; - extToCoreCurrentVersion.minor = minorVersion; - - } else if (extToCoreRegExp.indexIn(line) != -1) { - QString extension = extToCoreRegExp.cap(1); - extensionsNowInCore.insert(extension, extToCoreCurrentVersion); - } - } - - m_versions = versions.toList(); - qSort(m_versions); -} - -bool SpecParser::inDeprecationException(const QString &functionName) const -{ - return (functionName == QStringLiteral("TexImage3D")); -} diff --git a/util/glgen/specparser.h b/util/glgen/specparser.h index 19357841ca..0ba36ef8d8 100644 --- a/util/glgen/specparser.h +++ b/util/glgen/specparser.h @@ -46,6 +46,7 @@ #include class QTextStream; +class QXmlStreamReader; struct Version { int major; @@ -57,6 +58,11 @@ inline bool operator == (const Version &lhs, const Version &rhs) return (lhs.major == rhs.major && lhs.minor == rhs.minor); } +inline bool operator != (const Version &lhs, const Version &rhs) +{ + return !(lhs == rhs); +} + inline bool operator < (const Version &lhs, const Version &rhs) { if (lhs.major != rhs.major) @@ -73,6 +79,17 @@ inline bool operator > (const Version &lhs, const Version &rhs) return (lhs.minor > rhs.minor); } +inline bool operator >= (const Version &lhs, const Version &rhs) +{ + return !(lhs < rhs); +} + + +inline bool operator <= (const Version &lhs, const Version &rhs) +{ + return !(lhs > rhs); +} + inline uint qHash(const Version &v) { return qHash(v.major * 100 + v.minor * 10); @@ -102,6 +119,11 @@ inline bool operator == (const VersionProfile &lhs, const VersionProfile &rhs) return lhs.version == rhs.version; } +inline bool operator != (const VersionProfile &lhs, const VersionProfile &rhs) +{ + return !(lhs == rhs); +} + inline bool operator < (const VersionProfile &lhs, const VersionProfile &rhs) { if (lhs.profile != rhs.profile) @@ -140,13 +162,47 @@ struct Function QList arguments; }; +inline bool operator== (const Argument &lhs, const Argument &rhs) +{ + if ((lhs.type != rhs.type) || (lhs.name != rhs.name) || (lhs.direction != rhs.direction)) { + return false; + } + + return (lhs.mode != rhs.mode); +} + +inline bool operator!= (const Argument &lhs, const Argument &rhs) +{ + return !(lhs == rhs); +} + +inline bool operator== (const Function &lhs, const Function &rhs) +{ + if ((lhs.returnType != rhs.returnType) || (lhs.name != rhs.name)) { + return false; + } + + return (lhs.arguments == rhs.arguments); +} + +inline bool operator!= (const Function &lhs, const Function &rhs) +{ + return !(lhs == rhs); +} + typedef QList FunctionList; typedef QMap FunctionCollection; +struct FunctionProfile +{ + VersionProfile::OpenGLProfile profile; + Function function; +}; + class SpecParser { public: - explicit SpecParser(); + virtual ~SpecParser() {} QString specFileName() const { @@ -158,22 +214,28 @@ public: return m_typeMapFileName; } - QList versions() const {return m_versions;} - QList versionProfiles() const {return m_functions.uniqueKeys();} + virtual QList versions() const = 0; + + QList versionProfiles() const {return versionFunctions().uniqueKeys();} QList functionsForVersion(const VersionProfile &v) const { - return m_functions.values(v); + return versionFunctions().values(v); } QStringList extensions() const { - return QStringList(m_extensionFunctions.uniqueKeys()); + return QStringList(extensionFunctions().uniqueKeys()); } QList functionsForExtension(const QString &extension) { - return m_extensionFunctions.values(extension); + QList func; + + Q_FOREACH (const FunctionProfile &f, extensionFunctions().values(extension)) + func.append(f.function); + + return func; } void setSpecFileName(QString arg) @@ -186,25 +248,15 @@ public: m_typeMapFileName = arg; } - void parse(); + virtual bool parse() = 0; protected: - bool parseTypeMap(); - void parseEnums(); - void parseFunctions(QTextStream &stream); - bool inDeprecationException(const QString &functionName) const; + virtual const QMultiHash &versionFunctions() const = 0; + virtual const QMultiMap &extensionFunctions() const = 0; private: QString m_specFileName; QString m_typeMapFileName; - - QMap m_typeMap; - QMultiMap m_functions; - - QList m_versions; - - // Extension support - QMultiMap m_extensionFunctions; }; #endif // SPECPARSER_H diff --git a/util/glgen/xmlspecparser.cpp b/util/glgen/xmlspecparser.cpp new file mode 100644 index 0000000000..c2be6d292d --- /dev/null +++ b/util/glgen/xmlspecparser.cpp @@ -0,0 +1,440 @@ +/*************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the utilities of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "xmlspecparser.h" + +#include +#include +#include +#include +#include +#include + +#ifdef SPECPARSER_DEBUG +#define qXmlSpecParserDebug qDebug +#else +#define qXmlSpecParserDebug QT_NO_QDEBUG_MACRO +#endif + +bool XmlSpecParser::parse() +{ + // Open up a stream on the actual OpenGL function spec file + QFile file(specFileName()); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Failed to open spec file:" << specFileName() << "Aborting"; + return false; + } + + QXmlStreamReader stream(&file); + + // Extract the info that we need + parseFunctions(stream); + return true; +} + +void XmlSpecParser::parseParam(QXmlStreamReader &stream, Function &func) +{ + Argument arg; + arg.type = QString(); + + while (!stream.isEndDocument()) { + stream.readNext(); + + if (stream.isStartElement()) { + QString tag = stream.name().toString(); + + if (tag == "ptype") { + if (stream.readNext() == QXmlStreamReader::Characters) + arg.type.append(stream.text().toString()); + } + + else if (tag == "name") { + if (stream.readNext() == QXmlStreamReader::Characters) + arg.name = stream.text().toString().trimmed(); + } + } else if (stream.isCharacters()) { + arg.type.append(stream.text().toString()); + } else if (stream.isEndElement()) { + QString tag = stream.name().toString(); + + if (tag == "param") { + // compatibility with old spec + QRegularExpression typeRegExp("(const )?(.+)(? funcs = m_extensionFunctions.values("GL_ARB_imaging"); + + VersionProfile vp; + vp.version = versionThreshold; + + Q_FOREACH (const FunctionProfile& fp, funcs) { + vp.profile = fp.profile; + m_functions.insert(vp, fp.function); + } + + // now we will prune any duplicates + QSet funcset; + + Q_FOREACH (const Version& v, m_versions) { + // check compatibility first + VersionProfile vp; + vp.version = v; + + vp.profile = VersionProfile::CompatibilityProfile; + + Q_FOREACH (const Function& f, m_functions.values(vp)) { + // remove duplicate + if (funcset.contains(f.name)) + m_functions.remove(vp, f); + + funcset.insert(f.name); + } + + vp.profile = VersionProfile::CoreProfile; + + Q_FOREACH (const Function& f, m_functions.values(vp)) { + + // remove duplicate + if (funcset.contains(f.name)) + m_functions.remove(vp, f); + + funcset.insert(f.name); + } + } +} diff --git a/util/glgen/xmlspecparser.h b/util/glgen/xmlspecparser.h new file mode 100644 index 0000000000..3049e911cc --- /dev/null +++ b/util/glgen/xmlspecparser.h @@ -0,0 +1,83 @@ +/*************************************************************************** +** +** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB) +** Contact: http://www.qt-project.org/legal +** +** This file is part of the utilities of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XMLSPECPARSER_H +#define XMLSPECPARSER_H + +#include "specparser.h" + +#include +#include + +class QXmlStreamReader; + +class XmlSpecParser : public SpecParser +{ +public: + virtual QList versions() const { return m_versions; } + + virtual bool parse(); + +protected: + const QMultiHash &versionFunctions() const { return m_functions; } + const QMultiMap &extensionFunctions() const { return m_extensionFunctions; } + +private: + void parseFunctions(QXmlStreamReader &stream); + void parseCommands(QXmlStreamReader &stream); + void parseCommand(QXmlStreamReader &stream); + void parseParam(QXmlStreamReader &stream, Function &func); + void parseFeature(QXmlStreamReader &stream); + void parseExtension(QXmlStreamReader &stream); + void parseRequire(QXmlStreamReader &stream, FunctionList& profile); + void parseRemoveCore(QXmlStreamReader &stream); + + QMultiHash m_functions; + + QList m_versions; + + // Extension support + QMultiMap m_extensionFunctions; + + QMap m_functionList; +}; + +#endif // XMLSPECPARSER_H -- cgit v1.2.3