diff options
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 45 | ||||
-rw-r--r-- | src/qml/compiler/qqmlirbuilder_p.h | 4 |
2 files changed, 48 insertions, 1 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 9c32b9aed1..bd0aedf089 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -459,6 +459,51 @@ void Document::extractScriptMetaData(QString &script, QQmlError *error) return; } +void Document::removeScriptPragmas(QString &script) +{ + const QString pragma(QLatin1String("pragma")); + const QString library(QLatin1String("library")); + + QQmlJS::Lexer l(0); + l.setCode(script, 0); + + int token = l.lex(); + + while (true) { + if (token != QQmlJSGrammar::T_DOT) + return; + + int startOffset = l.tokenOffset(); + int startLine = l.tokenStartLine(); + + token = l.lex(); + + if (token != QQmlJSGrammar::T_PRAGMA || + l.tokenStartLine() != startLine || + script.mid(l.tokenOffset(), l.tokenLength()) != pragma) + return; + + token = l.lex(); + + if (token != QQmlJSGrammar::T_IDENTIFIER || + l.tokenStartLine() != startLine) + return; + + QString pragmaValue = script.mid(l.tokenOffset(), l.tokenLength()); + int endOffset = l.tokenLength() + l.tokenOffset(); + + token = l.lex(); + if (l.tokenStartLine() == startLine) + return; + + if (pragmaValue == library) { + replaceWithSpace(script, startOffset, endOffset - startOffset); + } else { + return; + } + } +} + IRBuilder::IRBuilder(const QSet<QString> &illegalNames) : illegalNames(illegalNames) , _object(0) diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index c2e1ee496e..a345290672 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -43,18 +43,19 @@ #include <private/qqmljsast_p.h> #include <private/qqmlpool_p.h> -#include <private/qqmlscript_p.h> #include <private/qqmljsengine_p.h> #include <private/qv4compiler_p.h> #include <private/qv4compileddata_p.h> #include <private/qqmljsmemorypool_p.h> #include <private/qv4codegen_p.h> #include <private/qv4compiler_p.h> +#include <private/qqmlpropertycache_p.h> #include <QTextStream> #include <QCoreApplication> QT_BEGIN_NAMESPACE +class QQmlContextData; class QQmlTypeNameCache; namespace QmlIR { @@ -324,6 +325,7 @@ struct Q_QML_EXPORT Document QString stringAt(int index) const { return jsGenerator.strings.value(index); } void extractScriptMetaData(QString &script, QQmlError *error); + static void removeScriptPragmas(QString &script); }; struct Q_QML_EXPORT IRBuilder : public QQmlJS::AST::Visitor |