Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-09 08:19:08

0001 #!/usr/bin/env python
0002 #
0003 # Copyright 2007 Neal Norwitz
0004 # Portions Copyright 2007 Google Inc.
0005 #
0006 # Licensed under the Apache License, Version 2.0 (the "License");
0007 # you may not use this file except in compliance with the License.
0008 # You may obtain a copy of the License at
0009 #
0010 #      http://www.apache.org/licenses/LICENSE-2.0
0011 #
0012 # Unless required by applicable law or agreed to in writing, software
0013 # distributed under the License is distributed on an "AS IS" BASIS,
0014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015 # See the License for the specific language governing permissions and
0016 # limitations under the License.
0017 
0018 """C++ keywords and helper utilities for determining keywords."""
0019 
0020 __author__ = 'nnorwitz@google.com (Neal Norwitz)'
0021 
0022 
0023 try:
0024     # Python 3.x
0025     import builtins
0026 except ImportError:
0027     # Python 2.x
0028     import __builtin__ as builtins
0029 
0030 
0031 if not hasattr(builtins, 'set'):
0032     # Nominal support for Python 2.3.
0033     from sets import Set as set
0034 
0035 
0036 TYPES = set('bool char int long short double float void wchar_t unsigned signed'.split())
0037 TYPE_MODIFIERS = set('auto register const inline extern static virtual volatile mutable'.split())
0038 ACCESS = set('public protected private friend'.split())
0039 
0040 CASTS = set('static_cast const_cast dynamic_cast reinterpret_cast'.split())
0041 
0042 OTHERS = set('true false asm class namespace using explicit this operator sizeof'.split())
0043 OTHER_TYPES = set('new delete typedef struct union enum typeid typename template'.split())
0044 
0045 CONTROL = set('case switch default if else return goto'.split())
0046 EXCEPTION = set('try catch throw'.split())
0047 LOOP = set('while do for break continue'.split())
0048 
0049 ALL = TYPES | TYPE_MODIFIERS | ACCESS | CASTS | OTHERS | OTHER_TYPES | CONTROL | EXCEPTION | LOOP
0050 
0051 
0052 def IsKeyword(token):
0053     return token in ALL
0054 
0055 def IsBuiltinType(token):
0056     if token in ('virtual', 'inline'):
0057         # These only apply to methods, they can't be types by themselves.
0058         return False
0059     return token in TYPES or token in TYPE_MODIFIERS