OLD | NEW |
1 | 1 |
2 | 2 |
3 import sys | 3 import sys |
4 | 4 |
5 import datatypes | 5 import datatypes |
6 import pdfspec_autogen | 6 import pdfspec_autogen |
7 | 7 |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 print('private:') | 334 print('private:') |
335 for cc in cls.fCCPrivate: | 335 for cc in cls.fCCPrivate: |
336 print(' ' + cc) | 336 print(' ' + cc) |
337 | 337 |
338 if cls.fBase == '': | 338 if cls.fBase == '': |
339 print('protected:') | 339 print('protected:') |
340 print(' const PdfMemDocument* fPodofoDoc;') | 340 print(' const PdfMemDocument* fPodofoDoc;') |
341 print(' const PdfObject* fPodofoObj;') | 341 print(' const PdfObject* fPodofoObj;') |
342 print | 342 print |
343 print('public:') | 343 print('public:') |
344 print(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc, const P
dfObject* podofoObj) : fPodofoDoc(podofoDoc), fPodofoObj(podofoObj) {}') | 344 print(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc = NULL,
const PdfObject* podofoObj = NULL) : fPodofoDoc(podofoDoc), fPodofoObj(podofoObj
) {}') |
| 345 print(' const PdfMemDocument* doc() const { return fPodofoDoc;}') |
345 print(' const PdfObject* podofo() const { return fPodofoObj;}') | 346 print(' const PdfObject* podofo() const { return fPodofoObj;}') |
346 else: | 347 else: |
347 print('public:') | 348 print('public:') |
348 print(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc, const P
dfObject* podofoObj) : SkPdf' + cls.fBase + '(podofoDoc, podofoObj) {}') | 349 print(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc = NULL,
const PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '(podofoDoc, podofoObj
) {}') |
349 print | 350 print |
350 | 351 |
351 #check required fieds, also, there should be an internal_valid() manually
wrote for complex | 352 #check required fieds, also, there should be an internal_valid() manually
wrote for complex |
352 # situations | 353 # situations |
353 # right now valid return true | 354 # right now valid return true |
354 print(' virtual bool valid() const {return true;}') | 355 print(' virtual bool valid() const {return true;}') |
355 print | 356 print |
356 | 357 |
| 358 print(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fName + '& f
rom) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPodofoObj; re
turn *this;}') |
| 359 print |
| 360 |
357 for field in cls.fFields: | 361 for field in cls.fFields: |
358 prop = field.fProp | 362 prop = field.fProp |
359 if prop.fCppName != '': | 363 if prop.fCppName != '': |
360 if prop.fCppName[0] == '[': | 364 if prop.fCppName[0] == '[': |
361 print('/*') # comment code of the atributes that can have any name | 365 print('/*') # comment code of the atributes that can have any name |
362 | 366 |
363 print(' ' + prop.fCppType + ' ' + prop.fCppName + '() const {') | 367 print(' ' + prop.fCppType + ' ' + prop.fCppName + '() const {') |
364 print(' ' + prop.fCppType + ' ret;') | 368 print(' ' + prop.fCppType + ' ret;') |
365 print(' if (' + prop.fCppReader + '(fPodofoDoc, fPodofoObj->GetDict
ionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) return ret;') | 369 print(' if (' + prop.fCppReader + '(fPodofoDoc, fPodofoObj->GetDict
ionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) return ret;') |
366 if field.fRequired == False: | 370 if field.fRequired == False: |
(...skipping 18 matching lines...) Expand all Loading... |
385 # later, p2, generate constructor when not knowing the type - very similar
with parsing? | 389 # later, p2, generate constructor when not knowing the type - very similar
with parsing? |
386 | 390 |
387 # generate parser | 391 # generate parser |
388 | 392 |
389 # TODO(edisonn): fast recognition based on must attributes. | 393 # TODO(edisonn): fast recognition based on must attributes. |
390 print('class PodofoMapper {') | 394 print('class PodofoMapper {') |
391 print('public:') | 395 print('public:') |
392 for name in self.fClassesNamesInOrder: | 396 for name in self.fClassesNamesInOrder: |
393 cls = self.fClasses[name] | 397 cls = self.fClasses[name] |
394 | 398 |
395 print(' static bool map' + name + '(const PdfMemDocument& podofoDoc, cons
t PdfObject& podofoObj, SkPdfObject** out) {') | 399 |
| 400 print(' static bool map(const SkPdfObject& in, SkPdf' + name + '** out) {
') |
| 401 print(' return map(*in.doc(), *in.podofo(), out);') |
| 402 print(' }') |
| 403 print |
| 404 |
| 405 print(' static bool map(const PdfMemDocument& podofoDoc, const PdfObject&
podofoObj, SkPdf' + name + '** out) {') |
396 print(' if (!isA' + name + '(podofoDoc, podofoObj)) return false;') | 406 print(' if (!isA' + name + '(podofoDoc, podofoObj)) return false;') |
397 print | 407 print |
398 | 408 |
399 for sub in cls.fEnumSubclasses: | 409 for sub in cls.fEnumSubclasses: |
400 print(' if (map' + enumToCls[sub].fName + '(podofoDoc, podofoObj, out
)) return true;') | 410 print(' if (map(podofoDoc, podofoObj, (SkPdf' + enumToCls[sub].fName
+ '**)out)) return true;') |
401 | 411 |
402 print | 412 print |
403 | 413 |
404 print(' *out = new SkPdf' + name + '(&podofoDoc, &podofoObj);') | 414 print(' *out = new SkPdf' + name + '(&podofoDoc, &podofoObj);') |
405 print(' return true;') | 415 print(' return true;') |
406 print(' }') | 416 print(' }') |
407 print | 417 print |
408 | 418 |
409 for name in self.fClassesNamesInOrder: | 419 for name in self.fClassesNamesInOrder: |
410 cls = self.fClasses[name] | 420 cls = self.fClasses[name] |
411 | 421 |
412 print(' static bool isA' + name + '(const PdfMemDocument& podofoDoc, cons
t PdfObject& podofoObj) {') | 422 print(' static bool isA' + name + '(const PdfMemDocument& podofoDoc, cons
t PdfObject& podofoObj) {') |
413 | 423 |
414 if cls.fCheck != '': | 424 if cls.fCheck != '': |
415 print(' return ' + cls.fCheck + ';') | 425 print(' return ' + cls.fCheck + ';') |
416 else: | 426 else: |
417 cntMust = 0 | 427 cntMust = 0 |
418 for field in cls.fFields: | 428 for field in cls.fFields: |
419 prop = field.fProp | 429 prop = field.fProp |
420 if prop.fHasMust: | 430 if prop.fHasMust: |
421 cntMust = cntMust + 1 | 431 cntMust = cntMust + 1 |
422 print(' ' + prop.fCppType + ' ' + prop.fCppName + ';') | 432 print(' ' + prop.fCppType + ' ' + prop.fCppName + ';') |
423 print(' if (!' + prop.fCppReader + '(&podofoDoc, podofoObj.GetDic
tionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &' + prop.fCppName + '
)) return false;') | 433 print(' if (!' + prop.fCppReader + '(&podofoDoc, podofoObj.GetDic
tionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &' + prop.fCppName + '
)) return false;') |
424 print(' if (' + prop.fCppName + ' != ' + prop.fMustBe.toCpp() + '
) return false;') | 434 print(' if (' + prop.fCppName + ' != ' + prop.fMustBe.toCpp() + '
) return false;') |
425 print | 435 print |
426 | 436 |
427 # hack, we only care about dictionaries now, so ret tru only if there is
a match | 437 print(' return true;') |
428 if cntMust != 0 or len(cls.fEnumSubclasses) > 0: | |
429 print(' return true;') | |
430 else: | |
431 print(' return false;') | |
432 | 438 |
433 print(' }') | 439 print(' }') |
434 print | 440 print |
435 | 441 |
436 print('};') | 442 print('};') |
437 print | 443 print |
438 | 444 |
439 return | 445 return |
440 | 446 |
441 def generateCode(): | 447 def generateCode(): |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 482 |
477 | 483 |
478 manager.write() | 484 manager.write() |
479 | 485 |
480 return 1 | 486 return 1 |
481 | 487 |
482 if '__main__' == __name__: | 488 if '__main__' == __name__: |
483 sys.exit(generateCode()) | 489 sys.exit(generateCode()) |
484 | 490 |
485 | 491 |
OLD | NEW |