mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 00:07:59 +02:00
added support for new C++11 keywords and features to CppParser and PocoDoc
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// CppToken.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppParser/src/CppToken.cpp#2 $
|
||||
// $Id: //poco/1.4/CppParser/src/CppToken.cpp#3 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
@@ -254,6 +254,8 @@ int OperatorToken::asInteger() const
|
||||
IdentifierToken::IdentifierToken()
|
||||
{
|
||||
int i = 1;
|
||||
_kwMap["alignas"] = i++;
|
||||
_kwMap["alignof"] = i++;
|
||||
_kwMap["and"] = i++;
|
||||
_kwMap["and_eq"] = i++;
|
||||
_kwMap["asm"] = i++;
|
||||
@@ -265,11 +267,15 @@ IdentifierToken::IdentifierToken()
|
||||
_kwMap["case"] = i++;
|
||||
_kwMap["catch"] = i++;
|
||||
_kwMap["char"] = i++;
|
||||
_kwMap["char16_t"] = i++;
|
||||
_kwMap["char32_t"] = i++;
|
||||
_kwMap["class"] = i++;
|
||||
_kwMap["compl"] = i++;
|
||||
_kwMap["const"] = i++;
|
||||
_kwMap["constexpr"] = i++;
|
||||
_kwMap["const_cast"] = i++;
|
||||
_kwMap["continue"] = i++;
|
||||
_kwMap["decltype"] = i++;
|
||||
_kwMap["default"] = i++;
|
||||
_kwMap["delete"] = i++;
|
||||
_kwMap["do"] = i++;
|
||||
@@ -292,8 +298,10 @@ IdentifierToken::IdentifierToken()
|
||||
_kwMap["mutable"] = i++;
|
||||
_kwMap["namespace"] = i++;
|
||||
_kwMap["new"] = i++;
|
||||
_kwMap["noexcept"] = i++;
|
||||
_kwMap["not"] = i++;
|
||||
_kwMap["not_eq"] = i++;
|
||||
_kwMap["nullptr"] = i++;
|
||||
_kwMap["operator"] = i++;
|
||||
_kwMap["or"] = i++;
|
||||
_kwMap["or_eq"] = i++;
|
||||
@@ -307,11 +315,13 @@ IdentifierToken::IdentifierToken()
|
||||
_kwMap["signed"] = i++;
|
||||
_kwMap["sizeof"] = i++;
|
||||
_kwMap["static"] = i++;
|
||||
_kwMap["static_assert"] = i++;
|
||||
_kwMap["static_cast"] = i++;
|
||||
_kwMap["struct"] = i++;
|
||||
_kwMap["switch"] = i++;
|
||||
_kwMap["template"] = i++;
|
||||
_kwMap["this"] = i++;
|
||||
_kwMap["thread_local"] = i++;
|
||||
_kwMap["throw"] = i++;
|
||||
_kwMap["true"] = i++;
|
||||
_kwMap["try"] = i++;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Function.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppParser/src/Function.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/Function.cpp#2 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: SymbolTable
|
||||
@@ -128,6 +128,36 @@ void Function::makePureVirtual()
|
||||
}
|
||||
|
||||
|
||||
void Function::makeFinal()
|
||||
{
|
||||
_flags |= FN_FINAL;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeOverride()
|
||||
{
|
||||
_flags |= FN_OVERRIDE;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeNoexcept()
|
||||
{
|
||||
_flags |= FN_NOEXCEPT;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeDefault()
|
||||
{
|
||||
_flags |= FN_DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
void Function::makeDelete()
|
||||
{
|
||||
_flags |= FN_DELETE;
|
||||
}
|
||||
|
||||
|
||||
bool Function::isConstructor() const
|
||||
{
|
||||
return name() == nameSpace()->name();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Parser.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppParser/src/Parser.cpp#1 $
|
||||
// $Id: //poco/1.4/CppParser/src/Parser.cpp#2 $
|
||||
//
|
||||
// Library: CppParser
|
||||
// Package: CppParser
|
||||
@@ -151,11 +151,13 @@ inline void Parser::append(std::string& decl, const std::string& token)
|
||||
}
|
||||
decl.append(token);
|
||||
if (token == "const"
|
||||
|| token == "constexpr"
|
||||
|| token == "static"
|
||||
|| token == "mutable"
|
||||
|| token == "inline"
|
||||
|| token == "volatile"
|
||||
|| token == "register")
|
||||
|| token == "register"
|
||||
|| token == "thread_local")
|
||||
decl.append(" ");
|
||||
}
|
||||
|
||||
@@ -300,6 +302,12 @@ const Token* Parser::parseClass(const Token* pNext, std::string& decl)
|
||||
else
|
||||
syntaxError("class/struct name");
|
||||
pNext = next();
|
||||
bool isFinal = false;
|
||||
if (isIdentifier(pNext) && pNext->asString() == "final")
|
||||
{
|
||||
pNext = next();
|
||||
isFinal = true;
|
||||
}
|
||||
if (!isOperator(pNext, OperatorToken::OP_SEMICOLON))
|
||||
{
|
||||
// if we have a template specialization the next token will be a <
|
||||
@@ -320,6 +328,7 @@ const Token* Parser::parseClass(const Token* pNext, std::string& decl)
|
||||
if (isOperator(pNext, OperatorToken::OP_COLON) || isOperator(pNext, OperatorToken::OP_OPENBRACE))
|
||||
{
|
||||
Struct* pClass = new Struct(decl, isClass, currentNameSpace());
|
||||
if (isFinal) pClass->makeFinal();
|
||||
pushNameSpace(pClass, line);
|
||||
_access = access;
|
||||
if (isOperator(pNext, OperatorToken::OP_COLON))
|
||||
@@ -632,22 +641,44 @@ const Token* Parser::parseFunc(const Token* pNext, std::string& decl)
|
||||
pNext = parseParameters(pNext, pFunc);
|
||||
expectOperator(pNext, OperatorToken::OP_CLOSPARENT, ")");
|
||||
pNext = next();
|
||||
if (isKeyword(pNext, IdentifierToken::KW_CONST))
|
||||
{
|
||||
if (pFunc) pFunc->makeConst();
|
||||
pNext = next();
|
||||
}
|
||||
if (isKeyword(pNext, IdentifierToken::KW_THROW))
|
||||
{
|
||||
while (!isOperator(pNext, OperatorToken::OP_ASSIGN) && !isOperator(pNext, OperatorToken::OP_SEMICOLON) &&
|
||||
!isOperator(pNext, OperatorToken::OP_OPENBRACE) && !isEOF(pNext))
|
||||
while (pNext->is(Poco::Token::IDENTIFIER_TOKEN) || pNext->is(Poco::Token::KEYWORD_TOKEN))
|
||||
{
|
||||
if (isKeyword(pNext, IdentifierToken::KW_CONST))
|
||||
{
|
||||
if (pFunc) pFunc->makeConst();
|
||||
pNext = next();
|
||||
}
|
||||
if (isKeyword(pNext, IdentifierToken::KW_THROW))
|
||||
{
|
||||
while (!isOperator(pNext, OperatorToken::OP_ASSIGN) && !isOperator(pNext, OperatorToken::OP_SEMICOLON) &&
|
||||
!isOperator(pNext, OperatorToken::OP_OPENBRACE) && !isEOF(pNext))
|
||||
pNext = next();
|
||||
}
|
||||
else if (isKeyword(pNext, IdentifierToken::KW_NOEXCEPT))
|
||||
{
|
||||
if (pFunc) pFunc->makeNoexcept();
|
||||
pNext = next();
|
||||
}
|
||||
else if (isIdentifier(pNext) && pNext->asString() == "override")
|
||||
{
|
||||
if (pFunc) pFunc->makeOverride();
|
||||
pNext = next();
|
||||
}
|
||||
else if (isIdentifier(pNext) && pNext->asString() == "final")
|
||||
{
|
||||
if (pFunc) pFunc->makeFinal();
|
||||
pNext = next();
|
||||
}
|
||||
}
|
||||
if (isOperator(pNext, OperatorToken::OP_ASSIGN))
|
||||
{
|
||||
pNext = next();
|
||||
if (!pNext->is(Token::INTEGER_LITERAL_TOKEN))
|
||||
syntaxError("0");
|
||||
if (!pNext->is(Token::INTEGER_LITERAL_TOKEN) && !isKeyword(pNext, IdentifierToken::KW_DEFAULT) && !isKeyword(pNext, IdentifierToken::KW_DELETE))
|
||||
syntaxError("0, default or delete");
|
||||
if (isKeyword(pNext, IdentifierToken::KW_DEFAULT))
|
||||
pFunc->makeDefault();
|
||||
else if (isKeyword(pNext, IdentifierToken::KW_DELETE))
|
||||
pFunc->makeDelete();
|
||||
pNext = next();
|
||||
if (pFunc) pFunc->makePureVirtual();
|
||||
expectOperator(pNext, OperatorToken::OP_SEMICOLON, ";");
|
||||
|
||||
Reference in New Issue
Block a user