2009-11-18 09:59:57 -05:00
|
|
|
|
2009-06-27 06:45:02 -04:00
|
|
|
//===--- CommandLineSourceLoc.h - Parsing for source locations-*- C++ -*---===//
|
|
|
|
|
//
|
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
|
//
|
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// Command line parsing for source locations.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H
|
|
|
|
|
#define LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H
|
|
|
|
|
|
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-12-01 06:08:04 -05:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-06-27 06:45:02 -04:00
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
|
|
/// \brief A source location that has been parsed on the command line.
|
|
|
|
|
struct ParsedSourceLocation {
|
|
|
|
|
std::string FileName;
|
|
|
|
|
unsigned Line;
|
|
|
|
|
unsigned Column;
|
2009-12-01 06:08:04 -05:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
/// Construct a parsed source location from a string; the Filename is empty on
|
|
|
|
|
/// error.
|
|
|
|
|
static ParsedSourceLocation FromString(llvm::StringRef Str) {
|
|
|
|
|
ParsedSourceLocation PSL;
|
|
|
|
|
std::pair<llvm::StringRef, llvm::StringRef> ColSplit = Str.rsplit(':');
|
|
|
|
|
std::pair<llvm::StringRef, llvm::StringRef> LineSplit =
|
|
|
|
|
ColSplit.first.rsplit(':');
|
|
|
|
|
|
|
|
|
|
// If both tail splits were valid integers, return success.
|
|
|
|
|
if (!ColSplit.second.getAsInteger(10, PSL.Column) &&
|
|
|
|
|
!LineSplit.second.getAsInteger(10, PSL.Line))
|
|
|
|
|
PSL.FileName = LineSplit.first;
|
|
|
|
|
|
|
|
|
|
return PSL;
|
|
|
|
|
}
|
2009-06-27 06:45:02 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
namespace cl {
|
|
|
|
|
/// \brief Command-line option parser that parses source locations.
|
|
|
|
|
///
|
|
|
|
|
/// Source locations are of the form filename:line:column.
|
|
|
|
|
template<>
|
2009-10-14 14:03:49 -04:00
|
|
|
class parser<clang::ParsedSourceLocation>
|
2009-06-27 06:45:02 -04:00
|
|
|
: public basic_parser<clang::ParsedSourceLocation> {
|
|
|
|
|
public:
|
2009-11-18 09:59:57 -05:00
|
|
|
inline bool parse(Option &O, StringRef ArgName, StringRef ArgValue,
|
2009-06-27 06:45:02 -04:00
|
|
|
clang::ParsedSourceLocation &Val);
|
|
|
|
|
};
|
|
|
|
|
|
2009-10-14 14:03:49 -04:00
|
|
|
bool
|
2009-06-27 06:45:02 -04:00
|
|
|
parser<clang::ParsedSourceLocation>::
|
2009-10-14 14:03:49 -04:00
|
|
|
parse(Option &O, StringRef ArgName, StringRef ArgValue,
|
2009-06-27 06:45:02 -04:00
|
|
|
clang::ParsedSourceLocation &Val) {
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
2009-12-01 06:08:04 -05:00
|
|
|
Val = ParsedSourceLocation::FromString(ArgValue);
|
|
|
|
|
if (Val.FileName.empty()) {
|
|
|
|
|
errs() << "error: "
|
|
|
|
|
<< "source location must be of the form filename:line:column\n";
|
2009-06-27 06:45:02 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-14 14:03:49 -04:00
|
|
|
|
2009-06-27 06:45:02 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|