Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 src: Value* | 38 src: Value* |
| 39 dst: Property* | 39 dst: Property* |
| 40 """ | 40 """ |
| 41 return { | 41 return { |
| 42 PropertyType.STRING: '%s->GetAsString(%s)', | 42 PropertyType.STRING: '%s->GetAsString(%s)', |
| 43 PropertyType.BOOLEAN: '%s->GetAsBoolean(%s)', | 43 PropertyType.BOOLEAN: '%s->GetAsBoolean(%s)', |
| 44 PropertyType.INTEGER: '%s->GetAsInteger(%s)', | 44 PropertyType.INTEGER: '%s->GetAsInteger(%s)', |
| 45 PropertyType.DOUBLE: '%s->GetAsDouble(%s)', | 45 PropertyType.DOUBLE: '%s->GetAsDouble(%s)', |
| 46 }[prop.type_] % (src, dst) | 46 }[prop.type_] % (src, dst) |
| 47 | 47 |
| 48 def GetValueType(prop): | 48 def GetValueType(prop): |
|
Yoyo Zhou
2012/04/09 23:48:47
This would need an additional argument (namespace
cduvall
2012/04/10 03:06:08
Ended up resolving the type before I passed it her
| |
| 49 """Returns the Value::Type corresponding to the model.PropertyType. | 49 """Returns the Value::Type corresponding to the model.PropertyType. |
| 50 """ | 50 """ |
| 51 return { | 51 return { |
| 52 PropertyType.STRING: 'Value::TYPE_STRING', | 52 PropertyType.STRING: 'Value::TYPE_STRING', |
| 53 PropertyType.INTEGER: 'Value::TYPE_INTEGER', | 53 PropertyType.INTEGER: 'Value::TYPE_INTEGER', |
| 54 PropertyType.BOOLEAN: 'Value::TYPE_BOOLEAN', | 54 PropertyType.BOOLEAN: 'Value::TYPE_BOOLEAN', |
| 55 PropertyType.DOUBLE: 'Value::TYPE_DOUBLE', | 55 PropertyType.DOUBLE: 'Value::TYPE_DOUBLE', |
| 56 PropertyType.ENUM: 'Value::TYPE_STRING', | 56 PropertyType.ENUM: 'Value::TYPE_STRING', |
| 57 PropertyType.REF: 'Value::TYPE_DICTIONARY', | 57 PropertyType.REF: 'Value::TYPE_LIST' if prop.is_array |
| 58 else 'Value::TYPE_DICTIONARY', | |
| 58 PropertyType.OBJECT: 'Value::TYPE_DICTIONARY', | 59 PropertyType.OBJECT: 'Value::TYPE_DICTIONARY', |
| 59 PropertyType.ARRAY: 'Value::TYPE_LIST', | 60 PropertyType.ARRAY: 'Value::TYPE_LIST', |
| 60 }[prop.type_] | 61 }[prop.type_] |
| 61 | 62 |
| 62 def GetParameterDeclaration(param, type_): | 63 def GetParameterDeclaration(param, type_): |
| 63 """Gets a parameter declaration of a given model.Property and its C++ | 64 """Gets a parameter declaration of a given model.Property and its C++ |
| 64 type. | 65 type. |
| 65 """ | 66 """ |
| 66 if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, | 67 if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, |
| 67 PropertyType.STRING): | 68 PropertyType.STRING): |
| 68 arg = '%(type)s& %(name)s' | 69 arg = '%(type)s& %(name)s' |
| 69 else: | 70 else: |
| 70 arg = '%(type)s %(name)s' | 71 arg = '%(type)s %(name)s' |
| 71 return arg % { | 72 return arg % { |
| 72 'type': type_, | 73 'type': type_, |
| 73 'name': param.unix_name, | 74 'name': param.unix_name, |
| 74 } | 75 } |
| 75 | 76 |
| 76 def GenerateIfndefName(path, filename): | 77 def GenerateIfndefName(path, filename): |
| 77 """Formats a path and filename as a #define name. | 78 """Formats a path and filename as a #define name. |
| 78 | 79 |
| 79 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__. |
| 80 """ | 81 """ |
| 81 return (('%s_%s_H__' % (path, filename)) | 82 return (('%s_%s_H__' % (path, filename)) |
| 82 .upper().replace(os.sep, '_').replace('/', '_')) | 83 .upper().replace(os.sep, '_').replace('/', '_')) |
| OLD | NEW |