From 328d6a1a469103df83a116558fe2e4fe6e1497a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Wed, 29 Jul 2020 09:02:41 +0200 Subject: [PATCH] add support for typed enums and deleted functions --- CppParser/include/Poco/CppParser/Enum.h | 18 ++++++++++++++++++ CppParser/include/Poco/CppParser/Function.h | 18 ++++++++++++++++++ CppParser/src/Enum.cpp | 14 +++++++++++++- CppParser/src/Parser.cpp | 10 +++++++++- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/CppParser/include/Poco/CppParser/Enum.h b/CppParser/include/Poco/CppParser/Enum.h index 8b7aad604..3c7c4e9d3 100644 --- a/CppParser/include/Poco/CppParser/Enum.h +++ b/CppParser/include/Poco/CppParser/Enum.h @@ -52,6 +52,13 @@ public: /// in the form #AnonEnum (where is a unique integer) /// will be assigned. + Enum(const std::string& name, NameSpace* pNameSpace, const std::string& baseType, int flags = 0); + /// Creates the Enum. + /// + /// If name is the empty string, an internal name + /// in the form #AnonEnum (where is a unique integer) + /// will be assigned. + ~Enum(); /// Destroys the Enum. @@ -64,7 +71,11 @@ public: Iterator end() const; /// Returns an iterator for iterating over the Enum's EnumValue's. + const std::string& baseType() const; + /// Returns the base type or an empty string if no base type has been specified. + int flags() const; + /// Returns the flags. Symbol::Kind kind() const; std::string toString() const; @@ -74,6 +85,7 @@ protected: private: Values _values; + std::string _baseType; int _flags; static int _count; }; @@ -82,6 +94,12 @@ private: // // inlines // +inline const std::string& Enum::baseType() const +{ + return _baseType; +} + + inline int Enum::flags() const { return _flags; diff --git a/CppParser/include/Poco/CppParser/Function.h b/CppParser/include/Poco/CppParser/Function.h index 8e051baa1..b59c273c7 100644 --- a/CppParser/include/Poco/CppParser/Function.h +++ b/CppParser/include/Poco/CppParser/Function.h @@ -113,6 +113,12 @@ public: bool isConst() const; /// Returns true iff the method is const. + bool isDefault() const; + /// Returns true iff the method has a default implementation. + + bool isDeleted() const; + /// Returns true iff the method has been deleted. + int countParameters() const; /// Returns the number of parameters. @@ -160,6 +166,18 @@ inline bool Function::isConst() const } +inline bool Function::isDefault() const +{ + return (flags() & FN_DEFAULT) != 0; +} + + +inline bool Function::isDeleted() const +{ + return (flags() & FN_DELETE) != 0; +} + + } } // namespace Poco::CppParser diff --git a/CppParser/src/Enum.cpp b/CppParser/src/Enum.cpp index 8ffb4b42c..1f21ad9d1 100644 --- a/CppParser/src/Enum.cpp +++ b/CppParser/src/Enum.cpp @@ -35,6 +35,14 @@ Enum::Enum(const std::string& name, NameSpace* pNameSpace, int flags): } +Enum::Enum(const std::string& name, NameSpace* pNameSpace, const std::string& baseType, int flags): + Symbol(processName(name), pNameSpace), + _baseType(baseType), + _flags(flags) +{ +} + + Enum::~Enum() { } @@ -81,7 +89,11 @@ Symbol::Kind Enum::kind() const std::string Enum::toString() const { std::ostringstream ostr; - ostr << "enum " << name() << "\n{\n"; + ostr << "enum "; + if (_flags & ENUM_IS_CLASS) ostr << "class "; + ostr << name(); + if (!_baseType.empty()) ostr << ": " << _baseType; + ostr << "\n{\n"; for (Iterator it = begin(); it != end(); ++it) { ostr << "\t" << (*it)->toString() << "\n"; diff --git a/CppParser/src/Parser.cpp b/CppParser/src/Parser.cpp index b01145fe8..810106ea1 100644 --- a/CppParser/src/Parser.cpp +++ b/CppParser/src/Parser.cpp @@ -804,6 +804,7 @@ const Token* Parser::parseEnum(const Token* pNext) { poco_assert (isKeyword(pNext, IdentifierToken::KW_ENUM)); + std::string baseType; int flags = 0; _pCurrentSymbol = 0; int line = _istr.getCurrentLineNumber(); @@ -821,8 +822,15 @@ const Token* Parser::parseEnum(const Token* pNext) name = pNext->tokenString(); pNext = next(); } + + if (isOperator(pNext, OperatorToken::OP_COLON)) + { + pNext = next(); + pNext = parseIdentifier(pNext, baseType); + } + expectOperator(pNext, OperatorToken::OP_OPENBRACE, "{"); - Enum* pEnum = new Enum(name, currentNameSpace(), flags); + Enum* pEnum = new Enum(name, currentNameSpace(), baseType, flags); addSymbol(pEnum, line); pNext = next(); while (pNext->is(Token::IDENTIFIER_TOKEN))