save filename
[libfirm] / ir / tr / type.h
index 9e558fd..33fe124 100644 (file)
@@ -1,20 +1,25 @@
-/*
- * (C) 2001 by Universitaet Karlsruhe
- */
-
 /**
  *
- *  @file type.h
+ * @file type.h
  *
- *  Datastructure to hold type information.
+ * Project:     libFIRM                                                   <br>
+ * File name:   ir/tr/type.h                                              <br>
+ * Purpose:     Representation of types.                                  <br>
+ * Author:      Goetz Lindenmaier                                         <br>
+ * Modified by:                                                           <br>
+ * Created:                                                               <br>
+ * Copyright:   (c) 2001-2003 Universität Karlsruhe                       <br>
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE. <br>
+ * CVS-ID:      $Id$
  *
- *  @author Goetz Lindenmaier
+ *
+ *  Datastructure to hold type information.
  *
  *  This module supplies a datastructure to represent all types
  *  known in the compiled program.  This includes types specified
  *  in the program as well as types defined by the language.  In the
  *  view of the intermediate representation there is no difference
- *  between these types.
+ *  between these types.  Finally it specifies some auxiliary types.
  *
  *  There exist several kinds of types, arranged by the structure of
  *  the type.  A type is described by a set of attributes.  Some of
  *  on the level of the programming language, modes at the level of
  *  the target processor.
  *
- * @see  tpop.h
+ *  @see  tpop.h
  */
 
-/* $Id$ */
-
 # ifndef _TYPE_H_
 # define _TYPE_H_
 
+# include <stdbool.h>
+
 # include "tpop.h"
 # include "firm_common.h"
 # include "ident.h"
 # include "irmode.h"
-# include <stdbool.h>
 # include "dbginfo.h"
 
 
@@ -116,7 +120,8 @@ typedef struct type type;
 # include "type_or_entity.h"
 
 /** Frees the memory used by the type.   Does not free the entities
-   belonging to the type, except for the array element entity.  */
+   belonging to the type, except for the array element entity.
+   Does not free if tp is "none" or "unknown". */
 void        free_type(type *tp);
 
 tp_op*      get_type_tpop(type *tp);
@@ -138,7 +143,7 @@ typedef enum {
   layout_fixed         /**< The layout is fixed, all component/member entities
                          have an offset assigned.  Size of the type is known.
                          Arrays can be accessed by explicit address
-                         computation. Default for pointer, primitive ane method
+                         computation. Default for pointer, primitive and method
                          types.  */
 } type_state;
 
@@ -160,7 +165,7 @@ ir_mode*    get_type_mode(type *tp);
 
 /** Sets the mode of a type.
  *
- * Only has an effect on primitive and enumeration types.
+ * Only has an effect on primitive, enumeration and pointer types.
  */
 void        set_type_mode(type *tp, ir_mode* m);
 
@@ -396,16 +401,18 @@ void    remove_class_supertype(type *clss, type *supertype);
 
 /** This enumeration flags the peculiarity of entities and types. */
 typedef enum peculiarity {
-  description,     /**< Represents only a description.  The entity/type is never
-                     allocated, no code/data exists for this entity/type. */
-  inherited,       /**< Describes explicitly that other entities are
-                     inherited to the owner of this entity.
-                     Overwrites must refer to at least one other
-                     entity.  If this is a method entity there exists
-                     no irg for this entity, only for one of the
-                     overwritten ones. */
-  existent         /**< The entity/type (can) exist. */
+  peculiarity_description,     /**< Represents only a description.  The entity/type is never
+                                   allocated, no code/data exists for this entity/type. */
+  peculiarity_inherited,       /**< Describes explicitly that other entities are
+                                   inherited to the owner of this entity.
+                                   Overwrites must refer to at least one other
+                                   entity.  If this is a method entity there exists
+                                   no irg for this entity, only for one of the
+                                   overwritten ones.
+                                   Only for entity. */
+  peculiarity_existent         /**< The entity/type (can) exist. */
 } peculiarity;
+char *get_peculiarity_string(peculiarity p);
 
 /* The peculiarity of the class.  The enumeration peculiarity is defined
    in entity.h */
@@ -541,6 +548,9 @@ void  set_method_res_type(type *method, int pos, type* tp);
 /* Returns an entity that represents the copied value result.  Only necessary
    for compounds passed by value. This information is constructed only on demand. */
 entity *get_method_value_res_ent(type *method, int pos);
+/*
+ */
+type *get_method_value_res_type(type *method);
 
 /**
  * this enum flags the variadicity of methods (methods with a
@@ -548,10 +558,13 @@ entity *get_method_value_res_ent(type *method, int pos);
  * non_variadic.
  */
 typedef enum variadicity {
-  non_variadic,                /**< non variadic */
-  variadic             /**< variadic */
+  variadicity_non_variadic,    /**< non variadic */
+  variadicity_variadic         /**< variadic */
 } variadicity;
 
+/** Returns the null-terminated name of this variadicity. */
+const char *get_variadicity_name(variadicity vari);
+
 /** Returns the variadicity of a method. */
 variadicity get_method_variadicity(type *method);
 
@@ -718,7 +731,7 @@ bool    is_enumeration_type     (type *enumeration);
 
 /** Creates a new type pointer with mode mode_p. */
 #define new_type_pointer(N, P) new_type_pointer_mode(N, P, mode_P)
-//type *new_type_pointer           (ident *name, type *points_to);
+/* type *new_type_pointer           (ident *name, type *points_to); */
 
 /** Creates a new type pointer with given pointer mode. */
 type *new_type_pointer_mode      (ident *name, type *points_to, ir_mode *ptr_mode);
@@ -737,6 +750,11 @@ type *get_pointer_points_to_type (type *pointer);
 /** Returns true if a type is a pointer type. */
 bool  is_pointer_type            (type *pointer);
 
+/** Returns the first pointer type that has as points_to tp.
+ *  Not efficient: O(#types).
+ *  If not found returns unknown_type. */
+type *find_pointer_type_to_type (type *tp);
+
 /**
  * @page primitive_type Representation of a primitive type
  *
@@ -754,6 +772,51 @@ type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db);
 bool  is_primitive_type  (type *primitive);
 
 
+/**
+ * @page none_type
+ *
+ *  This type is an auxiliary type dedicated to support type analyses.
+ *
+ *  The none type represents that there is no type.  The type can be used to
+ *  initialize fields of type* that actually can not contain a type or that
+ *  are initialized for an analysis. There exists exactly one type none.
+ *  This type is not on the type list in ir_prog. It is
+ *  allocated when initializing the type module.
+ *
+ *  The following values are set:
+ *    mode:  mode_BAD
+ *    name:  "type_none"
+ *    state: layout_fixed
+ *    size:  0
+ */
+/* A variable that contains the only none type. */
+extern type *none_type;
+/* Returns the none type */
+type *get_none_type(void);
+
+/**
+ * @page unknown_type
+ *
+ *  This type is an auxiliary type dedicated to support type analyses.
+ *
+ *  The unknown type represents that there could be a type, but it is not
+ *  known.  This type can be used to initialize fields before an analysis (not known
+ *  yet) or to represent the top of a lattice (could not be determined).  There exists
+ *  exactly one type unknown. This type is not on the type list in ir_prog.  It is
+ *  allocated when initializing the type module.
+ *
+ *  The following values are set:
+ *    mode:  mode_ANY
+ *    name:  "type_unknown"
+ *    state: layout_fixed
+ *    size:  0
+ */
+/* A variable that contains the only unknown type. */
+extern type *unknown_type;
+/* Returns the none type */
+type *get_unknown_type(void);
+
+
 /**
  *  Checks whether a type is atomic.
  *  @param tp - any type
@@ -798,8 +861,11 @@ entity *get_compound_member(type *tp, int pos);
 int is_compound_type(type *tp);
 
 
-/** Outputs a unique number for this type if libfirm is compiled for
-   debugging, (configure with --enable-debug) else returns 0. */
+/**
+ *  Outputs a unique number for this type if libfirm is compiled for
+ *  debugging, (configure with --enable-debug) else returns the address
+ *  of the type cast to long.
+ */
 INLINE long get_type_nr(type *tp);
 
 # endif /* _TYPE_H_ */