LLVM  3.7.0
DIASourceFile.cpp
Go to the documentation of this file.
1 //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
14 
15 using namespace llvm;
16 
18  CComPtr<IDiaSourceFile> DiaSourceFile)
19  : Session(PDBSession), SourceFile(DiaSourceFile) {}
20 
21 std::string DIASourceFile::getFileName() const {
22  CComBSTR FileName16;
23  HRESULT Result = SourceFile->get_fileName(&FileName16);
24  if (S_OK != Result)
25  return std::string();
26 
27  std::string FileName8;
28  llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str),
29  FileName16.ByteLength());
30  llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8);
31  return FileName8;
32 }
33 
34 uint32_t DIASourceFile::getUniqueId() const {
35  DWORD Id;
36  return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
37 }
38 
39 std::string DIASourceFile::getChecksum() const {
40  DWORD ByteSize = 0;
41  HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
42  if (ByteSize == 0)
43  return std::string();
44  std::vector<BYTE> ChecksumBytes(ByteSize);
45  Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
46  if (S_OK != Result)
47  return std::string();
48  return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
49 }
50 
52  DWORD Type;
53  HRESULT Result = SourceFile->get_checksumType(&Type);
54  if (S_OK != Result)
55  return PDB_Checksum::None;
56  return static_cast<PDB_Checksum>(Type);
57 }
58 
59 std::unique_ptr<IPDBEnumSymbols> DIASourceFile::getCompilands() const {
60  CComPtr<IDiaEnumSymbols> DiaEnumerator;
61  HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
62  if (S_OK != Result)
63  return nullptr;
64 
65  return std::unique_ptr<IPDBEnumSymbols>(
66  new DIAEnumSymbols(Session, DiaEnumerator));
67 }
std::string getFileName() const override
std::unique_ptr< IPDBEnumSymbols > getCompilands() const override
PDB_Checksum getChecksumType() const override
DIASourceFile(const DIASession &Session, CComPtr< IDiaSourceFile > DiaSourceFile)
uint32_t getUniqueId() const override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
PDB_Checksum
Specifies the hash algorithm that a source file from a PDB was hashed with.
Definition: PDBTypes.h:106
std::string getChecksum() const override
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)