xref: /aosp_15_r20/external/emboss/compiler/back_end/cpp/attributes.py (revision 99e0aae7469b87d12f0ad23e61142c2d74c1ef70)
1# Copyright 2023 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Attributes in the C++ backend and associated metadata."""
16
17from enum import Enum
18from compiler.util import attribute_util
19
20
21class Attribute(str, Enum):
22    """Attributes available in the C++ backend."""
23    NAMESPACE = "namespace"
24    ENUM_CASE = "enum_case"
25
26
27# Types associated with C++ backend attributes.
28TYPES = {
29    Attribute.NAMESPACE: attribute_util.STRING,
30    Attribute.ENUM_CASE: attribute_util.STRING,
31}
32
33
34class Scope(set, Enum):
35    """Allowed scopes for C++ backend attributes.
36
37    Each entry is a set of (Attribute, default?) tuples, the first value being
38    the attribute itself, the second value being a boolean value indicating
39    whether the attribute is allowed to be defaulted in that scope."""
40    BITS = {
41        # Bits may contain an enum definition.
42        (Attribute.ENUM_CASE, True)
43    }
44    ENUM = {
45        (Attribute.ENUM_CASE, True),
46    }
47    ENUM_VALUE = {
48        (Attribute.ENUM_CASE, False),
49    }
50    MODULE = {
51        (Attribute.NAMESPACE, False),
52        (Attribute.ENUM_CASE, True),
53    },
54    STRUCT = {
55        # Struct may contain an enum definition.
56        (Attribute.ENUM_CASE, True),
57    }
58