2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/AbstractTypeUser.h - AbstractTypeUser Interface ----*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-07 23:00:03 +00:00
|
|
|
//
|
2006-06-05 16:29:06 +00:00
|
|
|
// This file declares the AbstractTypeUser class.
|
2001-09-07 23:00:03 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ABSTRACT_TYPE_USER_H
|
|
|
|
#define LLVM_ABSTRACT_TYPE_USER_H
|
|
|
|
|
2007-04-22 22:16:55 +00:00
|
|
|
#if !defined(LLVM_TYPE_H) && !defined(LLVM_VALUE_H)
|
|
|
|
#error Do not include this file directly. Include Type.h instead.
|
2007-05-03 16:57:26 +00:00
|
|
|
#error Some versions of GCC (e.g. 3.4 and 4.1) can not handle the inlined method
|
2007-04-22 22:16:55 +00:00
|
|
|
#error PATypeHolder::dropRef() correctly otherwise.
|
|
|
|
#endif
|
2007-04-22 18:49:32 +00:00
|
|
|
|
2003-07-25 17:34:17 +00:00
|
|
|
// This is the "master" include for <cassert> Whether this file needs it or not,
|
|
|
|
// it must always include <cassert> for the files which include
|
|
|
|
// llvm/AbstractTypeUser.h
|
2003-06-30 21:59:07 +00:00
|
|
|
//
|
|
|
|
// In this way, most every LLVM source file will have access to the assert()
|
2003-07-25 17:34:17 +00:00
|
|
|
// macro without having to #include <cassert> directly.
|
2003-06-30 21:59:07 +00:00
|
|
|
//
|
2003-07-25 17:34:17 +00:00
|
|
|
#include <cassert>
|
2003-06-30 21:59:07 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-10-27 16:14:51 +00:00
|
|
|
class Type;
|
2001-09-07 23:00:03 +00:00
|
|
|
class DerivedType;
|
|
|
|
|
2006-06-05 16:29:06 +00:00
|
|
|
/// The AbstractTypeUser class is an interface to be implemented by classes who
|
|
|
|
/// could possibly use an abstract type. Abstract types are denoted by the
|
|
|
|
/// isAbstract flag set to true in the Type class. These are classes that
|
|
|
|
/// contain an Opaque type in their structure somewhere.
|
|
|
|
///
|
|
|
|
/// Classes must implement this interface so that they may be notified when an
|
|
|
|
/// abstract type is resolved. Abstract types may be resolved into more
|
2007-07-05 17:07:56 +00:00
|
|
|
/// concrete types through: linking, parsing, and bitcode reading. When this
|
2006-06-05 16:29:06 +00:00
|
|
|
/// happens, all of the users of the type must be updated to reference the new,
|
|
|
|
/// more concrete type. They are notified through the AbstractTypeUser
|
|
|
|
/// interface.
|
|
|
|
///
|
|
|
|
/// In addition to this, AbstractTypeUsers must keep the use list of the
|
|
|
|
/// potentially abstract type that they reference up-to-date. To do this in a
|
|
|
|
/// nice, transparent way, the PATypeHandle class is used to hold "Potentially
|
|
|
|
/// Abstract Types", and keep the use list of the abstract types up-to-date.
|
|
|
|
/// @brief LLVM Abstract Type User Representation
|
2001-09-07 23:00:03 +00:00
|
|
|
class AbstractTypeUser {
|
|
|
|
protected:
|
2004-02-26 07:24:18 +00:00
|
|
|
virtual ~AbstractTypeUser(); // Derive from me
|
2001-09-07 23:00:03 +00:00
|
|
|
public:
|
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
/// refineAbstractType - The callback method invoked when an abstract type is
|
|
|
|
/// resolved to another type. An object must override this method to update
|
|
|
|
/// its internal state to reference NewType instead of OldType.
|
|
|
|
///
|
2001-09-07 23:00:03 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy,
|
2005-04-22 03:18:56 +00:00
|
|
|
const Type *NewTy) = 0;
|
2003-10-03 18:46:24 +00:00
|
|
|
|
|
|
|
/// The other case which AbstractTypeUsers must be aware of is when a type
|
|
|
|
/// makes the transition from being abstract (where it has clients on it's
|
|
|
|
/// AbstractTypeUsers list) to concrete (where it does not). This method
|
|
|
|
/// notifies ATU's when this occurs for a type.
|
|
|
|
///
|
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy) = 0;
|
|
|
|
|
2002-04-04 19:18:00 +00:00
|
|
|
// for debugging...
|
|
|
|
virtual void dump() const = 0;
|
2001-09-07 23:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-02 23:35:57 +00:00
|
|
|
/// PATypeHandle - Handle to a Type subclass. This class is used to keep the
|
|
|
|
/// use list of abstract types up-to-date.
|
|
|
|
///
|
2001-09-07 23:00:03 +00:00
|
|
|
class PATypeHandle {
|
2003-06-18 19:22:36 +00:00
|
|
|
const Type *Ty;
|
2001-09-07 23:00:03 +00:00
|
|
|
AbstractTypeUser * const User;
|
|
|
|
|
|
|
|
// These functions are defined at the bottom of Type.h. See the comment there
|
|
|
|
// for justification.
|
2003-07-25 17:39:33 +00:00
|
|
|
void addUser();
|
|
|
|
void removeUser();
|
2001-09-07 23:00:03 +00:00
|
|
|
public:
|
|
|
|
// ctor - Add use to type if abstract. Note that Ty must not be null
|
2005-04-21 20:19:05 +00:00
|
|
|
inline PATypeHandle(const Type *ty, AbstractTypeUser *user)
|
2001-09-07 23:00:03 +00:00
|
|
|
: Ty(ty), User(user) {
|
|
|
|
addUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ctor - Add use to type if abstract.
|
|
|
|
inline PATypeHandle(const PATypeHandle &T) : Ty(T.Ty), User(T.User) {
|
|
|
|
addUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
// dtor - Remove reference to type...
|
|
|
|
inline ~PATypeHandle() { removeUser(); }
|
|
|
|
|
|
|
|
// Automatic casting operator so that the handle may be used naturally
|
2004-07-14 20:10:26 +00:00
|
|
|
inline operator Type *() const { return const_cast<Type*>(Ty); }
|
|
|
|
inline Type *get() const { return const_cast<Type*>(Ty); }
|
2001-09-07 23:00:03 +00:00
|
|
|
|
|
|
|
// operator= - Allow assignment to handle
|
2004-07-14 20:10:26 +00:00
|
|
|
inline Type *operator=(const Type *ty) {
|
2001-09-07 23:00:03 +00:00
|
|
|
if (Ty != ty) { // Ensure we don't accidentally drop last ref to Ty
|
|
|
|
removeUser();
|
|
|
|
Ty = ty;
|
|
|
|
addUser();
|
|
|
|
}
|
2004-07-14 20:10:26 +00:00
|
|
|
return get();
|
2001-09-07 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// operator= - Allow assignment to handle
|
2003-06-18 19:22:36 +00:00
|
|
|
inline const Type *operator=(const PATypeHandle &T) {
|
2001-09-07 23:00:03 +00:00
|
|
|
return operator=(T.Ty);
|
|
|
|
}
|
|
|
|
|
2003-06-18 19:22:36 +00:00
|
|
|
inline bool operator==(const Type *ty) {
|
2001-09-07 23:00:03 +00:00
|
|
|
return Ty == ty;
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator-> - Allow user to dereference handle naturally...
|
2003-06-18 19:22:36 +00:00
|
|
|
inline const Type *operator->() const { return Ty; }
|
2001-09-07 23:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-02 23:35:57 +00:00
|
|
|
/// PATypeHolder - Holder class for a potentially abstract type. This uses
|
|
|
|
/// efficient union-find techniques to handle dynamic type resolution. Unless
|
|
|
|
/// you need to do custom processing when types are resolved, you should always
|
|
|
|
/// use PATypeHolders in preference to PATypeHandles.
|
|
|
|
///
|
|
|
|
class PATypeHolder {
|
|
|
|
mutable const Type *Ty;
|
2003-10-02 19:08:18 +00:00
|
|
|
public:
|
2003-10-02 23:35:57 +00:00
|
|
|
PATypeHolder(const Type *ty) : Ty(ty) {
|
|
|
|
addRef();
|
|
|
|
}
|
|
|
|
PATypeHolder(const PATypeHolder &T) : Ty(T.Ty) {
|
|
|
|
addRef();
|
|
|
|
}
|
2003-10-02 19:08:18 +00:00
|
|
|
|
2003-12-23 23:25:21 +00:00
|
|
|
~PATypeHolder() { dropRef(); }
|
|
|
|
|
2004-07-14 20:10:26 +00:00
|
|
|
operator Type *() const { return get(); }
|
|
|
|
Type *get() const;
|
2003-10-02 19:08:18 +00:00
|
|
|
|
|
|
|
// operator-> - Allow user to dereference handle naturally...
|
2004-07-14 20:10:26 +00:00
|
|
|
Type *operator->() const { return get(); }
|
2001-09-07 23:00:03 +00:00
|
|
|
|
|
|
|
// operator= - Allow assignment to handle
|
2004-07-14 20:10:26 +00:00
|
|
|
Type *operator=(const Type *ty) {
|
2003-10-02 23:35:57 +00:00
|
|
|
if (Ty != ty) { // Don't accidentally drop last ref to Ty.
|
|
|
|
dropRef();
|
|
|
|
Ty = ty;
|
|
|
|
addRef();
|
|
|
|
}
|
|
|
|
return get();
|
2001-09-07 23:00:03 +00:00
|
|
|
}
|
2004-07-14 20:10:26 +00:00
|
|
|
Type *operator=(const PATypeHolder &H) {
|
2003-10-02 23:35:57 +00:00
|
|
|
return operator=(H.Ty);
|
2001-09-07 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
2004-08-04 04:45:42 +00:00
|
|
|
/// getRawType - This should only be used to implement the vmcore library.
|
|
|
|
///
|
|
|
|
const Type *getRawType() const { return Ty; }
|
|
|
|
|
2003-10-02 23:35:57 +00:00
|
|
|
private:
|
|
|
|
void addRef();
|
|
|
|
void dropRef();
|
2002-04-04 19:18:00 +00:00
|
|
|
};
|
2001-09-07 23:00:03 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-07 23:00:03 +00:00
|
|
|
#endif
|