[cfe-commits] r39143 - /cfe/cfe/trunk/include/clang/AST/Type.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:39:48 PDT 2007


Author: sabre
Date: Wed Jul 11 11:39:48 2007
New Revision: 39143

URL: http://llvm.org/viewvc/llvm-project?rev=39143&view=rev
Log:
Structure for the type representation.

Added:
    cfe/cfe/trunk/include/clang/AST/Type.h   (with props)

Added: cfe/cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Type.h?rev=39143&view=auto

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (added)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:39:48 2007
@@ -0,0 +1,123 @@
+//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the Type interface and subclasses.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_PARSE_TYPE_H
+#define LLVM_CLANG_PARSE_TYPE_H
+
+namespace llvm {
+namespace clang {
+  class TypeDecl;
+  class Type;
+  
+/// TypeRef - For efficiency, we don't store CVR-qualified types as nodes on
+/// their own: instead each reference to a type stores the qualifiers.  This
+/// greatly reduces the number of nodes we need to allocate for types (for
+/// example we only need one for 'int', 'const int', 'volatile int',
+/// 'const volatile int', etc).
+///
+/// As an added efficiency bonus, instead of making this a pair, we just store
+/// the three bits we care about in the low bits of the pointer.  To handle the
+/// packing/unpacking, we make TypeRef be a simple wrapper class that acts like
+/// a smart pointer.
+class TypeRef {
+  uintptr_t ThePtr;
+public:
+  enum {
+    Const    = 0x1,
+    Volatile = 0x2,
+    Restrict = 0x4,
+    CVRFlags = Const|Volatile|Restrict
+  };
+  
+  TypeRef(Type *Ptr, unsigned Quals) {
+    assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
+    ThePtr = static_cast<uintptr_t>(Ptr);
+    assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
+    ThePtr |= Quals;
+  }
+  
+  Type &operator*() const {
+    return *static_cast<Type*>(ThePtr & ~CVRFlags);
+  }
+
+  Type *operator->() const {
+    return static_cast<Type*>(ThePtr & ~CVRFlags);
+  }
+
+  bool isConstQualified() const {
+    return ThePtr & Const;
+  }
+  bool isVolatileQualified() const {
+    return ThePtr & Volatile;
+  }
+  bool isRestrictQualified() const {
+    return ThePtr & Restrict;
+  }
+  unsigned getQualifiers() const {
+    return ThePtr & CVRFlags;
+  }
+};
+
+
+/// Type - This is the base class of the type hierarchy.  A central concept
+/// with types is that each type always has a canonical type.  A canonical type
+/// is the type with any typedef names stripped out of it or the types it
+/// references.  For example, consider:
+///
+///  typedef int  foo;
+///  typedef foo* bar;
+///    'int *'    'foo *'    'bar'
+///
+/// There will be a Type object created for 'int'.  Since int is canonical, its
+/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
+/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
+/// there is a PointerType that represents 'int*', which, like 'int', is
+/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
+/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
+/// is also 'int*'.
+///
+/// Non-canonical types are useful for emitting diagnostics, without losing
+/// information about typedefs being used.  Canonical types are useful for type
+/// comparisons (they allow by-pointer equality tests) and useful for reasoning
+/// about whether something has a particular form (e.g. is a function type),
+/// because they implicitly, recursively, strip all typedefs out of a type.
+///
+/// Types, once created, are immutable.
+///
+class Type {
+  Type *CanonicalType;
+public:
+  bool isCanonical() const { return CanonicalType == this; }
+  Type *getCanonicalType() const { return CanonicalType; }
+};
+
+class PointerType : public CType {
+  TypeRef PointeeType;
+public:
+  
+};
+
+class TypedefType : public CType {
+  // Decl * here.
+public:
+  
+};
+
+
+/// ...
+    
+  
+}  // end namespace clang
+}  // end namespace llvm
+
+#endif

Propchange: cfe/cfe/trunk/include/clang/AST/Type.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/include/clang/AST/Type.h

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision





More information about the cfe-commits mailing list