| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
"""C++ keywords and helper utilities for determining keywords.""" |
| 19 |
|
| 20 |
__author__ = '[email protected] (Neal Norwitz)' |
| 21 |
|
| 22 |
|
| 23 |
try: |
| 24 |
|
| 25 |
import builtins |
| 26 |
except ImportError: |
| 27 |
|
| 28 |
import __builtin__ as builtins |
| 29 |
|
| 30 |
|
| 31 |
if not hasattr(builtins, 'set'): |
| 32 |
|
| 33 |
from sets import Set as set |
| 34 |
|
| 35 |
|
| 36 |
TYPES = set('bool char int long short double float void wchar_t unsigned signed'.split()) |
| 37 |
TYPE_MODIFIERS = set('auto register const inline extern static virtual volatile mutable'.split()) |
| 38 |
ACCESS = set('public protected private friend'.split()) |
| 39 |
|
| 40 |
CASTS = set('static_cast const_cast dynamic_cast reinterpret_cast'.split()) |
| 41 |
|
| 42 |
OTHERS = set('true false asm class namespace using explicit this operator sizeof'.split()) |
| 43 |
OTHER_TYPES = set('new delete typedef struct union enum typeid typename template'.split()) |
| 44 |
|
| 45 |
CONTROL = set('case switch default if else return goto'.split()) |
| 46 |
EXCEPTION = set('try catch throw'.split()) |
| 47 |
LOOP = set('while do for break continue'.split()) |
| 48 |
|
| 49 |
ALL = TYPES | TYPE_MODIFIERS | ACCESS | CASTS | OTHERS | OTHER_TYPES | CONTROL | EXCEPTION | LOOP |
| 50 |
|
| 51 |
|
| 52 |
def IsKeyword(token): |
| 53 |
return token in ALL |
| 54 |
|
| 55 |
def IsBuiltinType(token): |
| 56 |
if token in ('virtual', 'inline'): |
| 57 |
|
| 58 |
return False |
| 59 |
return token in TYPES or token in TYPE_MODIFIERS |