| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2021 The Meson development team |
| 3 |
|
| 4 |
from dataclasses import dataclass, field |
| 5 |
from enum import Enum |
| 6 |
import typing as T |
| 7 |
|
| 8 |
# Utils |
| 9 |
@dataclass |
| 10 |
class NamedObject: |
| 11 |
name: str |
| 12 |
description: str |
| 13 |
|
| 14 |
@property |
| 15 |
def hidden(self) -> bool: |
| 16 |
return self.name.startswith('_') |
| 17 |
|
| 18 |
@dataclass |
| 19 |
class FetureCheck: |
| 20 |
since: str |
| 21 |
deprecated: str |
| 22 |
|
| 23 |
@dataclass |
| 24 |
class DataTypeInfo: |
| 25 |
data_type: 'Object' |
| 26 |
holds: T.Optional['Type'] |
| 27 |
|
| 28 |
@dataclass |
| 29 |
class Type: |
| 30 |
raw: str |
| 31 |
resolved: T.List[DataTypeInfo] = field(init=False, default_factory=list) |
| 32 |
|
| 33 |
|
| 34 |
# Arguments |
| 35 |
@dataclass |
| 36 |
class ArgBase(NamedObject, FetureCheck): |
| 37 |
type: Type |
| 38 |
|
| 39 |
@dataclass |
| 40 |
class PosArg(ArgBase): |
| 41 |
default: str |
| 42 |
|
| 43 |
@dataclass |
| 44 |
class VarArgs(ArgBase): |
| 45 |
min_varargs: int |
| 46 |
max_varargs: int |
| 47 |
|
| 48 |
@dataclass |
| 49 |
class Kwarg(ArgBase): |
| 50 |
required: bool |
| 51 |
default: str |
| 52 |
|
| 53 |
|
| 54 |
# Function |
| 55 |
@dataclass |
| 56 |
class Function(NamedObject, FetureCheck): |
| 57 |
notes: T.List[str] |
| 58 |
warnings: T.List[str] |
| 59 |
returns: Type |
| 60 |
example: str |
| 61 |
posargs: T.List[PosArg] |
| 62 |
optargs: T.List[PosArg] |
| 63 |
varargs: T.Optional[VarArgs] |
| 64 |
kwargs: T.Dict[str, Kwarg] |
| 65 |
posargs_inherit: str |
| 66 |
optargs_inherit: str |
| 67 |
varargs_inherit: str |
| 68 |
kwargs_inherit: T.List[str] |
| 69 |
arg_flattening: bool |
| 70 |
|
| 71 |
@dataclass |
| 72 |
class Method(Function): |
| 73 |
obj: 'Object' |
| 74 |
|
| 75 |
|
| 76 |
# Types and objects |
| 77 |
class ObjectType(Enum): |
| 78 |
ELEMENTARY = 0 |
| 79 |
BUILTIN = 1 |
| 80 |
MODULE = 2 |
| 81 |
RETURNED = 3 |
| 82 |
|
| 83 |
@dataclass |
| 84 |
class Object(NamedObject, FetureCheck): |
| 85 |
notes: T.List[str] |
| 86 |
warnings: T.List[str] |
| 87 |
long_name: str |
| 88 |
example: str |
| 89 |
obj_type: ObjectType |
| 90 |
methods: T.List[Method] |
| 91 |
is_container: bool |
| 92 |
extends: str |
| 93 |
extends_obj: T.Optional['Object'] = None |
| 94 |
defined_by_module: T.Optional['Object'] = None |
| 95 |
returned_by: T.List[T.Union[Function, Method]] = field(default_factory=list) |
| 96 |
extended_by: T.List['Object'] = field(default_factory=list) |
| 97 |
inherited_methods: T.List[Method] = field(default_factory=list) |
| 98 |
|
| 99 |
# ROOT |
| 100 |
@dataclass |
| 101 |
class ReferenceManual: |
| 102 |
functions: T.List[Function] |
| 103 |
objects: T.List[Object] |