LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB/Native - NativeTypePointer.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 70 89 78.7 %
Date: 2018-10-20 13:21:21 Functions: 18 20 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- NativeTypePointer.cpp - info about pointer type ----------*- 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             : 
      10             : #include "llvm/DebugInfo/PDB/Native/NativeTypePointer.h"
      11             : 
      12             : #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
      13             : 
      14             : #include <cassert>
      15             : 
      16             : using namespace llvm;
      17             : using namespace llvm::codeview;
      18             : using namespace llvm::pdb;
      19             : 
      20           5 : NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
      21           5 :                                      codeview::TypeIndex TI)
      22           5 :     : NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI) {
      23             :   assert(TI.isSimple());
      24             :   assert(TI.getSimpleMode() != SimpleTypeMode::Direct);
      25           5 : }
      26             : 
      27          73 : NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
      28             :                                      codeview::TypeIndex TI,
      29          73 :                                      codeview::PointerRecord Record)
      30             :     : NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI),
      31          73 :       Record(std::move(Record)) {}
      32             : 
      33         156 : NativeTypePointer::~NativeTypePointer() {}
      34             : 
      35          29 : void NativeTypePointer::dump(raw_ostream &OS, int Indent,
      36             :                              PdbSymbolIdField ShowIdFields,
      37             :                              PdbSymbolIdField RecurseIdFields) const {
      38          29 :   NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
      39             : 
      40          29 :   if (isMemberPointer()) {
      41           3 :     dumpSymbolIdField(OS, "classParentId", getClassParentId(), Indent, Session,
      42             :                       PdbSymbolIdField::ClassParent, ShowIdFields,
      43             :                       RecurseIdFields);
      44             :   }
      45          58 :   dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
      46             :                     PdbSymbolIdField::LexicalParent, ShowIdFields,
      47             :                     RecurseIdFields);
      48          29 :   dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
      49             :                     PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
      50          29 :   dumpSymbolField(OS, "length", getLength(), Indent);
      51          29 :   dumpSymbolField(OS, "constType", isConstType(), Indent);
      52          29 :   dumpSymbolField(OS, "isPointerToDataMember", isPointerToDataMember(), Indent);
      53          29 :   dumpSymbolField(OS, "isPointerToMemberFunction", isPointerToMemberFunction(),
      54             :                   Indent);
      55          29 :   dumpSymbolField(OS, "RValueReference", isRValueReference(), Indent);
      56          29 :   dumpSymbolField(OS, "reference", isReference(), Indent);
      57          29 :   dumpSymbolField(OS, "restrictedType", isRestrictedType(), Indent);
      58          29 :   if (isMemberPointer()) {
      59           3 :     if (isSingleInheritance())
      60           3 :       dumpSymbolField(OS, "isSingleInheritance", 1, Indent);
      61           0 :     else if (isMultipleInheritance())
      62           0 :       dumpSymbolField(OS, "isMultipleInheritance", 1, Indent);
      63           0 :     else if (isVirtualInheritance())
      64           0 :       dumpSymbolField(OS, "isVirtualInheritance", 1, Indent);
      65             :   }
      66          29 :   dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
      67          29 :   dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
      68          29 : }
      69             : 
      70          30 : SymIndexId NativeTypePointer::getClassParentId() const {
      71          30 :   if (!isMemberPointer())
      72             :     return 0;
      73             : 
      74             :   assert(Record);
      75           4 :   const MemberPointerInfo &MPI = Record->getMemberInfo();
      76           8 :   return Session.getSymbolCache().findSymbolByTypeIndex(MPI.ContainingType);
      77             : }
      78             : 
      79          29 : uint64_t NativeTypePointer::getLength() const {
      80          29 :   if (Record)
      81          58 :     return Record->getSize();
      82             : 
      83           0 :   switch (TI.getSimpleMode()) {
      84             :   case SimpleTypeMode::NearPointer:
      85             :   case SimpleTypeMode::FarPointer:
      86             :   case SimpleTypeMode::HugePointer:
      87             :     return 2;
      88           0 :   case SimpleTypeMode::NearPointer32:
      89             :   case SimpleTypeMode::FarPointer32:
      90           0 :     return 4;
      91           0 :   case SimpleTypeMode::NearPointer64:
      92           0 :     return 8;
      93           0 :   case SimpleTypeMode::NearPointer128:
      94           0 :     return 16;
      95           0 :   default:
      96             :     assert(false && "invalid simple type mode!");
      97             :   }
      98           0 :   return 0;
      99             : }
     100             : 
     101          91 : SymIndexId NativeTypePointer::getTypeId() const {
     102             :   // This is the pointee SymIndexId.
     103          91 :   TypeIndex Referent = Record ? Record->ReferentType : TI.makeDirect();
     104             : 
     105         182 :   return Session.getSymbolCache().findSymbolByTypeIndex(Referent);
     106             : }
     107             : 
     108          91 : bool NativeTypePointer::isReference() const {
     109          91 :   if (!Record)
     110             :     return false;
     111         168 :   return Record->getMode() == PointerMode::LValueReference;
     112             : }
     113             : 
     114          54 : bool NativeTypePointer::isRValueReference() const {
     115          54 :   if (!Record)
     116             :     return false;
     117         106 :   return Record->getMode() == PointerMode::RValueReference;
     118             : }
     119             : 
     120         120 : bool NativeTypePointer::isPointerToDataMember() const {
     121         120 :   if (!Record)
     122             :     return false;
     123         238 :   return Record->getMode() == PointerMode::PointerToDataMember;
     124             : }
     125             : 
     126         115 : bool NativeTypePointer::isPointerToMemberFunction() const {
     127         115 :   if (!Record)
     128             :     return false;
     129         228 :   return Record->getMode() == PointerMode::PointerToMemberFunction;
     130             : }
     131             : 
     132          61 : bool NativeTypePointer::isConstType() const {
     133          61 :   if (!Record)
     134             :     return false;
     135         110 :   return (Record->getOptions() & PointerOptions::Const) != PointerOptions::None;
     136             : }
     137             : 
     138          61 : bool NativeTypePointer::isRestrictedType() const {
     139          61 :   if (!Record)
     140             :     return false;
     141          55 :   return (Record->getOptions() & PointerOptions::Restrict) !=
     142          55 :          PointerOptions::None;
     143             : }
     144             : 
     145          61 : bool NativeTypePointer::isVolatileType() const {
     146          61 :   if (!Record)
     147             :     return false;
     148          55 :   return (Record->getOptions() & PointerOptions::Volatile) !=
     149          55 :          PointerOptions::None;
     150             : }
     151             : 
     152          29 : bool NativeTypePointer::isUnalignedType() const {
     153          29 :   if (!Record)
     154             :     return false;
     155          29 :   return (Record->getOptions() & PointerOptions::Unaligned) !=
     156          29 :          PointerOptions::None;
     157             : }
     158             : 
     159             : static inline bool isInheritanceKind(const MemberPointerInfo &MPI,
     160             :                                      PointerToMemberRepresentation P1,
     161             :                                      PointerToMemberRepresentation P2) {
     162           2 :   return (MPI.getRepresentation() == P1 || MPI.getRepresentation() == P2);
     163             : }
     164             : 
     165           3 : bool NativeTypePointer::isSingleInheritance() const {
     166           3 :   if (!isMemberPointer())
     167             :     return false;
     168             :   return isInheritanceKind(
     169           3 :       Record->getMemberInfo(),
     170             :       PointerToMemberRepresentation::SingleInheritanceData,
     171             :       PointerToMemberRepresentation::SingleInheritanceFunction);
     172             : }
     173             : 
     174           0 : bool NativeTypePointer::isMultipleInheritance() const {
     175           0 :   if (!isMemberPointer())
     176             :     return false;
     177             :   return isInheritanceKind(
     178           0 :       Record->getMemberInfo(),
     179             :       PointerToMemberRepresentation::MultipleInheritanceData,
     180             :       PointerToMemberRepresentation::MultipleInheritanceFunction);
     181             : }
     182             : 
     183           0 : bool NativeTypePointer::isVirtualInheritance() const {
     184           0 :   if (!isMemberPointer())
     185             :     return false;
     186             :   return isInheritanceKind(
     187           0 :       Record->getMemberInfo(),
     188             :       PointerToMemberRepresentation::VirtualInheritanceData,
     189             :       PointerToMemberRepresentation::VirtualInheritanceFunction);
     190             : }
     191             : 
     192          91 : bool NativeTypePointer::isMemberPointer() const {
     193          91 :   return isPointerToDataMember() || isPointerToMemberFunction();
     194             : }

Generated by: LCOV version 1.13