// REQUIRES: asserts<div><br></div><div>?<br><br><div class="gmail_quote">On Mon, Jul 16, 2012 at 2:16 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Release-Asserts isn't supported right now, right, Alexander?<br>
<br>
<a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-July/023009.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-July/023009.html</a><br>
<br>
Not sure how to fix the test in the meantime...<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Jul 16, 2012, at 14:09 , David Dean <<a href="mailto:david_dean@apple.com">david_dean@apple.com</a>> wrote:<br>
<br>
> It doesn't appear to be exclusive to i386, maybe release without asserts?:<br>
><br>
> ******************** TEST 'Clang :: Tooling/clang-ast-dump.cpp' FAILED ********************Script:<br>
> --<br>
> clang-ast-dump "/Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin11-R/clang.src/test/Tooling/clang-ast-dump.cpp" -f test_namespace::TheClass::theMethod -- -c 2>&1|FileCheck /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin11-R/clang.src/test/Tooling/clang-ast-dump.cpp<br>
> --<br>
> Exit Code: 1<br>
> Command Output (stderr):<br>
> --<br>
> /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin11-R/clang.src/test/Tooling/clang-ast-dump.cpp:3:11: error: expected string not found in input<br>
> // CHECK: <CXXMethod ptr="0x{{[0-9a-f]+}}" name="theMethod" prototype="true"><br>
> ^<br>
> <stdin>:1:1: note: scanning from here<br>
> Processing: /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.clang-x86_64-darwin11-R/clang.src/test/Tooling/clang-ast-dump.cpp.<br>
> ^<br>
> --<br>
><br>
> ********************<br>
><br>
> Is there anything I can grab off the builder to help?<br>
><br>
> On 16 Jul 2012, at 1:13 PM, Jim Grosbach wrote:<br>
><br>
>> Hi Alexander,<br>
>><br>
>> This test is failing on i386 (32-bit) Darwin:<br>
>><br>
>>> /Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.apple-clang-x86_64-darwin10-R/clang.src/src/tools/clang/test/Tooling/clang-ast-dump.cpp:3:11: error: expected string not found in input<br>
>>> // CHECK: <CXXMethod ptr="0x{{[0-9a-f]+}}" name="theMethod" prototype="true"><br>
>>> ^<br>
>><br>
>><br>
>> Any idea why that would be? It's not obvious to me what's going wrong.<br>
>><br>
>> -Jim<br>
>><br>
>> On Jul 16, 2012, at 5:46 AM, Alexander Kornienko <<a href="mailto:alexfh@google.com">alexfh@google.com</a>> wrote:<br>
>><br>
>>> Author: alexfh<br>
>>> Date: Mon Jul 16 07:46:48 2012<br>
>>> New Revision: 160265<br>
>>><br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=160265&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=160265&view=rev</a><br>
>>> Log:<br>
>>> The new clang-ast-dump tool for selective AST dumping. Moved common command-line tool stuff to CommandLineClangTool<br>
>>><br>
>>> Added:<br>
>>> cfe/trunk/include/clang/Tooling/CommandLineClangTool.h<br>
>>> cfe/trunk/lib/Tooling/CommandLineClangTool.cpp<br>
>>> cfe/trunk/test/Tooling/clang-ast-dump.cpp<br>
>>> cfe/trunk/tools/clang-ast-dump/<br>
>>> cfe/trunk/tools/clang-ast-dump/CMakeLists.txt<br>
>>> cfe/trunk/tools/clang-ast-dump/ClangASTDump.cpp<br>
>>> cfe/trunk/tools/clang-ast-dump/Makefile<br>
>>> Modified:<br>
>>> cfe/trunk/lib/Tooling/CMakeLists.txt<br>
>>> cfe/trunk/test/CMakeLists.txt<br>
>>> cfe/trunk/tools/CMakeLists.txt<br>
>>> cfe/trunk/tools/Makefile<br>
>>> cfe/trunk/tools/clang-check/ClangCheck.cpp<br>
>>><br>
>>> Added: cfe/trunk/include/clang/Tooling/CommandLineClangTool.h<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CommandLineClangTool.h?rev=160265&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CommandLineClangTool.h?rev=160265&view=auto</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/include/clang/Tooling/CommandLineClangTool.h (added)<br>
>>> +++ cfe/trunk/include/clang/Tooling/CommandLineClangTool.h Mon Jul 16 07:46:48 2012<br>
>>> @@ -0,0 +1,80 @@<br>
>>> +//===- CommandLineClangTool.h - command-line clang tools driver -*- C++ -*-===//<br>
>>> +//<br>
>>> +// The LLVM Compiler Infrastructure<br>
>>> +//<br>
>>> +// This file is distributed under the University of Illinois Open Source<br>
>>> +// License. See LICENSE.TXT for details.<br>
>>> +//<br>
>>> +//===----------------------------------------------------------------------===//<br>
>>> +//<br>
>>> +// This file implements the CommandLineClangTool class used to run clang<br>
>>> +// tools as separate command-line applications with a consistent common<br>
>>> +// interface for handling compilation database and input files.<br>
>>> +//<br>
>>> +// It provides a common subset of command-line options, common algorithm<br>
>>> +// for locating a compilation database and source files, and help messages<br>
>>> +// for the basic command-line interface.<br>
>>> +//<br>
>>> +// It creates a CompilationDatabase, initializes a ClangTool and runs a<br>
>>> +// user-specified FrontendAction over all TUs in which the given files are<br>
>>> +// compiled.<br>
>>> +//<br>
>>> +// This class uses the Clang Tooling infrastructure, see<br>
>>> +// <a href="http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html" target="_blank">http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html</a><br>
>>> +// for details on setting it up with LLVM source tree.<br>
>>> +//<br>
>>> +//===----------------------------------------------------------------------===//<br>
>>> +<br>
>>> +#ifndef LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H<br>
>>> +#define LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H<br>
>>> +<br>
>>> +#include "llvm/Support/CommandLine.h"<br>
>>> +#include "clang/Tooling/CompilationDatabase.h"<br>
>>> +<br>
>>> +namespace clang {<br>
>>> +<br>
>>> +namespace tooling {<br>
>>> +<br>
>>> +class CompilationDatabase;<br>
>>> +class FrontendActionFactory;<br>
>>> +<br>
>>> +/// \brief A common driver for command-line Clang tools.<br>
>>> +///<br>
>>> +/// Parses a common subset of command-line arguments, locates and loads a<br>
>>> +/// compilation commands database, runs a tool with user-specified action. It<br>
>>> +/// also contains a help message for the common command-line options.<br>
>>> +/// An example of usage:<br>
>>> +/// @code<br>
>>> +/// int main(int argc, const char **argv) {<br>
>>> +/// CommandLineClangTool Tool;<br>
>>> +/// cl::extrahelp MoreHelp("\nMore help text...");<br>
>>> +/// Tool.initialize(argc, argv);<br>
>>> +/// return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());<br>
>>> +/// }<br>
>>> +/// @endcode<br>
>>> +///<br>
>>> +class CommandLineClangTool {<br>
>>> +public:<br>
>>> + /// Sets up command-line options and help messages.<br>
>>> + /// Add your own help messages after constructing this tool.<br>
>>> + CommandLineClangTool();<br>
>>> +<br>
>>> + /// Parses command-line, initializes a compilation database.<br>
>>> + /// This method exits program in case of error.<br>
>>> + void initialize(int argc, const char **argv);<br>
>>> +<br>
>>> + /// Runs a clang tool with an action created by \c ActionFactory.<br>
>>> + int run(FrontendActionFactory *ActionFactory);<br>
>>> +<br>
>>> +private:<br>
>>> + llvm::OwningPtr<CompilationDatabase> Compilations;<br>
>>> + llvm::cl::opt<std::string> BuildPath;<br>
>>> + llvm::cl::list<std::string> SourcePaths;<br>
>>> + llvm::cl::extrahelp MoreHelp;<br>
>>> +};<br>
>>> +<br>
>>> +} // namespace tooling<br>
>>> +<br>
>>> +} // namespace clang<br>
>>> +<br>
>>> +#endif // LLVM_TOOLS_CLANG_INCLUDE_CLANG_TOOLING_COMMANDLINECLANGTOOL_H<br>
>>><br>
>>> Modified: cfe/trunk/lib/Tooling/CMakeLists.txt<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CMakeLists.txt?rev=160265&r1=160264&r2=160265&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CMakeLists.txt?rev=160265&r1=160264&r2=160265&view=diff</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/lib/Tooling/CMakeLists.txt (original)<br>
>>> +++ cfe/trunk/lib/Tooling/CMakeLists.txt Mon Jul 16 07:46:48 2012<br>
>>> @@ -1,6 +1,7 @@<br>
>>> set(LLVM_LINK_COMPONENTS support)<br>
>>><br>
>>> add_clang_library(clangTooling<br>
>>> + CommandLineClangTool.cpp<br>
>>> CompilationDatabase.cpp<br>
>>> Refactoring.cpp<br>
>>> Tooling.cpp<br>
>>><br>
>>> Added: cfe/trunk/lib/Tooling/CommandLineClangTool.cpp<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommandLineClangTool.cpp?rev=160265&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommandLineClangTool.cpp?rev=160265&view=auto</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/lib/Tooling/CommandLineClangTool.cpp (added)<br>
>>> +++ cfe/trunk/lib/Tooling/CommandLineClangTool.cpp Mon Jul 16 07:46:48 2012<br>
>>> @@ -0,0 +1,80 @@<br>
>>> +//===--- CommandLineClangTool.cpp - command-line clang tools driver -------===//<br>
>>> +//<br>
>>> +// The LLVM Compiler Infrastructure<br>
>>> +//<br>
>>> +// This file is distributed under the University of Illinois Open Source<br>
>>> +// License. See LICENSE.TXT for details.<br>
>>> +//<br>
>>> +//===----------------------------------------------------------------------===//<br>
>>> +//<br>
>>> +// This file implements the CommandLineClangTool class used to run clang<br>
>>> +// tools as separate command-line applications with a consistent common<br>
>>> +// interface for handling compilation database and input files.<br>
>>> +//<br>
>>> +// It provides a common subset of command-line options, common algorithm<br>
>>> +// for locating a compilation database and source files, and help messages<br>
>>> +// for the basic command-line interface.<br>
>>> +//<br>
>>> +// It creates a CompilationDatabase, initializes a ClangTool and runs a<br>
>>> +// user-specified FrontendAction over all TUs in which the given files are<br>
>>> +// compiled.<br>
>>> +//<br>
>>> +//===----------------------------------------------------------------------===//<br>
>>> +<br>
>>> +#include "clang/Frontend/FrontendActions.h"<br>
>>> +#include "clang/Tooling/CommandLineClangTool.h"<br>
>>> +#include "clang/Tooling/Tooling.h"<br>
>>> +<br>
>>> +using namespace clang::tooling;<br>
>>> +using namespace llvm;<br>
>>> +<br>
>>> +static const char *MoreHelpText =<br>
>>> + "\n"<br>
>>> + "-p <build-path> is used to read a compile command database.\n"<br>
>>> + "\n"<br>
>>> + "\tFor example, it can be a CMake build directory in which a file named\n"<br>
>>> + "\tcompile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON\n"<br>
>>> + "\tCMake option to get this output). When no build path is specified,\n"<br>
>>> + "\tclang-check will attempt to locate it automatically using all parent\n"<br>
>>> + "\tpaths of the first input file. See:\n"<br>
>>> + "\thttp://<a href="http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html" target="_blank">clang.llvm.org/docs/HowToSetupToolingForLLVM.html</a> for an\n"<br>
>>> + "\texample of setting up Clang Tooling on a source tree.\n"<br>
>>> + "\n"<br>
>>> + "<source0> ... specify the paths of source files. These paths are looked\n"<br>
>>> + "\tup in the compile command database. If the path of a file is absolute,\n"<br>
>>> + "\tit needs to point into CMake's source tree. If the path is relative,\n"<br>
>>> + "\tthe current working directory needs to be in the CMake source tree and\n"<br>
>>> + "\tthe file must be in a subdirectory of the current working directory.\n"<br>
>>> + "\t\"./\" prefixes in the relative files will be automatically removed,\n"<br>
>>> + "\tbut the rest of a relative path must be a suffix of a path in the\n"<br>
>>> + "\tcompile command database.\n"<br>
>>> + "\n";<br>
>>> +<br>
>>> +CommandLineClangTool::CommandLineClangTool() :<br>
>>> + BuildPath("p", cl::desc("Build path"), cl::Optional),<br>
>>> + SourcePaths(cl::Positional, cl::desc("<source0> [... <sourceN>]"),<br>
>>> + cl::OneOrMore),<br>
>>> + MoreHelp(MoreHelpText) {<br>
>>> +}<br>
>>> +<br>
>>> +void CommandLineClangTool::initialize(int argc, const char **argv) {<br>
>>> + Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv));<br>
>>> + cl::ParseCommandLineOptions(argc, argv);<br>
>>> + if (!Compilations) {<br>
>>> + std::string ErrorMessage;<br>
>>> + if (!BuildPath.empty()) {<br>
>>> + Compilations.reset(CompilationDatabase::autoDetectFromDirectory(<br>
>>> + BuildPath, ErrorMessage));<br>
>>> + } else {<br>
>>> + Compilations.reset(CompilationDatabase::autoDetectFromSource(<br>
>>> + SourcePaths[0], ErrorMessage));<br>
>>> + }<br>
>>> + if (!Compilations)<br>
>>> + llvm::report_fatal_error(ErrorMessage);<br>
>>> + }<br>
>>> +}<br>
>>> +<br>
>>> +int CommandLineClangTool::run(FrontendActionFactory *ActionFactory) {<br>
>>> + ClangTool Tool(*Compilations, SourcePaths);<br>
>>> + return Tool.run(ActionFactory);<br>
>>> +}<br>
>>><br>
>>> Modified: cfe/trunk/test/CMakeLists.txt<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=160265&r1=160264&r2=160265&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=160265&r1=160264&r2=160265&view=diff</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/test/CMakeLists.txt (original)<br>
>>> +++ cfe/trunk/test/CMakeLists.txt Mon Jul 16 07:46:48 2012<br>
>>> @@ -31,7 +31,7 @@<br>
>>> set(CLANG_TEST_DEPS<br>
>>> clang clang-headers<br>
>>> c-index-test diagtool arcmt-test c-arcmt-test<br>
>>> - clang-check<br>
>>> + clang-check clang-ast-dump<br>
>>> llvm-dis llc opt FileCheck count not<br>
>>> )<br>
>>> set(CLANG_TEST_PARAMS<br>
>>> @@ -80,7 +80,7 @@<br>
>>> COMMENT "Running Clang regression tests"<br>
>>> DEPENDS clang clang-headers<br>
>>> c-index-test diagtool arcmt-test c-arcmt-test<br>
>>> - clang-check<br>
>>> + clang-check clang-ast-dump<br>
>>> )<br>
>>> set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")<br>
>>> endif()<br>
>>><br>
>>> Added: cfe/trunk/test/Tooling/clang-ast-dump.cpp<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-ast-dump.cpp?rev=160265&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-ast-dump.cpp?rev=160265&view=auto</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/test/Tooling/clang-ast-dump.cpp (added)<br>
>>> +++ cfe/trunk/test/Tooling/clang-ast-dump.cpp Mon Jul 16 07:46:48 2012<br>
>>> @@ -0,0 +1,22 @@<br>
>>> +// RUN: clang-ast-dump "%t/test.cpp" -f test_namespace::TheClass::theMethod -- -c 2>&1|FileCheck %s<br>
>>> +// FIXME: Make the above easier.<br>
>>> +<br>
>>> +// CHECK: <CXXMethod ptr="0x{{[0-9a-f]+}}" name="theMethod" prototype="true"><br>
>>> +// CHECK: <ParmVar ptr="0x{{[0-9a-f]+}}" name="x" initstyle="c"><br>
>>> +// CHECK: (CompoundStmt<br>
>>> +// CHECK-NEXT: (ReturnStmt<br>
>>> +// CHECK-NEXT: (BinaryOperator<br>
>>> +<br>
>>> +namespace test_namespace {<br>
>>> +<br>
>>> +class TheClass {<br>
>>> +public:<br>
>>> + int theMethod(int x) {<br>
>>> + return x + x;<br>
>>> + }<br>
>>> +};<br>
>>> +<br>
>>> +}<br>
>>> +<br>
>>> +// FIXME: This is incompatible to -fms-compatibility.<br>
>>> +// XFAIL: win32<br>
>>><br>
>>> Modified: cfe/trunk/tools/CMakeLists.txt<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=160265&r1=160264&r2=160265&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=160265&r1=160264&r2=160265&view=diff</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/tools/CMakeLists.txt (original)<br>
>>> +++ cfe/trunk/tools/CMakeLists.txt Mon Jul 16 07:46:48 2012<br>
>>> @@ -5,3 +5,4 @@<br>
>>> add_subdirectory(diagtool)<br>
>>> add_subdirectory(driver)<br>
>>> add_subdirectory(clang-check)<br>
>>> +add_subdirectory(clang-ast-dump)<br>
>>><br>
>>> Modified: cfe/trunk/tools/Makefile<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/Makefile?rev=160265&r1=160264&r2=160265&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/Makefile?rev=160265&r1=160264&r2=160265&view=diff</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/tools/Makefile (original)<br>
>>> +++ cfe/trunk/tools/Makefile Mon Jul 16 07:46:48 2012<br>
>>> @@ -9,7 +9,7 @@<br>
>>><br>
>>> CLANG_LEVEL := ..<br>
>>> DIRS := driver libclang c-index-test arcmt-test c-arcmt-test diagtool \<br>
>>> - clang-check<br>
>>> + clang-check clang-ast-dump<br>
>>><br>
>>> include $(CLANG_LEVEL)/../../Makefile.config<br>
>>><br>
>>><br>
>>> Added: cfe/trunk/tools/clang-ast-dump/CMakeLists.txt<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-ast-dump/CMakeLists.txt?rev=160265&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-ast-dump/CMakeLists.txt?rev=160265&view=auto</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/tools/clang-ast-dump/CMakeLists.txt (added)<br>
>>> +++ cfe/trunk/tools/clang-ast-dump/CMakeLists.txt Mon Jul 16 07:46:48 2012<br>
>>> @@ -0,0 +1,8 @@<br>
>>> +add_clang_executable(clang-ast-dump<br>
>>> + ClangASTDump.cpp<br>
>>> + )<br>
>>> +<br>
>>> +target_link_libraries(clang-ast-dump<br>
>>> + clangTooling<br>
>>> + clangBasic<br>
>>> + )<br>
>>><br>
>>> Added: cfe/trunk/tools/clang-ast-dump/ClangASTDump.cpp<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-ast-dump/ClangASTDump.cpp?rev=160265&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-ast-dump/ClangASTDump.cpp?rev=160265&view=auto</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/tools/clang-ast-dump/ClangASTDump.cpp (added)<br>
>>> +++ cfe/trunk/tools/clang-ast-dump/ClangASTDump.cpp Mon Jul 16 07:46:48 2012<br>
>>> @@ -0,0 +1,141 @@<br>
>>> +//===- tools/clang-ast-dump/ClangASTDump.cpp - Clang AST Dump tool --------===//<br>
>>> +//<br>
>>> +// The LLVM Compiler Infrastructure<br>
>>> +//<br>
>>> +// This file is distributed under the University of Illinois Open Source<br>
>>> +// License. See LICENSE.TXT for details.<br>
>>> +//<br>
>>> +//===----------------------------------------------------------------------===//<br>
>>> +//<br>
>>> +// This file implements a clang-ast-dump tool that dumps specified parts<br>
>>> +// of an AST of a number of translation units.<br>
>>> +//<br>
>>> +// Run with '-help' for details.<br>
>>> +//<br>
>>> +// This tool uses the Clang Tooling infrastructure, see<br>
>>> +// <a href="http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html" target="_blank">http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html</a><br>
>>> +// for details on setting it up with LLVM source tree.<br>
>>> +//<br>
>>> +//===----------------------------------------------------------------------===//<br>
>>> +<br>
>>> +#include "llvm/Support/CommandLine.h"<br>
>>> +#include "clang/AST/ASTContext.h"<br>
>>> +#include "clang/AST/ASTConsumer.h"<br>
>>> +#include "clang/AST/RecursiveASTVisitor.h"<br>
>>> +#include "clang/Frontend/FrontendActions.h"<br>
>>> +#include "clang/Tooling/CommandLineClangTool.h"<br>
>>> +#include "clang/Tooling/Tooling.h"<br>
>>> +<br>
>>> +using namespace clang::tooling;<br>
>>> +using namespace llvm;<br>
>>> +<br>
>>> +cl::opt<std::string> FilterString(<br>
>>> + "f",<br>
>>> + cl::desc("Filter string"),<br>
>>> + cl::Optional);<br>
>>> +<br>
>>> +cl::opt<bool> ListAll(<br>
>>> + "l",<br>
>>> + cl::desc("List all filterable nodes"),<br>
>>> + cl::init(false),<br>
>>> + cl::Optional);<br>
>>> +<br>
>>> +static const char *MoreHelpText =<br>
>>> + "-f <filter-string> can be used to dump only AST declaration nodes having\n"<br>
>>> + "\ta certain substring in a qualified name.\n"<br>
>>> + "\n"<br>
>>> + "-l \tlists qualified names of all filterable declaration nodes.\n"<br>
>>> + "\n";<br>
>>> +<br>
>>> +namespace {<br>
>>> +<br>
>>> +using namespace clang;<br>
>>> +<br>
>>> +class SelectiveDumpVisitor :<br>
>>> + public RecursiveASTVisitor<SelectiveDumpVisitor> {<br>
>>> + typedef RecursiveASTVisitor<SelectiveDumpVisitor> base;<br>
>>> +public:<br>
>>> + SelectiveDumpVisitor(const std::string &FilterString, bool ListAll)<br>
>>> + : FilterString(FilterString), ListAll(ListAll) {}<br>
>>> +<br>
>>> + ASTConsumer* newASTConsumer() {<br>
>>> + return new DumpConsumer(this);<br>
>>> + }<br>
>>> +<br>
>>> + bool shouldWalkTypesOfTypeLocs() const { return false; }<br>
>>> +<br>
>>> + void Run(TranslationUnitDecl *D) {<br>
>>> + if (ListAll) {<br>
>>> + llvm::outs().changeColor(llvm::raw_ostream::BLUE) <<<br>
>>> + "Listing all filterable nodes:\n";<br>
>>> + llvm::outs().resetColor();<br>
>>> + TraverseDecl(D);<br>
>>> + return;<br>
>>> + }<br>
>>> +<br>
>>> + if (FilterString.empty()) {<br>
>>> + llvm::outs().changeColor(llvm::raw_ostream::BLUE) <<<br>
>>> + "Dumping translation unit:\n";<br>
>>> + llvm::outs().resetColor();<br>
>>> + D->dumpXML(llvm::outs());<br>
>>> + return;<br>
>>> + }<br>
>>> +<br>
>>> + TraverseDecl(D);<br>
>>> + }<br>
>>> +<br>
>>> + bool TraverseDecl(Decl *D) {<br>
>>> + if (ListAll) {<br>
>>> + std::string Name = getName(D);<br>
>>> + if (!Name.empty())<br>
>>> + llvm::outs() << Name << "\n";<br>
>>> + return base::TraverseDecl(D);<br>
>>> + }<br>
>>> +<br>
>>> + if (filterMatches(D)) {<br>
>>> + llvm::outs().changeColor(llvm::raw_ostream::BLUE) <<<br>
>>> + "Dumping " << getName(D) << ":\n";<br>
>>> + llvm::outs().resetColor();<br>
>>> + D->dumpXML(llvm::outs());<br>
>>> + return true;<br>
>>> + }<br>
>>> + return base::TraverseDecl(D);<br>
>>> + }<br>
>>> +<br>
>>> +private:<br>
>>> + std::string getName(Decl *D) {<br>
>>> + if (isa<NamedDecl>(D))<br>
>>> + return cast<NamedDecl>(D)->getQualifiedNameAsString();<br>
>>> + return "";<br>
>>> + }<br>
>>> + bool filterMatches(Decl *D) {<br>
>>> + return getName(D).find(FilterString) != std::string::npos;<br>
>>> + }<br>
>>> +<br>
>>> + class DumpConsumer : public ASTConsumer {<br>
>>> + public:<br>
>>> + DumpConsumer(SelectiveDumpVisitor *Visitor) : Visitor(Visitor) {}<br>
>>> +<br>
>>> + virtual void HandleTranslationUnit(ASTContext &Context) {<br>
>>> + Visitor->Context = &Context;<br>
>>> + Visitor->Run(Context.getTranslationUnitDecl());<br>
>>> + }<br>
>>> +<br>
>>> + private:<br>
>>> + SelectiveDumpVisitor *Visitor;<br>
>>> + };<br>
>>> +<br>
>>> + ASTContext *Context;<br>
>>> + std::string FilterString;<br>
>>> + bool ListAll;<br>
>>> +};<br>
>>> +<br>
>>> +} // namespace<br>
>>> +<br>
>>> +int main(int argc, const char **argv) {<br>
>>> + CommandLineClangTool Tool;<br>
>>> + cl::extrahelp MoreHelp(MoreHelpText);<br>
>>> + Tool.initialize(argc, argv);<br>
>>> + SelectiveDumpVisitor Dumper(FilterString, ListAll);<br>
>>> + return Tool.run(newFrontendActionFactory(&Dumper));<br>
>>> +}<br>
>>><br>
>>> Added: cfe/trunk/tools/clang-ast-dump/Makefile<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-ast-dump/Makefile?rev=160265&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-ast-dump/Makefile?rev=160265&view=auto</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/tools/clang-ast-dump/Makefile (added)<br>
>>> +++ cfe/trunk/tools/clang-ast-dump/Makefile Mon Jul 16 07:46:48 2012<br>
>>> @@ -0,0 +1,23 @@<br>
>>> +##===- tools/clang-check/Makefile --------------------------*- Makefile -*-===##<br>
>>> +#<br>
>>> +# The LLVM Compiler Infrastructure<br>
>>> +#<br>
>>> +# This file is distributed under the University of Illinois Open Source<br>
>>> +# License. See LICENSE.TXT for details.<br>
>>> +#<br>
>>> +##===----------------------------------------------------------------------===##<br>
>>> +<br>
>>> +CLANG_LEVEL := ../..<br>
>>> +<br>
>>> +TOOLNAME = clang-ast-dump<br>
>>> +NO_INSTALL = 1<br>
>>> +<br>
>>> +# No plugins, optimize startup time.<br>
>>> +TOOL_NO_EXPORTS = 1<br>
>>> +<br>
>>> +LINK_COMPONENTS := support mc<br>
>>> +USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \<br>
>>> + clangTooling.a clangParse.a clangSema.a clangAnalysis.a \<br>
>>> + clangEdit.a clangAST.a clangLex.a clangBasic.a<br>
>>> +<br>
>>> +include $(CLANG_LEVEL)/Makefile<br>
>>><br>
>>> Modified: cfe/trunk/tools/clang-check/ClangCheck.cpp<br>
>>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/ClangCheck.cpp?rev=160265&r1=160264&r2=160265&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/ClangCheck.cpp?rev=160265&r1=160264&r2=160265&view=diff</a><br>
>>> ==============================================================================<br>
>>> --- cfe/trunk/tools/clang-check/ClangCheck.cpp (original)<br>
>>> +++ cfe/trunk/tools/clang-check/ClangCheck.cpp Mon Jul 16 07:46:48 2012<br>
>>> @@ -1,4 +1,4 @@<br>
>>> -//===- examples/Tooling/ClangCheck.cpp - Clang check tool -----------------===//<br>
>>> +//===- tools/clang-check/ClangCheck.cpp - Clang check tool ----------------===//<br>
>>> //<br>
>>> // The LLVM Compiler Infrastructure<br>
>>> //<br>
>>> @@ -10,75 +10,37 @@<br>
>>> // This file implements a clang-check tool that runs the<br>
>>> // clang::SyntaxOnlyAction over a number of translation units.<br>
>>> //<br>
>>> +// This tool uses the Clang Tooling infrastructure, see<br>
>>> +// <a href="http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html" target="_blank">http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html</a><br>
>>> +// for details on setting it up with LLVM source tree.<br>
>>> +//<br>
>>> //===----------------------------------------------------------------------===//<br>
>>><br>
>>> #include "llvm/Support/CommandLine.h"<br>
>>> #include "clang/Frontend/FrontendActions.h"<br>
>>> -#include "clang/Tooling/CompilationDatabase.h"<br>
>>> +#include "clang/Tooling/CommandLineClangTool.h"<br>
>>> #include "clang/Tooling/Tooling.h"<br>
>>><br>
>>> using namespace clang::tooling;<br>
>>> using namespace llvm;<br>
>>><br>
>>> -cl::opt<std::string> BuildPath(<br>
>>> - "p",<br>
>>> - cl::desc("<build-path>"),<br>
>>> - cl::Optional);<br>
>>> -<br>
>>> -cl::list<std::string> SourcePaths(<br>
>>> - cl::Positional,<br>
>>> - cl::desc("<source0> [... <sourceN>]"),<br>
>>> - cl::OneOrMore);<br>
>>> -<br>
>>> -static cl::extrahelp MoreHelp(<br>
>>> - "\n"<br>
>>> - "<build-path> is used to read a compile command database.\n"<br>
>>> - "\n"<br>
>>> - "For example, it can be a CMake build directory in which a file named\n"<br>
>>> - "compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON\n"<br>
>>> - "CMake option to get this output). When no build path is specified,\n"<br>
>>> - "clang-check will attempt to locate it automatically using all parent\n"<br>
>>> - "paths of the first input file.\n"<br>
>>> - "\n"<br>
>>> - "<source0> ... specify the paths of source files. These paths are looked\n"<br>
>>> - "up in the compile command database. If the path of a file is absolute,\n"<br>
>>> - "it needs to point into CMake's source tree. If the path is relative,\n"<br>
>>> - "the current working directory needs to be in the CMake source tree and\n"<br>
>>> - "the file must be in a subdirectory of the current working directory.\n"<br>
>>> - "\"./\" prefixes in the relative files will be automatically removed,\n"<br>
>>> - "but the rest of a relative path must be a suffix of a path in the\n"<br>
>>> - "compile command database.\n"<br>
>>> - "\n"<br>
>>> - "For example, to use clang-check on all files in a subtree of the source\n"<br>
>>> - "tree, use:\n"<br>
>>> - "\n"<br>
>>> - " find path/in/subtree -name '*.cpp'|xargs clang-check\n"<br>
>>> +static const char *MoreHelpText =<br>
>>> + "\tFor example, to run clang-check on all files in a subtree of the\n"<br>
>>> + "\tsource tree, use:\n"<br>
>>> "\n"<br>
>>> - "or using a specific build path:\n"<br>
>>> + "\t find path/in/subtree -name '*.cpp'|xargs clang-check\n"<br>
>>> "\n"<br>
>>> - " find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path\n"<br>
>>> + "\tor using a specific build path:\n"<br>
>>> "\n"<br>
>>> - "Note, that path/in/subtree and current directory should follow the\n"<br>
>>> - "rules described above.\n"<br>
>>> + "\t find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path\n"<br>
>>> "\n"<br>
>>> -);<br>
>>> + "\tNote, that path/in/subtree and current directory should follow the\n"<br>
>>> + "\trules described above.\n"<br>
>>> + "\n";<br>
>>><br>
>>> int main(int argc, const char **argv) {<br>
>>> - llvm::OwningPtr<CompilationDatabase> Compilations(<br>
>>> - FixedCompilationDatabase::loadFromCommandLine(argc, argv));<br>
>>> - cl::ParseCommandLineOptions(argc, argv);<br>
>>> - if (!Compilations) {<br>
>>> - std::string ErrorMessage;<br>
>>> - if (!BuildPath.empty()) {<br>
>>> - Compilations.reset(<br>
>>> - CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage));<br>
>>> - } else {<br>
>>> - Compilations.reset(CompilationDatabase::autoDetectFromSource(<br>
>>> - SourcePaths[0], ErrorMessage));<br>
>>> - }<br>
>>> - if (!Compilations)<br>
>>> - llvm::report_fatal_error(ErrorMessage);<br>
>>> - }<br>
>>> - ClangTool Tool(*Compilations, SourcePaths);<br>
>>> + CommandLineClangTool Tool;<br>
>>> + cl::extrahelp MoreHelp(MoreHelpText);<br>
>>> + Tool.initialize(argc, argv);<br>
>>> return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>());<br>
>>> }<br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> cfe-commits mailing list<br>
>>> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
>>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
>><br>
>> _______________________________________________<br>
>> cfe-commits mailing list<br>
>> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
><br>
> -David<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>