1f92157deSopenharmony_ci#!/usr/bin/env python
2f92157deSopenharmony_ci#
3f92157deSopenharmony_ci# Copyright 2007 Neal Norwitz
4f92157deSopenharmony_ci# Portions Copyright 2007 Google Inc.
5f92157deSopenharmony_ci#
6f92157deSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
7f92157deSopenharmony_ci# you may not use this file except in compliance with the License.
8f92157deSopenharmony_ci# You may obtain a copy of the License at
9f92157deSopenharmony_ci#
10f92157deSopenharmony_ci#      http://www.apache.org/licenses/LICENSE-2.0
11f92157deSopenharmony_ci#
12f92157deSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
13f92157deSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
14f92157deSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15f92157deSopenharmony_ci# See the License for the specific language governing permissions and
16f92157deSopenharmony_ci# limitations under the License.
17f92157deSopenharmony_ci
18f92157deSopenharmony_ci"""C++ keywords and helper utilities for determining keywords."""
19f92157deSopenharmony_ci
20f92157deSopenharmony_citry:
21f92157deSopenharmony_ci    # Python 3.x
22f92157deSopenharmony_ci    import builtins
23f92157deSopenharmony_ciexcept ImportError:
24f92157deSopenharmony_ci    # Python 2.x
25f92157deSopenharmony_ci    import __builtin__ as builtins
26f92157deSopenharmony_ci
27f92157deSopenharmony_ci
28f92157deSopenharmony_ciif not hasattr(builtins, 'set'):
29f92157deSopenharmony_ci    # Nominal support for Python 2.3.
30f92157deSopenharmony_ci    from sets import Set as set
31f92157deSopenharmony_ci
32f92157deSopenharmony_ci
33f92157deSopenharmony_ciTYPES = set('bool char int long short double float void wchar_t unsigned signed'.split())
34f92157deSopenharmony_ciTYPE_MODIFIERS = set('auto register const inline extern static virtual volatile mutable'.split())
35f92157deSopenharmony_ciACCESS = set('public protected private friend'.split())
36f92157deSopenharmony_ci
37f92157deSopenharmony_ciCASTS = set('static_cast const_cast dynamic_cast reinterpret_cast'.split())
38f92157deSopenharmony_ci
39f92157deSopenharmony_ciOTHERS = set('true false asm class namespace using explicit this operator sizeof'.split())
40f92157deSopenharmony_ciOTHER_TYPES = set('new delete typedef struct union enum typeid typename template'.split())
41f92157deSopenharmony_ci
42f92157deSopenharmony_ciCONTROL = set('case switch default if else return goto'.split())
43f92157deSopenharmony_ciEXCEPTION = set('try catch throw'.split())
44f92157deSopenharmony_ciLOOP = set('while do for break continue'.split())
45f92157deSopenharmony_ci
46f92157deSopenharmony_ciALL = TYPES | TYPE_MODIFIERS | ACCESS | CASTS | OTHERS | OTHER_TYPES | CONTROL | EXCEPTION | LOOP
47f92157deSopenharmony_ci
48f92157deSopenharmony_ci
49f92157deSopenharmony_cidef IsKeyword(token):
50f92157deSopenharmony_ci    return token in ALL
51f92157deSopenharmony_ci
52f92157deSopenharmony_cidef IsBuiltinType(token):
53f92157deSopenharmony_ci    if token in ('virtual', 'inline'):
54f92157deSopenharmony_ci        # These only apply to methods, they can't be types by themselves.
55f92157deSopenharmony_ci        return False
56f92157deSopenharmony_ci    return token in TYPES or token in TYPE_MODIFIERS
57