clang: include/clang/Frontend/CommandLineSourceLoc.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H

15#define LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H

16

18#include "llvm/Support/CommandLine.h"

19#include "llvm/Support/raw_ostream.h"

20#include

21

23

24

29

30public:

31

32

35 std::pair<StringRef, StringRef> ColSplit = Str.rsplit(':');

36 std::pair<StringRef, StringRef> LineSplit =

37 ColSplit.first.rsplit(':');

38

39

40 if (!ColSplit.second.getAsInteger(10, PSL.Column) &&

41 !LineSplit.second.getAsInteger(10, PSL.Line)) {

42 PSL.FileName = std::string(LineSplit.first);

43

44

45

48 }

49

50 return PSL;

51 }

52

53

55 return (llvm::Twine(FileName == "" ? "-" : FileName) + ":" +

57 .str();

58 }

59};

60

61

64

65

66 std::pair<unsigned, unsigned> Begin;

67

68

69 std::pair<unsigned, unsigned> End;

70

71

72

73

74

75

76

77

78

79

80 static std::optional fromString(StringRef Str) {

81 std::pair<StringRef, StringRef> RangeSplit = Str.rsplit('-');

82 unsigned EndLine, EndColumn;

83 bool HasEndLoc = false;

84 if (!RangeSplit.second.empty()) {

85 std::pair<StringRef, StringRef> Split = RangeSplit.second.rsplit(':');

86 if (Split.first.getAsInteger(10, EndLine) ||

87 Split.second.getAsInteger(10, EndColumn)) {

88

89

90

91 RangeSplit.first = Str;

92 } else

93 HasEndLoc = true;

94 }

96 if (Begin.FileName.empty())

97 return std::nullopt;

98 if (!HasEndLoc) {

99 EndLine = Begin.Line;

100 EndColumn = Begin.Column;

101 }

104 {EndLine, EndColumn}};

105 }

106};

107}

108

109namespace llvm {

110 namespace cl {

111

112

113

114 template<>

115 class parser<clang::ParsedSourceLocation> final

116 : public basic_parserclang::ParsedSourceLocation {

117 public:

118 inline bool parse(Option &O, StringRef ArgName, StringRef ArgValue,

120 };

121

122 bool

123 parserclang::ParsedSourceLocation::

124 parse(Option &O, StringRef ArgName, StringRef ArgValue,

126 using namespace clang;

127

128 Val = ParsedSourceLocation::FromString(ArgValue);

130 errs() << "error: "

131 << "source location must be of the form filename:line:column\n";

132 return true;

133 }

134

135 return false;

136 }

137 }

138}

139

140#endif

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

The JSON file list parser is used to communicate input to InstallAPI.

Diagnostic wrappers for TextAPI types for error reporting.

A source location that has been parsed on the command line.

static ParsedSourceLocation FromString(StringRef Str)

Construct a parsed source location from a string; the Filename is empty on error.

std::string ToString() const

Serialize ParsedSourceLocation back to a string.

A source range that has been parsed on the command line.

std::pair< unsigned, unsigned > End

The ending location of the range.

static std::optional< ParsedSourceRange > fromString(StringRef Str)

Returns a parsed source range from a string or std::nullopt if the string is invalid.

std::pair< unsigned, unsigned > Begin

The starting location of the range.