Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions
tree.hpp File Reference
#include "tree_label.hpp"
#include "observer.hpp"
#include "array.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  tree
class  tree_rep
class  atomic_rep
class  compound_rep
struct  type_helper< tree >

Defines

#define CHECK_ATOMIC(t)
#define CHECK_COMPOUND(t)

Typedefs

typedef tree scheme_tree

Functions

tree copy (tree t)
void destroy_tree_rep (tree_rep *rep)
int N (tree t)
int arity (tree t)
int right_index (tree t)
tree_label L (tree t)
tree_labelLR (tree t)
array< treeA (tree t)
array< tree > & AR (tree t)
bool is_atomic (tree t)
bool is_compound (tree t)
bool is_generic (tree t)
string get_label (tree t)
bool operator== (tree t, tree_label lab)
bool operator!= (tree t, tree_label lab)
bool operator== (tree t, string s)
bool operator!= (tree t, string s)
bool operator== (tree t, const char *s)
bool operator!= (tree t, const char *s)
tree_repinside (tree t)
bool strong_equal (tree t, tree u)
bool is_func (tree t, tree_label l)
bool is_func (tree t, tree_label l, int i)
bool is_bool (tree t)
bool is_int (tree t)
bool is_double (tree t)
bool is_string (tree t)
bool as_bool (tree t)
int as_int (tree t)
double as_double (tree t)
string as_string (tree t)
string tree_as_string (tree t)
template<class T >
tree as_tree (T x)
template<>
tree as_tree (int x)
template<>
tree as_tree (double x)
template<>
tree as_tree (pointer x)
tree bool_as_tree (bool f)
bool is_document (tree t)
bool is_concat (tree t)
bool is_format (tree t)
bool is_formatting (tree t)
bool is_table (tree t)
bool is_table_format (tree t)
bool is_multi_paragraph (tree t)
bool is_around (tree t)
bool is_script (tree t)
bool is_script (tree t, bool &right)
bool is_prime (tree t)
bool is_right_script_prime (tree t)
bool is_mod_active (tree t)
bool is_mod_active_once (tree t)
bool is_graphical_text (tree t)
bool is_empty (tree t)
bool is_applicable (tree t)
tree simplify_concat (tree t)
tree simplify_correct (tree t)
tree compound (string s)
tree compound (string s, tree t1)
tree compound (string s, tree t1, tree t2)
tree compound (string s, tree t1, tree t2, tree t3)
tree compound (string s, tree t1, tree t2, tree t3, tree t4)
tree compound (string s, array< tree > a)
bool is_extension (tree t)
bool is_extension (tree t, int n)
bool is_compound (tree t, string s)
bool is_compound (tree t, string s, int n)
tree tuple ()
tree tuple (tree t1)
tree tuple (tree t1, tree t2)
tree tuple (tree t1, tree t2, tree t3)
tree tuple (tree t1, tree t2, tree t3, tree t4)
bool is_tuple (tree t)
bool is_tuple (tree t, string s)
bool is_tuple (tree t, const char *s)
bool is_tuple (tree t, string s, int n)
bool is_tuple (tree t, const char *s, int n)
tree concat ()
tree concat (tree t1)
tree concat (tree t1, tree t2)
tree concat (tree t1, tree t2, tree t3)
tree concat (tree t1, tree t2, tree t3, tree t4)
tree concat (tree t1, tree t2, tree t3, tree t4, tree t5)
tree document ()
tree document (tree t1)
tree document (tree t1, tree t2)
tree document (tree t1, tree t2, tree t3)
tree document (tree t1, tree t2, tree t3, tree t4)
tree document (tree t1, tree t2, tree t3, tree t4, tree t5)
tree verbatim (tree t1)
tree correct (tree t)
int hash (tree t)

Define Documentation

#define CHECK_ATOMIC (   t)

Definition at line 143 of file tree.hpp.

#define CHECK_COMPOUND (   t)

Definition at line 144 of file tree.hpp.


Typedef Documentation

typedef tree scheme_tree

Definition at line 125 of file tree.hpp.


Function Documentation

array<tree> A ( tree  t) [inline]

Definition at line 190 of file tree.hpp.

                              {
  CHECK_COMPOUND (t);
  return (static_cast<compound_rep*> (t.rep))->a; }
array<tree>& AR ( tree  t) [inline]

Definition at line 193 of file tree.hpp.

                                {
  CHECK_COMPOUND (t);
  return (static_cast<compound_rep*> (t.rep))->a; }

Here is the caller graph for this function:

int arity ( tree  t) [inline]

Definition at line 181 of file tree.hpp.

                          {
  if (t.rep->op == STRING) return 0;
  else return N ((static_cast<compound_rep*> (t.rep))->a); }

Here is the call graph for this function:

bool as_bool ( tree  t) [inline]

Definition at line 228 of file tree.hpp.

                             {
  if (is_atomic (t)) return as_bool (t->label);
  else return false; }

Here is the call graph for this function:

double as_double ( tree  t) [inline]

Definition at line 234 of file tree.hpp.

                                 {
  if (is_atomic (t)) return as_double (t->label);
  else return 0.0; }

Here is the call graph for this function:

int as_int ( tree  t) [inline]

Definition at line 231 of file tree.hpp.

                           {
  if (is_atomic (t)) return as_int (t->label);
  else return 0; }

Here is the call graph for this function:

string as_string ( tree  t) [inline]

Definition at line 237 of file tree.hpp.

                                 {
  if (is_atomic (t)) return t->label;
  else return ""; }

Here is the call graph for this function:

template<class T >
tree as_tree ( T  x) [inline]

Definition at line 241 of file tree.hpp.

{ return (tree) x; }
template<>
tree as_tree ( int  x) [inline]

Definition at line 242 of file tree.hpp.

{ return as_string (x); }

Here is the call graph for this function:

template<>
tree as_tree ( double  x) [inline]

Definition at line 243 of file tree.hpp.

{ return as_string (x); }

Here is the call graph for this function:

template<>
tree as_tree ( pointer  x) [inline]

Definition at line 244 of file tree.hpp.

{ (void) x; return "pointer"; }
tree bool_as_tree ( bool  f) [inline]

Definition at line 245 of file tree.hpp.

                                  {
  return (f? tree ("true"): tree ("false")); }

Here is the caller graph for this function:

Definition at line 388 of file tree.cpp.

                    {
  return tree (make_tree_label (s));
}

Here is the call graph for this function:

tree compound ( string  s,
tree  t1 
)

Definition at line 393 of file tree.cpp.

                             {
  return tree (make_tree_label (s), t1);
}

Here is the call graph for this function:

tree compound ( string  s,
tree  t1,
tree  t2 
)

Definition at line 398 of file tree.cpp.

                                      {
  return tree (make_tree_label (s), t1, t2);
}

Here is the call graph for this function:

tree compound ( string  s,
tree  t1,
tree  t2,
tree  t3 
)

Definition at line 403 of file tree.cpp.

                                               {
  return tree (make_tree_label (s), t1, t2, t3);
}

Here is the call graph for this function:

tree compound ( string  s,
tree  t1,
tree  t2,
tree  t3,
tree  t4 
)

Definition at line 408 of file tree.cpp.

                                                        {
  return tree (make_tree_label (s), t1, t2, t3, t4);
}

Here is the call graph for this function:

tree compound ( string  s,
array< tree a 
)

Definition at line 413 of file tree.cpp.

                                   {
  return tree (make_tree_label (s), a);
}

Here is the call graph for this function:

tree concat ( ) [inline]

Definition at line 323 of file tree.hpp.

                      {
  return tree (CONCAT); }

Here is the caller graph for this function:

tree concat ( tree  t1) [inline]

Definition at line 325 of file tree.hpp.

                             {
  return tree (CONCAT, t1); }
tree concat ( tree  t1,
tree  t2 
) [inline]

Definition at line 327 of file tree.hpp.

                                      {
  return tree (CONCAT, t1, t2); }
tree concat ( tree  t1,
tree  t2,
tree  t3 
) [inline]

Definition at line 329 of file tree.hpp.

                                               {
  return tree (CONCAT, t1, t2, t3); }
tree concat ( tree  t1,
tree  t2,
tree  t3,
tree  t4 
) [inline]

Definition at line 331 of file tree.hpp.

                                                        {
  return tree (CONCAT, t1, t2, t3, t4); }
tree concat ( tree  t1,
tree  t2,
tree  t3,
tree  t4,
tree  t5 
) [inline]

Definition at line 333 of file tree.hpp.

                                                                 {
  return tree (CONCAT, t1, t2, t3, t4, t5); }
tree copy ( tree  t)

Definition at line 132 of file tree.cpp.

              {
  if (is_atomic (t)) return tree (copy (t->label));
  else {
    int i, n= N(t);
    tree t2 (t, n);
    for (i=0; i<n; i++) t2[i]= copy (t[i]);
    return t2;
  }
}

Here is the call graph for this function:

tree correct ( tree  t)
void destroy_tree_rep ( tree_rep rep)

Definition at line 24 of file tree.cpp.

                                 {
  if (((int) rep->op) == 0) tm_delete (static_cast<atomic_rep*> (rep));
  else if (((int) rep->op) > 0) tm_delete (static_cast<compound_rep*>(rep));
  else tm_delete (static_cast<generic_rep*>(rep));
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree document ( ) [inline]

Definition at line 336 of file tree.hpp.

                        {
  return tree (DOCUMENT); }
tree document ( tree  t1) [inline]

Definition at line 338 of file tree.hpp.

                               {
  return tree (DOCUMENT, t1); }
tree document ( tree  t1,
tree  t2 
) [inline]

Definition at line 340 of file tree.hpp.

                                        {
  return tree (DOCUMENT, t1, t2); }
tree document ( tree  t1,
tree  t2,
tree  t3 
) [inline]

Definition at line 342 of file tree.hpp.

                                                 {
  return tree (DOCUMENT, t1, t2, t3); }
tree document ( tree  t1,
tree  t2,
tree  t3,
tree  t4 
) [inline]

Definition at line 344 of file tree.hpp.

                                                          {
  return tree (DOCUMENT, t1, t2, t3, t4); }
tree document ( tree  t1,
tree  t2,
tree  t3,
tree  t4,
tree  t5 
) [inline]

Definition at line 346 of file tree.hpp.

                                                                   {
  return tree (DOCUMENT, t1, t2, t3, t4, t5); }
string get_label ( tree  t) [inline]

Definition at line 200 of file tree.hpp.

                                 {
  return is_atomic (t)? t->label: copy (as_string (L(t))); }

Here is the call graph for this function:

Here is the caller graph for this function:

int hash ( tree  t)

Definition at line 219 of file tree.cpp.

              {
  if (is_atomic (t)) return hash (t->label);
  else return ((int) L(t)) ^ hash (A(t));
}

Here is the call graph for this function:

tree_rep* inside ( tree  t) [inline]

Definition at line 214 of file tree.hpp.

                                 {
  return t.rep; }

Here is the caller graph for this function:

bool is_applicable ( tree  t) [inline]

Definition at line 270 of file tree.hpp.

                       {
  return is_compound (t) && (N(t) >= 1) &&
    ((L(t) == MACRO) || (L(t) == FUNC) || (L(t) == XMACRO));
}

Here is the call graph for this function:

bool is_around ( tree  t)

Definition at line 324 of file tree.cpp.

                   {
  return is_func (t, AROUND, 3) || is_func (t, VAR_AROUND, 3);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_atomic ( tree  t) [inline]

Definition at line 197 of file tree.hpp.

{ return (((int) t.rep->op) == 0); }
bool is_bool ( tree  t) [inline]

Definition at line 224 of file tree.hpp.

{ return is_atomic (t) && is_bool (t->label); }

Here is the call graph for this function:

bool is_compound ( tree  t) [inline]

Definition at line 198 of file tree.hpp.

{ return (((int) t.rep->op) > STRING); }
bool is_compound ( tree  t,
string  s 
)

Definition at line 433 of file tree.cpp.

                               {
  return as_string (L(t)) == s;
}

Here is the call graph for this function:

bool is_compound ( tree  t,
string  s,
int  n 
)

Definition at line 438 of file tree.cpp.

                                      {
  return (as_string (L(t)) == s) && (N(t) == n);
}

Here is the call graph for this function:

bool is_concat ( tree  t)

Definition at line 251 of file tree.cpp.

                   {
  return L(t) == CONCAT;
}
bool is_document ( tree  t)

Definition at line 246 of file tree.cpp.

                     {
  return L(t) == DOCUMENT;
}
bool is_double ( tree  t) [inline]

Definition at line 226 of file tree.hpp.

{ return is_atomic (t) && is_double(t->label); }

Here is the call graph for this function:

bool is_empty ( tree  t)

Definition at line 372 of file tree.cpp.

                  {
  if (is_atomic (t)) return (t == "");
  if (is_document (t) || is_concat (t)) {
    int i, n= N(t);
    for (i=0; i<n; i++)
      if (!is_empty (t[i])) return false;
    return is_concat (t) || (n<=1);
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_extension ( tree  t)

Definition at line 423 of file tree.cpp.

                      {
  return L(t) >= START_EXTENSIONS;
}
bool is_extension ( tree  t,
int  n 
)

Definition at line 428 of file tree.cpp.

                             {
  return (L(t) >= START_EXTENSIONS) && (N(t) == n);
}

Here is the call graph for this function:

bool is_format ( tree  t)

Definition at line 256 of file tree.cpp.

                   {
  return is_document (t) || is_concat (t);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_formatting ( tree  t)

Definition at line 261 of file tree.cpp.

                       {
  return (L(t)>=WITH_LIMITS) && (L(t)<=NEW_DPAGE);
}

Here is the caller graph for this function:

bool is_func ( tree  t,
tree_label  l 
) [inline]

Definition at line 219 of file tree.hpp.

                                           {
  return (t.rep->op==l) && (N(t)!=0); }

Here is the call graph for this function:

bool is_func ( tree  t,
tree_label  l,
int  i 
) [inline]

Definition at line 221 of file tree.hpp.

                                                  {
  return (t.rep->op==l) && (N(t)==i); }

Here is the call graph for this function:

bool is_generic ( tree  t) [inline]

Definition at line 199 of file tree.hpp.

{ return ((int) t.rep->op) < 0; }
bool is_graphical_text ( tree  t)

Definition at line 367 of file tree.cpp.

                           {
  return is_func (t, TEXT_AT) || is_func (t, MATH_AT);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_int ( tree  t) [inline]

Definition at line 225 of file tree.hpp.

{ return is_atomic (t) && is_int (t->label); }

Here is the call graph for this function:

bool is_mod_active ( tree  t)

Definition at line 356 of file tree.cpp.

                       {
  return (N(t) == 1) && (L(t) >= STYLE_ONLY) && (L(t) <= VAR_INACTIVE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_mod_active_once ( tree  t)

Definition at line 361 of file tree.cpp.

                            {
  return (N(t) == 1) &&
    ((L(t) == STYLE_ONLY) || (L(t) == ACTIVE) || (L(t) == INACTIVE));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_multi_paragraph ( tree  t)

Definition at line 278 of file tree.cpp.

                            {
  switch (L(t)) {
  case DOCUMENT:
    return true;
  case SURROUND:
    return is_multi_paragraph (t[2]);
  case DATOMS:
  case DLINES:
  case DPAGES:
  case WITH:
  case MARK:
  case EXPAND_AS:
  case STYLE_WITH:
  case VAR_STYLE_WITH:
  case STYLE_ONLY:
  case VAR_STYLE_ONLY:
  case ACTIVE:
  case VAR_ACTIVE:
    return is_multi_paragraph (t[N(t)-1]);
  case INCLUDE:
    return true;
  case LOCUS:
  case CANVAS:
    return is_multi_paragraph (t[N(t)-1]);
  default:
    {
      static hashset<tree_label> inline_set; // FIXME: use drd
      if (N(inline_set) == 0) {
       inline_set->insert (make_tree_label ("footnote"));
       inline_set->insert (make_tree_label ("script-input"));
       inline_set->insert (make_tree_label ("converter-input"));
      }
      if (L(t) < START_EXTENSIONS) return false;
      else if (inline_set->contains (L(t))) return false;
      else {
       int i, n= N(t);
       for (i=0; i<n; i++)
         if (is_multi_paragraph (t[i]))
           return true;
       return false;
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_prime ( tree  t)

Definition at line 345 of file tree.cpp.

                  {
  return ((L(t) == LPRIME) || (L(t) == RPRIME)) && (N(t) == 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 350 of file tree.cpp.

                               {
  return is_func (t, RSUB, 1) || is_func (t, RSUP, 1) ||
         is_func (t, RPRIME, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_script ( tree  t)

Definition at line 329 of file tree.cpp.

                   {
  return
    is_func (t, LSUB) || is_func (t, LSUP) ||
    is_func (t, RSUB) || is_func (t, RSUP);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_script ( tree  t,
bool &  right 
)

Definition at line 336 of file tree.cpp.

                                {
  if (is_func (t, LSUB) ||
      is_func (t, LSUP)) { right=false; return true; }
  if (is_func (t, RSUB) ||
      is_func (t, RSUP)) { right=true; return true; }
  return false;
}

Here is the call graph for this function:

bool is_string ( tree  t) [inline]

Definition at line 227 of file tree.hpp.

{ return is_atomic (t); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_table ( tree  t)

Definition at line 266 of file tree.cpp.

                  {
  return
    is_func (t, TABLE) || is_func (t, SUBTABLE) ||
    is_func (t, ROW) || is_func (t, CELL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_table_format ( tree  t)

Definition at line 273 of file tree.cpp.

                         {
  return is_func (t, TFORMAT);
}

Here is the call graph for this function:

bool is_tuple ( tree  t) [inline]

Definition at line 308 of file tree.hpp.

                              {
  return (L(t) == TUPLE); }
bool is_tuple ( tree  t,
string  s 
) [inline]

Definition at line 310 of file tree.hpp.

                                        {
  return (L(t) == TUPLE) && (N(t) >= 1) && (t[0] == s); }

Here is the call graph for this function:

bool is_tuple ( tree  t,
const char *  s 
) [inline]

Definition at line 312 of file tree.hpp.

                                             {
  return (L(t) == TUPLE) && (N(t) >= 1) && (t[0] == s); }

Here is the call graph for this function:

bool is_tuple ( tree  t,
string  s,
int  n 
) [inline]

Definition at line 314 of file tree.hpp.

                                               {
  return (L(t) == TUPLE) && (N(t) == (n+1)) && (t[0] == s); }

Here is the call graph for this function:

bool is_tuple ( tree  t,
const char *  s,
int  n 
) [inline]

Definition at line 316 of file tree.hpp.

                                                    {
  return (L(t) == TUPLE) && (N(t) == (n+1)) && (t[0] == s); }

Here is the call graph for this function:

tree_label L ( tree  t) [inline]

Definition at line 186 of file tree.hpp.

                             {
  return t.rep->op; }
tree_label& LR ( tree  t) [inline]

Definition at line 188 of file tree.hpp.

                               {
  return t.rep->op; }

Here is the caller graph for this function:

int N ( tree  t) [inline]

Definition at line 178 of file tree.hpp.

                      {
  CHECK_COMPOUND (t);
  return N ((static_cast<compound_rep*> (t.rep))->a); }

Here is the call graph for this function:

bool operator!= ( tree  t,
tree_label  lab 
) [inline]

Definition at line 204 of file tree.hpp.

                                                 {
  return (t.rep->op != lab) || (N(t)!=0); }

Here is the call graph for this function:

bool operator!= ( tree  t,
string  s 
) [inline]

Definition at line 208 of file tree.hpp.

                                           {
  return (t.rep->op != STRING) || (t->label != s); }
bool operator!= ( tree  t,
const char *  s 
) [inline]

Definition at line 212 of file tree.hpp.

                                                {
  return (t.rep->op != STRING) || (t->label != s); }
bool operator== ( tree  t,
tree_label  lab 
) [inline]

Definition at line 202 of file tree.hpp.

                                                 {
  return (t.rep->op == lab) && (N(t)==0); }

Here is the call graph for this function:

bool operator== ( tree  t,
string  s 
) [inline]

Definition at line 206 of file tree.hpp.

                                           {
  return (t.rep->op == STRING) && (t->label == s); }
bool operator== ( tree  t,
const char *  s 
) [inline]

Definition at line 210 of file tree.hpp.

                                                {
  return (t.rep->op == STRING) && (t->label == s); }
int right_index ( tree  t) [inline]

Definition at line 184 of file tree.hpp.

                                {
  return is_atomic (t)? N(t->label): 1; }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 458 of file tree.cpp.

                         {
  tree r (CONCAT);
  simplify_concat (r, t);
  if (N(r) == 0) return "";
  if (N(r) == 1) return r[0];
  return r;
}

Here is the call graph for this function:

Definition at line 467 of file tree.cpp.

                          {
  if (is_atomic (t)) return t;
  if (is_func (t, QUOTE, 1) && (is_atomic (t[0]))) return t[0];
  int i, n= N(t);
  tree r (t, n);
  for (i=0; i<n; i++)
    r[i]= simplify_correct (t[i]);
  if (is_concat (r)) r= simplify_concat (r);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool strong_equal ( tree  t,
tree  u 
) [inline]

Definition at line 216 of file tree.hpp.

                                          {
  return t.rep == u.rep; }

Definition at line 225 of file tree.cpp.

                        {
  if (is_atomic (t)) return t->label;
  else if (is_concat (t) || is_document (t)) {
    int i, n= N(t);
    string cumul;
    for (i=0; i<n; i++)
      cumul << tree_as_string (t[i]);
    return cumul;
  }
  else if (is_func (t, WITH))
    return tree_as_string (t[N(t)-1]);
  else if (is_compound (t, "nbsp", 0))
    return " ";
  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree tuple ( ) [inline]

Definition at line 297 of file tree.hpp.

                     {
  return tree (TUPLE); }
tree tuple ( tree  t1) [inline]

Definition at line 299 of file tree.hpp.

                            {
  return tree (TUPLE, t1); }
tree tuple ( tree  t1,
tree  t2 
) [inline]

Definition at line 301 of file tree.hpp.

                                     {
  return tree (TUPLE, t1, t2); }
tree tuple ( tree  t1,
tree  t2,
tree  t3 
) [inline]

Definition at line 303 of file tree.hpp.

                                              {
  return tree (TUPLE, t1, t2, t3); }
tree tuple ( tree  t1,
tree  t2,
tree  t3,
tree  t4 
) [inline]

Definition at line 305 of file tree.hpp.

                                                       {
  return tree (TUPLE, t1, t2, t3, t4); }
tree verbatim ( tree  t1) [inline]

Definition at line 349 of file tree.hpp.

                               {
  return compound ("verbatim", t1); }

Here is the call graph for this function:

Here is the caller graph for this function: