Commit eac518ae authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

C++: Support __thread and thread_local

Task-number: QTCREATORBUG-7679
Change-Id: I794f52b2bcfb6c78ceef86ec53b6ed32b3d53d9f
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 06612ece
......@@ -803,6 +803,17 @@ static inline int classify8(const char *s, LanguageFeatures features)
}
}
}
else if (s[3] == 'h') {
if (s[4] == 'r') {
if (s[5] == 'e') {
if (s[6] == 'a') {
if (s[7] == 'd') {
return T___THREAD;
}
}
}
}
}
}
}
}
......@@ -1443,6 +1454,31 @@ static inline int classify12(const char *s, LanguageFeatures features)
}
}
}
else if (features.cxx11Enabled && s[0] == 't') {
if (s[1] == 'h') {
if (s[2] == 'r') {
if (s[3] == 'e') {
if (s[4] == 'a') {
if (s[5] == 'd') {
if (s[6] == '_') {
if (s[7] == 'l') {
if (s[8] == 'o') {
if (s[9] == 'c') {
if (s[10] == 'a') {
if (s[11] == 'l') {
return T_THREAD_LOCAL;
}
}
}
}
}
}
}
}
}
}
}
}
return T_IDENTIFIER;
}
......
......@@ -3725,7 +3725,10 @@ bool Parser::lookAtStorageClassSpecifier() const
case T_EXTERN:
case T_MUTABLE:
case T_TYPEDEF:
case T___THREAD:
return true;
case T_THREAD_LOCAL:
return _languageFeatures.cxx11Enabled;
case T_CONSTEXPR:
if (_languageFeatures.cxx11Enabled)
return true;
......
......@@ -57,13 +57,13 @@ const char *token_names[] = {
("nullptr"), ("operator"), ("private"),
("protected"), ("public"), ("register"), ("reinterpret_cast"),
("return"), ("short"), ("signed"), ("sizeof"), ("static"),("static_assert"),
("static_cast"), ("struct"), ("switch"), ("template"), ("this"),
("static_cast"), ("struct"), ("switch"), ("template"), ("this"), ("thread_local"),
("throw"), ("true"), ("try"), ("typedef"), ("typeid"), ("typename"),
("union"), ("unsigned"), ("using"), ("virtual"), ("void"),
("volatile"), ("wchar_t"), ("while"),
// gnu
("__attribute__"), ("__typeof__"),
("__attribute__"), ("__thread"), ("__typeof__"),
// objc @keywords
("@catch"), ("@class"), ("@compatibility_alias"), ("@defs"), ("@dynamic"),
......
......@@ -173,6 +173,7 @@ enum Kind {
T_SWITCH,
T_TEMPLATE,
T_THIS,
T_THREAD_LOCAL,
T_THROW,
T_TRUE,
T_TRY,
......@@ -189,6 +190,7 @@ enum Kind {
T_WHILE,
T___ATTRIBUTE__,
T___THREAD,
T___TYPEOF__,
// obj c++ @ keywords
......
......@@ -107,6 +107,7 @@ private slots:
void gcc_attributes_2();
void gcc_attributes_3();
void crash_test_1();
void thread_local_1();
// expressions
void simple_name_1();
......@@ -246,6 +247,16 @@ void tst_AST::crash_test_1()
QVERIFY(ast);
}
void tst_AST::thread_local_1()
{
QSharedPointer<TranslationUnit> unit(parseStatement("__thread int i;\n"));
AST *ast = unit->ast();
QVERIFY(ast);
QCOMPARE(diag.errorCount, 0);
QCOMPARE(Token::name(T_THREAD_LOCAL), "thread_local");
QCOMPARE(Token::name(T___THREAD), "__thread");
}
void tst_AST::simple_declaration_1()
{
QSharedPointer<TranslationUnit> unit(parseStatement("\n"
......
......@@ -151,6 +151,7 @@ void tst_cxx11::parse_data()
QTest::newRow("templateGreaterGreater.1") << "templateGreaterGreater.1.cpp" << "";
QTest::newRow("packExpansion.1") << "packExpansion.1.cpp" << "";
QTest::newRow("declType.1") << "declType.1.cpp" << "";
QTest::newRow("threadLocal.1") << "threadLocal.1.cpp" << "";
}
void tst_cxx11::parse()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment