Skip to content

Commit

Permalink
Symbolizer works
Browse files Browse the repository at this point in the history
  • Loading branch information
fish2000 committed May 24, 2015
1 parent c6c05f8 commit 30a4816
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
8 changes: 4 additions & 4 deletions include/libimread/IO/png.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2012-2014 Luis Pedro Coelho <luis@luispedro.org>
// Copyright 2012-2014 Alexander Böhn <luis@luispedro.org>
// License: MIT (see COPYING.MIT file)

#ifndef LPC_PNG_H_INCLUDE_GUARD_WED_FEB__1_16_34_50_WET_2012
#define LPC_PNG_H_INCLUDE_GUARD_WED_FEB__1_16_34_50_WET_2012
#ifndef LIBIMREAD_IO_PNG_HH_
#define LIBIMREAD_IO_PNG_HH_

#include <cstring>
#include <csetjmp>
Expand Down Expand Up @@ -76,4 +76,4 @@ namespace im {
}


#endif // LPC_PNG_H_INCLUDE_GUARD_WED_FEB__1_16_34_50_WET_2012
#endif /// LIBIMREAD_IO_PNG_HH_
64 changes: 57 additions & 7 deletions scripts/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,54 @@
from os.path import join, dirname
# from pprint import pprint

SUFFIXES = (
SUFFIXES = set((
r"c",
r"cc", r"cpp", r"cxx",
r"m", r"mm",
r"h",
r"hh", r"hpp", r"hxx",
r"inl"
)
))

KEYWORDS = set((
"alignas", "alignof", "and", "and_eq", "asm", "auto",
"bitand", "bitor", "bool", "break",
"case", "catch", "char", "char16_t", "char32_t", "class",
"compl", "const", "constexpr", "const_cast", "continue",
"decltype", "default", "delete", "do", "double", "dynamic_cast",
"else", "enum", "explicit", "export", "extern",
"false", "float", "for", "friend",
"goto",
"if", "inline", "int",
"long",
"mutable",
"namespace", "new", "noexcept", "not", "not_eq", "nullptr",
"operator", "or", "or_eq",
"private", "protected", "public",
"register", "reinterpret_cast", "return",
"short", "signed", "sizeof", "static", "static_assert",
"static_cast", "struct", "switch",
"template", "this", "thread_local", "throw", "true",
"try", "typedef", "typeid", "typename",
"union", "unsigned", "using",
"virtual", "void", "volatile",
"wchar_t", "while",
"xor", "xor_eq"))

SYMBOL_PREFIX = r'_'

sanitizer = re.compile(r'^\W+')
# symbol_re = re.compile(r"(?:\w+)%s([a-zA-Z][0-9a-zA-Z_]+)(?!_t)" % SYMBOL_PREFIX)
symbol_re = re.compile(r"(?:\s+)(?:%s)([a-z][0-9a-z_]+)(?!_t)" % SYMBOL_PREFIX)
suffix_re = re.compile(r"(%s)$" % ("|".join(map(
lambda suffix: r"\.%s" % suffix, SUFFIXES))))

quotes = re.compile(r"'(.*)'", re.MULTILINE)
dbl_quotes = re.compile(r'"(.*)"', re.MULTILINE)
cpp_comments = re.compile(r'//(.*)\n', re.MULTILINE)
c_comments = re.compile(r'/\*(.*)\*/', re.MULTILINE)
blockout = lambda match: "#" * len(match.group(0))

def collect_files(root_dir, suffixes):
""" Collect files recursively that match one or more file suffixes.
"""
Expand All @@ -35,22 +71,36 @@ def collect_files(root_dir, suffixes):
collected |= found
return collected

sanitizer = re.compile(r'^\W+')

def sanitize_suffixes(*suffixes):
return (sanitizer.sub('', suffix.lower()) for suffix in suffixes)

collect = functools.partial(collect_files, suffixes=list(sanitize_suffixes(*SUFFIXES)))

def parse_source_file(fn):
with open(fn, "rb") as fh:
source_file = fh.read()
source_edit = (source_file,)
for blockout_re in (quotes, dbl_quotes, cpp_comments, c_comments):
source_edit = blockout_re.subn(blockout, source_edit[0])
try:
sym = set(symbol_re.findall(source_edit[0]))
except:
return set()
return sym - KEYWORDS

if __name__ == '__main__':
print("")
print("> SCANNING...")
print("")

# collected = collect_files(dirname(dirname(__file__)), suffixes=list(sanitize_suffixes(*SUFFIXES)))
symbols = set()
collected = collect(dirname(dirname(__file__)))
print("> FOUND %i grand total" % len(collected))

for source_file in sorted(collected):
print(">>> %s" % source_file)
print("Parsing file: %s" % source_file)
symbols |= parse_source_file(source_file)

print("> FOUND %i grand total:" % len(symbols))
# print(symbols)
print(", ".join(sorted(symbols)))

0 comments on commit 30a4816

Please sign in to comment.