Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: mojo/public/c/bindings/lib/type_table.h

Issue 2072903002: C bindings pt3: Type table definitions and barebones files to get generated code to compile. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Renamed MojomTypeTable* stuff. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file contains structs used for constructing type tables for generated
viettrungluu 2016/06/21 23:06:52 Maybe you should call them "type descriptors" inst
vardhan 2016/06/22 15:18:48 Done.
6 // mojom types. A type table for a mojom struct is a table describing the
7 // byte-offsets of all the pointers and handles in the struct, and has
8 // references to the type tables that further describe the pointers. This table
9 // is used for doing all computations for the struct -- determining serialized
10 // size, encoding and decoding recursively, etc. A type description is generated
11 // for each struct, union, array and map. Note that mojom maps are just mojom
12 // structs with two mojom arrays, so there is no separate descriptor for it.
13 //
14 // The user is not expected to construct type tables -- a bindings generator
15 // will do this when it generates bindings for a mojom file.
16 //
17 // A type table for a mojom struct is a |MojomTypeDescriptorStruct| containing
18 // an array of entries of types of |MojomTypeDescriptorStructEntry|. Similarly,
19 // unions are described with |MojomTypeDescriptorUnion| with entries of
20 // |MojomTypeDescriptorUnionEntry|. Arrays are described with
21 // |MojomTypeDescriptorArray|.
22
23 #ifndef MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
24 #define MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
25
26 #include <stdbool.h>
27 #include <stdint.h>
28
29 #include "mojo/public/c/system/macros.h"
30
31 MOJO_BEGIN_EXTERN_C
32
33 // This enum is used in a type table entry for the |elem_type| field, and
34 // indicates which type the accompanying |elem_table| is describing.
35 enum MojomTypeDescriptorType {
36 // A map is a struct with 2 arrays.
viettrungluu 2016/06/21 23:06:52 Probably you should prepend "Note: " to this. Als
vardhan 2016/06/22 15:18:48 Done.
37 MOJOM_TYPE_DESCRIPTOR_TYPE_STRUCT = 0,
38 MOJOM_TYPE_DESCRIPTOR_TYPE_ARRAY = 1,
39 MOJOM_TYPE_DESCRIPTOR_TYPE_UNION = 2,
40 MOJOM_TYPE_DESCRIPTOR_TYPE_HANDLE = 3,
41 MOJOM_TYPE_DESCRIPTOR_TYPE_INTERFACE = 4,
42 // This is only used in an array table entry, and serves as a way to terminate
43 // a chain of array entries; the last entry in the chain always contains a
44 // plain-old-data type.
45 MOJOM_TYPE_DESCRIPTOR_TYPE_POD = 5,
46 };
47
48 // This struct is used to describe each entry in a mojom struct. Each entry
49 // indicates whether it is describing a reference type, or a handle type through
50 // the field |elem_type|. |elem_table| points to the type descriptor describing
51 // the field, if the type has one (handles don't have type descriptors).
52 // |offset| indicates the starting byte offset of the element within the struct.
53 struct MojomTypeDescriptorStructEntry {
54 // The type that |elem_table| points to.
viettrungluu 2016/06/21 23:06:52 (And then here you could just refer to the comment
vardhan 2016/06/22 15:18:48 Done.
55 // - If MOJOM_TYPE_DESCRIPTOR_TYPE_STRUCT, then |elem_table| points to a
56 // |MojomTypeDescriptorStruct|.
57 // - If MOJOM_TYPE_DESCRIPTOR_TYPE_UNION, then |elem_table| points to a
58 // |MojomTypeDescriptorUnion|.
59 // - If MOJOM_TYPE_DESCRIPTOR_TYPE_ARRAY, then |elem_table| points to a
60 // |MojomTypeDescriptorArray|.
61 // - For any other value, |elem_table| is NULL.
62 enum MojomTypeDescriptorType elem_type;
63 // Use |elem_type| to decide which type |elem_table| should be casted to.
64 const void* elem_table;
65 // |offset| does not account for the struct header. Offset 0 always refers to
66 // the first element.
67 uint32_t offset;
68 // Corresponds to the '[MinVersion]' attribute in mojom IDL. This determines
69 // if this field should be ignored if its min_version < version of the struct
70 // we are dealing with.
71 uint32_t min_version;
72 // Is this field nullable?
73 bool nullable;
74 };
75
76 // Mojom structs are described using this struct.
77 struct MojomTypeDescriptorStruct {
viettrungluu 2016/06/21 23:06:53 Note that since this is C, you can actually put th
vardhan 2016/06/22 15:18:48 cool, done.
78 size_t num_entries;
79 // |entries| is an array of |num_entries|, each describing a field of
80 // reference or handle type.
81 const struct MojomTypeDescriptorStructEntry* entries;
82 };
83
84 // Like |MojomTypeDescriptorStructEntry|, this variant is used to construct a
85 // type table for a union. Instead of an offset, it describes a union field by
86 // its |tag|.
87 struct MojomTypeDescriptorUnionEntry {
88 // The behaviour of |elem_type| and |elem_table| is the same as
89 // |MojomTypeDescriptorStructEntry|.
90 enum MojomTypeDescriptorType elem_type;
91 const void* elem_table;
92 // The tag of the union field.
93 uint32_t tag;
94 bool nullable;
95 };
96
97 // Mojom unions are described using this struct.
98 struct MojomTypeDescriptorUnion {
99 size_t num_entries;
100 const struct MojomTypeDescriptorUnionEntry* entries;
101 };
102
103 // Describes a mojom array. To describe an array, we don't need a type table of
104 // entries, since arrays can only describe 1 type. However, that one type can
105 // recursively be an array (e.g, array<array<int>>), in which case a chain of
106 // array entries are constructed.
107 struct MojomTypeDescriptorArray {
108 enum MojomTypeDescriptorType elem_type;
109 const void* elem_table;
110 // How many elements is this array expected to hold?
111 // 0 means unspecified.
112 uint32_t num_elements;
113 bool nullable;
114 };
115
116 // This describes a mojom string.
117 // A mojom string is a mojom array of chars without a fixed-sized.
118 extern const struct MojomTypeDescriptorArray MojomStringTypeDescription;
viettrungluu 2016/06/21 23:06:53 I was wonder, w.r.t. the name, whether it shouldn'
vardhan 2016/06/22 15:18:48 Done.
119
120 MOJO_END_EXTERN_C
121
122 #endif // MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698