summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/preprocessor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/moc/preprocessor.cpp')
-rw-r--r--src/tools/moc/preprocessor.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index f253c49995..a2a1a958cf 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -529,7 +529,7 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
return symbols;
}
-Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &index,
+void Preprocessor::macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand, int &index,
int lineNum, bool one, const QSet<QByteArray> &excludeSymbols)
{
SymbolStack symbols;
@@ -539,16 +539,18 @@ Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &in
sf.excludedSymbols = excludeSymbols;
symbols.push(sf);
- Symbols result;
if (toExpand.isEmpty())
- return result;
+ return;
for (;;) {
QByteArray macro;
Symbols newSyms = macroExpandIdentifier(that, symbols, lineNum, &macro);
if (macro.isEmpty()) {
- result += newSyms;
+ // not a macro
+ Symbol s = symbols.symbol();
+ s.lineNum = lineNum;
+ *into += s;
} else {
SafeSymbols sf;
sf.symbols = newSyms;
@@ -565,8 +567,6 @@ Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &in
index = symbols.top().index;
else
index = toExpand.size();
-
- return result;
}
@@ -576,10 +576,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
// not a macro
if (s.token != PP_IDENTIFIER || !that->macros.contains(s) || symbols.dontReplaceSymbol(s.lexem())) {
- Symbols syms;
- syms += s;
- syms.last().lineNum = lineNum;
- return syms;
+ return Symbols();
}
const Macro &macro = that->macros.value(s);
@@ -600,7 +597,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
syms.last().lineNum = lineNum;
return syms;
}
- QList<Symbols> arguments;
+ QVarLengthArray<Symbols, 5> arguments;
while (symbols.hasNext()) {
Symbols argument;
// strip leading space
@@ -653,7 +650,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
if (i == macro.symbols.size() - 1 || macro.symbols.at(i + 1).token != PP_HASHHASH) {
Symbols arg = arguments.at(index);
int idx = 1;
- expansion += macroExpand(that, arg, idx, lineNum, false, symbols.excludeSymbols());
+ macroExpand(&expansion, that, arg, idx, lineNum, false, symbols.excludeSymbols());
} else {
expansion += arguments.at(index);
}
@@ -661,9 +658,12 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
expansion += s;
}
} else if (mode == Hash) {
- if (index < 0 || index >= arguments.size()) {
+ if (index < 0) {
that->error("'#' is not followed by a macro parameter");
continue;
+ } else if (index >= arguments.size()) {
+ that->error("Macro invoked with too few parameters for a use of '#'");
+ continue;
}
const Symbols &arg = arguments.at(index);
@@ -726,7 +726,7 @@ void Preprocessor::substituteUntilNewline(Symbols &substituted)
while (hasNext()) {
Token token = next();
if (token == PP_IDENTIFIER) {
- substituted += macroExpand(this, symbols, index, symbol().lineNum, true);
+ macroExpand(&substituted, this, symbols, index, symbol().lineNum, true);
} else if (token == PP_DEFINED) {
bool braces = test(PP_LPAREN);
next(PP_IDENTIFIER);
@@ -1148,7 +1148,7 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed)
}
case PP_IDENTIFIER: {
// substitute macros
- preprocessed += macroExpand(this, symbols, index, symbol().lineNum, true);
+ macroExpand(&preprocessed, this, symbols, index, symbol().lineNum, true);
continue;
}
case PP_HASH: