Skip to content

Commit 78c69b9

Browse files
committed
added support for new C++11 keywords and features to CppParser and PocoDoc
1 parent 83fd9e4 commit 78c69b9

7 files changed

Lines changed: 157 additions & 29 deletions

File tree

‎CppParser/include/Poco/CppParser/CppToken.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// CppToken.h
33
//
4-
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/CppToken.h#1 $
4+
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/CppToken.h#2 $
55
//
66
// Library: CppParser
77
// Package: CppParser
@@ -134,7 +134,9 @@ class CppParser_API IdentifierToken: public CppToken
134134
public:
135135
enum Keywords
136136
{
137-
KW_AND = 1,
137+
KW_ALIGNAS = 1,
138+
KW_ALIGNOF,
139+
KW_AND,
138140
KW_AND_EQ,
139141
KW_ASM,
140142
KW_AUTO,
@@ -145,11 +147,15 @@ class CppParser_API IdentifierToken: public CppToken
145147
KW_CASE,
146148
KW_CATCH,
147149
KW_CHAR,
150+
KW_CHAR_16T,
151+
KW_CHAR_32T,
148152
KW_CLASS,
149153
KW_COMPL,
150154
KW_CONST,
155+
KW_CONSTEXPR,
151156
KW_CONST_CAST,
152157
KW_CONTINUE,
158+
KW_DECLTYPE,
153159
KW_DEFAULT,
154160
KW_DELETE,
155161
KW_DO,
@@ -172,8 +178,10 @@ class CppParser_API IdentifierToken: public CppToken
172178
KW_MUTABLE,
173179
KW_NAMESPACE,
174180
KW_NEW,
181+
KW_NOEXCEPT,
175182
KW_NOT,
176183
KW_NOT_EQ,
184+
KW_NULLPTR,
177185
KW_OPERATOR,
178186
KW_OR,
179187
KW_OR_EQ,
@@ -187,11 +195,13 @@ class CppParser_API IdentifierToken: public CppToken
187195
KW_SIGNED,
188196
KW_SIZEOF,
189197
KW_STATIC,
198+
KW_STATIC_ASSERT,
190199
KW_STATIC_CAST,
191200
KW_STRUCT,
192201
KW_SWITCH,
193202
KW_TEMPLATE,
194203
KW_THIS,
204+
KW_THREAD_LOCAL,
195205
KW_THROW,
196206
KW_TRUE,
197207
KW_TRY,

‎CppParser/include/Poco/CppParser/Function.h‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Function.h
33
//
4-
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/Function.h#1 $
4+
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/Function.h#2 $
55
//
66
// Library: CppParser
77
// Package: SymbolTable
@@ -58,12 +58,17 @@ class CppParser_API Function: public Decl
5858
public:
5959
enum Flags
6060
{
61-
FN_STATIC = 1, /// The function is static.
62-
FN_VIRTUAL = 2, /// The function is virtual.
63-
FN_INLINE = 4, /// The function is inline.
64-
FN_CONST = 8, /// The function is const.
65-
FN_TEMPLATE = 16, /// The function is a template.
66-
FN_PURE_VIRTUAL = 32 /// The function is pure virtual.
61+
FN_STATIC = 1, /// The function is static.
62+
FN_VIRTUAL = 2, /// The function is virtual.
63+
FN_INLINE = 4, /// The function is inline.
64+
FN_CONST = 8, /// The function is const.
65+
FN_TEMPLATE = 16, /// The function is a template.
66+
FN_PURE_VIRTUAL = 32, /// The function is pure virtual.
67+
FN_FINAL = 64, /// The function is final.
68+
FN_OVERRIDE = 128, /// The function is override.
69+
FN_NOEXCEPT = 256, /// The function is noexcept.
70+
FN_DEFAULT = 512, /// The function is default.
71+
FN_DELETE = 1024 /// The function has been deleted.
6772
};
6873

6974
typedef std::vector<Parameter*> Parameters;
@@ -94,6 +99,21 @@ class CppParser_API Function: public Decl
9499

95100
void makePureVirtual();
96101
/// Sets the FN_PURE_VIRTUAL flag.
102+
103+
void makeFinal();
104+
/// Sets the FN_FINAL flag.
105+
106+
void makeOverride();
107+
/// Sets the FN_OVERRIDE flag.
108+
109+
void makeNoexcept();
110+
/// Sets the FN_NOEXCEPT flag.
111+
112+
void makeDefault();
113+
/// Sets the FN_DEFAULT flag.
114+
115+
void makeDelete();
116+
/// Sets the FN_DELETE flag.
97117

98118
int flags() const;
99119
/// Returns the function's flags.

‎CppParser/include/Poco/CppParser/Struct.h‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Struct.h
33
//
4-
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/Struct.h#1 $
4+
// $Id: //poco/1.4/CppParser/include/Poco/CppParser/Struct.h#2 $
55
//
66
// Library: CppParser
77
// Package: SymbolTable
@@ -61,7 +61,8 @@ class CppParser_API Struct: public NameSpace
6161
{
6262
FN_TEMPLATE = 1,
6363
FN_INLINE = 2, // when the whole class is inlined in a c++ file
64-
FN_TEMPLATE_SPECIALIZATION = 4
64+
FN_TEMPLATE_SPECIALIZATION = 4,
65+
FN_FINAL = 8
6566
};
6667

6768
struct Base
@@ -115,10 +116,16 @@ class CppParser_API Struct: public NameSpace
115116

116117
void makeInline();
117118
/// Changes the class to a inline class, i.e. definition and implementation are hidden in a cpp file.
119+
120+
void makeFinal();
121+
/// Makes the class final.
118122

119123
bool isInline() const;
120124
/// Returns true if the complete class is inlined in a cpp file.
121125

126+
bool isFinal() const;
127+
/// Returns true if the class is final.
128+
122129
void constructors(Functions& functions) const;
123130
/// Returns all constructors, sorted by their parameter count.
124131

@@ -190,12 +197,24 @@ inline void Struct::makeInline()
190197
}
191198

192199

200+
inline void Struct::makeFinal()
201+
{
202+
_flags |= FN_FINAL;
203+
}
204+
205+
193206
inline bool Struct::isInline() const
194207
{
195208
return (_flags & FN_INLINE) != 0;
196209
}
197210

198211

212+
inline bool Struct::isFinal() const
213+
{
214+
return (_flags & FN_FINAL) != 0;
215+
}
216+
217+
199218
inline bool Struct::isDerived() const
200219
{
201220
return !_bases.empty();

‎CppParser/src/CppToken.cpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// CppToken.cpp
33
//
4-
// $Id: //poco/1.4/CppParser/src/CppToken.cpp#2 $
4+
// $Id: //poco/1.4/CppParser/src/CppToken.cpp#3 $
55
//
66
// Library: CppParser
77
// Package: CppParser
@@ -254,6 +254,8 @@ int OperatorToken::asInteger() const
254254
IdentifierToken::IdentifierToken()
255255
{
256256
int i = 1;
257+
_kwMap["alignas"] = i++;
258+
_kwMap["alignof"] = i++;
257259
_kwMap["and"] = i++;
258260
_kwMap["and_eq"] = i++;
259261
_kwMap["asm"] = i++;
@@ -265,11 +267,15 @@ IdentifierToken::IdentifierToken()
265267
_kwMap["case"] = i++;
266268
_kwMap["catch"] = i++;
267269
_kwMap["char"] = i++;
270+
_kwMap["char16_t"] = i++;
271+
_kwMap["char32_t"] = i++;
268272
_kwMap["class"] = i++;
269273
_kwMap["compl"] = i++;
270274
_kwMap["const"] = i++;
275+
_kwMap["constexpr"] = i++;
271276
_kwMap["const_cast"] = i++;
272277
_kwMap["continue"] = i++;
278+
_kwMap["decltype"] = i++;
273279
_kwMap["default"] = i++;
274280
_kwMap["delete"] = i++;
275281
_kwMap["do"] = i++;
@@ -292,8 +298,10 @@ IdentifierToken::IdentifierToken()
292298
_kwMap["mutable"] = i++;
293299
_kwMap["namespace"] = i++;
294300
_kwMap["new"] = i++;
301+
_kwMap["noexcept"] = i++;
295302
_kwMap["not"] = i++;
296303
_kwMap["not_eq"] = i++;
304+
_kwMap["nullptr"] = i++;
297305
_kwMap["operator"] = i++;
298306
_kwMap["or"] = i++;
299307
_kwMap["or_eq"] = i++;
@@ -307,11 +315,13 @@ IdentifierToken::IdentifierToken()
307315
_kwMap["signed"] = i++;
308316
_kwMap["sizeof"] = i++;
309317
_kwMap["static"] = i++;
318+
_kwMap["static_assert"] = i++;
310319
_kwMap["static_cast"] = i++;
311320
_kwMap["struct"] = i++;
312321
_kwMap["switch"] = i++;
313322
_kwMap["template"] = i++;
314323
_kwMap["this"] = i++;
324+
_kwMap["thread_local"] = i++;
315325
_kwMap["throw"] = i++;
316326
_kwMap["true"] = i++;
317327
_kwMap["try"] = i++;

‎CppParser/src/Function.cpp‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Function.cpp
33
//
4-
// $Id: //poco/1.4/CppParser/src/Function.cpp#1 $
4+
// $Id: //poco/1.4/CppParser/src/Function.cpp#2 $
55
//
66
// Library: CppParser
77
// Package: SymbolTable
@@ -128,6 +128,36 @@ void Function::makePureVirtual()
128128
}
129129

130130

131+
void Function::makeFinal()
132+
{
133+
_flags |= FN_FINAL;
134+
}
135+
136+
137+
void Function::makeOverride()
138+
{
139+
_flags |= FN_OVERRIDE;
140+
}
141+
142+
143+
void Function::makeNoexcept()
144+
{
145+
_flags |= FN_NOEXCEPT;
146+
}
147+
148+
149+
void Function::makeDefault()
150+
{
151+
_flags |= FN_DEFAULT;
152+
}
153+
154+
155+
void Function::makeDelete()
156+
{
157+
_flags |= FN_DELETE;
158+
}
159+
160+
131161
bool Function::isConstructor() const
132162
{
133163
return name() == nameSpace()->name();

‎CppParser/src/Parser.cpp‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Parser.cpp
33
//
4-
// $Id: //poco/1.4/CppParser/src/Parser.cpp#1 $
4+
// $Id: //poco/1.4/CppParser/src/Parser.cpp#2 $
55
//
66
// Library: CppParser
77
// Package: CppParser
@@ -151,11 +151,13 @@ inline void Parser::append(std::string& decl, const std::string& token)
151151
}
152152
decl.append(token);
153153
if (token == "const"
154+
|| token == "constexpr"
154155
|| token == "static"
155156
|| token == "mutable"
156157
|| token == "inline"
157158
|| token == "volatile"
158-
|| token == "register")
159+
|| token == "register"
160+
|| token == "thread_local")
159161
decl.append(" ");
160162
}
161163

@@ -300,6 +302,12 @@ const Token* Parser::parseClass(const Token* pNext, std::string& decl)
300302
else
301303
syntaxError("class/struct name");
302304
pNext = next();
305+
bool isFinal = false;
306+
if (isIdentifier(pNext) && pNext->asString() == "final")
307+
{
308+
pNext = next();
309+
isFinal = true;
310+
}
303311
if (!isOperator(pNext, OperatorToken::OP_SEMICOLON))
304312
{
305313
// 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)
320328
if (isOperator(pNext, OperatorToken::OP_COLON) || isOperator(pNext, OperatorToken::OP_OPENBRACE))
321329
{
322330
Struct* pClass = new Struct(decl, isClass, currentNameSpace());
331+
if (isFinal) pClass->makeFinal();
323332
pushNameSpace(pClass, line);
324333
_access = access;
325334
if (isOperator(pNext, OperatorToken::OP_COLON))
@@ -632,22 +641,44 @@ const Token* Parser::parseFunc(const Token* pNext, std::string& decl)
632641
pNext = parseParameters(pNext, pFunc);
633642
expectOperator(pNext, OperatorToken::OP_CLOSPARENT, ")");
634643
pNext = next();
635-
if (isKeyword(pNext, IdentifierToken::KW_CONST))
636-
{
637-
if (pFunc) pFunc->makeConst();
638-
pNext = next();
639-
}
640-
if (isKeyword(pNext, IdentifierToken::KW_THROW))
641-
{
642-
while (!isOperator(pNext, OperatorToken::OP_ASSIGN) && !isOperator(pNext, OperatorToken::OP_SEMICOLON) &&
643-
!isOperator(pNext, OperatorToken::OP_OPENBRACE) && !isEOF(pNext))
644+
while (pNext->is(Poco::Token::IDENTIFIER_TOKEN) || pNext->is(Poco::Token::KEYWORD_TOKEN))
645+
{
646+
if (isKeyword(pNext, IdentifierToken::KW_CONST))
647+
{
648+
if (pFunc) pFunc->makeConst();
644649
pNext = next();
650+
}
651+
if (isKeyword(pNext, IdentifierToken::KW_THROW))
652+
{
653+
while (!isOperator(pNext, OperatorToken::OP_ASSIGN) && !isOperator(pNext, OperatorToken::OP_SEMICOLON) &&
654+
!isOperator(pNext, OperatorToken::OP_OPENBRACE) && !isEOF(pNext))
655+
pNext = next();
656+
}
657+
else if (isKeyword(pNext, IdentifierToken::KW_NOEXCEPT))
658+
{
659+
if (pFunc) pFunc->makeNoexcept();
660+
pNext = next();
661+
}
662+
else if (isIdentifier(pNext) && pNext->asString() == "override")
663+
{
664+
if (pFunc) pFunc->makeOverride();
665+
pNext = next();
666+
}
667+
else if (isIdentifier(pNext) && pNext->asString() == "final")
668+
{
669+
if (pFunc) pFunc->makeFinal();
670+
pNext = next();
671+
}
645672
}
646673
if (isOperator(pNext, OperatorToken::OP_ASSIGN))
647674
{
648675
pNext = next();
649-
if (!pNext->is(Token::INTEGER_LITERAL_TOKEN))
650-
syntaxError("0");
676+
if (!pNext->is(Token::INTEGER_LITERAL_TOKEN) && !isKeyword(pNext, IdentifierToken::KW_DEFAULT) && !isKeyword(pNext, IdentifierToken::KW_DELETE))
677+
syntaxError("0, default or delete");
678+
if (isKeyword(pNext, IdentifierToken::KW_DEFAULT))
679+
pFunc->makeDefault();
680+
else if (isKeyword(pNext, IdentifierToken::KW_DELETE))
681+
pFunc->makeDelete();
651682
pNext = next();
652683
if (pFunc) pFunc->makePureVirtual();
653684
expectOperator(pNext, OperatorToken::OP_SEMICOLON, ";");

0 commit comments

Comments
 (0)