Skip to content

Commit

Permalink
[C] Add C11 _Atomic type qualifier and specifier
Browse files Browse the repository at this point in the history
This was originally added in C11. It is an optional feature but
is often available due to being related to threads. It can be
as a type qualifier like const or as a type specifier like typeof.
It is implemented under both syntax rules to reflect this.
  • Loading branch information
James Buren committed Nov 2, 2024
1 parent 0871440 commit 241f317
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions C++/C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ variables:
stdint: 'int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t'
declspec: '__declspec\(\s*\w+(?:\([^)]+\))?\s*\)'
storage_classes: 'static|extern|register|thread_local|_Thread_local|constexpr|{{declspec}}'
type_qualifier: 'const|volatile'
type_qualifier: 'const|volatile|_Atomic'
compiler_directive: 'inline|restrict|__restrict__|__restrict'
modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}'
non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|sizeof|alignof|_Alignof|static_assert|_Static_assert|__declspec|__attribute__'
non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|_Atomic|sizeof|alignof|_Alignof|static_assert|_Static_assert|__declspec|__attribute__'

contexts:
main:
Expand Down Expand Up @@ -251,7 +251,7 @@ contexts:
- include: types-parens

types-parens:
- match: '\b(typeof|__typeof|__typeof__|typeof_unqual)\b\s*(\()'
- match: '\b(typeof|__typeof|__typeof__|typeof_unqual|_Atomic)\b\s*(\()'
captures:
1: keyword.declaration.type.c
2: meta.group.c punctuation.section.group.begin.c
Expand Down
6 changes: 6 additions & 0 deletions C++/syntax_test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ struct foo {
int i;
/* <- storage.type */

_Atomic int ai1;
/* <- storage.modifier */

_Atomic(int) ai2;
/* <- storage.modifier */

thread_local int tl1;
/* <- storage.modifier */

Expand Down

0 comments on commit 241f317

Please sign in to comment.