]> granicus.if.org Git - clang/commit
Add support for remembering origins to ExternalASTMerger
authorSean Callanan <scallanan@apple.com>
Wed, 27 Sep 2017 19:57:58 +0000 (19:57 +0000)
committerSean Callanan <scallanan@apple.com>
Wed, 27 Sep 2017 19:57:58 +0000 (19:57 +0000)
commit87d985aec94671ac64148e973c6aa3d5090b2ec0
tree04068b66ecced877bccb750b9ac4bedd093a98b8
parent31a16c4f5bc89d8e9ca6c0a52a34b98c18058b6b
Add support for remembering origins to ExternalASTMerger

ExternalASTMerger has hitherto relied on being able to look up
any Decl through its named DeclContext chain. This works for
many cases, but causes problems for function-local structs,
which cannot be looked up in their containing FunctionDecl. An
example case is

void f() {
  { struct S { int a; }; }
  { struct S { bool b; }; }
}

It is not possible to lookup either of the two Ses individually
(or even to provide enough information to disambiguate) after
parsing is over; and there is typically no need to, since they
are invisible to the outside world.

However, ExternalASTMerger needs to be able to complete either
S on demand. This led to an XFAIL on test/Import/local-struct,
which this patch removes. The way the patch works is:

It defines a new data structure, ExternalASTMerger::OriginMap,
which clients are expected to maintain (default-constructing
if the origin does not have an ExternalASTMerger servicing it)
As DeclContexts are imported, if they cannot be looked up by
name they are placed in the OriginMap. This allows
ExternalASTMerger to complete them later if necessary.
As DeclContexts are imported from an origin that already has
its own OriginMap, the origins are forwarded – but only for
those DeclContexts that are actually used. This keeps the
amount of stored data minimal.

The patch also applies several improvements from review:

- Thoroughly documents the interface to ExternalASTMerger;
- Adds optional logging to help track what's going on; and
- Cleans up a bunch of braces and dangling elses.

Differential Revision: https://reviews.llvm.org/D38208

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314336 91177308-0d34-0410-b5e6-96231b3b80d8
22 files changed:
include/clang/AST/ExternalASTMerger.h
lib/AST/ExternalASTMerger.cpp
lib/Sema/SemaType.cpp
test/Import/extern-c-function/Inputs/F.cpp [new file with mode: 0644]
test/Import/extern-c-function/test.cpp [new file with mode: 0644]
test/Import/forward-declared-objc-class/Inputs/S1.m [new file with mode: 0644]
test/Import/forward-declared-objc-class/Inputs/S2.m [new file with mode: 0644]
test/Import/forward-declared-objc-class/Inputs/S3.m [new file with mode: 0644]
test/Import/forward-declared-objc-class/test.m [new file with mode: 0644]
test/Import/forward-declared-struct/Inputs/S3.c [new file with mode: 0644]
test/Import/forward-declared-struct/test.c
test/Import/local-struct-use-origins/Inputs/Callee.cpp [new file with mode: 0644]
test/Import/local-struct-use-origins/test.cpp [new file with mode: 0644]
test/Import/local-struct/test.cpp
test/Import/objc-definitions-in-expression/Inputs/S.m [new file with mode: 0644]
test/Import/objc-definitions-in-expression/test.m [new file with mode: 0644]
test/Import/struct-and-var/Inputs/S1.cpp [new file with mode: 0644]
test/Import/struct-and-var/Inputs/S2.cpp [new file with mode: 0644]
test/Import/struct-and-var/test.cpp [new file with mode: 0644]
test/Import/template/Inputs/T.cpp [new file with mode: 0644]
test/Import/template/test.cpp [new file with mode: 0644]
tools/clang-import-test/clang-import-test.cpp