diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index a0b04dd7..5df734b8 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -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( + 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( + baseType, + EvalStatementKind::Type, + typeStatement, + PStatement(), + pointerLevel + ); + } else { + return std::make_shared( 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( 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( + baseType, + EvalStatementKind::Function, + funcStatement, + typeStatement, + pointerLevel + ); +} + PStatement CppParser::doParseEvalTypeInfo( const QString &fileName, const PStatement &scope, diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index cf5115fa..e27920b9 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -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, diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index 93895dea..c9a92a68 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -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(); - 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) diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index 9e9324e5..ab1a2903 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -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,