Commit Graph

172 Commits

Author SHA1 Message Date
Alexander Kornienko afd5701dc3 Make clang tools ignore -fcolor-diagnostics and -fdiagnostics-color retrieved from the compilation database.
Summary:
Clang tools' diagnostic output could be force colored when a command
line from the compilation database contains -fcolor-diagnostics or
-fdiagnostics-color. This is not what we want e.g. for vim integration.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, revane, jordan_rose

Differential Revision: http://llvm-reviews.chandlerc.com/D917

llvm-svn: 183304
2013-06-05 11:33:11 +00:00
Manuel Klimek d91ac93087 Enables chaining of argument adjusters in clang tools.
This enables changing clang-check to get extra arguments.

Patch by Pavel Labath.

llvm-svn: 183227
2013-06-04 14:44:44 +00:00
Daniel Jasper 2a250b8b49 Let clang-format move the cursor appropriately.
With this patch, clang-format will try to keep the cursor at the
original code position in editor integrations (implemented for emacs and
vim). This means, after formatting, clang-format will try to keep the
cursor on the same character of the same token.

llvm-svn: 182373
2013-05-21 12:21:39 +00:00
Daniel Jasper ec04c0dba0 Add a more convenient interface to use clang-format.
It turns out that several implementations go through the trouble of
setting up a SourceManager and Lexer and abstracting this into a
function makes usage easier.

Also abstracts SourceManager-independent ranges out of
tooling::Refactoring and provides a convenience function to create them
from line ranges.

llvm-svn: 181997
2013-05-16 10:40:07 +00:00
Edwin Vane 34794c5b3d ClangTool output cleanup
Information messages sent to stdout by ClangTool now only happen when the
-debug flag is set.

Error messages that used to go to stdout now go to stderr.

Author: Ariel J Bernal <ariel.j.bernal@intel.com>
llvm-svn: 177177
2013-03-15 20:14:01 +00:00
Edwin Vane 2e9b174da6 Reverting r176944 until Author fixes test failure.
llvm-svn: 176945
2013-03-13 13:48:47 +00:00
Edwin Vane 666f6b6de7 ClangTool output cleanup
Information messages sent to stdout by ClangTool now only happen when the -debug
flag is set.

Error messages that used to go to stdout now go to stderr.

Author: Ariel J Bernal <ariel.j.bernal@intel.com>
llvm-svn: 176944
2013-03-13 13:36:56 +00:00
Peter Collingbourne fe7a348614 CommandLineArgumentParser: handle single quotes.
Differential Revision: http://llvm-reviews.chandlerc.com/D482

llvm-svn: 176404
2013-03-02 06:00:16 +00:00
Sean Silva f1b49e237f Nuke SetUpBuildDumpLog.
Also, it was the only reason that `argc` and `argv` were being passed
into createDiagnostics, so remove those parameters and clean up callers.

llvm-svn: 172945
2013-01-20 01:58:28 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00
Arnaud A. de Grandmaison 3128a11ee8 Fix spurious output in JSONCompilationDatabase
llvm-svn: 172321
2013-01-12 18:37:52 +00:00
Edwin Vane 5038ac0fb8 Allow RefactoringTool to write to memory instead of always to disk
RefactoringTool::run() always writes the result of rewrites to disk.
Instead, make this optional and provide a method for getting the
refactoring results in a memory buffer instead.

Also made ClangTool polymorphic so RefactoringTool could inherit from it
to properly express the IS-A relationship. This change also provides
access to ClangTool's public interface, e.g. mapVirtualFile() which is
important once refactored buffers start living in memory instead of on
disk.

Reviewers: klimek
llvm-svn: 172219
2013-01-11 17:04:55 +00:00
Edwin Vane 524741fbbd Style and Doc fix for CommonOptionsParser
- Renaming GetCompilations() and GetSourcePathList() to follow LLVM
  style.
- Updating docs to reflect name change.
- Also updating help text to not mention clang-check since this class
  can be used by any tool.

Reviewed By: Alexander Kornienko

llvm-svn: 170229
2012-12-14 18:58:25 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
Argyrios Kyrtzidis 251ad5e06b Introduce CompilationDatabase::getAllCompileCommands() that returns all
compile commands of the database and expose it via the libclang API.

llvm-svn: 169226
2012-12-04 07:26:44 +00:00
Rafael Espindola b0448cd52a Remove some dead code. CLANG_IS_PRODUCTION is now just a build flag and
is not used in any #ifdef.

llvm-svn: 168703
2012-11-27 16:10:37 +00:00
Douglas Gregor 811db4eac4 Make DiagnosticOptions intrusively reference-counted, and make sure
the various stakeholders bump up the reference count. In particular,
the diagnostics engine now keeps the DiagnosticOptions object alive.

llvm-svn: 166508
2012-10-23 22:26:28 +00:00
Daniel Jasper 74351ff4ac Only report first error when no compilation database is found.
Review: http://llvm-reviews.chandlerc.com/D62
llvm-svn: 165933
2012-10-15 13:12:24 +00:00
Daniel Jasper 8c059026c0 Hopefully appease Windows buildbot with Japanese (?) error message.
llvm-svn: 165414
2012-10-08 18:37:21 +00:00
Daniel Jasper fddb32c3d6 FileNameMatchTrie: Use StringRef instead of Twines where possible.
llvm-svn: 165412
2012-10-08 18:31:54 +00:00
Daniel Jasper 26cf9c4379 Support symlinks and relative paths in complilation databases.
Review: http://llvm-reviews.chandlerc.com/D30
llvm-svn: 165392
2012-10-08 16:08:15 +00:00
Ted Kremenek cdf814900d Split library clangRewrite into clangRewriteCore and clangRewriteFrontend.
This is similar to how we divide up the StaticAnalyzer libraries to separate
core functionality to what is clearly associated with Frontend actions.

llvm-svn: 163050
2012-09-01 05:09:24 +00:00
Nico Weber 077a53e5ab Tooling: Add a runToolOnCodeWithArgs() function that allows
passing additional parameters to a tool.

Use this to fix a FIXME in testing code.

llvm-svn: 162889
2012-08-30 02:02:19 +00:00
Alexander Kornienko 9ed8c4e941 Only add common tool options when CommonOptionsParser is used.
Summary: Subj.

Reviewers: chandlerc, klimek, djasper

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D29

llvm-svn: 162798
2012-08-28 22:15:41 +00:00
NAKAMURA Takumi d574ac2f4d Fix the definition of JSONAnchorSource. MSVC mangles variable symbols, and "volatile" affects.
llvm-svn: 162550
2012-08-24 10:39:28 +00:00
Daniel Jasper 6ed1f85c24 Use LLVM's plugin registry to enable registering new compilation
databases. Move JSONCompilationDatabase.h to its own files and
register it as plugin.

llvm-svn: 162541
2012-08-24 05:50:27 +00:00
Alexander Kornienko 4bcd58b87d Updated LibTooling.html, minor improvements in CommonOptionsParser
llvm-svn: 162521
2012-08-24 00:39:14 +00:00
Alexander Kornienko 01387267c7 Reverted clang-check to fully supported CommandLine Library use-case: global
static variables.

llvm-svn: 162391
2012-08-22 20:52:52 +00:00
Manuel Klimek 3aad855a89 Fixes a segfault in Tooling when using pch's:
Clear the FileManager's stat cache in between running
translation units, as the stat cache loaded from a pch
is only valid for one compiler invocation.

llvm-svn: 161047
2012-07-31 13:56:54 +00:00
NAKAMURA Takumi 836926dbdf clang/lib: [CMake] Update tblgen'd dependencies.
llvm-svn: 160851
2012-07-27 06:18:33 +00:00
NAKAMURA Takumi 075c89bc06 clang/lib: [CMake] Reformat, alphabetize lists.
llvm-svn: 160850
2012-07-27 06:18:12 +00:00
Alexander Kornienko df36746d52 Reverted custom init hook from r160369.
llvm-svn: 160432
2012-07-18 12:24:51 +00:00
Alexander Kornienko 11330dc726 Add a custom initialize hook for clang tools + minor fixes in CustomCompilationDatabase.h
llvm-svn: 160369
2012-07-17 16:11:17 +00:00
Daniel Jasper 6389dd145d Finishing the move of RefactoringCallbacks and fixing the corresponding
buildbot failures.

llvm-svn: 160355
2012-07-17 08:37:03 +00:00
Daniel Jasper 1975e03494 Move RefactoringCallbacks to Tooling to avoid dependency from
ASTMatchers (lower level abstraction) to Tooling (higher level
abstraction).

llvm-svn: 160351
2012-07-17 08:03:01 +00:00
Ted Kremenek 816255dc39 Fix copy-paste mistake for CMake dependency.
llvm-svn: 160315
2012-07-16 20:22:15 +00:00
Ted Kremenek 42bff962b6 Looks like libTooling might also depend on ClangDiagnosticCommon.
llvm-svn: 160313
2012-07-16 19:44:15 +00:00
Alexander Kornienko f2f82550fd The new clang-ast-dump tool for selective AST dumping. Moved common command-line tool stuff to CommandLineClangTool
llvm-svn: 160265
2012-07-16 12:46:48 +00:00
Manuel Klimek 60b8016197 Allows retrieving all files in a CompilationDatabase.
Patch by Tobias Koenig, some test changes by myself.

llvm-svn: 160167
2012-07-13 12:31:45 +00:00
Daniel Jasper bb89ae9392 Add a hook to supply a custom CompilationDatabase. To add a custom CompilationDatabase, make it implement findCompilationDatabaseForDirectory in CustomCompilationDatabase.h and set USE_COSTUM_COMPILATION_DATABASE.
Differential Revision: http://llvm-reviews.chandlerc.com/D4

llvm-svn: 160061
2012-07-11 19:13:13 +00:00
Arnaud A. de Grandmaison 617f5269c3 Adds support for auto-detection of compilation databases, looking in a directory and all its parents.
llvm-svn: 159998
2012-07-10 16:56:35 +00:00
Manuel Klimek 65fd0e1fd3 Adds support for auto-detection of compilation databases
from a source file and changes clang-check to make use of this.

This makes clang-check just work on in-tree builds, and allows
easy setup via a symlink per source directory to make clang-check
work without any extra configuration.

llvm-svn: 159990
2012-07-10 13:10:51 +00:00
Manuel Klimek 5da9dcb275 Adapts the FrontendAction convenience functions so that it can be
used with classes that generate ASTConsumers; this allows decoupling
the ASTConsumer generation from the Frontend library (like, for example,
the MatchFinder in the upcoming ASTMatcher patch).

llvm-svn: 159760
2012-07-05 18:13:01 +00:00
Chandler Carruth 28969b4139 Remove a goofy CMake hack and use the standard CMake facilities to
express library-level dependencies within Clang.

This is no more verbose really, and plays nicer with the rest of the
CMake facilities. It should also have no change in functionality.

llvm-svn: 158888
2012-06-21 01:30:21 +00:00
Alexander Kornienko 8388d24701 Fixed a problem related to resolution of built-in headers in case a path of tool's binary contains sym-links.
llvm-svn: 157944
2012-06-04 19:02:59 +00:00
NAKAMURA Takumi 4de31654bb ToolInvocation::mapVirtualFile(): Tweak for Win32. Handle the key as native path.
llvm-svn: 157889
2012-06-02 15:34:21 +00:00
Alexander Kornienko 21d6ec9224 Fix an object lifetime issue in clang/Tooling.
llvm-svn: 157759
2012-05-31 17:58:43 +00:00
Manuel Klimek 8b1c60220d Adds a toString method to Replacement, which helps debugging.
Adds missing header guards to Refactoring.h.

llvm-svn: 157694
2012-05-30 16:04:29 +00:00
Alexander Kornienko 9e8d22896c Fixed a memory leak in clang/Tooling.
llvm-svn: 157687
2012-05-30 12:10:28 +00:00
NAKAMURA Takumi 9b2d17c613 Tooling: Canonicalize Key in IndexByFile[]. llvm::sys::path::native() may be used here.
It fixes test/Tooling on Win32 hosts.

llvm-svn: 157350
2012-05-23 22:24:20 +00:00
Manuel Klimek 3f00134c05 Adds the Refactoring library, which is a layer on top of the Tooling library
that allows easy refactoring across translation units.

llvm-svn: 157331
2012-05-23 16:29:20 +00:00
Manuel Klimek fdbe4f9dc2 Fixes crasher bug in JSONCompilationDatabase for invalid input.
llvm-svn: 156814
2012-05-15 11:46:07 +00:00
David Blaikie c9bd941f1f Fix -Wdelete-non-virtual-dtor in Tooling code.
Also, add an anchor as per http://llvm.org/docs/CodingStandards.html#ll_virtual_anch

llvm-svn: 156495
2012-05-09 18:31:50 +00:00
Simon Atanasyan 32df72db66 Declare abstract class ArgumentsAdjuster. This abstract interface describes
a command line argument adjuster, which is responsible for command line
arguments modification before the arguments are used to run a frontend action.

Define class ClangSyntaxOnlyAdjuster implements ArgumentsAdjuster interface.
This class converts input command line arguments to the "syntax check only"
variant.

Reviewed by Manuel Klimek.

llvm-svn: 156478
2012-05-09 16:18:30 +00:00
Manuel Klimek f33dcb0449 Fix includes for unices that don't have chdir declared transitively.
llvm-svn: 156302
2012-05-07 10:02:55 +00:00
Manuel Klimek 74cec54b80 Includes direct.h for windows compilation.
llvm-svn: 156301
2012-05-07 09:45:46 +00:00
Manuel Klimek 805d8dc52a Fixes resolution of relative paths when running clang tools.
The chdir is not the perfect fix, as it is thread hostile. The
real fix will be to make -working-dir work correctly, which will
take time to implement. Before that, the tooling library cannot
be used concurrently.

llvm-svn: 156299
2012-05-07 09:17:48 +00:00
Manuel Klimek 3778a435d1 Fixes the header search logic for tools:
The driver needs to get the correct path to the executable to deduce
the header search path.

llvm-svn: 155542
2012-04-25 09:25:41 +00:00
Manuel Klimek ff26efceb4 Adds a FixedCompilationDatabase to be able to specify tool parameters
at the command line.

llvm-svn: 154989
2012-04-18 07:41:50 +00:00
Manuel Klimek 40636c9986 Switches the JSONCompilationDatabase to use the YAML parser.
This will allow us to delete the JSON parser from llvm.

The biggest change is a general change of strategy - instead
of storing StringRef's to the values for the command line and
directory in the input buffer, we store ScalarNode*'s. The
reason is that the YAML parser's getRawValue on ScalarNodes
returns a string that includes the quotes in case of double
quoted strings.

For the same reason we're removing the JSON parsing part of
the command line parsing - this means an extra copy for a
command line when it is requested (and only when it is requested).

llvm-svn: 154929
2012-04-17 16:54:26 +00:00
Manuel Klimek 3521ae9580 Fixes a fix to finding the current directory:
We currently want to look whether PWD is available - if PWD is available it will
get us the non-resolved current path, while fs::current_path will resolve
symlinks. The long term fix is to not rely on that behavior any more.

llvm-svn: 154330
2012-04-09 18:08:23 +00:00
NAKAMURA Takumi 3a64a4b1ec Tooling.cpp: Reorder inclusions according to the conding standards.
llvm-svn: 154016
2012-04-04 13:59:41 +00:00
NAKAMURA Takumi f0c8779db4 Tooling.cpp: Don't refer to $ENV{PWD}. Use llvm::sys::fs instead.
$ENV{PWD} is not expected to be set on all hosts.

llvm-svn: 154015
2012-04-04 13:59:36 +00:00
Manuel Klimek 47c245a537 Adds a tooling library.
Provides an API to run clang tools (FrontendActions) as standalone tools,
or repeatedly in-memory in a process. This is useful for unit-testing,
map-reduce style applications, source transformation daemons or command line
tools.

The ability to run over multiple translation units with different command
line arguments enables building up refactoring tools that need to apply
transformations across translation unit boundaries.

See tools/clang-check/ClangCheck.cpp for an example.

llvm-svn: 154008
2012-04-04 12:07:46 +00:00
Manuel Klimek 8a160cc42b Reverts the Tooling changes as requested by Chris.
llvm-svn: 132462
2011-06-02 16:58:33 +00:00
Manuel Klimek 0cfc6a045c This patch implements an AST matching framework that allows to write
tools that match on the C++ ASTs. The main interface is in ASTMatchers.h,
an example implementation of a tool that removes redundant .c_str() calls
is in the example RemoveCStrCalls.cpp.

Various contributions:
Zhanyong Wan, Chandler Carruth, Marcin Kowalczyk, Wei Xu, James Dennett.

llvm-svn: 132374
2011-05-31 23:49:32 +00:00
Manuel Klimek c9675152b3 Pulls the common part of the clang-check example into Tooling, to allow new tools to be implemented without duplicating the boilerplate.
llvm-svn: 131425
2011-05-16 21:33:46 +00:00
Nico Weber 1eace078a4 Let clang-check actually use the Directory entry in the json file.
llvm-svn: 131367
2011-05-14 21:20:23 +00:00
Benjamin Kramer e63dbc373a Remove noisy semicolons.
llvm-svn: 130621
2011-04-30 19:55:55 +00:00
Nico Weber e8fdcac02c Add lib/Tooling to the Makefile build.
llvm-svn: 130581
2011-04-30 03:09:18 +00:00
Manuel Klimek 6825eebcd6 This is the next step in building the standalone tools infrastructure:
This patch simplifies writing of standalone Clang tools. As an
example, we add clang-check, a tool that runs a syntax only frontend
action over a .cc file. When you integrate this into your favorite
editor, you get much faster feedback on your compilation errors, thus
reducing your feedback cycle especially when writing new code.

The tool depends on integration of an outstanding patch to CMake to
work which allows you to always have a current compile command
database in your cmake output directory when you set
CMAKE_EXPORT_COMPILE_COMMANDS.

llvm-svn: 130306
2011-04-27 16:39:14 +00:00
Manuel Klimek d861e8b7be Adds a function to run FrontendActions over in-memory code. This is
the first step towards a standalone Clang tool infrastructure.
The plan is to make it easy to build command line tools that run over
the AST of source files in a project outside of the build system.

llvm-svn: 129924
2011-04-21 18:37:41 +00:00