summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-06-27 10:45:02 +0000
committered <ed@FreeBSD.org>2009-06-27 10:45:02 +0000
commitc1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a (patch)
tree2c5a83521a20c02e7805581a174008aa9bc23579 /tools
parent14660dbe9881f68a6cc2b9f014e1fb7b7228bca4 (diff)
downloadFreeBSD-src-c1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a.zip
FreeBSD-src-c1ff020ff2d3e7ba86f7ab986ac7569c34f2ab1a.tar.gz
Import Clang r74383.
Diffstat (limited to 'tools')
-rw-r--r--tools/CMakeLists.txt1
-rw-r--r--tools/Makefile2
-rw-r--r--tools/clang-cc/CMakeLists.txt1
-rw-r--r--tools/clang-cc/clang-cc.cpp100
-rw-r--r--tools/index-test/CMakeLists.txt17
-rw-r--r--tools/index-test/Makefile23
-rw-r--r--tools/index-test/index-test.cpp150
7 files changed, 217 insertions, 77 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 6c66dea..fc30fb8 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -1,2 +1,3 @@
add_subdirectory(clang-cc)
add_subdirectory(driver)
+add_subdirectory(index-test)
diff --git a/tools/Makefile b/tools/Makefile
index 43124ba..5b49cc8 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -8,6 +8,6 @@
##===----------------------------------------------------------------------===##
LEVEL := ../../..
-DIRS := clang-cc driver
+DIRS := clang-cc driver index-test
include $(LEVEL)/Makefile.common
diff --git a/tools/clang-cc/CMakeLists.txt b/tools/clang-cc/CMakeLists.txt
index ec2ea3d..e224d40 100644
--- a/tools/clang-cc/CMakeLists.txt
+++ b/tools/clang-cc/CMakeLists.txt
@@ -24,3 +24,4 @@ set( LLVM_LINK_COMPONENTS
add_clang_executable(clang-cc
clang-cc.cpp
)
+add_dependencies(clang-cc clang-headers)
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 39d839e..a3ffb48 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -33,6 +33,7 @@
#include "clang/Frontend/PCHReader.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Frontend/CommandLineSourceLoc.h"
#include "clang/Frontend/Utils.h"
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/CodeGen/ModuleBuilder.h"
@@ -79,85 +80,19 @@ using namespace clang;
// Source Location Parser
//===----------------------------------------------------------------------===//
-/// \brief A source location that has been parsed on the command line.
-struct ParsedSourceLocation {
- std::string FileName;
- unsigned Line;
- unsigned Column;
-
- /// \brief Try to resolve the file name of a parsed source location.
- ///
- /// \returns true if there was an error, false otherwise.
- bool ResolveLocation(FileManager &FileMgr, RequestedSourceLocation &Result);
-};
-
-bool
-ParsedSourceLocation::ResolveLocation(FileManager &FileMgr,
- RequestedSourceLocation &Result) {
- const FileEntry *File = FileMgr.getFile(FileName);
+static bool ResolveParsedLocation(ParsedSourceLocation &ParsedLoc,
+ FileManager &FileMgr,
+ RequestedSourceLocation &Result) {
+ const FileEntry *File = FileMgr.getFile(ParsedLoc.FileName);
if (!File)
return true;
Result.File = File;
- Result.Line = Line;
- Result.Column = Column;
+ Result.Line = ParsedLoc.Line;
+ Result.Column = ParsedLoc.Column;
return false;
}
-namespace llvm {
- namespace cl {
- /// \brief Command-line option parser that parses source locations.
- ///
- /// Source locations are of the form filename:line:column.
- template<>
- class parser<ParsedSourceLocation>
- : public basic_parser<ParsedSourceLocation> {
- public:
- bool parse(Option &O, const char *ArgName,
- const std::string &ArgValue,
- ParsedSourceLocation &Val);
- };
-
- bool
- parser<ParsedSourceLocation>::
- parse(Option &O, const char *ArgName, const std::string &ArgValue,
- ParsedSourceLocation &Val) {
- using namespace clang;
-
- const char *ExpectedFormat
- = "source location must be of the form filename:line:column";
- std::string::size_type SecondColon = ArgValue.rfind(':');
- if (SecondColon == std::string::npos) {
- std::fprintf(stderr, "%s\n", ExpectedFormat);
- return true;
- }
- char *EndPtr;
- long Column
- = std::strtol(ArgValue.c_str() + SecondColon + 1, &EndPtr, 10);
- if (EndPtr != ArgValue.c_str() + ArgValue.size()) {
- std::fprintf(stderr, "%s\n", ExpectedFormat);
- return true;
- }
-
- std::string::size_type FirstColon = ArgValue.rfind(':', SecondColon-1);
- if (FirstColon == std::string::npos) {
- std::fprintf(stderr, "%s\n", ExpectedFormat);
- return true;
- }
- long Line = std::strtol(ArgValue.c_str() + FirstColon + 1, &EndPtr, 10);
- if (EndPtr != ArgValue.c_str() + SecondColon) {
- std::fprintf(stderr, "%s\n", ExpectedFormat);
- return true;
- }
-
- Val.FileName = ArgValue.substr(0, FirstColon);
- Val.Line = Line;
- Val.Column = Column;
- return false;
- }
- }
-}
-
//===----------------------------------------------------------------------===//
// Global options.
//===----------------------------------------------------------------------===//
@@ -380,13 +315,15 @@ enum LangKind {
langkind_objc,
langkind_objc_cpp,
langkind_objcxx,
- langkind_objcxx_cpp
+ langkind_objcxx_cpp,
+ langkind_ocl
};
static llvm::cl::opt<LangKind>
BaseLang("x", llvm::cl::desc("Base language to compile"),
llvm::cl::init(langkind_unspecified),
llvm::cl::values(clEnumValN(langkind_c, "c", "C"),
+ clEnumValN(langkind_ocl, "cl", "OpenCL C"),
clEnumValN(langkind_cxx, "c++", "C++"),
clEnumValN(langkind_objc, "objective-c", "Objective C"),
clEnumValN(langkind_objcxx,"objective-c++","Objective C++"),
@@ -497,6 +434,8 @@ static LangKind GetLanguage(const std::string &Filename) {
else if (Ext == "C" || Ext == "cc" || Ext == "cpp" || Ext == "CPP" ||
Ext == "c++" || Ext == "cp" || Ext == "cxx")
return langkind_cxx;
+ else if (Ext == "cl")
+ return langkind_ocl;
else
return langkind_c;
}
@@ -545,6 +484,12 @@ static void InitializeLangOptions(LangOptions &Options, LangKind LK){
Options.ObjC1 = Options.ObjC2 = 1;
Options.CPlusPlus = 1;
break;
+ case langkind_ocl:
+ Options.OpenCL = 1;
+ Options.AltiVec = 1;
+ Options.CXXOperatorNames = 1;
+ Options.LaxVectorConversions = 1;
+ break;
}
if (ObjCExclusiveGC)
@@ -729,6 +674,9 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
// Based on the base language, pick one.
switch (LK) {
case lang_unspecified: assert(0 && "Unknown base language");
+ case langkind_ocl:
+ LangStd = lang_c99;
+ break;
case langkind_c:
case langkind_asm_cpp:
case langkind_c_cpp:
@@ -1687,7 +1635,7 @@ public:
PrintSourceRangeInfo,
PrintDiagnosticOption,
!NoDiagnosticsFixIt,
- MessageLength));
+ MessageLength));
}
virtual void setLangOptions(const LangOptions *LO) {
@@ -1979,8 +1927,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
for (unsigned Idx = 0, Last = FixItAtLocations.size();
Idx != Last; ++Idx) {
RequestedSourceLocation Requested;
- if (FixItAtLocations[Idx].ResolveLocation(PP.getFileManager(),
- Requested)) {
+ if (ResolveParsedLocation(FixItAtLocations[Idx],
+ PP.getFileManager(), Requested)) {
fprintf(stderr, "FIX-IT could not find file \"%s\"\n",
FixItAtLocations[Idx].FileName.c_str());
} else {
diff --git a/tools/index-test/CMakeLists.txt b/tools/index-test/CMakeLists.txt
new file mode 100644
index 0000000..09f4fc1
--- /dev/null
+++ b/tools/index-test/CMakeLists.txt
@@ -0,0 +1,17 @@
+set(LLVM_NO_RTTI 1)
+
+set( LLVM_USED_LIBS
+ clangFrontend
+ clangSema
+ clangAST
+ clangLex
+ clangBasic
+ )
+
+set( LLVM_LINK_COMPONENTS
+ bitreader
+ )
+
+add_clang_executable(index-test
+ index-test.cpp
+ )
diff --git a/tools/index-test/Makefile b/tools/index-test/Makefile
new file mode 100644
index 0000000..4fbde29
--- /dev/null
+++ b/tools/index-test/Makefile
@@ -0,0 +1,23 @@
+##===- tools/index-test/Makefile ---------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../../../..
+
+TOOLNAME = index-test
+CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include
+CXXFLAGS = -fno-rtti
+
+# No plugins, optimize startup time.
+TOOL_NO_EXPORTS = 1
+
+include $(LEVEL)/Makefile.config
+
+LINK_COMPONENTS := bitreader
+USEDLIBS = clangFrontend.a clangSema.a clangAST.a clangLex.a clangBasic.a
+
+include $(LLVM_SRC_ROOT)/Makefile.rules
diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp
new file mode 100644
index 0000000..5606e75
--- /dev/null
+++ b/tools/index-test/index-test.cpp
@@ -0,0 +1,150 @@
+//===--- index-test.cpp - Indexing test bed -------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This utility may be invoked in the following manner:
+// index-test --help - Output help info.
+// index-test [options] - Read from stdin.
+// index-test [options] file - Read from "file".
+// index-test [options] file1 file2 - Read these files.
+//
+// Files must be AST files.
+//
+//===----------------------------------------------------------------------===//
+//
+// -point-at [file:column:line]
+// Point at a declaration/statement/expression. If no other operation is
+// specified, prints some info about it.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/Utils.h"
+#include "clang/Frontend/CommandLineSourceLoc.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/System/Signals.h"
+using namespace clang;
+
+
+static llvm::cl::list<ParsedSourceLocation>
+PointAtLocation("point-at", llvm::cl::Optional,
+ llvm::cl::value_desc("source-location"),
+ llvm::cl::desc("Point at the given source location of the first AST file"));
+
+static llvm::cl::opt<bool>
+DisableFree("disable-free",
+ llvm::cl::desc("Disable freeing of memory on exit"),
+ llvm::cl::init(false));
+
+static llvm::cl::list<std::string>
+InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>"));
+
+int main(int argc, char **argv) {
+ llvm::sys::PrintStackTraceOnErrorSignal();
+ llvm::PrettyStackTraceProgram X(argc, argv);
+ llvm::cl::ParseCommandLineOptions(argc, argv,
+ "LLVM 'Clang' Indexing Test Bed: http://clang.llvm.org\n");
+
+ FileManager FileMgr;
+
+ // If no input was specified, read from stdin.
+ if (InputFilenames.empty())
+ InputFilenames.push_back("-");
+
+ // FIXME: Only the first AST file is used for now.
+
+ const std::string &InFile = InputFilenames[0];
+
+ std::string ErrMsg;
+ llvm::OwningPtr<ASTUnit> AST;
+
+ AST.reset(ASTUnit::LoadFromPCHFile(InFile, FileMgr, &ErrMsg));
+ if (!AST) {
+ llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n';
+ return 1;
+ }
+
+ struct ASTPoint {
+ Decl *D;
+ Stmt *Node;
+ ASTPoint() : D(0), Node(0) {}
+ };
+
+ ASTPoint Point;
+
+ if (!PointAtLocation.empty()) {
+ const std::string &Filename = PointAtLocation[0].FileName;
+ const FileEntry *File = FileMgr.getFile(Filename);
+
+ // Safety check. Using an out-of-date AST file will only lead to crashes
+ // or incorrect results.
+ // FIXME: Check all the source files that make up the AST file.
+ const FileEntry *ASTFile = FileMgr.getFile(InFile);
+ if (File->getModificationTime() > ASTFile->getModificationTime()) {
+ llvm::errs() << "[" << InFile << "] Error: " <<
+ "Pointing at a source file which was modified after creating "
+ "the AST file\n";
+ return 1;
+ }
+
+ if (File == 0) {
+ llvm::errs() << "File '" << Filename << "' does not exist\n";
+ return 1;
+ }
+ unsigned Line = PointAtLocation[0].Line;
+ unsigned Col = PointAtLocation[0].Column;
+
+ SourceLocation Loc = AST->getSourceManager().getLocation(File, Line, Col);
+ if (Loc.isInvalid()) {
+ llvm::errs() << "[" << InFile << "] Error: " <<
+ "Couldn't resolve source location (invalid location)\n";
+ return 1;
+ }
+
+ llvm::tie(Point.D, Point.Node) =
+ ResolveLocationInAST(AST->getASTContext(), Loc);
+ if (Point.D == 0) {
+ llvm::errs() << "[" << InFile << "] Error: " <<
+ "Couldn't resolve source location (no declaration found)\n";
+ return 1;
+ }
+ }
+
+ if (Point.D) {
+ llvm::raw_ostream &OS = llvm::outs();
+ assert(Point.D && "If no node was found we should have exited with error");
+ OS << "Declaration node at point: " << Point.D->getDeclKindName() << " ";
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(Point.D))
+ OS << ND->getNameAsString();
+ OS << "\n";
+
+ if (Point.Node) {
+ OS << "Statement node at point: " << Point.Node->getStmtClassName()
+ << " ";
+ Point.Node->printPretty(OS, AST->getASTContext());
+ OS << "\n";
+ }
+ }
+
+ if (DisableFree)
+ AST.take();
+
+ // Managed static deconstruction. Useful for making things like
+ // -time-passes usable.
+ llvm::llvm_shutdown();
+
+ return 0;
+}
OpenPOWER on IntegriCloud