Back to index

texmacs  1.0.7.15
tag_info.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : tag_info.hpp
00004 * DESCRIPTION: DRD information about tags
00005 * COPYRIGHT  : (C) 2003  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef TAG_INFO_H
00013 #define TAG_INFO_H
00014 #include "tree.hpp"
00015 
00016 #define TYPE_INVALID         -1
00017 #define TYPE_REGULAR          0
00018 #define TYPE_ADHOC            1
00019 #define TYPE_RAW              2
00020 #define TYPE_VARIABLE         3
00021 #define TYPE_ARGUMENT         4
00022 #define TYPE_BINDING          5
00023 #define TYPE_BOOLEAN          6
00024 #define TYPE_INTEGER          7
00025 #define TYPE_STRING           8
00026 #define TYPE_LENGTH           9
00027 #define TYPE_NUMERIC         10
00028 #define TYPE_CODE            11
00029 #define TYPE_IDENTIFIER      12
00030 #define TYPE_URL             13
00031 #define TYPE_GRAPHICAL       14
00032 #define TYPE_POINT           15
00033 #define TYPE_CONSTRAINT      16
00034 #define TYPE_GRAPHICAL_ID    17
00035 #define TYPE_ANIMATION       18
00036 #define TYPE_DURATION        19
00037 #define TYPE_OBSOLETE        20
00038 #define TYPE_UNKNOWN         21
00039 #define TYPE_ERROR           22
00040 
00041 int    drd_encode (tree t);
00042 tree   drd_decode (int i);
00043 int    drd_encode_type (string s);
00044 string drd_decode_type (int i);
00045 
00046 /******************************************************************************
00047 * The parent_info class contains outer information about tags
00048 *
00049 * - The type field specifies the type of the return value of the tag.
00050 *   For instance, regular content has the type TYPE_REGULAR and
00051 *   the tag PLUS which performs a numerical operation admits
00052 *   the type TYPE_NUMERIC.
00053 *
00054 * - The arity fields together with the child_mode determine the possible
00055 *   arities and how to convert logical indices of children to
00056 *   physical indices in the array 'ci'.
00057 *
00058 *    o ARITY_NORMAL    : the arity is given by arity_base+arity_extra
00059 *    o ARITY_OPTIONS   : arity_base <= arity < arity_base+arity_extra
00060 *    o ARITY_REPEAT    : arity= arity_base + any_number * arity_extra
00061 *    o ARITY_VAR_REPEAT: as ARITY_REPEAT, but repetition "comes first"
00062 *
00063 *    o CHILD_UNIFORM : all children have the same properties
00064 *    o CHILD_BIFORM  : two types of properties (corresponds to base/extra)
00065 *    o CHILD_DETAILED: as many as arity_base+arity_extra types of properties
00066 *
00067 * - The border_mode field specifies whether the cursor may be put behind and
00068 *   before the tag or not (the 0 and 1 paths). For instance, this field
00069 *   is BORDER_INNER for CONCAT and BORDER_YES for FRAC.
00070 *
00071 * - The block field specifies when the parent should be considered
00072 *   as a block. In the case of BLOCK_OR, the parent is a block
00073 *   if one of the children satisfying BLOCK_REQUIRE_NONE is a block.
00074 *
00075 * - The freeze_* fields specify that the contents of the corresponding
00076 *   fields may not be overwritten during the heuristic determination of
00077 *   missing drd information.
00078 ******************************************************************************/
00079 
00080 #define ARITY_NORMAL          0
00081 #define ARITY_OPTIONS         1
00082 #define ARITY_REPEAT          2
00083 #define ARITY_VAR_REPEAT      3
00084 
00085 #define CHILD_UNIFORM         0
00086 #define CHILD_BIFORM          1
00087 #define CHILD_DETAILED        2
00088 
00089 #define BLOCK_NO              0
00090 #define BLOCK_YES             1
00091 #define BLOCK_OR              2
00092 
00093 #define BORDER_YES            0
00094 #define BORDER_INNER          1
00095 #define BORDER_OUTER          2
00096 #define BORDER_NO             3
00097 
00098 struct parent_info {
00099   unsigned type             : 5; // the type
00100   unsigned arity_mode       : 2; // arity layout
00101   unsigned arity_base       : 6; // base arity (minimal arity)
00102   unsigned arity_extra      : 4; // extra arity (optional, repeated, etc.)
00103   unsigned child_mode       : 2; // child layout
00104   unsigned border_mode      : 2; // is the border inaccessible?
00105   unsigned block            : 2; // is a block structure?
00106   unsigned with_like        : 1; // is only an environment modifier?
00107   unsigned freeze_type      : 1; // true => disable heuristic determination
00108   unsigned freeze_arity     : 1;
00109   unsigned freeze_border    : 1;
00110   unsigned freeze_block     : 1;
00111   unsigned freeze_with      : 1;
00112 
00113   parent_info (int arity, int extra, int amode, int cmode, bool frozen= false);
00114   parent_info (tree t);
00115   inline ~parent_info () {}
00116   operator tree ();
00117   bool operator == (const parent_info& pi);
00118   bool operator != (const parent_info& pi);
00119   friend tm_ostream& operator << (tm_ostream& out, parent_info pi);
00120 };
00121 
00122 /******************************************************************************
00123 * The child_info class contains more detailed information about each of
00124 * the children of the tag.
00125 *
00126 * - The type field specifies the type of the field.
00127 *   Fields with regular content admit TYPE_REGULAR as their type.
00128 *
00129 * - The accessible field specifies whether the field can be accessed.
00130 *   ACCESSIBLE_ALWAYS children can always be accessed, ACCESSIBLE_NEVER
00131 *   children can only be accessed in source mode and ACCESSIBLE_HIDDEN
00132 *   children may require unfolding in order to be accessed.
00133 *
00134 * - The writability field specifies whether an accessible field can be edited.
00135 *   When the writability of a child is disabled, its whole descendance
00136 *   becomes read-only, except for those parts whose writability are re-enabled.
00137 *
00138 * - The block field specifies whether the field is required to be
00139 *   a block structure, an inline structure, or any of the two.
00140 *
00141 * - The mode field specifies the mode for each child. In case of MODE_PARENT,
00142 *   the mode of the child is the same as the mode of its parent.
00143 *
00144 * - The freeze_* fields specify that the contents of the corresponding
00145 *   fields may not be overwritten during the heuristic determination of
00146 *   missing drd information.
00147 ******************************************************************************/
00148 
00149 #define ACCESSIBLE_NEVER      0
00150 #define ACCESSIBLE_HIDDEN     1
00151 #define ACCESSIBLE_ALWAYS     2
00152 
00153 #define WRITABILITY_NORMAL    0
00154 #define WRITABILITY_DISABLE   1
00155 #define WRITABILITY_ENABLE    2
00156 
00157 #define BLOCK_REQUIRE_BLOCK   0
00158 #define BLOCK_REQUIRE_INLINE  1
00159 #define BLOCK_REQUIRE_NONE    2
00160 
00161 struct child_info {
00162   unsigned type              :  5; // argument type
00163   unsigned accessible        :  2; // child is accessible?
00164   unsigned writability       :  2; // writability of child
00165   unsigned block             :  2; // require children to be blocks?
00166   unsigned env               : 16; // environment of the child?
00167   unsigned freeze_type       :  1; // true => disable heuristic determination
00168   unsigned freeze_accessible :  1;
00169   unsigned freeze_writability:  1;
00170   unsigned freeze_block      :  1;
00171   unsigned freeze_env        :  1;
00172 
00173   child_info (bool frozen= false);
00174   child_info (tree t);
00175   inline ~child_info () {}
00176   operator tree ();
00177   bool operator == (const child_info& pi);
00178   bool operator != (const child_info& pi);
00179   friend tm_ostream& operator << (tm_ostream& out, child_info ci);
00180 };
00181 
00182 class tag_info;
00183 class tag_info_rep: concrete_struct {
00184 public:
00185   parent_info       pi;
00186   array<child_info> ci;
00187   tree              extra;
00188 
00189   tag_info_rep (parent_info pi, array<child_info> ci, tree extra);
00190   tag_info_rep (int arity, int extra, int amode, int cmode, bool frozen);
00191   inline ~tag_info_rep () {}
00192 
00193   tag_info inner_border ();
00194   tag_info outer_border ();
00195   tag_info with_like ();
00196   tag_info type (int tp);
00197   tag_info type (int i, int tp);
00198   tag_info accessible (int i);
00199   tag_info hidden (int i);
00200   tag_info disable_writable (int i);
00201   tag_info enable_writable (int i);
00202   tag_info locals (int i, string var, string val);
00203   tag_info name (string s);
00204   tag_info long_name (string s);
00205   tag_info name (int i, string s);
00206   tag_info long_name (int i, string s);
00207   int      get_index (int child, int n);
00208   void     set_attribute (string which, tree val);
00209   tree     get_attribute (string which);
00210 
00211   friend class tag_info;
00212 };
00213 
00214 /******************************************************************************
00215 * The main tag_info class consists of parent_info and an array of child_info
00216 ******************************************************************************/
00217 
00218 class tag_info {
00219   CONCRETE(tag_info);
00220   tag_info (parent_info pi, array<child_info> ci, tree extra);
00221   tag_info (int arity=0, int extra=0,
00222            int am=ARITY_NORMAL, int cm= CHILD_UNIFORM,
00223            bool frozen= false);
00224   tag_info (tree t);
00225   operator tree ();
00226   child_info& operator () (int child, int n);
00227 };
00228 CONCRETE_CODE(tag_info);
00229 
00230 bool operator == (tag_info ti1, tag_info ti2);
00231 bool operator != (tag_info ti1, tag_info ti2);
00232 tm_ostream& operator << (tm_ostream& out, tag_info ti);
00233 tag_info copy (tag_info ti);
00234 
00235 #endif // defined TAG_INFO_H