summaryrefslogtreecommitdiff
path: root/src/buildstream/node.pxd
blob: fdfa06c70e53a20bb0e039d135e0ad622f8f52b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#
#  Copyright (C) 2019 Bloomberg L.P.
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
#  Authors:
#        Benjamin Schubert <bschubert@bloomberg.net>

# Documentation for each class and method here can be found in the adjacent
# implementation file (_yaml.pyx)

cdef class Node:

    cdef int file_index
    cdef int line
    cdef int column

    # Public Methods
    cpdef Node clone(self)
    cpdef ProvenanceInformation get_provenance(self)

    # Private Methods used in BuildStream
    cpdef void _assert_fully_composited(self) except *
    cpdef object _strip_node_info(self)

    # Protected Methods
    cdef void _compose_on(self, str key, MappingNode target, list path) except *
    cdef bint _is_composite_list(self) except *
    cdef bint _shares_position_with(self, Node target)
    cdef bint _walk_find(self, Node target, list path) except *


cdef class MappingNode(Node):
    cdef dict value

    # Public Methods
    cpdef bint get_bool(self, str key, default=*) except *
    cpdef int get_int(self, str key, default=*) except *
    cpdef MappingNode get_mapping(self, str key, default=*)
    cpdef Node get_node(self, str key, list allowed_types=*, bint allow_none=*)
    cpdef ScalarNode get_scalar(self, str key, default=*)
    cpdef SequenceNode get_sequence(self, str key, object default=*)
    cpdef str get_str(self, str key, object default=*)
    cpdef object items(self)
    cpdef list keys(self)
    cpdef void safe_del(self, str key)
    cpdef void validate_keys(self, list valid_keys) except *
    cpdef object values(self)

    # Private Methods used in BuildStream
    cpdef void _composite(self, MappingNode target) except *
    cpdef void _composite_under(self, MappingNode target) except *
    cpdef list _find(self, Node target)

    # Protected Methods
    cdef void _compose_on_composite_dict(self, MappingNode target)
    cdef void _compose_on_list(self, SequenceNode target)

    # Private Methods
    cdef void __composite(self, MappingNode target, list path=*) except *
    cdef Node _get(self, str key, default, default_constructor)


cdef class ScalarNode(Node):
    cdef str value

    # Public Methods
    cpdef bint as_bool(self) except *
    cpdef int as_int(self) except *
    cpdef str as_str(self)
    cpdef bint is_none(self)


cdef class SequenceNode(Node):
    cdef list value

    # Public Methods
    cpdef void append(self, object value)
    cpdef list as_str_list(self)
    cpdef MappingNode mapping_at(self, int index)
    cpdef Node node_at(self, int index, list allowed_types=*)
    cpdef ScalarNode scalar_at(self, int index)
    cpdef SequenceNode sequence_at(self, int index)


cdef class ProvenanceInformation:

    cdef readonly Node _node
    cdef readonly Node _toplevel
    cdef readonly _project
    cdef readonly bint _is_synthetic
    cdef readonly str _filename
    cdef readonly str _displayname
    cdef readonly str _shortname
    cdef readonly int _col
    cdef readonly int _line


cdef int _SYNTHETIC_FILE_INDEX
cdef Py_ssize_t _create_new_file(str filename, str shortname, str displayname, object project)
cdef void _set_root_node_for_file(Py_ssize_t file_index, MappingNode contents) except *