def getSyntaxRegions(self): self.tokenizer = CppTokenizer(self.source) for token in self.tokenizer.getTokens(): if token.token_type == self.tokenizer.KEYWORD: yield (token.start, token.end, 'k') elif token.token_type == self.tokenizer.STRING: yield (token.start, token.end, 'str') elif token.token_type == self.tokenizer.COMMENT: yield (token.start, token.end, 'c') elif token.token_type == self.tokenizer.PREPROCESSOR: yield (token.start, token.end, 'p')
def ensureHtmlifier(blob, srcpath, treecfg, conn=None, dbpath=None): global htmlifier_current_path global htmlifier_current if srcpath != htmlifier_current_path: htmlifier_current_path = srcpath if dbpath is None: dbpath = srcpath htmlifier_current = CxxHtmlifier(blob, dbpath, treecfg, conn) htmlifier_current.tokenizer = CppTokenizer(dxr.readFile(srcpath)) return htmlifier_current
class CxxHtmlifier: def __init__(self, blob, srcpath, treecfg): self.source = dxr.readFile(srcpath) self.srcpath = srcpath.replace(treecfg.sourcedir + '/', '') self.blob_file = blob["byfile"].get(self.srcpath, None) def collectSidebar(self): if self.blob_file is None: return def line(linestr): return linestr.split(':')[1] def make_tuple(df, name, loc, scope="scopeid", decl=False): if decl: img = 'images/icons/page_white_code.png' else: loc = df[loc] img = 'images/icons/page_white_wrench.png' if scope in df and df[scope] > 0: return (df[name], loc.split(':')[1], df[name], img, dxr.languages.get_row_for_id("scopes", df[scope])["sname"]) return (df[name], loc.split(':')[1], df[name], img) for df in self.blob_file["types"]: yield make_tuple(df, "tqualname", "tloc", "scopeid") for df in self.blob_file["functions"]: yield make_tuple(df, "fqualname", "floc", "scopeid") for df in self.blob_file["variables"]: if "scopeid" in df and dxr.languages.get_row_for_id("functions", df["scopeid"]) is not None: continue yield make_tuple(df, "vname", "vloc", "scopeid") tblmap = { "functions": "fqualname", "types": "tqualname" } for df in self.blob_file["decldef"]: table = df["table"] if table in tblmap: yield make_tuple(dxr.languages.get_row_for_id(table, df["defid"]), tblmap[table], df["declloc"], "scopeid", True) for df in self.blob_file["macros"]: yield make_tuple(df, "macroname", "macroloc") def getSyntaxRegions(self): self.tokenizer = CppTokenizer(self.source) for token in self.tokenizer.getTokens(): if token.token_type == self.tokenizer.KEYWORD: yield (token.start, token.end, 'k') elif token.token_type == self.tokenizer.STRING: yield (token.start, token.end, 'str') elif token.token_type == self.tokenizer.COMMENT: yield (token.start, token.end, 'c') elif token.token_type == self.tokenizer.PREPROCESSOR: yield (token.start, token.end, 'p') def getLinkRegions(self): if self.blob_file is None: return def make_link(obj, clazz, rid): start, end = obj['extent'].split(':') start, end = int(start), int(end) kwargs = {} kwargs['rid'] = rid kwargs['class'] = clazz return (start, end, kwargs) tblmap = { "variables": ("var", "varid"), "functions": ("func", "funcid"), "types": ("t", "tid"), "refs": ("ref", "refid"), } for tablename in tblmap: tbl = self.blob_file[tablename] kind, rid = tblmap[tablename] for df in tbl: if 'extent' in df: yield make_link(df, kind, df[rid]) for decl in self.blob_file["decldef"]: if 'extent' not in decl: continue yield make_link(decl, tblmap[decl["table"]][0], decl["defid"]) for macro in self.blob_file["macros"]: line, col = macro['macroloc'].split(':')[1:] line, col = int(line), int(col) yield ((line, col), (line, col + len(macro['macroname'])), {'class': 'm', 'rid': macro['macroid']}) def getLineAnnotations(self): if self.blob_file is None: return for warn in self.blob_file["warnings"]: line = int(warn["wloc"].split(":")[1]) yield (line, {"class": "lnw", "title": warn["wmsg"]})
class CxxHtmlifier: def __init__(self, blob, srcpath, treecfg, conn): self.source = dxr.readFile(srcpath) self.srcpath = srcpath.replace(treecfg.sourcedir + '/', '') self.blob_file = None #blob["byfile"].get(self.srcpath, None) self.conn = conn def collectSidebar(self): def make_tuple(df, name, loc, scope="scopeid", decl=False): if decl: img = 'images/icons/page_white_code.png' else: img = 'images/icons/page_white_wrench.png' try: sname = df['sname'] except: sname = None pass if sname is not None and len(sname) > 0: return (df[name], df[loc], df[name], img, sname) return (df[name], df[loc], df[name], img) for row in self.conn.execute("SELECT tqualname, file_line, scopeid, (SELECT sname from scopes where scopes.scopeid = types.scopeid) AS sname " + "FROM types WHERE file_id = (SELECT id FROM files where path = ?)", (self.srcpath,)).fetchall(): yield make_tuple(row, "tqualname", "file_line", "scopeid") for row in self.conn.execute("SELECT fqualname, file_line, scopeid, (SELECT sname from scopes where scopes.scopeid = functions.scopeid) AS sname " + "FROM functions WHERE file_id = (SELECT id FROM files WHERE path = ?)", (self.srcpath,)).fetchall(): yield make_tuple(row, "fqualname", "file_line", "scopeid") for row in self.conn.execute("SELECT vname, file_line, scopeid, (SELECT sname from scopes where scopes.scopeid = variables.scopeid) AS sname " + "FROM variables WHERE file_id = (SELECT id FROM files WHERE path = ?) AND " + "scopeid NOT IN (SELECT funcid FROM functions WHERE functions.file_id = variables.file_id)", (self.srcpath,)).fetchall(): yield make_tuple(row, "vname", "file_line", "scopeid") tblmap = { "functions": "fqualname", "types": "tqualname" } # for df in self.blob_file["decldef"]: # table = df["table"] # if table in tblmap: # yield make_tuple(dxr.languages.get_row_for_id(table, df["defid"]), tblmap[table], # df["declloc"], "scopeid", True) for row in self.conn.execute("SELECT macroname, file_line FROM macros WHERE file_id = (SELECT id FROM files WHERE path = ?)", (self.srcpath,)).fetchall(): yield make_tuple(row, "macroname", "file_line") def getSyntaxRegions(self): self.tokenizer = CppTokenizer(self.source) for token in self.tokenizer.getTokens(): if token.token_type == self.tokenizer.KEYWORD: yield (token.start, token.end, 'k') elif token.token_type == self.tokenizer.STRING: yield (token.start, token.end, 'str') elif token.token_type == self.tokenizer.COMMENT: yield (token.start, token.end, 'c') elif token.token_type == self.tokenizer.PREPROCESSOR: yield (token.start, token.end, 'p') def getLinkRegions(self): def make_link(obj, clazz, rid): start = obj['extent_start'] end = obj['extent_end'] kwargs = {} kwargs['rid'] = rid kwargs['class'] = clazz return (start, end, kwargs) for row in self.conn.execute("SELECT refid, extent_start, extent_end FROM refs WHERE file_id = (SELECT id FROM files WHERE path = ?) ORDER BY extent_start", (self.srcpath,)).fetchall(): yield make_link(row, "ref", row['refid']) for row in self.conn.execute("SELECT varid, extent_start, extent_end FROM variables WHERE file_id = (SELECT id FROM files WHERE path = ?) ORDER BY extent_start", (self.srcpath,)).fetchall(): yield make_link(row, "var", row['varid']) for row in self.conn.execute("SELECT funcid, extent_start, extent_end FROM functions WHERE file_id = (SELECT id FROM files WHERE path = ?) ORDER BY extent_start", (self.srcpath,)).fetchall(): yield make_link(row, "func", row['funcid']) for row in self.conn.execute("SELECT tid, extent_start, extent_end FROM types WHERE file_id = (SELECT id FROM files WHERE path = ?) ORDER BY extent_start", (self.srcpath,)).fetchall(): yield make_link(row, "t", row['tid']) for row in self.conn.execute("SELECT tid, extent_start, extent_end FROM typedefs WHERE file_id = (SELECT id FROM files WHERE path = ?) ORDER BY extent_start", (self.srcpath,)).fetchall(): yield make_link(row, "t", row['tid']) for row in self.conn.execute("SELECT macroid, macroname, file_line, file_col FROM macros WHERE file_id = (SELECT id FROM files WHERE path = ?)", (self.srcpath,)).fetchall(): line = row['file_line'] col = row['file_col'] yield ((line, col), (line, col + len(row['macroname'])), {'class': 'm', 'rid': row['macroid']}) def getLineAnnotations(self): for row in self.conn.execute("SELECT wmsg, file_line FROM warnings WHERE file_id = (SELECT id FROM files WHERE path = ?)", (self.srcpath,)).fetchall(): yield (row[1], {"class": "lnw", "title": row[0]})