~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/VMCore/TypeSymbolTable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- TypeSymbolTable.cpp - Implement the TypeSymbolTable class ---------===//
 
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
// This file implements the TypeSymbolTable class for the VMCore library.
 
11
//
 
12
//===----------------------------------------------------------------------===//
 
13
 
 
14
#include "llvm/TypeSymbolTable.h"
 
15
#include "llvm/DerivedTypes.h"
 
16
#include "llvm/ADT/StringExtras.h"
 
17
#include "llvm/ADT/StringRef.h"
 
18
#include "llvm/Support/Debug.h"
 
19
#include "llvm/Support/ManagedStatic.h"
 
20
#include "llvm/Support/raw_ostream.h"
 
21
#include <algorithm>
 
22
using namespace llvm;
 
23
 
 
24
#define DEBUG_SYMBOL_TABLE 0
 
25
#define DEBUG_ABSTYPE 0
 
26
 
 
27
TypeSymbolTable::~TypeSymbolTable() {
 
28
  // Drop all abstract type references in the type plane...
 
29
  for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
 
30
    if (TI->second->isAbstract())   // If abstract, drop the reference...
 
31
      cast<DerivedType>(TI->second)->removeAbstractTypeUser(this);
 
32
  }
 
33
}
 
34
 
 
35
std::string TypeSymbolTable::getUniqueName(StringRef BaseName) const {
 
36
  std::string TryName = BaseName;
 
37
  
 
38
  const_iterator End = tmap.end();
 
39
 
 
40
  // See if the name exists
 
41
  while (tmap.find(TryName) != End)            // Loop until we find a free
 
42
    TryName = BaseName.str() + utostr(++LastUnique); // name in the symbol table
 
43
  return TryName;
 
44
}
 
45
 
 
46
// lookup a type by name - returns null on failure
 
47
Type* TypeSymbolTable::lookup(StringRef Name) const {
 
48
  const_iterator TI = tmap.find(Name);
 
49
  Type* result = 0;
 
50
  if (TI != tmap.end())
 
51
    result = const_cast<Type*>(TI->second);
 
52
  return result;
 
53
}
 
54
 
 
55
// remove - Remove a type from the symbol table...
 
56
Type* TypeSymbolTable::remove(iterator Entry) {
 
57
  assert(Entry != tmap.end() && "Invalid entry to remove!");
 
58
  const Type* Result = Entry->second;
 
59
 
 
60
#if DEBUG_SYMBOL_TABLE
 
61
  dump();
 
62
  dbgs() << " Removing Value: " << Result->getDescription() << "\n";
 
63
#endif
 
64
 
 
65
  tmap.erase(Entry);
 
66
  
 
67
  // If we are removing an abstract type, remove the symbol table from it's use
 
68
  // list...
 
69
  if (Result->isAbstract()) {
 
70
#if DEBUG_ABSTYPE
 
71
    dbgs() << "Removing abstract type from symtab"
 
72
           << Result->getDescription()
 
73
           << "\n";
 
74
#endif
 
75
    cast<DerivedType>(Result)->removeAbstractTypeUser(this);
 
76
  }
 
77
 
 
78
  return const_cast<Type*>(Result);
 
79
}
 
80
 
 
81
 
 
82
// insert - Insert a type into the symbol table with the specified name...
 
83
void TypeSymbolTable::insert(StringRef Name, const Type* T) {
 
84
  assert(T && "Can't insert null type into symbol table!");
 
85
 
 
86
  if (tmap.insert(std::make_pair(Name, T)).second) {
 
87
    // Type inserted fine with no conflict.
 
88
    
 
89
#if DEBUG_SYMBOL_TABLE
 
90
    dump();
 
91
    dbgs() << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
 
92
#endif
 
93
  } else {
 
94
    // If there is a name conflict...
 
95
    
 
96
    // Check to see if there is a naming conflict.  If so, rename this type!
 
97
    std::string UniqueName = Name;
 
98
    if (lookup(Name))
 
99
      UniqueName = getUniqueName(Name);
 
100
    
 
101
#if DEBUG_SYMBOL_TABLE
 
102
    dump();
 
103
    dbgs() << " Inserting type: " << UniqueName << ": "
 
104
           << T->getDescription() << "\n";
 
105
#endif
 
106
 
 
107
    // Insert the tmap entry
 
108
    tmap.insert(make_pair(UniqueName, T));
 
109
  }
 
110
  
 
111
  // If we are adding an abstract type, add the symbol table to it's use list.
 
112
  if (T->isAbstract()) {
 
113
    cast<DerivedType>(T)->addAbstractTypeUser(this);
 
114
#if DEBUG_ABSTYPE
 
115
    dbgs() << "Added abstract type to ST: " << T->getDescription() << "\n";
 
116
#endif
 
117
  }
 
118
}
 
119
 
 
120
// This function is called when one of the types in the type plane are refined
 
121
void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
 
122
                                         const Type *NewType) {
 
123
  // Loop over all of the types in the symbol table, replacing any references
 
124
  // to OldType with references to NewType.  Note that there may be multiple
 
125
  // occurrences, and although we only need to remove one at a time, it's
 
126
  // faster to remove them all in one pass.
 
127
  //
 
128
  for (iterator I = begin(), E = end(); I != E; ++I) {
 
129
    if (I->second == (Type*)OldType) {  // FIXME when Types aren't const.
 
130
#if DEBUG_ABSTYPE
 
131
      dbgs() << "Removing type " << OldType->getDescription() << "\n";
 
132
#endif
 
133
      OldType->removeAbstractTypeUser(this);
 
134
 
 
135
      I->second = (Type*)NewType;  // TODO FIXME when types aren't const
 
136
      if (NewType->isAbstract()) {
 
137
#if DEBUG_ABSTYPE
 
138
        dbgs() << "Added type " << NewType->getDescription() << "\n";
 
139
#endif
 
140
        cast<DerivedType>(NewType)->addAbstractTypeUser(this);
 
141
      }
 
142
    }
 
143
  }
 
144
}
 
145
 
 
146
 
 
147
// Handle situation where type becomes Concreate from Abstract
 
148
void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
 
149
  // Loop over all of the types in the symbol table, dropping any abstract
 
150
  // type user entries for AbsTy which occur because there are names for the
 
151
  // type.
 
152
  for (iterator TI = begin(), TE = end(); TI != TE; ++TI)
 
153
    if (TI->second == const_cast<Type*>(static_cast<const Type*>(AbsTy)))
 
154
      AbsTy->removeAbstractTypeUser(this);
 
155
}
 
156
 
 
157
static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
 
158
  dbgs() << "  '" << T.first << "' = ";
 
159
  T.second->dump();
 
160
  dbgs() << "\n";
 
161
}
 
162
 
 
163
void TypeSymbolTable::dump() const {
 
164
  dbgs() << "TypeSymbolPlane: ";
 
165
  for_each(tmap.begin(), tmap.end(), DumpTypes);
 
166
}
 
167