<commit_before>//===--- SourceLoc.cpp - SourceLoc and SourceRange implementations --------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/Basic/SourceLoc.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"
using namespace swift;

void SourceLoc::print(raw_ostream &OS, const llvm::SourceMgr &SM,
                      int &LastBuffer) const {
  if (isInvalid()) {
    OS << "<invalid loc>";
    return;
  }
  int BufferIndex = SM.FindBufferContainingLoc(Value);
  if (BufferIndex == -1) {
    OS << "<malformed loc>";
    return;
  }
  
  const llvm::MemoryBuffer *Buffer = SM.getMemoryBuffer((unsigned)BufferIndex);
  const char *BufferStart = Buffer->getBufferStart();
  
  
  if (BufferIndex != LastBuffer) {
    OS << Buffer->getBufferIdentifier();
    LastBuffer = BufferIndex;
  }
  
  OS << ':' << (Value.getPointer() - BufferStart);
}

void SourceLoc::dump(const llvm::SourceMgr &SM) const {
  print(llvm::errs(), SM);
}

void SourceRange::print(raw_ostream &OS, const llvm::SourceMgr &SM,
                        int &LastBuffer) const {
  OS << '[';
  Start.print(OS, SM, LastBuffer);
  OS << " - ";
  End.print(OS, SM, LastBuffer);
  OS << ']';
  
  if (Start.isInvalid() || End.isInvalid())
    return;
  
  OS << " RangeText=\""
     << StringRef(Start.Value.getPointer(),
                  End.Value.getPointer() - Start.Value.getPointer())
     << '"';
}

void SourceRange::dump(const llvm::SourceMgr &SM) const {
  print(llvm::errs(), SM);
}
<commit_msg>further improvements to SLoc printing: actually print line and column #'s now.  This depends on llvm r156243<commit_after>//===--- SourceLoc.cpp - SourceLoc and SourceRange implementations --------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/Basic/SourceLoc.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"
using namespace swift;

void SourceLoc::print(raw_ostream &OS, const llvm::SourceMgr &SM,
                      int &LastBuffer) const {
  if (isInvalid()) {
    OS << "<invalid loc>";
    return;
  }
  int BufferIndex = SM.FindBufferContainingLoc(Value);
  if (BufferIndex == -1) {
    OS << "<malformed loc>";
    return;
  }
  
  if (BufferIndex != LastBuffer) {
    OS << SM.getMemoryBuffer((unsigned)BufferIndex)->getBufferIdentifier();
    LastBuffer = BufferIndex;
  } else {
    OS << "line";
  }

  auto LineAndCol = SM.getLineAndColumn(Value, BufferIndex);

  OS << ':' << LineAndCol.first << ':' << LineAndCol.second;
}

void SourceLoc::dump(const llvm::SourceMgr &SM) const {
  print(llvm::errs(), SM);
}

void SourceRange::print(raw_ostream &OS, const llvm::SourceMgr &SM,
                        int &LastBuffer) const {
  OS << '[';
  Start.print(OS, SM, LastBuffer);
  OS << " - ";
  End.print(OS, SM, LastBuffer);
  OS << ']';
  
  if (Start.isInvalid() || End.isInvalid())
    return;
  
  OS << " RangeText=\""
     << StringRef(Start.Value.getPointer(),
                  End.Value.getPointer() - Start.Value.getPointer()+1)
     << '"';
}

void SourceRange::dump(const llvm::SourceMgr &SM) const {
  print(llvm::errs(), SM);
}

{'fraction_non_alphanumeric': 0.1926651595076614, 'fraction_numerical': 0.00728460185882944, 'mean_word_length': 2.7672658467360454, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1271574', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1213, 'n_words': 307}