Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.systemnative.CPPLibraryEmitter Class Reference

Public Member Functions

def __init__ (self, emitters, cpp_sources_dir)
 
def CreateHeaderEmitter (self, interface_name, library_name, is_callback=False)
 
def CreateSourceEmitter (self, interface_name)
 
def EmitDerivedSources (self, template, output_dir)
 
def EmitResolver (self, template, output_dir)
 
def EmitClassIdTable (self, database, output_dir, type_registry, renamer)
 

Detailed Description

Definition at line 1162 of file systemnative.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.systemnative.CPPLibraryEmitter.__init__ (   self,
  emitters,
  cpp_sources_dir 
)

Definition at line 1164 of file systemnative.py.

1164 def __init__(self, emitters, cpp_sources_dir):
1165 self._emitters = emitters
1166 self._cpp_sources_dir = cpp_sources_dir
1167 self._library_headers = dict((lib, []) for lib in HTML_LIBRARY_NAMES)
1168 self._sources_list = []
1169

Member Function Documentation

◆ CreateHeaderEmitter()

def scripts.systemnative.CPPLibraryEmitter.CreateHeaderEmitter (   self,
  interface_name,
  library_name,
  is_callback = False 
)

Definition at line 1170 of file systemnative.py.

1173 is_callback=False):
1174 path = os.path.join(self._cpp_sources_dir, 'Dart%s.h' % interface_name)
1175 if not is_callback:
1176 self._library_headers[library_name].append(path)
1177 return self._emitters.FileEmitter(path)
1178
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition: editor.cpp:211

◆ CreateSourceEmitter()

def scripts.systemnative.CPPLibraryEmitter.CreateSourceEmitter (   self,
  interface_name 
)

Definition at line 1179 of file systemnative.py.

1179 def CreateSourceEmitter(self, interface_name):
1180 path = os.path.join(self._cpp_sources_dir,
1181 'Dart%s.cpp' % interface_name)
1182 self._sources_list.append(path)
1183 return self._emitters.FileEmitter(path)
1184

◆ EmitClassIdTable()

def scripts.systemnative.CPPLibraryEmitter.EmitClassIdTable (   self,
  database,
  output_dir,
  type_registry,
  renamer 
)

Definition at line 1214 of file systemnative.py.

1214 def EmitClassIdTable(self, database, output_dir, type_registry, renamer):
1215
1216 def HasConverters(interface):
1217 is_node_test = lambda interface: interface.id == 'Node'
1218 is_active_test = lambda interface: 'ActiveDOMObject' in interface.ext_attrs
1219 is_event_target_test = lambda interface: 'EventTarget' in interface.ext_attrs
1220
1221 return (
1222 any(map(is_node_test, database.Hierarchy(interface))) or
1223 any(map(is_active_test, database.Hierarchy(interface))) or
1224 any(map(is_event_target_test, database.Hierarchy(interface))))
1225
1226 path = os.path.join(output_dir, 'DartWebkitClassIds.h')
1227 e = self._emitters.FileEmitter(path)
1228 e.Emit(
1229 '// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file\n'
1230 )
1231 e.Emit(
1232 '// for details. All rights reserved. Use of this source code is governed by a\n'
1233 )
1234 e.Emit('// BSD-style license that can be found in the LICENSE file.\n')
1235 e.Emit('// WARNING: Do not edit - generated code.\n')
1236 e.Emit('// See dart/tools/dom/scripts/systemnative.py\n')
1237 e.Emit('\n')
1238 e.Emit('#ifndef DartWebkitClassIds_h\n')
1239 e.Emit('#define DartWebkitClassIds_h\n')
1240 e.Emit('\n')
1241 e.Emit('namespace WebCore {\n')
1242 e.Emit('\n')
1243 e.Emit('enum {\n')
1244 e.Emit(' _InvalidClassId = 0,\n')
1245 e.Emit(' _HistoryCrossFrameClassId,\n')
1246 e.Emit(' _LocationCrossFrameClassId,\n')
1247 e.Emit(' _DOMWindowCrossFrameClassId,\n')
1248 e.Emit(' _DateTimeClassId,\n')
1249 e.Emit(' _JsObjectClassId,\n')
1250 e.Emit(' _JsFunctionClassId,\n')
1251 e.Emit(' _JsArrayClassId,\n')
1252 e.Emit(
1253 ' // New types that are not auto-generated should be added here.\n'
1254 )
1255 e.Emit('\n')
1256 for interface in database.GetInterfaces():
1257 e.Emit(' %sClassId,\n' % interface.id)
1258 e.Emit(' NumWebkitClassIds\n')
1259 e.Emit('};\n')
1260 e.Emit(
1261 'class ActiveDOMObject;\n'
1262 'class EventTarget;\n'
1263 'class Node;\n'
1264 'typedef ActiveDOMObject* (*ToActiveDOMObject)(void* value);\n'
1265 'typedef EventTarget* (*ToEventTarget)(void* value);\n'
1266 'typedef Node* (*ToNode)(void* value);\n'
1267 'typedef struct {\n'
1268 ' const char* class_name;\n'
1269 ' int library_id;\n'
1270 ' int base_class_id;\n'
1271 ' ToActiveDOMObject toActiveDOMObject;\n'
1272 ' ToEventTarget toEventTarget;\n'
1273 ' ToNode toNode;\n'
1274 '} DartWrapperTypeInfo;\n'
1275 'typedef DartWrapperTypeInfo _DartWebkitClassInfo[NumWebkitClassIds];\n'
1276 '\n'
1277 'extern _DartWebkitClassInfo DartWebkitClassInfo;\n'
1278 '\n'
1279 '} // namespace WebCore\n'
1280 '#endif // DartWebkitClassIds_h\n')
1281
1282 path = os.path.join(output_dir, 'DartWebkitClassIds.cpp')
1283 e = self._emitters.FileEmitter(path)
1284 e.Emit(
1285 '// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file\n'
1286 )
1287 e.Emit(
1288 '// for details. All rights reserved. Use of this source code is governed by a\n'
1289 )
1290 e.Emit('// BSD-style license that can be found in the LICENSE file.\n')
1291 e.Emit('// WARNING: Do not edit - generated code.\n')
1292 e.Emit('// See dart/tools/dom/scripts/systemnative.py\n')
1293 e.Emit('\n')
1294 e.Emit('#include "config.h"\n')
1295 e.Emit('#include "DartWebkitClassIds.h"\n')
1296 e.Emit('\n')
1297 e.Emit('#include "bindings/dart/DartLibraryIds.h"\n')
1298 for interface in database.GetInterfaces():
1299 if HasConverters(interface):
1300 e.Emit('#include "Dart%s.h"\n' % interface.id)
1301 e.Emit('\n')
1302
1303 e.Emit('namespace WebCore {\n')
1304
1305 e.Emit('\n')
1306
1307 e.Emit(
1308 'ActiveDOMObject* toNullActiveDOMObject(void* value) { return 0; }\n'
1309 )
1310 e.Emit('EventTarget* toNullEventTarget(void* value) { return 0; }\n')
1311 e.Emit('Node* toNullNode(void* value) { return 0; }\n')
1312
1313 e.Emit("_DartWebkitClassInfo DartWebkitClassInfo = {\n")
1314
1315 e.Emit(' {\n'
1316 ' "_InvalidClassId", -1, -1,\n'
1317 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1318 ' },\n')
1319 e.Emit(' {\n'
1320 ' "_HistoryCrossFrame", DartHtmlLibraryId, -1,\n'
1321 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1322 ' },\n')
1323 e.Emit(' {\n'
1324 ' "_LocationCrossFrame", DartHtmlLibraryId, -1,\n'
1325 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1326 ' },\n')
1327 e.Emit(' {\n'
1328 ' "_DOMWindowCrossFrame", DartHtmlLibraryId, -1,\n'
1329 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1330 ' },\n')
1331 e.Emit(' {\n'
1332 ' "DateTime", DartCoreLibraryId, -1,\n'
1333 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1334 ' },\n')
1335 e.Emit(' {\n'
1336 ' "JsObject", DartJsLibraryId, -1,\n'
1337 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1338 ' },\n')
1339 e.Emit(' {\n'
1340 ' "JsFunction", DartJsLibraryId, _JsObjectClassId,\n'
1341 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1342 ' },\n')
1343 e.Emit(' {\n'
1344 ' "JsArray", DartJsLibraryId, _JsObjectClassId,\n'
1345 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1346 ' },\n')
1347 e.Emit(
1348 ' // New types that are not auto-generated should be added here.\n'
1349 )
1350 for interface in database.GetInterfaces():
1351 name = interface.id
1352 type_info = type_registry.TypeInfo(name)
1353 type_info.native_type().replace('<', '_').replace('>', '_')
1354 e.Emit(' {\n')
1355 e.Emit(' "%s", ' % type_info.implementation_name())
1356 e.Emit('Dart%sLibraryId, ' % renamer.GetLibraryId(interface))
1357 if interface.parents:
1358 supertype = interface.parents[0].type.id
1359 e.Emit('%sClassId,\n' % supertype)
1360 else:
1361 e.Emit(' -1,\n')
1362 if HasConverters(interface):
1363 e.Emit(
1364 ' Dart%s::toActiveDOMObject, Dart%s::toEventTarget,'
1365 ' Dart%s::toNode\n' % (name, name, name))
1366 else:
1367 e.Emit(
1368 ' toNullActiveDOMObject, toNullEventTarget, toNullNode\n'
1369 )
1370 e.Emit(' },\n')
1371
1372 e.Emit("};\n")
1373 e.Emit('\n')
1374 e.Emit('} // namespace WebCore\n')
1375
1376
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ EmitDerivedSources()

def scripts.systemnative.CPPLibraryEmitter.EmitDerivedSources (   self,
  template,
  output_dir 
)

Definition at line 1185 of file systemnative.py.

1185 def EmitDerivedSources(self, template, output_dir):
1186 partitions = 20 # FIXME: this should be configurable.
1187 sources_count = len(self._sources_list)
1188 for i in range(0, partitions):
1189 file_path = os.path.join(output_dir,
1190 'DartDerivedSources%02i.cpp' % (i + 1))
1191 includes_emitter = self._emitters.FileEmitter(file_path).Emit(
1192 template)
1193 for source_file in self._sources_list[i::partitions]:
1194 path = os.path.relpath(source_file, output_dir)
1195 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
1196

◆ EmitResolver()

def scripts.systemnative.CPPLibraryEmitter.EmitResolver (   self,
  template,
  output_dir 
)

Definition at line 1197 of file systemnative.py.

1197 def EmitResolver(self, template, output_dir):
1198 for library_name in self._library_headers.keys():
1199 file_path = os.path.join(output_dir,
1200 '%s_DartResolver.cpp' % library_name)
1201 includes_emitter, body_emitter = self._emitters.FileEmitter(
1202 file_path).Emit(
1203 template, LIBRARY_NAME=library_name)
1204
1205 headers = self._library_headers[library_name]
1206 for header_file in headers:
1207 path = os.path.relpath(header_file, output_dir)
1208 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
1209 body_emitter.Emit(
1210 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argumentCount, autoSetupScope))\n'
1211 ' return func;\n',
1212 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
1213

The documentation for this class was generated from the following file: