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

Side by Side Diff: tools/json_schema_compiler/cpp_util.py

Issue 9114036: Code generation for extensions api (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: a fistful of rework Created 8 years, 11 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 (c) 2012 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 """Utilies and constants specific to Chromium C++ code.
5 """
6
7 from datetime import datetime
8 from model import PropertyType
9
10 CHROMIUM_LICENSE = (
11 """// Copyright (c) %d The Chromium Authors. All rights reserved.
12 // Use of this source code is governed by a BSD-style license that can be
13 // found in the LICENSE file.""" % datetime.now().year
14 )
15 GENERATED_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITION IN
16 // %s
17 // DO NOT EDIT.
18 """
19
20 def cpp_name(s):
Yoyo Zhou 2012/01/19 02:19:40 Separate top-level function and class definitions
calamity 2012/01/20 01:10:25 Done.
21 """Translates a namespace name or function name into something more
22 suited to C++.
23
24 eg experimental.downloads -> Experimental_Downloads
25 updateAll -> UpdateAll.
26 """
27 return '_'.join([x[0].upper() + x[1:] for x in s.split('.')])
Yoyo Zhou 2012/01/19 02:19:40 x.capitalize()
calamity 2012/01/20 01:10:25 Capitalize inconveniently lowercases everything af
Yoyo Zhou 2012/01/23 23:16:42 Oh, sadness.
28
29 def create_fundamental_value(prop, var):
30 """Returns the C++ code for creating a value of the given property type
31 using the given variable.
32 """
33 return {
34 PropertyType.STRING: 'Value::CreateStringValue(%s)',
35 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)',
36 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)',
37 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)',
38 }[prop.type] % var
39
40
41 def get_fundamental_value(prop, var):
42 """Returns the C++ code for retrieving a fundamental type from a Value
43 into a variable.
44 """
45 return {
46 PropertyType.STRING: 'GetAsString(%s)',
47 PropertyType.BOOLEAN: 'GetAsBoolean(%s)',
48 PropertyType.INTEGER: 'GetAsInteger(%s)',
49 PropertyType.DOUBLE: 'GetAsDouble(%s)',
50 }[prop.type] % var
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698