Back to index

texmacs  1.0.7.15
Classes | Defines | Functions | Variables
evaluate_inactive.cpp File Reference
#include "evaluate_main.hpp"
#include "memorizer.hpp"
#include "std_environment.hpp"
#include "vars.hpp"

Go to the source code of this file.

Classes

struct  inactive_style_rep
class  inactive_style
class  inactive_memorizer_rep

Defines

#define STYLE_ANGULAR   0
#define STYLE_SCHEME   1
#define STYLE_LATEX   2
#define STYLE_FUNCTIONAL   3
#define SPECIAL_RAW   0
#define SPECIAL_FORMAT   1
#define SPECIAL_NORMAL   2
#define SPECIAL_MAXIMAL   3
#define COMPACT_ALL   0
#define COMPACT_INLINE_ARGS   1
#define COMPACT_INLINE_START   2
#define COMPACT_INLINE   3
#define COMPACT_NONE   4
#define CLOSE_MINIMAL   0
#define CLOSE_COMPACT   1
#define CLOSE_LONG   2
#define CLOSE_REPEAT   3

Functions

bool is_long_arg (tree t, int i)
bool is_long (tree t)
string arg_type (tree t, int i)
tree highlight (tree t, string kind)
tree rewrite_inactive (tree t, inactive_style sty)
tree rewrite_inactive_default (tree t, inactive_style sty)
inactive_style set_bf (inactive_style sty, bool block, bool flush)
inactive_style reset_bf (inactive_style sty)
int hash (inactive_style sty)
inactive_style retrieve (environment env)
memorizer inactive_memorizer (environment env, tree t, inactive_style sty)
tree rewrite_inactive_arg (tree t, int i, inactive_style sty)
tree rewrite_inactive_raw_data (tree t, inactive_style sty)
tree rewrite_inactive_document (tree t, inactive_style sty)
tree rewrite_inactive_concat (tree t, inactive_style sty)
tree rewrite_inactive_value (tree t, inactive_style sty)
tree rewrite_inactive_arg (tree t, inactive_style sty)
tree rewrite_inactive_symbol (tree t, inactive_style sty)
tree rewrite_inactive_style_with (tree t, inactive_style sty, bool once)
tree rewrite_inactive_active (tree t, inactive_style sty)
tree rewrite_inactive_var_active (tree t, inactive_style sty)
tree rewrite_inactive_hybrid (tree t, inactive_style sty)
tree rewrite_inactive_impl (tree t, inactive_style sty)
tree rewrite_inactive (tree t, int inactive_mode)

Variables

static tree psep_var ("par-par-sep")
static tree psep_0fn ("0fn")
static tree mode_var ("mode")
static tree mode_src ("src")
static tree surround1 ("")
static tree surround2 (VSPACE,"0.5fn")
static tree no_tree (UNINIT)
static tree quote1 (WITH,"color","blue","``")
static tree quote2 (WITH,"color","blue","''")

Class Documentation

struct inactive_style_rep

Definition at line 83 of file evaluate_inactive.cpp.

Class Members
unsigned block: 1
unsigned close: 4
unsigned compact: 4
unsigned flush: 1
unsigned mode: 4
unsigned recover: 1
unsigned special: 4
unsigned style: 4

Define Documentation

#define CLOSE_COMPACT   1

Definition at line 75 of file evaluate_inactive.cpp.

#define CLOSE_LONG   2

Definition at line 76 of file evaluate_inactive.cpp.

#define CLOSE_MINIMAL   0

Definition at line 74 of file evaluate_inactive.cpp.

#define CLOSE_REPEAT   3

Definition at line 77 of file evaluate_inactive.cpp.

#define COMPACT_ALL   0

Definition at line 68 of file evaluate_inactive.cpp.

#define COMPACT_INLINE   3

Definition at line 71 of file evaluate_inactive.cpp.

#define COMPACT_INLINE_ARGS   1

Definition at line 69 of file evaluate_inactive.cpp.

#define COMPACT_INLINE_START   2

Definition at line 70 of file evaluate_inactive.cpp.

#define COMPACT_NONE   4

Definition at line 72 of file evaluate_inactive.cpp.

#define SPECIAL_FORMAT   1

Definition at line 64 of file evaluate_inactive.cpp.

#define SPECIAL_MAXIMAL   3

Definition at line 66 of file evaluate_inactive.cpp.

#define SPECIAL_NORMAL   2

Definition at line 65 of file evaluate_inactive.cpp.

#define SPECIAL_RAW   0

Definition at line 63 of file evaluate_inactive.cpp.

#define STYLE_ANGULAR   0

Definition at line 58 of file evaluate_inactive.cpp.

#define STYLE_FUNCTIONAL   3

Definition at line 61 of file evaluate_inactive.cpp.

#define STYLE_LATEX   2

Definition at line 60 of file evaluate_inactive.cpp.

#define STYLE_SCHEME   1

Definition at line 59 of file evaluate_inactive.cpp.


Function Documentation

string arg_type ( tree  t,
int  i 
)

Here is the caller graph for this function:

int hash ( inactive_style  sty) [inline]

Definition at line 120 of file evaluate_inactive.cpp.

                                     {
  return sty.rep; }
tree highlight ( tree  t,
string  kind 
)

Definition at line 37 of file evaluate_inactive.cpp.

                                {
  if (is_compound (t))        return t;
  else if (kind == "")        return t;
  else if (kind == "macro")   return compound ("src-macro", t);
  else if (kind == "var")     return compound ("src-var", t);
  else if (kind == "arg")     return compound ("src-arg", t);
  else if (kind == "tt")      return compound ("src-tt", t);
  else if (kind == "integer") return compound ("src-integer", t);
  else if (kind == "length")  return compound ("src-length", t);
  else if (kind == "error")   return compound ("src-error", t);
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

memorizer inactive_memorizer ( environment  env,
tree  t,
inactive_style  sty 
) [inline]

Definition at line 197 of file evaluate_inactive.cpp.

                                                                 {
  return (memorizer_rep*) tm_new<inactive_memorizer_rep> (env, t, sty);
}

Here is the caller graph for this function:

bool is_long ( tree  t)

Definition at line 98 of file env_inactive.cpp.

                 {
  if (is_compound (t)) {
    int i, n= N(t);
    for (i=0; i<n; i++)
      if (is_long_arg (t, i))
       return true;
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool is_long_arg ( tree  t,
int  i 
)

Definition at line 27 of file env_inactive.cpp.

                            {
  // FIXME: should go into the DRD
  int n= N(t);
  switch (L(t)) {
  case DOCUMENT:
  case INCLUDE:
  case TFORMAT:
  case TABLE:
    return true;
  case CONCAT:
    return false;
  case SURROUND:
    if (i == 2) return true;
    break;
  case ROW:
    return is_long (t[i]);
  case ASSIGN:
  case DATOMS:
  case DLINES:
  case DPAGES:
  case WITH:
  case MARK:
  case MACRO:
  case XMACRO:
  case CELL:
  case EVAL:
  case QUOTE:
  case QUASI:
  case QUASIQUOTE:
  case UNQUOTE:
  case VAR_UNQUOTE:
    if (i == n-1) return is_long (t[i]);
    break;
  case STYLE_WITH:
  case VAR_STYLE_WITH:
    if (i == n-1) {
      for (i=0; i<n-1; i+=2)
       if (t[i] == SRC_COMPACT) {
         if (t[i+1] == "none") return true;
         if (t[i+1] == "all")  return false;
       }
      return is_long (t[i]);
    }
    break;
  case STYLE_ONLY:
  case VAR_STYLE_ONLY:
  case ACTIVE:
  case VAR_ACTIVE:
    return is_multi_paragraph (t[i]);
  case LOCUS:
  case CANVAS:
  case ORNAMENT:
    if (i == n-1) return is_long (t[i]);
    break;
  default:
    break;
  }

  tree u= t[i];
  switch (L(u)) {
  case TWITH:
  case CWITH:
  case ROW:
    return true;
  default:
    if (L(t) < START_EXTENSIONS) return false;
    return is_long (u);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 114 of file evaluate_inactive.cpp.

                                                    {
  inactive_style new_sty= sty;
  new_sty->block= 0;
  new_sty->flush= 0;
  return new_sty; }

Here is the caller graph for this function:

Definition at line 124 of file evaluate_inactive.cpp.

                           {
  string s;
  inactive_style sty;

  s= as_string (env [SRC_STYLE]);
  if (s == "angular") sty->style= STYLE_ANGULAR;
  else if (s == "scheme") sty->style= STYLE_SCHEME;
  else if (s == "latex") sty->style= STYLE_LATEX;
  else if (s == "functional") sty->style= STYLE_FUNCTIONAL;
  else sty->style= STYLE_ANGULAR;
  
  s= as_string (env [SRC_SPECIAL]);
  if (s == "raw") sty->special= SPECIAL_RAW;
  else if (s == "format") sty->special= SPECIAL_FORMAT;
  else if (s == "normal") sty->special= SPECIAL_NORMAL;
  else if (s == "maximal") sty->special= SPECIAL_MAXIMAL;
  else sty->special= SPECIAL_NORMAL;

  s= as_string (env [SRC_COMPACT]);
  if (s == "all") sty->compact= COMPACT_ALL;
  else if (s == "inline args") sty->compact= COMPACT_INLINE_ARGS;
  else if (s == "normal") sty->compact= COMPACT_INLINE_START;
  else if (s == "inline") sty->compact= COMPACT_INLINE;
  else if (s == "none") sty->compact= COMPACT_NONE;
  else sty->compact= COMPACT_INLINE_START;

  s= as_string (env [SRC_CLOSE]);
  if (s == "minimal") sty->close= CLOSE_MINIMAL;
  else if (s == "compact") sty->close= CLOSE_COMPACT;
  else if (s == "long") sty->close= CLOSE_LONG;
  else if (s == "repeat") sty->close= CLOSE_REPEAT;
  else sty->close= CLOSE_COMPACT;

  return sty;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 472 of file evaluate_inactive.cpp.

                                              {
  if (is_atomic (t)) {
    if (sty->style == STYLE_SCHEME)
      return tree (CONCAT, quote1, t, quote2);
    return t;
  }
  cout << "Inactive "
       << "[" << (t.operator -> ())
       << ", " << (std_env.operator -> ()) << "] "
       << t << INDENT << LF;
  memorizer mem= inactive_memorizer (std_env, t, sty);
  if (is_memorized (mem)) {
    cout << UNINDENT << "Memorized " << mem->get_tree () << LF;
    std_env= mem->get_environment ();
    return mem->get_tree ();
  }
  memorize_start ();
  tree r= rewrite_inactive_impl (t, sty);
  mem->set_tree (r);
  mem->set_environment (std_env);
  memorize_end ();
  cout << UNINDENT << "Rewritten as " << mem->get_tree () << LF;
  return mem->get_tree ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree rewrite_inactive ( tree  t,
int  inactive_mode 
)

Definition at line 498 of file evaluate_inactive.cpp.

                                             {
  //recover_env= tuple ();
  inactive_style sty= retrieve (std_env);
  sty->mode= inactive_mode;
  bool flag= (sty->mode >= INACTIVE_BLOCK_RECURSE);
  sty->block= sty->flush= flag;
  tree r= rewrite_inactive (t, sty);
  if (is_multi_paragraph (r)) {
    r= tree (WITH, psep_var, psep_0fn, r);
    r= tree (SURROUND, surround1, surround2, r);
  }
  if ((sty->mode == INACTIVE_INLINE_RECURSE) ||
      (sty->mode == INACTIVE_BLOCK_RECURSE))
    r= tree (WITH, mode_var, mode_src, r);
  return r;
}

Here is the call graph for this function:

Definition at line 320 of file evaluate_inactive.cpp.

                                                     {
  tree st= t[0];
  int i, n= N(st);
  tree r (st, n);
  bool mp= is_multi_paragraph (st);
  for (i=0; i<n; i++) {
    bool smp= mp && is_long_arg (st, i);
    if (is_func (st, WITH) && (i<n-1)) r[i]= st[i];
    else {
      inactive_style ss= set_bf (sty, sty->block && smp, sty->flush && smp);
      r[i]= rewrite_inactive_arg (st, i, ss);
    }
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree rewrite_inactive_arg ( tree  t,
int  i,
inactive_style  sty 
)

Definition at line 206 of file evaluate_inactive.cpp.

                                                         {
  tree r= t[i];
  if ((sty->mode == INACTIVE_INLINE_RECURSE) ||
      (sty->mode == INACTIVE_BLOCK_RECURSE))
    {
      /*
      if (N (recover_env) > 0) {
       int j;
       tree recover= copy (recover_env), old_recover= recover_env;
       for (j=0; j<N(recover); j+=2) {
         string var= recover[j]->label;
         recover[j+1]= read (var);
         write_update (var, recover_env[j+1]);
       }
       recover_env= tuple ();
       r= rewrite_inactive (r, sty);
       recover_env= old_recover;
       for (j=0; j<N(recover); j+=2)
         write_update (recover[j]->label, recover[j+1]);
      }
      else
      */
       r= rewrite_inactive (r, sty);
    }
  return highlight (r, arg_type (t, i));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 280 of file evaluate_inactive.cpp.

                                                  {
  if ((N(t) == 1) && is_atomic (t[0]) &&
      sty->style != STYLE_SCHEME && sty->special >= SPECIAL_NORMAL)
    return highlight (t[0],
                    sty->mode == INACTIVE_INLINE_ERROR ||
                    sty->mode == INACTIVE_BLOCK_ERROR ?
                    string ("error"): string ("arg"));
  return rewrite_inactive_default (t, sty);
}

Here is the call graph for this function:

Definition at line 257 of file evaluate_inactive.cpp.

                                                     {
  if ((sty->special > SPECIAL_RAW) && (sty->compact != COMPACT_NONE)) {
    int i, n= N(t);
    tree r (CONCAT, n);
    for (i=0; i<n; i++)
      r[i]= rewrite_inactive_arg (t, i, reset_bf (sty));
    return r;
  }
  return rewrite_inactive_default (t, sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 360 of file evaluate_inactive.cpp.

                                                      {
  int i, d= 0, n= N(t);
  tree op= as_string (L(t));
  if ((L(t) == COMPOUND) &&
      is_atomic (t[0]) &&
      (sty->special >= SPECIAL_NORMAL))
    {
      d = 1;
      op= highlight (t[0], "var");
    }
  if (sty->mode == INACTIVE_INLINE_ERROR ||
      sty->mode == INACTIVE_BLOCK_ERROR)
    op= highlight (op, "error");

  if ((N(t) == d) ||
      (sty->compact == COMPACT_ALL) ||
      ((!sty->block) && (sty->compact != COMPACT_NONE)) ||
      (!is_long (t)) && (sty->compact != COMPACT_NONE))
    {
      tree r (INLINE_TAG, n+1-d);
      r[0]= op;
      for (i=d; i<n; i++)
       r[i+1-d]= rewrite_inactive_arg (t, i, reset_bf (sty));
      return r;
    }
  else {
    tree doc (DOCUMENT);
    bool compact= (sty->compact < COMPACT_INLINE);
 
    for (i=d; i<n; i++) {
      tree next;
      if ((!compact) || is_long_arg (t, i)) {
       if (i==d) doc << tree (OPEN_TAG, op);
       inactive_style ss= set_bf (sty, true, sty->close >= CLOSE_LONG);
       next= rewrite_inactive_arg (t, i, ss);
       next= compound ("indent*", next);
       i++;
      }

      int start= i;
      for (; i<n; i++)
       if ((!compact) || is_long_arg (t, i)) break;
      int end= i;
      tree_label l= MIDDLE_TAG;
      if (end == n) l= CLOSE_TAG;
      if (start == d) l= OPEN_TAG;
      tree u (l, end - start + 1);
      u[0]= op;
      for (i=0; i<end-start; i++)
       u[i+1]= rewrite_inactive_arg (t, start+i, reset_bf (sty));
      i= end-1;
      compact= (sty->compact < COMPACT_INLINE_START);

      if (start==d) doc << u;
      else {
       if (sty->close < CLOSE_LONG)
         doc << tree (SURROUND, "", u, next);
       else doc << next << u;
      }
    }

    if (sty->flush) doc= tree (SURROUND, "", compound ("right-flush"), doc);
    return doc;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 240 of file evaluate_inactive.cpp.

                                                       {
  if ((sty->block || (sty->compact == COMPACT_NONE)) &&
      (sty->special > SPECIAL_RAW) &&
      (sty->compact != COMPACT_ALL))
    {
      int i, n= N(t);
      tree r (DOCUMENT, n);
      for (i=0; i<n; i++) {
       inactive_style ss= set_bf (sty, true, sty->flush || (i<n-1));
       r[i]= rewrite_inactive_arg (t, i, ss);
      }
      return r;
    }
  return rewrite_inactive_default (t, sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 347 of file evaluate_inactive.cpp.

                                                     {
  if (is_atomic (t[0]) && (sty->special >= SPECIAL_NORMAL)) {
    int i, n= N(t);
    tree r (INLINE_TAG, n);
    r[0]= tree (CONCAT, "\\", highlight (t[0], "var"));
    for (i=1; i<n; i++)
      r[i]= rewrite_inactive_arg (t, i, reset_bf (sty));
    return r;
  }
  return rewrite_inactive_default (t, sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 427 of file evaluate_inactive.cpp.

                                                   {
  switch (L(t)) {
  case UNINIT:
    if (sty->special >= SPECIAL_NORMAL)
      return highlight ("?", "error");
    else return rewrite_inactive_default (t, sty);
  case RAW_DATA:
    return rewrite_inactive_raw_data (t, sty);
  case DOCUMENT:
    return rewrite_inactive_document (t, sty);
  case CONCAT:
    return rewrite_inactive_concat (t, sty);
  case VALUE:
    return rewrite_inactive_value (t, sty);
  case ARG:
    return rewrite_inactive_arg (t, sty);
  case STYLE_WITH:
    return rewrite_inactive_style_with (t, sty, true);
  case VAR_STYLE_WITH:
    return rewrite_inactive_style_with (t, sty, false);
  case STYLE_ONLY:
    return rewrite_inactive_active (t, sty);
  case VAR_STYLE_ONLY:
    return rewrite_inactive_var_active (t, sty);
  case ACTIVE:
    return rewrite_inactive_active (t, sty);
  case VAR_ACTIVE:
    return rewrite_inactive_var_active (t, sty);
  case SYMBOL:
    return rewrite_inactive_symbol (t, sty);
  case HYBRID:
    return rewrite_inactive_hybrid (t, sty);
  default:
    return rewrite_inactive_default (t, sty);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 234 of file evaluate_inactive.cpp.

                                                       {
  (void) t;
  return rewrite_inactive_default (tree (RAW_DATA), sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

tree rewrite_inactive_style_with ( tree  t,
inactive_style  sty,
bool  once 
)

Definition at line 298 of file evaluate_inactive.cpp.

                                                                    {
  (void) once;
  int /*i,*/ n= N(t);
  tree recover= tuple ();
  /*
  for (i=0; i<n-1; i+=2)
    if (is_atomic (t[i])) {
      recover << t[i] << read (t[i]->label);
      write_update (t[i]->label, t[i+1]);
    }
    if (once) recover_env= recover;
  */
  tree r= rewrite_inactive (t[n-1], sty);
  /*
  for (i=0; i<N(recover); i+=2)
    write_update (recover[i]->label, recover[i+1]);
  if (once) recover_env= tuple ();
  */
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 291 of file evaluate_inactive.cpp.

                                                     {
  if ((N(t) == 1) && is_atomic (t[0]) && (sty->special >= SPECIAL_NORMAL))
    return tree (INLINE_TAG, t[0]);
  return rewrite_inactive_default (t, sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 269 of file evaluate_inactive.cpp.

                                                    {
  if ((N(t) == 1) && is_atomic (t[0]) &&
      sty->style != STYLE_SCHEME && sty->special >= SPECIAL_NORMAL)
    return highlight (t[0],
                    sty->mode == INACTIVE_INLINE_ERROR ||
                    sty->mode == INACTIVE_BLOCK_ERROR ?
                    string ("error"): string ("var"));
  return rewrite_inactive_default (t, sty);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 337 of file evaluate_inactive.cpp.

                                                         {
  tree r= tree (WITH, mode_var, std_env [MODE], t[0]);
  if (sty->flush &&
      (sty->compact != COMPACT_ALL) &&
      (is_multi_paragraph (t[0])) || (sty->compact == COMPACT_NONE))
    r= tree (SURROUND, "", compound ("right-flush"), r);
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

inactive_style set_bf ( inactive_style  sty,
bool  block,
bool  flush 
) [inline]

Definition at line 108 of file evaluate_inactive.cpp.

                                                                          {
  inactive_style new_sty= sty;
  new_sty->block= block;
  new_sty->flush= flush;
  return new_sty; }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

tree mode_src("src") [static]
tree mode_var("mode") [static]
tree no_tree(UNINIT) [static]
tree psep_0fn("0fn") [static]
tree psep_var("par-par-sep") [static]
tree quote1(WITH,"color","blue","``") [static]
tree quote2(WITH,"color","blue","''") [static]
tree surround1("") [static]
tree surround2(VSPACE,"0.5fn") [static]