Skip to content

Commit

Permalink
C++: add "thread_local" to "properties:" field instead of recording t…
Browse files Browse the repository at this point in the history
…he keyword as a part of typeref

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 18, 2022
1 parent f616464 commit 29bcaad
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Units/parser-cxx.r/properties-constinit.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
g input.cc /^const char *g() { return "dynamic initialization"; }$/;" f typeref:typename:const char *
f input.cc /^constexpr const char *f(bool p) { return p ? "constant initializer" : g(); }$/;" f typeref:typename:const char * properties:constexpr
c input.cc /^constinit const char *c = f(true); \/\/ OK$/;" v typeref:typename:const char * properties:constinit
x input.cc /^extern thread_local constinit int x;$/;" x typeref:typename:thread_local int properties:extern,constinit
x input.cc /^extern thread_local constinit int x;$/;" x typeref:typename:int properties:extern,constinit,thread_local
f input.cc /^int f() { return x; } \/\/ no check of a guard variable needed$/;" f typeref:typename:int
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_keyword.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static CXXKeywordDescriptor g_aCXXKeywordTable[] = {
{
"thread_local",
CXXLanguageCPP,
CXXKeywordMayAppearInVariableDeclaration
CXXKeywordMayAppearInVariableDeclaration | CXXKeywordExcludeFromTypeNames
},
{
"throw",
Expand Down
4 changes: 4 additions & 0 deletions parsers/cxx/cxx_parser_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ static bool cxxParserParseBlockInternal(bool bExpectClosingBracket)
case CXXKeywordCONSTINIT:
g_cxx.uKeywordState |= CXXParserKeywordStateSeenConstinit;
break;
case CXXKeywordTHREAD_LOCAL:
g_cxx.uKeywordState |= CXXParserKeywordStateSeenThreadLocal;
break;

default:
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenTypedef)
{
Expand Down
2 changes: 2 additions & 0 deletions parsers/cxx/cxx_parser_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ typedef enum _CXXParserKeywordState
CXXParserKeywordStateSeenConsteval = (1 << 14),
// "constinit" has been seen
CXXParserKeywordStateSeenConstinit = (1 << 15),
// "thread_local" has been seen
CXXParserKeywordStateSeenThreadLocal = (1 << 16),
} CXXParserKeywordState;

#define CXX_PARSER_MAXIMUM_NESTING_LEVELS 1024
Expand Down
2 changes: 2 additions & 0 deletions parsers/cxx/cxx_parser_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ bool cxxParserExtractVariableDeclarations(CXXTokenChain * pChain,unsigned int uF
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenConstinit)
uProperties |= CXXTagPropertyConstinit;
// consteval is not here; it is for functions.
if(g_cxx.uKeywordState & CXXParserKeywordStateSeenThreadLocal)
uProperties |= CXXTagPropertyThreadLocal;

pszProperties = cxxTagSetProperties(uProperties);
}
Expand Down
2 changes: 2 additions & 0 deletions parsers/cxx/cxx_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ vString * cxxTagSetProperties(unsigned int uProperties)
ADD_PROPERTY("consteval");
if (uProperties & CXXTagPropertyConstinit)
ADD_PROPERTY("constinit");
if (uProperties & CXXTagPropertyThreadLocal)
ADD_PROPERTY("thread_local");

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

Expand Down
2 changes: 2 additions & 0 deletions parsers/cxx/cxx_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ typedef enum _CXXTagProperty
CXXTagPropertyConsteval = (1 << 19),
// constinit has been seen.
CXXTagPropertyConstinit = (1 << 20),
// thread_local has been seen.
CXXTagPropertyThreadLocal = (1 << 21),
} CXXTagProperty;

// Set the modifiers field of the tag.
Expand Down

0 comments on commit 29bcaad

Please sign in to comment.