view anagram/guisupport/dc.h @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -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.h - display contexts
 */

#ifndef DC_H
#define DC_H

class WindowConnector; // from wdata.h
#include "agstring.h"
#include "cint.h"

struct wd {
  const char *head_title_display;
  const char *foot_title_display;
  int refresh;                         /* increment to refresh */
  cint c_loc_doc;                      /* location of cursor on document */
  cint d_size;                         /* size of document */
};

struct dc {
  // Reference control

  int usage_count;

  class ref {
  protected:
    dc *window;

  public:
    ref(void);
    ref(dc *x);
    ref(const ref &x);

    ref &operator =(const ref &x);
    ref &operator =(dc *x);
    ~ref(void);

    void discardData(void);
    int exists(void) const { return window != NULL; }

    operator dc *(void) const;
    dc *operator ->(void) const;
    int operator ==(const ref &x) const { return window == x.window; }
    int operator !=(const ref &x) const { return window != x.window; }
  };

  AgString head_title, foot_title;
  AgString columnHeadTitle;

  dc *id;

  wd *des;                             /* describes desired window */
  WindowConnector *windowConnector;

  int *tab_stops;


  unsigned syntax_dependent : 1;

  void init_dc(void);
  void clear_data(void);

  dc(void);

  dc(const AgString head);
  dc(const AgString head, const AgString foot);
  dc(dc &x);

  virtual ~dc();

  struct MenuOption {
    const char *option_name;
    void (dc:: * action)();
    int (dc::  * ok_action)();
    MenuOption() : option_name(0) {}
    MenuOption(const char *name) : option_name(name) {}
    virtual ~MenuOption() {}
    virtual ref getAuxWindow(ref, unsigned) { return ref(); }
  };

  virtual AgString findHelpTopic();
  virtual MenuOption **getAuxWinMenu(void) { return NULL; }
  virtual ref anomaly_trace(unsigned)    { return ref(); }
  virtual ref aux_trace(unsigned)        { return ref(); }
  virtual ref derive_rule(unsigned)      { return ref(); }
  virtual ref derive_token(unsigned)     { return ref(); }
  virtual ref expansion_chain(unsigned)  { return ref(); }
  virtual ref expansion_rules(unsigned)  { return ref(); }
  virtual ref keywords(unsigned)         { return ref(); }
  virtual ref partition_sets(unsigned)   { return ref(); }
  virtual ref previous_states(unsigned)  { return ref(); }
  virtual ref problem_states(unsigned)   { return ref(); }
  virtual ref productions(unsigned)      { return ref(); }

  virtual ref reduction_states(unsigned) { return ref(); }
  virtual ref reduction_trace(unsigned)  { return ref(); }
  virtual ref rule_context(unsigned)     { return ref(); }
  //virtual ref rule_stack(unsigned)       { return ref(); }
  virtual ref select_conflict(unsigned)  { return ref(); }
  virtual ref set_elements(unsigned)     { return ref(); }
  virtual ref state_definition(unsigned) { return ref(); }
  virtual ref state_expansion(unsigned)  { return ref(); }
  virtual ref usage(unsigned)            { return ref(); }

  virtual int derive_rule_ok(unsigned)      { return 1; }
  virtual int expansion_chain_ok(unsigned)  { return 1; }
  virtual int expansion_rules_ok(unsigned)  { return 1; }
  virtual int keywords_ok(unsigned)         { return 1; }
  virtual int previous_states_ok(unsigned)  { return 1; }
  virtual int productions_ok(unsigned)      { return 1; }

  virtual int reduction_states_ok(unsigned) { return 1; }
  virtual int rule_context_ok(unsigned)     { return 1; }
  virtual int set_elements_ok(unsigned)     { return 1; }
  virtual int state_expansion_ok(unsigned)  { return 1; }
  virtual int usage_ok(unsigned)            { return 1; }

  void anomaly_trace()    ;
  void aux_trace()        ;
  void derive_rule()      ;
  void derive_token()     ;
  void expansion_chain()  ;
  void expansion_rules()  ;
  void keywords()         ;
  void partition_sets()   ;
  void previous_states()  ;
  void problem_states()   ;
  void productions()      ;

  void reduction_states() ;
  void reduction_trace()  ;
  void rule_context()     ;
  //void rule_stack()     ;
  void select_conflict()  ;
  void set_elements()     ;
  void state_definition() ;
  void state_expansion()  ;
  void usage()            ;

  int derive_rule_ok()    ;

  int anomaly_trace_ok()    { return 1; }
  int aux_trace_ok()        { return 1; }
  int derive_token_ok()     { return derive_rule_ok(); }
  int expansion_chain_ok();
  int expansion_rules_ok();
  int keywords_ok()       ;
  int partition_sets_ok()   { return 1; }
  int previous_states_ok();
  int problem_states_ok()   { return derive_rule_ok(); }
  int productions_ok()    ;

  int reduction_states_ok();
  int reduction_trace_ok()  { return derive_rule_ok(); }
  int rule_context_ok()   ;
  //int rule_stack_ok()     { return 1; }
  int select_conflict_ok()  { return derive_rule_ok(); }
  int set_elements_ok()   ;
  int state_definition_ok() { return 1; }
  int state_expansion_ok();
  int usage_ok()          ;

  struct AnomalyTraceOption : public MenuOption {
    AnomalyTraceOption(void) : MenuOption("Keyword Anomaly Trace") {
      ok_action = &dc::anomaly_trace_ok;
      action = &dc::anomaly_trace;
    }
    virtual ~AnomalyTraceOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->anomaly_trace(ln);
    }
  };

  struct AuxiliaryTraceOption : public MenuOption {
    AuxiliaryTraceOption(void) : MenuOption("Auxiliary Trace") {
      ok_action = &dc::aux_trace_ok;
      action = &dc::aux_trace;
    }
    virtual ~AuxiliaryTraceOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->aux_trace(ln);
    }
  };

  struct ConflictTraceOption : public MenuOption {
    ConflictTraceOption(void) : MenuOption("Conflict Trace") {
      ok_action = &dc::select_conflict_ok;
      action = &dc::select_conflict;
    }
    virtual ~ConflictTraceOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->select_conflict(ln);
    }
  };


  struct ExpansionChainOption : public MenuOption {
    ExpansionChainOption(void) : MenuOption("Expansion Chain") {
      ok_action = &dc::expansion_chain_ok;
      action = &dc::expansion_chain;
    }
    virtual ~ExpansionChainOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->expansion_chain(ln);
    }
  };

  struct ExpansionRulesOption : public MenuOption {
    ExpansionRulesOption(void) : MenuOption("Expansion Rules") {
      ok_action = &dc::expansion_rules_ok;
      action = &dc::expansion_rules;
    }
    virtual ~ExpansionRulesOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->expansion_rules(ln);
    }
  };

  struct KeywordsOption : public MenuOption {
    KeywordsOption(void) : MenuOption("Keywords") {
      ok_action = &dc::keywords_ok;
      action = &dc::keywords;
    }
    virtual ~KeywordsOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->keywords(ln);
    }
  };

  struct PartitionSetsOption : public MenuOption {
    PartitionSetsOption(void) : MenuOption("Partition Sets") {
      ok_action = &dc::partition_sets_ok;
      action = &dc::partition_sets;
    }
    virtual ~PartitionSetsOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->partition_sets(ln);
    }
  };

  struct PreviousStatesOption : public MenuOption {
    PreviousStatesOption(void) : MenuOption("Previous States") {
      ok_action = &dc::previous_states_ok;
      action = &dc::previous_states;
    }
    virtual ~PreviousStatesOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->previous_states(ln);
    }
  };

  struct ProblemStatesOption : public MenuOption {
    ProblemStatesOption(void) : MenuOption("Problem States") {
      ok_action = &dc::problem_states_ok;
      action = &dc::problem_states;
    }
    virtual ~ProblemStatesOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->problem_states(ln);
    }
  };

  struct ProductionsOption : public MenuOption {
    ProductionsOption(void) : MenuOption("Productions") {
      ok_action = &dc::productions_ok;
      action = &dc::productions;
    }
    virtual ~ProductionsOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->productions(ln);
    }
  };

  struct ReductionStatesOption : public MenuOption {
    ReductionStatesOption(void) : MenuOption("Reduction States") {
      ok_action = &dc::reduction_states_ok;
      action = &dc::reduction_states;
    }
    virtual ~ReductionStatesOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->reduction_states(ln);
    }
  };

  struct ReductionTraceOption : public MenuOption {
    ReductionTraceOption(void) : MenuOption("Reduction Trace") {
      ok_action = &dc::reduction_trace_ok;
      action = &dc::reduction_trace;
    }
    virtual ~ReductionTraceOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->reduction_trace(ln);
    }
  };

  struct RuleContextOption : public MenuOption {
    RuleContextOption(void) : MenuOption("Rule Context") {
      ok_action = &dc::rule_context_ok;
      action = &dc::rule_context;
    }
    virtual ~RuleContextOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->rule_context(ln);
    }
  };

  struct RuleDerivationOption : public MenuOption {
    RuleDerivationOption(void) : MenuOption("Rule Derivation") {
      ok_action = &dc::derive_rule_ok;
      action = &dc::derive_rule;
    }
    virtual ~RuleDerivationOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->derive_rule(ln);
    }
  };
/*
  struct RuleStackOption : public MenuOption {
    RuleStackOption(void) : MenuOption("Rule Stack") {
      ok_action = &dc::rule_stack_ok;
      action = &dc::rule_stack;
    }
    virtual ~RuleStackOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->rule_stack(ln);
    }
  };
*/
  struct SetElementsOption : public MenuOption {
    SetElementsOption(void) : MenuOption("Set Elements") {
      ok_action = &dc::set_elements_ok;
      action = &dc::set_elements;
    }
    virtual ~SetElementsOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->set_elements(ln);
    }
  };

  struct StateDefinitionOption : public MenuOption {
    StateDefinitionOption(void) : MenuOption("State Definition") {
      ok_action = &dc::state_definition_ok;
      action = &dc::state_definition;
    }
    virtual ~StateDefinitionOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->state_definition(ln);
    }
  };

  struct StateExpansionOption : public MenuOption {
    StateExpansionOption(void) : MenuOption("State Expansion") {
      ok_action = &dc::state_expansion_ok;
      action = &dc::state_expansion;
    }
    virtual ~StateExpansionOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->state_expansion(ln);
    }
  };

  struct TokenDerivationOption : public MenuOption {
    TokenDerivationOption(void) : MenuOption("Token Derivation") {
      ok_action = &dc::derive_token_ok;
      action = &dc::derive_token;
    }
    virtual ~TokenDerivationOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->derive_token(ln);
    }
  };

  struct TokenUsageOption : public MenuOption {
    TokenUsageOption(void): MenuOption("Token Usage") {
      ok_action = &dc::usage_ok;
      action = &dc::usage;
    }
    virtual ~TokenUsageOption() {}
    virtual ref getAuxWindow(ref d, unsigned ln) {
      return d->usage(ln);
    }
  };
/*
  static const char *help_gs_msg;
  static const char *help_index_msg;
  static const char *kbd_ref_msg;
  static const char *mouse_ref_msg;
  static const char *using_help_msg;
  static const char *help_wn_msg;
*/

  static AnomalyTraceOption    anomalyTraceOptionInstance;
  static AuxiliaryTraceOption  auxiliaryTraceOptionInstance;
  static ConflictTraceOption   conflictTraceOptionInstance;
  static ExpansionChainOption  expansionChainOptionInstance;
  static ExpansionRulesOption  expansionRulesOptionInstance;
  static KeywordsOption        keywordsOptionInstance;
  static PartitionSetsOption   partitionSetsOptionInstance;
  static PreviousStatesOption  previousStatesOptionInstance;
  static ProblemStatesOption   problemStatesOptionInstance;
  static ProductionsOption     productionsOptionInstance;
  static ReductionStatesOption reductionStatesOptionInstance;
  static ReductionTraceOption  reductionTraceOptionInstance;
  static RuleContextOption     ruleContextOptionInstance;
  static RuleDerivationOption  ruleDerivationOptionInstance;
  //static RuleStackOption       ruleStackOptionInstance;
  static SetElementsOption     setElementsOptionInstance;
  static StateDefinitionOption stateDefinitionOptionInstance;
  static StateExpansionOption  stateExpansionOptionInstance;
  static TokenDerivationOption tokenDerivationOptionInstance;
  static TokenUsageOption      tokenUsageOptionInstance;

  virtual void getLine(unsigned) const;
  virtual void synchCursor(unsigned) const {}
};

typedef dc::ref dc_ref;

template <class T>
class DcRef : public dc::ref {
public:
  DcRef(void);// {}
  DcRef(T *x);// : dc::ref((dc *) x) {}
  DcRef(const DcRef<T> &x);// : dc::ref(x) {}
  DcRef(dc::ref x);// : dc::ref(x) {}

  operator T *() { return (T *) window; }
  T *operator ->(void)
    { return (T *) window; }
};

template <class T>
DcRef<T>::DcRef(void) {}
template <class T>
DcRef<T>::DcRef(T *x) : dc::ref((dc *) x) {}
template <class T>
DcRef<T>::DcRef(const DcRef<T> &x) : dc::ref(x) {}
template <class T>
DcRef<T>::DcRef(dc::ref x) : dc::ref(x) {}


#endif /* DC_H */