Testbed and skeleton of a new expression parser
authorSean Callanan <scallanan@apple.com>
Thu, 22 Dec 2016 20:03:14 +0000 (20:03 +0000)
committerSean Callanan <scallanan@apple.com>
Thu, 22 Dec 2016 20:03:14 +0000 (20:03 +0000)
commit7d982509b8b91c37a6de9e7d9078c8bc6b9123a8
tree73a749f6192653e1ed87cfb6e61cd7fb924076bf
parent3885d87c601e48019dd5834a31a17a281591a483
Testbed and skeleton of a new expression parser

Recommitted after formal approval.

LLVM's JIT is now the foundation of dynamic-compilation features for many languages. Clang also has low-level support for dynamic compilation (ASTImporter and ExternalASTSource, notably). How the compiler is set up for dynamic parsing is generally left up to individual clients, for example LLDB's C/C++/Objective-C expression parser and the ROOT project.

Although this arrangement offers external clients the flexibility to implement dynamic features as they see fit, the lack of an in-tree client means that subtle bugs can be introduced that cause regressions in the external clients but aren't caught by tests (or users) until much later. LLDB for example regularly encounters complicated ODR violation scenarios where it is not immediately clear who is at fault.

Other external clients (notably, Cling) rely on similar functionality, and another goal is to break this functionality up into composable parts so that any client can be built easily on top of Clang without requiring extensive additional code.

I propose that the parts required to build a simple expression parser be added to Clang. Initially, I aim to have the following features:

A piece that looks up external declarations from a variety of sources (e.g., from previous dynamic compilations, from modules, or from DWARF) and uses clear conflict resolution rules to reconcile differences, with easily understood errors. This functionality will be supported by in-tree tests.
A piece that works hand in hand with the LLVM JIT to resolve the locations of external declarations so that e.g. variables can be redeclared and (for high-performance applications like DTrace) external variables can be accessed directly from the registers where they reside.
This commit adds a tester that parses a sequence of source files and then uses them as source data for an expression. External references are resolved using an ExternalASTSource that responds to name queries using an ASTImporter. This is the setup that LLDB uses, and the motivating reason for MinimalImport in ASTImporter. When complete, this tester will implement the first of the above goals.

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

llvm-svn: 290367
13 files changed:
clang/test/CMakeLists.txt
clang/test/Import/clang-flags/Inputs/S.c [new file with mode: 0644]
clang/test/Import/clang-flags/test.c [new file with mode: 0644]
clang/test/Import/empty-struct/Inputs/S.c [new file with mode: 0644]
clang/test/Import/empty-struct/test.c [new file with mode: 0644]
clang/test/Import/error-in-expression/Inputs/S.c [new file with mode: 0644]
clang/test/Import/error-in-expression/test.c [new file with mode: 0644]
clang/test/Import/error-in-import/Inputs/S.c [new file with mode: 0644]
clang/test/Import/error-in-import/test.c [new file with mode: 0644]
clang/test/Import/missing-import/test.c [new file with mode: 0644]
clang/tools/CMakeLists.txt
clang/tools/clang-import-test/CMakeLists.txt [new file with mode: 0644]
clang/tools/clang-import-test/clang-import-test.cpp [new file with mode: 0644]