view anagram/agcore/data.cpp @ 1:60d3ca9d3f6b

Fix stupid bug in help2html.
author David A. Holland
date Tue, 12 Aug 2008 00:13:42 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-1999 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * data.cpp - Data Module
 */

#include <time.h>
#include "port.h"

#include "agarray.h"
#include "arrays.h"
#include "assert.h"
#include "config.h"
#include "data.h"
#include "dict.h"
#include "error.h"
#include "lexeme.h"
#include "myalloc.h"
#include "nckwtr.h"
#include "p.h"
#include "q1a.h"
#include "q1glbl.h"
#include "q5.h"
#include "rpz.h"
#include "tsd.h"

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


tuple_dict *frss_dict;

tsd *unres_con;
tsd *res_con;
int precedence_level = 0;
int enum_base = 0;

tsd *prr;
tsd *key_mess;
tsd *rename_macro_list;

int void_token_type = 1;
int int_token_type;
int long_token_type;
unsigned nprods = 0;

syntax_states syntax_state = syntax_error;

const char *syntaxStateString[] = {
  "Ready",
  "Loaded",
  "Error",
  "Parsed",
  "Analyzed",
  "Built"
};

char_set_map *map_char_set = NULL;
unsigned *part_list = NULL;
unsigned *chars_list = NULL;

static int ints[2];

list_dict *char_set_dict = NULL;
list_dict *key_list_dict = NULL;
list_dict *part_dict     = NULL;
list_dict *prod_dict     = NULL;
list_dict *vp_prod_dict  = NULL;

vp_prod_number_map *map_vp_prod_number = NULL;

unsigned *previous_states_list = NULL;
unsigned *completed_forms_list = NULL;
unsigned *gotos_list = NULL;
unsigned *reductions_list = NULL;
unsigned *a_actions_list = NULL;
unsigned *t_actions_list = NULL;
unsigned *p_actions_list = NULL;
unsigned *completions_list = NULL;
unsigned *chain_completions_list = NULL;
unsigned *chain_gotos_list = NULL;
unsigned *reduction_states_list = NULL;
unsigned nstates;

part_number_map *map_part_number = NULL;

char_number_map *map_char_number = NULL;
int max_char_number = -1;
int min_char_number = 0;
unsigned n_chars = 0;


/* flags */


FILE        *h_file = NULL;
FILE        *pe_file = NULL;

char        *key_ends = NULL;
tsd         *key_table = NULL;
unsigned     n_key_ends = 0;
int          max_key_length = 0;

int character_seen;

AgStack<int> distinguishSets;

static void reset_summary_lists(void) {
  part_list =  reset_list(part_list, 260);
  chars_list = reset_list(chars_list, 260);
}

static void reset_result_lists(void) {
  previous_states_list = reset_list(previous_states_list, 0);
  completed_forms_list = reset_list(completed_forms_list, 0);
  gotos_list = reset_list(gotos_list, 0);
  reductions_list = reset_list(reductions_list, 0);
  a_actions_list = reset_list(a_actions_list, 0);
  t_actions_list = reset_list(t_actions_list, 0);
  p_actions_list = reset_list(p_actions_list, 0);
  completions_list = reset_list(completions_list, 0);
  chain_completions_list = reset_list(chain_completions_list, 0);
  chain_gotos_list = reset_list(chain_gotos_list, 0);
  reduction_states_list = reset_list(reduction_states_list, 0);
}

#define reset_map(name, n) \
    map_##name = (name##_map *) \
	reset_array_size(map_##name, n, sizeof(name##_map))

static void reset_summary_arrays(void) {
  reset_map(char_number, 260);
  reset_map(char_set, 50);
  reset_map(part_number, 50);
  reset_map(vp_prod_number, 50);
}

void init_data(void) {
  LOGSECTION("init_data");

  reset_summary_lists();
  LOGS("summary lists reset");

  reset_result_lists();
  LOGS("result_lists reset");

  reset_summary_arrays();
  LOGS("summary_arrays reset");

  max_key_length = 0;
  map_state_number = (state_number_map *) 
	init_array(0, sizeof(state_number_map));
  nstates = 0;
  semantic_productions = 0;

  isht_dict = null_list_dict();
  frss_dict = null_tuple_dict(3);

  completed_form_dict = null_tuple_dict(2);
  MAP(completed_form, 20);

  unres_con = spec_tsd(0, 4);
  res_con = spec_tsd(0, 4);
  prr = spec_tsd(0, 4);
  key_mess = spec_tsd(0, 4);
  sgt = spec_tsd(100, 3);
  srt = spec_tsd(100, 2);

  rename_macro_list = spec_tsd(0, 2);

  disregard_token = disregard_cont_rule = disregard_skip_rule = 0;
  disregardList.reset();

  distinguishSets.reset();

  char_set_dict = null_list_dict();
  part_dict = null_list_dict();

  vp_prod_dict = null_list_dict();
  add_list_dict(ints, 0, char_set_dict);
  add_list_dict(ints, 0, part_dict);
  add_list_dict(ints, 0, vp_prod_dict);
  error_token = eof_token = 0;
  n_chars = min_char_number = 0;
  max_char_number = -1;

  ibnfb = ibnfs = NULL;
  ibnfn = NULL;
  token_perm = NULL;
  precedence_level = 0;
  nprods = 0;
  n_conflicts = 0;
  enum_base = 0;
  reset_errors();

  token_perm = NULL;
}

void reset_summary_data(void) {
  LOGSECTION("reset_summary_data");
  reset_summary_lists();
  reset_summary_arrays();

  delete_tsd(bnf_table);
  bnf_table = spec_tsd(200,2);

  if (key_table != NULL) {
    key_table = delete_tsd(key_table);
  }

  if (key_list_dict != NULL) {
    key_list_dict = delete_list_dict(key_list_dict);
  }

  if (key_ends != NULL) {
    DEALLOCATE(key_ends);
    key_ends = NULL;
  }

  n_key_ends = 0;
  max_key_length = 0;
  disregardList.reset();
  disregard_token = disregard_cont_rule = disregard_skip_rule = 0;
  distinguishSets.reset();
  ibnf_table = delete_tsd(ibnf_table);

  reset_list_dict(char_set_dict);
  reset_list_dict(part_dict);
  reset_list_dict(vp_prod_dict);

  add_list_dict(ints, 0, char_set_dict);
  add_list_dict(ints, 0, part_dict);
  add_list_dict(ints, 0, vp_prod_dict);
  n_chars = min_char_number = 0;
  max_char_number = -1;
  nforms = ntkns = 0;
  character_seen = 0;

  if (token_perm != NULL) {
    DEALLOCATE(token_perm);
    token_perm = NULL;
  }

  if (ibnfn != NULL) {
    DEALLOCATE(ibnfn);
    ibnfn = NULL;
  }

  if (ibnfb != NULL) {
    DEALLOCATE(ibnfb);
    ibnfb = NULL;
  }

  if (ibnfs != NULL) {
    DEALLOCATE(ibnfs);
    ibnfs = NULL;
  }

  //partition_required = 0;
  syntax_error_flag = 0;
  parse_abort_flag = 0;
  precedence_level = 0;
  enum_base = 0;
  nprods = 0;
  semantic_productions = 0;
  reset_errors();
}

static void reset_result_tuples(void) {
  reset_list_dict(isht_dict);
  reset_tuple_dict(frss_dict);
  reset_tuple_dict(completed_form_dict);
  reset_array(map_completed_form);
  reset_tsd(sgt);
  reset_tsd(srt);
  reset_tsd(unres_con);
  reset_tsd(res_con);
  reset_tsd(prr);
  reset_tsd(key_mess);
  reset_tsd(rename_macro_list);
}

void reset_result_data(void) {
  LOGSECTION("reset_result_data");
  reset_result_lists();
  reset_result_tuples();
  reset_array(map_state_number);
  nstates = kits = nits = 0;
  n_conflicts = 0;
  clear_conflict_expansion();
  if (key_table != NULL) key_table = delete_tsd(key_table);
  if (key_ends != NULL) {DEALLOCATE(key_ends); key_ends = NULL;}
  n_key_ends = 0;
}