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

Side by Side Diff: experimental/PdfViewer/generate_code.py

Issue 17856004: refactoring for pdf viewer lib (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 1
2 2
3 import sys 3 import sys
4 4
5 import datatypes 5 import datatypes
6 from autogen.pdfspec_autogen import * 6 from autogen.pdfspec_autogen import *
7 7
8 knowTypes = { 8 knowTypes = {
9 '(any)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'], 9 '(any)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'],
10 '(undefined)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'tr ue'], 10 '(undefined)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'tr ue'],
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 # cls = self.fClasses[cls.fBase] 226 # cls = self.fClasses[cls.fBase]
227 # # TODO(edisonn): bad perf 227 # # TODO(edisonn): bad perf
228 # for subField in cls.fFields: 228 # for subField in cls.fFields:
229 # if subField.fProp.fName == field.fProp.fName: 229 # if subField.fProp.fName == field.fProp.fName:
230 # mustBe = mustBe + subField.fProp.fMustBe 230 # mustBe = mustBe + subField.fProp.fMustBe
231 231
232 return mustBe 232 return mustBe
233 233
234 def write(self): 234 def write(self):
235 global fileHeaders 235 global fileHeaders
236 global fileHeadersCpp
236 global knowTypes 237 global knowTypes
237 238
238 # generate enum 239 # generate enum
239 enumsRoot = [] 240 enumsRoot = []
240 241
241 enumToCls = {} 242 enumToCls = {}
242 243
243 for name in self.fClasses: 244 for name in self.fClasses:
244 cls = self.fClasses[name] 245 cls = self.fClasses[name]
245 cls.fEnum = 'k' + name + '_SkPdfObjectType' 246 cls.fEnum = 'k' + name + '_SkPdfObjectType'
246 cls.fEnumEnd = 'k' + name + '__End_SkPdfObjectType' 247 cls.fEnumEnd = 'k' + name + '__End_SkPdfObjectType'
247 248
248 fileHeaders.write('#include "SkPdf' + cls.fName + '_autogen.h"\n') 249 fileHeaders.write('#include "SkPdf' + cls.fName + '_autogen.h"\n')
250 fileHeadersCpp.write('#include "SkPdf' + cls.fName + '_autogen.cpp"\n')
249 251
250 if cls.fBase != '': 252 if cls.fBase != '':
251 self.fClasses[cls.fBase].fEnumSubclasses.append(cls.fEnum) 253 self.fClasses[cls.fBase].fEnumSubclasses.append(cls.fEnum)
252 254
253 if cls.fBase == '': 255 if cls.fBase == '':
254 enumsRoot.append(cls.fEnum) 256 enumsRoot.append(cls.fEnum)
255 257
256 enumToCls[cls.fEnum] = cls 258 enumToCls[cls.fEnum] = cls
257 259
258 enumsRoot.sort() 260 enumsRoot.sort()
(...skipping 20 matching lines...) Expand all
279 fileEnums.write('\n') 281 fileEnums.write('\n')
280 282
281 fileEnums.write('#endif // __DEFINED__SkPdfEnums\n') 283 fileEnums.write('#endif // __DEFINED__SkPdfEnums\n')
282 fileEnums.close() 284 fileEnums.close()
283 285
284 for name in self.fClassesNamesInOrder: 286 for name in self.fClassesNamesInOrder:
285 cls = self.fClasses[name] 287 cls = self.fClasses[name]
286 enum = cls.fEnum 288 enum = cls.fEnum
287 289
288 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w') 290 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w')
291 fileClassCpp = open('SkPdf' + cls.fName + '_autogen.cpp', 'w')
289 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') 292 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n')
290 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') 293 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n')
291 fileClass.write('\n') 294 fileClass.write('\n')
292 295
296 fileClassCpp.write('#include "SkPdf' + cls.fName + '_autogen.h"\n\n')
293 fileClass.write('#include "SkPdfUtils.h"\n') 297 fileClass.write('#include "SkPdfUtils.h"\n')
294 fileClass.write('#include "SkPdfEnums_autogen.h"\n') 298 fileClass.write('#include "SkPdfEnums_autogen.h"\n')
295 fileClass.write('#include "SkPdfArray_autogen.h"\n') 299 fileClass.write('#include "SkPdfArray_autogen.h"\n')
296 if cls.fBase != '': 300 if cls.fBase != '':
297 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') 301 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n')
298 fileClass.write('\n') 302 fileClass.write('\n')
299 303
300 if cls.fComment != '': 304 if cls.fComment != '':
301 fileClass.write('// ' + cls.fComment + '\n') 305 fileClass.write('// ' + cls.fComment + '\n')
302 306
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 360
357 lines = prop.fComment.split('\n') 361 lines = prop.fComment.split('\n')
358 if prop.fComment != '' and len(lines) > 0: 362 if prop.fComment != '' and len(lines) > 0:
359 fileClass.write('/** ' + lines[0] + '\n') 363 fileClass.write('/** ' + lines[0] + '\n')
360 for line in lines[1:]: 364 for line in lines[1:]:
361 fileClass.write(' * ' + line + '\n') 365 fileClass.write(' * ' + line + '\n')
362 fileClass.write('**/\n') 366 fileClass.write('**/\n')
363 367
364 if prop.fCppName[0] == '[': 368 if prop.fCppName[0] == '[':
365 fileClass.write('/*\n') # comment code of the atributes that can ha ve any name 369 fileClass.write('/*\n') # comment code of the atributes that can ha ve any name
370 fileClassCpp.write('/*\n') # comment code of the atributes that can have any name
366 371
367 # TODO(edisonn): has_foo(); 372 # TODO(edisonn): has_foo();
368 fileClass.write(' bool has_' + prop.fCppName + '() const {\n') 373 fileClass.write(' bool has_' + prop.fCppName + '() const {\n')
369 fileClass.write(' return (ObjectFromDictionary(fPodofoDoc, fPodofoO bj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));\n') 374 fileClass.write(' return (ObjectFromDictionary(fPodofoDoc, fPodofoO bj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));\n')
370 fileClass.write(' }\n') 375 fileClass.write(' }\n')
371 fileClass.write('\n') 376 fileClass.write('\n')
372 377
373 if len(prop.fTypes.split()) == 1: 378 if len(prop.fTypes.split()) == 1:
374 t = prop.fTypes.strip() 379 t = prop.fTypes.strip()
375 fileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '() c onst {\n') 380 fileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '() c onst;\n')
376 fileClass.write(' ' + knowTypes[t][0] + ' ret;\n') 381 fileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + ':: ' + prop.fCppName + '() const {\n')
377 fileClass.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodofo Obj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) retu rn ret;\n') 382 fileClassCpp.write(' ' + knowTypes[t][0] + ' ret;\n')
383 fileClassCpp.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodof oObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) ret urn ret;\n')
378 if field.fRequired == False and prop.fDefault != '': 384 if field.fRequired == False and prop.fDefault != '':
379 fileClass.write(' return ' + prop.fDefault.toCpp() + ';\n'); 385 fileClassCpp.write(' return ' + prop.fDefault.toCpp() + ';\n');
380 else: 386 else:
381 fileClass.write(' // TODO(edisonn): warn about missing required field, assert for known good pdfs\n') 387 fileClassCpp.write(' // TODO(edisonn): warn about missing require d field, assert for known good pdfs\n')
382 fileClass.write(' return ' + knowTypes[t][2].toCpp() + ';\n'); 388 fileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ';\n');
383 fileClass.write(' }\n') 389 fileClassCpp.write('}\n')
384 fileClass.write('\n') 390 fileClassCpp.write('\n')
385 else: 391 else:
386 for type in prop.fTypes.split(): 392 for type in prop.fTypes.split():
387 t = type.strip() 393 t = type.strip()
388 fileClass.write(' bool is' + prop.fCppName + 'A' + t.title() + '( ) const {\n') 394 fileClass.write(' bool is' + prop.fCppName + 'A' + t.title() + '( ) const {\n')
389 fileClass.write(' SkPdfObject* ret = NULL;\n') 395 fileClass.write(' SkPdfObject* ret = NULL;\n')
390 fileClass.write(' if (!ObjectFromDictionary(fPodofoDoc, fPodofo Obj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) retu rn false;\n') 396 fileClass.write(' if (!ObjectFromDictionary(fPodofoDoc, fPodofo Obj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) retu rn false;\n')
391 fileClass.write(' return ' + knowTypes[t][3] + ';\n') 397 fileClass.write(' return ' + knowTypes[t][3] + ';\n')
392 fileClass.write(' }\n') 398 fileClass.write(' }\n')
393 fileClass.write('\n') 399 fileClass.write('\n')
394 400
395 fileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppName + 'As' + t.title() + '() const {\n') 401 fileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppName + 'As' + t.title() + '() const;\n')
396 fileClass.write(' ' + knowTypes[t][0] + ' ret = ' + knowTypes[t ][2].toCpp() + ';\n') 402 fileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + ' ::get' + prop.fCppName + 'As' + t.title() + '() const {\n')
397 fileClass.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodo foObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) re turn ret;\n') 403 fileClassCpp.write(' ' + knowTypes[t][0] + ' ret = ' + knowTypes[ t][2].toCpp() + ';\n')
398 fileClass.write(' // TODO(edisonn): warn about missing required field, assert for known good pdfs\n') 404 fileClassCpp.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPod ofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) r eturn ret;\n')
399 fileClass.write(' return ' + knowTypes[t][2].toCpp() + ';\n') 405 fileClassCpp.write(' // TODO(edisonn): warn about missing require d field, assert for known good pdfs\n')
400 fileClass.write(' }\n') 406 fileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ';\n')
401 fileClass.write('\n') 407 fileClassCpp.write('}\n')
408 fileClassCpp.write('\n')
402 409
403 410
404 if prop.fCppName[0] == '[': 411 if prop.fCppName[0] == '[':
405 fileClass.write('*/\n') # comment code of the atributes that can ha ve any name 412 fileClass.write('*/\n') # comment code of the atributes that can ha ve any name
413 fileClassCpp.write('*/\n') # comment code of the atributes that can have any name
406 414
407 415
408 fileClass.write('};\n') 416 fileClass.write('};\n')
409 fileClass.write('\n') 417 fileClass.write('\n')
410 418
411 fileClass.write('#endif // __DEFINED__SkPdf' + cls.fName + '\n') 419 fileClass.write('#endif // __DEFINED__SkPdf' + cls.fName + '\n')
412 fileClass.close() 420 fileClass.close()
421 fileClassCpp.close()
413 422
414 423
415 424
416 # generate constructor when knowing the type 425 # generate constructor when knowing the type
417 # later, p2, generate constructor when not knowing the type - very similar with parsing? 426 # later, p2, generate constructor when not knowing the type - very similar with parsing?
418 427
419 # generate parser 428 # generate parser
420 # TODO(edisonn): fast recognition based on must attributes. 429 # TODO(edisonn): fast recognition based on must attributes.
421 fileMapper = open('SkPdfPodofoMapper_autogen.h', 'w') 430 fileMapper = open('SkPdfPodofoMapper_autogen.h', 'w')
431 fileMapperCpp = open('SkPdfPodofoMapper_autogen.cpp', 'w')
422 fileMapper.write('#ifndef __DEFINED__SkPdfPodofoMapper\n') 432 fileMapper.write('#ifndef __DEFINED__SkPdfPodofoMapper\n')
423 fileMapper.write('#define __DEFINED__SkPdfPodofoMapper\n') 433 fileMapper.write('#define __DEFINED__SkPdfPodofoMapper\n')
424 fileMapper.write('\n') 434 fileMapper.write('\n')
425 435
426 fileMapper.write('#include "SkPdfHeaders_autogen.h"\n') 436 fileMapper.write('#include "SkPdfHeaders_autogen.h"\n')
427 fileMapper.write('class PodofoMapper {\n') 437 fileMapperCpp.write('#include "SkPdfPodofoMapper_autogen.h"\n')
428 fileMapper.write('public:\n') 438 # fileMapper.write('class PodofoMapper {\n')
439 # fileMapper.write('public:\n')
429 for name in self.fClassesNamesInOrder: 440 for name in self.fClassesNamesInOrder:
430 cls = self.fClasses[name] 441 cls = self.fClasses[name]
431 442
432 443
433 fileMapper.write(' static bool map(const SkPdfObject& in, SkPdf' + name + '** out) {\n') 444 fileMapper.write('bool map' + name + '(const SkPdfObject& in, SkPdf' + nam e + '** out);\n')
434 fileMapper.write(' return map(*in.doc(), *in.podofo(), out);\n')
435 fileMapper.write(' }\n')
436 fileMapper.write('\n')
437 445
438 fileMapper.write(' static bool map(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdf' + name + '** out) {\n') 446 fileMapperCpp.write('bool map' + name + '(const SkPdfObject& in, SkPdf' + name + '** out) {\n')
439 fileMapper.write(' if (!is' + name + '(podofoDoc, podofoObj)) return fa lse;\n') 447 fileMapperCpp.write(' return map' + name + '(*in.doc(), *in.podofo(), out );\n')
440 fileMapper.write('\n') 448 fileMapperCpp.write('}\n')
449 fileMapperCpp.write('\n')
450
451 fileMapper.write('bool map' + name + '(const PdfMemDocument& podofoDoc, co nst PdfObject& podofoObj, SkPdf' + name + '** out);\n')
452 fileMapperCpp.write('bool map' + name + '(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdf' + name + '** out) {\n')
453 fileMapperCpp.write(' if (!is' + name + '(podofoDoc, podofoObj)) return f alse;\n')
454 fileMapperCpp.write('\n')
441 455
442 # stream must be last one 456 # stream must be last one
443 hasStream = False 457 hasStream = False
444 for sub in cls.fEnumSubclasses: 458 for sub in cls.fEnumSubclasses:
445 if cls.fName == 'Object' and enumToCls[sub].fName == 'Stream': 459 if cls.fName == 'Object' and enumToCls[sub].fName == 'Stream':
446 hasStream = True 460 hasStream = True
447 else: 461 else:
448 fileMapper.write(' if (map(podofoDoc, podofoObj, (SkPdf' + enumToCl s[sub].fName + '**)out)) return true;\n') 462 fileMapperCpp.write(' if (map' + enumToCls[sub].fName + '(podofoDoc, podofoObj, (SkPdf' + enumToCls[sub].fName + '**)out)) return true;\n')
449 463
450 if hasStream: 464 if hasStream:
451 fileMapper.write(' if (map(podofoDoc, podofoObj, (SkPdfStream**)out)) return true;\n') 465 fileMapperCpp.write(' if (mapStream(podofoDoc, podofoObj, (SkPdfStream* *)out)) return true;\n')
452 466
453 467
454 fileMapper.write('\n') 468 fileMapperCpp.write('\n')
455 469
456 fileMapper.write(' *out = new SkPdf' + name + '(&podofoDoc, &podofoObj) ;\n') 470 fileMapperCpp.write(' *out = new SkPdf' + name + '(&podofoDoc, &podofoObj );\n')
457 fileMapper.write(' return true;\n') 471 fileMapperCpp.write(' return true;\n')
458 fileMapper.write(' }\n') 472 fileMapperCpp.write('}\n')
459 fileMapper.write('\n') 473 fileMapperCpp.write('\n')
460 474
461 for name in self.fClassesNamesInOrder: 475 for name in self.fClassesNamesInOrder:
462 cls = self.fClasses[name] 476 cls = self.fClasses[name]
463 477
464 fileMapper.write(' static bool is' + name + '(const PdfMemDocument& podof oDoc, const PdfObject& podofoObj) {\n') 478 fileMapper.write('bool is' + name + '(const PdfMemDocument& podofoDoc, con st PdfObject& podofoObj);\n')
479 fileMapperCpp.write('bool is' + name + '(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj) {\n')
465 480
466 if cls.fCheck != '': 481 if cls.fCheck != '':
467 fileMapper.write(' return ' + cls.fCheck + ';\n') 482 fileMapperCpp.write(' return ' + cls.fCheck + ';\n')
468 else: 483 else:
469 cntMust = 0 484 cntMust = 0
470 for field in cls.fFields: 485 for field in cls.fFields:
471 prop = field.fProp 486 prop = field.fProp
472 if prop.fHasMust: 487 if prop.fHasMust:
473 cntMust = cntMust + 1 488 cntMust = cntMust + 1
474 fileMapper.write(' ' + knowTypes[prop.fTypes.strip()][0] + ' ' + prop.fCppName + ';\n') 489 fileMapperCpp.write(' ' + knowTypes[prop.fTypes.strip()][0] + ' ' + prop.fCppName + ';\n')
475 fileMapper.write(' if (!' + knowTypes[prop.fTypes.strip()][1] + ' (&podofoDoc, podofoObj.GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &' + prop.fCppName + ')) return false;\n') 490 fileMapperCpp.write(' if (!' + knowTypes[prop.fTypes.strip()][1] + '(&podofoDoc, podofoObj.GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &' + prop.fCppName + ')) return false;\n')
476 491
477 eval = ''; 492 eval = '';
478 # TODO(edisonn): this could get out of hand, and could have poor per formance if continued on this path 493 # TODO(edisonn): this could get out of hand, and could have poor per formance if continued on this path
479 # but if we would write our parser, then best thing would be to crea te a map of (key, value) -> to bits 494 # but if we would write our parser, then best thing would be to crea te a map of (key, value) -> to bits
480 # and at each (key, value) we do an and with the bits existent, then we check what bits are left, which would tell the posible types of this diction ary 495 # and at each (key, value) we do an and with the bits existent, then we check what bits are left, which would tell the posible types of this diction ary
481 # and for non unique posinilities (if any) based on context, or the requester of dictionry we can determine fast the dictionary type 496 # and for non unique posinilities (if any) based on context, or the requester of dictionry we can determine fast the dictionary type
482 mustBe = self.determineAllMustBe(cls, field, enumToCls) 497 mustBe = self.determineAllMustBe(cls, field, enumToCls)
483 if len(mustBe) > 0: 498 if len(mustBe) > 0:
484 for cnd in mustBe: 499 for cnd in mustBe:
485 if eval == '': 500 if eval == '':
486 eval = '(' + prop.fCppName + ' != ' + cnd.toCpp() + ')' 501 eval = '(' + prop.fCppName + ' != ' + cnd.toCpp() + ')'
487 else: 502 else:
488 eval = eval + ' && ' + '(' + prop.fCppName + ' != ' + cnd.toCp p() + ')' 503 eval = eval + ' && ' + '(' + prop.fCppName + ' != ' + cnd.toCp p() + ')'
489 fileMapper.write(' if (' + eval + ') return false;\n') 504 fileMapperCpp.write(' if (' + eval + ') return false;\n')
490 fileMapper.write('\n') 505 fileMapperCpp.write('\n')
491 506
492 fileMapper.write(' return true;\n') 507 fileMapperCpp.write(' return true;\n')
493 508
494 fileMapper.write(' }\n') 509 fileMapperCpp.write('}\n')
495 fileMapper.write('\n') 510 fileMapperCpp.write('\n')
496 511
497 fileMapper.write('};\n') 512 fileMapper.write('bool ' + name + 'FromDictionary(const PdfMemDocument* pd fDoc, const PdfDictionary& dict, const char* key, SkPdf' + name + '** data);\n')
513 fileMapperCpp.write('bool ' + name + 'FromDictionary(const PdfMemDocument* pdfDoc, const PdfDictionary& dict, const char* key, SkPdf' + name + '** data) { \n')
514 fileMapperCpp.write(' const PdfObject* value = resolveReferenceObject(pdf Doc, dict.GetKey(PdfName(key)), true);\n')
515 fileMapperCpp.write(' if (value == NULL) { return false; }\n')
516 fileMapperCpp.write(' if (data == NULL) { return true; }\n')
517 fileMapperCpp.write(' return map' + name + '(*pdfDoc, *value, (SkPdf' + n ame + '**)data);\n')
518 fileMapperCpp.write('}\n')
519 fileMapperCpp.write('\n')
520
521 fileMapper.write('bool ' + name + 'FromDictionary(const PdfMemDocument* pd fDoc, const PdfDictionary& dict, const char* key, const char* abr, SkPdf' + name + '** data);\n')
522 fileMapperCpp.write('bool ' + name + 'FromDictionary(const PdfMemDocument* pdfDoc, const PdfDictionary& dict, const char* key, const char* abr, SkPdf' + n ame + '** data) {\n')
523 fileMapperCpp.write(' if (' + name + 'FromDictionary(pdfDoc, dict, key, d ata)) return true;\n')
524 fileMapperCpp.write(' if (abr == NULL || *abr == \'\\0\') return false;\n ')
525 fileMapperCpp.write(' return ' + name + 'FromDictionary(pdfDoc, dict, abr , data);\n')
526 fileMapperCpp.write('}\n')
527 fileMapperCpp.write('\n')
528
529 #fileMapper.write('};\n')
498 fileMapper.write('\n') 530 fileMapper.write('\n')
499 531
500 fileMapper.write('#endif // __DEFINED__SkPdfPodofoMapper\n') 532 fileMapper.write('#endif // __DEFINED__SkPdfPodofoMapper\n')
501 fileMapper.close() 533 fileMapper.close()
502 534
503 return 535 return
504 536
505 def generateCode(): 537 def generateCode():
506 global fileHeaders 538 global fileHeaders
539 global fileHeadersCpp
507 global knowTypes 540 global knowTypes
508 541
509 fileHeaders = open('SkPdfHeaders_autogen.h', 'w') 542 fileHeaders = open('SkPdfHeaders_autogen.h', 'w')
543 fileHeadersCpp = open('SkPdfHeaders_autogen.cpp', 'w')
510 fileHeaders.write('#ifndef __DEFINED__SkPdfHeaders\n') 544 fileHeaders.write('#ifndef __DEFINED__SkPdfHeaders\n')
511 fileHeaders.write('#define __DEFINED__SkPdfHeaders\n') 545 fileHeaders.write('#define __DEFINED__SkPdfHeaders\n')
512 fileHeaders.write('\n') 546 fileHeaders.write('\n')
513 547
514 fileHeaders.write('#include "SkPdfEnums_autogen.h"\n') 548 fileHeaders.write('#include "SkPdfEnums_autogen.h"\n')
515 549
550 fileHeadersCpp.write('#include "SkPdfHeaders_autogen.h"\n')
551
516 manager = PdfClassManager() 552 manager = PdfClassManager()
517 553
518 manager.addClass('Object') 554 manager.addClass('Object')
519 555
520 manager.addClass('Null').check('podofoObj.GetDataType() == ePdfDataType_Null') 556 manager.addClass('Null').check('podofoObj.GetDataType() == ePdfDataType_Null')
521 manager.addClass('Boolean').check('podofoObj.GetDataType() == ePdfDataType_Boo l')\ 557 manager.addClass('Boolean').check('podofoObj.GetDataType() == ePdfDataType_Boo l')\
522 .carbonCopyPublic('bool value() const {return fPodo foObj->GetBool();}') 558 .carbonCopyPublic('bool value() const {return fPodo foObj->GetBool();}')
523 559
524 manager.addClass('Integer').check('podofoObj.GetDataType() == ePdfDataType_Num ber || podofoObj.GetDataType() == ePdfDataType_Real')\ 560 manager.addClass('Integer').check('podofoObj.GetDataType() == ePdfDataType_Num ber || podofoObj.GetDataType() == ePdfDataType_Real')\
525 .carbonCopyPublic('long value() const {return fPodo foObj->GetNumber();}') 561 .carbonCopyPublic('long value() const {return fPodo foObj->GetNumber();}')
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 .type('name')\ 610 .type('name')\
575 .comment('')\ 611 .comment('')\
576 .must([datatypes.PdfName('MMType1')])\ 612 .must([datatypes.PdfName('MMType1')])\
577 .done().done()\ 613 .done().done()\
578 614
579 615
580 manager.write() 616 manager.write()
581 617
582 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n') 618 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n')
583 fileHeaders.close() 619 fileHeaders.close()
620 fileHeadersCpp.close()
584 621
585 return 1 622 return 1
586 623
587 if '__main__' == __name__: 624 if '__main__' == __name__:
588 sys.exit(generateCode()) 625 sys.exit(generateCode())
589 626
OLDNEW
« no previous file with comments | « experimental/PdfViewer/autogen/pdfspec_autogen.py ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698