Back to index

texmacs  1.0.7.15
Functions
tree.cpp File Reference
#include "generic_tree.hpp"
#include "drd_std.hpp"
#include "hashset.hpp"

Go to the source code of this file.

Functions

void destroy_tree_rep (tree_rep *rep)
bool operator== (tree t, tree u)
bool operator!= (tree t, tree u)
tree copy (tree t)
tree freeze (tree t)
tree operator* (tree t1, tree t2)
treeoperator<< (tree &t, tree t2)
treeoperator<< (tree &t, array< tree > a)
tm_ostreamoperator<< (tm_ostream &out, tree t)
void print_tree (tree t, int tab)
int hash (array< tree > a)
int hash (tree t)
string tree_as_string (tree t)
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)
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_label l)
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)
static void simplify_concat (tree &r, tree t)
tree simplify_concat (tree t)
tree simplify_correct (tree t)

Function Documentation

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 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:

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 freeze ( tree  t)

Definition at line 143 of file tree.cpp.

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

Here is the call graph for this function:

int hash ( array< tree a)

Definition at line 209 of file tree.cpp.

                     {
  register int i, h=0, n=N(a);
  for (i=0; i<n; i++) {
    h=(h<<7) + (h>>25);
    h=h + hash(a[i]);
  }
  return h;
}

Here is the call 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:

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_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_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_label  l)

Definition at line 418 of file tree.cpp.

                           {
  return l >= START_EXTENSIONS;
}

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_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_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_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 operator!= ( tree  t,
tree  u 
)

Definition at line 126 of file tree.cpp.

                             {
  return (L(t)!=L(u)) ||
    (L(t)==STRING? (t->label!=u->label): (A(t)!=A(u)));
}

Here is the call graph for this function:

tree operator* ( tree  t1,
tree  t2 
)

Definition at line 156 of file tree.cpp.

                              {
  int i;
  if (is_atomic (t1)) t1= tree (L(t2), t1);
  if (is_atomic (t2)) t2= tree (L(t1), t2);
  tree r (t1, N(t1)+N(t2));
  for (i=0; i<N(t1); i++) r[i]= t1[i];
  for (i=0; i<N(t2); i++) r[i+N(t1)]= t2[i];
  return r;
}

Here is the call graph for this function:

tree& operator<< ( tree t,
tree  t2 
)

Definition at line 167 of file tree.cpp.

                               {
  CHECK_COMPOUND (t);
  (static_cast<compound_rep*> (t.rep))->a << t2;
  return t;
}
tree& operator<< ( tree t,
array< tree a 
)

Definition at line 174 of file tree.cpp.

                                     {
  CHECK_COMPOUND (t);
  (static_cast<compound_rep*> (t.rep))->a << a;
  return t;
}
tm_ostream& operator<< ( tm_ostream out,
tree  t 
)

Definition at line 181 of file tree.cpp.

                                      {
  if (is_atomic (t)) return out << t->label;
  else if (is_compound (t)) {
    int i, n= N(t);
    out << as_string (L(t));
    if (n==0) return out << "()";
    out << " (";
    for (i=0; i< n-1; i++)
      out << t[i] << ", ";
    out << t[i] << ")";
    return out;
  }
  else out << as_blackbox (t);
  return out;
}

Here is the call graph for this function:

bool operator== ( tree  t,
tree  u 
)

Definition at line 120 of file tree.cpp.

                             {
  return (L(t)==L(u)) &&
    (L(t)==STRING? (t->label==u->label): (A(t)==A(u)));
}

Here is the call graph for this function:

void print_tree ( tree  t,
int  tab = 0 
)

Definition at line 198 of file tree.cpp.

                             {
  int i;
  for (i=0; i<tab; i++) cout << " ";
  if (is_atomic (t)) cout << t->label << "\n";
  else {
    cout << as_string (L(t)) << "\n";
    for (i=0; i<N(t); i++) print_tree (t[i], tab+2);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void simplify_concat ( tree r,
tree  t 
) [static]

Definition at line 447 of file tree.cpp.

                                  {
  int i, n= N(t);
  for (i=0; i<n; i++)
    if (is_concat (t[i])) simplify_concat (r, t[i]);
    else if (t[i] == "");
    else if (is_atomic (t[i]) && (N(r)>0) && is_atomic (r[N(r)-1]))
      r[N(r)-1]= tree (r[N(r)-1]->label * t[i]->label);
    else r << t[i];
}

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:

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: