Back to index

texmacs  1.0.7.15
bridge_expand_as.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : bridge_expand_as.cpp
00004 * DESCRIPTION: Bridge for expand_as construct
00005 * COPYRIGHT  : (C) 1999  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 #include "bridge.hpp"
00013 
00014 class bridge_expand_as_rep: public bridge_rep {
00015 protected:
00016   bridge body;
00017 
00018 public:
00019   bridge_expand_as_rep (typesetter ttt, tree st, path ip);
00020   void initialize ();
00021 
00022   void notify_assign (path p, tree u);
00023   void notify_insert (path p, tree u);
00024   void notify_remove (path p, int nr);
00025   bool notify_macro  (int type, string var, int level, path p, tree u);
00026   void notify_change ();
00027 
00028   void my_exec_until (path p);
00029   bool my_typeset_will_be_complete ();
00030   void my_typeset (int desired_status);
00031 };
00032 
00033 bridge_expand_as_rep::bridge_expand_as_rep (typesetter ttt, tree st, path ip):
00034   bridge_rep (ttt, st, ip)
00035 {
00036   initialize ();
00037 }
00038 
00039 void
00040 bridge_expand_as_rep::initialize () {
00041   if (is_nil (body)) body= make_bridge (ttt, st[1], descend (ip, 1));
00042   else replace_bridge (body, st[1], descend (ip, 1));
00043 }
00044 
00045 bridge
00046 bridge_expand_as (typesetter ttt, tree st, path ip) {
00047   return tm_new<bridge_expand_as_rep> (ttt, st, ip);
00048 }
00049 
00050 /******************************************************************************
00051 * Event notification
00052 ******************************************************************************/
00053 
00054 void
00055 bridge_expand_as_rep::notify_assign (path p, tree u) {
00056   // cout << "Assign " << p << ", " << u << " in " << st << "\n";
00057   ASSERT (!is_nil (p) || is_func (u, EXPAND_AS), "nil path");
00058   if (is_nil (p) || (p->item != 1)) {
00059     st= substitute (st, p, u);
00060     initialize ();
00061   }
00062   else {
00063     // bool mp_flag= is_multi_paragraph (st);
00064     if (is_atom (p)) {
00065       body= make_bridge (ttt, u, descend (ip, 1));
00066       st= substitute (st, 1, body->st);
00067     }
00068     else {
00069       body->notify_assign (p->next, u);
00070       st= substitute (st, p->item, body->st);
00071     }
00072     // if (mp_flag != is_multi_paragraph (st)) initialize ();
00073   }
00074   status= CORRUPTED;
00075 }
00076 
00077 void
00078 bridge_expand_as_rep::notify_insert (path p, tree u) {
00079   // cout << "Insert " << p << ", " << u << " in " << st << "\n";
00080   ASSERT (!is_nil (p), "nil path");
00081   if (is_atom (p) || (p->item != 1)) bridge_rep::notify_insert (p, u);
00082   else {
00083     // bool mp_flag= is_multi_paragraph (st);
00084     body->notify_insert (p->next, u);
00085     st= substitute (st, 1, body->st);
00086     // if (mp_flag != is_multi_paragraph (st)) initialize ();
00087   }
00088   status= CORRUPTED;
00089 }
00090 
00091 void
00092 bridge_expand_as_rep::notify_remove (path p, int nr) {
00093   // cout << "Remove " << p << ", " << nr << " in " << st << "\n";
00094   ASSERT (!is_nil (p), "nil path");
00095   if (is_atom (p) || (p->item != 1)) bridge_rep::notify_remove (p, nr);
00096   else {
00097     // bool mp_flag= is_multi_paragraph (st);
00098     body->notify_remove (p->next, nr);
00099     st= substitute (st, 1, body->st);
00100     // if (mp_flag != is_multi_paragraph (st)) initialize ();
00101   }
00102   status= CORRUPTED;
00103 }
00104 
00105 bool
00106 bridge_expand_as_rep::notify_macro 
00107   (int tp, string var, int l, path p, tree u)
00108 {
00109   /*
00110   cout << "Macro argument " << var << " [action=" << tp
00111        << ", level=" << l << "] " << p << ", " << u << " in " << st << "\n";
00112   */
00113 
00114   bool flag= env->depends (st[0], var, l) || env->depends (st[1], var, l);
00115   if (flag) initialize ();
00116   flag= body->notify_macro (tp, var, l, p, u) || flag;
00117   if (flag) status= CORRUPTED;
00118   return flag;
00119 }
00120 
00121 void
00122 bridge_expand_as_rep::notify_change () {
00123   status= CORRUPTED;
00124   body->notify_change ();
00125 }
00126 
00127 /******************************************************************************
00128 * Typesetting
00129 ******************************************************************************/
00130 
00131 void
00132 bridge_expand_as_rep::my_exec_until (path p) {
00133   if (p->item == 1) body->exec_until (p->next);
00134   else env->exec_until (st, p);
00135 }
00136 
00137 bool
00138 bridge_expand_as_rep::my_typeset_will_be_complete () {
00139   if (status != CORRUPTED) return false;
00140   return body->my_typeset_will_be_complete ();
00141 }
00142 
00143 void
00144 bridge_expand_as_rep::my_typeset (int desired_status) {
00145   ttt->insert_marker (st, ip);
00146   body->typeset (desired_status);
00147 }