- enhancement: Basic support for parsing variadic macros.
This commit is contained in:
parent
1c23010408
commit
4eca58b62a
1
NEWS.md
1
NEWS.md
|
@ -14,6 +14,7 @@ Red Panda C++ Version 2.26
|
|||
- fix: Should cd to working directory when debugging.
|
||||
- change: Ensure the line just below caret is visible while moving caret.
|
||||
- change: Set mouse cursor to hand pointing when it's on gutter.
|
||||
- enhancement: Basic support for parsing variadic macros.
|
||||
|
||||
Red Panda C++ Version 2.25
|
||||
|
||||
|
|
|
@ -946,6 +946,7 @@ void CppPreprocessor::parseArgs(PDefine define)
|
|||
define->argList[i]=define->argList[i].trimmed();
|
||||
define->argUsed.append(false);
|
||||
}
|
||||
define->varArgIndex=-1;
|
||||
QList<PDefineArgToken> tokens = tokenizeValue(define->value);
|
||||
|
||||
QString formatStr = "";
|
||||
|
@ -954,7 +955,12 @@ void CppPreprocessor::parseArgs(PDefine define)
|
|||
foreach (const PDefineArgToken& token, tokens) {
|
||||
switch(token->type) {
|
||||
case DefineArgTokenType::Identifier:
|
||||
index = define->argList.indexOf(token->value);
|
||||
if (token->value == "__VA_ARGS__") {
|
||||
index = define->argList.indexOf("...");
|
||||
define->varArgIndex = index;
|
||||
} else {
|
||||
index = define->argList.indexOf(token->value);
|
||||
}
|
||||
if (index>=0) {
|
||||
define->argUsed[index] = true;
|
||||
if (lastTokenType == DefineArgTokenType::Sharp) {
|
||||
|
@ -1469,14 +1475,21 @@ QString CppPreprocessor::expandFunction(PDefine define, QString args)
|
|||
i++;
|
||||
}
|
||||
argValues.append(args.mid(lastSplit,i-lastSplit));
|
||||
if (argValues.length() == define->argList.length()
|
||||
if (argValues.length() >= define->argList.length()
|
||||
&& argValues.length()>0) {
|
||||
QStringList varArgs;
|
||||
for (int i=0;i<argValues.length();i++) {
|
||||
if (define->argUsed[i]) {
|
||||
if (define->varArgIndex != -1
|
||||
&& i >= define->varArgIndex ) {
|
||||
varArgs.append(argValues[i].trimmed());
|
||||
} else if (i<define->argList.length()
|
||||
&& define->argUsed[i]) {
|
||||
QString argValue = argValues[i];
|
||||
result=result.arg(argValue.trimmed());
|
||||
}
|
||||
}
|
||||
if (!varArgs.isEmpty())
|
||||
result=result.arg(varArgs.join(","));
|
||||
}
|
||||
result.replace("%%","%");
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ struct Define {
|
|||
bool hardCoded;// if true, don't free memory (points to hard defines)
|
||||
QStringList argList; // args list to format values
|
||||
QList<bool> argUsed;
|
||||
int varArgIndex;
|
||||
QString formatValue; // format template to format values
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue