diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 5a724977..7d494d12 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -3360,12 +3360,61 @@ PEvalStatement CppParser::doEvalExpression(const QString& fileName, bool freeScoped) { //dummy function to easy later upgrades - return doEvalPointerToMembers(fileName, + return doEvalPointerArithmetic(fileName, phraseExpression, pos, scope, previousResult, - freeScoped); + freeScoped); +} + +PEvalStatement CppParser::doEvalPointerArithmetic(const QString &fileName, const QStringList &phraseExpression, int &pos, const PStatement &scope, const PEvalStatement &previousResult, bool freeScoped) +{ + if (pos>=phraseExpression.length()) + return PEvalStatement(); + //find the start scope statement + PEvalStatement currentResult = doEvalPointerToMembers( + fileName, + phraseExpression, + pos, + scope, + previousResult, + freeScoped); + while (pos < phraseExpression.length()) { + if (!currentResult) + break; + if (currentResult && + (phraseExpression[pos]=="+" + || phraseExpression[pos]=="-")) { + if (currentResult->kind == EvalStatementKind::Variable) { + pos++; + PEvalStatement op2=doEvalPointerToMembers( + fileName, + phraseExpression, + pos, + scope, + currentResult, + false); + //todo operator+/- overload + } else if (currentResult->kind == EvalStatementKind::Literal + && currentResult->baseType == "int") { + pos++; + PEvalStatement op2=doEvalPointerToMembers( + fileName, + phraseExpression, + pos, + scope, + currentResult, + false); + currentResult = op2; + } else + break; + } else + break; + } + qDebug()<kind == EvalStatementKind::Type) { - //static member + //class static member + result = doEvalTerm(fileName, + phraseExpression, + pos, + scope, + result, + false); } else if (result->kind == EvalStatementKind::Namespace) { - - } else - result = PEvalStatement(); + //namespace + result = doEvalTerm(fileName, + phraseExpression, + pos, + scope, + result, + false); + } + if (!result) + break; } else break; } @@ -3724,15 +3792,19 @@ PEvalStatement CppParser::doEvalTerm(const QString &fileName, } } else if (isIntegerLiteral(phraseExpression[pos])) { result = doCreateEvalLiteral("int"); + pos++; } else if (isFloatLiteral(phraseExpression[pos])) { result = doCreateEvalLiteral("double"); + pos++; } else if (isStringLiteral(phraseExpression[pos])) { result = doCreateEvalLiteral("char"); result->pointerLevel = 1; + pos++; } else if (isCharLiteral(phraseExpression[pos])) { result = doCreateEvalLiteral("char"); + pos++; } else - result = PEvalStatement(); + return result; if (result) { qDebug()<<"term kind:"<<(int)result->kind; } @@ -3933,11 +4005,13 @@ PStatement CppParser::doParseEvalTypeInfo( pointerLevel--; else if (highlighter.getTokenAttribute() == highlighter.identifierAttribute()) { if (token!= "const") - baseType = token; + baseType += token; } else if (token == "[") { bracketLevel++; } else if (token == "<") { templateLevel++; + } else if (token == "::") { + baseType += token; } } else if (bracketLevel > 0) { if (token == "[") { diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 9d84d00c..9c973d8b 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -227,6 +227,13 @@ private: const PEvalStatement& previousResult, bool freeScoped); + PEvalStatement doEvalPointerArithmetic( + const QString& fileName, + const QStringList& phraseExpression, + int &pos, + const PStatement& scope, + const PEvalStatement& previousResult, + bool freeScoped); PEvalStatement doEvalPointerToMembers( const QString& fileName, const QStringList& phraseExpression,