Back to index

texmacs  1.0.7.15
bridge_eval.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : bridge_eval.cpp
00004 * DESCRIPTION: Bridge between logical and physical long macro expansions
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 /******************************************************************************
00015 * The bridge_eval_rep class
00016 ******************************************************************************/
00017 
00018 class bridge_eval_rep: public bridge_rep {
00019 protected:
00020   tree   bt;
00021   bridge body;
00022 
00023 public:
00024   bridge_eval_rep (typesetter ttt, tree st, path ip);
00025   void initialize (tree body_t);
00026 
00027   void notify_assign (path p, tree u);
00028   bool notify_macro  (int type, string var, int l, path p, tree u);
00029   void notify_change ();
00030 
00031   void my_typeset (int desired_status);
00032 };
00033 
00034 bridge_eval_rep::bridge_eval_rep (typesetter ttt, tree st, path ip):
00035   bridge_rep (ttt, st, ip) {}
00036 
00037 void
00038 bridge_eval_rep::initialize (tree body_t) {
00039   if (is_nil (body)) body= make_bridge (ttt, attach_right (body_t, ip));
00040   else replace_bridge (body, path (), bt, attach_right (body_t, ip));
00041   bt= copy (body_t);
00042 }
00043 
00044 bridge
00045 bridge_eval (typesetter ttt, tree st, path ip) {
00046   return tm_new<bridge_eval_rep> (ttt, st, ip);
00047 }
00048 
00049 /******************************************************************************
00050 * Event notification
00051 ******************************************************************************/
00052 
00053 void
00054 bridge_eval_rep::notify_assign (path p, tree u) {
00055   //cout << "Assign " << p << ", " << u << " in " << st << "\n";
00056   status= CORRUPTED;
00057   st= substitute (st, p, u);
00058 }
00059 
00060 bool
00061 bridge_eval_rep::notify_macro (int tp, string v, int l, path p, tree u) {
00062   //cout << "Macro argument " << v << " [action=" << tp
00063   //<< ", level=" << l << "] " << p << ", " << u << " in " << st << "\n";
00064   //cout << "  Body= " << bt << "\n";
00065   (void) tp; (void) p; (void) u;
00066   bool flag= env->depends (st, v, l);
00067   //cout << "  Flag= " << flag << "\n";
00068   if (flag) {
00069     status= CORRUPTED;
00070     body->notify_macro (tp, v, l, p, u);
00071   }
00072   return flag;
00073 }
00074 
00075 void
00076 bridge_eval_rep::notify_change () {
00077   status= CORRUPTED;
00078 }
00079 
00080 /******************************************************************************
00081 * Typesetting
00082 ******************************************************************************/
00083 
00084 void
00085 bridge_eval_rep::my_typeset (int desired_status) {
00086   if (is_func (st, EVAL, 1))
00087     initialize (env->exec (st[0]));
00088   else if (is_func (st, QUASI, 1))
00089     initialize (env->exec (tree (QUASIQUOTE, st[0])));
00090   else initialize (tree (ERROR, "bad eval bridge"));
00091   ttt->insert_marker (st, ip);
00092   body->typeset (desired_status);
00093 }