OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 """Utilies and constants specific to Chromium C++ code. | 4 """Utilies and constants specific to Chromium C++ code. |
5 """ | 5 """ |
6 | 6 |
7 from datetime import datetime | 7 from datetime import datetime |
8 from model import PropertyType | 8 from model import PropertyType |
9 import os | 9 import os |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 PropertyType.STRING, PropertyType.ANY): | 68 PropertyType.STRING, PropertyType.ANY): |
69 arg = '%(type)s& %(name)s' | 69 arg = '%(type)s& %(name)s' |
70 else: | 70 else: |
71 arg = '%(type)s %(name)s' | 71 arg = '%(type)s %(name)s' |
72 return arg % { | 72 return arg % { |
73 'type': type_, | 73 'type': type_, |
74 'name': param.unix_name, | 74 'name': param.unix_name, |
75 } | 75 } |
76 | 76 |
77 def GenerateIfndefName(path, filename): | 77 def GenerateIfndefName(path, filename): |
78 """Formats a path and filename as a #define name. | 78 """Formats a path and filename as a #define name. |
79 | 79 |
80 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. | 80 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. |
81 """ | 81 """ |
82 return (('%s_%s_H__' % (path, filename)) | 82 return (('%s_%s_H__' % (path, filename)) |
83 .upper().replace(os.sep, '_').replace('/', '_')) | 83 .upper().replace(os.sep, '_').replace('/', '_')) |
84 | |
85 def GenerateTypeToCompiledTypeConversion(prop, from_, to): | |
86 return _GenerateTypeConversionHelper(prop.type_, prop.compiled_type, from_, | |
87 to) | |
88 | |
89 def GenerateCompiledTypeToTypeConversion(prop, from_, to): | |
90 return _GenerateTypeConversionHelper(prop.compiled_type, prop.type_, from_, | |
91 to) | |
92 | |
93 def _GenerateTypeConversionHelper(from_type, to_type, from_, to): | |
94 """Converts from PropertyType from_type to PropertyType to_type. | |
95 | |
96 from_type: The PropertyType to be converted from. | |
97 to_type: The PropertyType to be converted to. | |
98 from_: The variable name of the type to be converted from. | |
99 to: The variable name of the type to be converted to. | |
100 """ | |
101 # TODO(mwrosen): Add support for more from/to combinations as necessary. | |
102 try: | |
103 return { | |
104 PropertyType.STRING: { | |
105 PropertyType.INTEGER: 'base::StringToInt(%(from)s, &%(to)s)', | |
106 PropertyType.INT_64: 'base::StringToInt64(%(from)s, &%(to)s)' | |
107 }, | |
108 PropertyType.INTEGER: { | |
109 PropertyType.STRING: '%(to)s = base::IntToString(%(from)s)' | |
110 }, | |
111 PropertyType.INT_64: { | |
112 PropertyType.STRING: '%(to)s = base::Int64ToString(%(from)s)' | |
113 } | |
114 }[from_type][to_type] % {'from': from_, 'to': to} | |
115 except KeyError: | |
116 raise NotImplementedError() | |
not at google - send to devlin
2012/07/31 06:37:41
Exception message? "Conversion from blah to blah i
mitchellwrosen
2012/07/31 17:50:25
Right, meant to go back and put that in. I had to
| |
OLD | NEW |