57 sig += funcNamePrefix;
91 foreach (
Function ctor, constructors)
94 if (!constructors.isEmpty())
100 if (!functions.isEmpty())
118 sections[
access].constructors.append(ctor);
121 QString Class::Section::definition(
const Class *klass)
const
125 foreach (
Function ctor, constructors) {
132 if (!
func.hasBody())
continue;
156 block <<
"protected:";
172 return block.toString();
187 minInput = lst.
first();
188 maxInput = lst.
last();
199 if (
range.length() != 3
201 qWarning(
"Invalid range for char mapping function: %s", qPrintable(
range));
208 charFunctionRanges.append(seq);
213 for (
int i = 0;
i < dfa.
count(); ++
i)
219 headerFileName = section.
value(
"FileHeader");
233 std::sort(
keys.begin(),
keys.end());
238 for (;
i <
keys.count(); ++
i) {
245 sequences.
append(sequence);
251 sequences.
append(sequence);
263 bool Generator::isSingleReferencedFinalState(
int i)
const
265 return backReferenceMap.
value(
i) == 1
277 bool needsCharFunction =
false;
278 if (!charFunctionRanges.isEmpty()) {
280 while (
i < sequences.
count()) {
281 const TransitionSequence &seq = sequences.
at(
i);
282 if (!seq.testFunction.isEmpty()) {
287 foreach (TransitionSequence
range, charFunctionRanges)
288 if (
range.first >= seq.first &&
range.last <= seq.last) {
289 needsCharFunction =
true;
293 left.first = seq.first;
295 left.transition = seq.transition;
298 middle.transition = seq.transition;
301 right.last = seq.last;
302 right.transition = seq.transition;
327 if (sequences.
count() < 10
328 || sequences.
last().last == maxInput
329 || needsCharFunction) {
330 foreach (TransitionSequence seq, sequences) {
331 const bool embedFinalState = isSingleReferencedFinalState(seq.transition);
337 if (!seq.testFunction.isEmpty()) {
338 body <<
"if (" << seq.testFunction <<
")" << brace;
339 }
else if (seq.first == seq.last) {
340 body <<
"if (ch.unicode() == " << seq.first <<
")" << brace;
342 if (seq.last < maxInput)
343 body <<
"if (ch.unicode() >= " << seq.first
344 <<
" && ch.unicode() <= " << seq.last <<
")" << brace;
346 body <<
"if (ch.unicode() >= " << seq.first <<
")" << brace;
349 if (embedFinalState) {
350 body <<
"token = " << dfa.
at(seq.transition).
symbol <<
";";
351 body <<
"goto found;";
356 body <<
"goto state_" << seq.transition <<
";";
362 std::sort(
keys.begin(),
keys.end());
364 body <<
"switch (ch.unicode()) {";
366 for (
int k = 0; k <
keys.count(); ++k) {
368 const int trans = transitions.
value(
key);
373 else if (
key >= 48 &&
key < 127)
378 if (k <
keys.count() - 1
379 && transitions.
value(
keys.at(k + 1)) == trans) {
380 body <<
"case " << keyStr <<
":";
382 if (isSingleReferencedFinalState(trans)) {
383 body <<
"case " << keyStr <<
": token = " << dfa.
at(trans).
symbol <<
"; goto found;";
385 body <<
"case " << keyStr <<
": goto state_" << trans <<
";";
405 body <<
"input = inp;";
407 body <<
"lexemStart = 0;";
408 body <<
"lexemLength = 0;";
414 next.setInline(
true);
416 next.addBody(
"return (pos < input.length()) ? input.at(pos++) : QChar();");
418 next.addBody(
"return (pos < input.length()) ? input.at(pos++).toLower() : QChar();");
432 for (
int i = 0;
i < dfa.
count(); ++
i)
443 body <<
"lexemStart = pos;";
444 body <<
"lexemLength = 0;";
445 body <<
"int lastAcceptingPos = -1;";
446 body <<
"int token = -1;";
450 backReferenceMap.
clear();
452 foreach (
int state,
s.transitions)
453 backReferenceMap[
state]++;
455 bool haveSingleReferencedFinalState =
false;
457 for (
int i = 0;
i < dfa.
count(); ++
i) {
458 if (isSingleReferencedFinalState(
i)) {
459 haveSingleReferencedFinalState =
true;
464 body <<
"state_" <<
i <<
":";
466 body <<
"// initial state";
471 body <<
"lastAcceptingPos = pos;";
472 body <<
"token = " << dfa.
at(
i).
symbol <<
";";
480 body <<
"ch = next();";
489 if (haveSingleReferencedFinalState) {
491 body <<
"lastAcceptingPos = pos;";
496 body <<
"if (lastAcceptingPos != -1) {";
498 body <<
"lexemLength = lastAcceptingPos - lexemStart;";
499 body <<
"pos = lastAcceptingPos;";
502 body <<
"return token;";
509 if (!headerFileName.
isEmpty()) {
small capitals from c petite p scientific i
[1]
QString declaration() const
void addConstructor(Access access, const QString &body, const QString &args=QString())
void addMember(Access access, const QString &name)
QString definition() const
Generator(ClassDef *classDef, const QList< QByteArray > &metaTypes, const QHash< QByteArray, QByteArray > &knownQObjectClasses, const QHash< QByteArray, QByteArray > &knownGadgets, FILE *outfile=nullptr, bool requireCompleteTypes=false)
The QChar class provides a 16-bit Unicode character.
static constexpr QChar fromLatin1(char c) noexcept
operator<<(QDataStream &ds, qfloat16 f)
The QDebug class provides an output stream for debugging information.
The QDir class provides access to directory structures and their contents.
static QString fromNativeSeparators(const QString &pathName)
QString filePath(const QString &fileName) const
static QString cleanPath(const QString &path)
The QFile class provides an interface for reading from and writing to files.
bool open(OpenMode flags) override
QList< Key > keys() const
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
bool isEmpty() const noexcept
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
void remove(qsizetype i, qsizetype n=1)
qsizetype count() const noexcept
void prepend(rvalue_ref t)
void append(parameter_type t)
The QString class provides a Unicode character string.
QString & prepend(QChar c)
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString & replace(qsizetype i, qsizetype len, QChar after)
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromUtf8(QByteArrayView utf8)
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString number(int, int base=10)
QString & remove(qsizetype i, qsizetype len)
size_t qstrlen(const char *str)
#define QStringLiteral(str)
QHttpRequestHeader header("GET", QUrl::toPercentEncoding("/index.html"))
[1]
QString value(const QString &key, const QString &defaultValue=QString()) const
Qt::CaseSensitivity caseSensitivity
QSet< InputType > maxInputSet
void printDeclaration(CodeBlock &block, const QString &funcNamePrefix=QString()) const
QString definition() const
void setName(const QString &name)
void setReturnType(const QString &type)
void addBody(const QString &_body)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
TransitionMap transitions