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

Issue 1982193002: Add enum class support to json_schema_compiler (idl files)

Created:
4 years, 7 months ago by tapted
Modified:
4 years, 7 months ago
Reviewers:
Devlin
CC:
chromium-reviews, asanka, sadrul, hcarmona+bubble_chromium.org, shuchen+watch_chromium.org, bondd+autofillwatch_chromium.org, dmazzoni+watch_chromium.org, stevenjb+watch_chromium.org, yusukes+watch_chromium.org, extensions-reviews_chromium.org, msw+watch_chromium.org, Matt Giuca, nona+watch_chromium.org, aboxhall+watch_chromium.org, jam, Peter Beverloo, je_julie, darin-cc_chromium.org, vabr+watchlistautofill_chromium.org, kalyank, mlamouri+watch-content_chromium.org, vabr+watchlistpasswordmanager_chromium.org, derat+watch_chromium.org, tapted, rouslan+autofill_chromium.org, mlamouri+watch-notifications_chromium.org, yuzo+watch_chromium.org, oshima+watch_chromium.org, chromium-apps-reviews_chromium.org, gcasto+watchlist_chromium.org, dbeam+watch-downloads_chromium.org, rouslan+bubble_chromium.org, mkwst+watchlist-passwords_chromium.org, groby+bubble_chromium.org, tfarina, nektar+watch_chromium.org, jdonnelly+autofillwatch_chromium.org, dtseng+watch_chromium.org, mkwst+moarreviews-renderer_chromium.org, estade+watch_chromium.org, James Su, davemoore+watch_chromium.org, chrome-apps-syd-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add enum class support to json_schema_compiler (idl files) Allows an .idl file to generate headers with enum classes that can be forward declared. This can help avoid a proliferation of transitive "hard" dependencies where a generated header needs to be included from a component's publicly exposed headers. To change an enum to an enum class, simply prefix with [enum_class]. E.g. "enum Foo { a };" changes to "[enum_class] enum Foo { a };" Then instead of generating enum Foo { FOO_NONE, FOO_A, FOO_LAST = FOO_A }; generates enum class Foo { NONE, A, LAST = A }; BUG=611898, 612382

Patch Set 1 #

Patch Set 2 : rebase #

Patch Set 3 : iwyu #

Patch Set 4 : Adds a test #

Patch Set 5 : Move AXEVent conversion to crrev.com/1988613002 #

Patch Set 6 : nit python style #

Total comments: 8

Patch Set 7 : enum -> enum_class #

Patch Set 8 : enum -> enum_class, TODOs #

Total comments: 4

Patch Set 9 : is_enum_class, fix ternary #

Patch Set 10 : I accidentally a patchset dependency #

Unified diffs Side-by-side diffs Delta from patch set Stats (+112 lines, -18 lines) Patch
M tools/json_schema_compiler/cc_generator.py View 4 chunks +4 lines, -4 lines 0 comments Download
M tools/json_schema_compiler/cpp_type_generator.py View 1 2 3 4 5 6 7 8 1 chunk +25 lines, -9 lines 0 comments Download
M tools/json_schema_compiler/h_generator.py View 1 2 3 4 5 6 7 8 1 chunk +8 lines, -4 lines 0 comments Download
M tools/json_schema_compiler/idl_schema.py View 1 2 3 4 5 6 7 1 chunk +3 lines, -1 line 0 comments Download
M tools/json_schema_compiler/model.py View 1 2 3 4 5 6 7 8 1 chunk +3 lines, -0 lines 0 comments Download
M tools/json_schema_compiler/test/idl_basics.idl View 1 2 3 4 5 6 2 chunks +22 lines, -0 lines 0 comments Download
M tools/json_schema_compiler/test/idl_schemas_unittest.cc View 1 2 3 1 chunk +47 lines, -0 lines 0 comments Download

Messages

Total messages: 12 (7 generated)
tapted
Guess I might as well publish this out. Follow-up that applies this to AXEvent is ...
4 years, 7 months ago (2016-05-17 12:59:44 UTC) #7
Devlin
Is the goal to eventually fully phase out vanilla enums here? (I'd be supportive of ...
4 years, 7 months ago (2016-05-17 19:04:11 UTC) #8
tapted
On 2016/05/17 19:04:11, Devlin wrote: > Is the goal to eventually fully phase out vanilla ...
4 years, 7 months ago (2016-05-18 09:35:54 UTC) #10
Devlin
lgtm https://codereview.chromium.org/1982193002/diff/140001/tools/json_schema_compiler/cpp_type_generator.py File tools/json_schema_compiler/cpp_type_generator.py (right): https://codereview.chromium.org/1982193002/diff/140001/tools/json_schema_compiler/cpp_type_generator.py#newcode58 tools/json_schema_compiler/cpp_type_generator.py:58: return self._AddEnumScope(type_, 'NONE', is_in_declaration, False) On 2016/05/18 09:35:54, ...
4 years, 7 months ago (2016-05-19 00:33:12 UTC) #11
tapted
4 years, 7 months ago (2016-05-19 12:22:33 UTC) #12
(I'll wait for after branch for this - I don't think it's risky, but there's no
point stressing things)

https://codereview.chromium.org/1982193002/diff/140001/tools/json_schema_comp...
File tools/json_schema_compiler/cpp_type_generator.py (right):

https://codereview.chromium.org/1982193002/diff/140001/tools/json_schema_comp...
tools/json_schema_compiler/cpp_type_generator.py:58: return
self._AddEnumScope(type_, 'NONE', is_in_declaration, False)
On 2016/05/19 00:33:12, Devlin wrote:
> On 2016/05/18 09:35:54, tapted wrote:
> > On 2016/05/17 19:04:10, Devlin wrote:
> > > The fact that optional enums are NONEs instead of just an empty unique_ptr
> is
> > > pretty annoying, and there's even a TODO lying around to fix it. [1] 
Since
> > > everywhere we change to an enum class will have to be updated, maybe this
is
> a
> > > good time to change that?  WDYT?
> > 
> > [1] -> null pointer? :)
> > 
> > But I think it would be tricky to map a unique_ptr into the use cases for
> things
> > like AXEvent and other things from ax_enums.idl. The same enums are used
> > extensively in browser-only UI, without touching json at all (no
base::*Value
> > etc.). And, e.g., ui::AX_EVENT_NONE is used often as a sentinel value. So I
> > think we would still need `NONE` at least for the stuff in ax_enums.idl, but
> we
> > could perhaps phase it out of some other generated types that only ever
> operate
> > using base::Value and `NONE` is an error state rather than a ~"don't care"
> > state.
> 
> Whoops, [1] ->
>
https://code.google.com/p/chromium/codesearch#chromium/src/tools/json_schema_...
> 
> Is there any case outside of ax events that actually uses NONE for something
> other than optional values?  It's really inconsistent, so I'd like to fix it
at
> some point, and, given that this is a massive enum overhauling, it seemed
> appropriate.  But... ah well.

`git grep ui::AX.*NONE` shows up a lot of other ax examples that would be tricky
to migrate from `none` (e.g. AX_ROLE, and others apart from AX_EVENT). And while
`git grep -C10 'api::.*_NONE'` under extensions/browser/api shows up mostly
error-state handling (DCHECK, NOTREACHED, and so forth), there are a lot of
situations where an enum is returned, and there's some logic that requires it to
be initialized to "some" value beforehand.

The change to make these methods return, e.g., a scoped_ptr<base::Value> instead
of an enum wouldn't be mechanical. Whereas changing from an enum to an enum
class is almost purely mechanical -- a simple sed script and `git cl format` do
most of the job. All that was left in the AXEvent change in
http://crrev.com/1988613002 was adding a static_cast<int> to an stream output.
So, while it is an overhaul, it's a straightforward one.

https://codereview.chromium.org/1982193002/diff/180001/tools/json_schema_comp...
File tools/json_schema_compiler/h_generator.py (right):

https://codereview.chromium.org/1982193002/diff/180001/tools/json_schema_comp...
tools/json_schema_compiler/h_generator.py:144: c.Sblock('enum %s%s {' %
(type_.is_class and 'class ' or '', enum_name))
On 2016/05/19 00:33:12, Devlin wrote:
> ha nifty, but is this pythonic?  Maybe it's my c++-brain, but I think I'd
still
> prefer:
> 'class ' if type_.is_class else ''

Ah, apparently this is me revealing how long it's been since I've done serious
python :). My brain had C++'s ternary if-else wired to this construct, but
Python 2.5 introduced an actual ternary syntax "A if condition else B" which is
used elsewhere in json_schema_compiler - so I've switched over to that.

https://codereview.chromium.org/1982193002/diff/180001/tools/json_schema_comp...
File tools/json_schema_compiler/model.py (right):

https://codereview.chromium.org/1982193002/diff/180001/tools/json_schema_comp...
tools/json_schema_compiler/model.py:215: self.is_class = json.get('enum_class',
False)
On 2016/05/19 00:33:12, Devlin wrote:
> nit: here, too, I'd prefer this to be enum_class or is_enum_class.

Done.

Powered by Google App Engine
This is Rietveld 408576698