Skip to content

Commit 42f6643

Browse files
authored
Misra add c11 keywords (#3448)
1 parent d4174a3 commit 42f6643

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

addons/cppcheckdata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(self, element):
159159

160160
def __repr__(self):
161161
attrs = ["type", "sign", "bits", "typeScopeId", "originalTypeName",
162-
"constness", "constness", "pointer"]
162+
"constness", "pointer"]
163163
return "{}({})".format(
164164
"ValueType",
165165
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
@@ -198,7 +198,7 @@ class Token:
198198
isName Is this token a symbol name
199199
isNumber Is this token a number, for example 123, 12.34
200200
isInt Is this token a int value such as 1234
201-
isFloat Is this token a int value such as 12.34
201+
isFloat Is this token a float value such as 12.34
202202
isString Is this token a string literal such as "hello"
203203
strlen string length for string literal
204204
isChar Is this token a char literal such as 'x'

addons/misra.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import argparse
2525
import codecs
2626
import string
27+
import copy
2728

2829
try:
2930
from itertools import izip as zip
@@ -340,30 +341,37 @@ def isStdLibId(id_, standard='c99'):
340341

341342
# Reserved keywords defined in ISO/IEC9899:1990 -- ch 6.1.1
342343
C90_KEYWORDS = {
343-
'auto', 'break', 'double', 'else', 'enum', 'extern', 'float', 'for',
344-
'goto', 'if', 'case', 'char', 'const', 'continue', 'default', 'do', 'int',
345-
'long', 'struct', 'switch', 'register', 'typedef', 'union', 'unsigned',
346-
'void', 'volatile', 'while', 'return', 'short', 'signed', 'sizeof',
347-
'static'
344+
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
345+
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if',
346+
'int', 'long', 'register', 'return', 'short', 'signed',
347+
'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned',
348+
'void', 'volatile', 'while'
348349
}
349350

350351

351352
# Reserved keywords defined in ISO/IEC 9899 WF14/N1256 -- ch. 6.4.1
352-
C99_KEYWORDS = {
353-
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
354-
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if', 'inline',
355-
'int', 'long', 'register', 'restrict', 'return', 'short', 'signed',
356-
'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned',
357-
'void', 'volatile', 'while', '_Bool', '_Complex', '_Imaginary'
353+
C99_ADDED_KEYWORDS = {
354+
'inline', 'restrict', '_Bool', '_Complex', '_Imaginary',
355+
'bool', 'complex', 'imaginary'
358356
}
359357

358+
C11_ADDED_KEYWORDS = {
359+
'_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn',
360+
'_Statis_assert', '_Thread_local' ,
361+
'alignas', 'alignof', 'noreturn', 'static_assert'
362+
}
360363

361364
def isKeyword(keyword, standard='c99'):
362365
kw_set = {}
363366
if standard == 'c89':
364367
kw_set = C90_KEYWORDS
365368
elif standard == 'c99':
366-
kw_set = C99_KEYWORDS
369+
kw_set = copy.copy(C90_KEYWORDS)
370+
kw_set.update(C99_ADDED_KEYWORDS)
371+
else:
372+
kw_set = copy.copy(C90_KEYWORDS)
373+
kw_set.update(C99_ADDED_KEYWORDS)
374+
kw_set.update(C11_ADDED_KEYWORDS)
367375
return keyword in kw_set
368376

369377

0 commit comments

Comments
 (0)