aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-26 19:24:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-26 19:24:09 +0000
commitf0c55418e2b09eaab37c820d3756cc1b4584d084 (patch)
tree9263bf60f263bb5a7aaa4d2c1be43e5fc4d942e0 /tools
parent583e75cce441388bc562fa225d23499261a0091e (diff)
downloadsrc-f0c55418e2b09eaab37c820d3756cc1b4584d084.tar.gz
src-f0c55418e2b09eaab37c820d3756cc1b4584d084.zip
Vendor import of clang trunk r301441:vendor/clang/clang-trunk-r301441
Notes
Notes: svn path=/vendor/clang/dist/; revision=317447 svn path=/vendor/clang/clang-trunk-r301441/; revision=317448; tag=vendor/clang/clang-trunk-r301441
Diffstat (limited to 'tools')
-rw-r--r--tools/c-index-test/c-index-test.c1
-rw-r--r--tools/clang-format/ClangFormat.cpp17
-rwxr-xr-xtools/clang-format/git-clang-format51
-rw-r--r--tools/libclang/CXIndexDataConsumer.cpp1
-rw-r--r--tools/libclang/CXType.cpp6
5 files changed, 47 insertions, 29 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 0dde4c7cc764..e8763ffc00ae 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -3014,6 +3014,7 @@ static const char *getEntityLanguageString(CXIdxEntityLanguage kind) {
case CXIdxEntityLang_C: return "C";
case CXIdxEntityLang_ObjC: return "ObjC";
case CXIdxEntityLang_CXX: return "C++";
+ case CXIdxEntityLang_Swift: return "Swift";
}
assert(0 && "Garbage language kind");
return 0;
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp
index ac0d0a8512f4..14bff19a1a0c 100644
--- a/tools/clang-format/ClangFormat.cpp
+++ b/tools/clang-format/ClangFormat.cpp
@@ -276,14 +276,17 @@ static bool format(StringRef FileName) {
}
// Get new affected ranges after sorting `#includes`.
Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges);
- bool IncompleteFormat = false;
+ FormattingAttemptStatus Status;
Replacements FormatChanges = reformat(*FormatStyle, *ChangedCode, Ranges,
- AssumedFileName, &IncompleteFormat);
+ AssumedFileName, &Status);
Replaces = Replaces.merge(FormatChanges);
if (OutputXML) {
outs() << "<?xml version='1.0'?>\n<replacements "
"xml:space='preserve' incomplete_format='"
- << (IncompleteFormat ? "true" : "false") << "'>\n";
+ << (Status.FormatComplete ? "false" : "true") << "'";
+ if (!Status.FormatComplete)
+ outs() << " line=" << Status.Line;
+ outs() << ">\n";
if (Cursor.getNumOccurrences() != 0)
outs() << "<cursor>"
<< FormatChanges.getShiftedCodePosition(CursorPosition)
@@ -307,11 +310,15 @@ static bool format(StringRef FileName) {
if (Rewrite.overwriteChangedFiles())
return true;
} else {
- if (Cursor.getNumOccurrences() != 0)
+ if (Cursor.getNumOccurrences() != 0) {
outs() << "{ \"Cursor\": "
<< FormatChanges.getShiftedCodePosition(CursorPosition)
<< ", \"IncompleteFormat\": "
- << (IncompleteFormat ? "true" : "false") << " }\n";
+ << (Status.FormatComplete ? "false" : "true");
+ if (!Status.FormatComplete)
+ outs() << ", \"Line\": " << Status.Line;
+ outs() << " }\n";
+ }
Rewrite.getEditBuffer(ID).write(outs());
}
}
diff --git a/tools/clang-format/git-clang-format b/tools/clang-format/git-clang-format
index 74fd451a847b..3d1ba8a3c107 100755
--- a/tools/clang-format/git-clang-format
+++ b/tools/clang-format/git-clang-format
@@ -23,6 +23,7 @@ git clang-format -h
Requires Python 2.7
"""
+from __future__ import print_function
import argparse
import collections
import contextlib
@@ -138,15 +139,15 @@ def main():
if opts.verbose >= 1:
ignored_files.difference_update(changed_lines)
if ignored_files:
- print 'Ignoring changes in the following files (wrong extension):'
+ print('Ignoring changes in the following files (wrong extension):')
for filename in ignored_files:
- print ' ', filename
+ print(' %s' % filename)
if changed_lines:
- print 'Running clang-format on the following files:'
+ print('Running clang-format on the following files:')
for filename in changed_lines:
- print ' ', filename
+ print(' %s' % filename)
if not changed_lines:
- print 'no modified files to format'
+ print('no modified files to format')
return
# The computed diff outputs absolute paths, so we must cd before accessing
# those files.
@@ -163,20 +164,20 @@ def main():
binary=opts.binary,
style=opts.style)
if opts.verbose >= 1:
- print 'old tree:', old_tree
- print 'new tree:', new_tree
+ print('old tree: %s' % old_tree)
+ print('new tree: %s' % new_tree)
if old_tree == new_tree:
if opts.verbose >= 0:
- print 'clang-format did not modify any files'
+ print('clang-format did not modify any files')
elif opts.diff:
print_diff(old_tree, new_tree)
else:
changed_files = apply_changes(old_tree, new_tree, force=opts.force,
patch_mode=opts.patch)
if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
- print 'changed files:'
+ print('changed files:')
for filename in changed_files:
- print ' ', filename
+ print(' %s' % filename)
def load_git_config(non_string_options=None):
@@ -320,7 +321,7 @@ def filter_by_extension(dictionary, allowed_extensions):
`allowed_extensions` must be a collection of lowercase file extensions,
excluding the period."""
allowed_extensions = frozenset(allowed_extensions)
- for filename in dictionary.keys():
+ for filename in list(dictionary.keys()):
base_ext = filename.rsplit('.', 1)
if len(base_ext) == 1 or base_ext[1].lower() not in allowed_extensions:
del dictionary[filename]
@@ -344,8 +345,13 @@ def run_clang_format_and_save_to_tree(changed_lines, revision=None,
"""Run clang-format on each file and save the result to a git tree.
Returns the object ID (SHA-1) of the created tree."""
+ def iteritems(container):
+ try:
+ return container.iteritems() # Python 2
+ except AttributeError:
+ return container.items() # Python 3
def index_info_generator():
- for filename, line_ranges in changed_lines.iteritems():
+ for filename, line_ranges in iteritems(changed_lines):
if revision:
git_metadata_cmd = ['git', 'ls-tree',
'%s:%s' % (revision, os.path.dirname(filename)),
@@ -356,6 +362,9 @@ def run_clang_format_and_save_to_tree(changed_lines, revision=None,
mode = oct(int(stdout.split()[0], 8))
else:
mode = oct(os.stat(filename).st_mode)
+ # Adjust python3 octal format so that it matches what git expects
+ if mode.startswith('0o'):
+ mode = '0' + mode[2:]
blob_id = clang_format_to_blob(filename, line_ranges,
revision=revision,
binary=binary,
@@ -488,10 +497,10 @@ def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
if not force:
unstaged_files = run('git', 'diff-files', '--name-status', *changed_files)
if unstaged_files:
- print >>sys.stderr, ('The following files would be modified but '
- 'have unstaged changes:')
- print >>sys.stderr, unstaged_files
- print >>sys.stderr, 'Please commit, stage, or stash them first.'
+ print('The following files would be modified but '
+ 'have unstaged changes:', file=sys.stderr)
+ print(unstaged_files, file=sys.stderr)
+ print('Please commit, stage, or stash them first.', file=sys.stderr)
sys.exit(2)
if patch_mode:
# In patch mode, we could just as well create an index from the new tree
@@ -521,20 +530,20 @@ def run(*args, **kwargs):
if p.returncode == 0:
if stderr:
if verbose:
- print >>sys.stderr, '`%s` printed to stderr:' % ' '.join(args)
- print >>sys.stderr, stderr.rstrip()
+ print('`%s` printed to stderr:' % ' '.join(args), file=sys.stderr)
+ print(stderr.rstrip(), file=sys.stderr)
if strip:
stdout = stdout.rstrip('\r\n')
return stdout
if verbose:
- print >>sys.stderr, '`%s` returned %s' % (' '.join(args), p.returncode)
+ print('`%s` returned %s' % (' '.join(args), p.returncode), file=sys.stderr)
if stderr:
- print >>sys.stderr, stderr.rstrip()
+ print(stderr.rstrip(), file=sys.stderr)
sys.exit(2)
def die(message):
- print >>sys.stderr, 'error:', message
+ print('error:', message, file=sys.stderr)
sys.exit(2)
diff --git a/tools/libclang/CXIndexDataConsumer.cpp b/tools/libclang/CXIndexDataConsumer.cpp
index 5d9776be3b6c..9cd5ff4f505f 100644
--- a/tools/libclang/CXIndexDataConsumer.cpp
+++ b/tools/libclang/CXIndexDataConsumer.cpp
@@ -1315,6 +1315,7 @@ static CXIdxEntityLanguage getEntityLangFromSymbolLang(SymbolLanguage L) {
case SymbolLanguage::C: return CXIdxEntityLang_C;
case SymbolLanguage::ObjC: return CXIdxEntityLang_ObjC;
case SymbolLanguage::CXX: return CXIdxEntityLang_CXX;
+ case SymbolLanguage::Swift: return CXIdxEntityLang_Swift;
}
llvm_unreachable("invalid symbol language");
}
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 16e993e2ac01..fce7ef2c0d86 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -147,9 +147,6 @@ static inline CXTranslationUnit GetTU(CXType CT) {
static Optional<ArrayRef<TemplateArgument>>
GetTemplateArguments(QualType Type) {
assert(!Type.isNull());
- if (const auto *Specialization = Type->getAs<TemplateSpecializationType>())
- return Specialization->template_arguments();
-
if (const auto *RecordDecl = Type->getAsCXXRecordDecl()) {
const auto *TemplateDecl =
dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl);
@@ -157,6 +154,9 @@ GetTemplateArguments(QualType Type) {
return TemplateDecl->getTemplateArgs().asArray();
}
+ if (const auto *Specialization = Type->getAs<TemplateSpecializationType>())
+ return Specialization->template_arguments();
+
return None;
}