view anagram/guisupport/dc.cpp @ 15:f5acaf0c8a29

Don't cast through "volatile int". Causes a gcc warning nowadays. XXX: should put something else back here to frighten the optimizer
author David A. Holland
date Tue, 31 May 2022 01:00:55 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * dc.cpp - display contexts
 */

#include "assert.h"
#include "dc.h"
#include "myalloc.h"
#include "stacks.h"
#include "wdata.h"
#include "wm1.h"

//#define INCLUDE_LOGGING
#include "log.h"


static int dcsCreated = 0;
static int dcsDestroyed = 0;


////////////////////////////////////////////////////////////
//
// dc methods

void dc::init_dc(void) {
  LOGSECTION("dc::init");
  LOGV((int) this) LCV(head_title) LCV(foot_title);
  id = this;
  clear_data();
  des = ZALLOCATE(1, wd);

  tab_stops = NULL;
  syntax_dependent = 1;
  dcsCreated++;
}

void dc::clear_data(void) {
  LOGSECTION("dc::clear_data");
  usage_count = 0;
  tab_stops = NULL;
  syntax_dependent = 1;
}

dc::dc(void)
  : head_title()
  , foot_title()
  , windowConnector(0)
{
  init_dc();
}

dc::dc(const AgString head)
  : head_title(head)
  , foot_title()
  , windowConnector(0)
{
  init_dc();
}

dc::dc(const AgString head, const AgString foot)
  : head_title(head)
  , foot_title(foot)
  , windowConnector(0)
{
  init_dc();
}

dc::dc(dc &x)
  : head_title(x.head_title)
  , foot_title(x.foot_title)
  , windowConnector(0)
{
  id = this;
  des = ZALLOCATE(1,wd);
  *des = *x.des;
  syntax_dependent = x.syntax_dependent;
  tab_stops = x.tab_stops;
  columnHeadTitle = x.columnHeadTitle;
  usage_count = 0;
  dcsCreated++;
}

dc::~dc(void) {
  LOGSECTION("dc::~dc");
  LOGV(head_title) LCV(foot_title);
  assert(this == id && usage_count == 0);
  ok_ptr(this);
  ok_ptr(des);
  //if (windowConnector) delete windowConnector;
  DEALLOCATE(des);
  dcsDestroyed++;
}

AgString dc::findHelpTopic() { return AgString(); }

#define CURSOR  windowConnector->getCursorLine()

void dc::anomaly_trace()      { pop_up_window(anomaly_trace   (CURSOR)); }
void dc::aux_trace()          { pop_up_window(aux_trace       (CURSOR)); }
void dc::derive_rule()        { pop_up_window(derive_rule     (CURSOR)); }
void dc::derive_token()       { pop_up_window(derive_token    (CURSOR)); }
void dc::expansion_chain()    { pop_up_window(expansion_chain (CURSOR)); }
void dc::expansion_rules()    { pop_up_window(expansion_rules (CURSOR)); }
void dc::keywords()           { pop_up_window(keywords        (CURSOR)); }
void dc::partition_sets()     { pop_up_window(partition_sets  (CURSOR)); }
void dc::previous_states()    { pop_up_window(previous_states (CURSOR)); }
void dc::problem_states()     { pop_up_window(problem_states  (CURSOR)); }
void dc::productions()        { pop_up_window(productions     (CURSOR)); }

void dc::reduction_states()   { pop_up_window(reduction_states(CURSOR)); }
void dc::reduction_trace()    { pop_up_window(reduction_trace (CURSOR)); }
void dc::rule_context()       { pop_up_window(rule_context    (CURSOR)); }
//void dc::rule_stack()       { pop_up_window(rule_stack      (CURSOR)); }
void dc::select_conflict()    { pop_up_window(select_conflict (CURSOR)); }
void dc::set_elements()       { pop_up_window(set_elements    (CURSOR)); }
void dc::state_definition()   { pop_up_window(state_definition(CURSOR)); }
void dc::state_expansion()    { pop_up_window(state_expansion (CURSOR)); }
void dc::usage()              { pop_up_window(usage           (CURSOR)); }

int dc::derive_rule_ok()      { return derive_rule_ok         (CURSOR); }
int dc::expansion_chain_ok()  { return expansion_chain_ok     (CURSOR); }

int dc::expansion_rules_ok()  { return expansion_rules_ok     (CURSOR); }

int dc::keywords_ok()         { return keywords_ok            (CURSOR); }
int dc::previous_states_ok()  { return previous_states_ok     (CURSOR); }
int dc::productions_ok()      { return productions_ok         (CURSOR); }
int dc::reduction_states_ok() { return reduction_states_ok    (CURSOR); }
int dc::rule_context_ok()     { return rule_context_ok        (CURSOR); }
int dc::set_elements_ok()     { return set_elements_ok        (CURSOR); }
int dc::state_expansion_ok()  { return state_expansion_ok     (CURSOR); }
int dc::usage_ok()            { return usage_ok               (CURSOR); }

#undef CURSOR

void dc::getLine(unsigned ln) const {
  LOGSECTION("dc::getLine");
  LOGV(ln);
  assert(ln < (unsigned) des->d_size.y);
  ics();
}

////////////////////////////////////////////////////////////
//
// dc_ref methods

dc::ref::ref() : window(0) {}

dc::ref::ref(dc *x) {
  LOGSECTION("dc::ref::ref");
  window = x;
  if (window) {
    ok_ptr(window);
    window->usage_count++;
    LOGV((int) window) LCV(window->usage_count);
  }
}

dc::ref::ref(const ref &x) {
  window = x.window;
  if (window) {
    ok_ptr(window);
    window->usage_count++;
  }
}

dc::ref &dc::ref::operator =(const ref &x) {
  if (window == x.window) {
    return *this;
  }
  if (window) {
    ok_ptr(window);
    if (window->usage_count && --window->usage_count == 0) {
      delete window;
    }
  }
  window = x.window;
  if (window) {
    ok_ptr(window);
    window->usage_count++;
  }
  return *this;
}

dc::ref &dc::ref::operator =(dc *x) {
  if (window == x) {
    return *this;
  }
  if (window) {
    ok_ptr(window);
    LOGV((int) window) LCV(window->usage_count);
    if (window->usage_count && --window->usage_count == 0) {
      delete window;
    }
  }
  window = x;
  if (window) {
    ok_ptr(window);
    LOGV(window->usage_count);
    window->usage_count++;
  }
  return *this;
}

dc::ref::~ref(void) {
  LOGSECTION("dc::ref::~ref");
  if (window) {
    ok_ptr(window);
    LOGV((int) window) LCV(window->usage_count);
    if (window->usage_count && --window->usage_count == 0) {
      delete window;
    }
  }
}

void dc::ref::discardData(void) {
  dc *alias = window;
  window = 0;
  if (alias) {
    ok_ptr(alias);
    LOGV((int) alias) LCV(alias->usage_count);
    if (alias->usage_count && --alias->usage_count == 0) {
      delete alias;
    }
  }
}

dc::ref::operator dc *(void) const {
  if (window) {
    ok_ptr(window);
  }
  return window;
}

dc *dc::ref::operator ->(void) const {
  ok_ptr(window);
  return window;
}