X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2Fsort_includes.py;h=70bfdedfc6d32ad1572bae3c80a96e64955e1248;hb=HEAD;hp=c1500f52e043958d9945d506bf620c91a25ca39a;hpb=fd025797ea5197b838f87ce57f2df5bccf27ad20;p=oota-llvm.git diff --git a/utils/sort_includes.py b/utils/sort_includes.py index c1500f52e04..70bfdedfc6d 100755 --- a/utils/sort_includes.py +++ b/utils/sort_includes.py @@ -18,14 +18,19 @@ def sort_includes(f): if 'INPUTS/' in f.name or 'test/' in f.name: return + ext = os.path.splitext(f.name)[1] + if ext not in ['.cpp', '.c', '.h', '.inc', '.def']: + return + lines = f.readlines() - look_for_api_header = os.path.splitext(f.name)[1] == '.cpp' + look_for_api_header = ext in ['.cpp', '.c'] found_headers = False headers_begin = 0 headers_end = 0 api_headers = [] local_headers = [] - project_headers = [] + subproject_headers = [] + llvm_headers = [] system_headers = [] for (i, l) in enumerate(lines): if l.strip() == '': @@ -40,12 +45,16 @@ def sort_includes(f): api_headers.append(header) look_for_api_header = False continue - if header.startswith('<') or header.startswith('"gtest/'): + if (header.startswith('<') or header.startswith('"gtest/') or + header.startswith('"isl/') or header.startswith('"json/')): system_headers.append(header) continue - if (header.startswith('"llvm/') or header.startswith('"llvm-c/') or - header.startswith('"clang/') or header.startswith('"clang-c/')): - project_headers.append(header) + if (header.startswith('"clang/') or header.startswith('"clang-c/') or + header.startswith('"polly/')): + subproject_headers.append(header) + continue + if (header.startswith('"llvm/') or header.startswith('"llvm-c/')): + llvm_headers.append(header) continue local_headers.append(header) continue @@ -60,10 +69,11 @@ def sort_includes(f): if not found_headers: return - local_headers.sort() - project_headers.sort() - system_headers.sort() - headers = api_headers + local_headers + project_headers + system_headers + local_headers = sorted(set(local_headers)) + subproject_headers = sorted(set(subproject_headers)) + llvm_headers = sorted(set(llvm_headers)) + system_headers = sorted(set(system_headers)) + headers = api_headers + local_headers + subproject_headers + llvm_headers + system_headers header_lines = ['#include ' + h for h in headers] lines = lines[:headers_begin] + header_lines + lines[headers_end + 1:]