1 2 /****************************************************************************** 3 * MODULE : tag_info.hpp 4 * DESCRIPTION: DRD information about tags 5 * COPYRIGHT : (C) 2003 Joris van der Hoeven 6 ******************************************************************************* 7 * This software falls under the GNU general public license version 3 or later. 8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE 9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. 10 ******************************************************************************/ 11 12 #ifndef TAG_INFO_H 13 #define TAG_INFO_H 14 #include "tree.hpp" 15 16 #define TYPE_INVALID -1 17 #define TYPE_REGULAR 0 18 #define TYPE_ADHOC 1 19 #define TYPE_RAW 2 20 #define TYPE_VARIABLE 3 21 #define TYPE_ARGUMENT 4 22 #define TYPE_BINDING 5 23 #define TYPE_BOOLEAN 6 24 #define TYPE_INTEGER 7 25 #define TYPE_STRING 8 26 #define TYPE_LENGTH 9 27 #define TYPE_NUMERIC 10 28 #define TYPE_CODE 11 29 #define TYPE_IDENTIFIER 12 30 #define TYPE_URL 13 31 #define TYPE_COLOR 14 32 #define TYPE_GRAPHICAL 15 33 #define TYPE_POINT 16 34 #define TYPE_CONSTRAINT 17 35 #define TYPE_GRAPHICAL_ID 18 36 #define TYPE_EFFECT 19 37 #define TYPE_ANIMATION 20 38 #define TYPE_DURATION 21 39 #define TYPE_OBSOLETE 22 40 #define TYPE_UNKNOWN 23 41 #define TYPE_ERROR 24 42 43 int drd_encode (tree t); 44 tree drd_decode (int i); 45 int drd_encode_type (string s); 46 string drd_decode_type (int i); 47 48 /****************************************************************************** 49 * The parent_info class contains outer information about tags 50 * 51 * - The type field specifies the type of the return value of the tag. 52 * For instance, regular content has the type TYPE_REGULAR and 53 * the tag PLUS which performs a numerical operation admits 54 * the type TYPE_NUMERIC. 55 * 56 * - The arity fields together with the child_mode determine the possible 57 * arities and how to convert logical indices of children to 58 * physical indices in the array 'ci'. 59 * 60 * o ARITY_NORMAL : the arity is given by arity_base+arity_extra 61 * o ARITY_OPTIONS : arity_base <= arity < arity_base+arity_extra 62 * o ARITY_REPEAT : arity= arity_base + any_number * arity_extra 63 * o ARITY_VAR_REPEAT: as ARITY_REPEAT, but repetition "comes first" 64 * 65 * o CHILD_UNIFORM : all children have the same properties 66 * o CHILD_BIFORM : two types of properties (corresponds to base/extra) 67 * o CHILD_DETAILED: as many as arity_base+arity_extra types of properties 68 * 69 * - The border_mode field specifies whether the cursor may be put behind and 70 * before the tag or not (the 0 and 1 paths). For instance, this field 71 * is BORDER_INNER for CONCAT and BORDER_YES for FRAC. 72 * 73 * - The block field specifies when the parent should be considered 74 * as a block. In the case of BLOCK_OR, the parent is a block 75 * if one of the children satisfying BLOCK_REQUIRE_NONE is a block. 76 * 77 * - The freeze_* fields specify that the contents of the corresponding 78 * fields may not be overwritten during the heuristic determination of 79 * missing drd information. 80 ******************************************************************************/ 81 82 #define ARITY_NORMAL 0 83 #define ARITY_OPTIONS 1 84 #define ARITY_REPEAT 2 85 #define ARITY_VAR_REPEAT 3 86 87 #define CHILD_UNIFORM 0 88 #define CHILD_BIFORM 1 89 #define CHILD_DETAILED 2 90 91 #define BLOCK_NO 0 92 #define BLOCK_YES 1 93 #define BLOCK_OR 2 94 95 #define BORDER_YES 0 96 #define BORDER_INNER 1 97 #define BORDER_OUTER 2 98 #define BORDER_NO 3 99 100 #define VAR_MACRO 0 101 #define VAR_PARAMETER 1 102 #define VAR_MACRO_PARAMETER 2 103 104 struct parent_info { 105 unsigned type : 5; // the type 106 unsigned arity_mode : 2; // arity layout 107 unsigned arity_base : 6; // base arity (minimal arity) 108 unsigned arity_extra : 4; // extra arity (optional, repeated, etc.) 109 unsigned child_mode : 2; // child layout 110 unsigned border_mode : 2; // is the border inaccessible? 111 unsigned block : 2; // is a block structure? 112 unsigned with_like : 1; // is only an environment modifier? 113 unsigned var_type : 2; // macro, parameter or macro parameter 114 unsigned freeze_type : 1; // true => disable heuristic determination 115 unsigned freeze_arity : 1; 116 unsigned freeze_border : 1; 117 unsigned freeze_block : 1; 118 unsigned freeze_with : 1; 119 unsigned freeze_var_type : 1; 120 121 parent_info (int arity, int extra, int amode, int cmode, bool frozen= false); 122 parent_info (tree t); ~parent_infoparent_info123 inline ~parent_info () {} 124 operator tree (); 125 bool operator == (const parent_info& pi); 126 bool operator != (const parent_info& pi); 127 friend tm_ostream& operator << (tm_ostream& out, parent_info pi); 128 }; 129 130 /****************************************************************************** 131 * The child_info class contains more detailed information about each of 132 * the children of the tag. 133 * 134 * - The type field specifies the type of the field. 135 * Fields with regular content admit TYPE_REGULAR as their type. 136 * 137 * - The accessible field specifies whether the field can be accessed. 138 * ACCESSIBLE_ALWAYS children can always be accessed, ACCESSIBLE_NEVER 139 * children can only be accessed in source mode and ACCESSIBLE_HIDDEN 140 * children may require unfolding in order to be accessed. 141 * 142 * - The writability field specifies whether an accessible field can be edited. 143 * When the writability of a child is disabled, its whole descendance 144 * becomes read-only, except for those parts whose writability are re-enabled. 145 * 146 * - The block field specifies whether the field is required to be 147 * a block structure, an inline structure, or any of the two. 148 * 149 * - The mode field specifies the mode for each child. In case of MODE_PARENT, 150 * the mode of the child is the same as the mode of its parent. 151 * 152 * - The freeze_* fields specify that the contents of the corresponding 153 * fields may not be overwritten during the heuristic determination of 154 * missing drd information. 155 ******************************************************************************/ 156 157 #define ACCESSIBLE_NEVER 0 158 #define ACCESSIBLE_HIDDEN 1 159 #define ACCESSIBLE_ALWAYS 2 160 161 #define WRITABILITY_NORMAL 0 162 #define WRITABILITY_DISABLE 1 163 #define WRITABILITY_ENABLE 2 164 165 #define BLOCK_REQUIRE_BLOCK 0 166 #define BLOCK_REQUIRE_INLINE 1 167 #define BLOCK_REQUIRE_NONE 2 168 169 struct child_info { 170 unsigned type : 5; // argument type 171 unsigned accessible : 2; // child is accessible? 172 unsigned writability : 2; // writability of child 173 unsigned block : 2; // require children to be blocks? 174 unsigned env : 16; // environment of the child? 175 unsigned freeze_type : 1; // true => disable heuristic determination 176 unsigned freeze_accessible : 1; 177 unsigned freeze_writability: 1; 178 unsigned freeze_block : 1; 179 unsigned freeze_env : 1; 180 181 child_info (bool frozen= false); 182 child_info (tree t); ~child_infochild_info183 inline ~child_info () {} 184 operator tree (); 185 bool operator == (const child_info& pi); 186 bool operator != (const child_info& pi); 187 friend tm_ostream& operator << (tm_ostream& out, child_info ci); 188 }; 189 190 class tag_info; 191 class tag_info_rep: concrete_struct { 192 public: 193 parent_info pi; 194 array<child_info> ci; 195 tree extra; 196 197 tag_info_rep (parent_info pi, array<child_info> ci, tree extra); 198 tag_info_rep (int arity, int extra, int amode, int cmode, bool frozen); ~tag_info_rep()199 inline ~tag_info_rep () {} 200 201 tag_info inner_border (); 202 tag_info outer_border (); 203 tag_info with_like (); 204 tag_info var_parameter (); 205 tag_info var_macro_parameter (); 206 tag_info type (int tp); 207 tag_info type (int i, int tp); 208 tag_info accessible (int i); 209 tag_info hidden (int i); 210 tag_info disable_writable (int i); 211 tag_info enable_writable (int i); 212 tag_info locals (int i, string var, string val); 213 tag_info name (string s); 214 tag_info long_name (string s); 215 tag_info name (int i, string s); 216 tag_info long_name (int i, string s); 217 int get_index (int child, int n); 218 void set_attribute (string which, tree val); 219 tree get_attribute (string which); 220 221 friend class tag_info; 222 }; 223 224 /****************************************************************************** 225 * The main tag_info class consists of parent_info and an array of child_info 226 ******************************************************************************/ 227 228 class tag_info { 229 CONCRETE(tag_info); 230 tag_info (parent_info pi, array<child_info> ci, tree extra); 231 tag_info (int arity=0, int extra=0, 232 int am=ARITY_NORMAL, int cm= CHILD_UNIFORM, 233 bool frozen= false); 234 tag_info (tree t); 235 operator tree (); 236 child_info& operator () (int child, int n); 237 }; 238 CONCRETE_CODE(tag_info); 239 240 bool operator == (tag_info ti1, tag_info ti2); 241 bool operator != (tag_info ti1, tag_info ti2); 242 tm_ostream& operator << (tm_ostream& out, tag_info ti); 243 tag_info copy (tag_info ti); 244 245 #endif // defined TAG_INFO_H 246