Juri Pakaste  committed 2d4906d

More cleanup

  • Participants
  • Parent commits 60b0b11

Comments (0)

Files changed (1)

File nsstringgen/

 from collections import namedtuple, OrderedDict
-from functools import reduce
 from tempfile import NamedTemporaryFile
 import os.path
     def preferred_name(self):
+        """Typedeffed name if one exists, otherwise the original."""
         if self.typedef_name:
             return self.typedef_name
             defn.kind if defn else None,
             "Same" if defn is not None and node == defn else "Not same"),
-    for c in node.get_children():
-        r.extend(print_tree(c, depth + 1))
+    for child in node.get_children():
+        r.extend(print_tree(child, depth + 1))
     return r
 class FileReader(object):
         self.fixed_files = {}
     def insert_content(self, sourcefile, content):
+        """Insert content of sourcefile to the cache."""
         self.fixed_files[os.path.abspath(sourcefile)] = content
     def read_extent(self, sourcefile, extent):
+        """Read extent from sourcefile."""
         sfpath = os.path.abspath(sourcefile)
         content = self.fixed_files.get(sfpath)
         if not content:
-            for c in node.get_children():
-                enums.extend(find_enums(c, parents + (node,)))
+            for child in node.get_children():
+                enums.extend(find_enums(child, parents + (node,)))
         return enums
     return find_enums
-def create_case(enumvalue):
+def create_value_case(enumvalue):
+    """Create a case statement for an EnumValue."""
     if enumvalue.value is None:
         return "case {0}: return @\"{0}\";".format(
         return ("case {0}: return [NSString stringWithFormat:@\""
                 "{0} (%d)\", {1}];".format(, enumvalue.value))
-def create_fun(parsed_enum):
+def create_case_fun(parsed_enum):
+    """Create a NSStringFromEnum for parsed_enum that assumes the enum
+    values are used separately."""
     name = parsed_enum.preferred_name
     if parsed_enum.typedef_name:
     defn = "{0} {{".format(decl)
     switchstart = "  switch (v) {"
-    cases = ["    {0}".format(create_case(ev)) for ev in parsed_enum.values]
+    cases = ["    {0}".format(create_value_case(ev))
+             for ev in parsed_enum.values]
     switchend = "  }"
     funend = "}"
     return "\n".join(
         (ext_decl, defn, switchstart, "\n".join(cases), switchend, funend))
 def create_mask_fun(parsed_enum):
+    """Create a NSStringFromEnum for parsed_enum that assumes the enum
+    values are used for bitmasks."""
     name = parsed_enum.preferred_name
     if parsed_enum.typedef_name:
     return "\n".join(lines)
 def create_includeargs(includes):
+    """Create an array of ["-include", i0, "-include", i1, …]
+    for include files."""
     includepairs = [["-include", inc] for inc in includes] if includes else []
     includeargs = sum(includepairs, [])
     return includeargs
     finder = create_finder(fname, file_reader)
     enums = finder(tu.cursor)
-    creator = create_mask_fun if mask else create_fun
+    creator = create_mask_fun if mask else create_case_fun
     return [creator(e) for e in enums if e.preferred_name]