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

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: cflags_c = std=c11 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
6 // mojom types. A type table for a mojom struct is a table describing where all
7 // the pointers and handles are, and references to the type tables that further
viettrungluu 2016/06/17 20:37:19 - where all the pointers and handles are in what?
vardhan 2016/06/21 16:07:36 Done.
8 // describe the pointers. This table is used for doing all computations for the
9 // struct -- determining serialized size, encoding and decoding recursively,
10 // etc. A type table is generated for each struct, union, array and map.
11 //
12 // The user is not expected to construct type tables -- a bindings generator
13 // will do this when it generates bindings for a mojom file.
14 //
15 // A type table for a mojom struct is an array of entries of type
viettrungluu 2016/06/17 20:37:19 So, if I understand you correctly, the |const void
vardhan 2016/06/21 16:07:36 Yes.
16 // |MojomPointerTableStructEntry|.
17 // Arrays are described using |MojomPointerTableArrayEntry|, and they are not
18 // tables -- an array entry simply describes 1 entry, the array's type.
19 // Unions are described using |MojomPointerTableUnionEntry|. They do not contain
20 // offsets, but instead contain the tag the field is meant to describe.
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 MojomPointerTableElemType {
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
40 MOJOM_ELEMENT_TYPE_HANDLE = 3,
41 MOJOM_ELEMENT_TYPE_INTERFACE = 4,
42
43 // This is only used in an array table entry, and serves as a way to terminate
44 // a chain of array entries.
45 MOJOM_ELEMENT_TYPE_POD = 5,
46 };
47
48 // The size of the type table is not directly encoded into any of the entries.
49 // Instead, each entry has a |keep_going| field which indicates that there is a
50 // following entry. Each entry indicates whether it is describing a reference
51 // type, or a handle type through the field |elem_type| (which is an enum of
52 // |MojomPointerTableElemType|). |offset| indicates the (within the struct)
53 // starting byte offset of the element. |elem_table| points to the type table
54 // describing the field, if the type has one (handles don't have type tables).
55 struct MojomPointerTableStructEntry {
56 // |elem_table| can be |MojomPointerTableStructEntry|,
57 // |MojomPointerTableUnionEntry|, |MojomPointerTableArrayEntry|, or NULL.
58 // Use |elem_type| to decide which it is.
59 const void* elem_table;
60 // |offset| does not account for the struct header. Offset 0 always refers to
61 // the first element.
62 uint32_t offset;
63 // Corresponds to the '[MinVersion]' attribute in mojom IDL. This determines
64 // if this field should be ignored if its min_version < version of the struct
65 // we are dealing with.
66 uint32_t min_version;
67 // The type that |elem_table| points to.
68 enum MojomPointerTableElemType elem_type;
viettrungluu 2016/06/17 20:37:19 As a matter of readability, this should be immedia
vardhan 2016/06/21 16:07:36 Done.
69 // Is this field nullable?
70 bool nullable;
71 // Are there more entries after this? (the last |MojomPointerTableStructEntry|
viettrungluu 2016/06/17 20:37:19 At the very least, you're missing a closing ')'...
vardhan 2016/06/21 16:07:36 (removed all-together)
72 bool keep_going;
73 };
74
75 // Like |MojomPointerTableStructEntry|, this variant is used to construct a type
76 // table for a union. Instead of an offset, it describes a union field by the
77 // |tag|.
78 struct MojomPointerTableUnionEntry {
79 const void* elem_table;
80 // The tag of the union field.
81 uint32_t tag;
82 enum MojomPointerTableElemType elem_type;
83 bool nullable;
84 bool keep_going;
85 };
86
87 // Describes an array. To describe an array, we don't need a type table, arrays
88 // can only describe 1 type. However, that one type can recursively be an array
89 // (e.g, array<array<array<int>>>), so an array entry, if it contains another
90 // array.
91 struct MojomPointerTableArrayEntry {
92 const void* elem_table;
93 // How many elements is this array expected to hold?
94 // 0 means unspecified.
95 uint32_t num_elements;
96 enum MojomPointerTableElemType elem_type;
97 bool nullable;
98 };
99
100 // This describes a mojom string.
101 // A mojom string is a mojom array of chars without a fixed-sized.
102 extern const struct MojomPointerTableArrayEntry MojomStringPointerEntry;
103
104 MOJO_END_EXTERN_C
105
106 #endif // MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698