Commit Graph

490 Commits

Author SHA1 Message Date
Bruno Cardoso Lopes f56ef90e26 [CMAKE][c-index-test] Honor CMAKE_OSX_SYSROOT to compute include dir for libxml2
On MacOS, if CMAKE_OSX_SYSROOT is used and the user has command line tools
installed, we currently get the include path for libxml2 as
/usr/include/libxml2, instead of ${CMAKE_OSX_SYSROOT}/usr/include/libxml2.

Make it consistent on MacOS by prefixing ${CMAKE_OSX_SYSROOT} when
possible.

rdar://problem/41103601

llvm-svn: 334747
2018-06-14 18:20:04 +00:00
Matt Morehouse cffb235afe [libclang] Make c-index-test.c ISO C90 compliant.
Fixes a build bot breakage caused by r334593.

llvm-svn: 334612
2018-06-13 16:00:39 +00:00
Ivan Donchevskii 3957e48a68 [libclang] Optionally add code completion results for arrow instead of dot
Follow up for D41537 - libclang part.

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

llvm-svn: 334593
2018-06-13 12:37:08 +00:00
Ivan Donchevskii 6e89528c55 [libclang] Allow skipping function bodies in preamble only
Second attempt. Fix line endings and warning.

As an addition to CXTranslationUnit_SkipFunctionBodies, provide the
new option CXTranslationUnit_LimitSkipFunctionBodiesToPreamble,
which constraints the skipping of functions bodies to the preamble
only. Function bodies in the main file are not affected if this
option is set.

Skipping function bodies only in the preamble is what clangd already
does and the introduced flag implements it for libclang clients.

Patch by Nikolai Kosjar.

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

llvm-svn: 332587
2018-05-17 09:24:37 +00:00
Ivan Donchevskii f70d28b1f4 Revert https://reviews.llvm.org/D46050 and https://reviews.llvm.org/D45815
Windows line endings.
Requires proper resubmission.

llvm-svn: 332585
2018-05-17 09:15:22 +00:00
Ivan Donchevskii f4b09a3a30 [libclang] Allow skipping function bodies in preamble only
As an addition to CXTranslationUnit_SkipFunctionBodies, provide the
new option CXTranslationUnit_LimitSkipFunctionBodiesToPreamble,
which constraints the skipping of functions bodies to the preamble
only. Function bodies in the main file are not affected if this
option is set.

Skipping function bodies only in the preamble is what clangd already
does and the introduced flag implements it for libclang clients.

Patch by Nikolai Kosjar.

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

llvm-svn: 332578
2018-05-17 07:31:29 +00:00
Adrian Prantl 9fc8faf9e6 Remove \brief commands from doxygen comments.
This is similar to the LLVM change https://reviews.llvm.org/D46290.

We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

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

llvm-svn: 331834
2018-05-09 01:00:01 +00:00
Benjamin Kramer 6f33fca7ec [index] Fix methods that take a shared_ptr to just take a reference.
There is no ownership here, passing a shared_ptr just adds confusion. No
functionality change intended.

llvm-svn: 330595
2018-04-23 14:30:21 +00:00
Sam McCall cc026ebf32 [Index] Return SourceLocation to consumers, not FileID/Offset pair.
Summary:
The FileID/Offset conversion is lossy. The code takes the fileLoc, which loses
e.g. the spelling location in some macro cases.
Instead, pass the original SourceLocation which preserves all information, and
update consumers to match current behavior.

This allows us to fix two bugs in clangd that need the spelling location.

Reviewers: akyrtzi, arphaman

Subscribers: ilya-biryukov, ioeric, cfe-commits

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

llvm-svn: 329570
2018-04-09 14:12:51 +00:00
Alexander Kornienko 2a8c18d991 Fix typos in clang
Found via codespell -q 3 -I ../clang-whitelist.txt
Where whitelist consists of:

  archtype
  cas
  classs
  checkk
  compres
  definit
  frome
  iff
  inteval
  ith
  lod
  methode
  nd
  optin
  ot
  pres
  statics
  te
  thru

Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few
files that have dubious fixes reverted.)

Differential revision: https://reviews.llvm.org/D44188

llvm-svn: 329399
2018-04-06 15:14:32 +00:00
Serge Pavlov 52525730a1 Clean up use of C allocation functions
If the value returned by `malloc`, `calloc` or `realloc` is not checked
for null pointer, this change replaces them for `safe_malloc`,
`safe_calloc` or `safe_realloc`, which are defined in the namespace `llvm`.
These function report fatal error on out of memory.

In the plain C files, assertion statements are added to ensure that memory
is successfully allocated.

The aim of this change is to get better diagnostics of OOM on Windows.

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

llvm-svn: 325661
2018-02-21 02:02:39 +00:00
Fangrui Song 31b97194e6 [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo
Summary:
CXIdxEntityRefInfo contains the member `CXIdxEntityRefKind kind;` to
differentiate implicit and direct calls. However, there are more roles
defined in SymbolRole. Among them, `Read/Write` are probably the most
useful ones as they can be used to differentiate Read/Write occurrences
of a symbol for document highlight in a text document.

See `export namespace DocumentHighlightKind`
on https://microsoft.github.io/language-server-protocol/specification

Subscribers: cfe-commits

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

llvm-svn: 324914
2018-02-12 17:42:09 +00:00
Steve O'Brien 9463321da6 c-index-test: small fix to CXString handling and disposal
Summary: (Separating some unrelated changes out of D42043)

Reviewers: vsk, benlangmuir, akyrtzi

Subscribers: cfe-commits

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

llvm-svn: 322883
2018-01-18 20:21:07 +00:00
Sam Clegg 295a702ddc Convert comment to C-style to prevent warning
llvm-svn: 322880
2018-01-18 19:31:33 +00:00
Simon Pilgrim eb9ecd380c Fix MSVC "uninitialized variable" warning.
llvm-svn: 322845
2018-01-18 13:28:54 +00:00
Sam McCall 2686e3cac6 [Index] Fix GCC warning again :-(
llvm-svn: 322720
2018-01-17 18:20:57 +00:00
Sam McCall 6b79024e12 [Index] Fix GCC warning. This is silly, but no llvm_unreachable and no C99.
llvm-svn: 322672
2018-01-17 15:57:14 +00:00
Sam McCall 63903569eb Squash -Wcovered-switch-default wairning
llvm-svn: 322549
2018-01-16 12:54:28 +00:00
Jonathan Coe 45ef5036c9 [libclang] Add PrintingPolicy for pretty printing declarations
Summary:
Introduce clang_getCursorPrettyPrinted() for pretty printing
declarations. Expose also PrintingPolicy, so the user gets more
fine-grained control of the entities being printed.

The already existing clang_getCursorDisplayName() is pretty limited -
for example, it does not handle return types, parameter names or default
arguments for function declarations. Addressing these issues in
clang_getCursorDisplayName() would mean to duplicate existing code
(e.g. clang::DeclPrinter), so rather expose new API to access the
existing functionality.

Reviewed By: jbcoe

Subscribers: cfe-commits

Tags: #clang

Patch by nik (Nikolai Kosjar)

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

llvm-svn: 322540
2018-01-16 10:19:56 +00:00
Sam McCall bb2cf63b32 [CodeComplete] Add an option to omit results from the preamble.
Summary:
Enumerating the contents of a namespace or global scope will omit any
decls that aren't already loaded, instead of deserializing them from the
PCH.

This allows a fast hybrid code completion where symbols from headers are
provided by an external index. (Sema already exposes the information
needed to do a reasonabl job of filtering them).
Clangd plans to implement this hybrid.

This option is just a hint - callers still need to postfilter results if
they want to *avoid* completing decls outside the main file.

Reviewers: bkramer, ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 322371
2018-01-12 14:51:47 +00:00
Ivan Donchevskii 08ff91089c [libclang] Support querying whether a declaration is invalid
This is useful for e.g. highlighting purposes in an IDE.

Note: First version of this patch was reverted due to failing tests in
opencl-types.cl with -target ppc64le-unknown-linux. These tests are
adapted now.

Patch by Nikolai Kosjar.

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

llvm-svn: 321794
2018-01-04 10:59:50 +00:00
Hans Wennborg fff458994e Revert r321697 "[libclang] Support querying whether a declaration is invalid" and follow-ups.
This broke test/Index/opencl-types.cl on several buildbots:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/3294
http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/6498
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/5239

> [libclang] Support querying whether a declaration is invalid
>
> This is useful for e.g. highlighting purposes in an IDE.
>
> Patch by Nikolai Kosjar.
>
> Differential Revision: https://reviews.llvm.org/D40072

Also reverting follow-ups that otherwise caused conflicts for the
revert:

r321700 "Fix line endings."
r321701 "Fix more line endings."

r321698 "[libclang] Fix cursors for functions with trailing return type"
> For the function declaration
>
> auto foo5(Foo) -> Foo;
> the parameter tokens were mapped to cursors representing the
> FunctionDecl:
>
> Keyword: "auto" [1:1 - 1:5] FunctionDecl=test5:1:6
> Identifier: "test5" [1:6 - 1:11] FunctionDecl=test5:1:6
> Punctuation: "(" [1:11 - 1:12] FunctionDecl=test5:1:6
> Identifier: "X" [1:12 - 1:13] FunctionDecl=test5:1:6 // Ops, not a TypeRef
> Punctuation: ")" [1:13 - 1:14] FunctionDecl=test5:1:6
> Punctuation: "->" [1:15 - 1:17] FunctionDecl=test5:1:6
> Identifier: "X" [1:18 - 1:19] TypeRef=struct X:7:8
> Punctuation: ";" [1:19 - 1:20]
>
> Fix this by ensuring that the trailing return type is not visited as
> first.
>
> Patch by Nikolai Kosjar.
>
> Differential Revision: https://reviews.llvm.org/D40561

llvm-svn: 321708
2018-01-03 14:20:15 +00:00
Ivan Donchevskii 1c27b15291 Fix line endings.
llvm-svn: 321700
2018-01-03 10:33:21 +00:00
Ivan Donchevskii 0b2f162d71 [libclang] Support querying whether a declaration is invalid
This is useful for e.g. highlighting purposes in an IDE.

Patch by Nikolai Kosjar.

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

llvm-svn: 321697
2018-01-03 09:49:31 +00:00
Alex Lorenz 34ccadcea9 [libclang] Add support for checking abstractness of records
This patch allows checking whether a C++ record declaration is abstract through
libclang and clang.cindex (Python).

Patch by Johann Klähn!

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

llvm-svn: 320748
2017-12-14 22:01:50 +00:00
Alex Lorenz 690f0e2f4e [libclang] Record code-completion invocations to a temporary file when
requested by client

This is a follow up to r319702 which records parsing invocations.

These files are not emitted by default, and the client has to specify the
invocation emission path first.

rdar://35322543

llvm-svn: 320085
2017-12-07 20:37:50 +00:00
Shoaib Meenai 266e9817f7 [clang] Add PRIVATE to target_link_libraries
Another follow-up to r319840. I'd done a test configure with
LLVM_BUILD_STATIC, so I'm not sure why this didn't show up in that.

llvm-svn: 319983
2017-12-06 23:02:00 +00:00
Shoaib Meenai d806af3499 [CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.
Dependencies added in this way apply to both the target and its
dependencies, i.e. they become part of the executable's link interface
and are transitive.

Transitive dependencies generally don't make sense for executables,
since you wouldn't normally be linking against an executable. This also
causes issues for generating install export files when using
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM
library dependencies, which are currently added as interface
dependencies. If clang is in the distribution components but the LLVM
libraries it depends on aren't (which is a perfectly legitimate use case
if the LLVM libraries are being built static and there are therefore no
run-time dependencies on them), CMake will complain about the LLVM
libraries not being in export set when attempting to generate the
install export file for clang. This is reasonable behavior on CMake's
part, and the right thing is for LLVM's build system to explicitly use
PRIVATE dependencies for executables.

Unfortunately, CMake doesn't allow you to mix and match the keyword and
non-keyword target_link_libraries signatures for a single target; i.e.,
if a single call to target_link_libraries for a particular target uses
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must
also be updated to use those keywords. This means we must do this change
in a single shot. I also fully expect to have missed some instances; I
tested by enabling all the projects in the monorepo (except dragonegg),
and configuring both with and without shared libraries, on both Darwin
and Linux, but I'm planning to rely on the buildbots for other
configurations (since it should be pretty easy to fix those).

Even after this change, we still have a lot of target_link_libraries
calls that don't specify a scope keyword, mostly for shared libraries.
I'm thinking about addressing those in a follow-up, but that's a
separate change IMO.

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

llvm-svn: 319840
2017-12-05 21:49:56 +00:00
Alex Lorenz 0861579610 [libclang] Record parsing invocation to a temporary file when requested
by client

This patch extends libclang by allowing it to record parsing operations to a
temporary JSON file. The file is deleted after parsing succeeds. When a crash
happens during parsing, the file is preserved and the client will be able to use
it to generate a reproducer for the crash.

These files are not emitted by default, and the client has to specify the
invocation emission path first.

rdar://35322543

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

llvm-svn: 319702
2017-12-04 21:56:36 +00:00
Shoaib Meenai 669cae1f28 [clang] Use add_llvm_install_targets
Use this function to create the install targets rather than doing so
manually, which gains us the `-stripped` install targets to perform
stripped installations.

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

llvm-svn: 319489
2017-11-30 22:35:02 +00:00
Dave Lee 1a532c9e1d [index] Generate class & metaclass manglings for objc
Summary:
ObjC classes have two associated symbols, one for the class and one for the
metaclass.

This change overloads `CodegenNameGenerator::getAllManglings` to produce both
class and metaclass symbols.

While this function is called by `clang_Cursor_getCXXManglings`, it's only
called for CXXRecordDecl and CXXMethodDecl, and so libclang's behavior is
unchanged.

Reviewers: arphaman, abdulras, alexshap, compnerd

Reviewed By: compnerd

Subscribers: compnerd

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

llvm-svn: 313997
2017-09-22 16:58:57 +00:00
Alex Lorenz ff7f42e61a [libclang] Support for querying whether an enum is scoped
This commit allows checking whether an enum declaration is scoped
through libclang and clang.cindex (Python).

Patch by Johann Klähn!

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

llvm-svn: 307771
2017-07-12 11:35:11 +00:00
Alex Lorenz 4fabc97c43 Revert r307769 (Forgot to mention the name of the contributor).
llvm-svn: 307770
2017-07-12 11:34:14 +00:00
Alex Lorenz 571b8cfac9 [libclang] Support for querying whether an enum is scoped
This commit allows checking whether an enum declaration is scoped
through libclang and clang.cindex (Python).

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

llvm-svn: 307769
2017-07-12 11:31:37 +00:00
Richard Smith dbafb6c338 Teach ASTReader how to read only the Preprocessor state from an AST file, not the ASTContext state.
We use this when running a preprocessor-only action on an AST file in order to
avoid paying the runtime cost of loading the extra information.

llvm-svn: 306760
2017-06-29 23:23:46 +00:00
Jonathan Coe 0a5b03b659 [libclang] Support for querying the exception specification type through libclang
Summary: This patch exposes the exception specification type (noexcept,
etc.) of a C++ function through libclang and Python clang.cindex.

Reviewers: rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: jbcoe, cfe-commits

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

Patch by Andrew Bennieston

llvm-svn: 306483
2017-06-27 22:54:56 +00:00
Argyrios Kyrtzidis 735e92c29a [libclang] Introduce a new parsing option 'CXTranslationUnit_SingleFileParse' that puts preprocessor in a mode for parsing a single file only.
This is useful for parsing a single file, as a fast/inaccurate 'mode' that can still provide declarations from the file, like the classes and their methods.

llvm-svn: 305044
2017-06-09 01:20:48 +00:00
Erik Verbruggen 346066b68c [libclang] Allow to suspend a translation unit.
A suspended translation unit uses significantly less memory but on the
other side does not support any other calls than
clang_reparseTranslationUnit to resume it or
clang_disposeTranslationUnit to dispose it completely.

This helps IDEs to reduce the memory footprint. The data that is freed
by a call to clang_suspendTranslationUnit will be re-generated on the
next (re)parse anyway. Used with a preamble, this allows pretty fast
resumption of the translation unit for further use (compared to disposal
of the translation unit and a parse from scratch).

Patch by Nikolai Kosjar!

llvm-svn: 304212
2017-05-30 14:25:54 +00:00
Argyrios Kyrtzidis 0381cc74c7 [libclang] Introduce clang_Cursor_isExternalSymbol that provides info about decls marked with external_source_symbol attribute
llvm-svn: 302677
2017-05-10 15:10:36 +00:00
Emilio Cobos Alvarez 485ad42521 [libclang] Expose some target information via the C API.
This allows users to query the target triple and target pointer width, which
would make me able to fix https://github.com/servo/rust-bindgen/issues/593 and
other related bugs in an elegant way (without having to manually parse the
target triple in the command line arguments).

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

llvm-svn: 301648
2017-04-28 15:56:39 +00:00
Argyrios Kyrtzidis 2a68486c8f [libclang] Enhance clang_Cursor_isDynamicCall and clang_Cursor_getReceiverType to handle ObjC property references
Also enhance clang_Cursor_getReceiverType to handle C++ method calls.

llvm-svn: 301568
2017-04-27 17:23:04 +00:00
Argyrios Kyrtzidis b4b85f2033 [index] If the 'external_source_symbol' attribute indicates 'Swift' as the language then report it accordingly
llvm-svn: 301183
2017-04-24 14:52:00 +00:00
Argyrios Kyrtzidis 4e5a65fc83 [c-index-test] Fix memory leak in c-index-test tool.
llvm-svn: 298441
2017-03-21 21:34:05 +00:00
Argyrios Kyrtzidis 3b25c91a9e [index/AST] Determine if a typedef shares a name and spelling location with its underlying tag type
In such a case, as when using the NS_ENUM macro, for indexing purposes treat the typedef as 'transparent',
meaning we treat its references as symbols of the underlying tag symbol.
Also provide a libclang API to check for such typedefs.

llvm-svn: 298392
2017-03-21 16:56:02 +00:00
Argyrios Kyrtzidis 6d1a15b2d4 [index] Add 'Parameter' symbol kind and 'Local' symbol property to distinguish function-local symbols
Parameters have a 'child' relation to their function/method.
Also add an option '-include-locals' to 'c-index-test core' to enable indexing of function-local symbols.

Original patch from Nathan Hawes with some changes by me.
https://reviews.llvm.org/D30304

llvm-svn: 296282
2017-02-26 05:37:56 +00:00
Argyrios Kyrtzidis 0af90586e7 [c-index-test] For the 'core' invocation, avoid running it under a new thread.
It's unnecessary.

llvm-svn: 295934
2017-02-23 05:51:47 +00:00
Rafael Espindola 46f68f50f0 Fix the static build.
llvm-svn: 295245
2017-02-15 22:19:04 +00:00
Argyrios Kyrtzidis 08155c9a54 [c-index-test] CMake: add missing reference to clangSerialization library.
llvm-svn: 293466
2017-01-30 07:11:27 +00:00
Argyrios Kyrtzidis a38cb204a3 [c-index-test] Provide capability to index module file imports and dump their input files.
This ensures the capability to index a module file using an existing ASTReader from a compiler instance or ASTUnit.

llvm-svn: 293461
2017-01-30 06:05:58 +00:00
Argyrios Kyrtzidis 5fab854082 [c-index-test] Provide capability for 'c-index-test core' to dump symbol information from a PCH/module file.
llvm-svn: 293416
2017-01-29 04:50:35 +00:00