def get_reflected_files(where, lst): for f in lst: full = os.path.join(where,f) if f.endswith(".h"): content = open(full).read() tkbms = util.extract_tkbms(content) valid_tkbms = lambda x : (not tkbms.has_key(x) or tkbms[x] != "NONE") if valid_tkbms("platform") and valid_tkbms("product") and util.hasReflectionDeclaration(content): yield full elif f.endswith(".hkclass") and not os.path.exists(full.replace(".hkclass",".h")): yield full
def parseString(self, txt): document = hkcToDom.Document(self.current_filename) document.file = hkcToDom.File() for key, value in util.extract_tkbms(txt).items(): setattr(document.file,key,value) txt = self.re_classAlign.sub(r"\1", txt) # HK_CLASSALIGN(class,8) -> class def do_align(match): return "%s; //+align(%s)\n" % (match.group(2), match.group(1) or match.group(3)) txt = self.re_align.sub(do_align, txt) # HK_ALIGN(int foo,8); -> int foo; //+align(8) txt = re.sub("(?m)^\s*$\n","",txt) # delete blank lines def docstring_join(match): s,e = match.span() lines = match.string[s:e].split("\n")[:-1] lines = ( l[l.index("///")+3:].strip() for l in lines ) return '//@hk.DocString("%s")\n' % " ".join(lines) # txt = self.re_docsComment.sub(docstring_join, txt) # join adjacent docstring lines txt = self.re_commentAttribute.sub(r"\001ATT\1\002;", txt) # save attributes, use unused char delimeters txt = self.re_cComment.sub("", txt) # remove c comments txt = self.re_cppComment.sub("", txt) # c++ comments too txt = txt.replace("\\\n", " ") # do preproc line joining txt = self.re_preproc.sub("", txt) # remove preprocessor txt = self.re_whitespace.sub(" ", txt) # and all whitespace def do_hkp_macros(match): substmacros = { "HCL_SHAPE_VIRTUAL": " virtual ", "HKP_SHAPE_VIRTUAL": " virtual ", "HKP_SHAPE_VIRTUAL_CONST": " const ", "HKP_SHAPE_VIRTUAL_THIS" : " " } return substmacros[match.group(1)] txt = self.re_refPtr.sub(r"\1*", txt) # hkRefPtr<T> -> T* txt = self.re_substmacros.sub(do_hkp_macros, txt) # substitude HKP_SHAPE_VIRTUAL, HKP_SHAPE_VIRTUAL_CONST and HKP_SHAPE_VIRTUAL_THIS macros txt = self.re_junkymacros.sub(r"\2 ", txt) # remove HK_CPU_PTR(\2), HK_PAD_ON_SPU(\2) and HK_THREAD_LOCAL(\2) macros while 1: item, match = self.globalMatcher.run(txt) if match == None: break newtxt = None if item == self.re_overideDestination: document.file.overridedestination = match.group(1) elif item == self.re_templateStart: newtxt, junk = self.parseTemplate(match, txt) elif item == self.re_hashInclude: self.debug("INCLUDE %s"% match.group("path")) document.file.includeheaders += "#include <%s>\n" % match.group("path") elif item == self.re_classStart: newtxt, klass = self.parseClass(match, txt, None) if klass: document.file._class.append(klass) elif item == self.re_enumStart: newtxt, enum = self.parseEnum(match, txt) if enum: document.file.enum.append(enum) elif item == self.re_unionStart: newtxt, union = self.parseUnion(match, txt) elif item == self.re_namespaceStart: newtxt, junk = self.parseNamespace(match, txt) elif item == self.re_taggedUnionStart: newtxt, union = self.parseTaggedUnion(match, txt) if union: document.file.taggedunion.append(union) elif item == self.re_externCstart: newtxt, junk = self.parseExternC(match, txt) elif item == self.re_typedef: pass elif item == self.re_externVariable: pass elif item == self.re_functionDefinition: newtxt, junk = self.parseFunction(match, txt) elif item == self.re_attributesPlaceholder: pass # ignore attributes on e.g typedef or global elif item == self.re_spuriousSemicolon: pass else: print "NO_ACTION", match.group(), item print "***", txt oldTxtLength = len(txt) if newtxt: txt = newtxt else: txt = txt[match.span()[1]:] if len(txt) >= oldTxtLength: raise ("*** Breaking from infinite loop ***\n" \ "While parsing '%s'\n" \ "'%s'" % (self.current_filename, txt) ) return document