Misra add c11 keywords (#3448)

This commit is contained in:
PeterSchops 2021-09-06 20:13:15 +02:00 committed by GitHub
parent d4174a31ba
commit 42f66433bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

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

View File

@ -24,6 +24,7 @@ import os
import argparse
import codecs
import string
import copy
try:
from itertools import izip as zip
@ -340,30 +341,37 @@ def isStdLibId(id_, standard='c99'):
# Reserved keywords defined in ISO/IEC9899:1990 -- ch 6.1.1
C90_KEYWORDS = {
'auto', 'break', 'double', 'else', 'enum', 'extern', 'float', 'for',
'goto', 'if', 'case', 'char', 'const', 'continue', 'default', 'do', 'int',
'long', 'struct', 'switch', 'register', 'typedef', 'union', 'unsigned',
'void', 'volatile', 'while', 'return', 'short', 'signed', 'sizeof',
'static'
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if',
'int', 'long', 'register', 'return', 'short', 'signed',
'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned',
'void', 'volatile', 'while'
}
# Reserved keywords defined in ISO/IEC 9899 WF14/N1256 -- ch. 6.4.1
C99_KEYWORDS = {
'auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if', 'inline',
'int', 'long', 'register', 'restrict', 'return', 'short', 'signed',
'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned',
'void', 'volatile', 'while', '_Bool', '_Complex', '_Imaginary'
C99_ADDED_KEYWORDS = {
'inline', 'restrict', '_Bool', '_Complex', '_Imaginary',
'bool', 'complex', 'imaginary'
}
C11_ADDED_KEYWORDS = {
'_Alignas', '_Alignof', '_Atomic', '_Generic', '_Noreturn',
'_Statis_assert', '_Thread_local' ,
'alignas', 'alignof', 'noreturn', 'static_assert'
}
def isKeyword(keyword, standard='c99'):
kw_set = {}
if standard == 'c89':
kw_set = C90_KEYWORDS
elif standard == 'c99':
kw_set = C99_KEYWORDS
kw_set = copy.copy(C90_KEYWORDS)
kw_set.update(C99_ADDED_KEYWORDS)
else:
kw_set = copy.copy(C90_KEYWORDS)
kw_set.update(C99_ADDED_KEYWORDS)
kw_set.update(C11_ADDED_KEYWORDS)
return keyword in kw_set