CommandLineSourceLoc.h (199482) | CommandLineSourceLoc.h (199990) |
---|---|
1 2//===--- CommandLineSourceLoc.h - Parsing for source locations-*- C++ -*---===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is distributed under the University of Illinois Open Source 7// License. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10// 11// Command line parsing for source locations. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H 16#define LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H 17 18#include "llvm/Support/CommandLine.h" | 1 2//===--- CommandLineSourceLoc.h - Parsing for source locations-*- C++ -*---===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is distributed under the University of Illinois Open Source 7// License. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10// 11// Command line parsing for source locations. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H 16#define LLVM_CLANG_FRONTEND_COMMANDLINESOURCELOC_H 17 18#include "llvm/Support/CommandLine.h" |
19#include <cstdio> | 19#include "llvm/Support/raw_ostream.h" |
20 21namespace clang { 22 23/// \brief A source location that has been parsed on the command line. 24struct ParsedSourceLocation { 25 std::string FileName; 26 unsigned Line; 27 unsigned Column; | 20 21namespace clang { 22 23/// \brief A source location that has been parsed on the command line. 24struct ParsedSourceLocation { 25 std::string FileName; 26 unsigned Line; 27 unsigned Column; |
28 29public: 30 /// Construct a parsed source location from a string; the Filename is empty on 31 /// error. 32 static ParsedSourceLocation FromString(llvm::StringRef Str) { 33 ParsedSourceLocation PSL; 34 std::pair<llvm::StringRef, llvm::StringRef> ColSplit = Str.rsplit(':'); 35 std::pair<llvm::StringRef, llvm::StringRef> LineSplit = 36 ColSplit.first.rsplit(':'); 37 38 // If both tail splits were valid integers, return success. 39 if (!ColSplit.second.getAsInteger(10, PSL.Column) && 40 !LineSplit.second.getAsInteger(10, PSL.Line)) 41 PSL.FileName = LineSplit.first; 42 43 return PSL; 44 } |
|
28}; 29 30} 31 32namespace llvm { 33 namespace cl { 34 /// \brief Command-line option parser that parses source locations. 35 /// --- 7 unchanged lines hidden (view full) --- 43 }; 44 45 bool 46 parser<clang::ParsedSourceLocation>:: 47 parse(Option &O, StringRef ArgName, StringRef ArgValue, 48 clang::ParsedSourceLocation &Val) { 49 using namespace clang; 50 | 45}; 46 47} 48 49namespace llvm { 50 namespace cl { 51 /// \brief Command-line option parser that parses source locations. 52 /// --- 7 unchanged lines hidden (view full) --- 60 }; 61 62 bool 63 parser<clang::ParsedSourceLocation>:: 64 parse(Option &O, StringRef ArgName, StringRef ArgValue, 65 clang::ParsedSourceLocation &Val) { 66 using namespace clang; 67 |
51 const char *ExpectedFormat 52 = "source location must be of the form filename:line:column"; 53 StringRef::size_type SecondColon = ArgValue.rfind(':'); 54 if (SecondColon == std::string::npos) { 55 std::fprintf(stderr, "%s\n", ExpectedFormat); | 68 Val = ParsedSourceLocation::FromString(ArgValue); 69 if (Val.FileName.empty()) { 70 errs() << "error: " 71 << "source location must be of the form filename:line:column\n"; |
56 return true; 57 } 58 | 72 return true; 73 } 74 |
59 unsigned Column; 60 if (ArgValue.substr(SecondColon + 1).getAsInteger(10, Column)) { 61 std::fprintf(stderr, "%s\n", ExpectedFormat); 62 return true; 63 } 64 ArgValue = ArgValue.substr(0, SecondColon); 65 66 StringRef::size_type FirstColon = ArgValue.rfind(':'); 67 if (FirstColon == std::string::npos) { 68 std::fprintf(stderr, "%s\n", ExpectedFormat); 69 return true; 70 } 71 unsigned Line; 72 if (ArgValue.substr(FirstColon + 1).getAsInteger(10, Line)) { 73 std::fprintf(stderr, "%s\n", ExpectedFormat); 74 return true; 75 } 76 77 Val.FileName = ArgValue.substr(0, FirstColon); 78 Val.Line = Line; 79 Val.Column = Column; | |
80 return false; 81 } 82 } 83} 84 85#endif | 75 return false; 76 } 77 } 78} 79 80#endif |