Skip to content

Commit 92d51a8

Browse files
committed
CXX: add "consteval" to "properties:" field
Close #3539. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 78b51af commit 92d51a8

File tree

11 files changed

+57
-1
lines changed

11 files changed

+57
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--sort=no
2+
--kinds-c++=*-{parameter}
3+
--fields=+x
4+
--fields-c++=+{properties}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sqr input.cc /^consteval int sqr(int n)$/;" f typeref:typename:int properties:consteval
2+
r input.cc /^constexpr int r = sqr(100); \/\/ OK$/;" v typeref:typename:int properties:constexpr
3+
x input.cc /^int x = 100;$/;" v typeref:typename:int
4+
r2 input.cc /^int r2 = sqr(x); \/\/ Error: Call does not produce a constant$/;" v typeref:typename:int
5+
sqrsqr input.cc /^consteval int sqrsqr(int n)$/;" f typeref:typename:int properties:consteval
6+
dblsqr input.cc /^constexpr int dblsqr(int n)$/;" f typeref:typename:int properties:constexpr
7+
f input.cc /^consteval int f() { return 42; }$/;" f typeref:typename:int properties:consteval
8+
g input.cc /^consteval auto g() { return &f; }$/;" f typeref:typename:auto properties:consteval
9+
h input.cc /^consteval int h(int (*p)() = g()) { return p(); }$/;" f typeref:typename:int properties:consteval
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Taken from https://en.cppreference.com/w/cpp/language/consteval
2+
consteval int sqr(int n)
3+
{
4+
return n*n;
5+
}
6+
constexpr int r = sqr(100); // OK
7+
8+
int x = 100;
9+
int r2 = sqr(x); // Error: Call does not produce a constant
10+
11+
consteval int sqrsqr(int n)
12+
{
13+
return sqr(sqr(n)); // Not a constant expression at this point, but OK
14+
}
15+
16+
constexpr int dblsqr(int n)
17+
{
18+
return 2 * sqr(n); // Error: Enclosing function is not consteval
19+
// and sqr(n) is not a constant
20+
}
21+
22+
consteval int f() { return 42; }
23+
consteval auto g() { return &f; }
24+
consteval int h(int (*p)() = g()) { return p(); }
25+

parsers/cxx/cxx_keyword.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ static CXXKeywordDescriptor g_aCXXKeywordTable[] = {
212212
CXXLanguageC | CXXLanguageCPP | CXXLanguageCUDA,
213213
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordFlagMayBePartOfTypeName
214214
},
215+
{
216+
"consteval",
217+
CXXLanguageCPP,
218+
CXXKeywordExcludeFromTypeNames
219+
},
215220
{
216221
"constexpr",
217222
CXXLanguageCPP,

parsers/cxx/cxx_keyword.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef enum _CXXKeyword
5252
//CXXKeywordCOMPL,
5353
CXXKeywordCONCEPT, // Concepts TS
5454
CXXKeywordCONST,
55+
CXXKeywordCONSTEVAL, // (since C++20)
5556
CXXKeywordCONSTEXPR, // (since C++11)
5657
CXXKeywordCONST_CAST,
5758
CXXKeywordCONTINUE,
@@ -175,4 +176,4 @@ void cxxKeywordEnableFinal(bool bEnableIt);
175176
bool cxxKeywordIsDisabled(CXXKeyword eKeywordId);
176177

177178

178-
#endif //!ctags_cxx_keyword_h_
179+
#endif //!ctags_cxx_keyword_h_

parsers/cxx/cxx_parser_block.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
640640
case CXXKeywordCONSTEXPR:
641641
g_cxx.uKeywordState |= CXXParserKeywordStateSeenConstexpr;
642642
break;
643+
case CXXKeywordCONSTEVAL:
644+
g_cxx.uKeywordState |= CXXParserKeywordStateSeenConsteval;
645+
break;
643646
default:
644647
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenTypedef)
645648
{

parsers/cxx/cxx_parser_function.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,8 @@ int cxxParserEmitFunctionTags(
17321732
uProperties |= CXXTagPropertyDeprecated;
17331733
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConstexpr)
17341734
uProperties |= CXXTagPropertyConstexpr;
1735+
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConsteval)
1736+
uProperties |= CXXTagPropertyConsteval;
17351737
if(pInfo->pSignatureConst)
17361738
uProperties |= CXXTagPropertyConst;
17371739
if(pInfo->uFlags & CXXFunctionSignatureInfoPure)

parsers/cxx/cxx_parser_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ typedef enum _CXXParserKeywordState
286286
CXXParserKeywordStateSeenFriend = (1 << 12),
287287
// "constexpr" has been seen
288288
CXXParserKeywordStateSeenConstexpr = (1 << 13),
289+
// "consteval" has been seen
290+
CXXParserKeywordStateSeenConsteval = (1 << 14),
289291
} CXXParserKeywordState;
290292

291293
#define CXX_PARSER_MAXIMUM_NESTING_LEVELS 1024

parsers/cxx/cxx_parser_variable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF
759759
// uProperties |= CXXTagPropertyVolatile;
760760
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConstexpr)
761761
uProperties |= CXXTagPropertyConstexpr;
762+
// consteval is not here; it is for functions.
762763

763764
pszProperties = cxxTagSetProperties(uProperties);
764765
}

parsers/cxx/cxx_tag.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ vString * cxxTagSetProperties(unsigned int uProperties)
372372
ADD_PROPERTY("fntryblock");
373373
if (uProperties & CXXTagPropertyConstexpr)
374374
ADD_PROPERTY("constexpr");
375+
if (uProperties & CXXTagPropertyConsteval)
376+
ADD_PROPERTY("consteval");
375377

376378
cxxTagSetField(CXXTagFieldProperties,vStringValue(pszProperties),false);
377379

0 commit comments

Comments
 (0)