- enhancement: Auto type induction for new / temp class object.

This commit is contained in:
Roy Qu 2024-03-24 19:42:29 +08:00
parent 0405a51206
commit 13e0393c8e
1 changed files with 32 additions and 33 deletions

View File

@ -4078,7 +4078,6 @@ void CppParser::handleVar(const QString& typePrefix,bool isExtern,bool isStatic,
PEvalStatement(), PEvalStatement(),
true,false); true,false);
if(aliasStatement) { if(aliasStatement) {
qDebug()<<phraseExpression<<aliasStatement->pointerLevel;
if (aliasStatement->effectiveTypeStatement) { if (aliasStatement->effectiveTypeStatement) {
addedVar->type = aliasStatement->effectiveTypeStatement->fullName; addedVar->type = aliasStatement->effectiveTypeStatement->fullName;
if (!addedVar->type.endsWith(">")) if (!addedVar->type.endsWith(">"))
@ -4618,7 +4617,32 @@ PEvalStatement CppParser::doEvalExpression(const QString& fileName,
i++; i++;
} }
} }
return doEvalPointerArithmetic(fileName,
if (phraseExpression[pos] == "new") {
pos++;
if (pos>=phraseExpression.length())
return PEvalStatement();
PEvalStatement result = doEvalExpression(
fileName,
phraseExpression,
pos,
scope,
previousResult,
freeScoped,
false);
if (result) {
if (pos < phraseExpression.length())
result = PEvalStatement();
else if (result->kind != EvalStatementKind::Variable) {
result = PEvalStatement();
} else {
result->pointerLevel++;
}
}
return result;
} else
return doEvalPointerArithmetic(
fileName,
phraseExpression, phraseExpression,
pos, pos,
scope, scope,
@ -5170,11 +5194,8 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
if (token=="*") // for expression like (const * char)? if (token=="*") // for expression like (const * char)?
pointerLevel++; pointerLevel++;
else if (mCppTypeKeywords.contains(token) else if (mCppTypeKeywords.contains(token)
|| !mCppKeywords.contains(token)) { || !mCppKeywords.contains(token))
break; break;
} else if (token=="new") {
break;
}
pos++; pos++;
} }
if (pos>=phraseExpression.length() || phraseExpression[pos]==")") if (pos>=phraseExpression.length() || phraseExpression[pos]==")")
@ -5183,12 +5204,6 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
result = doCreateEvalType(phraseExpression[pos]); result = doCreateEvalType(phraseExpression[pos]);
pos++; pos++;
} else if (isIdentifier(phraseExpression[pos])) { } else if (isIdentifier(phraseExpression[pos])) {
bool isNew = (phraseExpression[pos] == "new");
if (isNew) {
pos++;
if (pos>=phraseExpression.length())
return PEvalStatement();
}
PStatement statement; PStatement statement;
if (freeScoped) { if (freeScoped) {
if (!previousResult) { if (!previousResult) {
@ -5277,22 +5292,6 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
} }
} }
} }
if (result && isNew) {
if (result->kind != EvalStatementKind::Type) {
return PEvalStatement();
} else {
if (pos >= phraseExpression.length())
return PEvalStatement();
if (phraseExpression[pos]=='{')
doSkipInExpression(phraseExpression,pos,"{","}");
else if (phraseExpression[pos]=='(')
doSkipInExpression(phraseExpression,pos,"(",")");
else
return PEvalStatement();
result->kind = EvalStatementKind::Variable;
result->pointerLevel++;
}
}
} else if (isIntegerLiteral(phraseExpression[pos])) { } else if (isIntegerLiteral(phraseExpression[pos])) {
result = doCreateEvalLiteral("int"); result = doCreateEvalLiteral("int");
pos++; pos++;