view anagram/guisupport/symtabdc.cpp @ 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.
 *
 * symtabdc.cpp
 */

#include "csexp.h"
#include "dc.h"
#include "items.h"
#include "stacks.h"
#include "symbol.h"
#include "symtabdc.h"
#include "token.h"
#include "tree.h"
#include "ut.h"
#include "ws.h"

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


static int symbol_table_tabs[] = {6,0};

symbol_table_dc::symbol_table_dc(void)
  : dc("Symbol Table")
{
  LOGSECTION("symbol_table_dc::symbol_table_dc");
  des->d_size.y = Symbol::count() - 1;
  LOGV(Symbol::count());

  tab_stops = symbol_table_tabs;
  columnHeadTitle = "Token\tSymbol";
}

void symbol_table_dc::getLine(unsigned n) const {
  LOGSECTION("symbol_table_dc::getLine");
  LOGV(n) LCV(Symbol::count());
  int vptn;

  Symbol symbol = Symbol::sorted(n + 1);
  LOGV(symbol) LCV(symbol->string.pointer());
  ics();
  Token token = symbol->token_number;
  LOGV(token);
  if (token.isNotNull()) {
    apprintf("T%03d", (int) token);
  }
  acs('\t');
  ass(symbol->string.pointer());
  ParseTree parseTree = symbol->parse_tree;
  LOGV(parseTree);
  if (parseTree.isNotNull()) {
    ass( " = ");
    ass(parseTree->expression->asString().pointer());
    return;
  }
  LOGV(token->vp_prod_number);
  if (token.isNotNull() && (vptn = token->vp_prod_number) != 0) {
    ass( " = ");
    avptkn(vptn);
    return;
  }
}

unsigned symbol_table_dc::token(unsigned ln) {
  Symbol symbol = Symbol::sorted(ln + 1);
  return symbol->token_number;
}

int symbol_table_dc::expansion_rules_ok(unsigned ln) {
  return build_item_list_ok(token(ln));
}

dc_ref symbol_table_dc::expansion_rules(unsigned ln) {
  return build_item_list(token(ln));
}

int symbol_table_dc::productions_ok(unsigned ln) {
  return productions_window_ok(token(ln));
}

dc_ref symbol_table_dc::productions(unsigned ln) {
  return productions_window(token(ln));
}

int symbol_table_dc::set_elements_ok(unsigned ln) {
  Symbol symbol = Symbol::sorted(ln + 1);
  int pt = symbol->parse_tree;

  if (pt) {
    return char_set_window_ok(map_parse_tree[pt].char_set);
  }
  return token_set_window_ok(symbol->token_number);
}

dc_ref symbol_table_dc::set_elements(unsigned ln) {
  Symbol symbol = Symbol::sorted(ln + 1);
  int pt = symbol->parse_tree;

  if (pt) {
    return char_set_window(map_parse_tree[pt].char_set);
  }
  return token_set_window(symbol->token_number);
}

int symbol_table_dc::usage_ok(unsigned ln) {
  return token_usage_window_ok(token(ln));
}

dc_ref symbol_table_dc::usage(unsigned ln) {
  return token_usage_window(token(ln));
}