Merge branch 'memory'

This commit is contained in:
Roy Qu 2023-10-27 20:29:05 +08:00
commit 23dca20c24
3 changed files with 37 additions and 22 deletions

View File

@ -1337,6 +1337,7 @@ PStatement CppParser::addStatement(const PStatement& parent,
newType += newCommand.front();
newCommand.remove(0,1); // remove first
}
newCommand.squeeze();
// if (newCommand.startsWith("::") && parent && kind!=StatementKind::skBlock ) {
// qDebug()<<command<<fileName<<line<<kind<<parent->fullName;
// }
@ -1398,6 +1399,13 @@ PStatement CppParser::addStatement(const PStatement& parent,
else
result->fullName = getFullStatementName(newCommand, parent);
result->usageCount = -1;
result->args.squeeze();
result->noNameArgs.squeeze();
result->value.squeeze();
result->type.squeeze();
//result->fullName.squeeze();
//result->command.squeeze();
mStatementList.add(result);
if (result->kind == StatementKind::skNamespace) {
PStatementList namespaceList = mNamespaces.value(result->fullName,PStatementList());
@ -1417,6 +1425,8 @@ PStatement CppParser::addStatement(const PStatement& parent,
// if (result->command=="sync_with_stdio") {
// qDebug()<<result->fullName<<result->isStatic()<<(int)result->accessibility;
// }
return result;
}
@ -2476,9 +2486,11 @@ QString CppParser::getFullStatementName(const QString &command, const PStatement
PStatement scopeStatement=parent;
while (scopeStatement && !isNamedScope(scopeStatement->kind))
scopeStatement = scopeStatement->parentScope.lock();
if (scopeStatement)
return scopeStatement->fullName + "::" + command;
else
if (scopeStatement) {
QString s = scopeStatement->fullName + "::" + command;
s.squeeze();
return s;
} else
return command;
}

View File

@ -131,6 +131,9 @@ void CppPreprocessor::getDefineParts(const QString &input, QString &name, QStrin
args = "";
}
value = removeGCCAttributes(s.mid(i+1).trimmed());
name.squeeze();
value.squeeze();
args.squeeze();
}
void CppPreprocessor::addHardDefineByLine(const QString &line)
@ -942,9 +945,9 @@ void CppPreprocessor::parseArgs(PDefine define)
if(args=="")
return ;
define->argList = args.split(',');
for (int i=0;i<define->argList.size();i++) {
define->argList[i]=define->argList[i].trimmed();
QStringList argList = args.split(',');
for (int i=0;i<argList.size();i++) {
argList[i]=argList[i].trimmed();
define->argUsed.append(false);
}
QList<PDefineArgToken> tokens = tokenizeValue(define->value);
@ -956,10 +959,10 @@ void CppPreprocessor::parseArgs(PDefine define)
switch(token->type) {
case DefineArgTokenType::Identifier:
if (token->value == "__VA_ARGS__") {
index = define->argList.indexOf("...");
index = argList.indexOf("...");
define->varArgIndex = index;
} else {
index = define->argList.indexOf(token->value);
index = argList.indexOf(token->value);
}
if (index>=0) {
define->argUsed[index] = true;
@ -986,6 +989,7 @@ void CppPreprocessor::parseArgs(PDefine define)
lastTokenType = token->type;
}
define->formatValue = formatStr;
define->formatValue.squeeze();
}
QList<PDefineArgToken> CppPreprocessor::tokenizeValue(const QString &value)
@ -1456,9 +1460,9 @@ QString CppPreprocessor::expandFunction(PDefine define, QString args)
// args = args.mid(1,args.length()-2);
// }
if (define->argList.length()==0) {
if (define->argUsed.length()==0) {
// do nothing
} else if (define->argList.length()==1) {
} else if (define->argUsed.length()==1) {
if (define->argUsed[0])
result=result.arg(args);
} else {
@ -1504,25 +1508,25 @@ QString CppPreprocessor::expandFunction(PDefine define, QString args)
argValues.append(args.mid(lastSplit,i-lastSplit));
#ifdef QT_DEBUG
if (
(define->varArgIndex==-1 && argValues.length() != define->argList.length())
|| (define->varArgIndex!=-1 && argValues.length() < define->argList.length()-1)
(define->varArgIndex==-1 && argValues.length() != define->argUsed.length())
|| (define->varArgIndex!=-1 && argValues.length() < define->argUsed.length()-1)
) {
qDebug()<<"*** Expand Macro error ***";
qDebug()<<this->mFileName<<":"<<this->mIndex;
qDebug()<<"Macro: "<<define->name<<define->argList;
qDebug()<<"Macro: "<<define->name<<define->args;
qDebug()<<"Actual param: "<<args;
qDebug()<<"Params splitted: "<<argValues;
qDebug()<<"**********";
}
#endif
if (argValues.length() >= define->argList.length()
if (argValues.length() >= define->argUsed.length()
&& argValues.length()>0) {
QStringList varArgs;
for (int i=0;i<argValues.length();i++) {
if (define->varArgIndex != -1
&& i >= define->varArgIndex ) {
varArgs.append(argValues[i].trimmed());
} else if (i<define->argList.length()
} else if (i<define->argUsed.length()
&& define->argUsed[i]) {
QString argValue = argValues[i];
result=result.arg(argValue.trimmed());

View File

@ -50,7 +50,6 @@ struct Define {
QString value;
QString filename;
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
@ -145,8 +144,8 @@ enum class EvalStatementKind {
};
struct StatementMatchPosition{
int start;
int end;
uint16_t start;
uint16_t end;
};
enum StatementProperty {
@ -201,10 +200,10 @@ struct Statement {
// fields for code completion
int usageCount; //Usage Count
int matchPosTotal; // total of matched positions
int matchPosSpan; // distance between the first match pos and the last match pos;
int firstMatchLength; // length of first match;
int caseMatched; // if match with case
uint16_t matchPosTotal; // total of matched positions
uint16_t matchPosSpan; // distance between the first match pos and the last match pos;
uint16_t firstMatchLength; // length of first match;
uint16_t caseMatched; // if match with case
QList<PStatementMathPosition> matchPositions;
// definiton line/filename is valid