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

Unified Diff: experimental/PdfViewer/generate_code.py

Issue 16706007: generate enums for pdf types (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/generate_code.py
===================================================================
--- experimental/PdfViewer/generate_code.py (revision 9520)
+++ experimental/PdfViewer/generate_code.py (working copy)
@@ -88,6 +88,11 @@
self.fName = name
self.fBase = base
+ self.fEnumSubclasses = []
+
+ self.fEnum = '!UNDEFINED'
+ self.fEnumEnd = '!UNDEFINED'
+
def required(self):
field = PdfClassField(self, True)
self.fFields.append(field)
@@ -108,14 +113,66 @@
class PdfClassManager:
def __init__(self):
- self.fClasses = []
+ self.fClasses = {}
def addClass(self, name, base=''):
cls = PdfClass(name, base)
- self.fClasses.append(cls)
+ self.fClasses[name] = cls
return cls
+ def longName(self, name):
+ ret = ''
+ while name != '':
+ cls = self.fClasses[name]
+ ret = name + ret
+ name = cls.fBase
+
+ return ret
+
+
+ def writeEnum(self, enum, enumToCls):
+ print(' ' + enum + ',')
+ cls = enumToCls[enum]
+ cls.fEnumSubclasses.sort()
+
+ cnt = 0
+ for sub in cls.fEnumSubclasses:
+ self.writeEnum(cls.fEnumSubclasses[cnt], enumToCls)
+ cnt = cnt + 1
+
+ if cnt != 0:
+ print(' ' + cls.fEnumEnd + ',')
+
def write(self):
+ # generate enum
+ enumsRoot = []
+
+ enumToCls = {}
+
+ for name in self.fClasses:
+ cls = self.fClasses[name]
+ enum = self.longName(name)
+ cls.fEnum = 'k' + enum + '_PdfObjectType'
+ cls.fEnumEnd = 'k' + enum + '__End_PdfObjectType'
+
+ if cls.fBase != '':
+ self.fClasses[cls.fBase].fEnumSubclasses.append(cls.fEnum)
+
+ if cls.fBase == '':
+ enumsRoot.append(cls.fEnum)
+
+ enumToCls[cls.fEnum] = cls
+
+ enumsRoot.sort()
+
+ # write enums
+ print('enum PdfObjectType {')
+ for enum in enumsRoot:
+ self.writeEnum(enum, enumToCls)
+ print('};')
+
+ # generate each class
+ # generate parser
return
def generateCode():
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698