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

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: tiny cleanup in the generator 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
« no previous file with comments | « mojo/public/c/bindings/interface.h ('k') | mojo/public/c/bindings/lib/type_table.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 table is generated for
11 // each struct, union, array and map.
12 //
13 // The user is not expected to construct type tables -- a bindings generator
14 // will do this when it generates bindings for a mojom file.
15 //
16 // A type table for a mojom struct and a mojom union is a |MojomTypeTable| with
17 // containing an array of entries of types of |MojomTypeTableStructEntry| and
18 // |MojomTypeTableUnionEntry|, respectively.
19 // Since arrays only have one type, they are described by
20 // |MojomTypeTableArrayEntry|, not contained inside a |MojomTypeTable|.
21
22 #ifndef MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
23 #define MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
24
25 #include <stdbool.h>
26 #include <stdint.h>
27
28 #include "mojo/public/c/system/macros.h"
29
30 MOJO_BEGIN_EXTERN_C
31
32 // This enum is used in a type table entry for the |elem_type| field, and
33 // indicates which type the accompanying |elem_table| is describing.
34 enum MojomTypeTableElemType {
35 // A map is a struct with 2 arrays.
36 MOJOM_ELEMENT_TYPE_STRUCT = 0,
37 MOJOM_ELEMENT_TYPE_ARRAY = 1,
38 MOJOM_ELEMENT_TYPE_UNION = 2,
39 MOJOM_ELEMENT_TYPE_HANDLE = 3,
40 MOJOM_ELEMENT_TYPE_INTERFACE = 4,
41 // This is only used in an array table entry, and serves as a way to terminate
42 // a chain of array entries; the last entry in the chain always contains a
43 // plain-old-data type.
44 MOJOM_ELEMENT_TYPE_POD = 5,
45 };
46
47 // Structs and unions are described using this struct; |entries| is of type
viettrungluu 2016/06/21 18:08:30 I suggest you just make two separate structs (with
vardhan 2016/06/21 22:42:58 Done.
48 // |MojomTypeTableStructEntry| for mojom structs, and |MojomTypeTableUnion|
49 // for mojom unions.
50 struct MojomTypeTable {
51 size_t num_entries;
52 const void* entries;
53 };
54
55 // This struct is used to describe each entry in a mojom struct. Each entry
56 // indicates whether it is describing a reference type, or a handle type through
57 // the field |elem_type|. |elem_table| points to the type table describing the
58 // field, if the type has one (handles don't have type tables). |offset|
59 // indicates the starting byte offset of the element within the struct.
60 struct MojomTypeTableStructEntry {
61 // The type that |elem_table| points to.
62 // - If MOJOM_ELEMENT_TYPE_STRUCT, then |elem_table| points to a
63 // |MojomTypeTable|, with its |entries| field pointing to an array of
64 // |MojomTypeTableStructEntry|.
65 // - If MOJOM_ELEMENT_TYPE_UNION, then |elem_table| points to a
66 // |MojomTypeTable|, with its |entries| field pointing to an array of
67 // |MojomTypeTableUnionEntry|.
68 // - If MOJOM_ELEMENT_TYPE_ARRAY, then |elem_table| points to a
69 // |MojomTypeTableArrayEntry|.
70 // - For any other value, |elem_table| is NULL.
71 enum MojomTypeTableElemType elem_type;
72 // |elem_table| can be |MojomTypeTable|, MojomTypeTableArrayEntry|, or NULL.
viettrungluu 2016/06/21 18:08:30 I think you should rationalize the names of things
vardhan 2016/06/21 22:42:58 Done.
73 // Use |elem_type| to decide which it is.
74 const void* elem_table;
75 // |offset| does not account for the struct header. Offset 0 always refers to
76 // the first element.
77 uint32_t offset;
78 // Corresponds to the '[MinVersion]' attribute in mojom IDL. This determines
79 // if this field should be ignored if its min_version < version of the struct
80 // we are dealing with.
81 uint32_t min_version;
82 // Is this field nullable?
83 bool nullable;
84 };
85
86 // Like |MojomTypeTableStructEntry|, this variant is used to construct a type
87 // table for a union. Instead of an offset, it describes a union field by the
88 // |tag|.
89 struct MojomTypeTableUnionEntry {
90 // The behaviour of |elem_type| and |elem_table| is the same as
91 // |MojomTypeTableStructEntry|.
92 enum MojomTypeTableElemType elem_type;
93 const void* elem_table;
94 // The tag of the union field.
95 uint32_t tag;
96 bool nullable;
97 };
98
99 // Describes a mojom array. To describe an array, we don't need a type table of
100 // entries, since arrays can only describe 1 type. However, that one type can
101 // recursively be an array (e.g, array<array<int>>), in which case a
102 // chain of array entries are constructed.
103 struct MojomTypeTableArrayEntry {
104 enum MojomTypeTableElemType elem_type;
105 const void* elem_table;
106 // How many elements is this array expected to hold?
107 // 0 means unspecified.
108 uint32_t num_elements;
109 bool nullable;
110 };
111
112 // This describes a mojom string.
113 // A mojom string is a mojom array of chars without a fixed-sized.
114 extern const struct MojomTypeTableArrayEntry MojomTypeTableStringEntry;
viettrungluu 2016/06/21 18:08:30 It's very odd that MojomTypeTableStringEntry is no
vardhan 2016/06/21 22:42:58 Renamed to MojomStringTypeDescription.
115
116 MOJO_END_EXTERN_C
117
118 #endif // MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/interface.h ('k') | mojo/public/c/bindings/lib/type_table.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698