zcov: / include/clang/Frontend/CommandLineSourceLoc.h


Files: 1 Branches Taken: 50.0% 3 / 6
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 6 / 6
Line Coverage: 100.0% 7 / 7


Programs: 7 Runs 11951


       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 "llvm/Support/raw_ostream.h"
      20                 : 
      21                 : namespace clang {
      22                 : 
      23                 : /// \brief A source location that has been parsed on the command line.
      24             5325: struct ParsedSourceLocation {
      25                 :   std::string FileName;
      26                 :   unsigned Line;
      27                 :   unsigned Column;
      28                 : 
      29                 : public:
      30                 :   /// Construct a parsed source location from a string; the Filename is empty on
      31                 :   /// error.
      32               87:   static ParsedSourceLocation FromString(llvm::StringRef Str) {
      33               87:     ParsedSourceLocation PSL;
      34               87:     std::pair<llvm::StringRef, llvm::StringRef> ColSplit = Str.rsplit(':');
      35                 :     std::pair<llvm::StringRef, llvm::StringRef> LineSplit =
      36               87:       ColSplit.first.rsplit(':');
      37                 : 
      38                 :     // If both tail splits were valid integers, return success.
                       87: branch 1 taken
                        0: branch 2 not taken
                       87: branch 4 taken
                        0: branch 5 not taken
                       87: branch 6 taken
                        0: branch 7 not taken
      39               87:     if (!ColSplit.second.getAsInteger(10, PSL.Column) &&
      40                 :         !LineSplit.second.getAsInteger(10, PSL.Line))
      41               87:       PSL.FileName = LineSplit.first;
      42                 : 
      43                 :     return PSL;
      44                 :   }
      45                 : };
      46                 : 
      47                 : }
      48                 : 
      49                 : namespace llvm {
      50                 :   namespace cl {
      51                 :     /// \brief Command-line option parser that parses source locations.
      52                 :     ///
      53                 :     /// Source locations are of the form filename:line:column.
      54                 :     template<>
      55                 :     class parser<clang::ParsedSourceLocation>
      56                 :       : public basic_parser<clang::ParsedSourceLocation> {
      57                 :     public:
      58                 :       inline bool parse(Option &O, StringRef ArgName, StringRef ArgValue,
      59                 :                  clang::ParsedSourceLocation &Val);
      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                 : 
      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";
      72                 :         return true;
      73                 :       }
      74                 : 
      75                 :       return false;
      76                 :     }
      77                 :   }
      78                 : }
      79                 : 
      80                 : #endif

Generated: 2010-02-10 01:31 by zcov