work save

This commit is contained in:
Roy Qu 2021-12-07 14:48:20 +08:00
parent 8db5c531ab
commit f10bc14f3b
4 changed files with 113 additions and 33 deletions

View File

@ -3633,16 +3633,48 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
}
} else if (isIdentifier(phraseExpression[pos])) {
PStatement statement;
if (!freeScoped && !previousResult) {
statement = findMemberOfStatement(phraseExpression[pos],PStatement());
pos++;
} else if (freeScoped && !previousResult) {
statement = findStatementStartingFrom(
fileName,
phraseExpression[pos],
scope,
true);
}
if (freeScoped) {
if (previousResult) {
statement = findStatementStartingFrom(
fileName,
phraseExpression[pos],
previousResult->baseStatement);
} else {
statement = findStatementStartingFrom(
fileName,
phraseExpression[pos],
scope);
}
} else {
if (!previousResult) {
statement = findStatementInScope(phraseExpression[pos],PStatement());
} else {
statement = findStatementInScope(phraseExpression[pos],previousResult->baseStatement);
}
}
pos++;
if (statement) {
switch (statement->kind) {
case StatementKind::skNamespace:
result = doCreateEvalNamespace(statement);
break;
case StatementKind::skVariable:
result = doCreateEvalVariable(fileName,statement);
break;
case StatementKind::skEnumType:
case StatementKind::skClass:
case StatementKind::skEnumClassType:
case StatementKind::skTypedef:
result = doCreateEvalType(fileName,statement);
break;
case StatementKind::skFunction:
result = ;
break;
}
} else {
if (isTypeStatement())
result = PEvalStatement();
}
} else if (isIntegerLiteral(phraseExpression[pos])) {
} else if (isIntegerLiteral(phraseExpression[pos])) {
} else if (isFloatLiteral(phraseExpression[pos])) {
@ -3653,23 +3685,50 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName,
}
PEvalStatement CppParser::doCreateEvalType(const PStatement &typeStatement)
PEvalStatement CppParser::doCreateEvalNamespace(const PStatement &namespaceStatement)
{
Q_ASSERT(typeStatement);
Q_ASSERT(typeStatement->kind == StatementKind::skClass
|| typeStatement->kind == StatementKind::skEnumType
|| typeStatement->kind == StatementKind::skEnumClassType);
return EvalStatement::create(
if (!namespaceStatement)
return PEvalStatement();
return std::make_shared<EvalStatement>(
namespaceStatement->fullName,
EvalStatementKind::Namespace,
namespaceStatement,
PStatement());
}
PEvalStatement CppParser::doCreateEvalType(const QString& fileName,const PStatement &typeStatement)
{
if (!typeStatement)
return PEvalStatement();
if (typeStatement->kind == StatementKind::skTypedef) {
QString baseType;
int pointerLevel=0;
PStatement statement = doParseEvalTypeInfo(
fileName,
typeStatement->parentScope.lock(),
typeStatement->type,
baseType,
pointerLevel);
return std::make_shared<EvalStatement>(
baseType,
EvalStatementKind::Type,
typeStatement,
PStatement(),
pointerLevel
);
} else {
return std::make_shared<EvalStatement>(
typeStatement->fullName,
EvalStatementKind::Type,
typeStatement,
typeStatement);
PStatement());
}
}
PEvalStatement CppParser::doCreateEvalVariable(const QString &fileName, PStatement varStatement, const PStatement &scope)
PEvalStatement CppParser::doCreateEvalVariable(const QString &fileName, PStatement varStatement)
{
Q_ASSERT(varStatement);
Q_ASSERT(varStatement->kind == StatementKind::skVariable);
if (!varStatement)
return PEvalStatement();
QString baseType;
int pointerLevel=0;
PStatement typeStatement = doParseEvalTypeInfo(
@ -3678,7 +3737,7 @@ PEvalStatement CppParser::doCreateEvalVariable(const QString &fileName, PStateme
varStatement->type,
baseType,
pointerLevel);
return EvalStatement::create(
return std::make_shared<EvalStatement>(
baseType,
EvalStatementKind::Variable,
varStatement,
@ -3687,6 +3746,27 @@ PEvalStatement CppParser::doCreateEvalVariable(const QString &fileName, PStateme
);
}
PEvalStatement CppParser::doCreateEvalFunction(const QString &fileName, PStatement funcStatement)
{
if (!funcStatement)
return PEvalStatement();
QString baseType;
int pointerLevel=0;
PStatement typeStatement = doParseEvalTypeInfo(
fileName,
funcStatement->parentScope.lock(),
funcStatement->type,
baseType,
pointerLevel);
return std::make_shared<EvalStatement>(
baseType,
EvalStatementKind::Function,
funcStatement,
typeStatement,
pointerLevel
);
}
PStatement CppParser::doParseEvalTypeInfo(
const QString &fileName,
const PStatement &scope,

View File

@ -263,10 +263,12 @@ private:
const PEvalStatement& previousResult,
bool freeScoped);
PEvalStatement doCreateEvalNamespace(const PStatement& namespaceStatement);
PEvalStatement doCreateEvalType(const PStatement& typeStatement);
PEvalStatement doCreateEvalType(const QString& fileName,const PStatement& typeStatement);
PEvalStatement doCreateEvalVariable(const QString& fileName, PStatement varStatement, const PStatement& scope);
PEvalStatement doCreateEvalVariable(const QString& fileName, PStatement varStatement);
PEvalStatement doCreateEvalFunction(const QString& fileName, PStatement funcStatement);
PStatement doParseEvalTypeInfo(
const QString& fileName,

View File

@ -499,20 +499,18 @@ bool isScopeTypeKind(StatementKind kind)
}
}
PEvalStatement EvalStatement::create(
EvalStatement::EvalStatement(
const QString &baseType,
EvalStatementKind kind,
const PStatement &baseStatement,
const PStatement &effetiveTypeStatement,
const PStatement &typeStatement,
int pointerLevel)
{
PEvalStatement result = std::make_shared<EvalStatement>();
result->baseType = baseType;
result->kind = kind;
result->baseStatement = baseStatement;
result->effectiveTypeStatement = effectiveTypeStatement;
result->pointerLevel = pointerLevel;
return result;
this->baseType = baseType;
this->kind = kind;
this->baseStatement = baseStatement;
this->effectiveTypeStatement = typeStatement;
this->pointerLevel = pointerLevel;
}
void EvalStatement::assignType(const PEvalStatement &typeStatement)

View File

@ -161,7 +161,7 @@ struct EvalStatement {
PStatement baseStatement; // if not literal or primitive type, the base statement
PStatement effectiveTypeStatement;
public:
static PEvalStatement create(const QString& baseType,
EvalStatement (const QString& baseType,
EvalStatementKind kind,
const PStatement& baseStatement,
const PStatement& typeStatement,