1 //===--- CommandLineSourceLoc.h - Parsing for source locations-*- C++ -*---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Command line parsing for source locations.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H
15 #define LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H
17 #include "llvm/Support/CommandLine.h"
21 /// \brief A source location that has been parsed on the command line.
22 struct ParsedSourceLocation
{
32 /// \brief Command-line option parser that parses source locations.
34 /// Source locations are of the form filename:line:column.
36 class parser
<clang::ParsedSourceLocation
>
37 : public basic_parser
<clang::ParsedSourceLocation
> {
39 bool parse(Option
&O
, const char *ArgName
,
40 const std::string
&ArgValue
,
41 clang::ParsedSourceLocation
&Val
);
45 parser
<clang::ParsedSourceLocation
>::
46 parse(Option
&O
, const char *ArgName
, const std::string
&ArgValue
,
47 clang::ParsedSourceLocation
&Val
) {
48 using namespace clang
;
50 const char *ExpectedFormat
51 = "source location must be of the form filename:line:column";
52 std::string::size_type SecondColon
= ArgValue
.rfind(':');
53 if (SecondColon
== std::string::npos
) {
54 std::fprintf(stderr
, "%s\n", ExpectedFormat
);
59 = std::strtol(ArgValue
.c_str() + SecondColon
+ 1, &EndPtr
, 10);
60 if (EndPtr
!= ArgValue
.c_str() + ArgValue
.size()) {
61 std::fprintf(stderr
, "%s\n", ExpectedFormat
);
65 std::string::size_type FirstColon
= ArgValue
.rfind(':', SecondColon
-1);
66 if (FirstColon
== std::string::npos
) {
67 std::fprintf(stderr
, "%s\n", ExpectedFormat
);
70 long Line
= std::strtol(ArgValue
.c_str() + FirstColon
+ 1, &EndPtr
, 10);
71 if (EndPtr
!= ArgValue
.c_str() + SecondColon
) {
72 std::fprintf(stderr
, "%s\n", ExpectedFormat
);
76 Val
.FileName
= ArgValue
.substr(0, FirstColon
);